@agentshouse/mdruntime 0.1.0-alpha.5 → 0.1.0-alpha.50
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 +210 -0
- package/README.md +44 -0
- package/dist/adapter.d.ts +253 -19
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +2 -1
- package/dist/adapter.js.map +1 -1
- package/dist/attachment.d.ts +3 -0
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +11 -0
- package/dist/attachment.js.map +1 -0
- package/dist/bootstrap.d.ts +7 -6
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +30 -10
- package/dist/bootstrap.js.map +1 -1
- package/dist/change-set.d.ts +33 -0
- package/dist/change-set.d.ts.map +1 -0
- package/dist/change-set.js +95 -0
- package/dist/change-set.js.map +1 -0
- package/dist/change.d.ts +10 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js.map +1 -1
- package/dist/client.d.ts +75 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +237 -0
- package/dist/client.js.map +1 -0
- package/dist/collection.d.ts +26 -12
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +78 -31
- package/dist/collection.js.map +1 -1
- package/dist/connection.d.ts +85 -28
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1756 -510
- package/dist/connection.js.map +1 -1
- package/dist/conversation.d.ts +79 -0
- package/dist/conversation.d.ts.map +1 -0
- package/dist/conversation.js +635 -0
- package/dist/conversation.js.map +1 -0
- package/dist/durability.d.ts +8 -3
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +8 -62
- package/dist/durability.js.map +1 -1
- package/dist/file.d.ts +20 -0
- package/dist/file.d.ts.map +1 -0
- package/dist/file.js +149 -0
- package/dist/file.js.map +1 -0
- package/dist/host.d.ts +14 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +213 -0
- package/dist/host.js.map +1 -0
- package/dist/identity.d.ts +3 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +23 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +15 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/memory.d.ts +19 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +283 -24
- package/dist/memory.js.map +1 -1
- package/dist/model.d.ts +55 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +36 -0
- package/dist/model.js.map +1 -0
- package/dist/observation.d.ts +25 -0
- package/dist/observation.d.ts.map +1 -0
- package/dist/observation.js +92 -0
- package/dist/observation.js.map +1 -0
- package/dist/outcome.d.ts +22 -18
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +1 -11
- package/dist/outcome.js.map +1 -1
- package/dist/overlay.d.ts +9 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +145 -6
- package/dist/overlay.js.map +1 -1
- package/dist/paths.d.ts +0 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +0 -4
- package/dist/paths.js.map +1 -1
- package/dist/query.d.ts +213 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +470 -0
- package/dist/query.js.map +1 -0
- package/dist/read-side.d.ts +14 -0
- package/dist/read-side.d.ts.map +1 -0
- package/dist/read-side.js +457 -0
- package/dist/read-side.js.map +1 -0
- package/dist/refresh.d.ts +4 -4
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +40 -10
- package/dist/refresh.js.map +1 -1
- package/dist/replica.d.ts +27 -4
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +255 -13
- package/dist/replica.js.map +1 -1
- package/dist/room-draft.d.ts +124 -0
- package/dist/room-draft.d.ts.map +1 -0
- package/dist/room-draft.js +406 -0
- package/dist/room-draft.js.map +1 -0
- package/dist/rows.d.ts +41 -0
- package/dist/rows.d.ts.map +1 -0
- package/dist/rows.js +102 -0
- package/dist/rows.js.map +1 -0
- package/dist/save.d.ts +11 -2
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +116 -128
- package/dist/save.js.map +1 -1
- package/dist/search.d.ts +61 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +155 -0
- package/dist/search.js.map +1 -0
- package/dist/status.d.ts +9 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +5 -4
- package/dist/status.js.map +1 -1
- package/dist/store.d.ts +90 -18
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +492 -67
- package/dist/store.js.map +1 -1
- package/dist/transfer.d.ts +5 -0
- package/dist/transfer.d.ts.map +1 -1
- package/dist/transfer.js.map +1 -1
- package/dist/wire.d.ts +64 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +145 -0
- package/dist/wire.js.map +1 -0
- package/package.json +15 -13
package/dist/store.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sameChange } from './overlay.js';
|
|
2
2
|
const DATABASE = 'mdruntime';
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
3
|
+
const ROOMS = 'rooms';
|
|
4
|
+
const DOCUMENTS = 'documents';
|
|
5
|
+
const BINARY_TARGETS = 'binaryTargets';
|
|
6
|
+
const ATTACHMENTS = 'attachments';
|
|
7
|
+
const PENDING_CHANGES = 'pendingChanges';
|
|
8
|
+
const OUTCOMES = 'outcomes';
|
|
9
|
+
const DECLARATIONS = 'declarations';
|
|
10
|
+
const ROOM_DRAFTS = 'roomDrafts';
|
|
11
|
+
const PRESENTATION = 'presentation';
|
|
12
|
+
const CONVERSATIONS = 'conversations';
|
|
13
|
+
const MESSAGES = 'messages';
|
|
14
|
+
const CHAT_DRAFTS = 'chatDrafts';
|
|
15
|
+
const CURRENT = 'current';
|
|
16
|
+
const SCHEMA = 19;
|
|
12
17
|
function settled(request) {
|
|
13
18
|
return new Promise((resolve, reject)=>{
|
|
14
19
|
request.onsuccess = ()=>resolve(request.result);
|
|
@@ -22,108 +27,528 @@ function completed(transaction) {
|
|
|
22
27
|
transaction.onabort = ()=>reject(transaction.error);
|
|
23
28
|
});
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
const EMPTY_DECLARATIONS = {
|
|
31
|
+
lastCompleted: null,
|
|
32
|
+
generation: null,
|
|
33
|
+
providerLimits: [],
|
|
34
|
+
capabilities: [],
|
|
35
|
+
slots: []
|
|
36
|
+
};
|
|
37
|
+
function declaration(database) {
|
|
38
|
+
const transaction = database.transaction(DECLARATIONS, 'readonly');
|
|
39
|
+
return settled(transaction.objectStore(DECLARATIONS).get(CURRENT)).then((record)=>record ?? EMPTY_DECLARATIONS);
|
|
40
|
+
}
|
|
41
|
+
function updateDeclaration(database, update) {
|
|
42
|
+
const transaction = database.transaction(DECLARATIONS, 'readwrite');
|
|
43
|
+
const store = transaction.objectStore(DECLARATIONS);
|
|
44
|
+
const prior = store.get(CURRENT);
|
|
45
|
+
prior.onsuccess = ()=>{
|
|
46
|
+
store.put(update(prior.result ?? EMPTY_DECLARATIONS), CURRENT);
|
|
47
|
+
};
|
|
48
|
+
return completed(transaction);
|
|
49
|
+
}
|
|
50
|
+
function amendPending(database, locator, id, amendment) {
|
|
51
|
+
const transaction = database.transaction(PENDING_CHANGES, 'readwrite');
|
|
52
|
+
const pending = transaction.objectStore(PENDING_CHANGES);
|
|
53
|
+
const request = pending.get([
|
|
54
|
+
locator,
|
|
55
|
+
id
|
|
56
|
+
]);
|
|
57
|
+
request.onsuccess = ()=>{
|
|
58
|
+
const record = request.result;
|
|
59
|
+
if (record !== undefined) pending.put({
|
|
60
|
+
...record,
|
|
61
|
+
...amendment
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
return completed(transaction);
|
|
65
|
+
}
|
|
66
|
+
function roomRecord(record, queue) {
|
|
67
|
+
const { documents, binaryTargets, revisions, changes, written, attachments, ...room } = record;
|
|
68
|
+
return {
|
|
69
|
+
...room,
|
|
70
|
+
order: queue.map((batch)=>batch.id)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function removeRoomEntries(store, locator) {
|
|
74
|
+
const keys = store.getAllKeys();
|
|
75
|
+
keys.onsuccess = ()=>{
|
|
76
|
+
for (const key of keys.result){
|
|
77
|
+
if (Array.isArray(key) && key[0] === locator) store.delete(key);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function removeRuntimeStore() {
|
|
82
|
+
return new Promise((resolve, reject)=>{
|
|
83
|
+
const removal = indexedDB.deleteDatabase(DATABASE);
|
|
84
|
+
removal.onsuccess = ()=>resolve();
|
|
85
|
+
removal.onerror = ()=>reject(removal.error);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
export async function openRuntimeStore() {
|
|
27
89
|
const opening = indexedDB.open(DATABASE, SCHEMA);
|
|
28
90
|
opening.onupgradeneeded = ()=>{
|
|
29
91
|
const database = opening.result;
|
|
30
92
|
for (const name of [
|
|
31
93
|
...database.objectStoreNames
|
|
32
94
|
])database.deleteObjectStore(name);
|
|
33
|
-
database.createObjectStore(
|
|
95
|
+
database.createObjectStore(ROOMS, {
|
|
34
96
|
keyPath: 'locator'
|
|
35
97
|
});
|
|
36
|
-
database.createObjectStore(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
98
|
+
database.createObjectStore(DOCUMENTS, {
|
|
99
|
+
keyPath: [
|
|
100
|
+
'locator',
|
|
101
|
+
'path'
|
|
102
|
+
]
|
|
40
103
|
});
|
|
41
|
-
database.createObjectStore(
|
|
104
|
+
database.createObjectStore(BINARY_TARGETS, {
|
|
42
105
|
keyPath: [
|
|
43
106
|
'locator',
|
|
44
107
|
'path'
|
|
45
108
|
]
|
|
46
109
|
});
|
|
110
|
+
database.createObjectStore(ATTACHMENTS, {
|
|
111
|
+
keyPath: [
|
|
112
|
+
'locator',
|
|
113
|
+
'reference'
|
|
114
|
+
]
|
|
115
|
+
});
|
|
116
|
+
database.createObjectStore(PENDING_CHANGES, {
|
|
117
|
+
keyPath: [
|
|
118
|
+
'locator',
|
|
119
|
+
'id'
|
|
120
|
+
]
|
|
121
|
+
});
|
|
122
|
+
const outcomes = database.createObjectStore(OUTCOMES, {
|
|
123
|
+
keyPath: 'id'
|
|
124
|
+
});
|
|
125
|
+
outcomes.createIndex('locator', 'locator');
|
|
126
|
+
database.createObjectStore(DECLARATIONS);
|
|
127
|
+
database.createObjectStore(ROOM_DRAFTS, {
|
|
128
|
+
keyPath: [
|
|
129
|
+
'locator',
|
|
130
|
+
'path'
|
|
131
|
+
]
|
|
132
|
+
});
|
|
133
|
+
database.createObjectStore(PRESENTATION, {
|
|
134
|
+
keyPath: 'app'
|
|
135
|
+
});
|
|
136
|
+
database.createObjectStore(CONVERSATIONS, {
|
|
137
|
+
keyPath: 'conversation'
|
|
138
|
+
});
|
|
139
|
+
const messages = database.createObjectStore(MESSAGES, {
|
|
140
|
+
keyPath: [
|
|
141
|
+
'conversation',
|
|
142
|
+
'identity'
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
messages.createIndex('conversation', 'conversation');
|
|
146
|
+
database.createObjectStore(CHAT_DRAFTS, {
|
|
147
|
+
keyPath: 'conversation'
|
|
148
|
+
});
|
|
47
149
|
};
|
|
48
150
|
const database = await settled(opening);
|
|
49
151
|
return {
|
|
50
152
|
async all () {
|
|
51
|
-
const transaction = database.transaction(
|
|
52
|
-
|
|
153
|
+
const transaction = database.transaction([
|
|
154
|
+
ROOMS,
|
|
155
|
+
DOCUMENTS,
|
|
156
|
+
BINARY_TARGETS,
|
|
157
|
+
ATTACHMENTS
|
|
158
|
+
], 'readonly');
|
|
159
|
+
const [rooms, documents, targets, attachments] = await Promise.all([
|
|
160
|
+
settled(transaction.objectStore(ROOMS).getAll()),
|
|
161
|
+
settled(transaction.objectStore(DOCUMENTS).getAll()),
|
|
162
|
+
settled(transaction.objectStore(BINARY_TARGETS).getAll()),
|
|
163
|
+
settled(transaction.objectStore(ATTACHMENTS).getAll())
|
|
164
|
+
]);
|
|
165
|
+
const byRoom = new Map();
|
|
166
|
+
for (const { order, ...room } of rooms){
|
|
167
|
+
byRoom.set(room.locator, {
|
|
168
|
+
...room,
|
|
169
|
+
documents: {},
|
|
170
|
+
revisions: {},
|
|
171
|
+
changes: {},
|
|
172
|
+
written: {},
|
|
173
|
+
binaryTargets: [],
|
|
174
|
+
attachments: []
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
const head = (room, held)=>{
|
|
178
|
+
if (held.revision !== null) {
|
|
179
|
+
room.revisions[held.path] = held.revision;
|
|
180
|
+
}
|
|
181
|
+
if (held.change !== null) {
|
|
182
|
+
room.changes[held.path] = held.change;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
for (const document of documents){
|
|
186
|
+
const room = byRoom.get(document.locator);
|
|
187
|
+
if (room === undefined) continue;
|
|
188
|
+
room.documents[document.path] = document.content;
|
|
189
|
+
if (document.written !== null) {
|
|
190
|
+
room.written[document.path] = document.written;
|
|
191
|
+
}
|
|
192
|
+
head(room, document);
|
|
193
|
+
}
|
|
194
|
+
for (const target of targets){
|
|
195
|
+
const room = byRoom.get(target.locator);
|
|
196
|
+
if (room === undefined) continue;
|
|
197
|
+
room.binaryTargets.push(target.path);
|
|
198
|
+
head(room, target);
|
|
199
|
+
}
|
|
200
|
+
for (const { locator, ...attachment } of attachments){
|
|
201
|
+
const room = byRoom.get(locator);
|
|
202
|
+
if (room === undefined) continue;
|
|
203
|
+
room.attachments.push(attachment);
|
|
204
|
+
}
|
|
205
|
+
return [
|
|
206
|
+
...byRoom.values()
|
|
207
|
+
];
|
|
208
|
+
},
|
|
209
|
+
async write ({ next, previous, queue, previousQueue, saved, outcomes, roomDrafts, consumedRoomDrafts }) {
|
|
210
|
+
const transaction = database.transaction([
|
|
211
|
+
ROOMS,
|
|
212
|
+
DOCUMENTS,
|
|
213
|
+
BINARY_TARGETS,
|
|
214
|
+
ATTACHMENTS,
|
|
215
|
+
PENDING_CHANGES,
|
|
216
|
+
OUTCOMES,
|
|
217
|
+
ROOM_DRAFTS
|
|
218
|
+
], 'readwrite');
|
|
219
|
+
transaction.objectStore(ROOMS).put(roomRecord(next, queue));
|
|
220
|
+
const documents = transaction.objectStore(DOCUMENTS);
|
|
221
|
+
for (const path of Object.keys(previous?.documents ?? {})){
|
|
222
|
+
if (next.documents[path] === undefined) documents.delete([
|
|
223
|
+
next.locator,
|
|
224
|
+
path
|
|
225
|
+
]);
|
|
226
|
+
}
|
|
227
|
+
for (const [path, content] of Object.entries(next.documents)){
|
|
228
|
+
if (previous?.documents[path] === content && previous.revisions[path] === next.revisions[path] && previous.written[path] === next.written[path] && sameChange(previous.changes[path], next.changes[path])) continue;
|
|
229
|
+
documents.put({
|
|
230
|
+
locator: next.locator,
|
|
231
|
+
path,
|
|
232
|
+
content,
|
|
233
|
+
revision: next.revisions[path] ?? null,
|
|
234
|
+
change: next.changes[path] ?? null,
|
|
235
|
+
written: next.written[path] ?? null
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
const targets = transaction.objectStore(BINARY_TARGETS);
|
|
239
|
+
const beforeTargets = new Set(previous?.binaryTargets ?? []);
|
|
240
|
+
const afterTargets = new Set(next.binaryTargets);
|
|
241
|
+
for (const path of beforeTargets){
|
|
242
|
+
if (!afterTargets.has(path)) targets.delete([
|
|
243
|
+
next.locator,
|
|
244
|
+
path
|
|
245
|
+
]);
|
|
246
|
+
}
|
|
247
|
+
for (const path of afterTargets){
|
|
248
|
+
if (!beforeTargets.has(path) || previous?.revisions[path] !== next.revisions[path] || !sameChange(previous?.changes[path], next.changes[path])) {
|
|
249
|
+
targets.put({
|
|
250
|
+
locator: next.locator,
|
|
251
|
+
path,
|
|
252
|
+
revision: next.revisions[path] ?? null,
|
|
253
|
+
change: next.changes[path] ?? null
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const attachments = transaction.objectStore(ATTACHMENTS);
|
|
258
|
+
const held = new Map((previous?.attachments ?? []).map((attachment)=>[
|
|
259
|
+
attachment.reference,
|
|
260
|
+
attachment
|
|
261
|
+
]));
|
|
262
|
+
const declared = new Set(next.attachments.map((attachment)=>attachment.reference));
|
|
263
|
+
for (const reference of held.keys()){
|
|
264
|
+
if (!declared.has(reference)) attachments.delete([
|
|
265
|
+
next.locator,
|
|
266
|
+
reference
|
|
267
|
+
]);
|
|
268
|
+
}
|
|
269
|
+
for (const attachment of next.attachments){
|
|
270
|
+
if (held.get(attachment.reference) === attachment) continue;
|
|
271
|
+
attachments.put({
|
|
272
|
+
...attachment,
|
|
273
|
+
locator: next.locator
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
if (previousQueue !== undefined) {
|
|
277
|
+
const pending = transaction.objectStore(PENDING_CHANGES);
|
|
278
|
+
const before = new Set(previousQueue.map((batch)=>batch.id));
|
|
279
|
+
const after = new Set(queue.map((batch)=>batch.id));
|
|
280
|
+
for (const id of before){
|
|
281
|
+
if (!after.has(id)) pending.delete([
|
|
282
|
+
next.locator,
|
|
283
|
+
id
|
|
284
|
+
]);
|
|
285
|
+
}
|
|
286
|
+
for (const batch of queue){
|
|
287
|
+
if (!before.has(batch.id)) {
|
|
288
|
+
pending.put({
|
|
289
|
+
locator: next.locator,
|
|
290
|
+
id: batch.id,
|
|
291
|
+
batch,
|
|
292
|
+
drafts: saved ?? [],
|
|
293
|
+
submission: {
|
|
294
|
+
state: 'waiting'
|
|
295
|
+
},
|
|
296
|
+
lost: false
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const outcomeStore = transaction.objectStore(OUTCOMES);
|
|
302
|
+
for (const entry of outcomes ?? []){
|
|
303
|
+
if (entry.outcome === null) outcomeStore.delete(entry.id);
|
|
304
|
+
else outcomeStore.put({
|
|
305
|
+
locator: next.locator,
|
|
306
|
+
id: entry.id,
|
|
307
|
+
outcome: entry.outcome
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
const draftStore = transaction.objectStore(ROOM_DRAFTS);
|
|
311
|
+
for (const path of consumedRoomDrafts ?? [])draftStore.delete([
|
|
312
|
+
next.locator,
|
|
313
|
+
path
|
|
314
|
+
]);
|
|
315
|
+
for (const record of roomDrafts ?? [])draftStore.put(record);
|
|
316
|
+
await completed(transaction);
|
|
53
317
|
},
|
|
54
|
-
async
|
|
55
|
-
const transaction = database.transaction(
|
|
56
|
-
transaction.objectStore(
|
|
318
|
+
async revokeModels (records) {
|
|
319
|
+
const transaction = database.transaction(ROOMS, 'readwrite');
|
|
320
|
+
const rooms = transaction.objectStore(ROOMS);
|
|
321
|
+
const revoked = {
|
|
322
|
+
status: 'unavailable',
|
|
323
|
+
reason: 'revoked'
|
|
324
|
+
};
|
|
325
|
+
for (const { record, queue } of records){
|
|
326
|
+
rooms.put(roomRecord({
|
|
327
|
+
...record,
|
|
328
|
+
model: revoked,
|
|
329
|
+
selectionModel: revoked
|
|
330
|
+
}, queue));
|
|
331
|
+
}
|
|
57
332
|
await completed(transaction);
|
|
58
333
|
},
|
|
59
334
|
async lastCompleted () {
|
|
60
|
-
|
|
61
|
-
const value = await settled(transaction.objectStore(SYNCHRONIZATION).get(LAST_COMPLETED));
|
|
62
|
-
return value ?? null;
|
|
335
|
+
return (await declaration(database)).lastCompleted;
|
|
63
336
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
337
|
+
complete (at) {
|
|
338
|
+
return updateDeclaration(database, (record)=>({
|
|
339
|
+
...record,
|
|
340
|
+
lastCompleted: at
|
|
341
|
+
}));
|
|
68
342
|
},
|
|
69
343
|
async providerLimits () {
|
|
70
|
-
|
|
71
|
-
const value = await settled(transaction.objectStore(DISCOVERY).get(PROVIDER_LIMITS));
|
|
72
|
-
return value ?? [];
|
|
344
|
+
return (await declaration(database)).providerLimits;
|
|
73
345
|
},
|
|
74
|
-
async
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
346
|
+
async capabilities () {
|
|
347
|
+
return (await declaration(database)).capabilities;
|
|
348
|
+
},
|
|
349
|
+
async slots () {
|
|
350
|
+
return (await declaration(database)).slots;
|
|
351
|
+
},
|
|
352
|
+
declare (limits, capabilities, slots) {
|
|
353
|
+
return updateDeclaration(database, (record)=>({
|
|
354
|
+
...record,
|
|
355
|
+
providerLimits: limits,
|
|
356
|
+
capabilities,
|
|
357
|
+
slots
|
|
358
|
+
}));
|
|
78
359
|
},
|
|
79
360
|
async queues () {
|
|
80
|
-
const transaction = database.transaction(
|
|
81
|
-
|
|
361
|
+
const transaction = database.transaction([
|
|
362
|
+
ROOMS,
|
|
363
|
+
PENDING_CHANGES
|
|
364
|
+
], 'readonly');
|
|
365
|
+
const [rooms, pending] = await Promise.all([
|
|
366
|
+
settled(transaction.objectStore(ROOMS).getAll()),
|
|
367
|
+
settled(transaction.objectStore(PENDING_CHANGES).getAll())
|
|
368
|
+
]);
|
|
369
|
+
const byId = new Map(pending.map((record)=>[
|
|
370
|
+
`${record.locator}\0${record.id}`,
|
|
371
|
+
record
|
|
372
|
+
]));
|
|
373
|
+
return rooms.map((room)=>({
|
|
374
|
+
locator: room.locator,
|
|
375
|
+
pending: room.order.map((id)=>{
|
|
376
|
+
const record = byId.get(`${room.locator}\0${id}`);
|
|
377
|
+
if (record === undefined) throw new Error(`Missing Pending Change ${room.locator}/${id}`);
|
|
378
|
+
const { batch, drafts, submission, lost, upload } = record;
|
|
379
|
+
return {
|
|
380
|
+
batch,
|
|
381
|
+
state: {
|
|
382
|
+
drafts,
|
|
383
|
+
submission,
|
|
384
|
+
lost,
|
|
385
|
+
upload
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
})
|
|
389
|
+
}));
|
|
390
|
+
},
|
|
391
|
+
async outcomes () {
|
|
392
|
+
const transaction = database.transaction(OUTCOMES, 'readonly');
|
|
393
|
+
return settled(transaction.objectStore(OUTCOMES).getAll());
|
|
394
|
+
},
|
|
395
|
+
submit (locator, id, submission, lost) {
|
|
396
|
+
return amendPending(database, locator, id, {
|
|
397
|
+
submission,
|
|
398
|
+
lost
|
|
399
|
+
});
|
|
400
|
+
},
|
|
401
|
+
keepUpload (locator, id, upload) {
|
|
402
|
+
return amendPending(database, locator, id, {
|
|
403
|
+
upload
|
|
404
|
+
});
|
|
405
|
+
},
|
|
406
|
+
async roomDrafts () {
|
|
407
|
+
const transaction = database.transaction(ROOM_DRAFTS, 'readonly');
|
|
408
|
+
return settled(transaction.objectStore(ROOM_DRAFTS).getAll());
|
|
82
409
|
},
|
|
83
|
-
async
|
|
84
|
-
const transaction = database.transaction(
|
|
85
|
-
return settled(transaction.objectStore(
|
|
410
|
+
async presentation () {
|
|
411
|
+
const transaction = database.transaction(PRESENTATION, 'readonly');
|
|
412
|
+
return settled(transaction.objectStore(PRESENTATION).getAll());
|
|
86
413
|
},
|
|
87
|
-
async
|
|
88
|
-
const transaction = database.transaction(
|
|
89
|
-
transaction.objectStore(
|
|
414
|
+
async present (record) {
|
|
415
|
+
const transaction = database.transaction(PRESENTATION, 'readwrite');
|
|
416
|
+
transaction.objectStore(PRESENTATION).put(record);
|
|
90
417
|
await completed(transaction);
|
|
91
418
|
},
|
|
92
|
-
async
|
|
93
|
-
const transaction = database.transaction(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
419
|
+
async conversations () {
|
|
420
|
+
const transaction = database.transaction([
|
|
421
|
+
CONVERSATIONS,
|
|
422
|
+
MESSAGES
|
|
423
|
+
], 'readonly');
|
|
424
|
+
const [reads, messages] = await Promise.all([
|
|
425
|
+
settled(transaction.objectStore(CONVERSATIONS).getAll()),
|
|
426
|
+
settled(transaction.objectStore(MESSAGES).getAll())
|
|
97
427
|
]);
|
|
428
|
+
const held = new Map();
|
|
429
|
+
for (const { conversation, read } of reads){
|
|
430
|
+
held.set(conversation, {
|
|
431
|
+
conversation,
|
|
432
|
+
read,
|
|
433
|
+
messages: []
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
for (const { conversation, ...message } of messages){
|
|
437
|
+
const entry = held.get(conversation) ?? {
|
|
438
|
+
conversation,
|
|
439
|
+
read: undefined,
|
|
440
|
+
messages: []
|
|
441
|
+
};
|
|
442
|
+
entry.messages.push(message);
|
|
443
|
+
held.set(conversation, entry);
|
|
444
|
+
}
|
|
445
|
+
return [
|
|
446
|
+
...held.values()
|
|
447
|
+
];
|
|
448
|
+
},
|
|
449
|
+
async keepMessages ({ conversation, messages, read, sealed }) {
|
|
450
|
+
const transaction = database.transaction([
|
|
451
|
+
CONVERSATIONS,
|
|
452
|
+
MESSAGES,
|
|
453
|
+
CHAT_DRAFTS
|
|
454
|
+
], 'readwrite');
|
|
455
|
+
const stored = transaction.objectStore(MESSAGES);
|
|
456
|
+
for (const message of messages){
|
|
457
|
+
stored.put({
|
|
458
|
+
...message,
|
|
459
|
+
conversation
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
if (read !== undefined) {
|
|
463
|
+
transaction.objectStore(CONVERSATIONS).put({
|
|
464
|
+
conversation,
|
|
465
|
+
read
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
if (sealed === true) transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
98
469
|
await completed(transaction);
|
|
99
470
|
},
|
|
100
|
-
async
|
|
471
|
+
async dropConversations (conversations) {
|
|
101
472
|
const transaction = database.transaction([
|
|
102
|
-
|
|
103
|
-
|
|
473
|
+
CONVERSATIONS,
|
|
474
|
+
MESSAGES,
|
|
475
|
+
CHAT_DRAFTS
|
|
104
476
|
], 'readwrite');
|
|
105
|
-
transaction.objectStore(
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
477
|
+
const messages = transaction.objectStore(MESSAGES);
|
|
478
|
+
for (const conversation of conversations){
|
|
479
|
+
transaction.objectStore(CONVERSATIONS).delete(conversation);
|
|
480
|
+
transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
481
|
+
const keys = messages.index('conversation').getAllKeys(conversation);
|
|
482
|
+
keys.onsuccess = ()=>{
|
|
483
|
+
for (const key of keys.result)messages.delete(key);
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
await completed(transaction);
|
|
487
|
+
},
|
|
488
|
+
async chatDrafts () {
|
|
489
|
+
const transaction = database.transaction(CHAT_DRAFTS, 'readonly');
|
|
490
|
+
return settled(transaction.objectStore(CHAT_DRAFTS).getAll());
|
|
491
|
+
},
|
|
492
|
+
async keepChatDraft (record) {
|
|
493
|
+
const transaction = database.transaction(CHAT_DRAFTS, 'readwrite');
|
|
494
|
+
transaction.objectStore(CHAT_DRAFTS).put(record);
|
|
495
|
+
await completed(transaction);
|
|
496
|
+
},
|
|
497
|
+
async dropChatDraft (conversation) {
|
|
498
|
+
const transaction = database.transaction(CHAT_DRAFTS, 'readwrite');
|
|
499
|
+
transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
500
|
+
await completed(transaction);
|
|
501
|
+
},
|
|
502
|
+
async keepRoomDraft (record) {
|
|
503
|
+
const transaction = database.transaction(ROOM_DRAFTS, 'readwrite');
|
|
504
|
+
transaction.objectStore(ROOM_DRAFTS).put(record);
|
|
505
|
+
await completed(transaction);
|
|
506
|
+
},
|
|
507
|
+
async discardRoomDraft (locator, path) {
|
|
508
|
+
const transaction = database.transaction(ROOM_DRAFTS, 'readwrite');
|
|
509
|
+
transaction.objectStore(ROOM_DRAFTS).delete([
|
|
510
|
+
locator,
|
|
109
511
|
path
|
|
110
512
|
]);
|
|
111
513
|
await completed(transaction);
|
|
112
514
|
},
|
|
113
|
-
async
|
|
114
|
-
const transaction = database.transaction(
|
|
115
|
-
|
|
515
|
+
async dropRooms (locators) {
|
|
516
|
+
const transaction = database.transaction([
|
|
517
|
+
ROOMS,
|
|
518
|
+
DOCUMENTS,
|
|
519
|
+
BINARY_TARGETS,
|
|
520
|
+
ATTACHMENTS,
|
|
521
|
+
PENDING_CHANGES,
|
|
522
|
+
OUTCOMES,
|
|
523
|
+
ROOM_DRAFTS
|
|
524
|
+
], 'readwrite');
|
|
525
|
+
for (const locator of locators){
|
|
526
|
+
transaction.objectStore(ROOMS).delete(locator);
|
|
527
|
+
for (const name of [
|
|
528
|
+
DOCUMENTS,
|
|
529
|
+
BINARY_TARGETS,
|
|
530
|
+
ATTACHMENTS,
|
|
531
|
+
PENDING_CHANGES,
|
|
532
|
+
ROOM_DRAFTS
|
|
533
|
+
]){
|
|
534
|
+
removeRoomEntries(transaction.objectStore(name), locator);
|
|
535
|
+
}
|
|
536
|
+
const outcomes = transaction.objectStore(OUTCOMES);
|
|
537
|
+
const ids = outcomes.index('locator').getAllKeys(locator);
|
|
538
|
+
ids.onsuccess = ()=>{
|
|
539
|
+
for (const id of ids.result)outcomes.delete(id);
|
|
540
|
+
};
|
|
541
|
+
}
|
|
116
542
|
await completed(transaction);
|
|
117
543
|
},
|
|
118
544
|
async generation () {
|
|
119
|
-
|
|
120
|
-
const value = await settled(transaction.objectStore(SYNCHRONIZATION).get(GENERATION));
|
|
121
|
-
return value ?? null;
|
|
545
|
+
return (await declaration(database)).generation;
|
|
122
546
|
},
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
547
|
+
rememberGeneration (value) {
|
|
548
|
+
return updateDeclaration(database, (record)=>({
|
|
549
|
+
...record,
|
|
550
|
+
generation: value
|
|
551
|
+
}));
|
|
127
552
|
},
|
|
128
553
|
close () {
|
|
129
554
|
database.close();
|