@agentshouse/mdruntime 0.1.0-cf08ada271a7f → 0.1.0-cf08df9b663d8

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 (305) hide show
  1. package/README.md +21 -19
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +57 -38
  4. package/dist/act-lanes.d.ts +30 -0
  5. package/dist/act-lanes.d.ts.map +1 -0
  6. package/dist/act-lanes.js +225 -0
  7. package/dist/actions.d.ts +8 -2
  8. package/dist/actions.d.ts.map +1 -1
  9. package/dist/actions.js +173 -83
  10. package/dist/adapter.d.ts +210 -30
  11. package/dist/adapter.d.ts.map +1 -1
  12. package/dist/attached-model.d.ts +0 -1
  13. package/dist/attached-model.d.ts.map +1 -1
  14. package/dist/attached-model.js +2 -7
  15. package/dist/{binary.d.ts → attachment.d.ts} +8 -4
  16. package/dist/attachment.d.ts.map +1 -0
  17. package/dist/attachment.js +15 -0
  18. package/dist/authored.d.ts +88 -0
  19. package/dist/authored.d.ts.map +1 -0
  20. package/dist/authored.js +345 -0
  21. package/dist/chain.d.ts +1 -1
  22. package/dist/chain.d.ts.map +1 -1
  23. package/dist/chain.js +5 -2
  24. package/dist/change.d.ts +6 -2
  25. package/dist/change.d.ts.map +1 -1
  26. package/dist/change.js +3 -0
  27. package/dist/chat-types.d.ts +0 -2
  28. package/dist/chat-types.d.ts.map +1 -1
  29. package/dist/chat-types.js +2 -4
  30. package/dist/client.d.ts +29 -24
  31. package/dist/client.d.ts.map +1 -1
  32. package/dist/client.js +49 -64
  33. package/dist/collection.d.ts +6 -1
  34. package/dist/collection.d.ts.map +1 -1
  35. package/dist/collection.js +23 -9
  36. package/dist/column.d.ts +5 -0
  37. package/dist/column.d.ts.map +1 -0
  38. package/dist/column.js +9 -0
  39. package/dist/compile.d.ts +4 -1
  40. package/dist/compile.d.ts.map +1 -1
  41. package/dist/compile.js +88 -44
  42. package/dist/connection.d.ts +1 -1
  43. package/dist/connection.d.ts.map +1 -1
  44. package/dist/connection.js +32 -17
  45. package/dist/context.d.ts.map +1 -1
  46. package/dist/context.js +1 -1
  47. package/dist/conversation-live.d.ts +26 -11
  48. package/dist/conversation-live.d.ts.map +1 -1
  49. package/dist/conversation-live.js +24 -11
  50. package/dist/conversation-row.d.ts +23 -1
  51. package/dist/conversation-row.d.ts.map +1 -1
  52. package/dist/conversation-row.js +37 -8
  53. package/dist/conversation.d.ts +45 -11
  54. package/dist/conversation.d.ts.map +1 -1
  55. package/dist/conversation.js +337 -203
  56. package/dist/declaration.js +3 -3
  57. package/dist/discovery.d.ts +3 -1
  58. package/dist/discovery.d.ts.map +1 -1
  59. package/dist/discovery.js +46 -48
  60. package/dist/download.d.ts +6 -0
  61. package/dist/download.d.ts.map +1 -0
  62. package/dist/download.js +42 -0
  63. package/dist/durability.d.ts +6 -1
  64. package/dist/durability.d.ts.map +1 -1
  65. package/dist/durability.js +7 -0
  66. package/dist/entry.d.ts +26 -1
  67. package/dist/entry.d.ts.map +1 -1
  68. package/dist/entry.js +126 -36
  69. package/dist/expectation.d.ts +25 -14
  70. package/dist/expectation.d.ts.map +1 -1
  71. package/dist/expectation.js +51 -20
  72. package/dist/failure.d.ts +2 -0
  73. package/dist/failure.d.ts.map +1 -1
  74. package/dist/failure.js +6 -1
  75. package/dist/figures.d.ts +1 -1
  76. package/dist/figures.d.ts.map +1 -1
  77. package/dist/figures.js +6 -4
  78. package/dist/file.d.ts +1 -1
  79. package/dist/file.d.ts.map +1 -1
  80. package/dist/file.js +3 -2
  81. package/dist/holdings.d.ts.map +1 -1
  82. package/dist/holdings.js +5 -3
  83. package/dist/host.d.ts +7 -2
  84. package/dist/host.d.ts.map +1 -1
  85. package/dist/host.js +94 -30
  86. package/dist/house-query.d.ts +24 -0
  87. package/dist/house-query.d.ts.map +1 -0
  88. package/dist/house-query.js +102 -0
  89. package/dist/identity.d.ts +1 -1
  90. package/dist/identity.d.ts.map +1 -1
  91. package/dist/identity.js +1 -1
  92. package/dist/index.d.ts +27 -16
  93. package/dist/index.d.ts.map +1 -1
  94. package/dist/index.js +17 -9
  95. package/dist/install.d.ts +10 -5
  96. package/dist/install.d.ts.map +1 -1
  97. package/dist/install.js +49 -55
  98. package/dist/lifecycle.d.ts +2 -2
  99. package/dist/lifecycle.d.ts.map +1 -1
  100. package/dist/lifecycle.js +74 -51
  101. package/dist/linked-file.d.ts +7 -0
  102. package/dist/linked-file.d.ts.map +1 -0
  103. package/dist/linked-file.js +13 -0
  104. package/dist/listing.d.ts +27 -20
  105. package/dist/listing.d.ts.map +1 -1
  106. package/dist/listing.js +68 -69
  107. package/dist/live.d.ts +19 -3
  108. package/dist/live.d.ts.map +1 -1
  109. package/dist/live.js +94 -36
  110. package/dist/loaded.d.ts +7 -0
  111. package/dist/loaded.d.ts.map +1 -0
  112. package/dist/loaded.js +46 -0
  113. package/dist/locks.d.ts +2 -4
  114. package/dist/locks.d.ts.map +1 -1
  115. package/dist/locks.js +10 -38
  116. package/dist/lost.d.ts.map +1 -1
  117. package/dist/lost.js +8 -20
  118. package/dist/media.d.ts +19 -3
  119. package/dist/media.d.ts.map +1 -1
  120. package/dist/media.js +181 -34
  121. package/dist/memory.d.ts +7 -3
  122. package/dist/memory.d.ts.map +1 -1
  123. package/dist/memory.js +99 -37
  124. package/dist/messages.d.ts +21 -3
  125. package/dist/messages.d.ts.map +1 -1
  126. package/dist/messages.js +48 -16
  127. package/dist/modal.d.ts +2 -0
  128. package/dist/modal.d.ts.map +1 -0
  129. package/dist/modal.js +11 -0
  130. package/dist/model.d.ts +10 -7
  131. package/dist/model.d.ts.map +1 -1
  132. package/dist/model.js +7 -1
  133. package/dist/models.d.ts.map +1 -1
  134. package/dist/models.js +18 -35
  135. package/dist/name.d.ts +0 -1
  136. package/dist/name.d.ts.map +1 -1
  137. package/dist/name.js +3 -7
  138. package/dist/observation.d.ts +29 -12
  139. package/dist/observation.d.ts.map +1 -1
  140. package/dist/observation.js +206 -69
  141. package/dist/online.d.ts +7 -0
  142. package/dist/online.d.ts.map +1 -0
  143. package/dist/online.js +29 -0
  144. package/dist/opened.d.ts +6 -6
  145. package/dist/opened.d.ts.map +1 -1
  146. package/dist/opened.js +4 -4
  147. package/dist/opening.d.ts.map +1 -1
  148. package/dist/opening.js +22 -10
  149. package/dist/outcome.d.ts +33 -13
  150. package/dist/outcome.d.ts.map +1 -1
  151. package/dist/outcome.js +36 -6
  152. package/dist/overlay.d.ts +21 -7
  153. package/dist/overlay.d.ts.map +1 -1
  154. package/dist/overlay.js +112 -39
  155. package/dist/page-metadata.d.ts +8 -0
  156. package/dist/page-metadata.d.ts.map +1 -0
  157. package/dist/page-metadata.js +19 -0
  158. package/dist/parts.d.ts +5 -9
  159. package/dist/parts.d.ts.map +1 -1
  160. package/dist/parts.js +30 -15
  161. package/dist/paths.d.ts +1 -1
  162. package/dist/paths.js +1 -1
  163. package/dist/preparation.d.ts +33 -7
  164. package/dist/preparation.d.ts.map +1 -1
  165. package/dist/preparation.js +207 -96
  166. package/dist/presence.d.ts +58 -0
  167. package/dist/presence.d.ts.map +1 -0
  168. package/dist/presence.js +231 -0
  169. package/dist/queries.d.ts +2 -2
  170. package/dist/queries.d.ts.map +1 -1
  171. package/dist/queries.js +137 -79
  172. package/dist/query.d.ts +2 -2
  173. package/dist/query.d.ts.map +1 -1
  174. package/dist/questions.d.ts +1 -5
  175. package/dist/questions.d.ts.map +1 -1
  176. package/dist/questions.js +3 -8
  177. package/dist/queue.d.ts +2 -1
  178. package/dist/queue.d.ts.map +1 -1
  179. package/dist/queue.js +76 -49
  180. package/dist/reach.d.ts +15 -6
  181. package/dist/reach.d.ts.map +1 -1
  182. package/dist/reach.js +196 -37
  183. package/dist/react.d.ts +17 -5
  184. package/dist/react.d.ts.map +1 -1
  185. package/dist/react.js +28 -5
  186. package/dist/readiness.d.ts +23 -4
  187. package/dist/readiness.d.ts.map +1 -1
  188. package/dist/readiness.js +18 -10
  189. package/dist/reads.d.ts +5 -3
  190. package/dist/reads.d.ts.map +1 -1
  191. package/dist/reads.js +26 -14
  192. package/dist/recovery.d.ts +4 -1
  193. package/dist/recovery.d.ts.map +1 -1
  194. package/dist/recovery.js +31 -8
  195. package/dist/refresh.d.ts +1 -1
  196. package/dist/refresh.js +4 -4
  197. package/dist/refusal.d.ts.map +1 -1
  198. package/dist/refusal.js +2 -4
  199. package/dist/replica.d.ts +3 -8
  200. package/dist/replica.d.ts.map +1 -1
  201. package/dist/replica.js +5 -5
  202. package/dist/retried.d.ts +30 -0
  203. package/dist/retried.d.ts.map +1 -0
  204. package/dist/retried.js +72 -0
  205. package/dist/room-draft.d.ts +31 -6
  206. package/dist/room-draft.d.ts.map +1 -1
  207. package/dist/room-draft.js +262 -36
  208. package/dist/room-drafts.d.ts.map +1 -1
  209. package/dist/room-drafts.js +12 -7
  210. package/dist/room-list.d.ts +10 -0
  211. package/dist/room-list.d.ts.map +1 -0
  212. package/dist/room-list.js +47 -0
  213. package/dist/rows.d.ts +11 -3
  214. package/dist/rows.d.ts.map +1 -1
  215. package/dist/rows.js +25 -11
  216. package/dist/run-tables.d.ts +25 -0
  217. package/dist/run-tables.d.ts.map +1 -0
  218. package/dist/run-tables.js +98 -0
  219. package/dist/running.d.ts +5 -0
  220. package/dist/running.d.ts.map +1 -0
  221. package/dist/running.js +10 -0
  222. package/dist/runs.d.ts +27 -0
  223. package/dist/runs.d.ts.map +1 -0
  224. package/dist/runs.js +92 -0
  225. package/dist/runtime.d.ts +11 -5
  226. package/dist/runtime.d.ts.map +1 -1
  227. package/dist/save.d.ts +2 -0
  228. package/dist/save.d.ts.map +1 -1
  229. package/dist/save.js +120 -135
  230. package/dist/saves.d.ts +7 -5
  231. package/dist/saves.d.ts.map +1 -1
  232. package/dist/saves.js +116 -65
  233. package/dist/seed.d.ts.map +1 -1
  234. package/dist/seed.js +4 -4
  235. package/dist/selector.d.ts +3 -0
  236. package/dist/selector.d.ts.map +1 -0
  237. package/dist/selector.js +22 -0
  238. package/dist/shown.d.ts +8 -5
  239. package/dist/shown.d.ts.map +1 -1
  240. package/dist/shown.js +95 -67
  241. package/dist/socket/lanes.d.ts +12 -4
  242. package/dist/socket/lanes.d.ts.map +1 -1
  243. package/dist/socket/lanes.js +34 -8
  244. package/dist/socket/session.d.ts +4 -1
  245. package/dist/socket/session.d.ts.map +1 -1
  246. package/dist/socket/session.js +3 -0
  247. package/dist/socket.d.ts +9 -6
  248. package/dist/socket.d.ts.map +1 -1
  249. package/dist/socket.js +17 -16
  250. package/dist/source.d.ts +42 -7
  251. package/dist/source.d.ts.map +1 -1
  252. package/dist/source.js +76 -9
  253. package/dist/store/installs.d.ts +2 -2
  254. package/dist/store/installs.d.ts.map +1 -1
  255. package/dist/store/installs.js +10 -4
  256. package/dist/store/readiness.d.ts +5 -4
  257. package/dist/store/readiness.d.ts.map +1 -1
  258. package/dist/store/readiness.js +28 -12
  259. package/dist/store/records.d.ts +31 -7
  260. package/dist/store/records.d.ts.map +1 -1
  261. package/dist/store/records.js +70 -24
  262. package/dist/store/rooms-shown.d.ts +8 -0
  263. package/dist/store/rooms-shown.d.ts.map +1 -0
  264. package/dist/store/rooms-shown.js +13 -0
  265. package/dist/store.d.ts +24 -14
  266. package/dist/store.d.ts.map +1 -1
  267. package/dist/store.js +49 -17
  268. package/dist/stored.d.ts +41 -16
  269. package/dist/stored.d.ts.map +1 -1
  270. package/dist/stored.js +215 -57
  271. package/dist/surface.d.ts +20 -8
  272. package/dist/surface.d.ts.map +1 -1
  273. package/dist/surface.js +66 -32
  274. package/dist/sync.d.ts +4 -2
  275. package/dist/sync.d.ts.map +1 -1
  276. package/dist/sync.js +109 -82
  277. package/dist/tables.d.ts +40 -52
  278. package/dist/tables.d.ts.map +1 -1
  279. package/dist/tables.js +109 -326
  280. package/dist/tallies.d.ts.map +1 -1
  281. package/dist/tallies.js +3 -4
  282. package/dist/validation.d.ts +2 -0
  283. package/dist/validation.d.ts.map +1 -1
  284. package/dist/validation.js +50 -10
  285. package/dist/wire.d.ts +68 -8
  286. package/dist/wire.d.ts.map +1 -1
  287. package/dist/wire.js +28 -11
  288. package/package.json +4 -4
  289. package/dist/attempt.d.ts +0 -16
  290. package/dist/attempt.d.ts.map +0 -1
  291. package/dist/attempt.js +0 -70
  292. package/dist/binary.d.ts.map +0 -1
  293. package/dist/binary.js +0 -8
  294. package/dist/job.d.ts +0 -5
  295. package/dist/job.d.ts.map +0 -1
  296. package/dist/job.js +0 -7
  297. package/dist/log.d.ts +0 -6
  298. package/dist/log.d.ts.map +0 -1
  299. package/dist/log.js +0 -14
  300. package/dist/socket/rooms.d.ts +0 -41
  301. package/dist/socket/rooms.d.ts.map +0 -1
  302. package/dist/socket/rooms.js +0 -90
  303. package/dist/store/fences.d.ts +0 -16
  304. package/dist/store/fences.d.ts.map +0 -1
  305. package/dist/store/fences.js +0 -26
