@agentshouse/mdruntime 0.1.0-cba6f2439bb25 → 0.1.0-cbb9cd3aced1a

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 (338) hide show
  1. package/README.md +21 -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 +302 -0
  11. package/dist/adapter.d.ts +163 -109
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +3 -11
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +20 -60
  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/bootstrap.d.ts +12 -11
  20. package/dist/bootstrap.d.ts.map +1 -1
  21. package/dist/bootstrap.js +213 -89
  22. package/dist/cell.d.ts +6 -0
  23. package/dist/cell.d.ts.map +1 -0
  24. package/dist/cell.js +9 -0
  25. package/dist/chain.d.ts +2 -1
  26. package/dist/chain.d.ts.map +1 -1
  27. package/dist/change-set.d.ts +4 -0
  28. package/dist/change-set.d.ts.map +1 -1
  29. package/dist/change-set.js +6 -0
  30. package/dist/change.d.ts +5 -0
  31. package/dist/change.d.ts.map +1 -1
  32. package/dist/change.js +7 -2
  33. package/dist/chat-types.d.ts +3 -0
  34. package/dist/chat-types.d.ts.map +1 -0
  35. package/dist/chat-types.js +11 -0
  36. package/dist/client.d.ts +34 -23
  37. package/dist/client.d.ts.map +1 -1
  38. package/dist/client.js +44 -56
  39. package/dist/collection.d.ts +26 -7
  40. package/dist/collection.d.ts.map +1 -1
  41. package/dist/collection.js +20 -19
  42. package/dist/column.d.ts +5 -0
  43. package/dist/column.d.ts.map +1 -0
  44. package/dist/column.js +9 -0
  45. package/dist/compile.d.ts +8 -6
  46. package/dist/compile.d.ts.map +1 -1
  47. package/dist/compile.js +287 -335
  48. package/dist/connection.d.ts +5 -143
  49. package/dist/connection.d.ts.map +1 -1
  50. package/dist/connection.js +112 -5257
  51. package/dist/context.d.ts +2 -0
  52. package/dist/context.d.ts.map +1 -0
  53. package/dist/context.js +7 -0
  54. package/dist/conversation-live.d.ts +150 -0
  55. package/dist/conversation-live.d.ts.map +1 -0
  56. package/dist/conversation-live.js +259 -0
  57. package/dist/conversation-row.d.ts +40 -0
  58. package/dist/conversation-row.d.ts.map +1 -0
  59. package/dist/conversation-row.js +66 -0
  60. package/dist/conversation.d.ts +72 -51
  61. package/dist/conversation.d.ts.map +1 -1
  62. package/dist/conversation.js +1002 -925
  63. package/dist/declaration.d.ts +10 -0
  64. package/dist/declaration.d.ts.map +1 -0
  65. package/dist/declaration.js +24 -0
  66. package/dist/discovery.d.ts +11 -0
  67. package/dist/discovery.d.ts.map +1 -0
  68. package/dist/discovery.js +157 -0
  69. package/dist/download.d.ts +6 -0
  70. package/dist/download.d.ts.map +1 -0
  71. package/dist/download.js +42 -0
  72. package/dist/durability.d.ts +20 -1
  73. package/dist/durability.d.ts.map +1 -1
  74. package/dist/durability.js +7 -0
  75. package/dist/entry.d.ts +7 -2
  76. package/dist/entry.d.ts.map +1 -1
  77. package/dist/entry.js +38 -17
  78. package/dist/expectation.d.ts +26 -13
  79. package/dist/expectation.d.ts.map +1 -1
  80. package/dist/expectation.js +72 -19
  81. package/dist/failure.d.ts +3 -0
  82. package/dist/failure.d.ts.map +1 -1
  83. package/dist/failure.js +8 -0
  84. package/dist/figures.d.ts +49 -0
  85. package/dist/figures.d.ts.map +1 -0
  86. package/dist/figures.js +199 -0
  87. package/dist/file.d.ts +1 -1
  88. package/dist/file.d.ts.map +1 -1
  89. package/dist/file.js +3 -2
  90. package/dist/holdings.d.ts +29 -0
  91. package/dist/holdings.d.ts.map +1 -0
  92. package/dist/holdings.js +95 -0
  93. package/dist/host.d.ts +21 -8
  94. package/dist/host.d.ts.map +1 -1
  95. package/dist/host.js +88 -44
  96. package/dist/identity.d.ts +0 -1
  97. package/dist/identity.d.ts.map +1 -1
  98. package/dist/identity.js +0 -3
  99. package/dist/index.d.ts +38 -14
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +18 -5
  102. package/dist/install.d.ts +60 -0
  103. package/dist/install.d.ts.map +1 -0
  104. package/dist/install.js +537 -0
  105. package/dist/lifecycle.d.ts +7 -0
  106. package/dist/lifecycle.d.ts.map +1 -0
  107. package/dist/lifecycle.js +282 -0
  108. package/dist/listing.d.ts +52 -0
  109. package/dist/listing.d.ts.map +1 -0
  110. package/dist/listing.js +152 -0
  111. package/dist/live.d.ts +9 -6
  112. package/dist/live.d.ts.map +1 -1
  113. package/dist/live.js +118 -36
  114. package/dist/loaded.d.ts +5 -0
  115. package/dist/loaded.d.ts.map +1 -0
  116. package/dist/loaded.js +40 -0
  117. package/dist/locks.d.ts +7 -0
  118. package/dist/locks.d.ts.map +1 -0
  119. package/dist/locks.js +32 -0
  120. package/dist/lost.d.ts +5 -0
  121. package/dist/lost.d.ts.map +1 -0
  122. package/dist/lost.js +49 -0
  123. package/dist/media.d.ts +19 -2
  124. package/dist/media.d.ts.map +1 -1
  125. package/dist/media.js +119 -31
  126. package/dist/memory.d.ts +19 -6
  127. package/dist/memory.d.ts.map +1 -1
  128. package/dist/memory.js +255 -104
  129. package/dist/messages.d.ts +35 -5
  130. package/dist/messages.d.ts.map +1 -1
  131. package/dist/messages.js +109 -39
  132. package/dist/modal.d.ts +2 -0
  133. package/dist/modal.d.ts.map +1 -0
  134. package/dist/modal.js +11 -0
  135. package/dist/model.d.ts +2 -11
  136. package/dist/model.d.ts.map +1 -1
  137. package/dist/model.js +0 -23
  138. package/dist/models.d.ts +10 -0
  139. package/dist/models.d.ts.map +1 -0
  140. package/dist/models.js +153 -0
  141. package/dist/observation.d.ts +28 -13
  142. package/dist/observation.d.ts.map +1 -1
  143. package/dist/observation.js +185 -81
  144. package/dist/opened.d.ts +1 -1
  145. package/dist/opened.d.ts.map +1 -1
  146. package/dist/opened.js +5 -5
  147. package/dist/opening.d.ts +4 -0
  148. package/dist/opening.d.ts.map +1 -0
  149. package/dist/opening.js +53 -0
  150. package/dist/outcome.d.ts +17 -5
  151. package/dist/outcome.d.ts.map +1 -1
  152. package/dist/outcome.js +35 -2
  153. package/dist/overlay.d.ts +7 -2
  154. package/dist/overlay.d.ts.map +1 -1
  155. package/dist/overlay.js +48 -24
  156. package/dist/page-metadata.d.ts +8 -0
  157. package/dist/page-metadata.d.ts.map +1 -0
  158. package/dist/page-metadata.js +19 -0
  159. package/dist/parts.d.ts +4 -0
  160. package/dist/parts.d.ts.map +1 -0
  161. package/dist/parts.js +13 -0
  162. package/dist/paths.d.ts +1 -0
  163. package/dist/paths.d.ts.map +1 -1
  164. package/dist/paths.js +22 -0
  165. package/dist/preparation.d.ts +41 -0
  166. package/dist/preparation.d.ts.map +1 -0
  167. package/dist/preparation.js +314 -0
  168. package/dist/presence.d.ts +58 -0
  169. package/dist/presence.d.ts.map +1 -0
  170. package/dist/presence.js +231 -0
  171. package/dist/queries.d.ts +16 -0
  172. package/dist/queries.d.ts.map +1 -0
  173. package/dist/queries.js +308 -0
  174. package/dist/query.d.ts +14 -210
  175. package/dist/query.d.ts.map +1 -1
  176. package/dist/query.js +3 -505
  177. package/dist/questions.d.ts +30 -0
  178. package/dist/questions.d.ts.map +1 -0
  179. package/dist/questions.js +116 -0
  180. package/dist/queue.d.ts +40 -0
  181. package/dist/queue.d.ts.map +1 -0
  182. package/dist/queue.js +480 -0
  183. package/dist/reach.d.ts +16 -15
  184. package/dist/reach.d.ts.map +1 -1
  185. package/dist/reach.js +258 -149
  186. package/dist/react.d.ts +21 -3
  187. package/dist/react.d.ts.map +1 -1
  188. package/dist/react.js +33 -1
  189. package/dist/read.d.ts +7 -0
  190. package/dist/read.d.ts.map +1 -0
  191. package/dist/read.js +17 -0
  192. package/dist/readiness.d.ts +11 -19
  193. package/dist/readiness.d.ts.map +1 -1
  194. package/dist/readiness.js +7 -15
  195. package/dist/reads.d.ts +38 -10
  196. package/dist/reads.d.ts.map +1 -1
  197. package/dist/reads.js +164 -77
  198. package/dist/recovery.d.ts +3 -0
  199. package/dist/recovery.d.ts.map +1 -1
  200. package/dist/recovery.js +57 -1
  201. package/dist/refresh.d.ts +7 -5
  202. package/dist/refresh.d.ts.map +1 -1
  203. package/dist/refresh.js +35 -7
  204. package/dist/refusal.d.ts +5 -0
  205. package/dist/refusal.d.ts.map +1 -0
  206. package/dist/refusal.js +55 -0
  207. package/dist/replica.d.ts +11 -17
  208. package/dist/replica.d.ts.map +1 -1
  209. package/dist/replica.js +66 -36
  210. package/dist/retried.d.ts +30 -0
  211. package/dist/retried.d.ts.map +1 -0
  212. package/dist/retried.js +72 -0
  213. package/dist/room-draft.d.ts +34 -10
  214. package/dist/room-draft.d.ts.map +1 -1
  215. package/dist/room-draft.js +331 -111
  216. package/dist/room-drafts.d.ts +24 -0
  217. package/dist/room-drafts.d.ts.map +1 -0
  218. package/dist/room-drafts.js +220 -0
  219. package/dist/room-list.d.ts +10 -0
  220. package/dist/room-list.d.ts.map +1 -0
  221. package/dist/room-list.js +45 -0
  222. package/dist/rows.d.ts +16 -22
  223. package/dist/rows.d.ts.map +1 -1
  224. package/dist/rows.js +49 -186
  225. package/dist/runtime.d.ts +34 -0
  226. package/dist/runtime.d.ts.map +1 -0
  227. package/dist/runtime.js +1 -0
  228. package/dist/save.d.ts +42 -86
  229. package/dist/save.d.ts.map +1 -1
  230. package/dist/save.js +332 -228
  231. package/dist/saves.d.ts +34 -0
  232. package/dist/saves.d.ts.map +1 -0
  233. package/dist/saves.js +437 -0
  234. package/dist/search.d.ts +12 -63
  235. package/dist/search.d.ts.map +1 -1
  236. package/dist/search.js +9 -52
  237. package/dist/seed.d.ts +11 -2
  238. package/dist/seed.d.ts.map +1 -1
  239. package/dist/seed.js +71 -1
  240. package/dist/shared.d.ts +1 -7
  241. package/dist/shared.d.ts.map +1 -1
  242. package/dist/shared.js +13 -105
  243. package/dist/shown.d.ts +35 -0
  244. package/dist/shown.d.ts.map +1 -0
  245. package/dist/shown.js +313 -0
  246. package/dist/socket/admission.d.ts +7 -0
  247. package/dist/socket/admission.d.ts.map +1 -0
  248. package/dist/socket/admission.js +39 -0
  249. package/dist/socket/answers.d.ts +6 -0
  250. package/dist/socket/answers.d.ts.map +1 -0
  251. package/dist/socket/answers.js +20 -0
  252. package/dist/socket/lanes.d.ts +28 -0
  253. package/dist/socket/lanes.d.ts.map +1 -0
  254. package/dist/socket/lanes.js +103 -0
  255. package/dist/socket/reads.d.ts +10 -0
  256. package/dist/socket/reads.d.ts.map +1 -0
  257. package/dist/socket/reads.js +31 -0
  258. package/dist/socket/session.d.ts +38 -0
  259. package/dist/socket/session.d.ts.map +1 -0
  260. package/dist/socket/session.js +23 -0
  261. package/dist/socket.d.ts +67 -0
  262. package/dist/socket.d.ts.map +1 -0
  263. package/dist/socket.js +164 -0
  264. package/dist/source.d.ts +59 -0
  265. package/dist/source.d.ts.map +1 -0
  266. package/dist/source.js +93 -0
  267. package/dist/status.d.ts +0 -6
  268. package/dist/status.d.ts.map +1 -1
  269. package/dist/status.js +0 -6
  270. package/dist/store/installs.d.ts +30 -0
  271. package/dist/store/installs.d.ts.map +1 -0
  272. package/dist/store/installs.js +40 -0
  273. package/dist/store/readiness.d.ts +11 -0
  274. package/dist/store/readiness.d.ts.map +1 -0
  275. package/dist/store/readiness.js +68 -0
  276. package/dist/store/records.d.ts +224 -0
  277. package/dist/store/records.d.ts.map +1 -0
  278. package/dist/store/records.js +466 -0
  279. package/dist/store/room-held.d.ts +8 -0
  280. package/dist/store/room-held.d.ts.map +1 -0
  281. package/dist/store/room-held.js +17 -0
  282. package/dist/store/rooms-shown.d.ts +8 -0
  283. package/dist/store/rooms-shown.d.ts.map +1 -0
  284. package/dist/store/rooms-shown.js +13 -0
  285. package/dist/store/space.d.ts +11 -0
  286. package/dist/store/space.d.ts.map +1 -0
  287. package/dist/store/space.js +41 -0
  288. package/dist/store/watchers.d.ts +17 -0
  289. package/dist/store/watchers.d.ts.map +1 -0
  290. package/dist/store/watchers.js +56 -0
  291. package/dist/store/writes.d.ts +24 -0
  292. package/dist/store/writes.d.ts.map +1 -0
  293. package/dist/store/writes.js +125 -0
  294. package/dist/store.d.ts +115 -156
  295. package/dist/store.d.ts.map +1 -1
  296. package/dist/store.js +171 -394
  297. package/dist/stored.d.ts +72 -40
  298. package/dist/stored.d.ts.map +1 -1
  299. package/dist/stored.js +344 -212
  300. package/dist/surface.d.ts +92 -0
  301. package/dist/surface.d.ts.map +1 -0
  302. package/dist/surface.js +251 -0
  303. package/dist/sync.d.ts +19 -0
  304. package/dist/sync.d.ts.map +1 -0
  305. package/dist/sync.js +538 -0
  306. package/dist/tables.d.ts +118 -94
  307. package/dist/tables.d.ts.map +1 -1
  308. package/dist/tables.js +199 -321
  309. package/dist/tallies.d.ts +18 -0
  310. package/dist/tallies.d.ts.map +1 -0
  311. package/dist/tallies.js +128 -0
  312. package/dist/transfer.d.ts +0 -5
  313. package/dist/transfer.d.ts.map +1 -1
  314. package/dist/validation.d.ts +3 -4
  315. package/dist/validation.d.ts.map +1 -1
  316. package/dist/validation.js +42 -106
  317. package/dist/windows.d.ts +1 -12
  318. package/dist/windows.d.ts.map +1 -1
  319. package/dist/windows.js +2 -75
  320. package/dist/wire.d.ts +72 -9
  321. package/dist/wire.d.ts.map +1 -1
  322. package/dist/wire.js +26 -5
  323. package/package.json +3 -2
  324. package/dist/attempt.d.ts +0 -16
  325. package/dist/attempt.d.ts.map +0 -1
  326. package/dist/attempt.js +0 -70
  327. package/dist/fence.d.ts +0 -6
  328. package/dist/fence.d.ts.map +0 -1
  329. package/dist/fence.js +0 -10
  330. package/dist/fulltext.d.ts +0 -27
  331. package/dist/fulltext.d.ts.map +0 -1
  332. package/dist/fulltext.js +0 -370
  333. package/dist/log.d.ts +0 -5
  334. package/dist/log.d.ts.map +0 -1
  335. package/dist/log.js +0 -14
  336. package/dist/words.d.ts +0 -19
  337. package/dist/words.d.ts.map +0 -1
  338. package/dist/words.js +0 -156
