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