@agentshouse/mdruntime 0.1.0-c588e78cf6975 → 0.1.0-c59a5a6bd2f31

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 (201) hide show
  1. package/README.md +2 -2
  2. package/dist/acceptance.d.ts +26 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +384 -0
  5. package/dist/adapter.d.ts +38 -25
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/attached-model.d.ts +3 -10
  8. package/dist/attached-model.d.ts.map +1 -1
  9. package/dist/attached-model.js +21 -56
  10. package/dist/bootstrap.d.ts +8 -4
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +209 -78
  13. package/dist/chain.d.ts +2 -1
  14. package/dist/chain.d.ts.map +1 -1
  15. package/dist/change.d.ts +1 -0
  16. package/dist/change.d.ts.map +1 -1
  17. package/dist/chat-types.d.ts +3 -0
  18. package/dist/chat-types.d.ts.map +1 -0
  19. package/dist/chat-types.js +2 -0
  20. package/dist/client.d.ts +14 -4
  21. package/dist/client.d.ts.map +1 -1
  22. package/dist/client.js +3 -0
  23. package/dist/collection.d.ts +2 -1
  24. package/dist/collection.d.ts.map +1 -1
  25. package/dist/compile.d.ts +7 -7
  26. package/dist/compile.d.ts.map +1 -1
  27. package/dist/compile.js +229 -297
  28. package/dist/connection.d.ts +19 -43
  29. package/dist/connection.d.ts.map +1 -1
  30. package/dist/connection.js +1325 -3586
  31. package/dist/context.d.ts +2 -0
  32. package/dist/context.d.ts.map +1 -0
  33. package/dist/context.js +7 -0
  34. package/dist/conversation-row.d.ts +33 -0
  35. package/dist/conversation-row.d.ts.map +1 -0
  36. package/dist/conversation-row.js +47 -0
  37. package/dist/conversation.d.ts +18 -9
  38. package/dist/conversation.d.ts.map +1 -1
  39. package/dist/conversation.js +375 -224
  40. package/dist/durability.d.ts +6 -0
  41. package/dist/durability.d.ts.map +1 -1
  42. package/dist/entry.d.ts +2 -2
  43. package/dist/entry.d.ts.map +1 -1
  44. package/dist/entry.js +17 -8
  45. package/dist/figures.d.ts +48 -0
  46. package/dist/figures.d.ts.map +1 -0
  47. package/dist/figures.js +197 -0
  48. package/dist/host.d.ts +4 -5
  49. package/dist/host.d.ts.map +1 -1
  50. package/dist/host.js +22 -21
  51. package/dist/identity.d.ts +0 -1
  52. package/dist/identity.d.ts.map +1 -1
  53. package/dist/identity.js +0 -3
  54. package/dist/index.d.ts +18 -8
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +5 -1
  57. package/dist/install.d.ts +86 -0
  58. package/dist/install.d.ts.map +1 -0
  59. package/dist/install.js +537 -0
  60. package/dist/job.d.ts +33 -0
  61. package/dist/job.d.ts.map +1 -0
  62. package/dist/job.js +54 -0
  63. package/dist/live.d.ts +5 -4
  64. package/dist/live.d.ts.map +1 -1
  65. package/dist/live.js +62 -20
  66. package/dist/log.d.ts +1 -0
  67. package/dist/log.d.ts.map +1 -1
  68. package/dist/memory.d.ts +4 -1
  69. package/dist/memory.d.ts.map +1 -1
  70. package/dist/memory.js +43 -4
  71. package/dist/messages.d.ts +27 -3
  72. package/dist/messages.d.ts.map +1 -1
  73. package/dist/messages.js +97 -19
  74. package/dist/model.d.ts +2 -9
  75. package/dist/model.d.ts.map +1 -1
  76. package/dist/model.js +0 -9
  77. package/dist/observation.d.ts +2 -2
  78. package/dist/observation.d.ts.map +1 -1
  79. package/dist/observation.js +7 -2
  80. package/dist/outcome.d.ts +1 -0
  81. package/dist/outcome.d.ts.map +1 -1
  82. package/dist/outcome.js +3 -0
  83. package/dist/overlay.d.ts +1 -0
  84. package/dist/overlay.d.ts.map +1 -1
  85. package/dist/overlay.js +11 -0
  86. package/dist/parts.d.ts +59 -0
  87. package/dist/parts.d.ts.map +1 -0
  88. package/dist/parts.js +118 -0
  89. package/dist/query.d.ts +13 -210
  90. package/dist/query.d.ts.map +1 -1
  91. package/dist/query.js +3 -508
  92. package/dist/questions.d.ts +32 -0
  93. package/dist/questions.d.ts.map +1 -0
  94. package/dist/questions.js +118 -0
  95. package/dist/reach.d.ts +11 -11
  96. package/dist/reach.d.ts.map +1 -1
  97. package/dist/reach.js +166 -113
  98. package/dist/react.d.ts +4 -2
  99. package/dist/react.d.ts.map +1 -1
  100. package/dist/read.d.ts +7 -0
  101. package/dist/read.d.ts.map +1 -0
  102. package/dist/read.js +17 -0
  103. package/dist/readiness.d.ts +0 -2
  104. package/dist/readiness.d.ts.map +1 -1
  105. package/dist/reads.d.ts +35 -0
  106. package/dist/reads.d.ts.map +1 -0
  107. package/dist/reads.js +128 -0
  108. package/dist/recovery.d.ts.map +1 -1
  109. package/dist/recovery.js +9 -1
  110. package/dist/refresh.d.ts +1 -1
  111. package/dist/refresh.d.ts.map +1 -1
  112. package/dist/refresh.js +8 -20
  113. package/dist/replica.d.ts +8 -8
  114. package/dist/replica.d.ts.map +1 -1
  115. package/dist/replica.js +50 -18
  116. package/dist/room-draft.d.ts +3 -2
  117. package/dist/room-draft.d.ts.map +1 -1
  118. package/dist/room-draft.js +4 -4
  119. package/dist/room-drafts.d.ts +29 -0
  120. package/dist/room-drafts.d.ts.map +1 -0
  121. package/dist/room-drafts.js +216 -0
  122. package/dist/rows.d.ts +14 -22
  123. package/dist/rows.d.ts.map +1 -1
  124. package/dist/rows.js +48 -189
  125. package/dist/save.d.ts.map +1 -1
  126. package/dist/save.js +11 -8
  127. package/dist/saves.d.ts +96 -0
  128. package/dist/saves.d.ts.map +1 -0
  129. package/dist/saves.js +999 -0
  130. package/dist/search.d.ts +12 -63
  131. package/dist/search.d.ts.map +1 -1
  132. package/dist/search.js +9 -52
  133. package/dist/seed.d.ts +16 -2
  134. package/dist/seed.d.ts.map +1 -1
  135. package/dist/seed.js +66 -0
  136. package/dist/socket/admission.d.ts +7 -0
  137. package/dist/socket/admission.d.ts.map +1 -0
  138. package/dist/socket/admission.js +39 -0
  139. package/dist/socket/answers.d.ts +6 -0
  140. package/dist/socket/answers.d.ts.map +1 -0
  141. package/dist/socket/answers.js +20 -0
  142. package/dist/socket/reads.d.ts +10 -0
  143. package/dist/socket/reads.d.ts.map +1 -0
  144. package/dist/socket/reads.js +31 -0
  145. package/dist/socket.d.ts +43 -0
  146. package/dist/socket.d.ts.map +1 -0
  147. package/dist/socket.js +96 -0
  148. package/dist/source.d.ts +61 -0
  149. package/dist/source.d.ts.map +1 -0
  150. package/dist/source.js +81 -0
  151. package/dist/status.d.ts +0 -2
  152. package/dist/status.d.ts.map +1 -1
  153. package/dist/status.js +0 -6
  154. package/dist/store/fences.d.ts +16 -0
  155. package/dist/store/fences.d.ts.map +1 -0
  156. package/dist/store/fences.js +26 -0
  157. package/dist/store/installs.d.ts +30 -0
  158. package/dist/store/installs.d.ts.map +1 -0
  159. package/dist/store/installs.js +34 -0
  160. package/dist/store/records.d.ts +212 -0
  161. package/dist/store/records.d.ts.map +1 -0
  162. package/dist/store/records.js +408 -0
  163. package/dist/store/room-held.d.ts +8 -0
  164. package/dist/store/room-held.d.ts.map +1 -0
  165. package/dist/store/room-held.js +17 -0
  166. package/dist/store/watchers.d.ts +15 -0
  167. package/dist/store/watchers.d.ts.map +1 -0
  168. package/dist/store/watchers.js +36 -0
  169. package/dist/store/writes.d.ts +24 -0
  170. package/dist/store/writes.d.ts.map +1 -0
  171. package/dist/store/writes.js +125 -0
  172. package/dist/store.d.ts +78 -156
  173. package/dist/store.d.ts.map +1 -1
  174. package/dist/store.js +117 -401
  175. package/dist/stored.d.ts +58 -65
  176. package/dist/stored.d.ts.map +1 -1
  177. package/dist/stored.js +264 -243
  178. package/dist/tables.d.ts +107 -51
  179. package/dist/tables.d.ts.map +1 -1
  180. package/dist/tables.js +193 -59
  181. package/dist/tallies.d.ts +18 -0
  182. package/dist/tallies.d.ts.map +1 -0
  183. package/dist/tallies.js +129 -0
  184. package/dist/validation.d.ts.map +1 -1
  185. package/dist/validation.js +7 -4
  186. package/dist/windows.d.ts +1 -12
  187. package/dist/windows.d.ts.map +1 -1
  188. package/dist/windows.js +2 -75
  189. package/dist/wire.d.ts +14 -0
  190. package/dist/wire.d.ts.map +1 -1
  191. package/dist/wire.js +5 -0
  192. package/package.json +2 -2
  193. package/dist/fence.d.ts +0 -6
  194. package/dist/fence.d.ts.map +0 -1
  195. package/dist/fence.js +0 -10
  196. package/dist/fulltext.d.ts +0 -27
  197. package/dist/fulltext.d.ts.map +0 -1
  198. package/dist/fulltext.js +0 -370
  199. package/dist/words.d.ts +0 -19
  200. package/dist/words.d.ts.map +0 -1
  201. package/dist/words.js +0 -156
