@agentshouse/mdruntime 0.1.0-cbb8d8acc9d19 → 0.1.0-cbbae1fff01c6
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.
- package/README.md +24 -11
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +308 -0
- package/dist/actions.d.ts +20 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +251 -0
- package/dist/adapter.d.ts +194 -90
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +7 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +40 -41
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +70 -0
- package/dist/binary.d.ts +18 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +37 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +324 -52
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/chain.d.ts +12 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +13 -14
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +17 -56
- package/dist/change.d.ts +46 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +36 -0
- package/dist/chat-types.d.ts +5 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +13 -0
- package/dist/client.d.ts +56 -18
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +164 -23
- package/dist/collection.d.ts +31 -14
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +61 -55
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +711 -0
- package/dist/connection.d.ts +8 -104
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +107 -2094
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation-live.d.ts +135 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +247 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +53 -0
- package/dist/conversation.d.ts +67 -44
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1010 -549
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/discovery.d.ts +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +148 -0
- package/dist/durability.d.ts +19 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +20 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +161 -0
- package/dist/expectation.d.ts +23 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +92 -0
- package/dist/failure.d.ts +14 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +22 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- package/dist/holdings.d.ts +29 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +95 -0
- package/dist/host.d.ts +28 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +149 -27
- package/dist/identity.d.ts +3 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +13 -1
- package/dist/index.d.ts +40 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -0
- package/dist/install.d.ts +54 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +538 -0
- package/dist/job.d.ts +5 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +7 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +272 -0
- package/dist/listing.d.ts +48 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +139 -0
- package/dist/live.d.ts +23 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +165 -0
- package/dist/locks.d.ts +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +33 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +50 -0
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +25 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +295 -99
- package/dist/messages.d.ts +49 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +148 -0
- package/dist/model.d.ts +13 -13
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -15
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +156 -0
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +22 -4
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +127 -26
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +59 -0
- package/dist/outcome.d.ts +75 -5
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +84 -1
- package/dist/overlay.d.ts +17 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +168 -190
- package/dist/parts.d.ts +11 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +21 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +26 -0
- package/dist/preparation.d.ts +20 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +233 -0
- package/dist/presence.d.ts +52 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +220 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +270 -0
- package/dist/query.d.ts +51 -181
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -461
- package/dist/questions.d.ts +34 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +122 -0
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +455 -0
- package/dist/reach.d.ts +21 -5
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +305 -80
- package/dist/react.d.ts +43 -20
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +22 -21
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +49 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +27 -0
- package/dist/reads.d.ts +37 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +174 -0
- package/dist/recovery.d.ts +26 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +232 -0
- package/dist/refresh.d.ts +20 -7
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +155 -59
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +57 -0
- package/dist/replica.d.ts +53 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +361 -164
- package/dist/room-draft.d.ts +58 -12
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +270 -90
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +217 -0
- package/dist/rows.d.ts +32 -35
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +64 -124
- package/dist/runtime.d.ts +34 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +46 -22
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +969 -171
- package/dist/saves.d.ts +32 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +413 -0
- package/dist/search.d.ts +15 -54
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -121
- package/dist/seed.d.ts +25 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +145 -0
- package/dist/shared.d.ts +10 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +339 -0
- package/dist/shown.d.ts +32 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +290 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/lanes.d.ts +20 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +77 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket/session.d.ts +38 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +23 -0
- package/dist/socket.d.ts +67 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +170 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +82 -0
- package/dist/status.d.ts +7 -4
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -15
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +34 -0
- package/dist/store/readiness.d.ts +10 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +52 -0
- package/dist/store/records.d.ts +210 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +428 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- package/dist/store/space.d.ts +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +109 -94
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +161 -384
- package/dist/stored.d.ts +156 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +649 -0
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +223 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +521 -0
- package/dist/tables.d.ts +412 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +737 -0
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/turn.d.ts +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +75 -0
- package/dist/validation.d.ts +29 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +104 -0
- package/dist/windows.d.ts +11 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +16 -0
- package/dist/wire.d.ts +189 -37
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +77 -33
- package/package.json +27 -15
- package/AGENTS.md +0 -244
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
- package/dist/read-side.d.ts +0 -18
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -433
package/dist/store.js
CHANGED
|
@@ -1,395 +1,172 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 { createSpace } from './store/space.js';
|
|
11
|
+
import { createWatchers } from './store/watchers.js';
|
|
12
|
+
import { createWrites } from './store/writes.js';
|
|
13
|
+
export function createStore(options) {
|
|
14
|
+
const writes = createWrites();
|
|
15
|
+
const watchers = createWatchers(options.unpublished);
|
|
16
|
+
const { lost } = options;
|
|
17
|
+
const installs = createInstalls();
|
|
18
|
+
const seeds = new Map();
|
|
19
|
+
const landed = createRoomHeld();
|
|
20
|
+
const attached = createRoomHeld();
|
|
21
|
+
const typesHeld = new Map();
|
|
22
|
+
const device = createCell({
|
|
23
|
+
persistence: options.persistence,
|
|
24
|
+
storageLoss: null,
|
|
25
|
+
heldWhenOpened: false,
|
|
26
|
+
preparing: false,
|
|
27
|
+
sweeping: false,
|
|
28
|
+
unpreparedDemand: new Set(),
|
|
29
|
+
unpreparable: new Set(),
|
|
30
|
+
establishing: new Set(),
|
|
31
|
+
status: STARTING,
|
|
32
|
+
roomsShown: null,
|
|
20
33
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
const EMPTY_DECLARATIONS = {
|
|
30
|
-
lastCompleted: null,
|
|
31
|
-
generation: null,
|
|
32
|
-
providerLimits: [],
|
|
33
|
-
capabilities: [],
|
|
34
|
-
};
|
|
35
|
-
function declaration(database) {
|
|
36
|
-
const transaction = database.transaction(DECLARATIONS, 'readonly');
|
|
37
|
-
return settled(transaction.objectStore(DECLARATIONS).get(CURRENT)).then((record) => record ?? EMPTY_DECLARATIONS);
|
|
38
|
-
}
|
|
39
|
-
function updateDeclaration(database, update) {
|
|
40
|
-
const transaction = database.transaction(DECLARATIONS, 'readwrite');
|
|
41
|
-
const store = transaction.objectStore(DECLARATIONS);
|
|
42
|
-
const prior = store.get(CURRENT);
|
|
43
|
-
prior.onsuccess = () => {
|
|
44
|
-
store.put(update(prior.result ?? EMPTY_DECLARATIONS), CURRENT);
|
|
45
|
-
};
|
|
46
|
-
return completed(transaction);
|
|
47
|
-
}
|
|
48
|
-
function amendPending(database, locator, id, amendment) {
|
|
49
|
-
const transaction = database.transaction(PENDING_CHANGES, 'readwrite');
|
|
50
|
-
const pending = transaction.objectStore(PENDING_CHANGES);
|
|
51
|
-
const request = pending.get([locator, id]);
|
|
52
|
-
request.onsuccess = () => {
|
|
53
|
-
const record = request.result;
|
|
54
|
-
if (record !== undefined)
|
|
55
|
-
pending.put({ ...record, ...amendment });
|
|
56
|
-
};
|
|
57
|
-
return completed(transaction);
|
|
58
|
-
}
|
|
59
|
-
function roomRecord(record, queue) {
|
|
60
|
-
const { documents, binaryTargets, revisions, changes, written, attachments, ...room } = record;
|
|
61
|
-
return { ...room, order: queue.map((batch) => batch.id) };
|
|
62
|
-
}
|
|
63
|
-
function removeRoomEntries(store, locator) {
|
|
64
|
-
const keys = store.getAllKeys();
|
|
65
|
-
keys.onsuccess = () => {
|
|
66
|
-
for (const key of keys.result) {
|
|
67
|
-
if (Array.isArray(key) && key[0] === locator)
|
|
68
|
-
store.delete(key);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
export function removeRuntimeStore() {
|
|
73
|
-
return new Promise((resolve, reject) => {
|
|
74
|
-
const removal = indexedDB.deleteDatabase(DATABASE);
|
|
75
|
-
removal.onsuccess = () => resolve();
|
|
76
|
-
removal.onerror = () => reject(removal.error);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
export async function openRuntimeStore() {
|
|
80
|
-
const opening = indexedDB.open(DATABASE, STORE_SCHEMA);
|
|
81
|
-
opening.onupgradeneeded = () => {
|
|
82
|
-
const database = opening.result;
|
|
83
|
-
for (const name of [...database.objectStoreNames])
|
|
84
|
-
database.deleteObjectStore(name);
|
|
85
|
-
database.createObjectStore(ROOMS, { keyPath: 'locator' });
|
|
86
|
-
database.createObjectStore(DOCUMENTS, { keyPath: ['locator', 'path'] });
|
|
87
|
-
database.createObjectStore(BINARY_TARGETS, { keyPath: ['locator', 'path'] });
|
|
88
|
-
database.createObjectStore(ATTACHMENTS, { keyPath: ['locator', 'reference'] });
|
|
89
|
-
database.createObjectStore(PENDING_CHANGES, { keyPath: ['locator', 'id'] });
|
|
90
|
-
database.createObjectStore(DECLARATIONS);
|
|
91
|
-
database.createObjectStore(ROOM_DRAFTS, { keyPath: ['locator', 'path'] });
|
|
92
|
-
database.createObjectStore(PRESENTATION, { keyPath: 'app' });
|
|
93
|
-
database.createObjectStore(CONVERSATIONS, { keyPath: 'conversation' });
|
|
94
|
-
const messages = database.createObjectStore(MESSAGES, {
|
|
95
|
-
keyPath: ['conversation', 'identity'],
|
|
34
|
+
const space = createSpace(options.database, options.spaceFreed);
|
|
35
|
+
const readiness = createReadinessQueue(options.deliverReadiness, options.unpublished);
|
|
36
|
+
let opening;
|
|
37
|
+
function open() {
|
|
38
|
+
opening ??= options.opening(openRuntimeStore(options.database)).catch((error) => {
|
|
39
|
+
opening = undefined;
|
|
40
|
+
throw error;
|
|
96
41
|
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
42
|
+
return opening;
|
|
43
|
+
}
|
|
44
|
+
function prepareAgain(locator) {
|
|
45
|
+
const { unpreparable } = device.now();
|
|
46
|
+
device.set({
|
|
47
|
+
unpreparable: locator === undefined
|
|
48
|
+
? new Set()
|
|
49
|
+
: new Set([...unpreparable].filter((held) => held !== locator)),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function typed(locator, persisted) {
|
|
53
|
+
if (persisted.status === 'unavailable')
|
|
54
|
+
return persisted;
|
|
55
|
+
const schema = persisted.snapshot.schema;
|
|
56
|
+
const held = typesHeld.get(locator);
|
|
57
|
+
if (held !== undefined && held.schema === schema)
|
|
58
|
+
return { ...persisted, types: held.types };
|
|
59
|
+
const types = schemaTypes(schema, options.roomTypes);
|
|
60
|
+
typesHeld.set(locator, { schema, types });
|
|
61
|
+
return { ...persisted, types };
|
|
62
|
+
}
|
|
63
|
+
function recordOf(stored) {
|
|
64
|
+
return { ...stored, model: typed(stored.locator, stored.model) };
|
|
65
|
+
}
|
|
66
|
+
async function rooms(locators) {
|
|
67
|
+
const held = await (await open()).rooms(locators);
|
|
68
|
+
return new Map(held
|
|
69
|
+
.filter(({ record }) => !lost(record.locator))
|
|
70
|
+
.map(({ record, indexed, documents }) => [
|
|
71
|
+
record.locator,
|
|
72
|
+
{ record: recordOf(record), indexed, documents },
|
|
73
|
+
]));
|
|
74
|
+
}
|
|
75
|
+
async function work(locator) {
|
|
76
|
+
if (lost(locator))
|
|
77
|
+
return { replica: undefined, queue: [], states: new Map() };
|
|
78
|
+
const { room, queue } = await (await open()).room(locator);
|
|
79
|
+
const batches = queue.map(({ batch }) => batch);
|
|
80
|
+
const states = new Map(queue.map(({ batch, state }) => [batch.id, state]));
|
|
81
|
+
return {
|
|
82
|
+
replica: room === null
|
|
83
|
+
? undefined
|
|
84
|
+
: { record: recordOf(room.record), queue: batches, states, overlaid: room.overlaid },
|
|
85
|
+
queue: batches,
|
|
86
|
+
states,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async function drafts(locator, paths) {
|
|
90
|
+
const held = await (await open()).roomDrafts(locator, paths);
|
|
91
|
+
return held.filter((record) => !lost(record.locator));
|
|
92
|
+
}
|
|
101
93
|
return {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
94
|
+
device,
|
|
95
|
+
space,
|
|
96
|
+
readiness,
|
|
97
|
+
ask: options.database.ask,
|
|
98
|
+
changed: options.changed,
|
|
99
|
+
open,
|
|
100
|
+
durably: (work) => writes.exclusive(async () => {
|
|
101
|
+
const local = await open();
|
|
102
|
+
return work(local);
|
|
103
|
+
}),
|
|
104
|
+
exclusive: writes.exclusive,
|
|
105
|
+
gathered: writes.gathered,
|
|
106
|
+
written: writes.written,
|
|
107
|
+
startingWrite: writes.startingWrite,
|
|
108
|
+
finishingWrite: writes.finishingWrite,
|
|
109
|
+
ahead: writes.ahead,
|
|
110
|
+
rederive: writes.rederive,
|
|
111
|
+
refreshPage: writes.refreshPage,
|
|
112
|
+
stageBytes: writes.stageBytes,
|
|
113
|
+
deriveBytes: writes.deriveBytes,
|
|
114
|
+
rooms,
|
|
115
|
+
record: async (locator) => (await rooms([locator])).get(locator)?.record,
|
|
116
|
+
work,
|
|
117
|
+
replica: async (locator) => (await work(locator)).replica,
|
|
118
|
+
async covering() {
|
|
119
|
+
const held = await (await open()).covering();
|
|
120
|
+
return {
|
|
121
|
+
rooms: new Map([...held.rooms].filter(([locator]) => !lost(locator))),
|
|
122
|
+
queues: new Map([...held.queues].filter(([locator]) => !lost(locator))),
|
|
129
123
|
};
|
|
130
|
-
for (const document of documents) {
|
|
131
|
-
const room = byRoom.get(document.locator);
|
|
132
|
-
if (room === undefined)
|
|
133
|
-
continue;
|
|
134
|
-
room.documents[document.path] = document.content;
|
|
135
|
-
if (document.written !== null) {
|
|
136
|
-
room.written[document.path] = document.written;
|
|
137
|
-
}
|
|
138
|
-
head(room, document);
|
|
139
|
-
}
|
|
140
|
-
for (const target of targets) {
|
|
141
|
-
const room = byRoom.get(target.locator);
|
|
142
|
-
if (room === undefined)
|
|
143
|
-
continue;
|
|
144
|
-
room.binaryTargets.push(target.path);
|
|
145
|
-
head(room, target);
|
|
146
|
-
}
|
|
147
|
-
for (const { locator, ...attachment } of attachments) {
|
|
148
|
-
const room = byRoom.get(locator);
|
|
149
|
-
if (room === undefined)
|
|
150
|
-
continue;
|
|
151
|
-
room.attachments.push(attachment);
|
|
152
|
-
}
|
|
153
|
-
return [...byRoom.values()];
|
|
154
|
-
},
|
|
155
|
-
async write({ next, previous, queue, previousQueue, saved, roomDrafts, consumedRoomDrafts }) {
|
|
156
|
-
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
|
|
157
|
-
transaction.objectStore(ROOMS).put(roomRecord(next, queue));
|
|
158
|
-
const documents = transaction.objectStore(DOCUMENTS);
|
|
159
|
-
for (const path of Object.keys(previous?.documents ?? {})) {
|
|
160
|
-
if (next.documents[path] === undefined)
|
|
161
|
-
documents.delete([next.locator, path]);
|
|
162
|
-
}
|
|
163
|
-
for (const [path, content] of Object.entries(next.documents)) {
|
|
164
|
-
if (previous?.documents[path] === content &&
|
|
165
|
-
previous.revisions[path] === next.revisions[path] &&
|
|
166
|
-
previous.written[path] === next.written[path] &&
|
|
167
|
-
sameChange(previous.changes[path], next.changes[path]))
|
|
168
|
-
continue;
|
|
169
|
-
documents.put({
|
|
170
|
-
locator: next.locator,
|
|
171
|
-
path,
|
|
172
|
-
content,
|
|
173
|
-
revision: next.revisions[path] ?? null,
|
|
174
|
-
change: next.changes[path] ?? null,
|
|
175
|
-
written: next.written[path] ?? null,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
const targets = transaction.objectStore(BINARY_TARGETS);
|
|
179
|
-
const beforeTargets = new Set(previous?.binaryTargets ?? []);
|
|
180
|
-
const afterTargets = new Set(next.binaryTargets);
|
|
181
|
-
for (const path of beforeTargets) {
|
|
182
|
-
if (!afterTargets.has(path))
|
|
183
|
-
targets.delete([next.locator, path]);
|
|
184
|
-
}
|
|
185
|
-
for (const path of afterTargets) {
|
|
186
|
-
if (!beforeTargets.has(path) ||
|
|
187
|
-
previous?.revisions[path] !== next.revisions[path] ||
|
|
188
|
-
!sameChange(previous?.changes[path], next.changes[path])) {
|
|
189
|
-
targets.put({
|
|
190
|
-
locator: next.locator,
|
|
191
|
-
path,
|
|
192
|
-
revision: next.revisions[path] ?? null,
|
|
193
|
-
change: next.changes[path] ?? null,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
const attachments = transaction.objectStore(ATTACHMENTS);
|
|
198
|
-
const held = new Map((previous?.attachments ?? []).map((attachment) => [attachment.reference, attachment]));
|
|
199
|
-
const declared = new Set(next.attachments.map((attachment) => attachment.reference));
|
|
200
|
-
for (const reference of held.keys()) {
|
|
201
|
-
if (!declared.has(reference))
|
|
202
|
-
attachments.delete([next.locator, reference]);
|
|
203
|
-
}
|
|
204
|
-
for (const attachment of next.attachments) {
|
|
205
|
-
if (held.get(attachment.reference) === attachment)
|
|
206
|
-
continue;
|
|
207
|
-
attachments.put({ ...attachment, locator: next.locator });
|
|
208
|
-
}
|
|
209
|
-
if (previousQueue !== undefined) {
|
|
210
|
-
const pending = transaction.objectStore(PENDING_CHANGES);
|
|
211
|
-
const before = new Set(previousQueue.map((batch) => batch.id));
|
|
212
|
-
const after = new Set(queue.map((batch) => batch.id));
|
|
213
|
-
for (const id of before) {
|
|
214
|
-
if (!after.has(id))
|
|
215
|
-
pending.delete([next.locator, id]);
|
|
216
|
-
}
|
|
217
|
-
for (const batch of queue) {
|
|
218
|
-
if (!before.has(batch.id)) {
|
|
219
|
-
pending.put({
|
|
220
|
-
locator: next.locator,
|
|
221
|
-
id: batch.id,
|
|
222
|
-
batch,
|
|
223
|
-
drafts: saved ?? [],
|
|
224
|
-
submission: { state: 'waiting' },
|
|
225
|
-
lost: false,
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
const draftStore = transaction.objectStore(ROOM_DRAFTS);
|
|
231
|
-
for (const path of consumedRoomDrafts ?? [])
|
|
232
|
-
draftStore.delete([next.locator, path]);
|
|
233
|
-
for (const record of roomDrafts ?? [])
|
|
234
|
-
draftStore.put(record);
|
|
235
|
-
await completed(transaction);
|
|
236
|
-
},
|
|
237
|
-
async revokeModels(records) {
|
|
238
|
-
const transaction = database.transaction(ROOMS, 'readwrite');
|
|
239
|
-
const rooms = transaction.objectStore(ROOMS);
|
|
240
|
-
const revoked = { status: 'unavailable', reason: 'revoked' };
|
|
241
|
-
for (const { record, queue } of records) {
|
|
242
|
-
rooms.put(roomRecord({ ...record, model: revoked, selectionModel: revoked }, queue));
|
|
243
|
-
}
|
|
244
|
-
await completed(transaction);
|
|
245
|
-
},
|
|
246
|
-
async lastCompleted() {
|
|
247
|
-
return (await declaration(database)).lastCompleted;
|
|
248
|
-
},
|
|
249
|
-
complete(at) {
|
|
250
|
-
return updateDeclaration(database, (record) => ({ ...record, lastCompleted: at }));
|
|
251
|
-
},
|
|
252
|
-
async providerLimits() {
|
|
253
|
-
return (await declaration(database)).providerLimits;
|
|
254
124
|
},
|
|
255
|
-
async
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
async queues() {
|
|
266
|
-
const transaction = database.transaction([ROOMS, PENDING_CHANGES], 'readonly');
|
|
267
|
-
const [rooms, pending] = await Promise.all([
|
|
268
|
-
settled(transaction.objectStore(ROOMS).getAll()),
|
|
269
|
-
settled(transaction.objectStore(PENDING_CHANGES).getAll()),
|
|
270
|
-
]);
|
|
271
|
-
const byId = new Map(pending.map((record) => [`${record.locator}\0${record.id}`, record]));
|
|
272
|
-
return rooms.map((room) => ({
|
|
273
|
-
locator: room.locator,
|
|
274
|
-
pending: room.order.map((id) => {
|
|
275
|
-
const record = byId.get(`${room.locator}\0${id}`);
|
|
276
|
-
if (record === undefined)
|
|
277
|
-
throw new Error(`Missing Pending Change ${room.locator}/${id}`);
|
|
278
|
-
const { batch, drafts, submission, lost, upload, accepted } = record;
|
|
279
|
-
return { batch, state: { drafts, submission, lost, upload, accepted } };
|
|
280
|
-
}),
|
|
281
|
-
}));
|
|
282
|
-
},
|
|
283
|
-
submit(locator, id, submission, lost) {
|
|
284
|
-
return amendPending(database, locator, id, { submission, lost });
|
|
285
|
-
},
|
|
286
|
-
accept(locator, id, roomVersion) {
|
|
287
|
-
return amendPending(database, locator, id, { accepted: roomVersion });
|
|
288
|
-
},
|
|
289
|
-
keepUpload(locator, id, upload) {
|
|
290
|
-
return amendPending(database, locator, id, { upload });
|
|
291
|
-
},
|
|
292
|
-
async roomDrafts() {
|
|
293
|
-
const transaction = database.transaction(ROOM_DRAFTS, 'readonly');
|
|
294
|
-
return settled(transaction.objectStore(ROOM_DRAFTS).getAll());
|
|
295
|
-
},
|
|
296
|
-
async presentation() {
|
|
297
|
-
const transaction = database.transaction(PRESENTATION, 'readonly');
|
|
298
|
-
return settled(transaction.objectStore(PRESENTATION).getAll());
|
|
299
|
-
},
|
|
300
|
-
async present(record) {
|
|
301
|
-
const transaction = database.transaction(PRESENTATION, 'readwrite');
|
|
302
|
-
transaction.objectStore(PRESENTATION).put(record);
|
|
303
|
-
await completed(transaction);
|
|
304
|
-
},
|
|
305
|
-
async conversations() {
|
|
306
|
-
const transaction = database.transaction([CONVERSATIONS, MESSAGES], 'readonly');
|
|
307
|
-
const [reads, messages] = await Promise.all([
|
|
308
|
-
settled(transaction.objectStore(CONVERSATIONS).getAll()),
|
|
309
|
-
settled(transaction.objectStore(MESSAGES).getAll()),
|
|
310
|
-
]);
|
|
311
|
-
const held = new Map();
|
|
312
|
-
for (const { conversation, read } of reads) {
|
|
313
|
-
held.set(conversation, { conversation, read, messages: [] });
|
|
314
|
-
}
|
|
315
|
-
for (const { conversation, ...message } of messages) {
|
|
316
|
-
const entry = held.get(conversation) ?? { conversation, read: undefined, messages: [] };
|
|
317
|
-
entry.messages.push(message);
|
|
318
|
-
held.set(conversation, entry);
|
|
319
|
-
}
|
|
320
|
-
return [...held.values()];
|
|
321
|
-
},
|
|
322
|
-
async keepMessages({ conversation, messages, read, sealed }) {
|
|
323
|
-
const transaction = database.transaction([CONVERSATIONS, MESSAGES, CHAT_DRAFTS], 'readwrite');
|
|
324
|
-
const stored = transaction.objectStore(MESSAGES);
|
|
325
|
-
for (const message of messages) {
|
|
326
|
-
stored.put({ ...message, conversation });
|
|
327
|
-
}
|
|
328
|
-
if (read !== undefined) {
|
|
329
|
-
transaction
|
|
330
|
-
.objectStore(CONVERSATIONS)
|
|
331
|
-
.put({ conversation, read });
|
|
332
|
-
}
|
|
333
|
-
if (sealed === true)
|
|
334
|
-
transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
335
|
-
await completed(transaction);
|
|
336
|
-
},
|
|
337
|
-
async dropConversations(conversations) {
|
|
338
|
-
const transaction = database.transaction([CONVERSATIONS, MESSAGES, CHAT_DRAFTS], 'readwrite');
|
|
339
|
-
const messages = transaction.objectStore(MESSAGES);
|
|
340
|
-
for (const conversation of conversations) {
|
|
341
|
-
transaction.objectStore(CONVERSATIONS).delete(conversation);
|
|
342
|
-
transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
343
|
-
const keys = messages.index('conversation').getAllKeys(conversation);
|
|
344
|
-
keys.onsuccess = () => {
|
|
345
|
-
for (const key of keys.result)
|
|
346
|
-
messages.delete(key);
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
await completed(transaction);
|
|
350
|
-
},
|
|
351
|
-
async chatDrafts() {
|
|
352
|
-
const transaction = database.transaction(CHAT_DRAFTS, 'readonly');
|
|
353
|
-
return settled(transaction.objectStore(CHAT_DRAFTS).getAll());
|
|
354
|
-
},
|
|
355
|
-
async keepChatDraft(record) {
|
|
356
|
-
const transaction = database.transaction(CHAT_DRAFTS, 'readwrite');
|
|
357
|
-
transaction.objectStore(CHAT_DRAFTS).put(record);
|
|
358
|
-
await completed(transaction);
|
|
359
|
-
},
|
|
360
|
-
async dropChatDraft(conversation) {
|
|
361
|
-
const transaction = database.transaction(CHAT_DRAFTS, 'readwrite');
|
|
362
|
-
transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
363
|
-
await completed(transaction);
|
|
364
|
-
},
|
|
365
|
-
async keepRoomDraft(record) {
|
|
366
|
-
const transaction = database.transaction(ROOM_DRAFTS, 'readwrite');
|
|
367
|
-
transaction.objectStore(ROOM_DRAFTS).put(record);
|
|
368
|
-
await completed(transaction);
|
|
369
|
-
},
|
|
370
|
-
async discardRoomDraft(locator, path) {
|
|
371
|
-
const transaction = database.transaction(ROOM_DRAFTS, 'readwrite');
|
|
372
|
-
transaction.objectStore(ROOM_DRAFTS).delete([locator, path]);
|
|
373
|
-
await completed(transaction);
|
|
374
|
-
},
|
|
375
|
-
async dropRooms(locators) {
|
|
376
|
-
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
|
|
377
|
-
for (const locator of locators) {
|
|
378
|
-
transaction.objectStore(ROOMS).delete(locator);
|
|
379
|
-
for (const name of [DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS]) {
|
|
380
|
-
removeRoomEntries(transaction.objectStore(name), locator);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
await completed(transaction);
|
|
384
|
-
},
|
|
385
|
-
async generation() {
|
|
386
|
-
return (await declaration(database)).generation;
|
|
125
|
+
async status() {
|
|
126
|
+
const held = await (await open()).status();
|
|
127
|
+
return {
|
|
128
|
+
queued: held.queued.filter((locator) => !lost(locator)),
|
|
129
|
+
lastCompleted: held.lastCompleted,
|
|
130
|
+
unsent: held.unsent.filter(({ room }) => !lost(room)),
|
|
131
|
+
resets: held.resets.filter(({ locator }) => !lost(locator)),
|
|
132
|
+
returned: held.returned.filter(({ locator }) => !lost(locator)),
|
|
133
|
+
};
|
|
387
134
|
},
|
|
388
|
-
|
|
389
|
-
|
|
135
|
+
queued: async () => (await (await open()).queued()).filter((locator) => !lost(locator)),
|
|
136
|
+
drafts,
|
|
137
|
+
draft: async (locator, path) => (await drafts(locator, [path]))[0],
|
|
138
|
+
composed: ({ model, declaration }) => compositionOf(model, declaration.typedSelection, options.builtIn, options.typedPaths),
|
|
139
|
+
publication: watchers.publication,
|
|
140
|
+
owing: watchers.owing,
|
|
141
|
+
watch: watchers.watch,
|
|
142
|
+
watching: watchers.watching,
|
|
143
|
+
tell: watchers.tell,
|
|
144
|
+
installs,
|
|
145
|
+
seeds: {
|
|
146
|
+
of: (key) => seeds.get(key),
|
|
147
|
+
keep(key, seed) {
|
|
148
|
+
seeds.set(key, seed);
|
|
149
|
+
},
|
|
150
|
+
drop(key) {
|
|
151
|
+
seeds.delete(key);
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
landed,
|
|
155
|
+
attached,
|
|
156
|
+
opened: openedFiles(options.database, lost),
|
|
157
|
+
prepareAgain,
|
|
158
|
+
part: (file, part) => options.database.ask({ kind: 'file.part', key: file, part }),
|
|
159
|
+
forget(locator) {
|
|
160
|
+
typesHeld.delete(locator);
|
|
161
|
+
landed.forget(locator);
|
|
162
|
+
attached.forget(locator);
|
|
163
|
+
installs.change(locator, ({ installing }) => ({ ...NO_INSTALL, installing }));
|
|
164
|
+
prepareAgain(locator);
|
|
390
165
|
},
|
|
391
166
|
close() {
|
|
392
|
-
|
|
167
|
+
space.stop();
|
|
168
|
+
readiness.close();
|
|
169
|
+
watchers.close();
|
|
393
170
|
},
|
|
394
171
|
};
|
|
395
172
|
}
|