package/dist/sync.js CHANGED
@@ -1,22 +1,26 @@
1
1
  import { resendCalls, resendLater } from './actions.js';
2
- import { catchUpConversations, reconcileConversations, resendConversations, } from './conversation.js';
2
+ import { catchUpConversations, reconcileOpening, resendConversations } from './conversation.js';
3
3
  import { declared, sameDeclaration } from './declaration.js';
4
- import { applyDiscovery, discoverRooms, malformed, signIn } from './discovery.js';
4
+ import { applyDiscovery, discoverRooms, DISCOVERY, malformed, signIn, zoned } from './discovery.js';
5
5
  import { behind, caughtUpTo, publish, pullBootstrap, pullRefresh, reachedBy, replaced, standingAt, } from './install.js';
6
- import { heldRooms, listHeld, name, readable } from './listing.js';
6
+ import { heldRooms, name } from './listing.js';
7
7
  import { retainModel, revoked, scoped } from './models.js';
8
+ import { refusalError } from './failure.js';
8
9
  import { refuse } from './refusal.js';
10
+ import { roomListChanged } from './room-list.js';
9
11
  import { emitRooms, moveTo, rest, roomUnreadable, submissionDue, transferring, AUTHORITY_TOPIC, } from './shown.js';
10
12
  import { unconfirmed } from './transfer.js';
