@agentshouse/mdruntime 0.1.0-cfac557170cf3 → 0.1.0-cfaff87a9d88a

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 (356) 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 +322 -0
  11. package/dist/adapter.d.ts +209 -118
  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 +347 -0
  19. package/dist/binary.d.ts +6 -2
  20. package/dist/binary.d.ts.map +1 -1
  21. package/dist/binary.js +10 -3
  22. package/dist/bootstrap.d.ts +12 -11
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +213 -89
  25. package/dist/cell.d.ts +6 -0
  26. package/dist/cell.d.ts.map +1 -0
  27. package/dist/cell.js +9 -0
  28. package/dist/chain.d.ts +2 -1
  29. package/dist/chain.d.ts.map +1 -1
  30. package/dist/change-set.d.ts +4 -0
  31. package/dist/change-set.d.ts.map +1 -1
  32. package/dist/change-set.js +6 -0
  33. package/dist/change.d.ts +7 -2
  34. package/dist/change.d.ts.map +1 -1
  35. package/dist/change.js +7 -2
  36. package/dist/chat-types.d.ts +3 -0
  37. package/dist/chat-types.d.ts.map +1 -0
  38. package/dist/chat-types.js +11 -0
  39. package/dist/client.d.ts +41 -25
  40. package/dist/client.d.ts.map +1 -1
  41. package/dist/client.js +58 -69
  42. package/dist/collection.d.ts +28 -7
  43. package/dist/collection.d.ts.map +1 -1
  44. package/dist/collection.js +35 -27
  45. package/dist/column.d.ts +5 -0
  46. package/dist/column.d.ts.map +1 -0
  47. package/dist/column.js +9 -0
  48. package/dist/compile.d.ts +10 -7
  49. package/dist/compile.d.ts.map +1 -1
  50. package/dist/compile.js +336 -354
  51. package/dist/connection.d.ts +6 -144
  52. package/dist/connection.d.ts.map +1 -1
  53. package/dist/connection.js +115 -5314
  54. package/dist/context.d.ts +2 -0
  55. package/dist/context.d.ts.map +1 -0
  56. package/dist/context.js +7 -0
  57. package/dist/conversation-live.d.ts +149 -0
  58. package/dist/conversation-live.d.ts.map +1 -0
  59. package/dist/conversation-live.js +259 -0
  60. package/dist/conversation-row.d.ts +40 -0
  61. package/dist/conversation-row.d.ts.map +1 -0
  62. package/dist/conversation-row.js +66 -0
  63. package/dist/conversation.d.ts +75 -55
  64. package/dist/conversation.d.ts.map +1 -1
  65. package/dist/conversation.js +1015 -928
  66. package/dist/declaration.d.ts +10 -0
  67. package/dist/declaration.d.ts.map +1 -0
  68. package/dist/declaration.js +24 -0
  69. package/dist/discovery.d.ts +12 -0
  70. package/dist/discovery.d.ts.map +1 -0
  71. package/dist/discovery.js +175 -0
  72. package/dist/download.d.ts +6 -0
  73. package/dist/download.d.ts.map +1 -0
  74. package/dist/download.js +42 -0
  75. package/dist/durability.d.ts +20 -1
  76. package/dist/durability.d.ts.map +1 -1
  77. package/dist/durability.js +7 -0
  78. package/dist/entry.d.ts +16 -2
  79. package/dist/entry.d.ts.map +1 -1
  80. package/dist/entry.js +60 -21
  81. package/dist/expectation.d.ts +26 -13
  82. package/dist/expectation.d.ts.map +1 -1
  83. package/dist/expectation.js +72 -19
  84. package/dist/failure.d.ts +3 -0
  85. package/dist/failure.d.ts.map +1 -1
  86. package/dist/failure.js +8 -0
  87. package/dist/figures.d.ts +49 -0
  88. package/dist/figures.d.ts.map +1 -0
  89. package/dist/figures.js +199 -0
  90. package/dist/file.d.ts +1 -1
  91. package/dist/file.d.ts.map +1 -1
  92. package/dist/file.js +3 -2
  93. package/dist/holdings.d.ts +29 -0
  94. package/dist/holdings.d.ts.map +1 -0
  95. package/dist/holdings.js +95 -0
  96. package/dist/host.d.ts +25 -8
  97. package/dist/host.d.ts.map +1 -1
  98. package/dist/host.js +128 -59
  99. package/dist/house-query.d.ts +24 -0
  100. package/dist/house-query.d.ts.map +1 -0
  101. package/dist/house-query.js +67 -0
  102. package/dist/identity.d.ts +0 -1
  103. package/dist/identity.d.ts.map +1 -1
  104. package/dist/identity.js +0 -3
  105. package/dist/index.d.ts +42 -16
  106. package/dist/index.d.ts.map +1 -1
  107. package/dist/index.js +20 -6
  108. package/dist/install.d.ts +60 -0
  109. package/dist/install.d.ts.map +1 -0
  110. package/dist/install.js +537 -0
  111. package/dist/lifecycle.d.ts +7 -0
  112. package/dist/lifecycle.d.ts.map +1 -0
  113. package/dist/lifecycle.js +290 -0
  114. package/dist/listing.d.ts +60 -0
  115. package/dist/listing.d.ts.map +1 -0
  116. package/dist/listing.js +168 -0
  117. package/dist/live.d.ts +23 -6
  118. package/dist/live.d.ts.map +1 -1
  119. package/dist/live.js +138 -39
  120. package/dist/loaded.d.ts +7 -0
  121. package/dist/loaded.d.ts.map +1 -0
  122. package/dist/loaded.js +46 -0
  123. package/dist/locks.d.ts +7 -0
  124. package/dist/locks.d.ts.map +1 -0
  125. package/dist/locks.js +34 -0
  126. package/dist/lost.d.ts +5 -0
  127. package/dist/lost.d.ts.map +1 -0
  128. package/dist/lost.js +49 -0
  129. package/dist/media.d.ts +20 -4
  130. package/dist/media.d.ts.map +1 -1
  131. package/dist/media.js +170 -36
  132. package/dist/memory.d.ts +20 -7
  133. package/dist/memory.d.ts.map +1 -1
  134. package/dist/memory.js +260 -109
  135. package/dist/messages.d.ts +40 -5
  136. package/dist/messages.d.ts.map +1 -1
  137. package/dist/messages.js +118 -39
  138. package/dist/modal.d.ts +2 -0
  139. package/dist/modal.d.ts.map +1 -0
  140. package/dist/modal.js +11 -0
  141. package/dist/model.d.ts +6 -13
  142. package/dist/model.d.ts.map +1 -1
  143. package/dist/model.js +6 -23
  144. package/dist/models.d.ts +10 -0
  145. package/dist/models.d.ts.map +1 -0
  146. package/dist/models.js +153 -0
  147. package/dist/name.d.ts +0 -1
  148. package/dist/name.d.ts.map +1 -1
  149. package/dist/name.js +3 -7
  150. package/dist/observation.d.ts +30 -13
  151. package/dist/observation.d.ts.map +1 -1
  152. package/dist/observation.js +218 -81
  153. package/dist/online.d.ts +7 -0
  154. package/dist/online.d.ts.map +1 -0
  155. package/dist/online.js +29 -0
  156. package/dist/opened.d.ts +1 -1
  157. package/dist/opened.d.ts.map +1 -1
  158. package/dist/opened.js +5 -5
  159. package/dist/opening.d.ts +4 -0
  160. package/dist/opening.d.ts.map +1 -0
  161. package/dist/opening.js +69 -0
  162. package/dist/outcome.d.ts +28 -8
  163. package/dist/outcome.d.ts.map +1 -1
  164. package/dist/outcome.js +36 -3
  165. package/dist/overlay.d.ts +10 -5
  166. package/dist/overlay.d.ts.map +1 -1
  167. package/dist/overlay.js +48 -24
  168. package/dist/page-metadata.d.ts +8 -0
  169. package/dist/page-metadata.d.ts.map +1 -0
  170. package/dist/page-metadata.js +19 -0
  171. package/dist/parts.d.ts +6 -0
  172. package/dist/parts.d.ts.map +1 -0
  173. package/dist/parts.js +36 -0
  174. package/dist/paths.d.ts +1 -0
  175. package/dist/paths.d.ts.map +1 -1
  176. package/dist/paths.js +22 -0
  177. package/dist/preparation.d.ts +46 -0
  178. package/dist/preparation.d.ts.map +1 -0
  179. package/dist/preparation.js +344 -0
  180. package/dist/presence.d.ts +58 -0
  181. package/dist/presence.d.ts.map +1 -0
  182. package/dist/presence.js +231 -0
  183. package/dist/queries.d.ts +16 -0
  184. package/dist/queries.d.ts.map +1 -0
  185. package/dist/queries.js +330 -0
  186. package/dist/query.d.ts +16 -212
  187. package/dist/query.d.ts.map +1 -1
  188. package/dist/query.js +3 -505
  189. package/dist/questions.d.ts +30 -0
  190. package/dist/questions.d.ts.map +1 -0
  191. package/dist/questions.js +117 -0
  192. package/dist/queue.d.ts +40 -0
  193. package/dist/queue.d.ts.map +1 -0
  194. package/dist/queue.js +480 -0
  195. package/dist/reach.d.ts +26 -15
  196. package/dist/reach.d.ts.map +1 -1
  197. package/dist/reach.js +350 -160
  198. package/dist/react.d.ts +21 -3
  199. package/dist/react.d.ts.map +1 -1
  200. package/dist/react.js +33 -1
  201. package/dist/read.d.ts +7 -0
  202. package/dist/read.d.ts.map +1 -0
  203. package/dist/read.js +17 -0
  204. package/dist/readiness.d.ts +22 -20
  205. package/dist/readiness.d.ts.map +1 -1
  206. package/dist/readiness.js +21 -20
  207. package/dist/reads.d.ts +38 -10
  208. package/dist/reads.d.ts.map +1 -1
  209. package/dist/reads.js +164 -77
  210. package/dist/recovery.d.ts +4 -1
  211. package/dist/recovery.d.ts.map +1 -1
  212. package/dist/recovery.js +40 -9
  213. package/dist/reference-forms.d.ts +4 -0
  214. package/dist/reference-forms.d.ts.map +1 -0
  215. package/dist/reference-forms.js +74 -0
  216. package/dist/refresh.d.ts +7 -5
  217. package/dist/refresh.d.ts.map +1 -1
  218. package/dist/refresh.js +37 -9
  219. package/dist/refusal.d.ts +5 -0
  220. package/dist/refusal.d.ts.map +1 -0
  221. package/dist/refusal.js +55 -0
  222. package/dist/replica.d.ts +11 -17
  223. package/dist/replica.d.ts.map +1 -1
  224. package/dist/replica.js +68 -38
  225. package/dist/retried.d.ts +30 -0
  226. package/dist/retried.d.ts.map +1 -0
  227. package/dist/retried.js +72 -0
  228. package/dist/room-draft.d.ts +34 -10
  229. package/dist/room-draft.d.ts.map +1 -1
  230. package/dist/room-draft.js +335 -112
  231. package/dist/room-drafts.d.ts +24 -0
  232. package/dist/room-drafts.d.ts.map +1 -0
  233. package/dist/room-drafts.js +222 -0
  234. package/dist/room-list.d.ts +10 -0
  235. package/dist/room-list.d.ts.map +1 -0
  236. package/dist/room-list.js +45 -0
  237. package/dist/rows.d.ts +24 -22
  238. package/dist/rows.d.ts.map +1 -1
  239. package/dist/rows.js +63 -186
  240. package/dist/running.d.ts +5 -0
  241. package/dist/running.d.ts.map +1 -0
  242. package/dist/running.js +10 -0
  243. package/dist/runtime.d.ts +36 -0
  244. package/dist/runtime.d.ts.map +1 -0
  245. package/dist/runtime.js +1 -0
  246. package/dist/save.d.ts +43 -86
  247. package/dist/save.d.ts.map +1 -1
  248. package/dist/save.js +332 -228
  249. package/dist/saves.d.ts +34 -0
  250. package/dist/saves.d.ts.map +1 -0
  251. package/dist/saves.js +463 -0
  252. package/dist/search.d.ts +12 -63
  253. package/dist/search.d.ts.map +1 -1
  254. package/dist/search.js +9 -52
  255. package/dist/seed.d.ts +11 -2
  256. package/dist/seed.d.ts.map +1 -1
  257. package/dist/seed.js +71 -1
  258. package/dist/shared.d.ts +1 -7
  259. package/dist/shared.d.ts.map +1 -1
  260. package/dist/shared.js +13 -105
  261. package/dist/shown.d.ts +35 -0
  262. package/dist/shown.d.ts.map +1 -0
  263. package/dist/shown.js +326 -0
  264. package/dist/socket/admission.d.ts +7 -0
  265. package/dist/socket/admission.d.ts.map +1 -0
  266. package/dist/socket/admission.js +39 -0
  267. package/dist/socket/answers.d.ts +6 -0
  268. package/dist/socket/answers.d.ts.map +1 -0
  269. package/dist/socket/answers.js +20 -0
  270. package/dist/socket/lanes.d.ts +28 -0
  271. package/dist/socket/lanes.d.ts.map +1 -0
  272. package/dist/socket/lanes.js +103 -0
  273. package/dist/socket/reads.d.ts +10 -0
  274. package/dist/socket/reads.d.ts.map +1 -0
  275. package/dist/socket/reads.js +31 -0
  276. package/dist/socket/session.d.ts +41 -0
  277. package/dist/socket/session.d.ts.map +1 -0
  278. package/dist/socket/session.js +26 -0
  279. package/dist/socket.d.ts +68 -0
  280. package/dist/socket.d.ts.map +1 -0
  281. package/dist/socket.js +165 -0
  282. package/dist/source.d.ts +61 -0
  283. package/dist/source.d.ts.map +1 -0
  284. package/dist/source.js +95 -0
  285. package/dist/status.d.ts +0 -6
  286. package/dist/status.d.ts.map +1 -1
  287. package/dist/status.js +0 -6
  288. package/dist/store/installs.d.ts +30 -0
  289. package/dist/store/installs.d.ts.map +1 -0
  290. package/dist/store/installs.js +40 -0
  291. package/dist/store/readiness.d.ts +11 -0
  292. package/dist/store/readiness.d.ts.map +1 -0
  293. package/dist/store/readiness.js +68 -0
  294. package/dist/store/records.d.ts +229 -0
  295. package/dist/store/records.d.ts.map +1 -0
  296. package/dist/store/records.js +474 -0
  297. package/dist/store/room-held.d.ts +8 -0
  298. package/dist/store/room-held.d.ts.map +1 -0
  299. package/dist/store/room-held.js +17 -0
  300. package/dist/store/rooms-shown.d.ts +8 -0
  301. package/dist/store/rooms-shown.d.ts.map +1 -0
  302. package/dist/store/rooms-shown.js +13 -0
  303. package/dist/store/space.d.ts +11 -0
  304. package/dist/store/space.d.ts.map +1 -0
  305. package/dist/store/space.js +41 -0
  306. package/dist/store/watchers.d.ts +17 -0
  307. package/dist/store/watchers.d.ts.map +1 -0
  308. package/dist/store/watchers.js +56 -0
  309. package/dist/store/writes.d.ts +24 -0
  310. package/dist/store/writes.d.ts.map +1 -0
  311. package/dist/store/writes.js +125 -0
  312. package/dist/store.d.ts +116 -156
  313. package/dist/store.d.ts.map +1 -1
  314. package/dist/store.js +174 -394
  315. package/dist/stored.d.ts +87 -41
  316. package/dist/stored.d.ts.map +1 -1
  317. package/dist/stored.js +466 -228
  318. package/dist/surface.d.ts +94 -0
  319. package/dist/surface.d.ts.map +1 -0
  320. package/dist/surface.js +255 -0
  321. package/dist/sync.d.ts +21 -0
  322. package/dist/sync.d.ts.map +1 -0
  323. package/dist/sync.js +557 -0
  324. package/dist/tables.d.ts +128 -92
  325. package/dist/tables.d.ts.map +1 -1
  326. package/dist/tables.js +208 -323
  327. package/dist/tallies.d.ts +18 -0
  328. package/dist/tallies.d.ts.map +1 -0
  329. package/dist/tallies.js +128 -0
  330. package/dist/transfer.d.ts +0 -5
  331. package/dist/transfer.d.ts.map +1 -1
  332. package/dist/validation.d.ts +5 -4
  333. package/dist/validation.d.ts.map +1 -1
  334. package/dist/validation.js +87 -105
  335. package/dist/windows.d.ts +1 -12
  336. package/dist/windows.d.ts.map +1 -1
  337. package/dist/windows.js +2 -75
  338. package/dist/wire.d.ts +85 -14
  339. package/dist/wire.d.ts.map +1 -1
  340. package/dist/wire.js +37 -15
  341. package/package.json +3 -2
  342. package/dist/attempt.d.ts +0 -16
  343. package/dist/attempt.d.ts.map +0 -1
  344. package/dist/attempt.js +0 -70
  345. package/dist/fence.d.ts +0 -6
  346. package/dist/fence.d.ts.map +0 -1
  347. package/dist/fence.js +0 -10
  348. package/dist/fulltext.d.ts +0 -27
  349. package/dist/fulltext.d.ts.map +0 -1
  350. package/dist/fulltext.js +0 -370
  351. package/dist/log.d.ts +0 -5
  352. package/dist/log.d.ts.map +0 -1
  353. package/dist/log.js +0 -14
  354. package/dist/words.d.ts +0 -19
  355. package/dist/words.d.ts.map +0 -1
  356. package/dist/words.js +0 -156
