@agentshouse/mdruntime 0.1.0-cdb8840578a20 → 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.
- package/README.md +19 -16
- package/dist/acceptance.d.ts +6 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +389 -0
- package/dist/actions.d.ts +20 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +250 -0
- package/dist/adapter.d.ts +151 -79
- 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/binary.d.ts +0 -5
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +1 -1
- package/dist/bootstrap.d.ts +31 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +319 -107
- 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 +9 -16
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -88
- package/dist/change.d.ts +32 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +10 -1
- 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 +33 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +98 -11
- package/dist/collection.d.ts +11 -21
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +39 -291
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +717 -0
- package/dist/connection.d.ts +7 -129
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +97 -3359
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/{chat/context.js → context.js} +1 -4
- 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 +43 -18
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +718 -312
- 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 +175 -0
- package/dist/durability.d.ts +16 -4
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +5 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +33 -28
- package/dist/figures.d.ts +48 -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 +7 -8
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +101 -24
- package/dist/identity.d.ts +0 -2
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -6
- package/dist/index.d.ts +32 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/install.d.ts +56 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +560 -0
- package/dist/job.d.ts +33 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +54 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +267 -0
- package/dist/listing.d.ts +53 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +175 -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 +9 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +61 -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 +61 -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 +19 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +248 -103
- package/dist/messages.d.ts +52 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +168 -0
- package/dist/model.d.ts +8 -10
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -18
- package/dist/models.d.ts +14 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +193 -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 +17 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +100 -5
- 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 +56 -0
- package/dist/outcome.d.ts +49 -8
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +42 -0
- package/dist/overlay.d.ts +4 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +106 -156
- package/dist/{chat/parts.d.ts → parts.d.ts} +11 -9
- package/dist/parts.d.ts.map +1 -0
- package/dist/{chat/parts.js → parts.js} +45 -46
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -0
- package/dist/preparation.d.ts +20 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +226 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +272 -0
- package/dist/query.d.ts +26 -185
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -464
- package/dist/{chat/questions.d.ts → questions.d.ts} +5 -2
- package/dist/questions.d.ts.map +1 -0
- package/dist/{chat/questions.js → questions.js} +12 -1
- package/dist/reach.d.ts +19 -9
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +287 -99
- package/dist/react.d.ts +12 -4
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +7 -17
- package/dist/{chat/read.d.ts → read.d.ts} +2 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/{chat/read.js → read.js} +4 -0
- package/dist/readiness.d.ts +14 -17
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +2 -8
- package/dist/reads.d.ts +36 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +150 -0
- package/dist/recovery.d.ts +3 -2
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +43 -8
- package/dist/refresh.d.ts +17 -14
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +143 -52
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +56 -0
- package/dist/replica.d.ts +55 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +331 -181
- package/dist/room-draft.d.ts +37 -6
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +161 -74
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +216 -0
- package/dist/rows.d.ts +31 -29
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +59 -116
- package/dist/runtime.d.ts +42 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +53 -14
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +534 -187
- package/dist/saves.d.ts +70 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +1004 -0
- package/dist/search.d.ts +15 -78
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -184
- package/dist/seed.d.ts +25 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +146 -0
- package/dist/shared.d.ts +7 -3
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +119 -66
- package/dist/shown.d.ts +31 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +294 -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/rooms.d.ts +43 -0
- package/dist/socket/rooms.d.ts.map +1 -0
- package/dist/socket/rooms.js +90 -0
- package/dist/socket/session.d.ts +39 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +23 -0
- package/dist/socket.d.ts +70 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +175 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +81 -0
- package/dist/status.d.ts +4 -5
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -7
- package/dist/store/fences.d.ts +16 -0
- package/dist/store/fences.d.ts.map +1 -0
- package/dist/store/fences.js +26 -0
- 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 +212 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +408 -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 +43 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +57 -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 +106 -150
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +136 -713
- package/dist/stored.d.ts +156 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +637 -0
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +222 -0
- package/dist/sync.d.ts +20 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +531 -0
- package/dist/tables.d.ts +415 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +740 -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 +5 -3
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +51 -21
- 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 +50 -6
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +16 -2
- package/package.json +18 -19
- package/AGENTS.md +0 -300
- package/dist/acquisition.d.ts +0 -14
- package/dist/acquisition.d.ts.map +0 -1
- package/dist/acquisition.js +0 -24
- package/dist/chat/acts.d.ts +0 -33
- package/dist/chat/acts.d.ts.map +0 -1
- package/dist/chat/acts.js +0 -36
- package/dist/chat/context.d.ts +0 -3
- package/dist/chat/context.d.ts.map +0 -1
- package/dist/chat/input.d.ts +0 -9
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -99
- package/dist/chat/kit.d.ts +0 -61
- package/dist/chat/kit.d.ts.map +0 -1
- package/dist/chat/kit.js +0 -123
- package/dist/chat/lasting.d.ts +0 -6
- package/dist/chat/lasting.d.ts.map +0 -1
- package/dist/chat/lasting.js +0 -19
- package/dist/chat/list.d.ts +0 -27
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -63
- package/dist/chat/markdown.d.ts +0 -20
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -188
- package/dist/chat/message.d.ts +0 -6
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -192
- package/dist/chat/messages.d.ts +0 -22
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -155
- package/dist/chat/name.d.ts +0 -6
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -11
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -17
- package/dist/chat/overlay.d.ts +0 -31
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -97
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/process.d.ts +0 -20
- package/dist/chat/process.d.ts.map +0 -1
- package/dist/chat/process.js +0 -32
- package/dist/chat/provider.d.ts +0 -63
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -629
- package/dist/chat/question.d.ts +0 -9
- package/dist/chat/question.d.ts.map +0 -1
- package/dist/chat/question.js +0 -80
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat/ready.d.ts +0 -34
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -91
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -302
- package/dist/chat.d.ts +0 -14
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -8
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/read-side.d.ts +0 -25
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -639
package/dist/store.js
CHANGED
|
@@ -1,729 +1,152 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
[CHAT_DRAFTS, { keyPath: 'conversation' }],
|
|
35
|
-
[FACTS, undefined],
|
|
36
|
-
[FENCES, { keyPath: 'locator' }],
|
|
37
|
-
];
|
|
38
|
-
const REPLICA_STORES = [
|
|
39
|
-
[ROOMS, { keyPath: 'locator' }],
|
|
40
|
-
[DOCUMENTS, { keyPath: ['locator', 'transfer', 'path'] }],
|
|
41
|
-
[BINARY_FILES, { keyPath: ['locator', 'transfer', 'path'] }],
|
|
42
|
-
[TRANSFERS, { keyPath: 'locator' }],
|
|
43
|
-
[RECEIVED, { keyPath: 'key' }],
|
|
44
|
-
[RECEIVED_PARTS, { keyPath: ['key', 'index'] }],
|
|
45
|
-
[DECLARATIONS, undefined],
|
|
46
|
-
[PRESENTATION, { keyPath: 'app' }],
|
|
47
|
-
[CONVERSATIONS, { keyPath: 'conversation' }],
|
|
48
|
-
[MESSAGES, { keyPath: ['conversation', 'identity'] }],
|
|
49
|
-
];
|
|
50
|
-
const READ_BATCH = 256;
|
|
51
|
-
const MESSAGE_INDEXES = [
|
|
52
|
-
['conversation', 'conversation'],
|
|
53
|
-
['position', ['conversation', 'position']],
|
|
54
|
-
['turn', ['conversation', 'turn']],
|
|
55
|
-
];
|
|
56
|
-
function settled(request) {
|
|
57
|
-
return new Promise((resolve, reject) => {
|
|
58
|
-
request.onsuccess = () => resolve(request.result);
|
|
59
|
-
request.onerror = () => reject(request.error);
|
|
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,
|
|
60
34
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
lastCompleted: null,
|
|
71
|
-
providerLimits: [],
|
|
72
|
-
capabilities: [],
|
|
73
|
-
};
|
|
74
|
-
function declaration(database) {
|
|
75
|
-
const transaction = database.transaction(DECLARATIONS, 'readonly');
|
|
76
|
-
return settled(transaction.objectStore(DECLARATIONS).get(CURRENT)).then((record) => record ?? EMPTY_DECLARATIONS);
|
|
77
|
-
}
|
|
78
|
-
function updateDeclaration(database, update) {
|
|
79
|
-
const transaction = database.transaction(DECLARATIONS, 'readwrite');
|
|
80
|
-
const store = transaction.objectStore(DECLARATIONS);
|
|
81
|
-
const prior = store.get(CURRENT);
|
|
82
|
-
prior.onsuccess = () => {
|
|
83
|
-
store.put(update(prior.result ?? EMPTY_DECLARATIONS), CURRENT);
|
|
84
|
-
};
|
|
85
|
-
return completed(transaction);
|
|
86
|
-
}
|
|
87
|
-
function amendPending(database, locator, id, amendment) {
|
|
88
|
-
const transaction = database.transaction(PENDING_CHANGES, 'readwrite');
|
|
89
|
-
const pending = transaction.objectStore(PENDING_CHANGES);
|
|
90
|
-
const request = pending.get([locator, id]);
|
|
91
|
-
request.onsuccess = () => {
|
|
92
|
-
const record = request.result;
|
|
93
|
-
if (record !== undefined)
|
|
94
|
-
pending.put({ ...record, ...amendment });
|
|
95
|
-
};
|
|
96
|
-
return completed(transaction);
|
|
97
|
-
}
|
|
98
|
-
function accepted({ conversation: _held, ...message }) {
|
|
99
|
-
return message;
|
|
100
|
-
}
|
|
101
|
-
function roomRecord(record) {
|
|
102
|
-
const { documents, binaries, revisions, changes, written, ...room } = record;
|
|
103
|
-
return room;
|
|
104
|
-
}
|
|
105
|
-
function chatDraftRecord(record) {
|
|
106
|
-
return { ...record, revision: record.revision ?? '' };
|
|
107
|
-
}
|
|
108
|
-
function underTransfer(locator, transfer, after) {
|
|
109
|
-
return after === undefined
|
|
110
|
-
? IDBKeyRange.bound([locator, transfer], [locator, transfer, []])
|
|
111
|
-
: IDBKeyRange.bound([locator, transfer, after], [locator, transfer, []], true);
|
|
112
|
-
}
|
|
113
|
-
function underRoom(locator) {
|
|
114
|
-
return IDBKeyRange.bound([locator], [locator, []]);
|
|
115
|
-
}
|
|
116
|
-
async function readTransfer(store, locator, transfer, receive) {
|
|
117
|
-
let range = underTransfer(locator, transfer);
|
|
118
|
-
for (;;) {
|
|
119
|
-
const batch = await settled(store.getAll(range, READ_BATCH));
|
|
120
|
-
for (const record of batch)
|
|
121
|
-
receive(record);
|
|
122
|
-
if (batch.length < READ_BATCH)
|
|
123
|
-
return;
|
|
124
|
-
range = underTransfer(locator, transfer, batch[batch.length - 1].path);
|
|
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;
|
|
42
|
+
});
|
|
43
|
+
return opening;
|
|
125
44
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
layer.changes[held.path] = held.change;
|
|
137
|
-
};
|
|
138
|
-
await readTransfer(transaction.objectStore(DOCUMENTS), locator, transfer, (document) => {
|
|
139
|
-
layer.documents[document.path] = document.content;
|
|
140
|
-
if (document.written !== null)
|
|
141
|
-
layer.written[document.path] = document.written;
|
|
142
|
-
head(document);
|
|
143
|
-
});
|
|
144
|
-
await readTransfer(transaction.objectStore(BINARY_FILES), locator, transfer, (file) => {
|
|
145
|
-
layer.binaries[file.path] = file.binary;
|
|
146
|
-
head(file);
|
|
147
|
-
});
|
|
148
|
-
return layer;
|
|
149
|
-
}
|
|
150
|
-
function documentRecord(locator, transfer, layer, path) {
|
|
151
|
-
return {
|
|
152
|
-
locator,
|
|
153
|
-
transfer,
|
|
154
|
-
path,
|
|
155
|
-
content: layer.documents[path],
|
|
156
|
-
revision: layer.revisions[path] ?? null,
|
|
157
|
-
change: layer.changes[path] ?? null,
|
|
158
|
-
written: layer.written[path] ?? null,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
function binaryFileRecord(locator, transfer, layer, path) {
|
|
162
|
-
return {
|
|
163
|
-
locator,
|
|
164
|
-
transfer,
|
|
165
|
-
path,
|
|
166
|
-
revision: layer.revisions[path] ?? null,
|
|
167
|
-
change: layer.changes[path] ?? null,
|
|
168
|
-
binary: layer.binaries[path],
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
function writeLayer(transaction, locator, transfer, next, base) {
|
|
172
|
-
const documents = transaction.objectStore(DOCUMENTS);
|
|
173
|
-
const files = transaction.objectStore(BINARY_FILES);
|
|
174
|
-
const paths = base === null
|
|
175
|
-
? new Set([...Object.keys(next.documents), ...Object.keys(next.binaries)])
|
|
176
|
-
: new Set([
|
|
177
|
-
...differing(base.documents, next.documents),
|
|
178
|
-
...differing(base.revisions, next.revisions),
|
|
179
|
-
...differing(base.written, next.written),
|
|
180
|
-
...differing(base.changes, next.changes, sameChange),
|
|
181
|
-
...differing(base.binaries, next.binaries, sameBinary),
|
|
182
|
-
]);
|
|
183
|
-
for (const path of paths) {
|
|
184
|
-
if (next.documents[path] !== undefined) {
|
|
185
|
-
documents.put(documentRecord(locator, transfer, next, path));
|
|
186
|
-
}
|
|
187
|
-
else if (base?.documents[path] !== undefined) {
|
|
188
|
-
documents.delete([locator, transfer, path]);
|
|
189
|
-
}
|
|
190
|
-
if (next.binaries[path] !== undefined) {
|
|
191
|
-
files.put(binaryFileRecord(locator, transfer, next, path));
|
|
192
|
-
}
|
|
193
|
-
else if (base?.binaries[path] !== undefined) {
|
|
194
|
-
files.delete([locator, transfer, path]);
|
|
195
|
-
}
|
|
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 };
|
|
196
55
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const keys = store.getAllKeys();
|
|
200
|
-
keys.onsuccess = () => {
|
|
201
|
-
for (const key of keys.result) {
|
|
202
|
-
if (Array.isArray(key) && key[0] === locator)
|
|
203
|
-
store.delete(key);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
function removeDatabase(name) {
|
|
208
|
-
return new Promise((resolve, reject) => {
|
|
209
|
-
const removal = indexedDB.deleteDatabase(name);
|
|
210
|
-
removal.onsuccess = () => resolve();
|
|
211
|
-
removal.onerror = () => reject(removal.error);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
export async function authoredHolder() {
|
|
215
|
-
const authored = await openAuthored();
|
|
216
|
-
try {
|
|
217
|
-
const transaction = authored.transaction(FACTS, 'readonly');
|
|
218
|
-
const held = transaction.objectStore(FACTS).get(HOLDER);
|
|
219
|
-
await completed(transaction);
|
|
220
|
-
return typeof held.result === 'string' ? held.result : null;
|
|
56
|
+
function recordOf(stored) {
|
|
57
|
+
return { ...stored, model: typed(stored.locator, stored.model) };
|
|
221
58
|
}
|
|
222
|
-
|
|
223
|
-
|
|
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
|
+
]));
|
|
224
67
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
owned = held.result === holder;
|
|
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,
|
|
238
80
|
};
|
|
239
|
-
await completed(transaction);
|
|
240
|
-
return owned;
|
|
241
|
-
}
|
|
242
|
-
finally {
|
|
243
|
-
authored.close();
|
|
244
81
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
try {
|
|
249
|
-
const transaction = authored.transaction(FACTS, 'readonly');
|
|
250
|
-
const held = transaction.objectStore(FACTS).get(BINDING);
|
|
251
|
-
await completed(transaction);
|
|
252
|
-
return typeof held.result === 'string' ? held.result : null;
|
|
253
|
-
}
|
|
254
|
-
finally {
|
|
255
|
-
authored.close();
|
|
82
|
+
async function drafts(locator, paths) {
|
|
83
|
+
const held = await (await open()).roomDrafts(locator, paths);
|
|
84
|
+
return held.filter((record) => !fences.has(record.locator));
|
|
256
85
|
}
|
|
257
|
-
}
|
|
258
|
-
export async function bindAuthored(binding) {
|
|
259
|
-
const authored = await openAuthored();
|
|
260
|
-
try {
|
|
261
|
-
const transaction = authored.transaction(FACTS, 'readwrite');
|
|
262
|
-
transaction.objectStore(FACTS).put(binding, BINDING);
|
|
263
|
-
await completed(transaction);
|
|
264
|
-
}
|
|
265
|
-
finally {
|
|
266
|
-
authored.close();
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
export async function removeRuntimeStore(holder) {
|
|
270
|
-
await removeDatabase(DATABASE);
|
|
271
|
-
if (holder !== undefined && (await authoredBy(holder)))
|
|
272
|
-
return true;
|
|
273
|
-
await removeDatabase(AUTHORED);
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
export function openDatabase(name, version, upgrade) {
|
|
277
|
-
return new Promise((resolve, reject) => {
|
|
278
|
-
const opening = indexedDB.open(name, version);
|
|
279
|
-
opening.onupgradeneeded = (event) => upgrade(opening, event.oldVersion);
|
|
280
|
-
opening.onsuccess = () => resolve(opening.result);
|
|
281
|
-
opening.onerror = () => {
|
|
282
|
-
if (opening.error?.name !== 'VersionError') {
|
|
283
|
-
reject(opening.error);
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
removeDatabase(name)
|
|
287
|
-
.then(() => openDatabase(name, version, upgrade))
|
|
288
|
-
.then(resolve, reject);
|
|
289
|
-
};
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
function openReplica() {
|
|
293
|
-
return openDatabase(DATABASE, STORE_SCHEMA, (opening, oldVersion) => {
|
|
294
|
-
const database = opening.result;
|
|
295
|
-
if (oldVersion < REPLICA_SHAPE) {
|
|
296
|
-
for (const name of [...database.objectStoreNames])
|
|
297
|
-
database.deleteObjectStore(name);
|
|
298
|
-
}
|
|
299
|
-
for (const [name, parameters] of REPLICA_STORES) {
|
|
300
|
-
if (database.objectStoreNames.contains(name))
|
|
301
|
-
continue;
|
|
302
|
-
database.createObjectStore(name, parameters);
|
|
303
|
-
}
|
|
304
|
-
const messages = opening.transaction.objectStore(MESSAGES);
|
|
305
|
-
for (const [name, keyPath] of MESSAGE_INDEXES) {
|
|
306
|
-
if (!messages.indexNames.contains(name))
|
|
307
|
-
messages.createIndex(name, keyPath);
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
function openAuthored() {
|
|
312
|
-
return openDatabase(AUTHORED, AUTHORED_SCHEMA, (opening) => {
|
|
313
|
-
const database = opening.result;
|
|
314
|
-
for (const [name, parameters] of AUTHORED_STORES) {
|
|
315
|
-
if (!database.objectStoreNames.contains(name))
|
|
316
|
-
database.createObjectStore(name, parameters);
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
export async function openRuntimeStore(fenced) {
|
|
321
|
-
const authored = await openAuthored();
|
|
322
|
-
const database = await openReplica().catch((error) => {
|
|
323
|
-
authored.close();
|
|
324
|
-
throw error;
|
|
325
|
-
});
|
|
326
86
|
return {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
pending.put({
|
|
357
|
-
locator,
|
|
358
|
-
id: batch.id,
|
|
359
|
-
batch,
|
|
360
|
-
drafts: saved?.get(batch.id) ?? [],
|
|
361
|
-
submission: { state: 'waiting' },
|
|
362
|
-
lost: false,
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
}
|
|
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();
|
|
113
|
+
return {
|
|
114
|
+
rooms: new Map([...held.rooms].filter(([locator]) => !fences.has(locator))),
|
|
115
|
+
queues: new Map([...held.queues].filter(([locator]) => !fences.has(locator))),
|
|
366
116
|
};
|
|
367
|
-
const draftStore = transaction.objectStore(ROOM_DRAFTS);
|
|
368
|
-
for (const path of consumedRoomDrafts ?? [])
|
|
369
|
-
draftStore.delete([locator, path]);
|
|
370
|
-
for (const record of roomDrafts ?? [])
|
|
371
|
-
draftStore.put(record);
|
|
372
|
-
await completed(transaction);
|
|
373
|
-
},
|
|
374
|
-
async write({ next, previous, stored }) {
|
|
375
|
-
if (next === previous || fenced(next.locator))
|
|
376
|
-
return;
|
|
377
|
-
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_FILES, TRANSFERS], 'readwrite');
|
|
378
|
-
transaction.objectStore(ROOMS).put(roomRecord(next));
|
|
379
|
-
const moved = previous?.transfer !== next.transfer;
|
|
380
|
-
if (moved && previous !== null) {
|
|
381
|
-
const range = underTransfer(previous.locator, previous.transfer);
|
|
382
|
-
transaction.objectStore(DOCUMENTS).delete(range);
|
|
383
|
-
transaction.objectStore(BINARY_FILES).delete(range);
|
|
384
|
-
}
|
|
385
|
-
if (moved)
|
|
386
|
-
transaction.objectStore(TRANSFERS).delete(next.locator);
|
|
387
|
-
writeLayer(transaction, next.locator, next.transfer, next, moved ? (stored ?? null) : previous);
|
|
388
|
-
await completed(transaction);
|
|
389
|
-
},
|
|
390
|
-
async revokeModels(records) {
|
|
391
|
-
const transaction = database.transaction(ROOMS, 'readwrite');
|
|
392
|
-
const rooms = transaction.objectStore(ROOMS);
|
|
393
|
-
const revoked = { status: 'unavailable', reason: 'revoked' };
|
|
394
|
-
for (const record of records) {
|
|
395
|
-
if (fenced(record.locator))
|
|
396
|
-
continue;
|
|
397
|
-
rooms.put(roomRecord({ ...record, model: revoked, selectionModel: revoked }));
|
|
398
|
-
}
|
|
399
|
-
await completed(transaction);
|
|
400
|
-
},
|
|
401
|
-
async lastCompleted() {
|
|
402
|
-
return (await declaration(database)).lastCompleted;
|
|
403
|
-
},
|
|
404
|
-
complete(at) {
|
|
405
|
-
return updateDeclaration(database, (record) => ({ ...record, lastCompleted: at }));
|
|
406
|
-
},
|
|
407
|
-
async providerLimits() {
|
|
408
|
-
return (await declaration(database)).providerLimits;
|
|
409
|
-
},
|
|
410
|
-
async capabilities() {
|
|
411
|
-
return (await declaration(database)).capabilities;
|
|
412
|
-
},
|
|
413
|
-
declare(limits, capabilities) {
|
|
414
|
-
return updateDeclaration(database, (record) => ({
|
|
415
|
-
...record,
|
|
416
|
-
providerLimits: limits,
|
|
417
|
-
capabilities,
|
|
418
|
-
}));
|
|
419
|
-
},
|
|
420
|
-
async member() {
|
|
421
|
-
const transaction = database.transaction(DECLARATIONS, 'readonly');
|
|
422
|
-
const held = await settled(transaction.objectStore(DECLARATIONS).get(MEMBER));
|
|
423
|
-
return held ?? null;
|
|
424
|
-
},
|
|
425
|
-
async keepMember(member) {
|
|
426
|
-
const transaction = database.transaction(DECLARATIONS, 'readwrite');
|
|
427
|
-
transaction.objectStore(DECLARATIONS).put(member, MEMBER);
|
|
428
|
-
await completed(transaction);
|
|
429
|
-
},
|
|
430
|
-
async targets() {
|
|
431
|
-
const transaction = database.transaction(DECLARATIONS, 'readonly');
|
|
432
|
-
const held = await settled(transaction.objectStore(DECLARATIONS).get(TARGETS));
|
|
433
|
-
return held ?? {};
|
|
434
|
-
},
|
|
435
|
-
async keepTargets(targets) {
|
|
436
|
-
const transaction = database.transaction(DECLARATIONS, 'readwrite');
|
|
437
|
-
transaction.objectStore(DECLARATIONS).put(targets, TARGETS);
|
|
438
|
-
await completed(transaction);
|
|
439
|
-
},
|
|
440
|
-
async queues() {
|
|
441
|
-
const transaction = authored.transaction([QUEUES, PENDING_CHANGES], 'readonly');
|
|
442
|
-
const [queues, pending] = await Promise.all([
|
|
443
|
-
settled(transaction.objectStore(QUEUES).getAll()),
|
|
444
|
-
settled(transaction.objectStore(PENDING_CHANGES).getAll()),
|
|
445
|
-
]);
|
|
446
|
-
const byId = new Map(pending.map((record) => [`${record.locator}\0${record.id}`, record]));
|
|
447
|
-
return queues
|
|
448
|
-
.filter((queue) => !fenced(queue.locator))
|
|
449
|
-
.map((queue) => ({
|
|
450
|
-
locator: queue.locator,
|
|
451
|
-
pending: queue.order.map((id) => {
|
|
452
|
-
const record = byId.get(`${queue.locator}\0${id}`);
|
|
453
|
-
if (record === undefined)
|
|
454
|
-
throw new Error(`Missing Pending Change ${queue.locator}/${id}`);
|
|
455
|
-
const { batch, drafts, submission, lost, upload, accepted } = record;
|
|
456
|
-
return { batch, state: { drafts, submission, lost, upload, accepted } };
|
|
457
|
-
}),
|
|
458
|
-
}));
|
|
459
|
-
},
|
|
460
|
-
async submit(locator, id, submission, lost) {
|
|
461
|
-
if (!fenced(locator))
|
|
462
|
-
await amendPending(authored, locator, id, { submission, lost });
|
|
463
|
-
},
|
|
464
|
-
async accept(locator, id, roomVersion) {
|
|
465
|
-
if (!fenced(locator))
|
|
466
|
-
await amendPending(authored, locator, id, { accepted: roomVersion });
|
|
467
|
-
},
|
|
468
|
-
async keepUpload(locator, id, upload) {
|
|
469
|
-
if (!fenced(locator))
|
|
470
|
-
await amendPending(authored, locator, id, { upload });
|
|
471
|
-
},
|
|
472
|
-
async roomDrafts() {
|
|
473
|
-
const transaction = authored.transaction(ROOM_DRAFTS, 'readonly');
|
|
474
|
-
const held = await settled(transaction.objectStore(ROOM_DRAFTS).getAll());
|
|
475
|
-
return held.filter((record) => !fenced(record.locator));
|
|
476
|
-
},
|
|
477
|
-
async presentation() {
|
|
478
|
-
const transaction = database.transaction(PRESENTATION, 'readonly');
|
|
479
|
-
return settled(transaction.objectStore(PRESENTATION).getAll());
|
|
480
|
-
},
|
|
481
|
-
async present(record) {
|
|
482
|
-
const transaction = database.transaction(PRESENTATION, 'readwrite');
|
|
483
|
-
transaction.objectStore(PRESENTATION).put(record);
|
|
484
|
-
await completed(transaction);
|
|
485
|
-
},
|
|
486
|
-
async conversations() {
|
|
487
|
-
const transaction = database.transaction([CONVERSATIONS, MESSAGES], 'readonly');
|
|
488
|
-
const records = await settled(transaction.objectStore(CONVERSATIONS).getAll());
|
|
489
|
-
const held = new Map(records.map(({ conversation, read, partial }) => [
|
|
490
|
-
conversation,
|
|
491
|
-
{ conversation, read, partial: partial === true },
|
|
492
|
-
]));
|
|
493
|
-
const keys = transaction.objectStore(MESSAGES).index('conversation');
|
|
494
|
-
await new Promise((resolve, reject) => {
|
|
495
|
-
const cursor = keys.openKeyCursor(null, 'nextunique');
|
|
496
|
-
cursor.onerror = () => reject(cursor.error);
|
|
497
|
-
cursor.onsuccess = () => {
|
|
498
|
-
const at = cursor.result;
|
|
499
|
-
if (at === null) {
|
|
500
|
-
resolve();
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
const conversation = at.key;
|
|
504
|
-
if (!held.has(conversation)) {
|
|
505
|
-
held.set(conversation, { conversation, read: undefined, partial: true });
|
|
506
|
-
}
|
|
507
|
-
at.continue();
|
|
508
|
-
};
|
|
509
|
-
});
|
|
510
|
-
return [...held.values()];
|
|
511
|
-
},
|
|
512
|
-
async keepMessages({ conversation, messages, read }) {
|
|
513
|
-
const transaction = database.transaction([CONVERSATIONS, MESSAGES], 'readwrite');
|
|
514
|
-
const stored = transaction.objectStore(MESSAGES);
|
|
515
|
-
for (const message of messages) {
|
|
516
|
-
stored.put({ ...message, conversation });
|
|
517
|
-
}
|
|
518
|
-
if (read !== undefined) {
|
|
519
|
-
transaction.objectStore(CONVERSATIONS).put({
|
|
520
|
-
conversation,
|
|
521
|
-
read: read.at,
|
|
522
|
-
...(read.partial ? { partial: true } : {}),
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
await completed(transaction);
|
|
526
|
-
},
|
|
527
|
-
async messageWindow(conversation, limit) {
|
|
528
|
-
const transaction = database.transaction(MESSAGES, 'readonly');
|
|
529
|
-
const index = transaction.objectStore(MESSAGES).index('position');
|
|
530
|
-
const range = IDBKeyRange.bound([conversation], [conversation, []]);
|
|
531
|
-
if (limit === undefined) {
|
|
532
|
-
return (await settled(index.getAll(range))).map(accepted);
|
|
533
|
-
}
|
|
534
|
-
const latest = [];
|
|
535
|
-
if (limit === 0)
|
|
536
|
-
return latest;
|
|
537
|
-
await new Promise((resolve, reject) => {
|
|
538
|
-
const cursor = index.openCursor(range, 'prev');
|
|
539
|
-
cursor.onerror = () => reject(cursor.error);
|
|
540
|
-
cursor.onsuccess = () => {
|
|
541
|
-
const at = cursor.result;
|
|
542
|
-
if (at === null) {
|
|
543
|
-
resolve();
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
latest.push(accepted(at.value));
|
|
547
|
-
if (latest.length === limit)
|
|
548
|
-
resolve();
|
|
549
|
-
else
|
|
550
|
-
at.continue();
|
|
551
|
-
};
|
|
552
|
-
});
|
|
553
|
-
return latest.reverse();
|
|
554
|
-
},
|
|
555
|
-
async messagesAfter(conversation, identity) {
|
|
556
|
-
const transaction = database.transaction(MESSAGES, 'readonly');
|
|
557
|
-
const range = identity === null
|
|
558
|
-
? IDBKeyRange.bound([conversation], [conversation, []])
|
|
559
|
-
: IDBKeyRange.bound([conversation, identity], [conversation, []], true);
|
|
560
|
-
const held = await settled(transaction.objectStore(MESSAGES).getAll(range, READ_BATCH));
|
|
561
|
-
return held.map(accepted);
|
|
562
|
-
},
|
|
563
|
-
async messageIdentities(conversation) {
|
|
564
|
-
const transaction = database.transaction(MESSAGES, 'readonly');
|
|
565
|
-
const keys = await settled(transaction.objectStore(MESSAGES).index('conversation').getAllKeys(conversation));
|
|
566
|
-
return keys.map((key) => key[1]);
|
|
567
|
-
},
|
|
568
|
-
async turnArrived(conversation, turn) {
|
|
569
|
-
const transaction = database.transaction(MESSAGES, 'readonly');
|
|
570
|
-
const held = await settled(transaction.objectStore(MESSAGES).index('turn').count([conversation, turn]));
|
|
571
|
-
return held > 0;
|
|
572
|
-
},
|
|
573
|
-
async dropConversations(conversations) {
|
|
574
|
-
const drafts = authored.transaction(CHAT_DRAFTS, 'readwrite');
|
|
575
|
-
for (const conversation of conversations)
|
|
576
|
-
drafts.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
577
|
-
await completed(drafts);
|
|
578
|
-
const transaction = database.transaction([CONVERSATIONS, MESSAGES], 'readwrite');
|
|
579
|
-
const messages = transaction.objectStore(MESSAGES);
|
|
580
|
-
for (const conversation of conversations) {
|
|
581
|
-
transaction.objectStore(CONVERSATIONS).delete(conversation);
|
|
582
|
-
const keys = messages.index('conversation').getAllKeys(conversation);
|
|
583
|
-
keys.onsuccess = () => {
|
|
584
|
-
for (const key of keys.result)
|
|
585
|
-
messages.delete(key);
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
|
-
await completed(transaction);
|
|
589
|
-
},
|
|
590
|
-
async chatDrafts() {
|
|
591
|
-
const transaction = authored.transaction(CHAT_DRAFTS, 'readonly');
|
|
592
|
-
const held = await settled(transaction.objectStore(CHAT_DRAFTS).getAll());
|
|
593
|
-
return held.map(chatDraftRecord);
|
|
594
|
-
},
|
|
595
|
-
async keepChatDrafts(records) {
|
|
596
|
-
const transaction = authored.transaction(CHAT_DRAFTS, 'readwrite');
|
|
597
|
-
for (const record of records)
|
|
598
|
-
transaction.objectStore(CHAT_DRAFTS).put(record);
|
|
599
|
-
await completed(transaction);
|
|
600
|
-
},
|
|
601
|
-
async dropChatDraft(conversation) {
|
|
602
|
-
const transaction = authored.transaction(CHAT_DRAFTS, 'readwrite');
|
|
603
|
-
transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
604
|
-
await completed(transaction);
|
|
605
|
-
},
|
|
606
|
-
async keepRoomDraft(record) {
|
|
607
|
-
if (fenced(record.locator))
|
|
608
|
-
return;
|
|
609
|
-
const transaction = authored.transaction(ROOM_DRAFTS, 'readwrite');
|
|
610
|
-
transaction.objectStore(ROOM_DRAFTS).put(record);
|
|
611
|
-
await completed(transaction);
|
|
612
|
-
},
|
|
613
|
-
async discardRoomDraft(locator, path) {
|
|
614
|
-
if (fenced(locator))
|
|
615
|
-
return;
|
|
616
|
-
const transaction = authored.transaction(ROOM_DRAFTS, 'readwrite');
|
|
617
|
-
transaction.objectStore(ROOM_DRAFTS).delete([locator, path]);
|
|
618
|
-
await completed(transaction);
|
|
619
|
-
},
|
|
620
|
-
async fences() {
|
|
621
|
-
const transaction = authored.transaction(FENCES, 'readonly');
|
|
622
|
-
const held = await settled(transaction.objectStore(FENCES).getAll());
|
|
623
|
-
return held.map((fence) => fence.locator);
|
|
624
|
-
},
|
|
625
|
-
async erase(locators) {
|
|
626
|
-
const work = authored.transaction([FENCES, QUEUES, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
|
|
627
|
-
for (const locator of locators) {
|
|
628
|
-
work.objectStore(FENCES).put({ locator });
|
|
629
|
-
work.objectStore(QUEUES).delete(locator);
|
|
630
|
-
for (const name of [PENDING_CHANGES, ROOM_DRAFTS]) {
|
|
631
|
-
removeRoomEntries(work.objectStore(name), locator);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
await completed(work);
|
|
635
|
-
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_FILES, TRANSFERS], 'readwrite');
|
|
636
|
-
for (const locator of locators) {
|
|
637
|
-
transaction.objectStore(ROOMS).delete(locator);
|
|
638
|
-
transaction.objectStore(TRANSFERS).delete(locator);
|
|
639
|
-
transaction.objectStore(DOCUMENTS).delete(underRoom(locator));
|
|
640
|
-
transaction.objectStore(BINARY_FILES).delete(underRoom(locator));
|
|
641
|
-
}
|
|
642
|
-
await completed(transaction);
|
|
643
|
-
const fences = authored.transaction(FENCES, 'readwrite');
|
|
644
|
-
for (const locator of locators)
|
|
645
|
-
fences.objectStore(FENCES).delete(locator);
|
|
646
|
-
await completed(fences);
|
|
647
|
-
},
|
|
648
|
-
async discard(locator) {
|
|
649
|
-
const transaction = authored.transaction([QUEUES, PENDING_CHANGES], 'readwrite');
|
|
650
|
-
transaction.objectStore(QUEUES).delete(locator);
|
|
651
|
-
removeRoomEntries(transaction.objectStore(PENDING_CHANGES), locator);
|
|
652
|
-
await completed(transaction);
|
|
653
|
-
},
|
|
654
|
-
async transfers() {
|
|
655
|
-
const transaction = database.transaction(TRANSFERS, 'readonly');
|
|
656
|
-
const held = await settled(transaction.objectStore(TRANSFERS).getAll());
|
|
657
|
-
return held.filter((record) => !fenced(record.locator));
|
|
658
|
-
},
|
|
659
|
-
staged(record) {
|
|
660
|
-
const transaction = database.transaction([DOCUMENTS, BINARY_FILES], 'readonly');
|
|
661
|
-
return readLayer(transaction, record.locator, record.transfer);
|
|
662
|
-
},
|
|
663
|
-
async stage(record, page) {
|
|
664
|
-
if (fenced(record.locator))
|
|
665
|
-
return;
|
|
666
|
-
const transaction = database.transaction([TRANSFERS, DOCUMENTS, BINARY_FILES], 'readwrite');
|
|
667
|
-
writeLayer(transaction, record.locator, record.transfer, page, null);
|
|
668
|
-
transaction.objectStore(TRANSFERS).put(record);
|
|
669
|
-
await completed(transaction);
|
|
670
|
-
},
|
|
671
|
-
async abandon(locator) {
|
|
672
|
-
if (fenced(locator))
|
|
673
|
-
return;
|
|
674
|
-
const transaction = database.transaction([TRANSFERS, DOCUMENTS, BINARY_FILES], 'readwrite');
|
|
675
|
-
const transfers = transaction.objectStore(TRANSFERS);
|
|
676
|
-
const held = transfers.get(locator);
|
|
677
|
-
held.onsuccess = () => {
|
|
678
|
-
const record = held.result;
|
|
679
|
-
if (record === undefined)
|
|
680
|
-
return;
|
|
681
|
-
transfers.delete(locator);
|
|
682
|
-
const range = underTransfer(locator, record.transfer);
|
|
683
|
-
transaction.objectStore(DOCUMENTS).delete(range);
|
|
684
|
-
transaction.objectStore(BINARY_FILES).delete(range);
|
|
685
|
-
};
|
|
686
|
-
await completed(transaction);
|
|
687
|
-
},
|
|
688
|
-
async receivedHeads() {
|
|
689
|
-
const transaction = database.transaction(RECEIVED, 'readonly');
|
|
690
|
-
return settled(transaction.objectStore(RECEIVED).getAll());
|
|
691
|
-
},
|
|
692
|
-
async receivedParts(key, count) {
|
|
693
|
-
const transaction = database.transaction(RECEIVED_PARTS, 'readonly');
|
|
694
|
-
const kept = await settled(transaction
|
|
695
|
-
.objectStore(RECEIVED_PARTS)
|
|
696
|
-
.getAll(IDBKeyRange.bound([key, 0], [key, count], false, true)));
|
|
697
|
-
return kept.map((part) => part.value);
|
|
698
|
-
},
|
|
699
|
-
async keepReceived(key, head, part) {
|
|
700
|
-
const transaction = database.transaction([RECEIVED, RECEIVED_PARTS], 'readwrite');
|
|
701
|
-
transaction.objectStore(RECEIVED).put({ key, head });
|
|
702
|
-
if (part !== undefined)
|
|
703
|
-
transaction.objectStore(RECEIVED_PARTS).put({ key, ...part });
|
|
704
|
-
await completed(transaction);
|
|
705
|
-
},
|
|
706
|
-
async dropReceived(keys) {
|
|
707
|
-
const transaction = database.transaction([RECEIVED, RECEIVED_PARTS], 'readwrite');
|
|
708
|
-
for (const key of keys) {
|
|
709
|
-
transaction.objectStore(RECEIVED).delete(key);
|
|
710
|
-
transaction.objectStore(RECEIVED_PARTS).delete(IDBKeyRange.bound([key], [key, []]));
|
|
711
|
-
}
|
|
712
|
-
await completed(transaction);
|
|
713
|
-
},
|
|
714
|
-
async generation() {
|
|
715
|
-
const transaction = authored.transaction(FACTS, 'readonly');
|
|
716
|
-
const held = await settled(transaction.objectStore(FACTS).get(GENERATION));
|
|
717
|
-
return held ?? null;
|
|
718
117
|
},
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
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);
|
|
723
145
|
},
|
|
724
146
|
close() {
|
|
725
|
-
|
|
726
|
-
|
|
147
|
+
space.stop();
|
|
148
|
+
readiness.close();
|
|
149
|
+
watchers.close();
|
|
727
150
|
},
|
|
728
151
|
};
|
|
729
152
|
}
|