@agentshouse/mdruntime 0.1.0-cba6f2439bb25 → 0.1.0-cbbae1fff01c6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +308 -0
- package/dist/actions.d.ts +20 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +251 -0
- package/dist/adapter.d.ts +95 -103
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +3 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +21 -56
- package/dist/bootstrap.d.ts +12 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +213 -89
- 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 +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/change.d.ts +1 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +4 -2
- 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 +24 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +9 -5
- package/dist/collection.d.ts +23 -7
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +13 -19
- package/dist/compile.d.ts +6 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +272 -332
- package/dist/connection.d.ts +5 -143
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +105 -5253
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation-live.d.ts +135 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +247 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +53 -0
- package/dist/conversation.d.ts +41 -47
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +874 -911
- 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 +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +148 -0
- package/dist/durability.d.ts +15 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +2 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +17 -7
- package/dist/expectation.d.ts +4 -2
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +33 -11
- package/dist/failure.d.ts +1 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- 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 +20 -8
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +44 -34
- package/dist/identity.d.ts +0 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -3
- package/dist/index.d.ts +28 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/install.d.ts +54 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +538 -0
- package/dist/job.d.ts +5 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +7 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +272 -0
- package/dist/listing.d.ts +48 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +139 -0
- package/dist/live.d.ts +5 -4
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +64 -23
- package/dist/locks.d.ts +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +33 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +50 -0
- package/dist/media.d.ts +2 -2
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +22 -12
- package/dist/memory.d.ts +14 -5
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +177 -85
- package/dist/messages.d.ts +24 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +89 -31
- package/dist/model.d.ts +2 -11
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -23
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +156 -0
- package/dist/observation.d.ts +2 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +14 -14
- package/dist/opened.d.ts +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +5 -5
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +59 -0
- package/dist/outcome.d.ts +4 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +3 -0
- package/dist/overlay.d.ts +3 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +43 -21
- package/dist/parts.d.ts +11 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +21 -0
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +22 -0
- package/dist/preparation.d.ts +20 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +233 -0
- package/dist/presence.d.ts +52 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +220 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +270 -0
- package/dist/query.d.ts +14 -210
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/questions.d.ts +34 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +122 -0
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +455 -0
- package/dist/reach.d.ts +15 -13
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +187 -140
- package/dist/react.d.ts +14 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +10 -1
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +2 -16
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +4 -10
- package/dist/reads.d.ts +36 -10
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +160 -77
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +35 -1
- package/dist/refresh.d.ts +7 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +35 -7
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +57 -0
- package/dist/replica.d.ts +11 -17
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +64 -34
- package/dist/room-draft.d.ts +7 -8
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +100 -103
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +217 -0
- package/dist/rows.d.ts +14 -21
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +49 -186
- package/dist/runtime.d.ts +34 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +41 -86
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +239 -116
- package/dist/saves.d.ts +32 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +413 -0
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/shared.d.ts +1 -7
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -105
- package/dist/shown.d.ts +32 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +290 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/lanes.d.ts +20 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +77 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket/session.d.ts +38 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +23 -0
- package/dist/socket.d.ts +67 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +170 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +82 -0
- package/dist/status.d.ts +0 -6
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -6
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +34 -0
- package/dist/store/readiness.d.ts +10 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +52 -0
- package/dist/store/records.d.ts +210 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +428 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- package/dist/store/space.d.ts +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +110 -157
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +162 -394
- package/dist/stored.d.ts +59 -38
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +287 -206
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +223 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +521 -0
- package/dist/tables.d.ts +116 -56
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +214 -98
- 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/validation.d.ts +3 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +42 -100
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +21 -9
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +10 -4
- package/package.json +3 -2
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -370
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -156
package/dist/store.js
CHANGED
|
@@ -1,404 +1,172 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
}),
|
|
35
|
-
}),
|
|
36
|
-
...(founded === undefined
|
|
37
|
-
? {}
|
|
38
|
-
: {
|
|
39
|
-
founded: founded.map((batch) => ({
|
|
40
|
-
id: batch.id,
|
|
41
|
-
batch: JSON.stringify(batch),
|
|
42
|
-
files: batchFiles(batch),
|
|
43
|
-
})),
|
|
44
|
-
}),
|
|
45
|
-
...(roomDrafts === undefined ? {} : { roomDrafts: roomDrafts.map(roomDraftRow) }),
|
|
46
|
-
...(consumedRoomDrafts === undefined ? {} : { consumedRoomDrafts }),
|
|
47
|
-
...(accepted === undefined
|
|
48
|
-
? {}
|
|
49
|
-
: {
|
|
50
|
-
amendments: accepted.map(({ id, roomVersion }) => ({
|
|
51
|
-
id,
|
|
52
|
-
amendment: JSON.stringify({ accepted: roomVersion }),
|
|
53
|
-
})),
|
|
54
|
-
}),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function marked(value) {
|
|
58
|
-
return typeof value === 'object' && value !== null && FILE in value;
|
|
59
|
-
}
|
|
60
|
-
function keyed(keys, value) {
|
|
61
|
-
const stored = [];
|
|
62
|
-
const files = [];
|
|
63
|
-
const record = JSON.stringify(value, (_name, held) => {
|
|
64
|
-
if (!(held instanceof Blob))
|
|
65
|
-
return held;
|
|
66
|
-
let key = keys.get(held);
|
|
67
|
-
if (key === undefined) {
|
|
68
|
-
key = binaryLocalId();
|
|
69
|
-
keys.set(held, key);
|
|
70
|
-
}
|
|
71
|
-
stored.push({ key, blob: held });
|
|
72
|
-
files.push(key);
|
|
73
|
-
return { [FILE]: key, type: held.type };
|
|
1
|
+
import { schemaTypes } from './attached-model.js';
|
|
2
|
+
import { createCell } from './cell.js';
|
|
3
|
+
import { openedFiles } from './opened.js';
|
|
4
|
+
import { compositionOf } from './replica.js';
|
|
5
|
+
import { STARTING } from './status.js';
|
|
6
|
+
import { createInstalls, NO_INSTALL } from './store/installs.js';
|
|
7
|
+
import { openRuntimeStore, } from './store/records.js';
|
|
8
|
+
import { createReadinessQueue } from './store/readiness.js';
|
|
9
|
+
import { createRoomHeld } from './store/room-held.js';
|
|
10
|
+
import { createSpace } from './store/space.js';
|
|
11
|
+
import { createWatchers } from './store/watchers.js';
|
|
12
|
+
import { createWrites } from './store/writes.js';
|
|
13
|
+
export function createStore(options) {
|
|
14
|
+
const writes = createWrites();
|
|
15
|
+
const watchers = createWatchers(options.unpublished);
|
|
16
|
+
const { lost } = options;
|
|
17
|
+
const installs = createInstalls();
|
|
18
|
+
const seeds = new Map();
|
|
19
|
+
const landed = createRoomHeld();
|
|
20
|
+
const attached = createRoomHeld();
|
|
21
|
+
const typesHeld = new Map();
|
|
22
|
+
const device = createCell({
|
|
23
|
+
persistence: options.persistence,
|
|
24
|
+
storageLoss: null,
|
|
25
|
+
heldWhenOpened: false,
|
|
26
|
+
preparing: false,
|
|
27
|
+
sweeping: false,
|
|
28
|
+
unpreparedDemand: new Set(),
|
|
29
|
+
unpreparable: new Set(),
|
|
30
|
+
establishing: new Set(),
|
|
31
|
+
status: STARTING,
|
|
32
|
+
roomsShown: null,
|
|
74
33
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (typeof value !== 'object' || value === null)
|
|
83
|
-
return value;
|
|
84
|
-
const restored = {};
|
|
85
|
-
for (const [name, item] of Object.entries(value))
|
|
86
|
-
restored[name] = await filed(item, read);
|
|
87
|
-
return restored;
|
|
88
|
-
}
|
|
89
|
-
function json(value, fallback) {
|
|
90
|
-
return value === undefined ? fallback : JSON.parse(value);
|
|
91
|
-
}
|
|
92
|
-
export function openRuntimeStore(fenced, authored) {
|
|
93
|
-
const keys = new WeakMap();
|
|
94
|
-
const read = async (key, type) => {
|
|
95
|
-
const blob = await authored.ask({ kind: 'authored.file', key, type });
|
|
96
|
-
keys.set(blob, key);
|
|
97
|
-
return blob;
|
|
98
|
-
};
|
|
99
|
-
const restored = async (records) => Promise.all(records.map(async (record) => (await filed(JSON.parse(record), read))));
|
|
100
|
-
const amend = async (locator, id, amendment) => {
|
|
101
|
-
if (fenced(locator))
|
|
102
|
-
return;
|
|
103
|
-
await authored.ask({
|
|
104
|
-
kind: 'authored.amend',
|
|
105
|
-
locator,
|
|
106
|
-
id,
|
|
107
|
-
amendment: JSON.stringify(amendment),
|
|
34
|
+
const space = createSpace(options.database, options.spaceFreed);
|
|
35
|
+
const readiness = createReadinessQueue(options.deliverReadiness, options.unpublished);
|
|
36
|
+
let opening;
|
|
37
|
+
function open() {
|
|
38
|
+
opening ??= options.opening(openRuntimeStore(options.database)).catch((error) => {
|
|
39
|
+
opening = undefined;
|
|
40
|
+
throw error;
|
|
108
41
|
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
42
|
+
return opening;
|
|
43
|
+
}
|
|
44
|
+
function prepareAgain(locator) {
|
|
45
|
+
const { unpreparable } = device.now();
|
|
46
|
+
device.set({
|
|
47
|
+
unpreparable: locator === undefined
|
|
48
|
+
? new Set()
|
|
49
|
+
: new Set([...unpreparable].filter((held) => held !== locator)),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function typed(locator, persisted) {
|
|
53
|
+
if (persisted.status === 'unavailable')
|
|
54
|
+
return persisted;
|
|
55
|
+
const schema = persisted.snapshot.schema;
|
|
56
|
+
const held = typesHeld.get(locator);
|
|
57
|
+
if (held !== undefined && held.schema === schema)
|
|
58
|
+
return { ...persisted, types: held.types };
|
|
59
|
+
const types = schemaTypes(schema, options.roomTypes);
|
|
60
|
+
typesHeld.set(locator, { schema, types });
|
|
61
|
+
return { ...persisted, types };
|
|
62
|
+
}
|
|
63
|
+
function recordOf(stored) {
|
|
64
|
+
return { ...stored, model: typed(stored.locator, stored.model) };
|
|
65
|
+
}
|
|
66
|
+
async function rooms(locators) {
|
|
67
|
+
const held = await (await open()).rooms(locators);
|
|
68
|
+
return new Map(held
|
|
69
|
+
.filter(({ record }) => !lost(record.locator))
|
|
70
|
+
.map(({ record, indexed, documents }) => [
|
|
71
|
+
record.locator,
|
|
72
|
+
{ record: recordOf(record), indexed, documents },
|
|
73
|
+
]));
|
|
74
|
+
}
|
|
75
|
+
async function work(locator) {
|
|
76
|
+
if (lost(locator))
|
|
77
|
+
return { replica: undefined, queue: [], states: new Map() };
|
|
78
|
+
const { room, queue } = await (await open()).room(locator);
|
|
79
|
+
const batches = queue.map(({ batch }) => batch);
|
|
80
|
+
const states = new Map(queue.map(({ batch, state }) => [batch.id, state]));
|
|
81
|
+
return {
|
|
82
|
+
replica: room === null
|
|
83
|
+
? undefined
|
|
84
|
+
: { record: recordOf(room.record), queue: batches, states, overlaid: room.overlaid },
|
|
85
|
+
queue: batches,
|
|
86
|
+
states,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async function drafts(locator, paths) {
|
|
90
|
+
const held = await (await open()).roomDrafts(locator, paths);
|
|
91
|
+
return held.filter((record) => !lost(record.locator));
|
|
92
|
+
}
|
|
121
93
|
return {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
94
|
+
device,
|
|
95
|
+
space,
|
|
96
|
+
readiness,
|
|
97
|
+
ask: options.database.ask,
|
|
98
|
+
changed: options.changed,
|
|
99
|
+
open,
|
|
100
|
+
durably: (work) => writes.exclusive(async () => {
|
|
101
|
+
const local = await open();
|
|
102
|
+
return work(local);
|
|
103
|
+
}),
|
|
104
|
+
exclusive: writes.exclusive,
|
|
105
|
+
gathered: writes.gathered,
|
|
106
|
+
written: writes.written,
|
|
107
|
+
startingWrite: writes.startingWrite,
|
|
108
|
+
finishingWrite: writes.finishingWrite,
|
|
109
|
+
ahead: writes.ahead,
|
|
110
|
+
rederive: writes.rederive,
|
|
111
|
+
refreshPage: writes.refreshPage,
|
|
112
|
+
stageBytes: writes.stageBytes,
|
|
113
|
+
deriveBytes: writes.deriveBytes,
|
|
114
|
+
rooms,
|
|
115
|
+
record: async (locator) => (await rooms([locator])).get(locator)?.record,
|
|
116
|
+
work,
|
|
117
|
+
replica: async (locator) => (await work(locator)).replica,
|
|
118
|
+
async covering() {
|
|
119
|
+
const held = await (await open()).covering();
|
|
131
120
|
return {
|
|
132
|
-
rooms: new Map(held.rooms
|
|
133
|
-
|
|
134
|
-
.map(({ locator, key, record }) => [
|
|
135
|
-
locator,
|
|
136
|
-
{ ...JSON.parse(record), key },
|
|
137
|
-
])),
|
|
138
|
-
unindexed,
|
|
139
|
-
overlaid,
|
|
140
|
-
erasing: held.erasing.length > 0,
|
|
141
|
-
orphans: held.orphans,
|
|
142
|
-
lastCompleted: json(held.facts.lastCompleted, null),
|
|
143
|
-
providerLimits: json(held.facts.providerLimits, []),
|
|
144
|
-
capabilities: json(held.facts.capabilities, []),
|
|
145
|
-
member: json(held.facts.member, null),
|
|
146
|
-
targets: json(held.facts.targets, {}),
|
|
147
|
-
presentation: held.presentation.map(({ app, value }) => ({
|
|
148
|
-
app,
|
|
149
|
-
value: JSON.parse(value),
|
|
150
|
-
})),
|
|
151
|
-
conversationList: json(held.facts.conversationList, null),
|
|
121
|
+
rooms: new Map([...held.rooms].filter(([locator]) => !lost(locator))),
|
|
122
|
+
queues: new Map([...held.queues].filter(([locator]) => !lost(locator))),
|
|
152
123
|
};
|
|
153
124
|
},
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
entries(key, view, paths) {
|
|
164
|
-
return authored.ask({ kind: 'replica.entries', key, view, paths });
|
|
165
|
-
},
|
|
166
|
-
typed(key, view, paths) {
|
|
167
|
-
return authored.ask({ kind: 'replica.typed', key, view, paths });
|
|
168
|
-
},
|
|
169
|
-
referrers(key, view, targets, kinds) {
|
|
170
|
-
return authored.ask({ kind: 'replica.referrers', key, view, targets, kinds });
|
|
171
|
-
},
|
|
172
|
-
walk(key, view, after, bytes) {
|
|
173
|
-
return authored.ask({ kind: 'replica.walk', key, view, after, bytes });
|
|
174
|
-
},
|
|
175
|
-
files(key, view, after, limit) {
|
|
176
|
-
return authored.ask({ kind: 'replica.files', key, view, after, limit });
|
|
177
|
-
},
|
|
178
|
-
folders(key, view, paths) {
|
|
179
|
-
return authored.ask({ kind: 'replica.folders', key, view, paths });
|
|
180
|
-
},
|
|
181
|
-
typedWithin(key, view, roots, within) {
|
|
182
|
-
return authored.ask({ kind: 'replica.typedWithin', key, view, roots, within });
|
|
183
|
-
},
|
|
184
|
-
search(ask) {
|
|
185
|
-
return authored.ask({ kind: 'replica.search', ...ask });
|
|
186
|
-
},
|
|
187
|
-
async stage(record, composition, page) {
|
|
188
|
-
if (fenced(record.locator))
|
|
189
|
-
return null;
|
|
190
|
-
return authored.ask({
|
|
191
|
-
kind: 'replica.stage',
|
|
192
|
-
locator: record.locator,
|
|
193
|
-
transfer: record.transfer,
|
|
194
|
-
key: record.key,
|
|
195
|
-
fingerprint: composedOf(composition).fingerprint,
|
|
196
|
-
entries: page.entries,
|
|
197
|
-
folders: page.folders,
|
|
198
|
-
});
|
|
199
|
-
},
|
|
200
|
-
async refresh(key, composition, page) {
|
|
201
|
-
await authored.ask({
|
|
202
|
-
kind: 'replica.refresh',
|
|
203
|
-
key,
|
|
204
|
-
composed: composedOf(composition),
|
|
205
|
-
entries: page.entries,
|
|
206
|
-
removals: page.removals,
|
|
207
|
-
folders: page.folders,
|
|
208
|
-
folderRemovals: page.folderRemovals,
|
|
209
|
-
});
|
|
210
|
-
},
|
|
211
|
-
async unrefresh(key) {
|
|
212
|
-
await authored.ask({ kind: 'replica.unrefresh', key });
|
|
213
|
-
},
|
|
214
|
-
async commit({ rooms, writes = [], files = [], whole = false, discards = [] }) {
|
|
215
|
-
const kept = whole ? writes : writes.filter(({ locator }) => !fenced(locator));
|
|
216
|
-
const refused = whole ? kept.find(({ locator }) => fenced(locator)) : undefined;
|
|
217
|
-
if (refused !== undefined) {
|
|
218
|
-
return { fenced: refused.locator, counts: {}, changed: {}, indexed: {} };
|
|
219
|
-
}
|
|
220
|
-
for (const room of rooms)
|
|
221
|
-
change(room.key);
|
|
222
|
-
const committed = await authored.ask({
|
|
223
|
-
kind: 'replica.commit',
|
|
224
|
-
...(kept.length === 0 && files.length === 0 && discards.length === 0
|
|
225
|
-
? {}
|
|
226
|
-
: { authored: { writes: rows(kept), files, whole, discards } }),
|
|
227
|
-
rooms: rooms.filter(({ locator }) => !fenced(locator)),
|
|
228
|
-
});
|
|
229
|
-
if (committed.fenced === null || !whole)
|
|
230
|
-
noted(kept);
|
|
231
|
-
for (const locator of discards)
|
|
232
|
-
queued.delete(locator);
|
|
233
|
-
return committed;
|
|
234
|
-
},
|
|
235
|
-
async fence(locators) {
|
|
236
|
-
await authored.ask({ kind: 'replica.fence', locators });
|
|
237
|
-
for (const locator of locators)
|
|
238
|
-
queued.delete(locator);
|
|
239
|
-
},
|
|
240
|
-
async erase(locator, limit) {
|
|
241
|
-
return (await authored.ask({ kind: 'replica.erase', locator, limit })).remaining;
|
|
242
|
-
},
|
|
243
|
-
async abandon(locator) {
|
|
244
|
-
if (fenced(locator))
|
|
245
|
-
return;
|
|
246
|
-
await authored.ask({ kind: 'replica.abandon', locator });
|
|
247
|
-
},
|
|
248
|
-
async release(key) {
|
|
249
|
-
await authored.ask({ kind: 'replica.release', key });
|
|
250
|
-
},
|
|
251
|
-
async rederive(key, composition, bytes, ms, floor) {
|
|
252
|
-
change(key);
|
|
253
|
-
return authored.ask({
|
|
254
|
-
kind: 'replica.rederive',
|
|
255
|
-
key,
|
|
256
|
-
composed: composedOf(composition),
|
|
257
|
-
bytes,
|
|
258
|
-
ms,
|
|
259
|
-
floor,
|
|
260
|
-
});
|
|
261
|
-
},
|
|
262
|
-
async fact(name, value) {
|
|
263
|
-
await authored.ask({ kind: 'replica.fact', name, value: JSON.stringify(value) });
|
|
264
|
-
},
|
|
265
|
-
async queues() {
|
|
266
|
-
const { queues, pending } = await authored.ask({ kind: 'authored.queues' });
|
|
267
|
-
queued.clear();
|
|
268
|
-
for (const queue of queues)
|
|
269
|
-
queued.set(queue.locator, new Set(queue.ids));
|
|
270
|
-
const byId = new Map(pending.map((record) => [`${record.locator}\0${record.id}`, record]));
|
|
271
|
-
return queues
|
|
272
|
-
.filter((queue) => !fenced(queue.locator))
|
|
273
|
-
.map((queue) => ({
|
|
274
|
-
locator: queue.locator,
|
|
275
|
-
pending: queue.ids.map((id) => {
|
|
276
|
-
const record = byId.get(`${queue.locator}\0${id}`);
|
|
277
|
-
if (record === undefined)
|
|
278
|
-
throw new Error(`Missing Pending Change ${queue.locator}/${id}`);
|
|
279
|
-
return {
|
|
280
|
-
batch: JSON.parse(record.batch),
|
|
281
|
-
state: JSON.parse(record.state),
|
|
282
|
-
};
|
|
283
|
-
}),
|
|
284
|
-
}));
|
|
285
|
-
},
|
|
286
|
-
submit(locator, id, submission, lost) {
|
|
287
|
-
return amend(locator, id, { submission, lost });
|
|
288
|
-
},
|
|
289
|
-
keepUpload(locator, id, upload) {
|
|
290
|
-
return amend(locator, id, { upload });
|
|
291
|
-
},
|
|
292
|
-
async roomDrafts() {
|
|
293
|
-
const held = await authored.ask({ kind: 'authored.roomDrafts' });
|
|
294
|
-
return held
|
|
295
|
-
.map((record) => JSON.parse(record))
|
|
296
|
-
.filter((record) => !fenced(record.locator));
|
|
297
|
-
},
|
|
298
|
-
async present(record) {
|
|
299
|
-
await authored.ask({
|
|
300
|
-
kind: 'replica.present',
|
|
301
|
-
app: record.app,
|
|
302
|
-
value: JSON.stringify(record.value ?? null),
|
|
303
|
-
});
|
|
304
|
-
},
|
|
305
|
-
conversations() {
|
|
306
|
-
return authored.ask({ kind: 'conversation.held' });
|
|
307
|
-
},
|
|
308
|
-
async keepMessages(write) {
|
|
309
|
-
await authored.ask({ kind: 'conversation.keep', ...write });
|
|
310
|
-
},
|
|
311
|
-
messageWindow(conversation, limit, before) {
|
|
312
|
-
return authored.ask({ kind: 'conversation.window', conversation, limit, before });
|
|
313
|
-
},
|
|
314
|
-
messageCount(conversation) {
|
|
315
|
-
return authored.ask({ kind: 'conversation.count', conversation });
|
|
316
|
-
},
|
|
317
|
-
turnArrived(conversation, turn) {
|
|
318
|
-
return authored.ask({ kind: 'conversation.turn', conversation, turn });
|
|
319
|
-
},
|
|
320
|
-
async dropConversations(conversations) {
|
|
321
|
-
await authored.ask({ kind: 'conversation.drop', conversations });
|
|
322
|
-
},
|
|
323
|
-
async chatDrafts() {
|
|
324
|
-
const records = await authored.ask({ kind: 'authored.chatDrafts' });
|
|
325
|
-
return records.map((record) => JSON.parse(record));
|
|
326
|
-
},
|
|
327
|
-
async keepChatDrafts(records) {
|
|
328
|
-
await authored.ask({
|
|
329
|
-
kind: 'authored.chatDraft',
|
|
330
|
-
kept: records.map((record) => ({
|
|
331
|
-
conversation: record.conversation,
|
|
332
|
-
record: JSON.stringify(record),
|
|
333
|
-
})),
|
|
334
|
-
dropped: [],
|
|
335
|
-
});
|
|
336
|
-
},
|
|
337
|
-
async dropChatDraft(conversation) {
|
|
338
|
-
await authored.ask({ kind: 'authored.chatDraft', kept: [], dropped: [conversation] });
|
|
339
|
-
},
|
|
340
|
-
async calls() {
|
|
341
|
-
return restored(await authored.ask({ kind: 'authored.calls' }));
|
|
342
|
-
},
|
|
343
|
-
async keepCall(record) {
|
|
344
|
-
const { stored, ...kept } = keyed(keys, record);
|
|
345
|
-
await authored.ask({
|
|
346
|
-
kind: 'authored.call',
|
|
347
|
-
operation: record.operation,
|
|
348
|
-
kept,
|
|
349
|
-
files: stored,
|
|
350
|
-
});
|
|
351
|
-
},
|
|
352
|
-
async dropCall(operation) {
|
|
353
|
-
await authored.ask({ kind: 'authored.call', operation, kept: null, files: [] });
|
|
354
|
-
},
|
|
355
|
-
async keepRoomDraft(record, files) {
|
|
356
|
-
if (fenced(record.locator))
|
|
357
|
-
return;
|
|
358
|
-
const { path, ...kept } = roomDraftRow(record);
|
|
359
|
-
await authored.ask({
|
|
360
|
-
kind: 'authored.roomDraft',
|
|
361
|
-
locator: record.locator,
|
|
362
|
-
path,
|
|
363
|
-
kept,
|
|
364
|
-
files,
|
|
365
|
-
});
|
|
366
|
-
},
|
|
367
|
-
async discardRoomDraft(locator, path) {
|
|
368
|
-
if (fenced(locator))
|
|
369
|
-
return;
|
|
370
|
-
await authored.ask({ kind: 'authored.roomDraft', locator, path, kept: null, files: [] });
|
|
371
|
-
},
|
|
372
|
-
fences() {
|
|
373
|
-
return authored.ask({ kind: 'authored.fences' });
|
|
374
|
-
},
|
|
375
|
-
receivedHeads() {
|
|
376
|
-
return authored.ask({ kind: 'replica.received' });
|
|
377
|
-
},
|
|
378
|
-
receivedParts(key, count) {
|
|
379
|
-
return authored.ask({ kind: 'replica.receivedParts', key, count });
|
|
380
|
-
},
|
|
381
|
-
async keepReceived(key, head, part) {
|
|
382
|
-
await authored.ask({
|
|
383
|
-
kind: 'replica.receive',
|
|
384
|
-
key,
|
|
385
|
-
head: JSON.stringify(head),
|
|
386
|
-
...(part === undefined
|
|
387
|
-
? {}
|
|
388
|
-
: { part: { index: part.index, value: JSON.stringify(part.value) } }),
|
|
389
|
-
});
|
|
390
|
-
},
|
|
391
|
-
async dropReceived(keys) {
|
|
392
|
-
await authored.ask({ kind: 'replica.unreceive', keys });
|
|
393
|
-
},
|
|
394
|
-
generation() {
|
|
395
|
-
return fact('generation');
|
|
396
|
-
},
|
|
397
|
-
async rememberGeneration(value) {
|
|
398
|
-
await authored.ask({ kind: 'authored.remember', name: 'generation', value });
|
|
125
|
+
async status() {
|
|
126
|
+
const held = await (await open()).status();
|
|
127
|
+
return {
|
|
128
|
+
queued: held.queued.filter((locator) => !lost(locator)),
|
|
129
|
+
lastCompleted: held.lastCompleted,
|
|
130
|
+
unsent: held.unsent.filter(({ room }) => !lost(room)),
|
|
131
|
+
resets: held.resets.filter(({ locator }) => !lost(locator)),
|
|
132
|
+
returned: held.returned.filter(({ locator }) => !lost(locator)),
|
|
133
|
+
};
|
|
399
134
|
},
|
|
400
|
-
|
|
401
|
-
|
|
135
|
+
queued: async () => (await (await open()).queued()).filter((locator) => !lost(locator)),
|
|
136
|
+
drafts,
|
|
137
|
+
draft: async (locator, path) => (await drafts(locator, [path]))[0],
|
|
138
|
+
composed: ({ model, declaration }) => compositionOf(model, declaration.typedSelection, options.builtIn, options.typedPaths),
|
|
139
|
+
publication: watchers.publication,
|
|
140
|
+
owing: watchers.owing,
|
|
141
|
+
watch: watchers.watch,
|
|
142
|
+
watching: watchers.watching,
|
|
143
|
+
tell: watchers.tell,
|
|
144
|
+
installs,
|
|
145
|
+
seeds: {
|
|
146
|
+
of: (key) => seeds.get(key),
|
|
147
|
+
keep(key, seed) {
|
|
148
|
+
seeds.set(key, seed);
|
|
149
|
+
},
|
|
150
|
+
drop(key) {
|
|
151
|
+
seeds.delete(key);
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
landed,
|
|
155
|
+
attached,
|
|
156
|
+
opened: openedFiles(options.database, lost),
|
|
157
|
+
prepareAgain,
|
|
158
|
+
part: (file, part) => options.database.ask({ kind: 'file.part', key: file, part }),
|
|
159
|
+
forget(locator) {
|
|
160
|
+
typesHeld.delete(locator);
|
|
161
|
+
landed.forget(locator);
|
|
162
|
+
attached.forget(locator);
|
|
163
|
+
installs.change(locator, ({ installing }) => ({ ...NO_INSTALL, installing }));
|
|
164
|
+
prepareAgain(locator);
|
|
165
|
+
},
|
|
166
|
+
close() {
|
|
167
|
+
space.stop();
|
|
168
|
+
readiness.close();
|
|
169
|
+
watchers.close();
|
|
402
170
|
},
|
|
403
171
|
};
|
|
404
172
|
}
|