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