package/dist/tables.js CHANGED
@@ -1,11 +1,20 @@
1
+ import { sql } from '@agentshouse/mdmodel';
1
2
  import { answerQuery } from './compile.js';
2
- import { searched, SEARCH_TABLES } from './fulltext.js';
3
- import { droppedMessages, forgottenMessages, heldConversations, keptMessages, messageCount, messageWindow, MESSAGE_TABLES, turnArrived, } from './messages.js';
4
- import { abandon, release, commit, counts, ended, entries, erase, fenceRooms, files, folders, opened, rederive, referrers, refreshing, REPLICA_TABLES, stage, typed, typedWithin, unrefresh, walk, } from './stored.js';
3
+ import { amended, authoredLocators, authoredPart, call, callRecords, chatDraft, chatDraftConversations, chatDraftRecord, chatDraftRecords, chatDraftsDropped, claim, fact, fenced, fencedWork, fences, FILE_PART_BYTES, authoredEmptied, heldOrder, kept, moving, pendingBatch, pendingState, queuedLocators, queueOf, queues, remember, roomDraft, roomDraftRecords, spooled, unfenced, unsent, unsentStatus, } from './authored.js';
4
+ import { count, text, texts } from './column.js';
5
+ import { conversationFacts, conversationRows, forgottenConversations, heldConversations, keptFact, keptMessages, messageCount, messageWindow, MESSAGE_TABLES, turnArrived, } from './messages.js';
6
+ import { keptRead, READ_TABLES, readsOfOtherBuildsForgotten, storedRead, } from './reads.js';
7
+ import { conversationTallies, roomTallies, } from './tallies.js';
8
+ import { abandon, release, commit, covering, demoted, ended, entries, erase, facts, fenceRooms, folders, heldLocators, heldRoom, heldRooms, offlineMode, opened, overlaid, presentation, rederive, referrers, refreshing, REPLICA_TABLES, resume, stage, typed, stagedLocators, tablesOf, typedWithin, unrefresh, } from './stored.js';
9
+ export { authoredEmptied, authoredTable, FILE_PART_BYTES, formatted, heldTables, } from './authored.js';
5
10
  const STATEMENTS_HELD = 256;
