@agentshouse/mdruntime 0.1.0-ce5c5bb29be5a → 0.1.0-ce6bc9239a3ee

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 +81 -49
  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 +9 -5
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +209 -75
  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 +16 -6
  21. package/dist/client.d.ts.map +1 -1
  22. package/dist/client.js +3 -1
  23. package/dist/collection.d.ts +2 -1
  24. package/dist/collection.d.ts.map +1 -1
  25. package/dist/compile.d.ts +6 -6
  26. package/dist/compile.d.ts.map +1 -1
  27. package/dist/compile.js +262 -318
  28. package/dist/connection.d.ts +20 -44
  29. package/dist/connection.d.ts.map +1 -1
  30. package/dist/connection.js +1438 -3393
  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 +26 -17
  38. package/dist/conversation.d.ts.map +1 -1
  39. package/dist/conversation.js +441 -307
  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 -7
  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 -6
  49. package/dist/host.d.ts.map +1 -1
  50. package/dist/host.js +22 -26
  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 +63 -22
  66. package/dist/log.d.ts +1 -0
  67. package/dist/log.d.ts.map +1 -1
  68. package/dist/memory.d.ts +11 -4
  69. package/dist/memory.d.ts.map +1 -1
  70. package/dist/memory.js +171 -81
  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 +14 -209
  90. package/dist/query.d.ts.map +1 -1
  91. package/dist/query.js +3 -505
  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 +12 -12
  96. package/dist/reach.d.ts.map +1 -1
  97. package/dist/reach.js +182 -136
  98. package/dist/react.d.ts +5 -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 +36 -0
  106. package/dist/reads.d.ts.map +1 -0
  107. package/dist/reads.js +136 -0
  108. package/dist/recovery.d.ts.map +1 -1
  109. package/dist/recovery.js +9 -1
  110. package/dist/refresh.d.ts +6 -4
  111. package/dist/refresh.d.ts.map +1 -1
  112. package/dist/refresh.js +32 -4
  113. package/dist/replica.d.ts +8 -8
  114. package/dist/replica.d.ts.map +1 -1
  115. package/dist/replica.js +50 -15
  116. package/dist/room-draft.d.ts +4 -3
  117. package/dist/room-draft.d.ts.map +1 -1
  118. package/dist/room-draft.js +65 -52
  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 -21
  123. package/dist/rows.d.ts.map +1 -1
  124. package/dist/rows.js +48 -184
  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 -145
  173. package/dist/store.d.ts.map +1 -1
  174. package/dist/store.js +117 -367
  175. package/dist/stored.d.ts +58 -32
  176. package/dist/stored.d.ts.map +1 -1
  177. package/dist/stored.js +264 -187
  178. package/dist/tables.d.ts +107 -25
  179. package/dist/tables.d.ts.map +1 -1
  180. package/dist/tables.js +193 -47
  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 +15 -4
  190. package/dist/wire.d.ts.map +1 -1
  191. package/dist/wire.js +6 -1
  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,374 +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),
92
+ rooms: new Map([...held.rooms].filter(([locator]) => !fences.has(locator))),
93
+ queues: new Map([...held.queues].filter(([locator]) => !fences.has(locator))),
144
94
  };
145
95
  },
