@agentshouse/mdruntime 0.1.0-c835af48a82d3 → 0.1.0-c83bc1fac9b35

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