11
13
  export const OPENING_LANE = 'opening';
14
+ const FINISHING = 'finishing';
12
15
  async function advance(runtime, room, local, authorized, running, unheld) {
13
- const { store, socket } = runtime;
16
+ const { store, socket, presence } = runtime;
14
17
  const live = () => running() && !store.space.full();
15
18
  if (!live())
16
19
  return unconfirmed;
17
20
  const held = unheld === undefined ? await store.record(room.locator) : undefined;
18
21
  if (socket.streamed && (held !== undefined || !store.installs.of(room.locator).beyondHorizon)) {
19
- socket.rooms.stand(room.locator, { stale: false });
22
+ presence.stood(room.locator, false);
23
+ runtime.retries.succeeded('download', room.locator);
20
24
  await name(runtime, room.locator);
21
25
  return null;
22
26
  }
@@ -27,7 +31,7 @@ async function advance(runtime, room, local, authorized, running, unheld) {
27
31
  return advance(runtime, room, local, authorized, live);
28
32
  if (refreshed !== 'beyond-horizon')
29
33
  return refreshed;
30
- if (socket.rooms.standing(room.locator).reloadDue)
34
+ if (presence.standing(room.locator).reloadDue)
31
35
  return unconfirmed;
32
36
  replaced(store, [room.locator]);
33
37
  }
@@ -45,18 +49,15 @@ async function advance(runtime, room, local, authorized, running, unheld) {
45
49
  : advance(runtime, room, local, authorized, live);
46
50
  }
47
51
  async function refreshedRoom(runtime, room, local, authorized, held, live, hold, refresh) {
48
- const { store, socket } = runtime;
49
- const { rooms } = socket;
52
+ const { store, socket, presence } = runtime;
50
53
  const refreshed = await pullRefresh(runtime, authorized, held, live, hold, refresh);
51
54
  if (!live())
52
55
  return unconfirmed;
53
56
  if (refreshed.kind === 'still-current') {
54
- rooms.stand(room.locator, { stale: false });
55
- if (rooms.standing(room.locator).unreadable) {
56
- rooms.stand(room.locator, { refusal: null });
57
- readable(runtime, room);
58
- emitRooms(runtime);
59
- }
57
+ presence.stood(room.locator, false);
58
+ runtime.retries.succeeded('download', room.locator);
59
+ if (presence.readable(room.locator))
60
+ emitRooms(runtime, [room.locator]);
60
61
  return null;
61
62
  }
62
63
  if (refreshed.kind === 'advanced') {
@@ -79,43 +80,44 @@ export function advanced(runtime, room, local, authorized) {
79
80
  return runtime.socket.lanes.inRoom(room.locator, (live) => advance(runtime, room, local, authorized, live));
80
81
  }
81
82
  export async function withhold(runtime, withheld, room, local, progress) {
82
- const { store, socket, journal } = runtime;
83
- const { rooms } = socket;
84
- if (withheld.kind === 'unconfirmed' || store.fences.has(room.locator))
83
+ const { presence } = runtime;
84
+ if (withheld.kind === 'unconfirmed' || presence.lost(room.locator))
85
85
  return;
86
86
  if (withheld.kind === 'not-ready') {
87
87
  progress.complete = false;
88
88
  askAgain(runtime, room.locator);
89
89
  return;
90
90
  }
91
- rooms.stand(room.locator, { stale: true });
91
+ if (withheld.kind === 'transport-uncertainty') {
92
+ runtime.retries.uncertain('download', room.locator, withheld);
93
+ }
94
+ else if (withheld.kind === 'retryable-refusal') {
95
+ runtime.retries.failed('download', room.locator, refusalError(withheld));
96
+ }
92
97
  if (withheld.kind === 'transport-uncertainty' || withheld.kind === 'retryable-refusal') {
93
98
  const reset = withheld.kind === 'retryable-refusal' ? withheld.reset : undefined;
94
- rooms.stand(room.locator, { repairable: { reset } });
99
+ presence.stood(room.locator, true, { reset });
95
100
  repairLater(runtime, room.locator, reset === undefined ? { again: true } : { at: Date.parse(reset) });
96
101
  }
97
102
  else
98
- rooms.stand(room.locator, { repairable: null });
103
+ presence.stood(room.locator, true, null);
99
104
  if (withheld.kind === 'scoped-refusal') {
100
105
  await scoped(runtime, withheld, room.locator, declared(room));
101
106
  }
102
107
  else if (withheld.kind === 'transport-uncertainty') {
103
108
  progress.reachable = false;
104
109
  }
105
- else if (withheld.kind === 'retryable-refusal') {
106
- journal.record(`refusal ${withheld.kind} ${withheld.code}`);
107
- }
108
110
  else if (withheld.kind === 'room-not-readable') {
109
- roomUnreadable(runtime, room);
111
+ roomUnreadable(runtime, room.locator);
110
112
  }
111
113
  else if (withheld.kind === 'revoked-authorization') {
112
114
  await refuse(runtime, 'revoked-authorization');
113
115
  }
114
116
  }
115
117
  function askAgain(runtime, locator) {
116
- const { store, socket } = runtime;
117
- socket.rooms.askAgain(locator, () => {
118
- const room = socket.rooms.discovered(locator);
118
+ const { store, socket, presence } = runtime;
119
+ presence.askAgain(locator, () => {
120
+ const room = presence.room(locator);
119
121
  if (socket.closed() ||
120
122
  socket.stopping() ||
121
123
  (socket.streamed && !socket.isOpen()) ||
@@ -129,16 +131,14 @@ function askAgain(runtime, locator) {
129
131
  });
130
132
  }
131
133
  async function prepareRoom(runtime, room, progress, prior) {
132
- const { socket, journal } = runtime;
134
+ const { socket } = runtime;
133
135
  const { session } = socket;
134
136
  if (socket.closed() || session.now().authorization === undefined) {
135
137
  progress.complete = false;
136
138
  return false;
137
139
  }
138
140
  if (prior !== undefined && prior.declaration.replica.selection !== room.replica.selection) {
139
- listHeld(runtime, room.locator);
140
- emitRooms(runtime);
141
- journal.record(`selection changed ${room.locator}`);
141
+ emitRooms(runtime, [room.locator]);
142
142
  progress.complete = false;
143
143
  return false;
144
144
  }
@@ -151,8 +151,14 @@ async function prepareRoom(runtime, room, progress, prior) {
151
151
  return false;
152
152
  return room.replica.admission === 'admitted';
153
153
  }
154
- async function synchronize(runtime, listed, local, progress, attempt, live) {
154
+ async function synchronize(runtime, listed, progress, attempt, live) {
155
155
  const { store, socket } = runtime;
156
+ if (listed.length === 0) {
157
+ if (attempt === 'opened')
158
+ socket.hand([]);
159
+ return;
160
+ }
161
+ const local = await store.open();
156
162
  const heldNow = await store.rooms(listed.map(({ locator }) => locator));
157
163
  const prepared = await Promise.allSettled(listed.map((room) => prepareRoom(runtime, room, progress, heldNow.get(room.locator)?.record)));
158
164
  if (!live())
@@ -217,10 +223,10 @@ export async function loadRoom(runtime, room, local, progress, live, unheld) {
217
223
  await caughtUp(runtime, room, local, progress, live);
218
224
  }
219
225
  export async function reload(runtime, room, local, progress, live) {
220
- const { store, socket } = runtime;
226
+ const { store, socket, presence } = runtime;
221
227
  try {
222
228
  if (live())
223
- socket.rooms.stand(room.locator, { reloadDue: false });
229
+ presence.reload(room.locator, false);
224
230
  const { authorization } = socket.session.now();
225
231
  if (!live() || authorization === undefined)
226
232
  return;
@@ -240,24 +246,23 @@ export async function reload(runtime, room, local, progress, live) {
240
246
  }
241
247
  }
242
248
  function repairLater(runtime, locator, when) {
243
- const { socket, recovery } = runtime;
244
- if (!socket.isOpen() || socket.rooms.standing(locator).repairing)
249
+ const { socket, presence, recovery } = runtime;
250
+ if (!socket.isOpen() || presence.standing(locator).repairing)
245
251
  return;
246
252
  void recovery.attempt(`repair ${locator}`, (signal) => repairPass(runtime, locator, signal), when);
247
253
  }
248
254
  async function repairPass(runtime, locator, signal) {
249
- const { store, socket } = runtime;
250
- const { rooms } = socket;
251
- const room = rooms.discovered(locator);
255
+ const { store, socket, presence } = runtime;
256
+ const room = presence.room(locator);
252
257
  if (!socket.isOpen() ||
253
258
  !socket.continuing() ||
254
259
  socket.stopping() ||
255
- !rooms.standing(locator).stale)
260
+ !presence.standing(locator).stale)
256
261
  return 'done';
257
262
  if (room === undefined || room.replica.admission !== 'admitted')
258
263
  return 'done';
259
264
  const progress = { complete: true, reachable: true };
260
- rooms.stand(locator, { repairing: true });
265
+ presence.repairing(locator, true);
261
266
  try {
262
267
  const local = await store.open();
263
268
  await socket.lanes.roomTask(locator, async (live) => {
@@ -270,49 +275,52 @@ async function repairPass(runtime, locator, signal) {
270
275
  });
271
276
  }
272
277
  catch {
273
- rooms.stand(locator, { stale: true });
278
+ presence.stood(locator, true);
274
279
  progress.reachable = false;
275
280
  }
276
281
  finally {
277
- rooms.stand(locator, { repairing: false });
282
+ presence.repairing(locator, false);
278
283
  }
279
284
  if (signal.aborted)
280
285
  return 'done';
281
286
  await rest(runtime, progress);
282
- if (!rooms.standing(locator).stale) {
287
+ if (!presence.standing(locator).stale) {
283
288
  await submissionDue(runtime, [locator]);
284
289
  return 'done';
285
290
  }
286
- const { repairable } = rooms.standing(locator);
291
+ const { repairable } = presence.standing(locator);
287
292
  if (repairable === null)
288
293
  return 'done';
289
294
  return repairable.reset === undefined ? 'again' : { at: Date.parse(repairable.reset) };
290
295
  }
291
296
  export async function finishOpening(runtime, progress, live) {
292
- const { socket, conversations, recovery } = runtime;
297
+ const { store, socket, presence, conversations, recovery } = runtime;
293
298
  try {
294
299
  if (!live()) {
295
300
  progress.complete = false;
296
301
  return;
297
302
  }
303
+ const kept = store.needed();
298
304
  await submissionDue(runtime);
299
- for (const locator of socket.rooms.standingWhere(({ stale, repairable }) => stale && repairable !== null)) {
305
+ for (const locator of presence.repairsOwed())
300
306
  repairLater(runtime, locator, {});
301
- }
302
- await reconcileConversations(conversations);
307
+ await reconcileOpening(conversations);
303
308
  const reading = { complete: true, reachable: true };
304
309
  await catchUpConversations(conversations, reading);
305
- if (progress.reachable && reading.reachable)
310
+ if (kept && progress.reachable && reading.reachable) {
306
311
  await resendConversations(conversations, reading);
307
- if (progress.reachable) {
312
+ }
313
+ if (kept && progress.reachable) {
308
314
  void recovery.attempt('calls', (signal) => resendCalls(runtime, signal));
309
315
  }
310
316
  if (!reading.reachable) {
311
317
  progress.reachable = false;
312
318
  resendLater(runtime);
313
319
  }
320
+ runtime.retries.succeeded('conversations', FINISHING);
314
321
  }
315
- catch {
322
+ catch (error) {
323
+ runtime.retries.failed('conversations', FINISHING, error);
316
324
  progress.complete = false;
317
325
  }
318
326
  finally {
@@ -322,14 +330,17 @@ export async function finishOpening(runtime, progress, live) {
322
330
  }
323
331
  }
324
332
  }
325
- export function sync(runtime, attempt, found) {
326
- const { store, socket } = runtime;
333
+ export async function sync(runtime, attempt, found, current = () => true) {
334
+ const { socket } = runtime;
327
335
  const { session } = socket;
328
- return socket.lanes.task(OPENING_LANE, async (live) => {
336
+ let answered = true;
337
+ await socket.lanes.task(OPENING_LANE, async (live) => {
329
338
  if (!live()) {
330
339
  socket.readyFromStore();
331
340
  return;
332
341
  }
342
+ if (!current())
343
+ return;
333
344
  const progress = { complete: true, reachable: true };
334
345
  session.set({
335
346
  underway: attempt === 'opened' ? progress : null,
@@ -339,17 +350,17 @@ export function sync(runtime, attempt, found) {
339
350
  });
340
351
  moveTo(runtime, transferring(runtime));
341
352
  try {
342
- const local = await store.open();
343
- if (!live())
344
- return;
345
353
  await socket.authorize();
346
354
  if (!live())
347
355
  return;
348
- const listed = await discoverRooms(runtime, local, progress, live, found);
356
+ const listed = await discoverRooms(runtime, progress, live, found);
357
+ answered = progress.reachable;
349
358
  if (listed !== null)
350
- await synchronize(runtime, listed, local, progress, attempt, live);
359
+ await synchronize(runtime, listed, progress, attempt, live);
360
+ runtime.retries.succeeded('connection', OPENING_LANE);
351
361
  }
352
- catch {
362
+ catch (error) {
363
+ runtime.retries.failed('connection', OPENING_LANE, error);
353
364
  progress.complete = false;
354
365
  if (attempt === 'opened' && !socket.isHanded())
355
366
  progress.reachable = false;
@@ -368,40 +379,52 @@ export function sync(runtime, attempt, found) {
368
379
  session.set({ underway: null });
369
380
  await rest(runtime, progress, live);
370
381
  });
382
+ return answered;
383
+ }
384
+ export async function discover(runtime) {
385
+ const { recovery } = runtime;
386
+ if (await sync(runtime, 'unstreamed', null)) {
387
+ recovery.cancel(DISCOVERY);
388
+ return;
389
+ }
390
+ void recovery.attempt(DISCOVERY, async () => ((await sync(runtime, 'unstreamed', null)) ? 'done' : 'again'), { again: true, attempts: Infinity });
391
+ }
392
+ export function adopt(runtime, unstored) {
393
+ const { session } = runtime.socket;
394
+ return sync(runtime, 'unstreamed', unstored, () => session.now().unstored === unstored).then(() => undefined);
371
395
  }
372
396
  export function resynchronize(runtime) {
373
- const { store, socket } = runtime;
397
+ const { socket, presence } = runtime;
374
398
  return socket.lanes.task(OPENING_LANE, async (live) => {
375
399
  if (!live() || !socket.isAnnounced())
376
400
  return;
377
401
  const progress = { complete: true, reachable: true };
378
402
  moveTo(runtime, transferring(runtime));
379
403
  try {
380
- const local = await store.open();
381
- if (!live())
382
- return;
383
- await synchronize(runtime, socket.rooms.discoveredRooms(), local, progress, 'unstreamed', live);
404
+ await synchronize(runtime, presence.rooms(), progress, 'unstreamed', live);
405
+ runtime.retries.succeeded('download', OPENING_LANE);
384
406
  }
385
- catch {
407
+ catch (error) {
408
+ runtime.retries.failed('download', OPENING_LANE, error);
386
409
  progress.complete = false;
387
410
  }
388
411
  if (live())
389
412
  await finishOpening(runtime, progress, live);
390
413
  });
391
414
  }
392
- export function countAuthorityChange({ store, socket, lastAnswers }) {
415
+ export function countAuthorityChange({ store, socket, lastAnswers }, listed) {
393
416
  const authorityChanges = socket.session.now().authorityChanges + 1;
394
417
  socket.session.set({ authorityChanges });
395
418
  store.tell(AUTHORITY_TOPIC, authorityChanges);
396
- lastAnswers.again();
419
+ lastAnswers.again(listed);
397
420
  }
398
421
  export function changeAuthority(runtime, change) {
399
- const { store, socket, journal } = runtime;
422
+ const { store, socket } = runtime;
400
423
  const { session } = socket;
401
424
  return socket.lanes.task(OPENING_LANE, async (live) => {
402
425
  if (!live() || !socket.isAnnounced())
403
426
  return;
404
- countAuthorityChange(runtime);
427
+ countAuthorityChange(runtime, roomListChanged(runtime, change.roomList));
405
428
  const progress = { complete: true, reachable: true };
406
429
  moveTo(runtime, transferring(runtime));
407
430
  try {
@@ -410,18 +433,21 @@ export function changeAuthority(runtime, change) {
410
433
  return;
411
434
  const invalid = malformed(change.rooms);
412
435
  if (invalid !== null) {
413
- journal.record(invalid);
414
436
  await refuse(runtime, 'missing-required-guarantee');
415
437
  return;
416
438
  }
417
439
  if (change.member !== undefined)
418
440
  await signIn(runtime, local, change.member);
441
+ if (change.timeZone !== undefined)
442
+ await zoned(runtime, local, change.timeZone);
419
443
  const discoveries = session.now().discoveries + 1;
420
444
  session.set({ discoveries });
421
445
  const listed = await applyDiscovery(runtime, change.rooms, discoveries, change.left);
422
- await synchronize(runtime, listed, local, progress, 'authorized', live);
446
+ await synchronize(runtime, listed, progress, 'authorized', live);
447
+ runtime.retries.succeeded('connection', OPENING_LANE);
423
448
  }
424
- catch {
449
+ catch (error) {
450
+ runtime.retries.failed('connection', OPENING_LANE, error);
425
451
  progress.complete = false;
426
452
  }
427
453
  if (!live())
@@ -452,7 +478,7 @@ async function installCarried(runtime, room, local, change, live, progress) {
452
478
  ...(page.fileIds === undefined ? {} : { fileIds: page.fileIds }),
453
479
  ...(page.created === undefined ? {} : { created: page.created }),
454
480
  changes: page.changes,
455
- binaryFiles: page.binaryFiles,
481
+ attachments: page.attachments,
456
482
  ...(page.folders === undefined ? {} : { folders: page.folders }),
457
483
  }),
458
484
  reached: socket.reads.reached,
@@ -466,8 +492,8 @@ async function installCarried(runtime, room, local, change, live, progress) {
466
492
  await publish(runtime, local, room, bootstrapped.record, { kind: 'bootstrapped', refreshed: bootstrapped.refreshed, from }, live);
467
493
  }
468
494
  export function applyRoom(runtime, change) {
469
- const { store, socket } = runtime;
470
- const { rooms, session } = socket;
495
+ const { store, socket, presence } = runtime;
496
+ const { session } = socket;
471
497
  const { locator } = change;
472
498
  if (socket.stopping())
473
499
  return Promise.resolve();
@@ -480,7 +506,7 @@ export function applyRoom(runtime, change) {
480
506
  for (;;) {
481
507
  if (!live())
482
508
  return null;
483
- const room = rooms.discovered(locator);
509
+ const room = presence.room(locator);
484
510
  if (room === undefined || room.replica.admission !== 'admitted')
485
511
  return null;
486
512
  const held = await store.record(locator);
@@ -511,7 +537,7 @@ export function applyRoom(runtime, change) {
511
537
  remodelled: refreshed.remodelled,
512
538
  };
513
539
  if (await publish(runtime, local, room, refreshed.record, landing, writing)) {
514
- rooms.stand(locator, { stale: false });
540
+ presence.stood(locator, false);
515
541
  const declaration = declared(room);
516
542
  if (!sameDeclaration(held.declaration, declaration))
517
543
  await retainModel(runtime, locator, declaration, null);
@@ -519,10 +545,11 @@ export function applyRoom(runtime, change) {
519
545
  }
520
546
  }
521
547
  }
522
- catch {
523
- if (!rooms.standing(locator).stale)
548
+ catch (error) {
549
+ runtime.retries.failed('download', locator, error);
550
+ if (!presence.standing(locator).stale)
524
551
  void name(runtime, locator);
525
- rooms.stand(locator, { stale: true });
552
+ presence.stood(locator, true);
526
553
  return progress;
527
554
  }
528
555
  })
package/dist/tables.d.ts CHANGED
@@ -1,14 +1,18 @@
1
1
  import { type QueryAnswer, type QueryRoom } from './compile.js';
2
2
  import type { Composed } from './collection.js';
3
+ import { type AuthoredFact, type AuthoredWrite, type HeldQueues, type KeptRecord, type StoredFile } from './authored.js';
3
4
  import type { UnsentWork } from './durability.js';
4
- import { type ConversationWrite, type HeldConversation, type HeldRow, type MessageWindow } from './messages.js';
5
+ import { type ConversationWrite, type HeldConversation, type HeldFact, type HeldRow, type MessageWindow } from './messages.js';
5
6
  import type { GroupTotal, Plan } from './query.js';
7
+ import type { RunEvent, RunMarks } from './adapter.js';
8
+ import { type HeldRun, type RunsAsked, type RunSight } from './run-tables.js';
6
9
  import { type ReadAt } from './reads.js';
7
10
  import { type ConversationTally, type RoomTally } from './tallies.js';
8
- import { type Committed, type Covering, type HeldEntry, type HeldLocators, type HeldRoomRow, type HeldRoomWork, type ReplicaOpened, type Referrer, type Resumed, type RoomCommit, type StoredEntry, type TypedEntry, type View } from './stored.js';
9
- export type { Committed, Covering, HeldEntry, HeldLocators, HeldRoomRow, HeldRoomWork, OverlayEntry, ReplicaOpened, Referrer, Resumed, RoomCommit, StoredEntry, TypedEntry, View, } from './stored.js';
11
+ import { type Committed, type CoverLog, type Covering, type HeldEntry, type HeldLocators, type HeldRoomRow, type HeldRoomWork, type Holder, type ReplicaOpened, type Referrer, type Resumed, type RoomCommit, type Sought, type StoredEntry, type TypedEntry, type View } from './stored.js';
12
+ export type { Committed, CoverLog, Covering, HeldEntry, HeldLocators, HeldRoomRow, HeldRoomWork, Holder, OverlayEntry, ReplicaOpened, Referrer, Resumed, RoomCommit, Sought, StoredEntry, TypedEntry, View, } from './stored.js';
13
+ export { authoredEmptied, authoredTable, FILE_PART_BYTES, formatted, heldTables, type AuthoredFact, type AuthoredRows, type KeptRecord, type StoredFile, } from './authored.js';
10
14
  export type { QueryAnswer, QueryRoom } from './compile.js';
11
- export type { ConversationWrite, HeldConversation, HeldRow, MessageWindow } from './messages.js';
15
+ export type { ConversationFact, ConversationWrite, HeldConversation, HeldFact, HeldRow, MessageWindow, } from './messages.js';
12
16
  export type { ConversationTally, RoomTally } from './tallies.js';
13
17
  export type Value = string | number | bigint | Uint8Array | null;
14
18
  export type Row = Readonly<Record<string, Value>>;
@@ -50,53 +54,13 @@ export interface SqliteDatabase {
50
54
  prepare(sql: string): SqliteStatement;
51
55
  }
52
56
  export declare function sqliteConnection(engine: SqliteEngine, database: SqliteDatabase): Connection;
53
- export declare const FILE_PART_BYTES = 1048576;
54
57
  export declare const RUNTIME_TABLES: readonly string[];
55
- export type AuthoredFact = 'holder' | 'generation';
56
- export type StoredFile = {
57
- readonly key: string;
58
- readonly blob: Blob;
59
- };
60
58
  export interface FileSpool {
61
59
  held(): Iterable<string>;
62
60
  spool(key: string, type: string, parts: Iterable<Uint8Array>): Promise<Blob>;
63
61
  drop(key: string): Promise<void>;
64
62
  probe(bytes: number): Promise<void>;
65
63
  }
66
- export type KeptPending = {
67
- readonly id: string;
68
- readonly batch: string;
69
- readonly state: string;
70
- readonly files: readonly string[];
71
- readonly paths: readonly string[];
72
- readonly moving: boolean;
73
- };
74
- export type KeptRecord = {
75
- readonly record: string;
76
- readonly files: readonly string[];
77
- };
78
- export type AuthoredRows = {
79
- readonly locator: string;
80
- readonly order?: readonly string[];
81
- readonly added?: readonly KeptPending[];
82
- readonly founded?: readonly Omit<KeptPending, 'state'>[];
83
- readonly roomDrafts?: readonly (KeptRecord & {
84
- readonly path: string;
85
- })[];
86
- readonly consumedRoomDrafts?: readonly string[];
87
- };
88
- export type HeldQueues = {
89
- readonly queues: readonly {
90
- readonly locator: string;
91
- readonly ids: readonly string[];
92
- }[];
93
- readonly pending: readonly {
94
- readonly locator: string;
95
- readonly id: string;
96
- readonly batch: string;
97
- readonly state: string;
98
- }[];
99
- };
100
64
  export type HeldStatus = {
101
65
  readonly queued: readonly string[];
102
66
  readonly lastCompleted: string | null;
@@ -130,11 +94,6 @@ type Nothing = Readonly<Record<never, never>>;
130
94
  export type CommittedWrite = Committed & {
131
95
  readonly fenced: string | null;
132
96
  };
133
- export type AuthoredWrite = {
134
- readonly writes: readonly AuthoredRows[];
135
- readonly files: readonly StoredFile[];
136
- readonly whole: boolean;
137
- };
138
97
  export interface RuntimeRequests {
139
98
  readonly 'authored.status': Asked<Nothing, HeldStatus>;
140
99
  readonly 'authored.moving': Asked<Nothing, HeldQueues>;
@@ -211,21 +170,31 @@ export interface RuntimeRequests {
211
170
  readonly 'replica.room': Asked<{
212
171
  readonly locator: string;
213
172
  }, HeldRoomWork>;
214
- readonly 'replica.covering': Asked<Nothing, Covering>;
173
+ readonly 'replica.covering': Asked<{
174
+ readonly since: CoverLog | null;
175
+ }, Covering>;
215
176
  readonly 'replica.offline': Asked<{
216
177
  readonly locator: string;
217
178
  }, string | null>;
218
179
  readonly 'replica.held': Asked<Nothing, HeldLocators>;
219
180
  readonly 'replica.demote': Asked<Nothing, null>;
220
- readonly 'replica.facts': Asked<Nothing, Readonly<Record<string, string>>>;
181
+ readonly 'replica.facts': Asked<{
182
+ readonly names: readonly string[] | null;
183
+ }, Readonly<Record<string, string>>>;
221
184
  readonly 'replica.presentation': Asked<{
222
185
  readonly app: string;
223
186
  }, string | null>;
224
187
  readonly 'replica.query': Asked<{
225
188
  readonly plan: Plan;
226
189
  readonly rooms: readonly QueryRoom[];
190
+ readonly follows: readonly QueryRoom[];
227
191
  readonly budget: number | null;
228
192
  }, QueryAnswer>;
193
+ readonly 'replica.named': Asked<{
194
+ readonly plan: Plan;
195
+ readonly rooms: readonly QueryRoom[];
196
+ readonly handles: readonly string[];
197
+ }, readonly string[]>;
229
198
  readonly 'replica.tallies': Asked<{
230
199
  readonly totals: Plan;
231
200
  readonly rooms: readonly QueryRoom[];
@@ -246,6 +215,11 @@ export interface RuntimeRequests {
246
215
  readonly view: View;
247
216
  readonly targets: readonly string[];
248
217
  }, readonly Referrer[]>;
218
+ readonly 'replica.holders': Asked<{
219
+ readonly key: number;
220
+ readonly view: View;
221
+ readonly sought: readonly Sought[];
222
+ }, readonly Holder[]>;
249
223
  readonly 'replica.folders': Asked<{
250
224
  readonly key: number;
251
225
  readonly paths: readonly string[];
@@ -380,9 +354,12 @@ export interface RuntimeRequests {
380
354
  readonly conversations: readonly string[] | null;
381
355
  readonly since: string;
382
356
  }, readonly ConversationTally[]>;
357
+ readonly 'conversation.facts': Asked<Nothing, readonly HeldFact[]>;
358
+ readonly 'conversation.fact': Asked<HeldFact, null>;
359
+ readonly 'conversation.stored': Asked<Nothing, readonly string[]>;
383
360
  readonly 'conversation.drop': Asked<{
384
361
  readonly conversations: readonly string[];
385
- }, null>;
362
+ }, readonly string[]>;
386
363
  readonly 'space.probe': Asked<Nothing, null>;
387
364
  readonly 'read.stored': Asked<ReadAt, string | null>;
388
365
  readonly 'read.keep': Asked<ReadAt & {
@@ -391,6 +368,17 @@ export interface RuntimeRequests {
391
368
  readonly 'read.builds': Asked<{
392
369
  readonly build: string;
393
370
  }, null>;
371
+ readonly 'run.marks': Asked<Nothing, RunMarks>;
372
+ readonly 'run.held': Asked<{
373
+ readonly asked: RunsAsked;
374
+ readonly sight: RunSight;
375
+ }, readonly HeldRun[] | null>;
376
+ readonly 'run.keep': Asked<{
377
+ readonly event: RunEvent;
378
+ }, RunMarks | null>;
379
+ readonly 'run.left': Asked<{
380
+ readonly sight: RunSight;
381
+ }, RunMarks>;
394
382
  }
395
383
  export type RuntimeKind = keyof RuntimeRequests;
396
384
  export type RuntimeRequest<K extends RuntimeKind = RuntimeKind> = {