146
- counts(rooms) {
147
- return authored.ask({ kind: 'replica.counts', rooms });
148
- },
149
- query(plan, rooms, budget) {
150
- return authored.ask({ kind: 'replica.query', plan, rooms, budget });
151
- },
152
- changes(keys) {
153
- return keys.reduce((total, key) => total + (changed.get(key) ?? 0), 0);
154
- },
155
- entries(key, view, paths) {
156
- return authored.ask({ kind: 'replica.entries', key, view, paths });
157
- },
158
- typed(key, view, paths) {
159
- return authored.ask({ kind: 'replica.typed', key, view, paths });
160
- },
161
- referrers(key, view, targets, kinds) {
162
- return authored.ask({ kind: 'replica.referrers', key, view, targets, kinds });
163
- },
164
- files(key, view, after, limit) {
165
- return authored.ask({ kind: 'replica.files', key, view, after, limit });
166
- },
167
- folders(key, view, paths) {
168
- return authored.ask({ kind: 'replica.folders', key, view, paths });
169
- },
170
- typedWithin(key, view, roots, within) {
171
- return authored.ask({ kind: 'replica.typedWithin', key, view, roots, within });
172
- },
173
- search(ask) {
174
- return authored.ask({ kind: 'replica.search', ...ask });
175
- },
176
- async stage(record, composition, page) {
177
- if (fenced(record.locator))
178
- return null;
179
- return authored.ask({
180
- kind: 'replica.stage',
181
- locator: record.locator,
182
- transfer: record.transfer,
183
- key: record.key,
184
- fingerprint: composedOf(composition).fingerprint,
185
- entries: page.entries,
186
- folders: page.folders,
187
- });
188
- },
189
- async refresh(key, composition, page) {
190
- await authored.ask({
191
- kind: 'replica.refresh',
192
- key,
193
- composed: composedOf(composition),
194
- entries: page.entries,
195
- removals: page.removals,
196
- folders: page.folders,
197
- folderRemovals: page.folderRemovals,
198
- });
199
- },
200
- async unrefresh(key) {
201
- await authored.ask({ kind: 'replica.unrefresh', key });
202
- },
203
- async commit({ rooms, writes = [], files = [], whole = false, discards = [] }) {
204
- const kept = whole ? writes : writes.filter(({ locator }) => !fenced(locator));
205
- const refused = whole ? kept.find(({ locator }) => fenced(locator)) : undefined;
206
- if (refused !== undefined) {
207
- return { fenced: refused.locator, counts: {}, changed: {}, indexed: {} };
208
- }
209
- for (const room of rooms)
210
- change(room.key);
211
- const committed = await authored.ask({
212
- kind: 'replica.commit',
213
- ...(kept.length === 0 && files.length === 0 && discards.length === 0
214
- ? {}
215
- : { authored: { writes: rows(kept), files, whole, discards } }),
216
- rooms: rooms.filter(({ locator }) => !fenced(locator)),
217
- });
218
- if (committed.fenced === null || !whole)
219
- noted(kept);
220
- for (const locator of discards)
221
- queued.delete(locator);
222
- return committed;
223
- },
224
- async fence(locators) {
225
- await authored.ask({ kind: 'replica.fence', locators });
226
- for (const locator of locators)
227
- queued.delete(locator);
228
- },
229
- async erase(locator, limit) {
230
- return (await authored.ask({ kind: 'replica.erase', locator, limit })).remaining;
231
- },
232
- async abandon(locator) {
233
- if (fenced(locator))
234
- return;
235
- await authored.ask({ kind: 'replica.abandon', locator });
236
- },
237
- async release(key) {
238
- await authored.ask({ kind: 'replica.release', key });
239
- },
240
- async rederive(key, composition, bytes, ms, floor) {
241
- change(key);
242
- return authored.ask({
243
- kind: 'replica.rederive',
244
- key,
245
- composed: composedOf(composition),
246
- bytes,
247
- ms,
248
- floor,
249
- });
250
- },
251
- async fact(name, value) {
252
- await authored.ask({ kind: 'replica.fact', name, value: JSON.stringify(value) });
253
- },
254
- async queues() {
255
- const { queues, pending } = await authored.ask({ kind: 'authored.queues' });
256
- queued.clear();
257
- for (const queue of queues)
258
- queued.set(queue.locator, new Set(queue.ids));
259
- const byId = new Map(pending.map((record) => [`${record.locator}\0${record.id}`, record]));
260
- return queues
261
- .filter((queue) => !fenced(queue.locator))
262
- .map((queue) => ({
263
- locator: queue.locator,
264
- pending: queue.ids.map((id) => {
265
- const record = byId.get(`${queue.locator}\0${id}`);
266
- if (record === undefined)
267
- throw new Error(`Missing Pending Change ${queue.locator}/${id}`);
268
- return {
269
- batch: JSON.parse(record.batch),
270
- state: JSON.parse(record.state),
271
- };
272
- }),
273
- }));
274
- },
275
- submit(locator, id, submission, lost) {
276
- return amend(locator, id, { submission, lost });
277
- },
278
- keepUpload(locator, id, upload) {
279
- return amend(locator, id, { upload });
280
- },
281
- async roomDrafts() {
282
- const held = await authored.ask({ kind: 'authored.roomDrafts' });
283
- return held
284
- .map((record) => JSON.parse(record))
285
- .filter((record) => !fenced(record.locator));
286
- },
287
- async present(record) {
288
- await authored.ask({
289
- kind: 'replica.present',
290
- app: record.app,
291
- value: JSON.stringify(record.value ?? null),
292
- });
293
- },
294
- conversations() {
295
- return authored.ask({ kind: 'conversation.held' });
296
- },
297
- async keepMessages(write) {
298
- await authored.ask({ kind: 'conversation.keep', ...write });
299
- },
300
- messageWindow(conversation, limit, before) {
301
- return authored.ask({ kind: 'conversation.window', conversation, limit, before });
302
- },
303
- messageCount(conversation) {
304
- return authored.ask({ kind: 'conversation.count', conversation });
305
- },
306
- turnArrived(conversation, turn) {
307
- return authored.ask({ kind: 'conversation.turn', conversation, turn });
308
- },
309
- async dropConversations(conversations) {
310
- await authored.ask({ kind: 'conversation.drop', conversations });
311
- },
312
- async chatDrafts() {
313
- const records = await authored.ask({ kind: 'authored.chatDrafts' });
314
- return records.map((record) => JSON.parse(record));
315
- },
316
- async keepChatDrafts(records) {
317
- await authored.ask({
318
- kind: 'authored.chatDraft',
319
- kept: records.map((record) => ({
320
- conversation: record.conversation,
321
- record: JSON.stringify(record),
322
- })),
323
- dropped: [],
324
- });
325
- },
326
- async dropChatDraft(conversation) {
327
- await authored.ask({ kind: 'authored.chatDraft', kept: [], dropped: [conversation] });
328
- },
329
- async calls() {
330
- return restored(await authored.ask({ kind: 'authored.calls' }));
331
- },
332
- async keepCall(record) {
333
- const { stored, ...kept } = keyed(keys, record);
334
- await authored.ask({
335
- kind: 'authored.call',
336
- operation: record.operation,
337
- kept,
338
- files: stored,
339
- });
340
- },
341
- async dropCall(operation) {
342
- await authored.ask({ kind: 'authored.call', operation, kept: null, files: [] });
343
- },
344
- async keepRoomDraft(record, files) {
345
- if (fenced(record.locator))
346
- return;
347
- const { path, ...kept } = roomDraftRow(record);
348
- await authored.ask({
349
- kind: 'authored.roomDraft',
350
- locator: record.locator,
351
- path,
352
- kept,
353
- files,
354
- });
355
- },
356
- async discardRoomDraft(locator, path) {
357
- if (fenced(locator))
358
- return;
359
- await authored.ask({ kind: 'authored.roomDraft', locator, path, kept: null, files: [] });
360
- },
361
- fences() {
362
- return authored.ask({ kind: 'authored.fences' });
363
- },
364
- generation() {
365
- return fact('generation');
366
- },
367
- async rememberGeneration(value) {
368
- await authored.ask({ kind: 'authored.remember', name: 'generation', value });
369
- },
370
- file(key, type) {
371
- return authored.ask({ kind: 'authored.file', key, type });
372
- },
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,
373
123
  };