6
11
  export function sqliteConnection(engine, database) {
7
12
  const decoder = new TextDecoder();
8
13
  const held = new Map();
14
+ database.createFunction(sql.HOLDS_PHRASE, sql.holdsPhrase, {
15
+ arity: 2,
16
+ deterministic: true,
17
+ });
9
18
  function prepared(sql) {
10
19
  if (sql.includes(';'))
11
20
  return null;
@@ -65,62 +74,58 @@ export function sqliteConnection(engine, database) {
65
74
  },
66
75
  };
67
76
  }
68
- export const FILE_PART_BYTES = 1_048_576;
69
77
  const PROBE_BYTES = 4 * FILE_PART_BYTES;
70
- const TABLES = [
71
- ['authored_facts', 'name TEXT PRIMARY KEY, value TEXT NOT NULL'],
72
- ['authored_queues', 'locator TEXT PRIMARY KEY, ids TEXT NOT NULL'],
73
- [
74
- 'authored_pending',
75
- 'locator TEXT NOT NULL, id TEXT NOT NULL, batch TEXT NOT NULL, state TEXT NOT NULL, files TEXT NOT NULL, PRIMARY KEY (locator, id)',
76
- ],
77
- [
78
- 'authored_room_drafts',
79
- 'locator TEXT NOT NULL, path TEXT NOT NULL, record TEXT NOT NULL, files TEXT NOT NULL, PRIMARY KEY (locator, path)',
80
- ],
81
- ['authored_chat_drafts', 'conversation TEXT PRIMARY KEY, record TEXT NOT NULL'],
82
- ['authored_calls', 'operation TEXT PRIMARY KEY, record TEXT NOT NULL, files TEXT NOT NULL'],
83
- ['authored_fences', 'locator TEXT PRIMARY KEY'],
84
- ];
85
78
  export const RUNTIME_TABLES = [
86
- ...TABLES.map(([name, columns]) => `CREATE TABLE ${name} (${columns}) WITHOUT ROWID`),
87
- 'CREATE TABLE file_parts (key TEXT NOT NULL, part INTEGER NOT NULL, bytes BLOB NOT NULL, PRIMARY KEY (key, part))',
88
79
  'CREATE TABLE opened_files (key TEXT PRIMARY KEY, locator TEXT NOT NULL, path TEXT NOT NULL, revision TEXT NOT NULL, media_type TEXT NOT NULL, sha256 TEXT, byte_length INTEGER) WITHOUT ROWID',
89
80
  'CREATE INDEX opened_files_name ON opened_files (locator, path, revision)',
81
+ 'CREATE TABLE opened_parts (key TEXT NOT NULL, part INTEGER NOT NULL, bytes BLOB NOT NULL, PRIMARY KEY (key, part))',
90
82
  ...REPLICA_TABLES,
91
83
  ...MESSAGE_TABLES,
92
- ...SEARCH_TABLES,
84
+ ...READ_TABLES,
93
85
  ];
