@agentshouse/mdruntime 0.1.0-cd9e28a590f84 → 0.1.0-cdded6c080913

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