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