@@ -0,0 +1,474 @@
1
+ import { composedOf } from '../collection.js';
2
+ import { binaryLocalId } from '../identity.js';
3
+ import { lockingMode } from '../presence.js';
4
+ import { readsRuntime } from '../tables.js';
5
+ const FILE = '\u0000file';
6
+ const UNSTATED = {
7
+ lastCompleted: null,
8
+ providerLimits: [],
9
+ capabilities: [],
10
+ member: null,
11
+ timeZone: null,
12
+ targets: {},
13
+ conversationList: null,
14
+ agentList: null,
15
+ conversationCursor: null,
16
+ chatPins: [],
17
+ readUntil: null,
18
+ roomList: null,
19
+ queriesOnly: [],
20
+ };
21
+ function batchFacts(batch) {
22
+ return { paths: batch.changes.map(({ path }) => path), moving: batch.between !== undefined };
23
+ }
24
+ function batchFiles(batch) {
25
+ return batch.changes.flatMap((change) => (change.kind === 'binary' ? [change.localId] : []));
26
+ }
27
+ function draftFiles(drafts) {
28
+ return drafts.flatMap(({ parts }) => (parts.file === undefined ? [] : [parts.file.localId]));
29
+ }
30
+ function roomDraftRow(record) {
31
+ return { path: record.path, record: JSON.stringify(record), files: draftFiles([record]) };
32
+ }
33
+ function authoredRows({ locator, queue, stored, founded, saved, roomDrafts, consumedRoomDrafts, }) {
34
+ const held = new Set((stored ?? []).map(({ id }) => id));
35
+ return {
36
+ locator,
37
+ ...(queue === undefined
38
+ ? {}
39
+ : {
40
+ order: queue.map(({ id }) => id),
41
+ added: queue
42
+ .filter(({ id }) => !held.has(id))
43
+ .map((batch) => {
44
+ const drafts = saved?.get(batch.id) ?? [];
45
+ return {
46
+ id: batch.id,
47
+ batch: JSON.stringify(batch),
48
+ state: JSON.stringify({
49
+ drafts,
50
+ submission: { state: 'waiting' },
51
+ lost: false,
52
+ }),
53
+ files: [...batchFiles(batch), ...draftFiles(drafts)],
54
+ ...batchFacts(batch),
55
+ };
56
+ }),
57
+ }),
58
+ ...(founded === undefined
59
+ ? {}
60
+ : {
61
+ founded: founded.map((batch) => ({
62
+ id: batch.id,
63
+ batch: JSON.stringify(batch),
64
+ files: batchFiles(batch),
65
+ ...batchFacts(batch),
66
+ })),
67
+ }),
68
+ ...(roomDrafts === undefined ? {} : { roomDrafts: roomDrafts.map(roomDraftRow) }),
69
+ ...(consumedRoomDrafts === undefined ? {} : { consumedRoomDrafts }),
70
+ };
71
+ }
72
+ function marked(value) {
73
+ return typeof value === 'object' && value !== null && FILE in value;
74
+ }
75
+ function keyed(keys, value) {
76
+ const stored = [];
77
+ const files = [];
78
+ const record = JSON.stringify(value, (_name, held) => {
79
+ if (!(held instanceof Blob))
80
+ return held;
81
+ let key = keys.get(held);
82
+ if (key === undefined) {
83
+ key = binaryLocalId();
84
+ keys.set(held, key);
85
+ }
86
+ stored.push({ key, blob: held });
87
+ files.push(key);
88
+ return { [FILE]: key, type: held.type };
89
+ });
90
+ return { record, files, stored };
91
+ }
92
+ async function filed(value, read) {
93
+ if (Array.isArray(value))
94
+ return Promise.all(value.map((item) => filed(item, read)));
95
+ if (marked(value))
96
+ return read(value[FILE], value.type);
97
+ if (typeof value !== 'object' || value === null)
98
+ return value;
99
+ const restored = {};
100
+ for (const [name, item] of Object.entries(value))
101
+ restored[name] = await filed(item, read);
102
+ return restored;
103
+ }
104
+ function roomOf(row) {
105
+ return {
106
+ record: { ...JSON.parse(row.record), key: row.key },
107
+ indexed: row.indexed,
108
+ documents: row.documents,
109
+ };
110
+ }
111
+ function json(value, fallback) {
112
+ return value === undefined ? fallback : JSON.parse(value);
113
+ }
114
+ function coverOf(kept, answer) {
115
+ const { log, whole, rooms, removed, queues } = answer;
116
+ const queued = new Map(queues.map(({ locator, ids }) => [locator, ids]));
117
+ const fresh = whole || kept === null || kept.log.token !== log.token;
118
+ if (!fresh && log.at < kept.log.at)
119
+ return kept;
120
+ const held = fresh ? { rooms: new Map(), locking: new Set() } : kept;
121
+ for (const locator of removed) {
122
+ held.rooms.delete(locator);
123
+ held.locking.delete(locator);
124
+ }
125
+ for (const { locator, ...room } of rooms) {
126
+ held.rooms.set(locator, room);
127
+ if (lockingMode(room.offline))
128
+ held.locking.add(locator);
129
+ else
130
+ held.locking.delete(locator);
131
+ }
132
+ return { log, rooms: held.rooms, locking: held.locking, queues: queued };
133
+ }
134
+ export function openRuntimeStore(database) {
135
+ let written = 0;
136
+ let covered = null;
137
+ let kept = null;
138
+ const authored = {
139
+ ask(request) {
140
+ if (!readsRuntime(request))
141
+ written += 1;
142
+ return database.ask(request);
143
+ },
144
+ };
145
+ const keys = new WeakMap();
146
+ const read = async (key, type) => {
147
+ const blob = await authored.ask({ kind: 'authored.file', key, type });
148
+ keys.set(blob, key);
149
+ return blob;
150
+ };
151
+ const restored = async (records) => Promise.all(records.map(async (record) => (await filed(JSON.parse(record), read))));
152
+ const amend = async (locator, id, amendment) => {
153
+ await authored.ask({
154
+ kind: 'authored.amend',
155
+ locator,
156
+ id,
157
+ amendment: JSON.stringify(amendment),
158
+ });
159
+ };
160
+ const fact = (name) => authored.ask({ kind: 'authored.fact', name });
161
+ const changed = new Map();
162
+ const change = (key) => changed.set(key, (changed.get(key) ?? 0) + 1);
163
+ return {
164
+ opened() {
165
+ return authored.ask({ kind: 'replica.open' });
166
+ },
167
+ async rooms(locators) {
168
+ const held = await authored.ask({ kind: 'replica.rooms', locators: locators ?? null });
169
+ return held.map(roomOf);
170
+ },
171
+ async room(locator) {
172
+ const { room, queue } = await authored.ask({ kind: 'replica.room', locator });
173
+ return {
174
+ room: room === null ? null : { ...roomOf(room), overlaid: new Set(room.overlaid) },
175
+ queue: queue.map(({ batch, state }) => ({
176
+ batch: JSON.parse(batch),
177
+ state: JSON.parse(state),
178
+ })),
179
+ };
180
+ },
181
+ covering() {
182
+ if (covered?.at === written)
183
+ return covered.cover;
184
+ const held = {
185
+ at: written,
186
+ cover: authored
187
+ .ask({ kind: 'replica.covering', since: kept?.log ?? null })
188
+ .then((answer) => {
189
+ kept = coverOf(kept, answer);
190
+ return kept;
191
+ }),
192
+ };
193
+ covered = held;
194
+ held.cover.catch(() => {
195
+ if (covered === held)
196
+ covered = null;
197
+ });
198
+ return held.cover;
199
+ },
200
+ offline(locator) {
201
+ return authored.ask({ kind: 'replica.offline', locator });
202
+ },
203
+ async held() {
204
+ const { held, staged } = await authored.ask({ kind: 'replica.held' });
205
+ return { held: new Set(held), staged: new Set(staged) };
206
+ },
207
+ async status() {
208
+ const { queued, lastCompleted, changes, resets, returned } = await authored.ask({
209
+ kind: 'authored.status',
210
+ });
211
+ return {
212
+ queued,
213
+ lastCompleted: json(lastCompleted ?? undefined, null),
214
+ unsent: changes.map(({ locator, path }) => ({ room: locator, path })),
215
+ resets,
216
+ returned: returned.map((record) => JSON.parse(record)),
217
+ };
218
+ },
219
+ async batch(locator, id) {
220
+ const held = await authored.ask({ kind: 'authored.batch', locator, id });
221
+ return held === null ? null : JSON.parse(held);
222
+ },
223
+ order(locator) {
224
+ return authored.ask({ kind: 'authored.order', locator });
225
+ },
226
+ queued() {
227
+ return authored.ask({ kind: 'authored.queued' });
228
+ },
229
+ async moving() {
230
+ const { queues, pending } = await authored.ask({ kind: 'authored.moving' });
231
+ return {
232
+ queued: new Map(queues.map(({ locator, ids }) => [locator, ids])),
233
+ moving: pending.map(({ locator, batch, state }) => ({
234
+ locator,
235
+ batch: JSON.parse(batch),
236
+ state: JSON.parse(state),
237
+ })),
238
+ };
239
+ },
240
+ async pending(locator, id) {
241
+ const { state, room } = await authored.ask({ kind: 'authored.pending', locator, id });
242
+ return { state: state === null ? undefined : JSON.parse(state), room };
243
+ },
244
+ facts: (async (names) => {
245
+ const held = await authored.ask({ kind: 'replica.facts', names: names ?? null });
246
+ return Object.fromEntries((names ?? Object.keys(UNSTATED)).map((name) => [
247
+ name,
248
+ json(held[name], UNSTATED[name]),
249
+ ]));
250
+ }),
251
+ async presentation(app) {
252
+ const held = await authored.ask({ kind: 'replica.presentation', app });
253
+ return held === null ? undefined : JSON.parse(held);
254
+ },
255
+ async demote() {
256
+ await authored.ask({ kind: 'replica.demote' });
257
+ },
258
+ query(plan, rooms, follows, budget) {
259
+ return authored.ask({ kind: 'replica.query', plan, rooms, follows, budget });
260
+ },
261
+ named(plan, rooms, handles) {
262
+ return authored.ask({ kind: 'replica.named', plan, rooms, handles });
263
+ },
264
+ changes(keys) {
265
+ return keys.reduce((total, key) => total + (changed.get(key) ?? 0), 0);
266
+ },
267
+ entries(key, view, paths) {
268
+ return authored.ask({ kind: 'replica.entries', key, view, paths });
269
+ },
270
+ typed(key, view, paths) {
271
+ return authored.ask({ kind: 'replica.typed', key, view, paths });
272
+ },
273
+ referrers(key, view, targets) {
274
+ return authored.ask({ kind: 'replica.referrers', key, view, targets });
275
+ },
276
+ holders(key, view, sought) {
277
+ return authored.ask({ kind: 'replica.holders', key, view, sought });
278
+ },
279
+ folders(key, paths) {
280
+ return authored.ask({ kind: 'replica.folders', key, paths });
281
+ },
282
+ typedWithin(key, view, roots, within) {
283
+ return authored.ask({ kind: 'replica.typedWithin', key, view, roots, within });
284
+ },
285
+ stage(record, composition, page) {
286
+ return authored.ask({
287
+ kind: 'replica.stage',
288
+ locator: record.locator,
289
+ transfer: record.transfer,
290
+ key: record.key,
291
+ fingerprint: composedOf(composition).fingerprint,
292
+ entries: page.entries,
293
+ folders: page.folders,
294
+ part: page.part ?? null,
295
+ });
296
+ },
297
+ resume(record, composition, parts, published) {
298
+ return authored.ask({
299
+ kind: 'replica.resume',
300
+ locator: record.locator,
301
+ transfer: record.transfer,
302
+ fingerprint: composedOf(composition).fingerprint,
303
+ parts,
304
+ published,
305
+ });
306
+ },
307
+ async refresh(key, composition, page) {
308
+ await authored.ask({
309
+ kind: 'replica.refresh',
310
+ key,
311
+ composed: composedOf(composition),
312
+ entries: page.entries,
313
+ removals: page.removals,
314
+ folders: page.folders,
315
+ folderRemovals: page.folderRemovals,
316
+ });
317
+ },
318
+ async unrefresh(key) {
319
+ await authored.ask({ kind: 'replica.unrefresh', key });
320
+ },
321
+ commit({ rooms, writes = [], files = [], whole = false }) {
322
+ for (const room of rooms)
323
+ change(room.key);
324
+ return authored.ask({
325
+ kind: 'replica.commit',
326
+ ...(writes.length === 0 && files.length === 0
327
+ ? {}
328
+ : { authored: { writes: writes.map(authoredRows), files, whole } }),
329
+ rooms,
330
+ });
331
+ },
332
+ async fence(locators) {
333
+ await authored.ask({ kind: 'replica.fence', locators });
334
+ },
335
+ async erase(locator, limit) {
336
+ return (await authored.ask({ kind: 'replica.erase', locator, limit })).remaining;
337
+ },
338
+ async abandon(locator) {
339
+ await authored.ask({ kind: 'replica.abandon', locator });
340
+ },
341
+ async unfence(locators) {
342
+ return new Set(await authored.ask({ kind: 'replica.unfence', locators }));
343
+ },
344
+ async release(key) {
345
+ await authored.ask({ kind: 'replica.release', key });
346
+ },
347
+ async rederive(key, composition, bytes, ms, floor) {
348
+ change(key);
349
+ return authored.ask({
350
+ kind: 'replica.rederive',
351
+ key,
352
+ composed: composedOf(composition),
353
+ bytes,
354
+ ms,
355
+ floor,
356
+ });
357
+ },
358
+ async fact(name, value) {
359
+ await authored.ask({ kind: 'replica.fact', name, value: JSON.stringify(value) });
360
+ },
361
+ submit(locator, id, submission, lost) {
362
+ return amend(locator, id, { submission, lost });
363
+ },
364
+ keepUpload(locator, id, upload) {
365
+ return amend(locator, id, { upload });
366
+ },
367
+ async roomDrafts(locator, paths) {
368
+ const held = await authored.ask({
369
+ kind: 'authored.roomDrafts',
370
+ locator: locator ?? null,
371
+ paths: paths ?? null,
372
+ });
373
+ return held.map((record) => JSON.parse(record));
374
+ },
375
+ async present(record) {
376
+ await authored.ask({
377
+ kind: 'replica.present',
378
+ app: record.app,
379
+ value: JSON.stringify(record.value ?? null),
380
+ });
381
+ },
382
+ conversations(conversations) {
383
+ return authored.ask({ kind: 'conversation.held', conversations: conversations ?? null });
384
+ },
385
+ async keepMessages(write) {
386
+ await authored.ask({ kind: 'conversation.keep', ...write });
387
+ },
388
+ messageWindow(conversation, limit, before, phrase = null) {
389
+ return authored.ask({ kind: 'conversation.window', conversation, limit, before, phrase });
390
+ },
391
+ messageCount(conversation, phrase = null) {
392
+ return authored.ask({ kind: 'conversation.count', conversation, phrase });
393
+ },
394
+ turnArrived(conversation, turn) {
395
+ return authored.ask({ kind: 'conversation.turn', conversation, turn });
396
+ },
397
+ conversationRows(conversations) {
398
+ return authored.ask({ kind: 'conversation.rows', conversations });
399
+ },
400
+ conversationFacts() {
401
+ return authored.ask({ kind: 'conversation.facts' });
402
+ },
403
+ async keepConversationFact(fact) {
404
+ await authored.ask({ kind: 'conversation.fact', ...fact });
405
+ },
406
+ storedConversations() {
407
+ return authored.ask({ kind: 'conversation.stored' });
408
+ },
409
+ dropConversations(conversations) {
410
+ return authored.ask({ kind: 'conversation.drop', conversations });
411
+ },
412
+ async chatDrafts() {
413
+ const records = await authored.ask({ kind: 'authored.chatDrafts' });
414
+ return records.map((record) => JSON.parse(record));
415
+ },
416
+ async chatDraft(conversation) {
417
+ const record = await authored.ask({ kind: 'authored.chatDraft.read', conversation });
418
+ return record === null ? null : JSON.parse(record);
419
+ },
420
+ async keepChatDrafts(records) {
421
+ await authored.ask({
422
+ kind: 'authored.chatDraft',
423
+ kept: records.map((record) => ({
424
+ conversation: record.conversation,
425
+ record: JSON.stringify(record),
426
+ })),
427
+ dropped: [],
428
+ });
429
+ },
430
+ async dropChatDraft(conversation) {
431
+ await authored.ask({ kind: 'authored.chatDraft', kept: [], dropped: [conversation] });
432
+ },
433
+ async calls() {
434
+ return restored(await authored.ask({ kind: 'authored.calls' }));
435
+ },
436
+ async keepCall(record) {
437
+ const { stored, ...kept } = keyed(keys, record);
438
+ await authored.ask({
439
+ kind: 'authored.call',
440
+ operation: record.operation,
441
+ kept,
442
+ files: stored,
443
+ });
444
+ },
445
+ async dropCall(operation) {
446
+ await authored.ask({ kind: 'authored.call', operation, kept: null, files: [] });
447
+ },
448
+ async keepRoomDraft(record, files) {
449
+ const { path, ...kept } = roomDraftRow(record);
450
+ await authored.ask({
451
+ kind: 'authored.roomDraft',
452
+ locator: record.locator,
453
+ path,
454
+ kept,
455
+ files,
456
+ });
457
+ },
458
+ async discardRoomDraft(locator, path) {
459
+ await authored.ask({ kind: 'authored.roomDraft', locator, path, kept: null, files: [] });
460
+ },
461
+ fences() {
462
+ return authored.ask({ kind: 'authored.fences' });
463
+ },
464
+ generation() {
465
+ return fact('generation');
466
+ },
467
+ async rememberGeneration(value) {
468
+ await authored.ask({ kind: 'authored.remember', name: 'generation', value });
469
+ },
470
+ file(key, type) {
471
+ return authored.ask({ kind: 'authored.file', key, type });
472
+ },
473
+ };
474
+ }
@@ -0,0 +1,8 @@
1
+ export type RoomHeld<T> = {
2
+ of(locator: string, key: string): T | undefined;
3
+ hold(locator: string, key: string, value: T): void;
4
+ drop(locator: string, key: string): void;
5
+ forget(locator: string): void;
6
+ };
7
+ export declare function createRoomHeld<T>(): RoomHeld<T>;
8
+ //# sourceMappingURL=room-held.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"room-held.d.ts","sourceRoot":"","sources":["../../src/store/room-held.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;IACxB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACnD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AAEF,wBAAgB,cAAc,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAgB/C"}
@@ -0,0 +1,17 @@
1
+ export function createRoomHeld() {
2
+ const rooms = new Map();
3
+ return {
4
+ of: (locator, key) => rooms.get(locator)?.get(key),
5
+ hold(locator, key, value) {
6
+ const room = rooms.get(locator) ?? new Map();
7
+ room.set(key, value);
8
+ rooms.set(locator, room);
9
+ },
10
+ drop(locator, key) {
11
+ rooms.get(locator)?.delete(key);
12
+ },
13
+ forget(locator) {
14
+ rooms.delete(locator);
15
+ },
16
+ };
17
+ }
@@ -0,0 +1,8 @@
1
+ import type { ListedEntry, Listing } from '../listing.js';
2
+ export type RoomsShown = {
3
+ now(): Listing | null;
4
+ show(listing: Listing | null): void;
5
+ patch(entries: readonly ListedEntry[]): void;
6
+ };
7
+ export declare function createRoomsShown(): RoomsShown;
8
+ //# sourceMappingURL=rooms-shown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rooms-shown.d.ts","sourceRoot":"","sources":["../../src/store/rooms-shown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,IAAI,OAAO,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC;IACpC,KAAK,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,CAAC;CAC9C,CAAC;AAEF,wBAAgB,gBAAgB,IAAI,UAAU,CAW7C"}
@@ -0,0 +1,13 @@
1
+ export function createRoomsShown() {
2
+ let shown = null;
3
+ return {
4
+ now: () => shown,
5
+ show(listing) {
6
+ shown = listing === null ? null : new Map(listing);
7
+ },
8
+ patch(entries) {
9
+ for (const entry of entries)
10
+ shown?.set(entry.locator, entry);
11
+ },
12
+ };
13
+ }
@@ -0,0 +1,11 @@
1
+ import type { RuntimeDatabase } from '../tables.js';
2
+ export type Space = {
3
+ full(): boolean;
4
+ fill(): boolean;
5
+ probing(): boolean;
6
+ probeEachMinute(): void;
7
+ probe(): Promise<void>;
8
+ stop(): void;
9
+ };
10
+ export declare function createSpace(database: RuntimeDatabase, freed: () => void): Space;
11
+ //# sourceMappingURL=space.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"space.d.ts","sourceRoot":"","sources":["../../src/store/space.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,IAAI,OAAO,CAAC;IAChB,IAAI,IAAI,OAAO,CAAC;IAChB,OAAO,IAAI,OAAO,CAAC;IACnB,eAAe,IAAI,IAAI,CAAC;IACxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,IAAI,IAAI,CAAC;CACd,CAAC;AAEF,wBAAgB,WAAW,CAAC,QAAQ,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,IAAI,GAAG,KAAK,CA0C/E"}
@@ -0,0 +1,41 @@
1
+ export function createSpace(database, freed) {
2
+ let full = false;
3
+ let probing = null;
4
+ let testing = null;
5
+ function probe() {
6
+ testing ??= database.ask({ kind: 'space.probe' }).then(() => {
7
+ testing = null;
8
+ if (full) {
9
+ full = false;
10
+ if (probing !== null)
11
+ clearInterval(probing);
12
+ probing = null;
13
+ freed();
14
+ }
15
+ }, () => {
16
+ testing = null;
17
+ });
18
+ return testing;
19
+ }
20
+ return {
21
+ full: () => full,
22
+ fill() {
23
+ if (full)
24
+ return false;
25
+ full = true;
26
+ return true;
27
+ },
28
+ probing: () => probing !== null,
29
+ probeEachMinute() {
30
+ // A device whose storage filled after its install tries a write each minute, so space freed elsewhere ends its read-only mode without a Retry.
31
+ probing = setInterval(() => {
32
+ void probe();
33
+ }, 60_000);
34
+ },
35
+ probe,
36
+ stop() {
37
+ if (probing !== null)
38
+ clearInterval(probing);
39
+ },
40
+ };
41
+ }
@@ -0,0 +1,17 @@
1
+ export type Watcher = {
2
+ held(): boolean;
3
+ stop(): void;
4
+ answer(value: unknown): void;
5
+ };
6
+ export type Watching = 'all' | 'waiting' | 'ready';
7
+ type Watchers = {
8
+ publication(work: () => Promise<void>): Promise<void>;
9
+ owing<T>(topic: string, add: (owed: T | undefined) => T, work: (owed: T) => Promise<void>): Promise<void>;
10
+ watch(topic: string, notify: (value: unknown) => void): Watcher;
11
+ watching(topic: string, which?: Watching): readonly Watcher[];
12
+ tell(topic: string, value: unknown): void;
13
+ close(): void;
14
+ };
15
+ export declare function createWatchers(unpublished: (error: unknown) => void): Watchers;
16
+ export {};
17
+ //# sourceMappingURL=watchers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watchers.d.ts","sourceRoot":"","sources":["../../src/store/watchers.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,IAAI,OAAO,CAAC;IAChB,IAAI,IAAI,IAAI,CAAC;IACb,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,SAAS,GAAG,OAAO,CAAC;AAMnD,KAAK,QAAQ,GAAG;IACd,WAAW,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,KAAK,CAAC,CAAC,EACL,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,KAAK,CAAC,EAC/B,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAC/B,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC;IAChE,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,SAAS,OAAO,EAAE,CAAC;IAC9D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1C,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAEF,wBAAgB,cAAc,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,QAAQ,CA6D9E"}
@@ -0,0 +1,56 @@
1
+ export function createWatchers(unpublished) {
2
+ let published = Promise.resolve();
3
+ const topics = new Map();
4
+ const owed = new Map();
5
+ function publication(work) {
6
+ published = published.then(work).catch(unpublished);
7
+ return published;
8
+ }
9
+ return {
10
+ publication,
11
+ owing(topic, add, work) {
12
+ const held = owed.get(topic);
13
+ if (held !== undefined) {
14
+ held.value = add(held.value);
15
+ return held.shown;
16
+ }
17
+ const owing = { value: add(undefined), shown: Promise.resolve() };
18
+ owed.set(topic, owing);
19
+ owing.shown = publication(async () => {
20
+ owed.delete(topic);
21
+ await work(owing.value);
22
+ });
23
+ return owing.shown;
24
+ },
25
+ watch(topic, notify) {
26
+ const held = topics.get(topic) ?? new Set();
27
+ topics.set(topic, held);
28
+ const watcher = {
29
+ ready: false,
30
+ held: () => topics.get(topic)?.has(watcher) === true,
31
+ stop() {
32
+ const on = topics.get(topic);
33
+ on?.delete(watcher);
34
+ if (on?.size === 0)
35
+ topics.delete(topic);
36
+ },
37
+ answer(value) {
38
+ watcher.ready = true;
39
+ notify(value);
40
+ },
41
+ };
42
+ held.add(watcher);
43
+ return watcher;
44
+ },
45
+ watching(topic, which = 'all') {
46
+ return [...(topics.get(topic) ?? [])].filter(({ ready }) => which === 'all' || ready === (which === 'ready'));
47
+ },
48
+ tell(topic, value) {
49
+ for (const watcher of topics.get(topic) ?? [])
50
+ watcher.answer(value);
51
+ },
52
+ close() {
53
+ topics.clear();
54
+ },
55
+ };
56
+ }