@agentshouse/mdruntime 0.1.0-c03e7b79830dd → 0.1.0-c0bed82db8d73
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 +65 -65
- package/README.md +8 -7
- package/dist/adapter.d.ts +10 -14
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -2
- package/dist/binary.d.ts +0 -5
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +1 -1
- package/dist/bootstrap.d.ts +13 -2
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +94 -57
- package/dist/change-set.d.ts +1 -7
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +1 -4
- package/dist/client.d.ts +2 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -2
- package/dist/compile.d.ts +6 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +12 -3
- package/dist/connection.d.ts +4 -5
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +481 -448
- package/dist/conversation.d.ts +2 -0
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +40 -19
- package/dist/durability.d.ts +2 -5
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/fulltext.d.ts +27 -0
- package/dist/fulltext.d.ts.map +1 -0
- package/dist/fulltext.js +368 -0
- package/dist/host.d.ts +4 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +35 -15
- 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 +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +0 -11
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +90 -0
- package/dist/outcome.d.ts +0 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +0 -3
- package/dist/overlay.js +1 -1
- package/dist/query.d.ts +4 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +12 -1
- package/dist/reach.d.ts +0 -2
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +17 -28
- package/dist/readiness.d.ts +20 -9
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +6 -6
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +3 -1
- package/dist/refresh.d.ts +6 -2
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +60 -22
- package/dist/replica.d.ts +3 -1
- package/dist/replica.d.ts.map +1 -1
- package/dist/room-draft.d.ts +1 -0
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +33 -0
- package/dist/save.js +2 -2
- package/dist/search.d.ts +11 -43
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +0 -296
- package/dist/store.d.ts +17 -36
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +28 -227
- package/dist/stored.d.ts +9 -7
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +46 -40
- package/dist/tables.d.ts +46 -12
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +94 -7
- package/dist/wire.d.ts +0 -4
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +0 -1
- package/dist/words.d.ts +19 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +150 -0
- package/package.json +11 -18
- package/dist/chat/acts.d.ts +0 -33
- package/dist/chat/acts.d.ts.map +0 -1
- package/dist/chat/acts.js +0 -36
- package/dist/chat/context.d.ts +0 -3
- package/dist/chat/context.d.ts.map +0 -1
- package/dist/chat/context.js +0 -10
- package/dist/chat/earlier.d.ts +0 -10
- package/dist/chat/earlier.d.ts.map +0 -1
- package/dist/chat/earlier.js +0 -54
- package/dist/chat/house.d.ts +0 -25
- package/dist/chat/house.d.ts.map +0 -1
- package/dist/chat/house.js +0 -38
- package/dist/chat/input.d.ts +0 -11
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -92
- package/dist/chat/kit.d.ts +0 -61
- package/dist/chat/kit.d.ts.map +0 -1
- package/dist/chat/kit.js +0 -123
- package/dist/chat/lasting.d.ts +0 -6
- package/dist/chat/lasting.d.ts.map +0 -1
- package/dist/chat/lasting.js +0 -19
- package/dist/chat/list.d.ts +0 -28
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -103
- package/dist/chat/markdown.d.ts +0 -21
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -246
- package/dist/chat/message.d.ts +0 -7
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -244
- package/dist/chat/messages.d.ts +0 -30
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -198
- package/dist/chat/name.d.ts +0 -7
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -12
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -19
- package/dist/chat/overlay.d.ts +0 -32
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -103
- package/dist/chat/parts.d.ts +0 -58
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/parts.js +0 -120
- package/dist/chat/pieces.d.ts +0 -62
- package/dist/chat/pieces.d.ts.map +0 -1
- package/dist/chat/pieces.js +0 -1110
- package/dist/chat/process.d.ts +0 -20
- package/dist/chat/process.d.ts.map +0 -1
- package/dist/chat/process.js +0 -32
- package/dist/chat/provider.d.ts +0 -70
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -635
- package/dist/chat/question.d.ts +0 -9
- package/dist/chat/question.d.ts.map +0 -1
- package/dist/chat/question.js +0 -69
- package/dist/chat/questions.d.ts +0 -31
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/questions.js +0 -111
- package/dist/chat/read.d.ts +0 -5
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat/read.js +0 -13
- package/dist/chat/ready.d.ts +0 -37
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -93
- package/dist/chat/room-file.d.ts +0 -8
- package/dist/chat/room-file.d.ts.map +0 -1
- package/dist/chat/room-file.js +0 -72
- package/dist/chat/steady.d.ts +0 -3
- package/dist/chat/steady.d.ts.map +0 -1
- package/dist/chat/steady.js +0 -26
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -306
- package/dist/chat.d.ts +0 -15
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -8
package/dist/store.js
CHANGED
|
@@ -1,123 +1,5 @@
|
|
|
1
|
-
import { precedes } from './windows.js';
|
|
2
1
|
import { binaryLocalId } from './identity.js';
|
|
3
|
-
const DATABASE = 'mdruntime';
|
|
4
|
-
const CONVERSATIONS = 'conversations';
|
|
5
|
-
const MESSAGES = 'messages';
|
|
6
2
|
const FILE = '\u0000file';
|
|
7
|
-
export const STORE_SCHEMA = 26;
|
|
8
|
-
const STORES = [
|
|
9
|
-
[CONVERSATIONS, { keyPath: 'conversation' }],
|
|
10
|
-
[MESSAGES, { keyPath: ['conversation', 'identity'] }],
|
|
11
|
-
];
|
|
12
|
-
const READ_BATCH = 256;
|
|
13
|
-
const MESSAGE_INDEXES = [
|
|
14
|
-
['conversation', 'conversation'],
|
|
15
|
-
['position', ['conversation', 'position']],
|
|
16
|
-
['turn', ['conversation', 'turn']],
|
|
17
|
-
];
|
|
18
|
-
function settled(request) {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
request.onsuccess = () => resolve(request.result);
|
|
21
|
-
request.onerror = () => reject(request.error);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
const turns = new Map();
|
|
25
|
-
function idle(database) {
|
|
26
|
-
return turns.get(database.name) ?? Promise.resolve();
|
|
27
|
-
}
|
|
28
|
-
export function transacted(database, stores, mode, work) {
|
|
29
|
-
let release = () => { };
|
|
30
|
-
const turn = new Promise((resolve) => {
|
|
31
|
-
release = resolve;
|
|
32
|
-
});
|
|
33
|
-
const before = idle(database);
|
|
34
|
-
const queued = before.then(() => turn);
|
|
35
|
-
turns.set(database.name, queued);
|
|
36
|
-
void queued.then(() => {
|
|
37
|
-
if (turns.get(database.name) === queued)
|
|
38
|
-
turns.delete(database.name);
|
|
39
|
-
});
|
|
40
|
-
return before.then(() => {
|
|
41
|
-
let transaction;
|
|
42
|
-
try {
|
|
43
|
-
transaction = database.transaction(stores, mode);
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
release();
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
const committed = new Promise((resolve, reject) => {
|
|
50
|
-
transaction.oncomplete = () => {
|
|
51
|
-
release();
|
|
52
|
-
resolve();
|
|
53
|
-
};
|
|
54
|
-
transaction.onabort = () => {
|
|
55
|
-
release();
|
|
56
|
-
reject(transaction.error);
|
|
57
|
-
};
|
|
58
|
-
transaction.onerror = () => reject(transaction.error);
|
|
59
|
-
});
|
|
60
|
-
let value;
|
|
61
|
-
try {
|
|
62
|
-
value = work(transaction);
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
void committed.catch(() => { });
|
|
66
|
-
transaction.abort();
|
|
67
|
-
throw error;
|
|
68
|
-
}
|
|
69
|
-
return Promise.all([value, committed]).then(([held]) => held);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function accepted({ conversation: _held, ...message }) {
|
|
73
|
-
return message;
|
|
74
|
-
}
|
|
75
|
-
function removeDatabase(name) {
|
|
76
|
-
return new Promise((resolve, reject) => {
|
|
77
|
-
const removal = indexedDB.deleteDatabase(name);
|
|
78
|
-
removal.onsuccess = () => resolve();
|
|
79
|
-
removal.onerror = () => reject(removal.error);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
export async function endRuntimeStore(database, holder) {
|
|
83
|
-
await removeDatabase(DATABASE);
|
|
84
|
-
return database.ask({ kind: 'authored.end', holder: holder ?? null });
|
|
85
|
-
}
|
|
86
|
-
export function openDatabase(name, version, upgrade) {
|
|
87
|
-
return new Promise((resolve, reject) => {
|
|
88
|
-
const opening = indexedDB.open(name, version);
|
|
89
|
-
opening.onupgradeneeded = (event) => upgrade(opening, event.oldVersion);
|
|
90
|
-
opening.onsuccess = () => resolve(opening.result);
|
|
91
|
-
opening.onerror = () => {
|
|
92
|
-
if (opening.error?.name !== 'VersionError') {
|
|
93
|
-
reject(opening.error);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
removeDatabase(name)
|
|
97
|
-
.then(() => openDatabase(name, version, upgrade))
|
|
98
|
-
.then(resolve, reject);
|
|
99
|
-
};
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
function openConversations() {
|
|
103
|
-
return openDatabase(DATABASE, STORE_SCHEMA, (opening, oldVersion) => {
|
|
104
|
-
const database = opening.result;
|
|
105
|
-
if (oldVersion < STORE_SCHEMA) {
|
|
106
|
-
for (const name of [...database.objectStoreNames])
|
|
107
|
-
database.deleteObjectStore(name);
|
|
108
|
-
}
|
|
109
|
-
for (const [name, parameters] of STORES) {
|
|
110
|
-
if (database.objectStoreNames.contains(name))
|
|
111
|
-
continue;
|
|
112
|
-
database.createObjectStore(name, parameters);
|
|
113
|
-
}
|
|
114
|
-
const messages = opening.transaction.objectStore(MESSAGES);
|
|
115
|
-
for (const [name, keyPath] of MESSAGE_INDEXES) {
|
|
116
|
-
if (!messages.indexNames.contains(name))
|
|
117
|
-
messages.createIndex(name, keyPath);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
3
|
function batchFiles(batch) {
|
|
122
4
|
return batch.changes.flatMap((change) => (change.kind === 'binary' ? [change.localId] : []));
|
|
123
5
|
}
|
|
@@ -206,8 +88,7 @@ async function filed(value, read) {
|
|
|
206
88
|
function json(value, fallback) {
|
|
207
89
|
return value === undefined ? fallback : JSON.parse(value);
|
|
208
90
|
}
|
|
209
|
-
export
|
|
210
|
-
const database = await openConversations();
|
|
91
|
+
export function openRuntimeStore(fenced, authored) {
|
|
211
92
|
const keys = new WeakMap();
|
|
212
93
|
const read = async (key, type) => {
|
|
213
94
|
const blob = await authored.ask({ kind: 'authored.file', key, type });
|
|
@@ -239,7 +120,7 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
239
120
|
return {
|
|
240
121
|
async opened() {
|
|
241
122
|
const held = await authored.ask({ kind: 'replica.open' });
|
|
242
|
-
const
|
|
123
|
+
const unindexed = new Set(held.keys.flatMap(({ key, rederiving }) => (rederiving === null ? [] : [key])));
|
|
243
124
|
const overlaid = new Map();
|
|
244
125
|
for (const { key, path } of held.overlaid) {
|
|
245
126
|
const paths = overlaid.get(key) ?? new Set();
|
|
@@ -259,7 +140,7 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
259
140
|
locator,
|
|
260
141
|
{ ...JSON.parse(record), key },
|
|
261
142
|
])),
|
|
262
|
-
|
|
143
|
+
unindexed,
|
|
263
144
|
overlaid,
|
|
264
145
|
erasing: held.erasing.length > 0,
|
|
265
146
|
orphans: held.orphans,
|
|
@@ -301,24 +182,35 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
301
182
|
typedWithin(key, view, roots, within) {
|
|
302
183
|
return authored.ask({ kind: 'replica.typedWithin', key, view, roots, within });
|
|
303
184
|
},
|
|
304
|
-
|
|
305
|
-
return authored.ask({ kind: 'replica.
|
|
185
|
+
search(ask) {
|
|
186
|
+
return authored.ask({ kind: 'replica.search', ...ask });
|
|
306
187
|
},
|
|
307
|
-
async stage(record, composition, page,
|
|
188
|
+
async stage(record, composition, page, written) {
|
|
308
189
|
if (fenced(record.locator))
|
|
309
190
|
return null;
|
|
310
|
-
const { key
|
|
191
|
+
const { key, ...kept } = record;
|
|
311
192
|
return authored.ask({
|
|
312
193
|
kind: 'replica.stage',
|
|
313
194
|
locator: record.locator,
|
|
314
195
|
transfer: record.transfer,
|
|
315
|
-
record:
|
|
196
|
+
record: JSON.stringify(kept),
|
|
316
197
|
key,
|
|
317
198
|
composition,
|
|
318
199
|
entries: page.entries,
|
|
319
200
|
folders: page.folders,
|
|
201
|
+
...(written === undefined ? {} : { written }),
|
|
320
202
|
});
|
|
321
203
|
},
|
|
204
|
+
async transferPart(locator, token) {
|
|
205
|
+
if (fenced(locator))
|
|
206
|
+
return null;
|
|
207
|
+
return authored.ask({ kind: 'replica.transferPart', locator, token });
|
|
208
|
+
},
|
|
209
|
+
async keepPart(locator, token, part) {
|
|
210
|
+
if (fenced(locator))
|
|
211
|
+
return;
|
|
212
|
+
await authored.ask({ kind: 'replica.keepPart', locator, token, part });
|
|
213
|
+
},
|
|
322
214
|
async refresh(key, page) {
|
|
323
215
|
await authored.ask({
|
|
324
216
|
kind: 'replica.refresh',
|
|
@@ -336,7 +228,7 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
336
228
|
const kept = whole ? writes : writes.filter(({ locator }) => !fenced(locator));
|
|
337
229
|
const refused = whole ? kept.find(({ locator }) => fenced(locator)) : undefined;
|
|
338
230
|
if (refused !== undefined) {
|
|
339
|
-
return { fenced: refused.locator, counts: {}, changed: {},
|
|
231
|
+
return { fenced: refused.locator, counts: {}, changed: {}, indexed: {} };
|
|
340
232
|
}
|
|
341
233
|
for (const room of rooms)
|
|
342
234
|
change(room.key);
|
|
@@ -417,110 +309,22 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
417
309
|
});
|
|
418
310
|
},
|
|
419
311
|
conversations() {
|
|
420
|
-
return
|
|
421
|
-
const records = await settled(transaction.objectStore(CONVERSATIONS).getAll());
|
|
422
|
-
const held = new Map(records.map(({ conversation, read, partial }) => [
|
|
423
|
-
conversation,
|
|
424
|
-
{ conversation, read, partial: partial === true },
|
|
425
|
-
]));
|
|
426
|
-
const keys = transaction.objectStore(MESSAGES).index('conversation');
|
|
427
|
-
await new Promise((resolve, reject) => {
|
|
428
|
-
const cursor = keys.openKeyCursor(null, 'nextunique');
|
|
429
|
-
cursor.onerror = () => reject(cursor.error);
|
|
430
|
-
cursor.onsuccess = () => {
|
|
431
|
-
const at = cursor.result;
|
|
432
|
-
if (at === null) {
|
|
433
|
-
resolve();
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
const conversation = at.key;
|
|
437
|
-
if (!held.has(conversation)) {
|
|
438
|
-
held.set(conversation, { conversation, read: undefined, partial: true });
|
|
439
|
-
}
|
|
440
|
-
at.continue();
|
|
441
|
-
};
|
|
442
|
-
});
|
|
443
|
-
return [...held.values()];
|
|
444
|
-
});
|
|
312
|
+
return authored.ask({ kind: 'conversation.held' });
|
|
445
313
|
},
|
|
446
|
-
async keepMessages(
|
|
447
|
-
await
|
|
448
|
-
const stored = transaction.objectStore(MESSAGES);
|
|
449
|
-
for (const message of messages) {
|
|
450
|
-
stored.put({ ...message, conversation });
|
|
451
|
-
}
|
|
452
|
-
if (read !== undefined) {
|
|
453
|
-
transaction.objectStore(CONVERSATIONS).put({
|
|
454
|
-
conversation,
|
|
455
|
-
read: read.at,
|
|
456
|
-
...(read.partial ? { partial: true } : {}),
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
});
|
|
314
|
+
async keepMessages(write) {
|
|
315
|
+
await authored.ask({ kind: 'conversation.keep', ...write });
|
|
460
316
|
},
|
|
461
317
|
messageWindow(conversation, limit, before) {
|
|
462
|
-
return
|
|
463
|
-
const index = transaction.objectStore(MESSAGES).index('position');
|
|
464
|
-
const range = IDBKeyRange.bound([conversation], [conversation, before?.[0] ?? []]);
|
|
465
|
-
const latest = [];
|
|
466
|
-
let more = false;
|
|
467
|
-
await new Promise((resolve, reject) => {
|
|
468
|
-
const cursor = index.openCursor(range, 'prev');
|
|
469
|
-
cursor.onerror = () => reject(cursor.error);
|
|
470
|
-
cursor.onsuccess = () => {
|
|
471
|
-
const at = cursor.result;
|
|
472
|
-
if (at === null) {
|
|
473
|
-
resolve();
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
const record = at.value;
|
|
477
|
-
if (!precedes(record, before)) {
|
|
478
|
-
at.continue();
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
if (latest.length === limit) {
|
|
482
|
-
more = true;
|
|
483
|
-
resolve();
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
latest.push(accepted(record));
|
|
487
|
-
at.continue();
|
|
488
|
-
};
|
|
489
|
-
});
|
|
490
|
-
return { messages: latest.reverse(), more };
|
|
491
|
-
});
|
|
318
|
+
return authored.ask({ kind: 'conversation.window', conversation, limit, before });
|
|
492
319
|
},
|
|
493
320
|
messageCount(conversation) {
|
|
494
|
-
return
|
|
321
|
+
return authored.ask({ kind: 'conversation.count', conversation });
|
|
495
322
|
},
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
? IDBKeyRange.bound([conversation], [conversation, []])
|
|
499
|
-
: IDBKeyRange.bound([conversation, identity], [conversation, []], true);
|
|
500
|
-
const held = await transacted(database, MESSAGES, 'readonly', (transaction) => settled(transaction.objectStore(MESSAGES).getAll(range, READ_BATCH)));
|
|
501
|
-
return held.map(accepted);
|
|
502
|
-
},
|
|
503
|
-
async messageIdentities(conversation) {
|
|
504
|
-
const found = await transacted(database, MESSAGES, 'readonly', (transaction) => settled(transaction.objectStore(MESSAGES).index('conversation').getAllKeys(conversation)));
|
|
505
|
-
return found.map((key) => key[1]);
|
|
506
|
-
},
|
|
507
|
-
async turnArrived(conversation, turn) {
|
|
508
|
-
const held = await transacted(database, MESSAGES, 'readonly', (transaction) => settled(transaction.objectStore(MESSAGES).index('turn').count([conversation, turn])));
|
|
509
|
-
return held > 0;
|
|
323
|
+
turnArrived(conversation, turn) {
|
|
324
|
+
return authored.ask({ kind: 'conversation.turn', conversation, turn });
|
|
510
325
|
},
|
|
511
326
|
async dropConversations(conversations) {
|
|
512
|
-
await authored.ask({ kind: '
|
|
513
|
-
await transacted(database, [CONVERSATIONS, MESSAGES], 'readwrite', (transaction) => {
|
|
514
|
-
const messages = transaction.objectStore(MESSAGES);
|
|
515
|
-
for (const conversation of conversations) {
|
|
516
|
-
transaction.objectStore(CONVERSATIONS).delete(conversation);
|
|
517
|
-
const held = messages.index('conversation').getAllKeys(conversation);
|
|
518
|
-
held.onsuccess = () => {
|
|
519
|
-
for (const key of held.result)
|
|
520
|
-
messages.delete(key);
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
});
|
|
327
|
+
await authored.ask({ kind: 'conversation.drop', conversations });
|
|
524
328
|
},
|
|
525
329
|
async chatDrafts() {
|
|
526
330
|
const records = await authored.ask({ kind: 'authored.chatDrafts' });
|
|
@@ -602,8 +406,5 @@ export async function openRuntimeStore(fenced, authored) {
|
|
|
602
406
|
file(key, type) {
|
|
603
407
|
return authored.ask({ kind: 'authored.file', key, type });
|
|
604
408
|
},
|
|
605
|
-
close() {
|
|
606
|
-
void idle(database).then(() => database.close());
|
|
607
|
-
},
|
|
608
409
|
};
|
|
609
410
|
}
|
package/dist/stored.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { HeadChange } from './adapter.js';
|
|
2
2
|
import type { Composition } from './collection.js';
|
|
3
3
|
import type { HeldBinary } from './overlay.js';
|
|
4
|
-
import type { SearchedDocument } from './search.js';
|
|
5
4
|
import type { Connection } from './tables.js';
|
|
6
5
|
export declare const REPLICA_TABLES: readonly string[];
|
|
7
6
|
export type View = 'confirmed' | 'visible' | 'refreshed';
|
|
@@ -85,7 +84,7 @@ export type RoomCommit = {
|
|
|
85
84
|
export type Committed = {
|
|
86
85
|
readonly counts: Readonly<Record<string, number>>;
|
|
87
86
|
readonly changed: Readonly<Record<string, readonly string[] | null>>;
|
|
88
|
-
readonly
|
|
87
|
+
readonly indexed: Readonly<Record<string, boolean>>;
|
|
89
88
|
};
|
|
90
89
|
export type CountedRoom = {
|
|
91
90
|
readonly key: number;
|
|
@@ -100,11 +99,12 @@ export declare function entered(connection: Connection, locator: string, composi
|
|
|
100
99
|
export declare function stage(connection: Connection, request: {
|
|
101
100
|
readonly locator: string;
|
|
102
101
|
readonly transfer: string;
|
|
103
|
-
readonly record: string
|
|
102
|
+
readonly record: string;
|
|
104
103
|
readonly key: number | null;
|
|
105
104
|
readonly composition: Composition;
|
|
106
105
|
readonly entries: readonly StoredEntry[];
|
|
107
106
|
readonly folders: readonly string[];
|
|
107
|
+
readonly written?: string;
|
|
108
108
|
}): number;
|
|
109
109
|
export declare function refreshing(connection: Connection, request: {
|
|
110
110
|
readonly key: number;
|
|
@@ -134,10 +134,12 @@ export declare function files(connection: Connection, key: number, view: View, a
|
|
|
134
134
|
readonly revision: string;
|
|
135
135
|
}[];
|
|
136
136
|
export declare function typedWithin(connection: Connection, key: number, view: View, roots: readonly string[], within: boolean): boolean;
|
|
137
|
-
export declare function
|
|
138
|
-
|
|
139
|
-
readonly
|
|
140
|
-
|
|
137
|
+
export declare function transferPart(connection: Connection, locator: string, token: string): Uint8Array | null;
|
|
138
|
+
export declare function keepPart(connection: Connection, request: {
|
|
139
|
+
readonly locator: string;
|
|
140
|
+
readonly token: string;
|
|
141
|
+
readonly part: Uint8Array;
|
|
142
|
+
}): null;
|
|
141
143
|
export declare function opened(connection: Connection): ReplicaOpened;
|
|
142
144
|
export declare function ended(connection: Connection): void;
|
|
143
145
|
//# sourceMappingURL=stored.d.ts.map
|
package/dist/stored.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stored.d.ts","sourceRoot":"","sources":["../src/stored.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stored.d.ts","sourceRoot":"","sources":["../src/stored.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEn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AAE,UAAU,GAAG,IAAI,CAMlD"}
|
package/dist/stored.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { derived
|
|
1
|
+
import { indexDocument, unindexAll, unindexDocuments } from './fulltext.js';
|
|
2
|
+
import { derived } from './rows.js';
|
|
3
3
|
export const REPLICA_TABLES = [
|
|
4
4
|
'CREATE TABLE replica_keys (key INTEGER PRIMARY KEY AUTOINCREMENT, locator TEXT NOT NULL, transfer TEXT NOT NULL, composition TEXT NOT NULL, rederiving INTEGER)',
|
|
5
5
|
'CREATE TABLE replica_rooms (locator TEXT PRIMARY KEY, key INTEGER NOT NULL, record TEXT NOT NULL) WITHOUT ROWID',
|
|
6
6
|
'CREATE TABLE replica_transfers (locator TEXT PRIMARY KEY, key INTEGER NOT NULL, record TEXT NOT NULL) WITHOUT ROWID',
|
|
7
|
+
'CREATE TABLE replica_transfer_parts (locator TEXT NOT NULL, token TEXT NOT NULL, part BLOB NOT NULL)',
|
|
8
|
+
'CREATE INDEX replica_transfer_parts_locator ON replica_transfer_parts (locator)',
|
|
7
9
|
'CREATE TABLE replica_entries (id INTEGER PRIMARY KEY, key INTEGER NOT NULL, layer INTEGER NOT NULL, path TEXT NOT NULL, visible INTEGER NOT NULL, present INTEGER NOT NULL, queried INTEGER NOT NULL, binary TEXT, revision TEXT, file_id TEXT, change TEXT, written TEXT, type TEXT, declared TEXT, folder TEXT NOT NULL, fields TEXT, content TEXT)',
|
|
8
10
|
'CREATE UNIQUE INDEX replica_entries_path ON replica_entries (key, layer, path)',
|
|
9
11
|
'CREATE INDEX replica_entries_visible ON replica_entries (key, visible, path)',
|
|
@@ -97,9 +99,13 @@ function removeEntry(connection, key, layer, path) {
|
|
|
97
99
|
if (id === null)
|
|
98
100
|
return;
|
|
99
101
|
dropDerived(connection, id);
|
|
102
|
+
unindexDocuments(connection, [id]);
|
|
100
103
|
connection.run('DELETE FROM replica_entries WHERE id = ?', [id]);
|
|
101
104
|
}
|
|
102
|
-
function
|
|
105
|
+
function heldIds(connection, sql, bind) {
|
|
106
|
+
return connection.rows(sql, bind).map((row) => number(row.id));
|
|
107
|
+
}
|
|
108
|
+
function putEntry(connection, key, layer, entry, present, composition, searched = true) {
|
|
103
109
|
removeEntry(connection, key, layer, entry.path);
|
|
104
110
|
const made = present
|
|
105
111
|
? derived(entry.path, entry.binary === null ? entry.content : null, composition)
|
|
@@ -134,6 +140,9 @@ function putEntry(connection, key, layer, entry, present, composition) {
|
|
|
134
140
|
return;
|
|
135
141
|
const id = entryId(connection, key, layer, entry.path);
|
|
136
142
|
writeDerived(connection, id, key, made);
|
|
143
|
+
if (searched && entry.binary === null && entry.content !== null && made.queried) {
|
|
144
|
+
indexDocument(connection, id, entry.path, entry.content);
|
|
145
|
+
}
|
|
137
146
|
}
|
|
138
147
|
function revealed(connection, key, touched) {
|
|
139
148
|
if (touched.length === 0)
|
|
@@ -148,7 +157,8 @@ function newKey(connection, locator, transfer, composition) {
|
|
|
148
157
|
function recomposed(connection, key, composition) {
|
|
149
158
|
const [row] = connection.rows('SELECT composition FROM replica_keys WHERE key = ?', [key]);
|
|
150
159
|
const before = json(row?.composition);
|
|
151
|
-
|
|
160
|
+
const held = connection.rows('SELECT 1 FROM replica_entries WHERE key = ? LIMIT 1', [key]);
|
|
161
|
+
if (held.length === 0 || (before !== null && fingerprint(before) === fingerprint(composition))) {
|
|
152
162
|
connection.run('UPDATE replica_keys SET composition = ? WHERE key = ?', [
|
|
153
163
|
JSON.stringify(composition),
|
|
154
164
|
key,
|
|
@@ -163,9 +173,13 @@ function recomposed(connection, key, composition) {
|
|
|
163
173
|
export function entered(connection, locator, composition, rows) {
|
|
164
174
|
const key = newKey(connection, locator, '', composition);
|
|
165
175
|
for (const entry of rows)
|
|
166
|
-
putEntry(connection, key, CONFIRMED, entry, true, composition);
|
|
176
|
+
putEntry(connection, key, CONFIRMED, entry, true, composition, false);
|
|
167
177
|
return key;
|
|
168
178
|
}
|
|
179
|
+
function dropTransfer(connection, locator) {
|
|
180
|
+
connection.run('DELETE FROM replica_transfers WHERE locator = ?', [locator]);
|
|
181
|
+
connection.run('DELETE FROM replica_transfer_parts WHERE locator = ?', [locator]);
|
|
182
|
+
}
|
|
169
183
|
export function stage(connection, request) {
|
|
170
184
|
const [held] = connection.rows('SELECT key FROM replica_transfers WHERE locator = ?', [
|
|
171
185
|
request.locator,
|
|
@@ -175,8 +189,12 @@ export function stage(connection, request) {
|
|
|
175
189
|
? newKey(connection, request.locator, request.transfer, request.composition)
|
|
176
190
|
: number(held.key));
|
|
177
191
|
recomposed(connection, key, request.composition);
|
|
178
|
-
|
|
179
|
-
|
|
192
|
+
connection.run('INSERT OR REPLACE INTO replica_transfers (locator, key, record) VALUES (?, ?, ?)', [request.locator, key, request.record]);
|
|
193
|
+
if (request.written !== undefined) {
|
|
194
|
+
connection.run('DELETE FROM replica_transfer_parts WHERE locator = ? AND token = ?', [
|
|
195
|
+
request.locator,
|
|
196
|
+
request.written,
|
|
197
|
+
]);
|
|
180
198
|
}
|
|
181
199
|
const composition = compositionOf(connection, key);
|
|
182
200
|
for (const entry of request.entries) {
|
|
@@ -217,6 +235,7 @@ export function refreshing(connection, request) {
|
|
|
217
235
|
return null;
|
|
218
236
|
}
|
|
219
237
|
function dropLayer(connection, key, layer) {
|
|
238
|
+
unindexDocuments(connection, heldIds(connection, 'SELECT id FROM replica_entries WHERE key = ? AND layer = ?', [key, layer]));
|
|
220
239
|
for (const table of ['replica_values', 'replica_links']) {
|
|
221
240
|
connection.run(`DELETE FROM ${table} WHERE doc IN (SELECT id FROM replica_entries WHERE key = ? AND layer = ?)`, [key, layer]);
|
|
222
241
|
}
|
|
@@ -235,6 +254,7 @@ function refreshedPaths(connection, key) {
|
|
|
235
254
|
function applyRefresh(connection, key) {
|
|
236
255
|
const touched = refreshedPaths(connection, key);
|
|
237
256
|
const replaced = `SELECT c.id FROM replica_entries c JOIN replica_entries r ON r.key = c.key AND r.layer = ${REFRESHED} AND r.path = c.path WHERE c.key = ? AND c.layer = ${CONFIRMED}`;
|
|
257
|
+
unindexDocuments(connection, heldIds(connection, replaced, [key]));
|
|
238
258
|
for (const table of ['replica_values', 'replica_links']) {
|
|
239
259
|
connection.run(`DELETE FROM ${table} WHERE doc IN (${replaced})`, [key]);
|
|
240
260
|
}
|
|
@@ -279,7 +299,7 @@ function commitRoom(connection, room) {
|
|
|
279
299
|
if (room.published.from !== null && room.published.from !== room.key) {
|
|
280
300
|
erasing(connection, room.published.from, room.locator);
|
|
281
301
|
}
|
|
282
|
-
connection
|
|
302
|
+
dropTransfer(connection, room.locator);
|
|
283
303
|
}
|
|
284
304
|
if (room.refreshed === true) {
|
|
285
305
|
for (const path of applyRefresh(connection, room.key))
|
|
@@ -315,16 +335,16 @@ function commitRoom(connection, room) {
|
|
|
315
335
|
export function commit(connection, rooms) {
|
|
316
336
|
const counted = {};
|
|
317
337
|
const changed = {};
|
|
318
|
-
const
|
|
338
|
+
const indexed = {};
|
|
319
339
|
for (const room of rooms) {
|
|
320
340
|
changed[room.locator] = commitRoom(connection, room);
|
|
321
341
|
counted[room.locator] = counts(connection, [
|
|
322
342
|
{ key: room.key, roots: room.roots ?? rootsOf(connection, room.locator) },
|
|
323
343
|
])[0];
|
|
324
344
|
const [held] = connection.rows('SELECT rederiving FROM replica_keys WHERE key = ?', [room.key]);
|
|
325
|
-
|
|
345
|
+
indexed[room.locator] = held !== undefined && held.rederiving === null;
|
|
326
346
|
}
|
|
327
|
-
return { counts: counted, changed,
|
|
347
|
+
return { counts: counted, changed, indexed };
|
|
328
348
|
}
|
|
329
349
|
function rootsOf(connection, locator) {
|
|
330
350
|
const [row] = connection.rows('SELECT record FROM replica_rooms WHERE locator = ?', [locator]);
|
|
@@ -337,13 +357,13 @@ export function fenceRooms(connection, locators) {
|
|
|
337
357
|
erasing(connection, number(row.key), locator);
|
|
338
358
|
}
|
|
339
359
|
connection.run('DELETE FROM replica_rooms WHERE locator = ?', [locator]);
|
|
340
|
-
connection
|
|
360
|
+
dropTransfer(connection, locator);
|
|
341
361
|
}
|
|
342
362
|
return null;
|
|
343
363
|
}
|
|
344
364
|
export function abandon(connection, locator, kept) {
|
|
345
365
|
const [held] = connection.rows('SELECT key FROM replica_transfers WHERE locator = ?', [locator]);
|
|
346
|
-
connection
|
|
366
|
+
dropTransfer(connection, locator);
|
|
347
367
|
if (held === undefined)
|
|
348
368
|
return null;
|
|
349
369
|
if (!kept)
|
|
@@ -364,6 +384,7 @@ export function erase(connection, locator, limit) {
|
|
|
364
384
|
return { remaining: false };
|
|
365
385
|
const key = number(held.key);
|
|
366
386
|
const batch = 'SELECT id FROM replica_entries WHERE key = ? ORDER BY id LIMIT ?';
|
|
387
|
+
unindexDocuments(connection, heldIds(connection, batch, [key, limit]));
|
|
367
388
|
for (const table of ['replica_values', 'replica_links']) {
|
|
368
389
|
connection.run(`DELETE FROM ${table} WHERE doc IN (${batch})`, [key, limit]);
|
|
369
390
|
}
|
|
@@ -480,33 +501,17 @@ export function typedWithin(connection, key, view, roots, within) {
|
|
|
480
501
|
const placed = roots.length === 0 ? (within ? ' AND 0' : '') : ` AND ${within ? '' : 'NOT '}(${inside})`;
|
|
481
502
|
return (connection.rows(`SELECT 1 FROM replica_entries e WHERE e.key = ? AND ${viewed(view, 'e')} AND e.declared IS NOT NULL AND e.declared <> 'any'${placed} LIMIT 1`, bind).length > 0);
|
|
482
503
|
}
|
|
483
|
-
export function
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
const read = parse(text(row.content) ?? '', path);
|
|
495
|
-
if (!read.ok || !markdownPath(path))
|
|
496
|
-
continue;
|
|
497
|
-
documents.push({
|
|
498
|
-
room: locator,
|
|
499
|
-
path,
|
|
500
|
-
type: text(row.type),
|
|
501
|
-
fields: json(row.fields) ?? {},
|
|
502
|
-
preamble: read.document.preamble,
|
|
503
|
-
sections: read.document.sections,
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
return {
|
|
507
|
-
documents,
|
|
508
|
-
next: rows.length < limit ? null : text(rows.at(-1).path),
|
|
509
|
-
};
|
|
504
|
+
export function transferPart(connection, locator, token) {
|
|
505
|
+
const [held] = connection.rows('SELECT part FROM replica_transfer_parts WHERE locator = ? AND token = ?', [locator, token]);
|
|
506
|
+
return held?.part instanceof Uint8Array ? held.part : null;
|
|
507
|
+
}
|
|
508
|
+
export function keepPart(connection, request) {
|
|
509
|
+
connection.run('DELETE FROM replica_transfer_parts WHERE locator = ? AND token = ?', [
|
|
510
|
+
request.locator,
|
|
511
|
+
request.token,
|
|
512
|
+
]);
|
|
513
|
+
connection.run('INSERT INTO replica_transfer_parts (locator, token, part) SELECT ?, ?, ? WHERE EXISTS (SELECT 1 FROM replica_transfers WHERE locator = ?)', [request.locator, request.token, request.part, request.locator]);
|
|
514
|
+
return null;
|
|
510
515
|
}
|
|
511
516
|
export function opened(connection) {
|
|
512
517
|
const facts = {};
|
|
@@ -558,4 +563,5 @@ export function ended(connection) {
|
|
|
558
563
|
if (table !== undefined)
|
|
559
564
|
connection.run(`DELETE FROM ${table}`);
|
|
560
565
|
}
|
|
566
|
+
unindexAll(connection);
|
|
561
567
|
}
|