@agentshouse/mdruntime 0.1.0-cf281e8224a5d → 0.1.0-cf2e0e6e7cdce

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