94
- const OWNERS = ['authored_pending', 'authored_room_drafts', 'authored_calls'];
95
- const AUTHORED_KEYS = OWNERS.map((table) => `SELECT value FROM ${table}, json_each(${table}.files)`).join(' UNION ');
96
- const UNOWNED_PARTS = `DELETE FROM file_parts WHERE key NOT IN (${AUTHORED_KEYS} UNION SELECT key FROM opened_files)`;
86
+ const UNOPENED_PARTS = 'DELETE FROM opened_parts WHERE key NOT IN (SELECT key FROM opened_files)';
97
87
  const READS = new Set([
98
- 'authored.queues',
88
+ 'authored.status',
89
+ 'authored.moving',
90
+ 'authored.pending',
91
+ 'authored.batch',
92
+ 'authored.order',
93
+ 'authored.queued',
99
94
  'authored.roomDrafts',
95
+ 'authored.chatDraft.read',
100
96
  'authored.chatDrafts',
101
97
  'authored.calls',
102
98
  'authored.fences',
99
+ 'authored.unsent',
103
100
  'authored.fact',
104
101
  'authored.file',
105
102
  'replica.open',
103
+ 'replica.rooms',
104
+ 'replica.room',
105
+ 'replica.covering',
106
+ 'replica.offline',
107
+ 'replica.held',
108
+ 'replica.facts',
109
+ 'replica.presentation',
106
110
  'replica.query',
111
+ 'replica.tallies',
107
112
  'replica.entries',
108
113
  'replica.typed',
109
114
  'replica.referrers',
110
- 'replica.walk',
111
- 'replica.files',
112
115
  'replica.folders',
113
116
  'replica.typedWithin',
114
- 'replica.counts',
115
- 'replica.search',
116
- 'replica.received',
117
- 'replica.receivedParts',
118
117
  'opened.find',
118
+ 'opened.held',
119
119
  'file.part',
120
120
  'conversation.held',
121
121
  'conversation.window',
122
122
  'conversation.count',
123
123
  'conversation.turn',
124
+ 'conversation.rows',
125
+ 'conversation.tallies',
126
+ 'conversation.facts',
127
+ 'conversation.stored',
128
+ 'read.stored',
124
129
  ]);
