@agentshouse/mdruntime 0.1.0-c3c7796382e28 → 0.1.0-c3faae279d4d2

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