@agentshouse/mdruntime 0.1.0-alpha.9 → 0.1.0-c1954630fadb6
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 +227 -0
- package/README.md +44 -0
- package/dist/adapter.d.ts +184 -34
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -10
- package/dist/attached-model.d.ts +11 -0
- package/dist/attached-model.d.ts.map +1 -0
- package/dist/attached-model.js +34 -0
- package/dist/attachment.d.ts +3 -0
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +8 -0
- package/dist/bootstrap.d.ts +7 -9
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +29 -28
- package/dist/change-set.d.ts +33 -0
- package/dist/change-set.d.ts.map +1 -0
- package/dist/change-set.js +83 -0
- package/dist/change.d.ts +9 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +6 -5
- package/dist/client.d.ts +38 -32
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +114 -183
- package/dist/collection.d.ts +13 -16
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +45 -88
- package/dist/connection.d.ts +47 -44
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1542 -1158
- package/dist/conversation.d.ts +44 -22
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +540 -328
- package/dist/durability.js +6 -6
- package/dist/file.d.ts +2 -2
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +48 -71
- package/dist/host.d.ts +12 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +97 -119
- package/dist/identity.d.ts +1 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +10 -9
- package/dist/index.d.ts +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/log.js +5 -6
- package/dist/memory.d.ts +15 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +255 -220
- package/dist/model.d.ts +10 -29
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +18 -21
- package/dist/observation.d.ts +27 -0
- package/dist/observation.d.ts.map +1 -0
- package/dist/observation.js +95 -0
- package/dist/outcome.d.ts +10 -29
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +1 -23
- package/dist/overlay.d.ts +9 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +187 -43
- package/dist/paths.d.ts +0 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +12 -19
- package/dist/query.d.ts +215 -10
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +421 -15
- package/dist/reach.d.ts +40 -0
- package/dist/reach.d.ts.map +1 -0
- package/dist/reach.js +277 -0
- package/dist/react.d.ts +30 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +62 -0
- package/dist/read-side.d.ts +18 -0
- package/dist/read-side.d.ts.map +1 -0
- package/dist/read-side.js +377 -0
- package/dist/refresh.d.ts +5 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +49 -30
- package/dist/replica.d.ts +25 -5
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +227 -38
- package/dist/room-draft.d.ts +127 -0
- package/dist/room-draft.d.ts.map +1 -0
- package/dist/room-draft.js +329 -0
- package/dist/rows.d.ts +41 -0
- package/dist/rows.d.ts.map +1 -0
- package/dist/rows.js +100 -0
- package/dist/save.d.ts +6 -4
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +262 -350
- package/dist/search.d.ts +61 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +125 -0
- package/dist/status.d.ts +4 -6
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +9 -13
- package/dist/store.d.ts +59 -32
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +338 -134
- package/dist/transfer.d.ts +5 -0
- package/dist/transfer.d.ts.map +1 -1
- package/dist/transfer.js +1 -5
- package/dist/wire.d.ts +51 -16
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +77 -108
- package/package.json +17 -11
- package/dist/adapter.js.map +0 -1
- package/dist/bootstrap.js.map +0 -1
- package/dist/change.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/collection.js.map +0 -1
- package/dist/connection.js.map +0 -1
- package/dist/conversation.js.map +0 -1
- package/dist/durability.js.map +0 -1
- package/dist/file.js.map +0 -1
- package/dist/host.js.map +0 -1
- package/dist/identity.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/log.js.map +0 -1
- package/dist/memory.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/outcome.js.map +0 -1
- package/dist/overlay.js.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/query.js.map +0 -1
- package/dist/refresh.js.map +0 -1
- package/dist/replica.js.map +0 -1
- package/dist/save.js.map +0 -1
- package/dist/status.js.map +0 -1
- package/dist/store.js.map +0 -1
- package/dist/transfer.js.map +0 -1
- package/dist/wire.js.map +0 -1
package/dist/store.js
CHANGED
|
@@ -1,191 +1,395 @@
|
|
|
1
|
+
import { sameChange } from './overlay.js';
|
|
1
2
|
const DATABASE = 'mdruntime';
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
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 DECLARATIONS = 'declarations';
|
|
9
|
+
const ROOM_DRAFTS = 'roomDrafts';
|
|
7
10
|
const PRESENTATION = 'presentation';
|
|
8
11
|
const CONVERSATIONS = 'conversations';
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const SCHEMA = 8;
|
|
12
|
+
const MESSAGES = 'messages';
|
|
13
|
+
const CHAT_DRAFTS = 'chatDrafts';
|
|
14
|
+
const CURRENT = 'current';
|
|
15
|
+
const SCHEMA = 20;
|
|
14
16
|
function settled(request) {
|
|
15
|
-
return new Promise((resolve, reject)=>{
|
|
16
|
-
request.onsuccess = ()=>resolve(request.result);
|
|
17
|
-
request.onerror = ()=>reject(request.error);
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
request.onsuccess = () => resolve(request.result);
|
|
19
|
+
request.onerror = () => reject(request.error);
|
|
18
20
|
});
|
|
19
21
|
}
|
|
20
22
|
function completed(transaction) {
|
|
21
|
-
return new Promise((resolve, reject)=>{
|
|
22
|
-
transaction.oncomplete = ()=>resolve();
|
|
23
|
-
transaction.onerror = ()=>reject(transaction.error);
|
|
24
|
-
transaction.onabort = ()=>reject(transaction.error);
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
transaction.oncomplete = () => resolve();
|
|
25
|
+
transaction.onerror = () => reject(transaction.error);
|
|
26
|
+
transaction.onabort = () => reject(transaction.error);
|
|
25
27
|
});
|
|
26
28
|
}
|
|
29
|
+
const EMPTY_DECLARATIONS = {
|
|
30
|
+
lastCompleted: null,
|
|
31
|
+
generation: null,
|
|
32
|
+
providerLimits: [],
|
|
33
|
+
capabilities: [],
|
|
34
|
+
};
|
|
35
|
+
function declaration(database) {
|
|
36
|
+
const transaction = database.transaction(DECLARATIONS, 'readonly');
|
|
37
|
+
return settled(transaction.objectStore(DECLARATIONS).get(CURRENT)).then((record) => record ?? EMPTY_DECLARATIONS);
|
|
38
|
+
}
|
|
39
|
+
function updateDeclaration(database, update) {
|
|
40
|
+
const transaction = database.transaction(DECLARATIONS, 'readwrite');
|
|
41
|
+
const store = transaction.objectStore(DECLARATIONS);
|
|
42
|
+
const prior = store.get(CURRENT);
|
|
43
|
+
prior.onsuccess = () => {
|
|
44
|
+
store.put(update(prior.result ?? EMPTY_DECLARATIONS), CURRENT);
|
|
45
|
+
};
|
|
46
|
+
return completed(transaction);
|
|
47
|
+
}
|
|
48
|
+
function amendPending(database, locator, id, amendment) {
|
|
49
|
+
const transaction = database.transaction(PENDING_CHANGES, 'readwrite');
|
|
50
|
+
const pending = transaction.objectStore(PENDING_CHANGES);
|
|
51
|
+
const request = pending.get([locator, id]);
|
|
52
|
+
request.onsuccess = () => {
|
|
53
|
+
const record = request.result;
|
|
54
|
+
if (record !== undefined)
|
|
55
|
+
pending.put({ ...record, ...amendment });
|
|
56
|
+
};
|
|
57
|
+
return completed(transaction);
|
|
58
|
+
}
|
|
59
|
+
function roomRecord(record, queue) {
|
|
60
|
+
const { documents, binaryTargets, revisions, changes, written, attachments, ...room } = record;
|
|
61
|
+
return { ...room, order: queue.map((batch) => batch.id) };
|
|
62
|
+
}
|
|
63
|
+
function removeRoomEntries(store, locator) {
|
|
64
|
+
const keys = store.getAllKeys();
|
|
65
|
+
keys.onsuccess = () => {
|
|
66
|
+
for (const key of keys.result) {
|
|
67
|
+
if (Array.isArray(key) && key[0] === locator)
|
|
68
|
+
store.delete(key);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
27
72
|
export function removeRuntimeStore() {
|
|
28
|
-
return new Promise((resolve, reject)=>{
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
29
74
|
const removal = indexedDB.deleteDatabase(DATABASE);
|
|
30
|
-
removal.onsuccess = ()=>resolve();
|
|
31
|
-
removal.onerror = ()=>reject(removal.error);
|
|
75
|
+
removal.onsuccess = () => resolve();
|
|
76
|
+
removal.onerror = () => reject(removal.error);
|
|
32
77
|
});
|
|
33
78
|
}
|
|
34
|
-
function discardEveryEarlierStore(database) {
|
|
35
|
-
for (const name of [
|
|
36
|
-
...database.objectStoreNames
|
|
37
|
-
])database.deleteObjectStore(name);
|
|
38
|
-
}
|
|
39
79
|
export async function openRuntimeStore() {
|
|
40
80
|
const opening = indexedDB.open(DATABASE, SCHEMA);
|
|
41
|
-
opening.onupgradeneeded = ()=>{
|
|
81
|
+
opening.onupgradeneeded = () => {
|
|
42
82
|
const database = opening.result;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
database.createObjectStore(
|
|
48
|
-
database.createObjectStore(
|
|
49
|
-
database.createObjectStore(
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
database.createObjectStore(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
]
|
|
57
|
-
});
|
|
58
|
-
database.createObjectStore(PRESENTATION, {
|
|
59
|
-
keyPath: 'app'
|
|
60
|
-
});
|
|
61
|
-
database.createObjectStore(CONVERSATIONS, {
|
|
62
|
-
keyPath: 'conversation'
|
|
63
|
-
});
|
|
64
|
-
database.createObjectStore(INSTRUCTIONS, {
|
|
65
|
-
keyPath: 'conversation'
|
|
83
|
+
for (const name of [...database.objectStoreNames])
|
|
84
|
+
database.deleteObjectStore(name);
|
|
85
|
+
database.createObjectStore(ROOMS, { keyPath: 'locator' });
|
|
86
|
+
database.createObjectStore(DOCUMENTS, { keyPath: ['locator', 'path'] });
|
|
87
|
+
database.createObjectStore(BINARY_TARGETS, { keyPath: ['locator', 'path'] });
|
|
88
|
+
database.createObjectStore(ATTACHMENTS, { keyPath: ['locator', 'reference'] });
|
|
89
|
+
database.createObjectStore(PENDING_CHANGES, { keyPath: ['locator', 'id'] });
|
|
90
|
+
database.createObjectStore(DECLARATIONS);
|
|
91
|
+
database.createObjectStore(ROOM_DRAFTS, { keyPath: ['locator', 'path'] });
|
|
92
|
+
database.createObjectStore(PRESENTATION, { keyPath: 'app' });
|
|
93
|
+
database.createObjectStore(CONVERSATIONS, { keyPath: 'conversation' });
|
|
94
|
+
const messages = database.createObjectStore(MESSAGES, {
|
|
95
|
+
keyPath: ['conversation', 'identity'],
|
|
66
96
|
});
|
|
97
|
+
messages.createIndex('conversation', 'conversation');
|
|
98
|
+
database.createObjectStore(CHAT_DRAFTS, { keyPath: 'conversation' });
|
|
67
99
|
};
|
|
68
100
|
const database = await settled(opening);
|
|
69
101
|
return {
|
|
70
|
-
async all
|
|
71
|
-
const transaction = database.transaction(
|
|
72
|
-
|
|
102
|
+
async all() {
|
|
103
|
+
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS], 'readonly');
|
|
104
|
+
const [rooms, documents, targets, attachments] = await Promise.all([
|
|
105
|
+
settled(transaction.objectStore(ROOMS).getAll()),
|
|
106
|
+
settled(transaction.objectStore(DOCUMENTS).getAll()),
|
|
107
|
+
settled(transaction.objectStore(BINARY_TARGETS).getAll()),
|
|
108
|
+
settled(transaction.objectStore(ATTACHMENTS).getAll()),
|
|
109
|
+
]);
|
|
110
|
+
const byRoom = new Map();
|
|
111
|
+
for (const { order, ...room } of rooms) {
|
|
112
|
+
byRoom.set(room.locator, {
|
|
113
|
+
...room,
|
|
114
|
+
documents: {},
|
|
115
|
+
revisions: {},
|
|
116
|
+
changes: {},
|
|
117
|
+
written: {},
|
|
118
|
+
binaryTargets: [],
|
|
119
|
+
attachments: [],
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const head = (room, held) => {
|
|
123
|
+
if (held.revision !== null) {
|
|
124
|
+
room.revisions[held.path] = held.revision;
|
|
125
|
+
}
|
|
126
|
+
if (held.change !== null) {
|
|
127
|
+
room.changes[held.path] = held.change;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
for (const document of documents) {
|
|
131
|
+
const room = byRoom.get(document.locator);
|
|
132
|
+
if (room === undefined)
|
|
133
|
+
continue;
|
|
134
|
+
room.documents[document.path] = document.content;
|
|
135
|
+
if (document.written !== null) {
|
|
136
|
+
room.written[document.path] = document.written;
|
|
137
|
+
}
|
|
138
|
+
head(room, document);
|
|
139
|
+
}
|
|
140
|
+
for (const target of targets) {
|
|
141
|
+
const room = byRoom.get(target.locator);
|
|
142
|
+
if (room === undefined)
|
|
143
|
+
continue;
|
|
144
|
+
room.binaryTargets.push(target.path);
|
|
145
|
+
head(room, target);
|
|
146
|
+
}
|
|
147
|
+
for (const { locator, ...attachment } of attachments) {
|
|
148
|
+
const room = byRoom.get(locator);
|
|
149
|
+
if (room === undefined)
|
|
150
|
+
continue;
|
|
151
|
+
room.attachments.push(attachment);
|
|
152
|
+
}
|
|
153
|
+
return [...byRoom.values()];
|
|
73
154
|
},
|
|
74
|
-
async
|
|
75
|
-
const transaction = database.transaction(
|
|
76
|
-
transaction.objectStore(
|
|
155
|
+
async write({ next, previous, queue, previousQueue, saved, roomDrafts, consumedRoomDrafts }) {
|
|
156
|
+
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
|
|
157
|
+
transaction.objectStore(ROOMS).put(roomRecord(next, queue));
|
|
158
|
+
const documents = transaction.objectStore(DOCUMENTS);
|
|
159
|
+
for (const path of Object.keys(previous?.documents ?? {})) {
|
|
160
|
+
if (next.documents[path] === undefined)
|
|
161
|
+
documents.delete([next.locator, path]);
|
|
162
|
+
}
|
|
163
|
+
for (const [path, content] of Object.entries(next.documents)) {
|
|
164
|
+
if (previous?.documents[path] === content &&
|
|
165
|
+
previous.revisions[path] === next.revisions[path] &&
|
|
166
|
+
previous.written[path] === next.written[path] &&
|
|
167
|
+
sameChange(previous.changes[path], next.changes[path]))
|
|
168
|
+
continue;
|
|
169
|
+
documents.put({
|
|
170
|
+
locator: next.locator,
|
|
171
|
+
path,
|
|
172
|
+
content,
|
|
173
|
+
revision: next.revisions[path] ?? null,
|
|
174
|
+
change: next.changes[path] ?? null,
|
|
175
|
+
written: next.written[path] ?? null,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
const targets = transaction.objectStore(BINARY_TARGETS);
|
|
179
|
+
const beforeTargets = new Set(previous?.binaryTargets ?? []);
|
|
180
|
+
const afterTargets = new Set(next.binaryTargets);
|
|
181
|
+
for (const path of beforeTargets) {
|
|
182
|
+
if (!afterTargets.has(path))
|
|
183
|
+
targets.delete([next.locator, path]);
|
|
184
|
+
}
|
|
185
|
+
for (const path of afterTargets) {
|
|
186
|
+
if (!beforeTargets.has(path) ||
|
|
187
|
+
previous?.revisions[path] !== next.revisions[path] ||
|
|
188
|
+
!sameChange(previous?.changes[path], next.changes[path])) {
|
|
189
|
+
targets.put({
|
|
190
|
+
locator: next.locator,
|
|
191
|
+
path,
|
|
192
|
+
revision: next.revisions[path] ?? null,
|
|
193
|
+
change: next.changes[path] ?? null,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const attachments = transaction.objectStore(ATTACHMENTS);
|
|
198
|
+
const held = new Map((previous?.attachments ?? []).map((attachment) => [attachment.reference, attachment]));
|
|
199
|
+
const declared = new Set(next.attachments.map((attachment) => attachment.reference));
|
|
200
|
+
for (const reference of held.keys()) {
|
|
201
|
+
if (!declared.has(reference))
|
|
202
|
+
attachments.delete([next.locator, reference]);
|
|
203
|
+
}
|
|
204
|
+
for (const attachment of next.attachments) {
|
|
205
|
+
if (held.get(attachment.reference) === attachment)
|
|
206
|
+
continue;
|
|
207
|
+
attachments.put({ ...attachment, locator: next.locator });
|
|
208
|
+
}
|
|
209
|
+
if (previousQueue !== undefined) {
|
|
210
|
+
const pending = transaction.objectStore(PENDING_CHANGES);
|
|
211
|
+
const before = new Set(previousQueue.map((batch) => batch.id));
|
|
212
|
+
const after = new Set(queue.map((batch) => batch.id));
|
|
213
|
+
for (const id of before) {
|
|
214
|
+
if (!after.has(id))
|
|
215
|
+
pending.delete([next.locator, id]);
|
|
216
|
+
}
|
|
217
|
+
for (const batch of queue) {
|
|
218
|
+
if (!before.has(batch.id)) {
|
|
219
|
+
pending.put({
|
|
220
|
+
locator: next.locator,
|
|
221
|
+
id: batch.id,
|
|
222
|
+
batch,
|
|
223
|
+
drafts: saved ?? [],
|
|
224
|
+
submission: { state: 'waiting' },
|
|
225
|
+
lost: false,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const draftStore = transaction.objectStore(ROOM_DRAFTS);
|
|
231
|
+
for (const path of consumedRoomDrafts ?? [])
|
|
232
|
+
draftStore.delete([next.locator, path]);
|
|
233
|
+
for (const record of roomDrafts ?? [])
|
|
234
|
+
draftStore.put(record);
|
|
77
235
|
await completed(transaction);
|
|
78
236
|
},
|
|
79
|
-
async
|
|
80
|
-
const transaction = database.transaction(
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
transaction.objectStore(SYNCHRONIZATION).put(at, LAST_COMPLETED);
|
|
237
|
+
async revokeModels(records) {
|
|
238
|
+
const transaction = database.transaction(ROOMS, 'readwrite');
|
|
239
|
+
const rooms = transaction.objectStore(ROOMS);
|
|
240
|
+
const revoked = { status: 'unavailable', reason: 'revoked' };
|
|
241
|
+
for (const { record, queue } of records) {
|
|
242
|
+
rooms.put(roomRecord({ ...record, model: revoked, selectionModel: revoked }, queue));
|
|
243
|
+
}
|
|
87
244
|
await completed(transaction);
|
|
88
245
|
},
|
|
89
|
-
async
|
|
90
|
-
|
|
91
|
-
const value = await settled(transaction.objectStore(DISCOVERY).get(PROVIDER_LIMITS));
|
|
92
|
-
return value ?? [];
|
|
246
|
+
async lastCompleted() {
|
|
247
|
+
return (await declaration(database)).lastCompleted;
|
|
93
248
|
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
249
|
+
complete(at) {
|
|
250
|
+
return updateDeclaration(database, (record) => ({ ...record, lastCompleted: at }));
|
|
251
|
+
},
|
|
252
|
+
async providerLimits() {
|
|
253
|
+
return (await declaration(database)).providerLimits;
|
|
254
|
+
},
|
|
255
|
+
async capabilities() {
|
|
256
|
+
return (await declaration(database)).capabilities;
|
|
257
|
+
},
|
|
258
|
+
declare(limits, capabilities) {
|
|
259
|
+
return updateDeclaration(database, (record) => ({
|
|
260
|
+
...record,
|
|
261
|
+
providerLimits: limits,
|
|
262
|
+
capabilities,
|
|
263
|
+
}));
|
|
264
|
+
},
|
|
265
|
+
async queues() {
|
|
266
|
+
const transaction = database.transaction([ROOMS, PENDING_CHANGES], 'readonly');
|
|
267
|
+
const [rooms, pending] = await Promise.all([
|
|
268
|
+
settled(transaction.objectStore(ROOMS).getAll()),
|
|
269
|
+
settled(transaction.objectStore(PENDING_CHANGES).getAll()),
|
|
270
|
+
]);
|
|
271
|
+
const byId = new Map(pending.map((record) => [`${record.locator}\0${record.id}`, record]));
|
|
272
|
+
return rooms.map((room) => ({
|
|
273
|
+
locator: room.locator,
|
|
274
|
+
pending: room.order.map((id) => {
|
|
275
|
+
const record = byId.get(`${room.locator}\0${id}`);
|
|
276
|
+
if (record === undefined)
|
|
277
|
+
throw new Error(`Missing Pending Change ${room.locator}/${id}`);
|
|
278
|
+
const { batch, drafts, submission, lost, upload, accepted } = record;
|
|
279
|
+
return { batch, state: { drafts, submission, lost, upload, accepted } };
|
|
280
|
+
}),
|
|
281
|
+
}));
|
|
282
|
+
},
|
|
283
|
+
submit(locator, id, submission, lost) {
|
|
284
|
+
return amendPending(database, locator, id, { submission, lost });
|
|
285
|
+
},
|
|
286
|
+
accept(locator, id, roomVersion) {
|
|
287
|
+
return amendPending(database, locator, id, { accepted: roomVersion });
|
|
98
288
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return settled(transaction.objectStore(QUEUES).getAll());
|
|
289
|
+
keepUpload(locator, id, upload) {
|
|
290
|
+
return amendPending(database, locator, id, { upload });
|
|
102
291
|
},
|
|
103
|
-
async
|
|
104
|
-
const transaction = database.transaction(
|
|
105
|
-
return settled(transaction.objectStore(
|
|
292
|
+
async roomDrafts() {
|
|
293
|
+
const transaction = database.transaction(ROOM_DRAFTS, 'readonly');
|
|
294
|
+
return settled(transaction.objectStore(ROOM_DRAFTS).getAll());
|
|
106
295
|
},
|
|
107
|
-
async presentation
|
|
296
|
+
async presentation() {
|
|
108
297
|
const transaction = database.transaction(PRESENTATION, 'readonly');
|
|
109
298
|
return settled(transaction.objectStore(PRESENTATION).getAll());
|
|
110
299
|
},
|
|
111
|
-
async present
|
|
300
|
+
async present(record) {
|
|
112
301
|
const transaction = database.transaction(PRESENTATION, 'readwrite');
|
|
113
302
|
transaction.objectStore(PRESENTATION).put(record);
|
|
114
303
|
await completed(transaction);
|
|
115
304
|
},
|
|
116
|
-
async conversations
|
|
117
|
-
const transaction = database.transaction(CONVERSATIONS, 'readonly');
|
|
118
|
-
|
|
305
|
+
async conversations() {
|
|
306
|
+
const transaction = database.transaction([CONVERSATIONS, MESSAGES], 'readonly');
|
|
307
|
+
const [reads, messages] = await Promise.all([
|
|
308
|
+
settled(transaction.objectStore(CONVERSATIONS).getAll()),
|
|
309
|
+
settled(transaction.objectStore(MESSAGES).getAll()),
|
|
310
|
+
]);
|
|
311
|
+
const held = new Map();
|
|
312
|
+
for (const { conversation, read } of reads) {
|
|
313
|
+
held.set(conversation, { conversation, read, messages: [] });
|
|
314
|
+
}
|
|
315
|
+
for (const { conversation, ...message } of messages) {
|
|
316
|
+
const entry = held.get(conversation) ?? { conversation, read: undefined, messages: [] };
|
|
317
|
+
entry.messages.push(message);
|
|
318
|
+
held.set(conversation, entry);
|
|
319
|
+
}
|
|
320
|
+
return [...held.values()];
|
|
119
321
|
},
|
|
120
|
-
async
|
|
121
|
-
const transaction = database.transaction(CONVERSATIONS, 'readwrite');
|
|
122
|
-
transaction.objectStore(
|
|
322
|
+
async keepMessages({ conversation, messages, read, sealed }) {
|
|
323
|
+
const transaction = database.transaction([CONVERSATIONS, MESSAGES, CHAT_DRAFTS], 'readwrite');
|
|
324
|
+
const stored = transaction.objectStore(MESSAGES);
|
|
325
|
+
for (const message of messages) {
|
|
326
|
+
stored.put({ ...message, conversation });
|
|
327
|
+
}
|
|
328
|
+
if (read !== undefined) {
|
|
329
|
+
transaction
|
|
330
|
+
.objectStore(CONVERSATIONS)
|
|
331
|
+
.put({ conversation, read });
|
|
332
|
+
}
|
|
333
|
+
if (sealed === true)
|
|
334
|
+
transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
123
335
|
await completed(transaction);
|
|
124
336
|
},
|
|
125
|
-
async
|
|
126
|
-
const transaction = database.transaction(CONVERSATIONS, 'readwrite');
|
|
127
|
-
transaction.objectStore(
|
|
337
|
+
async dropConversations(conversations) {
|
|
338
|
+
const transaction = database.transaction([CONVERSATIONS, MESSAGES, CHAT_DRAFTS], 'readwrite');
|
|
339
|
+
const messages = transaction.objectStore(MESSAGES);
|
|
340
|
+
for (const conversation of conversations) {
|
|
341
|
+
transaction.objectStore(CONVERSATIONS).delete(conversation);
|
|
342
|
+
transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
343
|
+
const keys = messages.index('conversation').getAllKeys(conversation);
|
|
344
|
+
keys.onsuccess = () => {
|
|
345
|
+
for (const key of keys.result)
|
|
346
|
+
messages.delete(key);
|
|
347
|
+
};
|
|
348
|
+
}
|
|
128
349
|
await completed(transaction);
|
|
129
350
|
},
|
|
130
|
-
async
|
|
131
|
-
const transaction = database.transaction(
|
|
132
|
-
return settled(transaction.objectStore(
|
|
133
|
-
},
|
|
134
|
-
async keepInstruction (record) {
|
|
135
|
-
const transaction = database.transaction(INSTRUCTIONS, 'readwrite');
|
|
136
|
-
transaction.objectStore(INSTRUCTIONS).put(record);
|
|
137
|
-
await completed(transaction);
|
|
351
|
+
async chatDrafts() {
|
|
352
|
+
const transaction = database.transaction(CHAT_DRAFTS, 'readonly');
|
|
353
|
+
return settled(transaction.objectStore(CHAT_DRAFTS).getAll());
|
|
138
354
|
},
|
|
139
|
-
async
|
|
140
|
-
const transaction = database.transaction(
|
|
141
|
-
transaction.objectStore(
|
|
355
|
+
async keepChatDraft(record) {
|
|
356
|
+
const transaction = database.transaction(CHAT_DRAFTS, 'readwrite');
|
|
357
|
+
transaction.objectStore(CHAT_DRAFTS).put(record);
|
|
142
358
|
await completed(transaction);
|
|
143
359
|
},
|
|
144
|
-
async
|
|
145
|
-
const transaction = database.transaction(
|
|
146
|
-
transaction.objectStore(
|
|
360
|
+
async dropChatDraft(conversation) {
|
|
361
|
+
const transaction = database.transaction(CHAT_DRAFTS, 'readwrite');
|
|
362
|
+
transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
147
363
|
await completed(transaction);
|
|
148
364
|
},
|
|
149
|
-
async
|
|
150
|
-
const transaction = database.transaction(
|
|
151
|
-
transaction.objectStore(
|
|
152
|
-
locator,
|
|
153
|
-
path
|
|
154
|
-
]);
|
|
365
|
+
async keepRoomDraft(record) {
|
|
366
|
+
const transaction = database.transaction(ROOM_DRAFTS, 'readwrite');
|
|
367
|
+
transaction.objectStore(ROOM_DRAFTS).put(record);
|
|
155
368
|
await completed(transaction);
|
|
156
369
|
},
|
|
157
|
-
async
|
|
158
|
-
const transaction = database.transaction(
|
|
159
|
-
|
|
160
|
-
DRAFTS
|
|
161
|
-
], 'readwrite');
|
|
162
|
-
transaction.objectStore(QUEUES).put(queue);
|
|
163
|
-
const drafts = transaction.objectStore(DRAFTS);
|
|
164
|
-
for (const path of consumed)drafts.delete([
|
|
165
|
-
queue.locator,
|
|
166
|
-
path
|
|
167
|
-
]);
|
|
370
|
+
async discardRoomDraft(locator, path) {
|
|
371
|
+
const transaction = database.transaction(ROOM_DRAFTS, 'readwrite');
|
|
372
|
+
transaction.objectStore(ROOM_DRAFTS).delete([locator, path]);
|
|
168
373
|
await completed(transaction);
|
|
169
374
|
},
|
|
170
|
-
async
|
|
171
|
-
const transaction = database.transaction(
|
|
172
|
-
|
|
375
|
+
async dropRooms(locators) {
|
|
376
|
+
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
|
|
377
|
+
for (const locator of locators) {
|
|
378
|
+
transaction.objectStore(ROOMS).delete(locator);
|
|
379
|
+
for (const name of [DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS]) {
|
|
380
|
+
removeRoomEntries(transaction.objectStore(name), locator);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
173
383
|
await completed(transaction);
|
|
174
384
|
},
|
|
175
|
-
async generation
|
|
176
|
-
|
|
177
|
-
const value = await settled(transaction.objectStore(SYNCHRONIZATION).get(GENERATION));
|
|
178
|
-
return value ?? null;
|
|
385
|
+
async generation() {
|
|
386
|
+
return (await declaration(database)).generation;
|
|
179
387
|
},
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
transaction.objectStore(SYNCHRONIZATION).put(value, GENERATION);
|
|
183
|
-
await completed(transaction);
|
|
388
|
+
rememberGeneration(value) {
|
|
389
|
+
return updateDeclaration(database, (record) => ({ ...record, generation: value }));
|
|
184
390
|
},
|
|
185
|
-
close
|
|
391
|
+
close() {
|
|
186
392
|
database.close();
|
|
187
|
-
}
|
|
393
|
+
},
|
|
188
394
|
};
|
|
189
395
|
}
|
|
190
|
-
|
|
191
|
-
//# sourceMappingURL=store.js.map
|
package/dist/transfer.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import type { Refusal } from '@agentshouse/mdmodel';
|
|
1
2
|
export type Unconfirmed = {
|
|
2
3
|
kind: 'unconfirmed';
|
|
3
4
|
};
|
|
5
|
+
export type Refused = {
|
|
6
|
+
kind: 'refused';
|
|
7
|
+
refusal: Refusal;
|
|
8
|
+
};
|
|
4
9
|
export declare const unconfirmed: Unconfirmed;
|
|
5
10
|
//# sourceMappingURL=transfer.d.ts.map
|
package/dist/transfer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC;AAElD,eAAO,MAAM,WAAW,EAAE,WAAqC,CAAC"}
|
|
1
|
+
{"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC;AAElD,MAAM,MAAM,OAAO,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAE5D,eAAO,MAAM,WAAW,EAAE,WAAqC,CAAC"}
|
package/dist/transfer.js
CHANGED
package/dist/wire.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { ConnectionRefusal } from './connection.js';
|
|
2
|
-
export declare const RUNTIME_WIRE_PROTOCOL = 1;
|
|
3
|
-
export declare const PROTOCOL_MISMATCH: ConnectionRefusal;
|
|
4
2
|
export type RuntimePort = {
|
|
5
3
|
postMessage(message: unknown): void;
|
|
6
4
|
addEventListener(type: 'message' | 'close', listener: (event: {
|
|
@@ -8,10 +6,56 @@ export type RuntimePort = {
|
|
|
8
6
|
}) => void): void;
|
|
9
7
|
start(): void;
|
|
10
8
|
};
|
|
11
|
-
|
|
12
|
-
declare const
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
export type WireReach = 'within' | 'app' | 'runtime' | 'actions' | 'whole';
|
|
10
|
+
declare const MEMBERS: {
|
|
11
|
+
readonly rooms: 'within';
|
|
12
|
+
readonly query: 'within';
|
|
13
|
+
readonly search: 'within';
|
|
14
|
+
readonly types: 'within';
|
|
15
|
+
readonly save: 'within';
|
|
16
|
+
readonly history: 'within';
|
|
17
|
+
readonly call: 'actions';
|
|
18
|
+
readonly reached: 'within';
|
|
19
|
+
readonly log: 'whole';
|
|
20
|
+
readonly persistence: 'runtime';
|
|
21
|
+
readonly reauthorize: 'runtime';
|
|
22
|
+
readonly 'roomDraft.list': 'within';
|
|
23
|
+
readonly 'roomDraft.read': 'within';
|
|
24
|
+
readonly 'roomDraft.write': 'within';
|
|
25
|
+
readonly 'roomDraft.discard': 'within';
|
|
26
|
+
readonly 'presentation.read': 'app';
|
|
27
|
+
readonly 'presentation.write': 'app';
|
|
28
|
+
readonly 'conversation.list': 'within';
|
|
29
|
+
readonly 'conversation.read': 'within';
|
|
30
|
+
readonly 'conversation.create': 'within';
|
|
31
|
+
readonly 'conversation.send': 'within';
|
|
32
|
+
readonly 'conversation.answer': 'within';
|
|
33
|
+
readonly 'conversation.interrupt': 'within';
|
|
34
|
+
readonly 'conversation.kill': 'within';
|
|
35
|
+
readonly 'conversation.cancel': 'within';
|
|
36
|
+
readonly 'conversation.delete': 'within';
|
|
37
|
+
readonly 'chatDraft.write': 'within';
|
|
38
|
+
readonly 'chatDraft.discard': 'within';
|
|
39
|
+
};
|
|
40
|
+
declare const TOPICS: {
|
|
41
|
+
readonly rooms: 'within';
|
|
42
|
+
readonly 'connection-refusal': 'runtime';
|
|
43
|
+
readonly 'storage-loss': 'runtime';
|
|
44
|
+
readonly 'deployment-facts': 'runtime';
|
|
45
|
+
readonly 'sync-status': 'within';
|
|
46
|
+
readonly 'service-mode': 'runtime';
|
|
47
|
+
readonly query: 'within';
|
|
48
|
+
readonly queue: 'within';
|
|
49
|
+
readonly 'room-drafts': 'within';
|
|
50
|
+
readonly presentation: 'app';
|
|
51
|
+
readonly conversation: 'within';
|
|
52
|
+
};
|
|
53
|
+
export declare const WIRE_REACH: {
|
|
54
|
+
readonly members: Readonly<Record<string, WireReach>>;
|
|
55
|
+
readonly topics: Readonly<Record<string, WireReach>>;
|
|
56
|
+
};
|
|
57
|
+
export type WireMember = keyof typeof MEMBERS;
|
|
58
|
+
export type WireTopic = keyof typeof TOPICS;
|
|
15
59
|
export type WireRequest = {
|
|
16
60
|
kind: 'hello';
|
|
17
61
|
} | {
|
|
@@ -47,16 +91,7 @@ export type WireAnswer = {
|
|
|
47
91
|
kind: 'ended';
|
|
48
92
|
};
|
|
49
93
|
export declare const AUTHORIZATION_ENDED = "the host authorization ended";
|
|
50
|
-
export
|
|
51
|
-
mdRuntime: number;
|
|
52
|
-
message: WireRequest | WireAnswer;
|
|
53
|
-
};
|
|
54
|
-
export type Carried = {
|
|
55
|
-
matching: boolean;
|
|
56
|
-
message: unknown;
|
|
57
|
-
};
|
|
58
|
-
export declare function envelope(message: WireRequest | WireAnswer): WireEnvelope;
|
|
59
|
-
export declare function carried(data: unknown): Carried | null;
|
|
94
|
+
export declare const PORT_CLOSED = "the port closed";
|
|
60
95
|
export declare function request(message: unknown): WireRequest | null;
|
|
61
96
|
export declare function answer(message: unknown): WireAnswer | null;
|
|
62
97
|
export {};
|
package/dist/wire.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,
|
|
1
|
+
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"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"}
|