374
124
  }
package/dist/stored.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { HeadChange } from './adapter.js';
1
+ import type { SavedFacts, HeadChange } from './adapter.js';
2
2
  import { type Composed, type Composition } from './collection.js';
3
3
  import type { HeldBinary } from './overlay.js';
4
4
  import type { Connection } from './tables.js';
@@ -10,8 +10,10 @@ export type StoredEntry = {
10
10
  readonly binary: HeldBinary | null;
11
11
  readonly revision: string | null;
12
12
  readonly fileId: string | null;
13
+ readonly created: string | null;
13
14
  readonly change: HeadChange | null;
14
15
  readonly written: string | null;
16
+ readonly facts: SavedFacts | null;
15
17
  };
16
18
  export type OverlayEntry = StoredEntry & {
17
19
  readonly present: boolean;
@@ -27,35 +29,46 @@ export type TypedEntry = {
27
29
  export type Referrer = {
28
30
  readonly path: string;
29
31
  readonly target: string;
30
- readonly kind: string;
31
32
  };
32
- export type HeldKey = {
33
- readonly key: number;
33
+ export type HeldRoomRow = {
34
34
  readonly locator: string;
35
- readonly transfer: string;
36
- readonly rederiving: number | null;
37
- readonly searching: number | null;
35
+ readonly key: number;
36
+ readonly record: string;
37
+ readonly indexed: boolean;
38
+ readonly documents: number;
38
39
  };
39
- export type ReplicaOpened = {
40
+ export type HeldRoomWork = {
41
+ readonly room: (HeldRoomRow & {
42
+ readonly overlaid: readonly string[];
43
+ }) | null;
44
+ readonly queue: readonly {
45
+ readonly id: string;
46
+ readonly batch: string;
47
+ readonly state: string;
48
+ }[];
49
+ };
50
+ export type Covering = {
40
51
  readonly rooms: readonly {
41
52
  readonly locator: string;
42
53
  readonly key: number;
43
- readonly record: string;
54
+ readonly transfer: string;
55
+ readonly roomVersion: string;
56
+ readonly indexed: boolean;
57
+ readonly documents: number;
58
+ readonly bytes: number;
59
+ readonly offline: string;
44
60
  }[];
45
- readonly keys: readonly HeldKey[];
46
- readonly facts: Readonly<Record<string, string>>;
47
- readonly presentation: readonly {
48
- readonly app: string;
49
- readonly value: string;
50
- }[];
51
- readonly overlaid: readonly {
52
- readonly key: number;
53
- readonly path: string;
54
- }[];
55
- readonly erasing: readonly {
56
- readonly key: number;
61
+ readonly queues: readonly {
57
62
  readonly locator: string;
63
+ readonly ids: readonly string[];
58
64
  }[];
65
+ };
66
+ export type HeldLocators = {
67
+ readonly held: readonly string[];
68
+ readonly staged: readonly string[];
69
+ };
70
+ export type ReplicaOpened = {
71
+ readonly erasing: boolean;
59
72
  readonly orphans: readonly number[];
60
73
  };
61
74
  export type RoomCommit = {
@@ -78,14 +91,9 @@ export type RoomCommit = {
78
91
  };
79
92
  };
80
93
  export type Committed = {
81
- readonly counts: Readonly<Record<string, number>>;
82
94
  readonly changed: Readonly<Record<string, readonly string[] | null>>;
83
95
  readonly indexed: Readonly<Record<string, boolean>>;
84
96
  };
85
- export type CountedRoom = {
86
- readonly key: number;
87
- readonly roots: readonly string[];
88
- };
89
97
  export declare function entered(connection: Connection, locator: string, composition: Composition, rows: readonly StoredEntry[]): number;
90
98
  export declare function stage(connection: Connection, request: {
91
99
  readonly locator: string;
@@ -94,7 +102,20 @@ export declare function stage(connection: Connection, request: {
94
102
  readonly fingerprint: string;
95
103
  readonly entries: readonly StoredEntry[];
96
104
  readonly folders: readonly string[];
105
+ readonly part: string | null;
97
106
  }): number;
107
+ export type Resumed = {
108
+ readonly key: number | null;
109
+ readonly transfer: string;
110
+ readonly staged: readonly string[];
111
+ };
112
+ export declare function resume(connection: Connection, request: {
113
+ readonly locator: string;
114
+ readonly transfer: string;
115
+ readonly fingerprint: string;
116
+ readonly parts: readonly string[];
117
+ readonly published: number | null;
118
+ }): Resumed;
98
119
  export declare function refreshing(connection: Connection, request: {
99
120
  readonly key: number;
100
121
  readonly composed: Composed;
@@ -104,7 +125,6 @@ export declare function refreshing(connection: Connection, request: {
104
125
  readonly folderRemovals: readonly string[];
105
126
  }): null;
106
127
  export declare function unrefresh(connection: Connection, key: number): null;
107
- export declare function counts(connection: Connection, rooms: readonly CountedRoom[]): number[];
108
128
  export declare function commit(connection: Connection, rooms: readonly RoomCommit[]): Committed;
109
129
  export declare function fenceRooms(connection: Connection, locators: readonly string[]): null;
110
130
  export declare function abandon(connection: Connection, locator: string): null;
@@ -118,13 +138,19 @@ export declare function rederive(connection: Connection, key: number, composed:
118
138
  };
119
139
  export declare function entries(connection: Connection, key: number, view: View, list: readonly string[]): HeldEntry[];
120
140
  export declare function typed(connection: Connection, key: number, view: View, list: readonly string[]): TypedEntry[];
121
- export declare function referrers(connection: Connection, key: number, view: View, targets: readonly string[], kinds: readonly string[]): Referrer[];
122
- export declare function files(connection: Connection, key: number, view: View, after: string | null, limit: number): {
123
- readonly path: string;
124
- readonly revision: string;
125
- }[];
141
+ export declare function referrers(connection: Connection, key: number, view: View, targets: readonly string[]): Referrer[];
126
142
  export declare function folders(connection: Connection, key: number, view: View, list: readonly string[]): string[];
127
143
  export declare function typedWithin(connection: Connection, key: number, view: View, roots: readonly string[], within: boolean): boolean;
128
144
  export declare function opened(connection: Connection): ReplicaOpened;
145
+ export declare function heldRooms(connection: Connection, locators: readonly string[] | null): readonly HeldRoomRow[];
146
+ export declare function heldRoom(connection: Connection, locator: string): HeldRoomRow | null;
147
+ export declare function overlaid(connection: Connection, key: number): readonly string[];
148
+ export declare function covering(connection: Connection): Covering['rooms'];
149
+ export declare function offlineMode(connection: Connection, locator: string): string | null;
150
+ export declare function stagedLocators(connection: Connection): readonly string[];
151
+ export declare function heldLocators(connection: Connection): readonly string[];
152
+ export declare function demoted(connection: Connection): null;
153
+ export declare function facts(connection: Connection): Readonly<Record<string, string>>;
154
+ export declare function presentation(connection: Connection, app: string): string | null;
129
155
  export declare function ended(connection: Connection): void;
130
156
  //# sourceMappingURL=stored.d.ts.map