@agentshouse/mdruntime 0.1.0-cd50a4607cb7d → 0.1.0-cd574a610e9c8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -19
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +299 -0
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +26 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +302 -0
- package/dist/adapter.d.ts +226 -117
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +6 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +35 -41
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- 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 +31 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +309 -109
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/chain.d.ts +12 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +13 -16
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +17 -88
- package/dist/change.d.ts +36 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +17 -3
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +11 -0
- package/dist/client.d.ts +45 -25
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +132 -27
- package/dist/collection.d.ts +32 -21
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +53 -288
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +18 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +723 -0
- package/dist/connection.d.ts +7 -118
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +111 -2975
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/{chat/context.js → context.js} +2 -5
- package/dist/conversation-live.d.ts +150 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +259 -0
- package/dist/conversation-row.d.ts +40 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +66 -0
- package/dist/conversation.d.ts +85 -48
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1095 -688
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/discovery.d.ts +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +150 -0
- package/dist/durability.d.ts +23 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +9 -0
- package/dist/entry.d.ts +5 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +33 -28
- package/dist/expectation.d.ts +26 -13
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +72 -19
- package/dist/failure.d.ts +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +6 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +199 -0
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +8 -122
- package/dist/holdings.d.ts +29 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +95 -0
- package/dist/host.d.ts +27 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +177 -27
- package/dist/identity.d.ts +0 -2
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -6
- package/dist/index.d.ts +41 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -3
- package/dist/install.d.ts +60 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +537 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +282 -0
- package/dist/listing.d.ts +52 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +152 -0
- package/dist/live.d.ts +25 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +206 -0
- package/dist/loaded.d.ts +5 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +40 -0
- package/dist/locks.d.ts +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +32 -0
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +49 -0
- package/dist/media.d.ts +13 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +269 -0
- package/dist/memory.d.ts +25 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +320 -110
- package/dist/messages.d.ts +58 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +160 -0
- package/dist/model.d.ts +11 -13
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -24
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +153 -0
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +40 -10
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +233 -39
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +53 -0
- package/dist/outcome.d.ts +62 -9
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +72 -0
- package/dist/overlay.d.ts +9 -6
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +129 -166
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +4 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +13 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +26 -0
- package/dist/preparation.d.ts +41 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +314 -0
- package/dist/presence.d.ts +58 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +231 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +308 -0
- package/dist/query.d.ts +27 -186
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -464
- package/dist/{chat/questions.d.ts → questions.d.ts} +6 -7
- package/dist/questions.d.ts.map +1 -0
- package/dist/{chat/questions.js → questions.js} +12 -7
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +480 -0
- package/dist/reach.d.ts +20 -7
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +360 -98
- package/dist/react.d.ts +22 -5
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +40 -18
- package/dist/{chat/read.d.ts → read.d.ts} +2 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/{chat/read.js → read.js} +4 -0
- package/dist/readiness.d.ts +55 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +25 -0
- package/dist/reads.d.ts +39 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +178 -0
- package/dist/recovery.d.ts +5 -2
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +65 -8
- package/dist/refresh.d.ts +17 -14
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +145 -54
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +55 -0
- package/dist/replica.d.ts +50 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +340 -191
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +66 -12
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +416 -122
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +220 -0
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +45 -0
- package/dist/rows.d.ts +32 -29
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +60 -118
- package/dist/runtime.d.ts +34 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +43 -48
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +751 -303
- package/dist/saves.d.ts +34 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +437 -0
- package/dist/search.d.ts +15 -77
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -186
- package/dist/seed.d.ts +25 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +145 -0
- package/dist/shared.d.ts +6 -7
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +75 -104
- package/dist/shown.d.ts +33 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +309 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/lanes.d.ts +28 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +103 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket/session.d.ts +38 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +23 -0
- package/dist/socket.d.ts +67 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +164 -0
- package/dist/source.d.ts +59 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +93 -0
- package/dist/status.d.ts +4 -5
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -7
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +40 -0
- package/dist/store/readiness.d.ts +11 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +68 -0
- package/dist/store/records.d.ts +223 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +465 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- package/dist/store/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -0
- package/dist/store/space.d.ts +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +114 -141
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +163 -687
- package/dist/stored.d.ts +167 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +700 -0
- package/dist/surface.d.ts +90 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +225 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +536 -0
- package/dist/tables.d.ts +376 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +499 -0
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +128 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/turn.d.ts +5 -3
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +51 -21
- package/dist/validation.d.ts +29 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +98 -0
- package/dist/windows.d.ts +11 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +16 -0
- package/dist/wire.d.ts +230 -36
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +77 -33
- package/package.json +19 -19
- package/AGENTS.md +0 -296
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- 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/input.d.ts +0 -9
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -99
- package/dist/chat/kit.d.ts +0 -60
- 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 -26
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -62
- package/dist/chat/markdown.d.ts +0 -20
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -188
- package/dist/chat/message.d.ts +0 -6
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -192
- package/dist/chat/messages.d.ts +0 -21
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -151
- package/dist/chat/name.d.ts +0 -6
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -11
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -17
- package/dist/chat/overlay.d.ts +0 -31
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -97
- package/dist/chat/parts.d.ts +0 -57
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/parts.js +0 -119
- 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 -63
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -620
- package/dist/chat/question.d.ts +0 -9
- package/dist/chat/question.d.ts.map +0 -1
- package/dist/chat/question.js +0 -80
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat/ready.d.ts +0 -33
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -91
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -302
- package/dist/chat.d.ts +0 -14
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -8
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/log.d.ts +0 -5
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/read-side.d.ts +0 -25
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -639
package/dist/search.js
CHANGED
|
@@ -1,190 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { indexGeneration } from './identity.js';
|
|
3
|
-
import { invalid, known, limitOf, plain, } from './query.js';
|
|
4
|
-
import { inUnits, ROW_WEIGHT } from './turn.js';
|
|
5
|
-
const FIELDS = ['fields', 'sections', 'preamble', 'path', 'text'];
|
|
6
|
-
function documentId(room, path) {
|
|
7
|
-
return JSON.stringify(['document', room, path]);
|
|
8
|
-
}
|
|
9
|
-
function messageId(conversation, identity) {
|
|
10
|
-
return JSON.stringify(['message', conversation, identity]);
|
|
11
|
-
}
|
|
12
|
-
function scalars(value) {
|
|
13
|
-
if (value === null || value === undefined)
|
|
14
|
-
return [];
|
|
15
|
-
if (Array.isArray(value))
|
|
16
|
-
return value.flatMap(scalars);
|
|
17
|
-
if (typeof value === 'object')
|
|
18
|
-
return Object.values(value).flatMap(scalars);
|
|
19
|
-
return [String(value)];
|
|
20
|
-
}
|
|
1
|
+
import { invalid, known, plain } from '@agentshouse/mdmodel';
|
|
21
2
|
export function searchPlanOf(input) {
|
|
22
3
|
if (!plain(input))
|
|
23
4
|
invalid('search', 'expects a search object');
|
|
24
|
-
known(input, ['text', '
|
|
25
|
-
if (typeof input.text !== 'string')
|
|
26
|
-
invalid('text', 'expects
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
(!Array.isArray(
|
|
30
|
-
invalid('
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
text: input.text,
|
|
34
|
-
documents: input.documents,
|
|
35
|
-
conversations: conversations ?? null,
|
|
36
|
-
limit: limitOf(input.limit),
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export function createSearchIndex(source) {
|
|
40
|
-
const generation = indexGeneration();
|
|
41
|
-
const index = new MiniSearch({ fields: FIELDS });
|
|
42
|
-
const documents = new Map();
|
|
43
|
-
const messages = new Map();
|
|
44
|
-
const rooms = new Set();
|
|
45
|
-
const filling = new Set();
|
|
46
|
-
const conversations = new Set();
|
|
47
|
-
const acquiring = new Set();
|
|
48
|
-
const changedDocuments = new Map();
|
|
49
|
-
let changes = 0;
|
|
50
|
-
function addDocument(document) {
|
|
51
|
-
const id = documentId(document.room, document.path);
|
|
52
|
-
if (documents.has(id))
|
|
53
|
-
index.discard(id);
|
|
54
|
-
documents.set(id, { room: document.room, path: document.path, type: document.type });
|
|
55
|
-
index.add({
|
|
56
|
-
id,
|
|
57
|
-
fields: scalars(document.fields).join('\n'),
|
|
58
|
-
sections: Object.entries(document.sections)
|
|
59
|
-
.map(([heading, text]) => `${heading}\n${text}`)
|
|
60
|
-
.join('\n'),
|
|
61
|
-
preamble: document.preamble,
|
|
62
|
-
path: document.path,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
function addMessage(message) {
|
|
66
|
-
const id = messageId(message.conversation, message.identity);
|
|
67
|
-
if (messages.has(id))
|
|
68
|
-
index.discard(id);
|
|
69
|
-
messages.set(id, { conversation: message.conversation, identity: message.identity });
|
|
70
|
-
index.add({ id, text: message.text });
|
|
71
|
-
}
|
|
72
|
-
function discard(id, entries) {
|
|
73
|
-
if (entries.delete(id))
|
|
74
|
-
index.discard(id);
|
|
75
|
-
}
|
|
76
|
-
function* pending() {
|
|
77
|
-
for (;;) {
|
|
78
|
-
const next = changedDocuments.entries().next();
|
|
79
|
-
if (next.done === true)
|
|
80
|
-
return;
|
|
81
|
-
changedDocuments.delete(next.value[0]);
|
|
82
|
-
yield next.value;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
let catching = null;
|
|
86
|
-
function caughtUp() {
|
|
87
|
-
if (catching !== null)
|
|
88
|
-
return catching;
|
|
89
|
-
const running = inUnits(pending(), ([id, { room, path }]) => {
|
|
90
|
-
discard(id, documents);
|
|
91
|
-
const document = source.document(room, path);
|
|
92
|
-
if (document === null)
|
|
93
|
-
return ROW_WEIGHT;
|
|
94
|
-
addDocument(document);
|
|
95
|
-
return Object.values(document.sections).reduce((total, text) => total + text.length, ROW_WEIGHT + document.preamble.length);
|
|
96
|
-
});
|
|
97
|
-
if (!(running instanceof Promise))
|
|
98
|
-
return Promise.resolve();
|
|
99
|
-
catching = running.finally(() => {
|
|
100
|
-
catching = null;
|
|
101
|
-
});
|
|
102
|
-
return catching;
|
|
103
|
-
}
|
|
104
|
-
function ranked(text, entries, keep, limit) {
|
|
105
|
-
const found = index.search(text, {
|
|
106
|
-
filter: ({ id }) => {
|
|
107
|
-
const entry = entries.get(id);
|
|
108
|
-
return entry !== undefined && keep(entry, id);
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
return (limit === null ? found : found.slice(0, limit)).map(({ id, score, match }) => ({
|
|
112
|
-
...entries.get(id),
|
|
113
|
-
score,
|
|
114
|
-
match,
|
|
115
|
-
}));
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
generation: () => generation,
|
|
119
|
-
rooms: () => rooms,
|
|
120
|
-
conversations: () => conversations,
|
|
121
|
-
async indexRoom(room) {
|
|
122
|
-
if (rooms.has(room) || filling.has(room))
|
|
123
|
-
return;
|
|
124
|
-
filling.add(room);
|
|
125
|
-
try {
|
|
126
|
-
await inUnits(source.room(room), (path) => {
|
|
127
|
-
const document = filling.has(room) ? source.document(room, path) : null;
|
|
128
|
-
if (document === null)
|
|
129
|
-
return ROW_WEIGHT;
|
|
130
|
-
addDocument(document);
|
|
131
|
-
return Object.values(document.sections).reduce((total, text) => total + text.length, ROW_WEIGHT + document.preamble.length);
|
|
132
|
-
});
|
|
133
|
-
if (filling.has(room))
|
|
134
|
-
rooms.add(room);
|
|
135
|
-
}
|
|
136
|
-
finally {
|
|
137
|
-
filling.delete(room);
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
indexMessages(conversation, arriving, whole) {
|
|
141
|
-
for (const message of arriving)
|
|
142
|
-
addMessage(message);
|
|
143
|
-
if (!whole) {
|
|
144
|
-
acquiring.add(conversation);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
acquiring.delete(conversation);
|
|
148
|
-
conversations.add(conversation);
|
|
149
|
-
},
|
|
150
|
-
forget(leaving) {
|
|
151
|
-
const gone = new Set(leaving);
|
|
152
|
-
for (const [id, entry] of documents)
|
|
153
|
-
if (gone.has(entry.room))
|
|
154
|
-
discard(id, documents);
|
|
155
|
-
for (const room of leaving) {
|
|
156
|
-
rooms.delete(room);
|
|
157
|
-
filling.delete(room);
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
changed(set) {
|
|
161
|
-
changes += 1;
|
|
162
|
-
for (const { locator, path } of set.documents) {
|
|
163
|
-
if (rooms.has(locator) || filling.has(locator)) {
|
|
164
|
-
changedDocuments.set(documentId(locator, path), { room: locator, path });
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
for (const { conversation, identity, text } of set.messages) {
|
|
168
|
-
if (!conversations.has(conversation) && !acquiring.has(conversation))
|
|
169
|
-
continue;
|
|
170
|
-
const id = messageId(conversation, identity);
|
|
171
|
-
if (text === null)
|
|
172
|
-
discard(id, messages);
|
|
173
|
-
else
|
|
174
|
-
addMessage({ conversation, identity, text });
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
changes: () => changes,
|
|
178
|
-
caughtUp,
|
|
179
|
-
search({ text, limit }, selected, named) {
|
|
180
|
-
const chosen = selected === null
|
|
181
|
-
? null
|
|
182
|
-
: new Set(selected.map(({ room, path }) => documentId(room, path)));
|
|
183
|
-
const asked = new Set(named);
|
|
184
|
-
return {
|
|
185
|
-
documents: ranked(text, documents, (_entry, id) => chosen === null || chosen.has(id), limit).map(({ match, ...hit }) => ({ ...hit, matches: match })),
|
|
186
|
-
messages: ranked(text, messages, ({ conversation }) => asked.has(conversation), limit).map(({ match, ...hit }) => ({ ...hit, matches: match })),
|
|
187
|
-
};
|
|
188
|
-
},
|
|
189
|
-
};
|
|
5
|
+
known(input, ['text', 'rooms'], '');
|
|
6
|
+
if (typeof input.text !== 'string' || input.text.trim() === '')
|
|
7
|
+
invalid('text', 'expects words');
|
|
8
|
+
const rooms = input.rooms;
|
|
9
|
+
if (rooms !== undefined &&
|
|
10
|
+
(!Array.isArray(rooms) || rooms.some((named) => typeof named !== 'string'))) {
|
|
11
|
+
invalid('rooms', 'expects a list of Rooms');
|
|
12
|
+
}
|
|
13
|
+
return { text: input.text, rooms: rooms ?? null };
|
|
190
14
|
}
|
package/dist/seed.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Cover } from './live.js';
|
|
2
|
+
import { type KeyedResult } from './observation.js';
|
|
3
|
+
import type { Plan, QueryRows } from './query.js';
|
|
4
|
+
import type { Deliver } from './reach.js';
|
|
5
|
+
import type { Runtime } from './runtime.js';
|
|
6
|
+
import type { HeldCover, Store } from './store.js';
|
|
7
|
+
export type EntrySeed = {
|
|
8
|
+
readonly at: Readonly<Record<string, string>>;
|
|
9
|
+
readonly queries: readonly {
|
|
10
|
+
readonly query: unknown;
|
|
11
|
+
readonly rows: QueryRows;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
export type Seeded = {
|
|
15
|
+
readonly rows: QueryRows;
|
|
16
|
+
readonly at: Readonly<Record<string, string>>;
|
|
17
|
+
};
|
|
18
|
+
type SeededWatch = (coverOf: (cover: Cover, held: HeldCover) => Cover, deliver: (message: unknown) => void) => () => void;
|
|
19
|
+
export declare function entrySeedOf(value: unknown): EntrySeed | null;
|
|
20
|
+
export declare function seededResult(seed: Seeded): KeyedResult;
|
|
21
|
+
export declare function seedApplies(runtime: Runtime, plan: Plan, held: HeldCover): Seeded | null;
|
|
22
|
+
export declare function keepEntrySeed(store: Store, entry: EntrySeed): void;
|
|
23
|
+
export declare function watchSeeded(runtime: Runtime, plan: Plan, deliver: Deliver, watch: SeededWatch): () => void;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=seed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAwB,KAAK,WAAW,EAAqB,MAAM,kBAAkB,CAAC;AAC7F,OAAO,KAAK,EAAE,IAAI,EAA4C,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9C,QAAQ,CAAC,OAAO,EAAE,SAAS;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;KAAE,EAAE,CAAC;CACpF,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC;AAEjG,KAAK,WAAW,GAAG,CACjB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,KAAK,KAAK,EACjD,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAChC,MAAM,IAAI,CAAC;AA0ChB,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAe5D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAmBtD;AA+BD,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAOxF;AAYD,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAMlE;AAED,wBAAgB,WAAW,CACzB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,WAAW,GACjB,MAAM,IAAI,CA4BZ"}
|
package/dist/seed.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { queryKey } from '@agentshouse/mdmodel';
|
|
2
|
+
import { pendingChange, whole } from './observation.js';
|
|
3
|
+
import { documentKey } from './rows.js';
|
|
4
|
+
const seedTopic = (key) => `seed\u0000${key}`;
|
|
5
|
+
function plain(value) {
|
|
6
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function windowOf(value) {
|
|
9
|
+
const { next, total } = value;
|
|
10
|
+
if (next !== undefined && typeof next !== 'string')
|
|
11
|
+
return null;
|
|
12
|
+
if (total !== undefined && !Number.isSafeInteger(total))
|
|
13
|
+
return null;
|
|
14
|
+
return {
|
|
15
|
+
...(next === undefined ? {} : { next }),
|
|
16
|
+
...(total === undefined ? {} : { total: total }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function rowsOf(value) {
|
|
20
|
+
if (!plain(value))
|
|
21
|
+
return null;
|
|
22
|
+
const window = windowOf(value);
|
|
23
|
+
if (window === null)
|
|
24
|
+
return null;
|
|
25
|
+
if (Array.isArray(value.groups)) {
|
|
26
|
+
const groups = value.groups;
|
|
27
|
+
return groups.every((group) => plain(group) && Array.isArray(group.key) && typeof group.count === 'number')
|
|
28
|
+
? { groups: groups, ...window }
|
|
29
|
+
: null;
|
|
30
|
+
}
|
|
31
|
+
if (!Array.isArray(value.documents))
|
|
32
|
+
return null;
|
|
33
|
+
const documents = value.documents;
|
|
34
|
+
return documents.every((document) => plain(document) && typeof document.room === 'string' && typeof document.path === 'string')
|
|
35
|
+
? { documents: documents, ...window }
|
|
36
|
+
: null;
|
|
37
|
+
}
|
|
38
|
+
export function entrySeedOf(value) {
|
|
39
|
+
if (!plain(value) || !plain(value.at) || !Array.isArray(value.queries))
|
|
40
|
+
return null;
|
|
41
|
+
const at = {};
|
|
42
|
+
for (const [room, version] of Object.entries(value.at)) {
|
|
43
|
+
if (typeof version !== 'string')
|
|
44
|
+
return null;
|
|
45
|
+
at[room] = version;
|
|
46
|
+
}
|
|
47
|
+
const queries = [];
|
|
48
|
+
for (const entry of value.queries) {
|
|
49
|
+
if (!plain(entry) || !plain(entry.query))
|
|
50
|
+
return null;
|
|
51
|
+
const rows = rowsOf(entry.rows);
|
|
52
|
+
if (rows === null)
|
|
53
|
+
return null;
|
|
54
|
+
queries.push({ query: entry.query, rows });
|
|
55
|
+
}
|
|
56
|
+
return { at, queries };
|
|
57
|
+
}
|
|
58
|
+
export function seededResult(seed) {
|
|
59
|
+
const coverage = {
|
|
60
|
+
rooms: Object.entries(seed.at).map(([room, generation]) => ({
|
|
61
|
+
room,
|
|
62
|
+
generation,
|
|
63
|
+
current: false,
|
|
64
|
+
})),
|
|
65
|
+
overlay: [],
|
|
66
|
+
};
|
|
67
|
+
if ('groups' in seed.rows) {
|
|
68
|
+
return {
|
|
69
|
+
result: { ...seed.rows, coverage },
|
|
70
|
+
keys: seed.rows.groups.map((_group, index) => index),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
result: { ...seed.rows, coverage },
|
|
75
|
+
keys: seed.rows.documents.map((document) => documentKey(document.room, document.path)),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function seedRoomHeld({ socket }, room, version, held) {
|
|
79
|
+
const stored = held.rooms.get(room);
|
|
80
|
+
return (stored !== undefined &&
|
|
81
|
+
stored.indexed &&
|
|
82
|
+
socket.reads.reached(room, stored.roomVersion, version));
|
|
83
|
+
}
|
|
84
|
+
function seedHeld(runtime, at, held) {
|
|
85
|
+
const { socket, presence } = runtime;
|
|
86
|
+
return Object.entries(at).every(([room, version]) => (socket.session.now().roomsListed &&
|
|
87
|
+
presence.room(room) === undefined &&
|
|
88
|
+
!held.rooms.has(room)) ||
|
|
89
|
+
seedRoomHeld(runtime, room, version, held));
|
|
90
|
+
}
|
|
91
|
+
export function seedApplies(runtime, plan, held) {
|
|
92
|
+
const { seeds } = runtime.store;
|
|
93
|
+
const seed = seeds.of(plan.key);
|
|
94
|
+
if (seed === undefined)
|
|
95
|
+
return null;
|
|
96
|
+
if (!seedHeld(runtime, seed.at, held))
|
|
97
|
+
return seed;
|
|
98
|
+
seeds.drop(plan.key);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
function seedBehind(runtime, plan, cover, held) {
|
|
102
|
+
const seed = seedApplies(runtime, plan, held);
|
|
103
|
+
if (seed === null || 'pending' in cover)
|
|
104
|
+
return cover;
|
|
105
|
+
return {
|
|
106
|
+
pending: Object.entries(seed.at)
|
|
107
|
+
.filter(([room, version]) => !seedRoomHeld(runtime, room, version, held))
|
|
108
|
+
.map(([room]) => ({ room, awaits: 'acquisition' })),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export function keepEntrySeed(store, entry) {
|
|
112
|
+
for (const { query, rows } of entry.queries) {
|
|
113
|
+
const key = queryKey(query);
|
|
114
|
+
store.seeds.keep(key, { rows, at: entry.at });
|
|
115
|
+
for (const watcher of store.watching(seedTopic(key)))
|
|
116
|
+
watcher.answer(null);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export function watchSeeded(runtime, plan, deliver, watch) {
|
|
120
|
+
const { store } = runtime;
|
|
121
|
+
let seeded = false;
|
|
122
|
+
let pending = true;
|
|
123
|
+
const shown = () => {
|
|
124
|
+
const seed = store.seeds.of(plan.key);
|
|
125
|
+
if (seed === undefined || seeded || !pending)
|
|
126
|
+
return;
|
|
127
|
+
seeded = true;
|
|
128
|
+
deliver(seededResult(seed));
|
|
129
|
+
};
|
|
130
|
+
const watcher = store.watch(seedTopic(plan.key), shown);
|
|
131
|
+
const stop = watch((cover, held) => seedBehind(runtime, plan, cover, held), (message) => {
|
|
132
|
+
const answered = message;
|
|
133
|
+
pending = whole(answered) ? 'pending' in answered.result : pendingChange(answered);
|
|
134
|
+
if (pending && store.seeds.of(plan.key) !== undefined) {
|
|
135
|
+
shown();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
seeded = false;
|
|
139
|
+
deliver(message);
|
|
140
|
+
});
|
|
141
|
+
return () => {
|
|
142
|
+
watcher.stop();
|
|
143
|
+
stop();
|
|
144
|
+
};
|
|
145
|
+
}
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export type Paths<V> = Readonly<Record<string, V>>;
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function differing<V>(left: Paths<V>, right: Paths<V>, same?: (left: V, right: V) => boolean): ReadonlySet<string>;
|
|
2
|
+
export declare function guarding<V>(values: Paths<V>, handler: ProxyHandler<Paths<V>>): Paths<V>;
|
|
3
|
+
export declare function entriesIn<V>(map: Paths<V>): Generator<readonly [string, V]>;
|
|
4
|
+
export declare function sortedKeys(map: Paths<unknown>): Generator<number, readonly string[], void>;
|
|
5
|
+
export declare function sorting(keys: Iterable<string>): Generator<number, readonly string[], void>;
|
|
6
|
+
export declare function patching<V>(base: Paths<V>, set: Iterable<readonly [string, V]>, removed?: Iterable<string>): Generator<number, Paths<V>, void>;
|
|
8
7
|
export declare function drafted<V>(base: Paths<V>): Record<string, V>;
|
|
9
8
|
export declare function settled<V>(draft: Record<string, V>): Paths<V>;
|
|
10
|
-
export
|
|
9
|
+
export declare function settling<V>(draft: Record<string, V>): Generator<number, Paths<V>, void>;
|
|
11
10
|
//# sourceMappingURL=shared.d.ts.map
|
package/dist/shared.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AA8LnD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAIvF;AAED,wBAAiB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAQ5E;AAqCD,wBAAiB,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,CAAC,CAE3F;AAED,wBAAiB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,CAAC,CAoB3F;AAED,wBAAiB,QAAQ,CAAC,CAAC,EACzB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EACd,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EACnC,OAAO,GAAE,QAAQ,CAAC,MAAM,CAAM,GAC7B,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAgBnC;AAMD,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAiD5D;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAE7D;AAED,wBAAiB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAUxF"}
|
package/dist/shared.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { finished, ROW_WEIGHT } from './turn.js';
|
|
1
2
|
const BITS = 5;
|
|
2
3
|
const MASK = (1 << BITS) - 1;
|
|
3
4
|
const roots = new WeakMap();
|
|
4
|
-
const tallies = new WeakMap();
|
|
5
5
|
function hashOf(key) {
|
|
6
6
|
let hash = 0x811c9dc5;
|
|
7
7
|
for (let index = 0; index < key.length; index += 1) {
|
|
@@ -100,21 +100,15 @@ function lone(node) {
|
|
|
100
100
|
}
|
|
101
101
|
function taken(node, hash, key, shift) {
|
|
102
102
|
if (isLeaf(node))
|
|
103
|
-
return
|
|
103
|
+
return undefined;
|
|
104
104
|
if (isCollision(node)) {
|
|
105
105
|
const leaves = node.leaves.filter((leaf) => leaf.key !== key);
|
|
106
|
-
if (leaves.length === node.leaves.length)
|
|
107
|
-
return node;
|
|
108
106
|
return leaves.length === 1 ? leaves[0] : { hash: node.hash, leaves };
|
|
109
107
|
}
|
|
110
108
|
const bit = 1 << fragment(hash, shift);
|
|
111
|
-
if ((node.bitmap & bit) === 0)
|
|
112
|
-
return node;
|
|
113
109
|
const at = slot(node.bitmap, bit);
|
|
114
110
|
const child = node.children[at];
|
|
115
111
|
const next = taken(child, hash, key, shift + BITS);
|
|
116
|
-
if (next === child)
|
|
117
|
-
return node;
|
|
118
112
|
if (next === undefined) {
|
|
119
113
|
if (node.children.length === 1)
|
|
120
114
|
return undefined;
|
|
@@ -179,122 +173,95 @@ function facade(root) {
|
|
|
179
173
|
roots.set(map, root);
|
|
180
174
|
return map;
|
|
181
175
|
}
|
|
182
|
-
|
|
176
|
+
const guarded = new WeakMap();
|
|
177
|
+
export function guarding(values, handler) {
|
|
178
|
+
const map = new Proxy(values, handler);
|
|
179
|
+
guarded.set(map, values);
|
|
180
|
+
return map;
|
|
181
|
+
}
|
|
182
|
+
export function* entriesIn(map) {
|
|
183
|
+
const root = roots.get(map);
|
|
184
|
+
if (root === undefined) {
|
|
185
|
+
const values = guarded.get(map) ?? map;
|
|
186
|
+
for (const key of Object.keys(values))
|
|
187
|
+
yield [key, values[key]];
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
for (const leaf of leavesOf(root.node))
|
|
191
|
+
yield [leaf.key, leaf.value];
|
|
192
|
+
}
|
|
193
|
+
function* rooted(map) {
|
|
183
194
|
const held = roots.get(map);
|
|
184
195
|
if (held !== undefined)
|
|
185
196
|
return held;
|
|
186
197
|
let node;
|
|
187
|
-
|
|
188
|
-
for (const [key, value] of Object.entries(map)) {
|
|
198
|
+
for (const [key, value] of entriesIn(map)) {
|
|
189
199
|
node = put(node, { key, hash: hashOf(key), value }, 0);
|
|
190
|
-
|
|
200
|
+
yield ROW_WEIGHT;
|
|
191
201
|
}
|
|
192
|
-
return { node
|
|
202
|
+
return { node };
|
|
193
203
|
}
|
|
194
|
-
|
|
195
|
-
|
|
204
|
+
const RUN = 1 << 10;
|
|
205
|
+
function* merged(left, right) {
|
|
206
|
+
const into = [];
|
|
207
|
+
let at = 0;
|
|
208
|
+
let from = 0;
|
|
209
|
+
while (at < left.length || from < right.length) {
|
|
210
|
+
into.push(from === right.length || (at < left.length && left[at] < right[from])
|
|
211
|
+
? left[at++]
|
|
212
|
+
: right[from++]);
|
|
213
|
+
yield ROW_WEIGHT;
|
|
214
|
+
}
|
|
215
|
+
return into;
|
|
196
216
|
}
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
217
|
+
function* pathsOf(map) {
|
|
218
|
+
for (const [key] of entriesIn(map))
|
|
219
|
+
yield key;
|
|
220
|
+
}
|
|
221
|
+
export function* sortedKeys(map) {
|
|
222
|
+
return yield* sorting(pathsOf(map));
|
|
223
|
+
}
|
|
224
|
+
export function* sorting(keys) {
|
|
225
|
+
let runs = [];
|
|
226
|
+
let run = [];
|
|
227
|
+
for (const key of keys) {
|
|
228
|
+
run.push(key);
|
|
229
|
+
yield ROW_WEIGHT;
|
|
230
|
+
if (run.length === RUN) {
|
|
231
|
+
runs.push(run.sort());
|
|
232
|
+
run = [];
|
|
207
233
|
}
|
|
208
|
-
}
|
|
234
|
+
}
|
|
235
|
+
if (run.length > 0)
|
|
236
|
+
runs.push(run.sort());
|
|
237
|
+
while (runs.length > 1) {
|
|
238
|
+
const next = [];
|
|
239
|
+
for (let at = 0; at < runs.length; at += 2) {
|
|
240
|
+
next.push(at + 1 === runs.length ? runs[at] : yield* merged(runs[at], runs[at + 1]));
|
|
241
|
+
}
|
|
242
|
+
runs = next;
|
|
243
|
+
}
|
|
244
|
+
return runs[0] ?? [];
|
|
245
|
+
}
|
|
246
|
+
export function* patching(base, set, removed = []) {
|
|
247
|
+
const root = yield* rooted(base);
|
|
248
|
+
let node = root.node;
|
|
209
249
|
for (const key of removed) {
|
|
210
250
|
if (node === undefined)
|
|
211
251
|
break;
|
|
212
|
-
const before = lookup({ node
|
|
252
|
+
const before = lookup({ node }, key);
|
|
213
253
|
if (before === undefined)
|
|
214
254
|
continue;
|
|
215
255
|
node = taken(node, before.hash, key, 0);
|
|
216
|
-
|
|
217
|
-
shift(key, before, undefined);
|
|
256
|
+
yield ROW_WEIGHT;
|
|
218
257
|
}
|
|
219
258
|
for (const [key, value] of set) {
|
|
220
|
-
const before = lookup({ node, size }, key);
|
|
221
259
|
node = put(node, { key, hash: hashOf(key), value }, 0);
|
|
222
|
-
|
|
223
|
-
size += 1;
|
|
224
|
-
shift(key, before, value);
|
|
260
|
+
yield ROW_WEIGHT;
|
|
225
261
|
}
|
|
226
262
|
if (node === root.node && roots.has(base))
|
|
227
263
|
return base;
|
|
228
|
-
|
|
229
|
-
if (weighed.length > 0)
|
|
230
|
-
tallies.set(map, new Map(weighed));
|
|
231
|
-
return map;
|
|
232
|
-
}
|
|
233
|
-
export function tally(map, weigh) {
|
|
234
|
-
const held = tallies.get(map);
|
|
235
|
-
const known = held?.get(weigh);
|
|
236
|
-
if (known !== undefined)
|
|
237
|
-
return known;
|
|
238
|
-
let total = 0;
|
|
239
|
-
for (const [key, value] of Object.entries(map))
|
|
240
|
-
total += weigh(key, value);
|
|
241
|
-
if (roots.has(map)) {
|
|
242
|
-
const kept = held ?? new Map();
|
|
243
|
-
kept.set(weigh, total);
|
|
244
|
-
tallies.set(map, kept);
|
|
245
|
-
}
|
|
246
|
-
return total;
|
|
247
|
-
}
|
|
248
|
-
export function sizeOf(map) {
|
|
249
|
-
return roots.get(map)?.size ?? Object.keys(map).length;
|
|
250
|
-
}
|
|
251
|
-
function collect(node, into) {
|
|
252
|
-
for (const leaf of leavesOf(node))
|
|
253
|
-
into.add(leaf.key);
|
|
254
|
-
}
|
|
255
|
-
function compared(left, right, shift, same, into) {
|
|
256
|
-
if (left === right)
|
|
257
|
-
return;
|
|
258
|
-
if (left === undefined)
|
|
259
|
-
return collect(right, into);
|
|
260
|
-
if (right === undefined)
|
|
261
|
-
return collect(left, into);
|
|
262
|
-
if (!isLeaf(left) && !isCollision(left) && !isLeaf(right) && !isCollision(right)) {
|
|
263
|
-
const bits = left.bitmap | right.bitmap;
|
|
264
|
-
for (let remaining = bits; remaining !== 0; remaining &= remaining - 1) {
|
|
265
|
-
const bit = remaining & -remaining;
|
|
266
|
-
compared((left.bitmap & bit) === 0 ? undefined : left.children[slot(left.bitmap, bit)], (right.bitmap & bit) === 0 ? undefined : right.children[slot(right.bitmap, bit)], shift + BITS, same, into);
|
|
267
|
-
}
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
const before = new Map([...leavesOf(left)].map((leaf) => [leaf.key, leaf.value]));
|
|
271
|
-
for (const leaf of leavesOf(right)) {
|
|
272
|
-
const held = before.get(leaf.key);
|
|
273
|
-
before.delete(leaf.key);
|
|
274
|
-
if (held === undefined || !same(held, leaf.value))
|
|
275
|
-
into.add(leaf.key);
|
|
276
|
-
}
|
|
277
|
-
for (const key of before.keys())
|
|
278
|
-
into.add(key);
|
|
279
|
-
}
|
|
280
|
-
export function differing(left, right, same = Object.is) {
|
|
281
|
-
const into = new Set();
|
|
282
|
-
if (left === right)
|
|
283
|
-
return into;
|
|
284
|
-
const leftRoot = roots.get(left);
|
|
285
|
-
const rightRoot = roots.get(right);
|
|
286
|
-
if (leftRoot !== undefined && rightRoot !== undefined) {
|
|
287
|
-
compared(leftRoot.node, rightRoot.node, 0, same, into);
|
|
288
|
-
return into;
|
|
289
|
-
}
|
|
290
|
-
for (const key of Object.keys(left)) {
|
|
291
|
-
if (!Object.hasOwn(right, key) || !same(left[key], right[key]))
|
|
292
|
-
into.add(key);
|
|
293
|
-
}
|
|
294
|
-
for (const key of Object.keys(right))
|
|
295
|
-
if (!Object.hasOwn(left, key))
|
|
296
|
-
into.add(key);
|
|
297
|
-
return into;
|
|
264
|
+
return facade({ node });
|
|
298
265
|
}
|
|
299
266
|
const drafts = new WeakMap();
|
|
300
267
|
const GONE = Symbol('gone');
|
|
@@ -355,6 +322,9 @@ export function drafted(base) {
|
|
|
355
322
|
return draft;
|
|
356
323
|
}
|
|
357
324
|
export function settled(draft) {
|
|
325
|
+
return finished(settling(draft));
|
|
326
|
+
}
|
|
327
|
+
export function* settling(draft) {
|
|
358
328
|
const held = drafts.get(draft);
|
|
359
329
|
const set = [];
|
|
360
330
|
const removed = [];
|
|
@@ -363,6 +333,7 @@ export function settled(draft) {
|
|
|
363
333
|
removed.push(key);
|
|
364
334
|
else
|
|
365
335
|
set.push([key, value]);
|
|
336
|
+
yield ROW_WEIGHT;
|
|
366
337
|
}
|
|
367
|
-
return
|
|
338
|
+
return yield* patching(held.base, set, removed);
|
|
368
339
|
}
|
package/dist/shown.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Member } from './adapter.js';
|
|
2
|
+
import { type ChangeSet } from './change-set.js';
|
|
3
|
+
import type { QueueEntry } from './outcome.js';
|
|
4
|
+
import type { Runtime } from './runtime.js';
|
|
5
|
+
import type { Live, Moving } from './socket.js';
|
|
6
|
+
import { type CycleProgress } from './status.js';
|
|
7
|
+
export declare const ROOMS_TOPIC = "rooms";
|
|
8
|
+
export declare const STATUS_TOPIC = "sync-status";
|
|
9
|
+
export declare const REFUSAL_TOPIC = "connection-refusal";
|
|
10
|
+
export declare const STORAGE_LOSS_TOPIC = "storage-loss";
|
|
11
|
+
export declare const SERVICE_MODE_TOPIC = "service-mode";
|
|
12
|
+
export declare const MEMBER_TOPIC = "member";
|
|
13
|
+
export declare const AUTHORITY_TOPIC = "authority-changes";
|
|
14
|
+
export declare const LOCKS_TOPIC = "locks";
|
|
15
|
+
export declare const queueTopic: (locator: string) => string;
|
|
16
|
+
export declare function recoverReads({ liveQueries, figures }: Runtime, locators?: readonly string[]): void;
|
|
17
|
+
export declare function emitRooms(runtime: Runtime, changed?: readonly string[]): Promise<void>;
|
|
18
|
+
export declare function emitKnownRooms(runtime: Runtime): void;
|
|
19
|
+
export declare function emitRefusal(runtime: Runtime): void;
|
|
20
|
+
export declare function storageLossNow({ store }: Runtime): string | null;
|
|
21
|
+
export declare function emitStorageLoss(runtime: Runtime): void;
|
|
22
|
+
export declare function emitMember({ store }: Runtime, member: Member | null): void;
|
|
23
|
+
export declare function show(runtime: Runtime): Promise<void>;
|
|
24
|
+
export declare function moveTo(runtime: Runtime, next: Moving): Promise<void>;
|
|
25
|
+
export declare function statusShown(runtime: Runtime): Promise<void>;
|
|
26
|
+
export declare function transferring({ socket }: Runtime): Moving;
|
|
27
|
+
export declare function pendingShown(runtime: Runtime): Promise<void>;
|
|
28
|
+
export declare function entriesOf(runtime: Runtime, locator: string): Promise<readonly QueueEntry[]>;
|
|
29
|
+
export declare function publishChangeSet(runtime: Runtime, set: ChangeSet): Promise<void>;
|
|
30
|
+
export declare function submissionDue(runtime: Runtime, locators?: readonly string[]): Promise<void>;
|
|
31
|
+
export declare function roomUnreadable(runtime: Runtime, locator: string): void;
|
|
32
|
+
export declare function rest(runtime: Runtime, progress: CycleProgress | null, live?: Live): Promise<void>;
|
|
33
|
+
//# sourceMappingURL=shown.d.ts.map
|