125
130
  const KINDS = new Set([
126
131
  ...READS,
@@ -132,26 +137,30 @@ const KINDS = new Set([
132
137
  'authored.claim',
133
138
  'authored.end',
134
139
  'replica.stage',
140
+ 'replica.resume',
135
141
  'replica.refresh',
136
142
  'replica.unrefresh',
137
143
  'replica.commit',
138
144
  'replica.fence',
139
145
  'replica.erase',
140
146
  'replica.abandon',
147
+ 'replica.unfence',
141
148
  'replica.release',
142
149
  'replica.rederive',
150
+ 'replica.demote',
143
151
  'replica.fact',
144
152
  'replica.present',
145
- 'replica.receive',
146
- 'replica.unreceive',
147
153
  'opened.begin',
148
154
  'opened.part',
149
155
  'opened.keep',
150
156
  'opened.drop',
151
157
  'opened.clean',
152
158
  'conversation.keep',
159
+ 'conversation.fact',
153
160
  'conversation.drop',
154
161
  'space.probe',
162
+ 'read.keep',
163
+ 'read.builds',
155
164
  ]);
156
165
  export function isRuntime(request) {
157
166
  return KINDS.has(request.kind);
@@ -159,239 +168,75 @@ export function isRuntime(request) {
159
168
  export function readsRuntime(request) {
160
169
  return READS.has(request.kind);
161
170
  }
162
- function text(value) {
163
- return typeof value === 'string' ? value : String(value);
164
- }
165
- function texts(rows, column) {
166
- return rows.map((row) => text(row[column]));
167
- }
168
- function owned(files) {
169
- return JSON.stringify([...new Set(files)]);
170
- }
171
- function fact(connection, name) {
172
- const [held] = connection.rows('SELECT value FROM authored_facts WHERE name = ?', [name]);
173
- return held === undefined ? null : text(held.value);
174
- }
175
- function remember(connection, name, value) {
176
- connection.run('INSERT OR REPLACE INTO authored_facts (name, value) VALUES (?, ?)', [
177
- name,
178
- value,
179
- ]);
180
- return null;
181
- }
182
- function fenced(connection, locator) {
183
- return connection.rows('SELECT 1 FROM authored_fences WHERE locator = ?', [locator]).length > 0;
184
- }
185
- function stored(connection, key) {
186
- return connection.rows('SELECT 1 FROM file_parts WHERE key = ? LIMIT 1', [key]).length > 0;
187
- }
188
- function storedPart(connection, key, part, bytes) {
189
- connection.run('INSERT INTO file_parts (key, part, bytes) VALUES (?, ?, ?)', [key, part, bytes]);
190
- }
191
- async function storedFiles(connection, files) {
192
- for (const { key, blob } of files) {
193
- if (stored(connection, key))
194
- continue;
195
- for (let at = 0, part = 0; at < blob.size; at += FILE_PART_BYTES, part += 1) {
196
- const bytes = new Uint8Array(await blob.slice(at, at + FILE_PART_BYTES).arrayBuffer());
197
- storedPart(connection, key, part, bytes);
198
- }
199
- }
200
- }
201
- function filePart(connection, key, part) {
202
- const [held] = connection.rows('SELECT bytes FROM file_parts WHERE key = ? AND part = ?', [
203
- key,
204
- part,
205
- ]);
206
- return held?.bytes instanceof Uint8Array ? held.bytes : null;
207
- }
208
- function* fileParts(connection, key) {
209
- for (let part = 0;; part += 1) {
210
- const bytes = filePart(connection, key, part);
211
- if (bytes === null)
212
- return;
213
- yield bytes;
214
- }
215
- }
216
- async function spooled(connection, spool, { key, type }) {
217
- for (const held of [...spool.held()]) {
218
- if (held !== key && !stored(connection, held))
219
- await spool.drop(held);
220
- }
221
- return spool.spool(key, type, fileParts(connection, key));
222
- }
223
- function unowned(connection) {
224
- connection.run(UNOWNED_PARTS);
225
- }
226
- function queued(connection) {
171
+ function heldWork(connection, locator) {
172
+ const room = heldRoom(connection, locator);
227
173
  return {
228
- queues: connection.rows('SELECT locator, ids FROM authored_queues').map((row) => ({
229
- locator: text(row.locator),
230
- ids: JSON.parse(text(row.ids)),
231
- })),
232
- pending: connection
233
- .rows('SELECT locator, id, batch, state FROM authored_pending')
234
- .map((row) => ({
235
- locator: text(row.locator),
236
- id: text(row.id),
237
- batch: text(row.batch),
238
- state: text(row.state),
239
- })),
174
+ room: room === null ? null : { ...room, overlaid: overlaid(connection, room.key) },
175
+ queue: queueOf(connection, locator),
240
176
  };
241
177
  }
242
- function heldOrder(connection, locator) {
243
- const [held] = connection.rows('SELECT ids FROM authored_queues WHERE locator = ?', [locator]);
244
- return held === undefined ? [] : JSON.parse(text(held.ids));
245
- }
246
- function keptRows(connection, { locator, order, added, founded, roomDrafts, consumedRoomDrafts, amendments }) {
247
- for (const { id, amendment } of amendments ?? []) {
248
- amended(connection, { kind: 'authored.amend', locator, id, amendment });
249
- }
250
- for (const path of consumedRoomDrafts ?? []) {
251
- connection.run('DELETE FROM authored_room_drafts WHERE locator = ? AND path = ?', [
252
- locator,
253
- path,
254
- ]);
255
- }
256
- for (const { path, record, files } of roomDrafts ?? []) {
257
- connection.run('INSERT OR REPLACE INTO authored_room_drafts (locator, path, record, files) VALUES (?, ?, ?, ?)', [locator, path, record, owned(files)]);
258
- }
259
- if (order === undefined)
260
- return;
261
- const before = new Set(heldOrder(connection, locator));
262
- const after = new Set(order);
263
- if (after.size === 0)
264
- connection.run('DELETE FROM authored_queues WHERE locator = ?', [locator]);
265
- else {
266
- connection.run('INSERT OR REPLACE INTO authored_queues (locator, ids) VALUES (?, ?)', [
267
- locator,
268
- JSON.stringify([...after]),
269
- ]);
270
- }
271
- for (const id of before) {
272
- if (!after.has(id)) {
273
- connection.run('DELETE FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
274
- }
275
- }
276
- for (const { id, batch, state, files } of added ?? []) {
277
- if (before.has(id) || !after.has(id))
278
- continue;
279
- connection.run('INSERT OR REPLACE INTO authored_pending (locator, id, batch, state, files) VALUES (?, ?, ?, ?, ?)', [locator, id, batch, state, owned(files)]);
280
- }
281
- for (const { id, batch, files } of founded ?? []) {
282
- const [held] = connection.rows('SELECT files FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
283
- if (held === undefined || !before.has(id))
284
- continue;
285
- connection.run('UPDATE authored_pending SET batch = ?, files = ? WHERE locator = ? AND id = ?', [batch, owned([...JSON.parse(text(held.files)), ...files]), locator, id]);
286
- }
287
- }
288
- async function kept(connection, { writes, files, whole, discards }) {
289
- const refused = writes.find(({ locator }) => fenced(connection, locator));
290
- if (refused !== undefined && whole)
291
- return refused.locator;
292
- await storedFiles(connection, files);
293
- for (const write of writes) {
294
- if (!fenced(connection, write.locator))
295
- keptRows(connection, write);
296
- }
297
- for (const locator of discards ?? [])
298
- roomWork(connection, locator);
299
- unowned(connection);
300
- return refused?.locator ?? null;
178
+ function status(connection) {
179
+ return {
180
+ ...unsentStatus(connection),
181
+ lastCompleted: facts(connection, ['lastCompleted']).lastCompleted ?? null,
182
+ };
301
183
  }
302
- function amended(connection, { locator, id, amendment }) {
303
- if (fenced(connection, locator))
304
- return null;
305
- const [held] = connection.rows('SELECT state FROM authored_pending WHERE locator = ? AND id = ?', [locator, id]);
306
- if (held === undefined)
307
- return null;
308
- connection.run('UPDATE authored_pending SET state = ? WHERE locator = ? AND id = ?', [
309
- JSON.stringify({
310
- ...JSON.parse(text(held.state)),
311
- ...JSON.parse(amendment),
312
- }),
313
- locator,
314
- id,
315
- ]);
316
- return null;
184
+ function pendingOf(connection, locator, id) {
185
+ return {
186
+ state: pendingState(connection, locator, id),
187
+ room: connection.rows('SELECT 1 FROM replica_rooms WHERE locator = ?', [locator]).length > 0,
188
+ };
317
189
  }
318
- async function roomDraft(connection, { locator, path, kept: draft, files }) {
319
- if (fenced(connection, locator))
320
- return locator;
321
- await storedFiles(connection, files);
322
- if (draft === null) {
323
- connection.run('DELETE FROM authored_room_drafts WHERE locator = ? AND path = ?', [
324
- locator,
325
- path,
190
+ function storedConversations(connection, conversations) {
191
+ const named = conversations === null ? '' : ' WHERE conversation IN (SELECT value FROM json_each(?))';
192
+ const bound = conversations === null ? [] : [JSON.stringify(conversations)];
193
+ return [
194
+ ...new Set([
195
+ ...tablesOf(MESSAGE_TABLES).flatMap((table) => texts(connection.rows(`SELECT DISTINCT conversation FROM ${table}${named}`, bound), 'conversation')),
196
+ ...chatDraftConversations(connection, conversations),
197
+ ]),
198
+ ];
199
+ }
200
+ function droppedConversations(connection, conversations) {
201
+ const held = storedConversations(connection, conversations);
202
+ for (const table of tablesOf(MESSAGE_TABLES)) {
203
+ connection.run(`DELETE FROM ${table} WHERE conversation IN (SELECT value FROM json_each(?))`, [
204
+ JSON.stringify(conversations),
326
205
  ]);
327
206
  }
328
- else {
329
- connection.run('INSERT OR REPLACE INTO authored_room_drafts (locator, path, record, files) VALUES (?, ?, ?, ?)', [locator, path, draft.record, owned(draft.files)]);
330
- }
331
- unowned(connection);
332
- return null;
333
- }
334
- function chatDraft(connection, { kept: drafts, dropped }) {
335
- for (const conversation of dropped) {
336
- connection.run('DELETE FROM authored_chat_drafts WHERE conversation = ?', [conversation]);
337
- }
338
- for (const { conversation, record } of drafts) {
339
- connection.run('INSERT OR REPLACE INTO authored_chat_drafts (conversation, record) VALUES (?, ?)', [conversation, record]);
340
- }
341
- return null;
342
- }
343
- async function call(connection, { operation, kept: held, files }) {
344
- await storedFiles(connection, files);
345
- if (held === null)
346
- connection.run('DELETE FROM authored_calls WHERE operation = ?', [operation]);
347
- else {
348
- connection.run('INSERT OR REPLACE INTO authored_calls (operation, record, files) VALUES (?, ?, ?)', [operation, held.record, owned(held.files)]);
349
- }
350
- unowned(connection);
351
- return null;
207
+ chatDraftsDropped(connection, conversations);
208
+ return held;
352
209
  }
353
- function roomWork(connection, locator) {
354
- connection.run('DELETE FROM authored_queues WHERE locator = ?', [locator]);
355
- connection.run('DELETE FROM authored_pending WHERE locator = ?', [locator]);
210
+ function unopened(connection) {
211
+ connection.run(UNOPENED_PARTS);
356
212
  }
357
213
  function fence(connection, locators) {
214
+ fencedWork(connection, locators);
358
215
  for (const locator of locators) {
359
- connection.run('INSERT OR REPLACE INTO authored_fences (locator) VALUES (?)', [locator]);
360
- roomWork(connection, locator);
361
- connection.run('DELETE FROM authored_room_drafts WHERE locator = ?', [locator]);
362
216
  connection.run('DELETE FROM opened_files WHERE locator = ?', [locator]);
363
217
  }
364
- unowned(connection);
218
+ unopened(connection);
365
219
  return fenceRooms(connection, locators);
366
220
  }
367
221
  function erased(connection, { locator, limit }) {
368
- const done = erase(connection, locator, limit);
369
- if (locator !== null && !done.remaining) {
370
- connection.run('DELETE FROM authored_fences WHERE locator = ?', [locator]);
371
- }
372
- return done;
222
+ return erase(connection, locator, limit);
373
223
  }
374
- function claim(connection, holder) {
375
- const held = fact(connection, 'holder');
376
- if (held !== null)
377
- return held === holder;
378
- remember(connection, 'holder', holder);
379
- return true;
224
+ function unfencedRooms(connection, locators) {
225
+ const erased = locators.filter((locator) => connection.rows('SELECT 1 FROM replica_erasing WHERE locator = ? LIMIT 1', [locator])
226
+ .length === 0);
227
+ unfenced(connection, erased);
228
+ return erased;
380
229
  }
381
230
  function end(connection, holder) {
382
231
  ended(connection);
383
- forgottenMessages(connection);
232
+ forgottenConversations(connection);
384
233
  if (holder !== null && claim(connection, holder))
385
234
  return true;
386
- for (const [table] of TABLES)
387
- connection.run(`DELETE FROM ${table}`);
235
+ authoredEmptied(connection);
388
236
  connection.run('DELETE FROM opened_files');
389
- connection.run('DELETE FROM file_parts');
237
+ connection.run('DELETE FROM opened_parts');
390
238
  return false;
391
239
  }
392
- function count(value) {
393
- return typeof value === 'bigint' ? Number(value) : typeof value === 'number' ? value : 0;
394
- }
395
240
  function openedFile(connection, { locator, path, revision }) {
396
241
  const [held] = connection.rows('SELECT key, media_type, byte_length FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND byte_length IS NOT NULL', [locator, path, revision]);
397
242
  return held === undefined
@@ -406,7 +251,7 @@ function opening(connection, { key, locator, path, revision, mediaType }) {
406
251
  if (fenced(connection, locator))
407
252
  return false;
408
253
  connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND byte_length IS NULL', [locator, path, revision]);
409
- unowned(connection);
254
+ unopened(connection);
410
255
  connection.run('INSERT INTO opened_files (key, locator, path, revision, media_type) VALUES (?, ?, ?, ?, ?)', [key, locator, path, revision, mediaType]);
411
256
  return true;
412
257
  }
@@ -419,22 +264,26 @@ function fetching(connection, key) {
419
264
  function openedPart(connection, { key, part, bytes }) {
420
265
  if (fetching(connection, key) === null)
421
266
  return false;
422
- storedPart(connection, key, part, bytes);
267
+ connection.run('INSERT INTO opened_parts (key, part, bytes) VALUES (?, ?, ?)', [
268
+ key,
269
+ part,
270
+ bytes,
271
+ ]);
423
272
  return true;
424
273
  }
425
274
  function dropped(connection, key) {
426
275
  connection.run('DELETE FROM opened_files WHERE key = ?', [key]);
427
- connection.run('DELETE FROM file_parts WHERE key = ?', [key]);
276
+ connection.run('DELETE FROM opened_parts WHERE key = ?', [key]);
428
277
  return null;
429
278
  }
430
279
  function keptOpened(connection, { key, sha256, byteLength, parts }) {
431
280
  const fetched = fetching(connection, key);
432
281
  if (fetched === null)
433
282
  return false;
434
- const [held] = connection.rows('SELECT count(*) AS parts, min(part) AS first, max(part) AS last, coalesce(sum(length(bytes)), 0) AS bytes FROM file_parts WHERE key = ?', [key]);
435
- const whole = count(held?.parts) === parts &&
436
- count(held?.bytes) === byteLength &&
437
- (parts === 0 || (count(held?.first) === 0 && count(held?.last) === parts - 1));
283
+ const [held] = connection.rows('SELECT count(*) AS parts, min(part) AS first, max(part) AS last, coalesce(sum(length(bytes)), 0) AS bytes FROM opened_parts WHERE key = ?', [key]);
284
+ const whole = count(held.parts) === parts &&
285
+ count(held.bytes) === byteLength &&
286
+ (parts === 0 || (count(held.first) === 0 && count(held.last) === parts - 1));
438
287
  if (!whole) {
439
288
  dropped(connection, key);
440
289
  return false;
@@ -445,71 +294,82 @@ function keptOpened(connection, { key, sha256, byteLength, parts }) {
445
294
  key,
446
295
  ]);
447
296
  connection.run('DELETE FROM opened_files WHERE locator = ? AND path = ? AND revision = ? AND key <> ?', [fetched.locator, fetched.path, fetched.revision, key]);
448
- unowned(connection);
297
+ unopened(connection);
449
298
  return true;
450
299
  }
300
+ function heldPart(connection, key, part) {
301
+ const [held] = connection.rows('SELECT bytes FROM opened_parts WHERE key = ? AND part = ?', [
302
+ key,
303
+ part,
304
+ ]);
305
+ return held?.bytes instanceof Uint8Array ? held.bytes : authoredPart(connection, key, part);
306
+ }
307
+ function cleanable(connection) {
308
+ const [held] = connection.rows('SELECT coalesce(sum(length(bytes)), 0) AS bytes FROM opened_parts');
309
+ return count(held.bytes);
310
+ }
451
311
  function cleaned(connection) {
452
312
  connection.run('DELETE FROM opened_files');
453
- const [freed] = connection.rows(`SELECT coalesce(sum(length(bytes)), 0) AS bytes FROM file_parts WHERE key NOT IN (${AUTHORED_KEYS})`);
454
- unowned(connection);
455
- return count(freed?.bytes);
313
+ const freed = cleanable(connection);
314
+ unopened(connection);
315
+ return freed;
316
+ }
317
+ function openedHeld(connection) {
318
+ return {
319
+ rooms: connection
320
+ .rows('SELECT locator, count(*) AS files, sum(byte_length) AS bytes FROM opened_files WHERE byte_length IS NOT NULL GROUP BY locator ORDER BY locator')
321
+ .map((row) => ({ room: text(row.locator), count: count(row.files), size: count(row.bytes) })),
322
+ cleanable: cleanable(connection),
323
+ };
456
324
  }
457
325
  async function committed(connection, { authored, rooms }) {
458
326
  const refused = authored === undefined ? null : await kept(connection, authored);
459
327
  if (refused !== null && authored?.whole === true) {
460
- return { fenced: refused, counts: {}, changed: {}, indexed: {} };
328
+ return { fenced: refused, changed: {}, indexed: {} };
461
329
  }
462
330
  return {
463
331
  fenced: refused,
464
332
  ...commit(connection, rooms.filter(({ locator }) => !fenced(connection, locator))),
465
333
  };
466
334
  }
467
- function receivedParts(connection, key, count) {
468
- return connection
469
- .rows('SELECT value FROM replica_received_parts WHERE key = ? AND part < ? ORDER BY part', [
470
- key,
471
- count,
472
- ])
473
- .map((row) => JSON.parse(text(row.value)));
474
- }
475
- function receive(connection, { key, head, part }) {
476
- connection.run('INSERT OR REPLACE INTO replica_received (key, head) VALUES (?, ?)', [key, head]);
477
- if (part !== undefined) {
478
- connection.run('INSERT OR REPLACE INTO replica_received_parts (key, part, value) VALUES (?, ?, ?)', [key, part.index, part.value]);
479
- }
480
- return null;
481
- }
482
- function unreceive(connection, keys) {
483
- for (const key of keys) {
484
- connection.run('DELETE FROM replica_received WHERE key = ?', [key]);
485
- connection.run('DELETE FROM replica_received_parts WHERE key = ?', [key]);
486
- }
487
- return null;
488
- }
489
335
  export function answerRuntime(connection, request, spool) {
490
336
  switch (request.kind) {
491
- case 'authored.queues':
492
- return queued(connection);
337
+ case 'authored.status':
338
+ return status(connection);
339
+ case 'authored.moving':
340
+ return moving(connection);
341
+ case 'authored.pending':
342
+ return pendingOf(connection, request.locator, request.id);
343
+ case 'authored.batch':
344
+ return pendingBatch(connection, request.locator, request.id);
345
+ case 'authored.order':
346
+ return heldOrder(connection, request.locator);
347
+ case 'authored.queued':
348
+ return queuedLocators(connection);
493
349
  case 'authored.roomDrafts':
494
- return texts(connection.rows('SELECT record FROM authored_room_drafts'), 'record');
350
+ return roomDraftRecords(connection, request.locator, request.paths);
351
+ case 'authored.chatDraft.read':
352
+ return chatDraftRecord(connection, request.conversation);
495
353
  case 'authored.chatDrafts':
496
- return texts(connection.rows('SELECT record FROM authored_chat_drafts'), 'record');
354
+ return chatDraftRecords(connection);
497
355
  case 'authored.calls':
498
- return texts(connection.rows('SELECT record FROM authored_calls'), 'record');
356
+ return callRecords(connection);
499
357
  case 'authored.fences':
500
- return texts(connection.rows('SELECT locator FROM authored_fences'), 'locator');
358
+ return fences(connection);
359
+ case 'authored.unsent':
360
+ return unsent(connection);
501
361
  case 'authored.fact':
502
362
  return fact(connection, request.name);
503
363
  case 'authored.file':
504
- return spooled(connection, spool, request);
364
+ return spooled(connection, spool, request.key, request.type);
505
365
  case 'authored.amend':
506
- return amended(connection, request);
366
+ return amended(connection, request.locator, request.id, request.amendment);
507
367
  case 'authored.roomDraft':
508
- return roomDraft(connection, request);
368
+ return roomDraft(connection, request.locator, request.path, request.kept, request.files);
509
369
  case 'authored.chatDraft':
510
- return chatDraft(connection, request);
370
+ return chatDraft(connection, request.kept, request.dropped);
511
371
  case 'authored.call':
512
- return call(connection, request);
372
+ return call(connection, request.operation, request.kept, request.files);
513
373
  case 'authored.remember':
514
374
  return remember(connection, request.name, request.value);
515
375
  case 'authored.claim':
@@ -518,37 +378,43 @@ export function answerRuntime(connection, request, spool) {
518
378
  return end(connection, request.holder);
519
379
  case 'replica.open':
520
380
  return opened(connection);
381
+ case 'replica.rooms':
382
+ return heldRooms(connection, request.locators);
383
+ case 'replica.room':
384
+ return heldWork(connection, request.locator);
385
+ case 'replica.covering':
386
+ return { ...covering(connection, request.since), queues: queues(connection) };
387
+ case 'replica.offline':
388
+ return offlineMode(connection, request.locator);
389
+ case 'replica.held':
390
+ return {
391
+ held: [...new Set([...heldLocators(connection), ...authoredLocators(connection)])],
392
+ staged: stagedLocators(connection),
393
+ };
394
+ case 'replica.demote':
395
+ return demoted(connection);
396
+ case 'replica.facts':
397
+ return facts(connection, request.names);
398
+ case 'replica.presentation':
399
+ return presentation(connection, request.app);
521
400
  case 'replica.query':
522
401
  return answerQuery(connection, request.plan, request.rooms, request.budget);
402
+ case 'replica.tallies':
403
+ return roomTallies(connection, request.totals, request.rooms, request.since);
523
404
  case 'replica.entries':
524
405
  return entries(connection, request.key, request.view, request.paths);
525
406
  case 'replica.typed':
526
407
  return typed(connection, request.key, request.view, request.paths);
527
408
  case 'replica.referrers':
528
- return referrers(connection, request.key, request.view, request.targets, request.kinds);
529
- case 'replica.walk':
530
- return walk(connection, request.key, request.view, request.after, request.bytes);
531
- case 'replica.files':
532
- return files(connection, request.key, request.view, request.after, request.limit);
409
+ return referrers(connection, request.key, request.view, request.targets);
533
410
  case 'replica.folders':
534
- return folders(connection, request.key, request.view, request.paths);
411
+ return folders(connection, request.key, request.paths);
535
412
  case 'replica.typedWithin':
536
413
  return typedWithin(connection, request.key, request.view, request.roots, request.within);
537
- case 'replica.counts':
538
- return counts(connection, request.rooms);
539
- case 'replica.search': {
540
- const { kind: _kind, ...ask } = request;
541
- return searched(connection, ask);
542
- }
543
- case 'replica.received':
544
- return connection.rows('SELECT key, head FROM replica_received').map((row) => ({
545
- key: text(row.key),
546
- head: JSON.parse(text(row.head)),
547
- }));
548
- case 'replica.receivedParts':
549
- return receivedParts(connection, request.key, request.count);
550
414
  case 'replica.stage':
551
415
  return fenced(connection, request.locator) ? null : stage(connection, request);
416
+ case 'replica.resume':
417
+ return fenced(connection, request.locator) ? null : resume(connection, request);
552
418
  case 'replica.refresh':
553
419
  return refreshing(connection, request);
554
420
  case 'replica.unrefresh':
@@ -561,6 +427,8 @@ export function answerRuntime(connection, request, spool) {
561
427
  return erased(connection, request);
562
428
  case 'replica.abandon':
563
429
  return abandon(connection, request.locator);
430
+ case 'replica.unfence':
431
+ return unfencedRooms(connection, request.locators);
564
432
  case 'replica.release':
565
433
  return release(connection, request.key);
566
434
  case 'replica.rederive':
@@ -577,10 +445,6 @@ export function answerRuntime(connection, request, spool) {
577
445
  request.value,
578
446
  ]);
579
447
  return null;
580
- case 'replica.receive':
581
- return receive(connection, request);
582
- case 'replica.unreceive':
583
- return unreceive(connection, request.keys);
584
448
  case 'opened.find':
585
449
  return openedFile(connection, request);
586
450
  case 'opened.begin':
@@ -593,29 +457,43 @@ export function answerRuntime(connection, request, spool) {
593
457
  return dropped(connection, request.key);
594
458
  case 'opened.clean':
595
459
  return cleaned(connection);
460
+ case 'opened.held':
461
+ return openedHeld(connection);
596
462
  case 'file.part':
597
- return filePart(connection, request.key, request.part);
463
+ return heldPart(connection, request.key, request.part);
598
464
  case 'conversation.held':
599
- return heldConversations(connection);
465
+ return heldConversations(connection, request.conversations);
600
466
  case 'conversation.keep': {
601
467
  const { kind: _kind, ...write } = request;
602
468
  return keptMessages(connection, write);
603
469
  }
604
470
  case 'conversation.window':
605
- return messageWindow(connection, request.conversation, request.limit, request.before);
471
+ return messageWindow(connection, request.conversation, request.limit, request.before, request.phrase);
606
472
  case 'conversation.count':
607
- return messageCount(connection, request.conversation);
473
+ return messageCount(connection, request.conversation, request.phrase);
608
474
  case 'conversation.turn':
609
475
  return turnArrived(connection, request.conversation, request.turn);
476
+ case 'conversation.rows':
477
+ return conversationRows(connection, request.conversations);
478
+ case 'conversation.tallies':
479
+ return conversationTallies(connection, request.conversations, request.since);
480
+ case 'conversation.facts':
481
+ return conversationFacts(connection);
482
+ case 'conversation.fact': {
483
+ const { kind: _kind, ...fact } = request;
484
+ return keptFact(connection, fact);
485
+ }
486
+ case 'conversation.stored':
487
+ return storedConversations(connection, null);
610
488
  case 'conversation.drop':
611
- chatDraft(connection, {
612
- kind: 'authored.chatDraft',
613
- kept: [],
614
- dropped: request.conversations,
615
- });
616
- droppedMessages(connection, request.conversations);
617
- return null;
489
+ return droppedConversations(connection, request.conversations);
618
490
  case 'space.probe':
619
491
  return spool.probe(PROBE_BYTES).then(() => null);
492
+ case 'read.stored':
493
+ return storedRead(connection, request);
494
+ case 'read.keep':
495
+ return keptRead(connection, request, request.answer);
496
+ case 'read.builds':
497
+ return readsOfOtherBuildsForgotten(connection, request.build);
620
498
  }
621
499
  }