@agentshouse/mdruntime 0.1.0-cc294e382554d → 0.1.0-cc56db96f86ae
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/AGENTS.md +28 -23
- package/README.md +9 -8
- package/dist/adapter.d.ts +11 -10
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +60 -29
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +2 -6
- package/dist/change.d.ts +31 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +10 -1
- package/dist/chat/house.d.ts +25 -0
- package/dist/chat/house.d.ts.map +1 -0
- package/dist/chat/house.js +38 -0
- package/dist/chat/input.d.ts +3 -1
- package/dist/chat/input.d.ts.map +1 -1
- package/dist/chat/input.js +11 -18
- package/dist/chat/message.d.ts.map +1 -1
- package/dist/chat/message.js +45 -10
- package/dist/chat/messages.d.ts +6 -1
- package/dist/chat/messages.d.ts.map +1 -1
- package/dist/chat/messages.js +14 -11
- package/dist/chat/name.d.ts +1 -0
- package/dist/chat/name.d.ts.map +1 -1
- package/dist/chat/name.js +1 -1
- package/dist/chat/opened.d.ts +1 -0
- package/dist/chat/opened.d.ts.map +1 -1
- package/dist/chat/opened.js +2 -0
- package/dist/chat/overlay.d.ts.map +1 -1
- package/dist/chat/overlay.js +1 -5
- package/dist/chat/parts.d.ts +1 -0
- package/dist/chat/parts.d.ts.map +1 -1
- package/dist/chat/parts.js +3 -2
- package/dist/chat/provider.d.ts +5 -1
- package/dist/chat/provider.d.ts.map +1 -1
- package/dist/chat/provider.js +58 -77
- package/dist/chat/ready.d.ts +4 -1
- package/dist/chat/ready.d.ts.map +1 -1
- package/dist/chat/ready.js +7 -5
- package/dist/chat/room-file.d.ts +8 -0
- package/dist/chat/room-file.d.ts.map +1 -0
- package/dist/chat/room-file.js +67 -0
- package/dist/chat/style.d.ts.map +1 -1
- package/dist/chat/style.js +4 -0
- package/dist/chat.d.ts +1 -0
- package/dist/chat.d.ts.map +1 -1
- package/dist/client.d.ts +4 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -0
- package/dist/collection.d.ts +2 -2
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +56 -40
- package/dist/connection.d.ts +5 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +723 -158
- package/dist/conversation.d.ts +2 -2
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +18 -29
- package/dist/digest.d.ts +2 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +100 -0
- package/dist/durability.d.ts +1 -1
- package/dist/file.d.ts +2 -10
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -120
- package/dist/host.d.ts +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +7 -3
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +9 -5
- package/dist/outcome.d.ts +20 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +22 -0
- package/dist/overlay.d.ts +1 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +27 -3
- package/dist/query.d.ts +2 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +1 -0
- package/dist/reach.d.ts +5 -1
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +144 -39
- package/dist/read-side.d.ts +4 -4
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +585 -232
- package/dist/readiness.d.ts +1 -1
- package/dist/readiness.d.ts.map +1 -1
- package/dist/recovery.d.ts +2 -2
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +8 -7
- package/dist/refresh.js +8 -8
- package/dist/replica.d.ts +1 -2
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +69 -48
- package/dist/room-draft.d.ts +3 -1
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +21 -13
- package/dist/save.d.ts +43 -7
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +329 -77
- package/dist/search.d.ts +1 -1
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +61 -10
- package/dist/shared.d.ts +5 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +72 -9
- package/dist/store.d.ts +8 -13
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +189 -230
- package/dist/tables.d.ts +181 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +309 -0
- package/dist/turn.d.ts +1 -1
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +9 -6
- package/dist/windows.d.ts +0 -5
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +0 -9
- package/dist/wire.d.ts +8 -0
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +2 -0
- package/package.json +6 -2
package/dist/store.js
CHANGED
|
@@ -1,44 +1,25 @@
|
|
|
1
1
|
import { sameBinary, sameChange } from './overlay.js';
|
|
2
|
-
import { differences } from './shared.js';
|
|
2
|
+
import { differences, keysIn } from './shared.js';
|
|
3
3
|
import { inUnits, ROW_WEIGHT, stepped } from './turn.js';
|
|
4
4
|
import { precedes } from './windows.js';
|
|
5
|
+
import { binaryLocalId } from './identity.js';
|
|
5
6
|
const DATABASE = 'mdruntime';
|
|
6
|
-
const AUTHORED = 'mdruntime-authored';
|
|
7
|
-
const FENCES = 'fences';
|
|
8
7
|
const ROOMS = 'rooms';
|
|
9
8
|
const DOCUMENTS = 'documents';
|
|
10
9
|
const BINARY_FILES = 'binaryFiles';
|
|
11
10
|
const TRANSFERS = 'transfers';
|
|
12
11
|
const RECEIVED = 'received';
|
|
13
12
|
const RECEIVED_PARTS = 'receivedParts';
|
|
14
|
-
const PENDING_CHANGES = 'pendingChanges';
|
|
15
13
|
const DECLARATIONS = 'declarations';
|
|
16
|
-
const ROOM_DRAFTS = 'roomDrafts';
|
|
17
14
|
const PRESENTATION = 'presentation';
|
|
18
15
|
const CONVERSATIONS = 'conversations';
|
|
19
16
|
const MESSAGES = 'messages';
|
|
20
|
-
const CHAT_DRAFTS = 'chatDrafts';
|
|
21
|
-
const CALLS = 'calls';
|
|
22
|
-
const QUEUES = 'queues';
|
|
23
|
-
const FACTS = 'facts';
|
|
24
17
|
const CURRENT = 'current';
|
|
25
18
|
const MEMBER = 'member';
|
|
26
19
|
const TARGETS = 'targets';
|
|
27
|
-
const
|
|
28
|
-
const HOLDER = 'holder';
|
|
29
|
-
const BINDING = 'binding';
|
|
20
|
+
const FILE = '\u0000file';
|
|
30
21
|
export const STORE_SCHEMA = 25;
|
|
31
22
|
const REPLICA_SHAPE = 23;
|
|
32
|
-
export const AUTHORED_SCHEMA = 3;
|
|
33
|
-
const AUTHORED_STORES = [
|
|
34
|
-
[QUEUES, { keyPath: 'locator' }],
|
|
35
|
-
[PENDING_CHANGES, { keyPath: ['locator', 'id'] }],
|
|
36
|
-
[ROOM_DRAFTS, { keyPath: ['locator', 'path'] }],
|
|
37
|
-
[CHAT_DRAFTS, { keyPath: 'conversation' }],
|
|
38
|
-
[CALLS, { keyPath: 'operation' }],
|
|
39
|
-
[FACTS, undefined],
|
|
40
|
-
[FENCES, { keyPath: 'locator' }],
|
|
41
|
-
];
|
|
42
23
|
const REPLICA_STORES = [
|
|
43
24
|
[ROOMS, { keyPath: 'locator' }],
|
|
44
25
|
[DOCUMENTS, { keyPath: ['locator', 'transfer', 'path'] }],
|
|
@@ -128,17 +109,6 @@ function updateDeclaration(database, update) {
|
|
|
128
109
|
};
|
|
129
110
|
});
|
|
130
111
|
}
|
|
131
|
-
function amendPending(database, locator, id, amendment) {
|
|
132
|
-
return transacted(database, PENDING_CHANGES, 'readwrite', (transaction) => {
|
|
133
|
-
const pending = transaction.objectStore(PENDING_CHANGES);
|
|
134
|
-
const request = pending.get([locator, id]);
|
|
135
|
-
request.onsuccess = () => {
|
|
136
|
-
const record = request.result;
|
|
137
|
-
if (record !== undefined)
|
|
138
|
-
pending.put({ ...record, ...amendment });
|
|
139
|
-
};
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
112
|
function accepted({ conversation: _held, ...message }) {
|
|
143
113
|
return message;
|
|
144
114
|
}
|
|
@@ -146,9 +116,6 @@ function roomRecord(record) {
|
|
|
146
116
|
const { documents, binaries, revisions, fileIds, changes, written, ...room } = record;
|
|
147
117
|
return room;
|
|
148
118
|
}
|
|
149
|
-
function chatDraftRecord(record) {
|
|
150
|
-
return { ...record, revision: record.revision ?? '' };
|
|
151
|
-
}
|
|
152
119
|
function underTransfer(locator, transfer, after) {
|
|
153
120
|
return after === undefined
|
|
154
121
|
? IDBKeyRange.bound([locator, transfer], [locator, transfer, []])
|
|
@@ -218,7 +185,7 @@ function binaryFileRecord(locator, transfer, layer, path) {
|
|
|
218
185
|
}
|
|
219
186
|
function* changedIn(next, base) {
|
|
220
187
|
if (base === null)
|
|
221
|
-
return
|
|
188
|
+
return yield* keysIn(next.documents, next.binaries);
|
|
222
189
|
return new Set([
|
|
223
190
|
...(yield* differences(base.documents, next.documents)),
|
|
224
191
|
...(yield* differences(base.revisions, next.revisions)),
|
|
@@ -255,15 +222,6 @@ function writeLayer(transaction, locator, transfer, layer) {
|
|
|
255
222
|
: new Promise((resolve) => request.addEventListener('success', () => resolve()));
|
|
256
223
|
});
|
|
257
224
|
}
|
|
258
|
-
function removeRoomEntries(store, locator) {
|
|
259
|
-
const keys = store.getAllKeys();
|
|
260
|
-
keys.onsuccess = () => {
|
|
261
|
-
for (const key of keys.result) {
|
|
262
|
-
if (Array.isArray(key) && key[0] === locator)
|
|
263
|
-
store.delete(key);
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
225
|
function removeDatabase(name) {
|
|
268
226
|
return new Promise((resolve, reject) => {
|
|
269
227
|
const removal = indexedDB.deleteDatabase(name);
|
|
@@ -271,63 +229,9 @@ function removeDatabase(name) {
|
|
|
271
229
|
removal.onerror = () => reject(removal.error);
|
|
272
230
|
});
|
|
273
231
|
}
|
|
274
|
-
export async function
|
|
275
|
-
const authored = await openAuthored();
|
|
276
|
-
try {
|
|
277
|
-
const held = await transacted(authored, FACTS, 'readonly', (transaction) => settled(transaction.objectStore(FACTS).get(HOLDER)));
|
|
278
|
-
return typeof held === 'string' ? held : null;
|
|
279
|
-
}
|
|
280
|
-
finally {
|
|
281
|
-
authored.close();
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
export async function authoredBy(holder) {
|
|
285
|
-
const authored = await openAuthored();
|
|
286
|
-
try {
|
|
287
|
-
let owned = true;
|
|
288
|
-
await transacted(authored, FACTS, 'readwrite', (transaction) => {
|
|
289
|
-
const facts = transaction.objectStore(FACTS);
|
|
290
|
-
const held = facts.get(HOLDER);
|
|
291
|
-
held.onsuccess = () => {
|
|
292
|
-
if (held.result === undefined)
|
|
293
|
-
facts.put(holder, HOLDER);
|
|
294
|
-
else
|
|
295
|
-
owned = held.result === holder;
|
|
296
|
-
};
|
|
297
|
-
});
|
|
298
|
-
return owned;
|
|
299
|
-
}
|
|
300
|
-
finally {
|
|
301
|
-
authored.close();
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
export async function authoredBinding() {
|
|
305
|
-
const authored = await openAuthored();
|
|
306
|
-
try {
|
|
307
|
-
const held = await transacted(authored, FACTS, 'readonly', (transaction) => settled(transaction.objectStore(FACTS).get(BINDING)));
|
|
308
|
-
return typeof held === 'string' ? held : null;
|
|
309
|
-
}
|
|
310
|
-
finally {
|
|
311
|
-
authored.close();
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
export async function bindAuthored(binding) {
|
|
315
|
-
const authored = await openAuthored();
|
|
316
|
-
try {
|
|
317
|
-
await transacted(authored, FACTS, 'readwrite', (transaction) => {
|
|
318
|
-
transaction.objectStore(FACTS).put(binding, BINDING);
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
finally {
|
|
322
|
-
authored.close();
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
export async function removeRuntimeStore(holder) {
|
|
232
|
+
export async function endRuntimeStore(database, holder) {
|
|
326
233
|
await removeDatabase(DATABASE);
|
|
327
|
-
|
|
328
|
-
return true;
|
|
329
|
-
await removeDatabase(AUTHORED);
|
|
330
|
-
return false;
|
|
234
|
+
return database.ask({ kind: 'authored.end', holder: holder ?? null });
|
|
331
235
|
}
|
|
332
236
|
export function openDatabase(name, version, upgrade) {
|
|
333
237
|
return new Promise((resolve, reject) => {
|
|
@@ -364,21 +268,111 @@ function openReplica() {
|
|
|
364
268
|
}
|
|
365
269
|
});
|
|
366
270
|
}
|
|
367
|
-
function
|
|
368
|
-
return
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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);
|
|
373
329
|
}
|
|
330
|
+
stored.push({ key, blob: held });
|
|
331
|
+
files.push(key);
|
|
332
|
+
return { [FILE]: key, type: held.type };
|
|
374
333
|
});
|
|
334
|
+
return { record, files, stored };
|
|
375
335
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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),
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
const fact = (name) => authored.ask({ kind: 'authored.fact', name });
|
|
368
|
+
const queued = new Map();
|
|
369
|
+
const rows = (writes) => writes.map((write) => authoredRows(write, queued.get(write.locator)));
|
|
370
|
+
const noted = (writes) => {
|
|
371
|
+
for (const { locator, queue } of writes) {
|
|
372
|
+
if (queue !== undefined)
|
|
373
|
+
queued.set(locator, new Set(queue.map(({ id }) => id)));
|
|
374
|
+
}
|
|
375
|
+
};
|
|
382
376
|
return {
|
|
383
377
|
all() {
|
|
384
378
|
return transacted(database, [ROOMS, DOCUMENTS, BINARY_FILES], 'readonly', async (transaction) => {
|
|
@@ -393,53 +387,26 @@ export async function openRuntimeStore(fenced) {
|
|
|
393
387
|
return records;
|
|
394
388
|
});
|
|
395
389
|
},
|
|
396
|
-
async keepAuthored(
|
|
397
|
-
|
|
390
|
+
async keepAuthored(...writes) {
|
|
391
|
+
const kept = writes.filter(({ locator }) => !fenced(locator));
|
|
392
|
+
if (kept.length === 0)
|
|
398
393
|
return;
|
|
399
|
-
await
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
if (!after.has(id))
|
|
412
|
-
pending.delete([locator, id]);
|
|
413
|
-
}
|
|
414
|
-
for (const batch of queue) {
|
|
415
|
-
if (!before.has(batch.id)) {
|
|
416
|
-
pending.put({
|
|
417
|
-
locator,
|
|
418
|
-
id: batch.id,
|
|
419
|
-
batch,
|
|
420
|
-
drafts: saved?.get(batch.id) ?? [],
|
|
421
|
-
submission: { state: 'waiting' },
|
|
422
|
-
lost: false,
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
for (const batch of founded ?? []) {
|
|
427
|
-
if (!before.has(batch.id))
|
|
428
|
-
continue;
|
|
429
|
-
const stored = pending.get([locator, batch.id]);
|
|
430
|
-
stored.onsuccess = () => {
|
|
431
|
-
const record = stored.result;
|
|
432
|
-
if (record !== undefined)
|
|
433
|
-
pending.put({ ...record, batch });
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
const draftStore = transaction.objectStore(ROOM_DRAFTS);
|
|
438
|
-
for (const path of consumedRoomDrafts ?? [])
|
|
439
|
-
draftStore.delete([locator, path]);
|
|
440
|
-
for (const record of roomDrafts ?? [])
|
|
441
|
-
draftStore.put(record);
|
|
394
|
+
await authored.ask({ kind: 'authored.keep', writes: rows(kept), files: [], whole: false });
|
|
395
|
+
noted(kept);
|
|
396
|
+
},
|
|
397
|
+
async saveAuthored(files, ...writes) {
|
|
398
|
+
const refused = writes.find(({ locator }) => fenced(locator));
|
|
399
|
+
if (refused !== undefined)
|
|
400
|
+
return refused.locator;
|
|
401
|
+
const fencedThere = await authored.ask({
|
|
402
|
+
kind: 'authored.keep',
|
|
403
|
+
writes: rows(writes),
|
|
404
|
+
files,
|
|
405
|
+
whole: true,
|
|
442
406
|
});
|
|
407
|
+
if (fencedThere === null)
|
|
408
|
+
noted(writes);
|
|
409
|
+
return fencedThere;
|
|
443
410
|
},
|
|
444
411
|
async write({ next, previous, stored }) {
|
|
445
412
|
if (next === previous || fenced(next.locator))
|
|
@@ -510,39 +477,40 @@ export async function openRuntimeStore(fenced) {
|
|
|
510
477
|
});
|
|
511
478
|
},
|
|
512
479
|
async queues() {
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
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));
|
|
517
484
|
const byId = new Map(pending.map((record) => [`${record.locator}\0${record.id}`, record]));
|
|
518
485
|
return queues
|
|
519
486
|
.filter((queue) => !fenced(queue.locator))
|
|
520
487
|
.map((queue) => ({
|
|
521
488
|
locator: queue.locator,
|
|
522
|
-
pending: queue.
|
|
489
|
+
pending: queue.ids.map((id) => {
|
|
523
490
|
const record = byId.get(`${queue.locator}\0${id}`);
|
|
524
491
|
if (record === undefined)
|
|
525
492
|
throw new Error(`Missing Pending Change ${queue.locator}/${id}`);
|
|
526
|
-
|
|
527
|
-
|
|
493
|
+
return {
|
|
494
|
+
batch: JSON.parse(record.batch),
|
|
495
|
+
state: JSON.parse(record.state),
|
|
496
|
+
};
|
|
528
497
|
}),
|
|
529
498
|
}));
|
|
530
499
|
},
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
await amendPending(authored, locator, id, { submission, lost });
|
|
500
|
+
submit(locator, id, submission, lost) {
|
|
501
|
+
return amend(locator, id, { submission, lost });
|
|
534
502
|
},
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
await amendPending(authored, locator, id, { accepted: roomVersion });
|
|
503
|
+
accept(locator, id, roomVersion) {
|
|
504
|
+
return amend(locator, id, { accepted: roomVersion });
|
|
538
505
|
},
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
await amendPending(authored, locator, id, { upload });
|
|
506
|
+
keepUpload(locator, id, upload) {
|
|
507
|
+
return amend(locator, id, { upload });
|
|
542
508
|
},
|
|
543
509
|
async roomDrafts() {
|
|
544
|
-
const held = await
|
|
545
|
-
return held
|
|
510
|
+
const held = await authored.ask({ kind: 'authored.roomDrafts' });
|
|
511
|
+
return held
|
|
512
|
+
.map((record) => JSON.parse(record))
|
|
513
|
+
.filter((record) => !fenced(record.locator));
|
|
546
514
|
},
|
|
547
515
|
presentation() {
|
|
548
516
|
return transacted(database, PRESENTATION, 'readonly', (transaction) => settled(transaction.objectStore(PRESENTATION).getAll()));
|
|
@@ -645,10 +613,7 @@ export async function openRuntimeStore(fenced) {
|
|
|
645
613
|
return held > 0;
|
|
646
614
|
},
|
|
647
615
|
async dropConversations(conversations) {
|
|
648
|
-
await
|
|
649
|
-
for (const conversation of conversations)
|
|
650
|
-
drafts.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
651
|
-
});
|
|
616
|
+
await authored.ask({ kind: 'authored.chatDraft', kept: [], dropped: conversations });
|
|
652
617
|
await transacted(database, [CONVERSATIONS, MESSAGES], 'readwrite', (transaction) => {
|
|
653
618
|
const messages = transaction.objectStore(MESSAGES);
|
|
654
619
|
for (const conversation of conversations) {
|
|
@@ -662,61 +627,61 @@ export async function openRuntimeStore(fenced) {
|
|
|
662
627
|
});
|
|
663
628
|
},
|
|
664
629
|
async chatDrafts() {
|
|
665
|
-
const
|
|
666
|
-
return
|
|
630
|
+
const records = await authored.ask({ kind: 'authored.chatDrafts' });
|
|
631
|
+
return records.map((record) => JSON.parse(record));
|
|
667
632
|
},
|
|
668
633
|
async keepChatDrafts(records) {
|
|
669
|
-
await
|
|
670
|
-
|
|
671
|
-
|
|
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: [],
|
|
672
641
|
});
|
|
673
642
|
},
|
|
674
643
|
async dropChatDraft(conversation) {
|
|
675
|
-
await
|
|
676
|
-
transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
677
|
-
});
|
|
644
|
+
await authored.ask({ kind: 'authored.chatDraft', kept: [], dropped: [conversation] });
|
|
678
645
|
},
|
|
679
|
-
calls() {
|
|
680
|
-
return
|
|
646
|
+
async calls() {
|
|
647
|
+
return restored(await authored.ask({ kind: 'authored.calls' }));
|
|
681
648
|
},
|
|
682
649
|
async keepCall(record) {
|
|
683
|
-
|
|
684
|
-
|
|
650
|
+
const { stored, ...kept } = keyed(keys, record);
|
|
651
|
+
await authored.ask({
|
|
652
|
+
kind: 'authored.call',
|
|
653
|
+
operation: record.operation,
|
|
654
|
+
kept,
|
|
655
|
+
files: stored,
|
|
685
656
|
});
|
|
686
657
|
},
|
|
687
658
|
async dropCall(operation) {
|
|
688
|
-
await
|
|
689
|
-
transaction.objectStore(CALLS).delete(operation);
|
|
690
|
-
});
|
|
659
|
+
await authored.ask({ kind: 'authored.call', operation, kept: null, files: [] });
|
|
691
660
|
},
|
|
692
|
-
async keepRoomDraft(record) {
|
|
661
|
+
async keepRoomDraft(record, files) {
|
|
693
662
|
if (fenced(record.locator))
|
|
694
663
|
return;
|
|
695
|
-
|
|
696
|
-
|
|
664
|
+
const { path, ...kept } = roomDraftRow(record);
|
|
665
|
+
await authored.ask({
|
|
666
|
+
kind: 'authored.roomDraft',
|
|
667
|
+
locator: record.locator,
|
|
668
|
+
path,
|
|
669
|
+
kept,
|
|
670
|
+
files,
|
|
697
671
|
});
|
|
698
672
|
},
|
|
699
673
|
async discardRoomDraft(locator, path) {
|
|
700
674
|
if (fenced(locator))
|
|
701
675
|
return;
|
|
702
|
-
await
|
|
703
|
-
transaction.objectStore(ROOM_DRAFTS).delete([locator, path]);
|
|
704
|
-
});
|
|
676
|
+
await authored.ask({ kind: 'authored.roomDraft', locator, path, kept: null, files: [] });
|
|
705
677
|
},
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
return held.map((fence) => fence.locator);
|
|
678
|
+
fences() {
|
|
679
|
+
return authored.ask({ kind: 'authored.fences' });
|
|
709
680
|
},
|
|
710
681
|
async erase(locators) {
|
|
711
|
-
await
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
work.objectStore(QUEUES).delete(locator);
|
|
715
|
-
for (const name of [PENDING_CHANGES, ROOM_DRAFTS]) {
|
|
716
|
-
removeRoomEntries(work.objectStore(name), locator);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
});
|
|
682
|
+
await authored.ask({ kind: 'authored.fence', locators });
|
|
683
|
+
for (const locator of locators)
|
|
684
|
+
queued.delete(locator);
|
|
720
685
|
await transacted(database, [ROOMS, DOCUMENTS, BINARY_FILES, TRANSFERS], 'readwrite', (transaction) => {
|
|
721
686
|
for (const locator of locators) {
|
|
722
687
|
transaction.objectStore(ROOMS).delete(locator);
|
|
@@ -725,16 +690,11 @@ export async function openRuntimeStore(fenced) {
|
|
|
725
690
|
transaction.objectStore(BINARY_FILES).delete(underRoom(locator));
|
|
726
691
|
}
|
|
727
692
|
});
|
|
728
|
-
await
|
|
729
|
-
for (const locator of locators)
|
|
730
|
-
fences.objectStore(FENCES).delete(locator);
|
|
731
|
-
});
|
|
693
|
+
await authored.ask({ kind: 'authored.unfence', locators });
|
|
732
694
|
},
|
|
733
695
|
async discard(locator) {
|
|
734
|
-
await
|
|
735
|
-
|
|
736
|
-
removeRoomEntries(transaction.objectStore(PENDING_CHANGES), locator);
|
|
737
|
-
});
|
|
696
|
+
await authored.ask({ kind: 'authored.discard', locator });
|
|
697
|
+
queued.delete(locator);
|
|
738
698
|
},
|
|
739
699
|
async transfers() {
|
|
740
700
|
const held = await transacted(database, TRANSFERS, 'readonly', (transaction) => settled(transaction.objectStore(TRANSFERS).getAll()));
|
|
@@ -799,18 +759,17 @@ export async function openRuntimeStore(fenced) {
|
|
|
799
759
|
}
|
|
800
760
|
});
|
|
801
761
|
},
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
return held ?? null;
|
|
762
|
+
generation() {
|
|
763
|
+
return fact('generation');
|
|
805
764
|
},
|
|
806
765
|
async rememberGeneration(value) {
|
|
807
|
-
await
|
|
808
|
-
|
|
809
|
-
|
|
766
|
+
await authored.ask({ kind: 'authored.remember', name: 'generation', value });
|
|
767
|
+
},
|
|
768
|
+
file(key, type) {
|
|
769
|
+
return authored.ask({ kind: 'authored.file', key, type });
|
|
810
770
|
},
|
|
811
771
|
close() {
|
|
812
|
-
|
|
813
|
-
void idle(held).then(() => held.close());
|
|
772
|
+
void idle(database).then(() => database.close());
|
|
814
773
|
},
|
|
815
774
|
};
|
|
816
775
|
}
|