package/dist/store.js CHANGED
@@ -1,408 +1,124 @@
1
- import { composedOf } from './collection.js';
2
- import { binaryLocalId } from './identity.js';
3
- const FILE = '\u0000file';
4
- function batchFiles(batch) {
5
- return batch.changes.flatMap((change) => (change.kind === 'binary' ? [change.localId] : []));
6
- }
7
- function draftFiles(drafts) {
8
- return drafts.flatMap(({ parts }) => (parts.file === undefined ? [] : [parts.file.localId]));
9
- }
10
- function roomDraftRow(record) {
11
- return { path: record.path, record: JSON.stringify(record), files: draftFiles([record]) };
12
- }
13
- function authoredRows({ locator, queue, founded, saved, roomDrafts, consumedRoomDrafts }, held) {
14
- return {
15
- locator,
16
- ...(queue === undefined
17
- ? {}
18
- : {
19
- order: queue.map(({ id }) => id),
20
- added: queue
21
- .filter(({ id }) => held?.has(id) !== true)
22
- .map((batch) => {
23
- const drafts = saved?.get(batch.id) ?? [];
24
- return {
25
- id: batch.id,
26
- batch: JSON.stringify(batch),
27
- state: JSON.stringify({
28
- drafts,
29
- submission: { state: 'waiting' },
30
- lost: false,
31
- }),
32
- files: [...batchFiles(batch), ...draftFiles(drafts)],
33
- };
34
- }),
35
- }),
36
- ...(founded === undefined
37
- ? {}
38
- : {
39
- founded: founded.map((batch) => ({
40
- id: batch.id,
41
- batch: JSON.stringify(batch),
42
- files: batchFiles(batch),
43
- })),
44
- }),
45
- ...(roomDrafts === undefined ? {} : { roomDrafts: roomDrafts.map(roomDraftRow) }),
46
- ...(consumedRoomDrafts === undefined ? {} : { consumedRoomDrafts }),
47
- };
48
- }
49
- function marked(value) {
50
- return typeof value === 'object' && value !== null && FILE in value;
51
- }
52
- function keyed(keys, value) {
53
- const stored = [];
54
- const files = [];
55
- const record = JSON.stringify(value, (_name, held) => {
56
- if (!(held instanceof Blob))
57
- return held;
58
- let key = keys.get(held);
59
- if (key === undefined) {
60
- key = binaryLocalId();
61
- keys.set(held, key);
62
- }
63
- stored.push({ key, blob: held });
64
- files.push(key);
65
- return { [FILE]: key, type: held.type };
66
- });
67
- return { record, files, stored };
68
- }
69
- async function filed(value, read) {
70
- if (Array.isArray(value))
71
- return Promise.all(value.map((item) => filed(item, read)));
72
- if (marked(value))
73
- return read(value[FILE], value.type);
74
- if (typeof value !== 'object' || value === null)
75
- return value;
76
- const restored = {};
77
- for (const [name, item] of Object.entries(value))
78
- restored[name] = await filed(item, read);
79
- return restored;
80
- }
81
- function json(value, fallback) {
82
- return value === undefined ? fallback : JSON.parse(value);
83
- }
84
- export function openRuntimeStore(fenced, authored) {
85
- const keys = new WeakMap();
86
- const read = async (key, type) => {
87
- const blob = await authored.ask({ kind: 'authored.file', key, type });
88
- keys.set(blob, key);
89
- return blob;
90
- };
91
- const restored = async (records) => Promise.all(records.map(async (record) => (await filed(JSON.parse(record), read))));
92
- const amend = async (locator, id, amendment) => {
93
- if (fenced(locator))
94
- return;
95
- await authored.ask({
96
- kind: 'authored.amend',
97
- locator,
98
- id,
99
- amendment: JSON.stringify(amendment),
1
+ import { schemaTypes } from './attached-model.js';
2
+ import { openedFiles } from './opened.js';
3
+ import { compositionOf } from './replica.js';
4
+ import { createFences } from './store/fences.js';
5
+ import { createInstalls } from './store/installs.js';
6
+ import { openRuntimeStore, } from './store/records.js';
7
+ import { createRoomHeld } from './store/room-held.js';
8
+ import { createWatchers } from './store/watchers.js';
9
+ import { createWrites } from './store/writes.js';
10
+ export { NO_INSTALL } from './store/installs.js';
11
+ export function createStore(options) {
12
+ const writes = createWrites();
13
+ const watchers = createWatchers(options.unpublished);
14
+ const fences = createFences();
15
+ const installs = createInstalls();
16
+ const seeds = new Map();
17
+ const landed = createRoomHeld();
18
+ const attached = createRoomHeld();
19
+ const typesHeld = new Map();
20
+ let opening;
21
+ function open() {
22
+ opening ??= options.opening(openRuntimeStore(options.database)).catch((error) => {
23
+ opening = undefined;
24
+ throw error;
100
25
  });
101
- };
102
- const fact = (name) => authored.ask({ kind: 'authored.fact', name });
103
- const queued = new Map();
104
- const changed = new Map();
105
- const change = (key) => changed.set(key, (changed.get(key) ?? 0) + 1);
106
- const rows = (writes) => writes.map((write) => authoredRows(write, queued.get(write.locator)));
107
- const noted = (writes) => {
108
- for (const { locator, queue } of writes) {
109
- if (queue !== undefined)
110
- queued.set(locator, new Set(queue.map(({ id }) => id)));
111
- }
112
- };
26
+ return opening;
27
+ }
28
+ function typed(locator, persisted) {
29
+ if (persisted.status === 'unavailable')
30
+ return persisted;
31
+ const schema = persisted.snapshot.schema;
32
+ const held = typesHeld.get(locator);
33
+ if (held !== undefined && held.schema === schema)
34
+ return { ...persisted, types: held.types };
35
+ const types = schemaTypes(schema, options.roomTypes);
36
+ typesHeld.set(locator, { schema, types });
37
+ return { ...persisted, types };
38
+ }
39
+ function recordOf(stored) {
40
+ return { ...stored, model: typed(stored.locator, stored.model) };
41
+ }
42
+ async function rooms(locators) {
43
+ const held = await (await open()).rooms(locators);
44
+ return new Map(held
45
+ .filter(({ record }) => !fences.has(record.locator))
46
+ .map(({ record, indexed, documents }) => [
47
+ record.locator,
48
+ { record: recordOf(record), indexed, documents },
49
+ ]));
50
+ }
51
+ async function work(locator) {
52
+ if (fences.has(locator))
53
+ return { replica: undefined, queue: [], states: new Map() };
54
+ const { room, queue } = await (await open()).room(locator);
55
+ const batches = queue.map(({ batch }) => batch);
56
+ const states = new Map(queue.map(({ batch, state }) => [batch.id, state]));
57
+ return {
58
+ replica: room === null
59
+ ? undefined
60
+ : { record: recordOf(room.record), queue: batches, states, overlaid: room.overlaid },
61
+ queue: batches,
62
+ states,
63
+ };
64
+ }
65
+ async function drafts(locator, paths) {
66
+ const held = await (await open()).roomDrafts(locator, paths);
67
+ return held.filter((record) => !fences.has(record.locator));
68
+ }
113
69
  return {
114
- async opened() {
115
- const held = await authored.ask({ kind: 'replica.open' });
116
- const unindexed = new Set(held.keys.flatMap(({ key, rederiving, searching }) => rederiving === null && searching === null ? [] : [key]));
117
- const overlaid = new Map();
118
- for (const { key, path } of held.overlaid) {
119
- const paths = overlaid.get(key) ?? new Set();
120
- paths.add(path);
121
- overlaid.set(key, paths);
122
- }
70
+ open,
71
+ durably: (work) => writes.exclusive(async () => {
72
+ const local = await open();
73
+ return work(local);
74
+ }),
75
+ exclusive: writes.exclusive,
76
+ gathered: writes.gathered,
77
+ written: writes.written,
78
+ startingWrite: writes.startingWrite,
79
+ finishingWrite: writes.finishingWrite,
80
+ ahead: writes.ahead,
81
+ rederive: writes.rederive,
82
+ refreshPage: writes.refreshPage,
83
+ stageBytes: writes.stageBytes,
84
+ deriveBytes: writes.deriveBytes,
85
+ rooms,
86
+ record: async (locator) => (await rooms([locator])).get(locator)?.record,
87
+ work,
88
+ replica: async (locator) => (await work(locator)).replica,
89
+ async covering() {
90
+ const held = await (await open()).covering();
123
91
  return {
124
- rooms: new Map(held.rooms
125
- .filter(({ locator }) => !fenced(locator))
126
- .map(({ locator, key, record }) => [
127
- locator,
128
- { ...JSON.parse(record), key },
129
- ])),
130
- unindexed,
131
- overlaid,
132
- erasing: held.erasing.length > 0,
133
- orphans: held.orphans,
134
- lastCompleted: json(held.facts.lastCompleted, null),
135
- providerLimits: json(held.facts.providerLimits, []),
136
- capabilities: json(held.facts.capabilities, []),
137
- member: json(held.facts.member, null),
138
- targets: json(held.facts.targets, {}),
139
- presentation: held.presentation.map(({ app, value }) => ({
140
- app,
141
- value: JSON.parse(value),
142
- })),
143
- conversationList: json(held.facts.conversationList, null),
144
- conversationCursor: json(held.facts.conversationCursor, null),
92
+ rooms: new Map([...held.rooms].filter(([locator]) => !fences.has(locator))),
93
+ queues: new Map([...held.queues].filter(([locator]) => !fences.has(locator))),
145
94
  };
146
95
  },
147
- counts(rooms) {
148
- return authored.ask({ kind: 'replica.counts', rooms });
149
- },
150
- query(plan, rooms, budget) {
151
- return authored.ask({ kind: 'replica.query', plan, rooms, budget });
152
- },
153
- changes(keys) {
154
- return keys.reduce((total, key) => total + (changed.get(key) ?? 0), 0);
155
- },
156
- entries(key, view, paths) {
157
- return authored.ask({ kind: 'replica.entries', key, view, paths });
158
- },
159
- typed(key, view, paths) {
160
- return authored.ask({ kind: 'replica.typed', key, view, paths });
161
- },
162
- referrers(key, view, targets, kinds) {
163
- return authored.ask({ kind: 'replica.referrers', key, view, targets, kinds });
164
- },
165
- files(key, view, after, limit) {
166
- return authored.ask({ kind: 'replica.files', key, view, after, limit });
167
- },
168
- folders(key, view, paths) {
169
- return authored.ask({ kind: 'replica.folders', key, view, paths });
170
- },
171
- typedWithin(key, view, roots, within) {
172
- return authored.ask({ kind: 'replica.typedWithin', key, view, roots, within });
173
- },
174
- search(ask) {
175
- return authored.ask({ kind: 'replica.search', ...ask });
176
- },
177
- async stage(record, composition, page) {
178
- if (fenced(record.locator))
179
- return null;
180
- return authored.ask({
181
- kind: 'replica.stage',
182
- locator: record.locator,
183
- transfer: record.transfer,
184
- key: record.key,
185
- fingerprint: composedOf(composition).fingerprint,
186
- entries: page.entries,
187
- folders: page.folders,
188
- });
189
- },
190
- async refresh(key, composition, page) {
191
- await authored.ask({
192
- kind: 'replica.refresh',
193
- key,
194
- composed: composedOf(composition),
195
- entries: page.entries,
196
- removals: page.removals,
197
- folders: page.folders,
198
- folderRemovals: page.folderRemovals,
199
- });
200
- },
201
- async unrefresh(key) {
202
- await authored.ask({ kind: 'replica.unrefresh', key });
203
- },
204
- async hold(locator, key, composition, texts) {
205
- if (fenced(locator))
206
- return [];
207
- change(key);
208
- return authored.ask({
209
- kind: 'replica.hold',
210
- key,
211
- locator,
212
- composed: composedOf(composition),
213
- texts,
214
- });
215
- },
216
- async unhold(locator, key, composition) {
217
- if (fenced(locator))
218
- return { paths: [], bytes: 0 };
219
- change(key);
220
- return authored.ask({
221
- kind: 'replica.unhold',
222
- key,
223
- locator,
224
- composed: composedOf(composition),
225
- });
226
- },
227
- async wanted(locator, key) {
228
- if (fenced(locator))
229
- return [];
230
- return authored.ask({ kind: 'replica.wanted', key, locator });
231
- },
232
- async remember(locator, key, paths) {
233
- if (fenced(locator) || paths.length === 0)
234
- return;
235
- await authored.ask({ kind: 'replica.remember', key, locator, paths });
236
- },
237
- async commit({ rooms, writes = [], files = [], whole = false, discards = [] }) {
238
- const kept = whole ? writes : writes.filter(({ locator }) => !fenced(locator));
239
- const refused = whole ? kept.find(({ locator }) => fenced(locator)) : undefined;
240
- if (refused !== undefined) {
241
- return { fenced: refused.locator, counts: {}, changed: {}, indexed: {} };
242
- }
243
- for (const room of rooms)
244
- change(room.key);
245
- const committed = await authored.ask({
246
- kind: 'replica.commit',
247
- ...(kept.length === 0 && files.length === 0 && discards.length === 0
248
- ? {}
249
- : { authored: { writes: rows(kept), files, whole, discards } }),
250
- rooms: rooms.filter(({ locator }) => !fenced(locator)),
251
- });
252
- if (committed.fenced === null || !whole)
253
- noted(kept);
254
- for (const locator of discards)
255
- queued.delete(locator);
256
- return committed;
257
- },
258
- async fence(locators) {
259
- await authored.ask({ kind: 'replica.fence', locators });
260
- for (const locator of locators)
261
- queued.delete(locator);
262
- },
263
- async erase(locator, limit) {
264
- return (await authored.ask({ kind: 'replica.erase', locator, limit })).remaining;
265
- },
266
- async abandon(locator) {
267
- if (fenced(locator))
268
- return;
269
- await authored.ask({ kind: 'replica.abandon', locator });
270
- },
271
- async release(key) {
272
- await authored.ask({ kind: 'replica.release', key });
273
- },
274
- async rederive(key, composition, bytes, ms, floor) {
275
- change(key);
276
- return authored.ask({
277
- kind: 'replica.rederive',
278
- key,
279
- composed: composedOf(composition),
280
- bytes,
281
- ms,
282
- floor,
283
- });
284
- },
285
- async fact(name, value) {
286
- await authored.ask({ kind: 'replica.fact', name, value: JSON.stringify(value) });
287
- },
288
- async queues() {
289
- const { queues, pending } = await authored.ask({ kind: 'authored.queues' });
290
- queued.clear();
291
- for (const queue of queues)
292
- queued.set(queue.locator, new Set(queue.ids));
293
- const byId = new Map(pending.map((record) => [`${record.locator}\0${record.id}`, record]));
294
- return queues
295
- .filter((queue) => !fenced(queue.locator))
296
- .map((queue) => ({
297
- locator: queue.locator,
298
- pending: queue.ids.map((id) => {
299
- const record = byId.get(`${queue.locator}\0${id}`);
300
- if (record === undefined)
301
- throw new Error(`Missing Pending Change ${queue.locator}/${id}`);
302
- return {
303
- batch: JSON.parse(record.batch),
304
- state: JSON.parse(record.state),
305
- };
306
- }),
307
- }));
308
- },
309
- submit(locator, id, submission, lost) {
310
- return amend(locator, id, { submission, lost });
311
- },
312
- keepUpload(locator, id, upload) {
313
- return amend(locator, id, { upload });
314
- },
315
- async roomDrafts() {
316
- const held = await authored.ask({ kind: 'authored.roomDrafts' });
317
- return held
318
- .map((record) => JSON.parse(record))
319
- .filter((record) => !fenced(record.locator));
320
- },
321
- async present(record) {
322
- await authored.ask({
323
- kind: 'replica.present',
324
- app: record.app,
325
- value: JSON.stringify(record.value ?? null),
326
- });
327
- },
328
- conversations() {
329
- return authored.ask({ kind: 'conversation.held' });
330
- },
331
- async keepMessages(write) {
332
- await authored.ask({ kind: 'conversation.keep', ...write });
333
- },
334
- messageWindow(conversation, limit, before) {
335
- return authored.ask({ kind: 'conversation.window', conversation, limit, before });
336
- },
337
- messageCount(conversation) {
338
- return authored.ask({ kind: 'conversation.count', conversation });
339
- },
340
- turnArrived(conversation, turn) {
341
- return authored.ask({ kind: 'conversation.turn', conversation, turn });
342
- },
343
- async dropConversations(conversations) {
344
- await authored.ask({ kind: 'conversation.drop', conversations });
345
- },
346
- async chatDrafts() {
347
- const records = await authored.ask({ kind: 'authored.chatDrafts' });
348
- return records.map((record) => JSON.parse(record));
349
- },
350
- async keepChatDrafts(records) {
351
- await authored.ask({
352
- kind: 'authored.chatDraft',
353
- kept: records.map((record) => ({
354
- conversation: record.conversation,
355
- record: JSON.stringify(record),
356
- })),
357
- dropped: [],
358
- });
359
- },
360
- async dropChatDraft(conversation) {
361
- await authored.ask({ kind: 'authored.chatDraft', kept: [], dropped: [conversation] });
362
- },
363
- async calls() {
364
- return restored(await authored.ask({ kind: 'authored.calls' }));
365
- },
366
- async keepCall(record) {
367
- const { stored, ...kept } = keyed(keys, record);
368
- await authored.ask({
369
- kind: 'authored.call',
370
- operation: record.operation,
371
- kept,
372
- files: stored,
373
- });
374
- },
375
- async dropCall(operation) {
376
- await authored.ask({ kind: 'authored.call', operation, kept: null, files: [] });
377
- },
378
- async keepRoomDraft(record, files) {
379
- if (fenced(record.locator))
380
- return;
381
- const { path, ...kept } = roomDraftRow(record);
382
- await authored.ask({
383
- kind: 'authored.roomDraft',
384
- locator: record.locator,
385
- path,
386
- kept,
387
- files,
388
- });
389
- },
390
- async discardRoomDraft(locator, path) {
391
- if (fenced(locator))
392
- return;
393
- await authored.ask({ kind: 'authored.roomDraft', locator, path, kept: null, files: [] });
394
- },
395
- fences() {
396
- return authored.ask({ kind: 'authored.fences' });
397
- },
398
- generation() {
399
- return fact('generation');
400
- },
401
- async rememberGeneration(value) {
402
- await authored.ask({ kind: 'authored.remember', name: 'generation', value });
403
- },
404
- file(key, type) {
405
- return authored.ask({ kind: 'authored.file', key, type });
406
- },
96
+ drafts,
97
+ draft: async (locator, path) => (await drafts(locator, [path]))[0],
98
+ composed: (record) => compositionOf(record, options.builtIn, options.typedPaths),
99
+ publication: watchers.publication,
100
+ watch: watchers.watch,
101
+ watching: watchers.watching,
102
+ fences,
103
+ installs,
104
+ seeds: {
105
+ of: (key) => seeds.get(key),
106
+ keep(key, seed) {
107
+ seeds.set(key, seed);
108
+ },
109
+ drop(key) {
110
+ seeds.delete(key);
111
+ },
112
+ },
113
+ landed,
114
+ attached,
115
+ opened: openedFiles(options.database, fences.has),
116
+ part: (file, part) => options.database.ask({ kind: 'file.part', key: file, part }),
117
+ forget(locator) {
118
+ typesHeld.delete(locator);
119
+ landed.forget(locator);
120
+ attached.forget(locator);
121
+ },
122
+ close: watchers.close,
407
123
  };
408
124
  }