@agentshouse/mdruntime 0.1.0-c5fe3b2cddda7 → 0.1.0-c6197367d5fad
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 +21 -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 +156 -89
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +3 -11
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +20 -60
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/bootstrap.d.ts +9 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +204 -85
- 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 +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/change.d.ts +5 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +7 -2
- 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 +33 -23
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +43 -56
- package/dist/collection.d.ts +26 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +19 -2
- 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 +8 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +286 -336
- package/dist/connection.d.ts +5 -142
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +111 -4993
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- 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 +72 -51
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1001 -926
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts +11 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +157 -0
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +20 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +2 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +18 -8
- 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 +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- 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 +21 -7
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +83 -41
- 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 +37 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -5
- 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 +9 -6
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +118 -36
- 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 +19 -2
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +105 -27
- package/dist/memory.d.ts +18 -6
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +214 -91
- package/dist/messages.d.ts +35 -5
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +109 -39
- package/dist/model.d.ts +2 -10
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -14
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +153 -0
- package/dist/observation.d.ts +28 -13
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +185 -81
- package/dist/opened.d.ts +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +5 -5
- 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 +17 -2
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +35 -2
- package/dist/overlay.d.ts +7 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +48 -24
- 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 +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +22 -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 +14 -210
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/questions.d.ts +30 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +116 -0
- 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 +16 -15
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +257 -148
- package/dist/react.d.ts +19 -3
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +9 -6
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +3 -5
- 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 +3 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +38 -8
- package/dist/refresh.d.ts +2 -1
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +31 -3
- 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 +11 -16
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +66 -32
- 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 +34 -10
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +331 -111
- 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 +16 -22
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +49 -186
- 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 +42 -86
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +332 -228
- 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 +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/shared.d.ts +1 -6
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -95
- package/dist/shown.d.ts +35 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +313 -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 +0 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -6
- 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 +224 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +466 -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 +115 -143
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +171 -364
- package/dist/stored.d.ts +72 -35
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +337 -197
- package/dist/surface.d.ts +92 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +251 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +538 -0
- package/dist/tables.d.ts +118 -67
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +199 -278
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +128 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +9 -12
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +72 -9
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +26 -5
- package/package.json +3 -2
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -370
- package/dist/log.d.ts +0 -5
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -156
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { plain } from '@agentshouse/mdmodel';
|
|
2
|
+
import { changeSet } from './change-set.js';
|
|
3
|
+
import { collectionOf } from './collection.js';
|
|
4
|
+
import { runtimeError, uncaught } from './failure.js';
|
|
5
|
+
import { roomDraftRevision } from './identity.js';
|
|
6
|
+
import { normalize } from './paths.js';
|
|
7
|
+
import { slicing } from './replica.js';
|
|
8
|
+
import { binaryBase, gatheredParts, held, heldFile, heldMarks, readParts, staleWrite, underneath, } from './room-draft.js';
|
|
9
|
+
import { stepped } from './turn.js';
|
|
10
|
+
const ROOM_DRAFTS = 'room-drafts';
|
|
11
|
+
const presentationTopic = (app) => `presentation\u0000${app}`;
|
|
12
|
+
export async function visibleOf(store, locator, paths) {
|
|
13
|
+
const kept = await store.record(locator);
|
|
14
|
+
if (kept === undefined)
|
|
15
|
+
return undefined;
|
|
16
|
+
const local = await store.open();
|
|
17
|
+
const slice = await stepped(slicing(await local.entries(kept.key, 'visible', paths), paths));
|
|
18
|
+
return { ...slice, collection: collectionOf(slice.documents, store.composed(kept)) };
|
|
19
|
+
}
|
|
20
|
+
function roomDraftOf(record, visible) {
|
|
21
|
+
return structuredClone({
|
|
22
|
+
room: record.locator,
|
|
23
|
+
path: record.path,
|
|
24
|
+
revision: record.revision,
|
|
25
|
+
parts: record.parts,
|
|
26
|
+
changedUnderneath: underneath(record.parts, record.path, visible),
|
|
27
|
+
marks: record.marks,
|
|
28
|
+
returned: record.returned,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async function roomDraftsOf(store, records) {
|
|
32
|
+
const rooms = new Map();
|
|
33
|
+
for (const record of records) {
|
|
34
|
+
const paths = rooms.get(record.locator) ?? [];
|
|
35
|
+
paths.push(record.path);
|
|
36
|
+
rooms.set(record.locator, paths);
|
|
37
|
+
}
|
|
38
|
+
const layers = new Map();
|
|
39
|
+
for (const [locator, paths] of rooms) {
|
|
40
|
+
layers.set(locator, await visibleOf(store, locator, paths));
|
|
41
|
+
}
|
|
42
|
+
return records.map((record) => roomDraftOf(record, layers.get(record.locator)));
|
|
43
|
+
}
|
|
44
|
+
function inOrder(records) {
|
|
45
|
+
return [...records].sort((left, right) => {
|
|
46
|
+
if (left.locator !== right.locator)
|
|
47
|
+
return left.locator < right.locator ? -1 : 1;
|
|
48
|
+
if (left.path !== right.path)
|
|
49
|
+
return left.path < right.path ? -1 : 1;
|
|
50
|
+
return 0;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async function snapshotRoomDrafts(store) {
|
|
54
|
+
return roomDraftsOf(store, inOrder(await store.drafts()));
|
|
55
|
+
}
|
|
56
|
+
export function publishRoomDrafts({ store, socket }, waitingOnly, touched = null) {
|
|
57
|
+
const unwatched = () => socket.closed() || store.watching(ROOM_DRAFTS).length === 0;
|
|
58
|
+
if (unwatched())
|
|
59
|
+
return Promise.resolve();
|
|
60
|
+
return store.publication(async () => {
|
|
61
|
+
if (unwatched())
|
|
62
|
+
return;
|
|
63
|
+
const records = await store.drafts();
|
|
64
|
+
if (socket.closed())
|
|
65
|
+
return;
|
|
66
|
+
if (touched !== null &&
|
|
67
|
+
!records.some((record) => touched.some(({ locator, path }) => locator === record.locator && (path === null || path === record.path)))) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const value = await roomDraftsOf(store, inOrder(records));
|
|
71
|
+
if (socket.closed())
|
|
72
|
+
return;
|
|
73
|
+
const answered = store.watching(ROOM_DRAFTS, waitingOnly ? 'waiting' : 'all');
|
|
74
|
+
for (const watcher of answered)
|
|
75
|
+
watcher.answer(value);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async function presentationOf(store, app) {
|
|
79
|
+
const value = await (await store.open()).presentation(app);
|
|
80
|
+
return value === undefined ? null : structuredClone(value);
|
|
81
|
+
}
|
|
82
|
+
export function emitPresentation({ store, socket }, app) {
|
|
83
|
+
const topic = presentationTopic(app);
|
|
84
|
+
const listening = () => store.watching(topic, 'ready');
|
|
85
|
+
if (socket.closed() || listening().length === 0)
|
|
86
|
+
return Promise.resolve();
|
|
87
|
+
return store.publication(async () => {
|
|
88
|
+
if (socket.closed() || listening().length === 0)
|
|
89
|
+
return;
|
|
90
|
+
const value = await presentationOf(store, app);
|
|
91
|
+
if (socket.closed())
|
|
92
|
+
return;
|
|
93
|
+
for (const watcher of listening())
|
|
94
|
+
watcher.answer(value);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async function writtenRoomDraft({ store }, room, path, revision, input, next) {
|
|
98
|
+
const parts = readParts(input, path);
|
|
99
|
+
if (path === '' || normalize(path) !== path)
|
|
100
|
+
throw runtimeError('room-draft-malformed', `room-draft-malformed at ${path}: a path inside the Room, such as notes/a.md`);
|
|
101
|
+
const local = await store.open();
|
|
102
|
+
const current = await store.draft(room, path);
|
|
103
|
+
if ((current?.revision ?? null) !== revision) {
|
|
104
|
+
return staleWrite(current === undefined ? null : (await roomDraftsOf(store, [current]))[0]);
|
|
105
|
+
}
|
|
106
|
+
const file = parts.file === undefined
|
|
107
|
+
? undefined
|
|
108
|
+
: await heldFile(parts.file.blob, parts.file.base === undefined
|
|
109
|
+
? binaryBase(await visibleOf(store, room, [path]), path)
|
|
110
|
+
: parts.file.base);
|
|
111
|
+
const kept = held(current?.parts, parts, file);
|
|
112
|
+
const record = {
|
|
113
|
+
locator: room,
|
|
114
|
+
path,
|
|
115
|
+
revision: next,
|
|
116
|
+
parts: kept,
|
|
117
|
+
marks: heldMarks(current?.marks ?? {}, kept),
|
|
118
|
+
returned: current?.returned ?? null,
|
|
119
|
+
};
|
|
120
|
+
await local.keepRoomDraft(record, parts.file === undefined || file === undefined
|
|
121
|
+
? []
|
|
122
|
+
: [{ key: file.localId, blob: parts.file.blob }]);
|
|
123
|
+
await store.changed(changeSet(room, { drafts: [path] }));
|
|
124
|
+
return { outcome: 'written', roomDraft: (await roomDraftsOf(store, [record]))[0] };
|
|
125
|
+
}
|
|
126
|
+
async function keptPresentation({ store }, app, value) {
|
|
127
|
+
await (await store.open()).present({ app, value });
|
|
128
|
+
await store.changed(changeSet('', { presentation: app }));
|
|
129
|
+
}
|
|
130
|
+
export function roomDraftSurface(runtime) {
|
|
131
|
+
const { store } = runtime;
|
|
132
|
+
return {
|
|
133
|
+
list() {
|
|
134
|
+
return store
|
|
135
|
+
.exclusive(async () => {
|
|
136
|
+
await store.open();
|
|
137
|
+
return snapshotRoomDrafts(store);
|
|
138
|
+
})
|
|
139
|
+
.then((listed) => {
|
|
140
|
+
publishRoomDrafts(runtime, true);
|
|
141
|
+
return listed;
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
async read(room, path) {
|
|
145
|
+
const record = await store.draft(room, path);
|
|
146
|
+
return record === undefined ? null : (await roomDraftsOf(store, [record]))[0];
|
|
147
|
+
},
|
|
148
|
+
write(room, path, revision, input, next = roomDraftRevision()) {
|
|
149
|
+
if (typeof next !== 'string' || next === '')
|
|
150
|
+
return Promise.reject(runtimeError('room-draft-malformed'));
|
|
151
|
+
return store.gathered(`room-draft\u0000${room}\u0000${path}`, { revision, input, next }, (earlier, later) => {
|
|
152
|
+
if (later.revision !== earlier.next)
|
|
153
|
+
return null;
|
|
154
|
+
const parts = gatheredParts(earlier.input, later.input);
|
|
155
|
+
return parts === null
|
|
156
|
+
? null
|
|
157
|
+
: { revision: earlier.revision, input: parts, next: later.next };
|
|
158
|
+
}, (written) => writtenRoomDraft(runtime, room, path, written.revision, written.input, written.next));
|
|
159
|
+
},
|
|
160
|
+
discard(room, path, revision) {
|
|
161
|
+
return store.exclusive(async () => {
|
|
162
|
+
const local = await store.open();
|
|
163
|
+
const current = await store.draft(room, path);
|
|
164
|
+
if (current === undefined || current.revision !== revision) {
|
|
165
|
+
return staleWrite(current === undefined ? null : (await roomDraftsOf(store, [current]))[0]);
|
|
166
|
+
}
|
|
167
|
+
await local.discardRoomDraft(room, path);
|
|
168
|
+
await store.changed(changeSet(room, { drafts: [path] }));
|
|
169
|
+
return { outcome: 'written', roomDraft: null };
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export function presentationSurface(runtime) {
|
|
175
|
+
const { store } = runtime;
|
|
176
|
+
return {
|
|
177
|
+
read(app) {
|
|
178
|
+
return store.exclusive(() => presentationOf(store, app));
|
|
179
|
+
},
|
|
180
|
+
write(app, value) {
|
|
181
|
+
return store.exclusive(() => keptPresentation(runtime, app, structuredClone(value)));
|
|
182
|
+
},
|
|
183
|
+
edit(app, members) {
|
|
184
|
+
return store.gathered(`presentation\u0000${app}`, structuredClone(members), (earlier, later) => ({ ...earlier, ...later }), async (edited) => {
|
|
185
|
+
const kept = await (await store.open()).presentation(app);
|
|
186
|
+
await keptPresentation(runtime, app, Object.fromEntries([
|
|
187
|
+
...Object.entries(plain(kept) ? kept : {}).filter(([member]) => !Object.hasOwn(edited, member)),
|
|
188
|
+
...Object.entries(edited).filter(([, value]) => value !== null),
|
|
189
|
+
]));
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
export function watchRoomDrafts({ store, socket }, deliver) {
|
|
195
|
+
const watcher = store.watch(ROOM_DRAFTS, deliver);
|
|
196
|
+
const unwatched = () => socket.closed() || !watcher.held();
|
|
197
|
+
void store
|
|
198
|
+
.exclusive(async () => {
|
|
199
|
+
await store.open();
|
|
200
|
+
})
|
|
201
|
+
.then(() => store.publication(async () => {
|
|
202
|
+
if (unwatched())
|
|
203
|
+
return;
|
|
204
|
+
const value = await snapshotRoomDrafts(store);
|
|
205
|
+
if (!unwatched())
|
|
206
|
+
watcher.answer(value);
|
|
207
|
+
}), uncaught);
|
|
208
|
+
return watcher.stop;
|
|
209
|
+
}
|
|
210
|
+
export function watchPresentation({ store, socket }, app, deliver) {
|
|
211
|
+
const watcher = store.watch(presentationTopic(app), deliver);
|
|
212
|
+
void store
|
|
213
|
+
.exclusive(async () => {
|
|
214
|
+
const value = await presentationOf(store, app);
|
|
215
|
+
if (!socket.closed() && watcher.held())
|
|
216
|
+
watcher.answer(value);
|
|
217
|
+
})
|
|
218
|
+
.catch(uncaught);
|
|
219
|
+
return watcher.stop;
|
|
220
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuthorityChange, RoomList } from './adapter.js';
|
|
2
|
+
import type { Runtime } from './runtime.js';
|
|
3
|
+
import type { Deliver } from './reach.js';
|
|
4
|
+
export declare const ROOM_LIST_TOPIC = "room-list";
|
|
5
|
+
type RoomListChange = NonNullable<AuthorityChange['roomList']>;
|
|
6
|
+
export declare function roomsListed(runtime: Runtime, list: RoomList | undefined): Promise<void>;
|
|
7
|
+
export declare function roomListChanged(runtime: Runtime, change: RoomListChange | undefined): Promise<void>;
|
|
8
|
+
export declare function watchRoomList(runtime: Runtime, deliver: Deliver): () => void;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=room-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room-list.d.ts","sourceRoot":"","sources":["../src/room-list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,eAAO,MAAM,eAAe,cAAc,CAAC;AAE3C,KAAK,cAAc,GAAG,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;AA0B/D,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvF;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,cAAc,GAAG,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC,CAGf;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,IAAI,CAU5E"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { uncaught } from './failure.js';
|
|
2
|
+
export const ROOM_LIST_TOPIC = 'room-list';
|
|
3
|
+
async function kept(runtime, next) {
|
|
4
|
+
const local = await runtime.store.open();
|
|
5
|
+
const { roomList } = await local.facts(['roomList']);
|
|
6
|
+
const listed = next(roomList);
|
|
7
|
+
if (listed === null || JSON.stringify(listed) === JSON.stringify(roomList))
|
|
8
|
+
return;
|
|
9
|
+
await local.fact('roomList', listed);
|
|
10
|
+
runtime.store.tell(ROOM_LIST_TOPIC, listed);
|
|
11
|
+
}
|
|
12
|
+
function changed(held, change) {
|
|
13
|
+
const named = new Map(change.rooms.map((room) => [room.room_ref, room]));
|
|
14
|
+
const left = new Set(change.left);
|
|
15
|
+
const known = new Set(held.rooms.map((room) => room.room_ref));
|
|
16
|
+
return {
|
|
17
|
+
rooms: [
|
|
18
|
+
...held.rooms.flatMap((room) => left.has(room.room_ref) ? [] : [named.get(room.room_ref) ?? room]),
|
|
19
|
+
...change.rooms.filter((room) => !known.has(room.room_ref)),
|
|
20
|
+
],
|
|
21
|
+
spaces: change.spaces,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function roomsListed(runtime, list) {
|
|
25
|
+
if (list === undefined)
|
|
26
|
+
return Promise.resolve();
|
|
27
|
+
return kept(runtime, () => list).catch(uncaught);
|
|
28
|
+
}
|
|
29
|
+
export function roomListChanged(runtime, change) {
|
|
30
|
+
if (change === undefined)
|
|
31
|
+
return Promise.resolve();
|
|
32
|
+
return kept(runtime, (held) => (held === null ? null : changed(held, change))).catch(uncaught);
|
|
33
|
+
}
|
|
34
|
+
export function watchRoomList(runtime, deliver) {
|
|
35
|
+
const { store } = runtime;
|
|
36
|
+
const watcher = store.watch(ROOM_LIST_TOPIC, deliver);
|
|
37
|
+
void store
|
|
38
|
+
.open()
|
|
39
|
+
.then((local) => local.facts(['roomList']))
|
|
40
|
+
.then(({ roomList }) => {
|
|
41
|
+
if (watcher.held())
|
|
42
|
+
deliver(roomList);
|
|
43
|
+
}, uncaught);
|
|
44
|
+
return watcher.stop;
|
|
45
|
+
}
|
package/dist/rows.d.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
+
import { type HeldValue } from '@agentshouse/mdmodel';
|
|
2
|
+
import type { SavedFacts } from './adapter.js';
|
|
1
3
|
import { type Composition } from './collection.js';
|
|
2
|
-
|
|
3
|
-
type
|
|
4
|
-
readonly keys: string;
|
|
5
|
-
readonly places: string;
|
|
6
|
-
readonly item: number;
|
|
7
|
-
readonly kind: ValueKind;
|
|
8
|
-
readonly value: string | number | null;
|
|
9
|
-
readonly size: number | null;
|
|
10
|
-
};
|
|
11
|
-
type LinkKind = 'field' | 'section' | 'body';
|
|
4
|
+
import type { PlanReach } from './query.js';
|
|
5
|
+
type LinkKind = 'field' | 'link';
|
|
12
6
|
type HeldLink = {
|
|
13
7
|
readonly kind: LinkKind;
|
|
14
8
|
readonly keys: string;
|
|
@@ -19,28 +13,28 @@ type HeldLink = {
|
|
|
19
13
|
export type Described = {
|
|
20
14
|
readonly type: string | null;
|
|
21
15
|
readonly declared: string | null;
|
|
22
|
-
readonly queried: boolean;
|
|
23
16
|
readonly folder: string;
|
|
24
17
|
readonly fields: string | null;
|
|
18
|
+
readonly links: string | null;
|
|
19
|
+
};
|
|
20
|
+
export type Held = {
|
|
21
|
+
readonly type: string | null;
|
|
22
|
+
readonly fields: Readonly<Record<string, unknown>> | null;
|
|
23
|
+
readonly links: readonly string[];
|
|
25
24
|
};
|
|
26
|
-
export type Derived =
|
|
25
|
+
export type Derived = {
|
|
27
26
|
readonly values: readonly HeldValue[];
|
|
28
27
|
readonly links: readonly HeldLink[];
|
|
29
28
|
};
|
|
30
29
|
export declare function documentKey(room: string, path: string): string;
|
|
31
30
|
export declare function roomOfKey(key: string): string;
|
|
31
|
+
export declare function roomsOfReach(reach: PlanReach): ReadonlySet<string>;
|
|
32
32
|
export declare function pathOfKey(key: string): string;
|
|
33
33
|
export declare function markdownPath(path: string): boolean;
|
|
34
34
|
export declare function folderOf(path: string): string;
|
|
35
|
-
export
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
readonly glob: boolean;
|
|
40
|
-
};
|
|
41
|
-
export declare function placedOf(pointer: string, reach: Reach): Placed;
|
|
42
|
-
export declare function kindOf(value: unknown): ValueKind;
|
|
43
|
-
export declare function described(path: string, content: string | null): Described;
|
|
44
|
-
export declare function derived(path: string, content: string | null, composition: Composition): Derived;
|
|
35
|
+
export declare function writtenFacts(path: string, content: string, composition: Composition): SavedFacts | null;
|
|
36
|
+
export declare function described(path: string, content: string | null, facts: SavedFacts | null): Described;
|
|
37
|
+
export declare function heldOf(path: string, content: string | null, facts: SavedFacts | null): Held;
|
|
38
|
+
export declare function derived(path: string, held: Held, composition: Composition): Derived;
|
|
45
39
|
export {};
|
|
46
40
|
//# sourceMappingURL=rows.d.ts.map
|
package/dist/rows.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows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,EAAE,SAAS,QAAQ,EAAE,CAAC;CACrC,CAAC;AAMF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAElE;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7C;AAaD,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW,GACvB,UAAU,GAAG,IAAI,CAQnB;AAED,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,KAAK,EAAE,UAAU,GAAG,IAAI,GACvB,SAAS,CAaX;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,GAAG,IAAI,CAK3F;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAYnF"}
|
package/dist/rows.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { governing } from './collection.js';
|
|
3
|
-
import { definitionOf } from './model.js';
|
|
1
|
+
import { byCodePoint, documentFacts, indexed, parse } from '@agentshouse/mdmodel';
|
|
2
|
+
import { definitionsAt, governing } from './collection.js';
|
|
4
3
|
function keyOf(...parts) {
|
|
5
4
|
return `${parts.join('\u0000')}\u0000`;
|
|
6
5
|
}
|
|
@@ -10,6 +9,9 @@ export function documentKey(room, path) {
|
|
|
10
9
|
export function roomOfKey(key) {
|
|
11
10
|
return key.split('\u0000')[1];
|
|
12
11
|
}
|
|
12
|
+
export function roomsOfReach(reach) {
|
|
13
|
+
return new Set([...reach.rooms, ...reach.documents.map(roomOfKey)]);
|
|
14
|
+
}
|
|
13
15
|
export function pathOfKey(key) {
|
|
14
16
|
return key.split('\u0000')[2];
|
|
15
17
|
}
|
|
@@ -19,196 +21,57 @@ export function markdownPath(path) {
|
|
|
19
21
|
export function folderOf(path) {
|
|
20
22
|
return path.slice(0, Math.max(path.lastIndexOf('/'), 0));
|
|
21
23
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const keys = [first];
|
|
25
|
-
const gaps = [[]];
|
|
26
|
-
for (const segment of rest) {
|
|
27
|
-
if (ARRAY_INDEX.test(segment)) {
|
|
28
|
-
gaps.at(-1).push(segment);
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
keys.push(segment);
|
|
32
|
-
gaps.push([]);
|
|
33
|
-
}
|
|
34
|
-
const places = gaps
|
|
35
|
-
.map((gap, at) => {
|
|
36
|
-
const open = at < gaps.length - 1 ? reach !== 'exact' : reach === 'link';
|
|
37
|
-
return `/${gap.map((number) => `[.:]${number}`).join('')}.${open ? '*' : ''}`;
|
|
38
|
-
})
|
|
39
|
-
.join('');
|
|
40
|
-
return {
|
|
41
|
-
keys: keys.map((key) => `/${key}`).join(''),
|
|
42
|
-
places,
|
|
43
|
-
glob: /[[*]/u.test(places),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function placesOf({ done, head, tail }) {
|
|
47
|
-
return `${done}/${head}${tail}.`;
|
|
48
|
-
}
|
|
49
|
-
function throughOf(keys, places) {
|
|
50
|
-
const gaps = places.split('/').slice(1);
|
|
51
|
-
return keys
|
|
52
|
-
.split('/')
|
|
53
|
-
.slice(1)
|
|
54
|
-
.map((key, at) => `/${key}${gaps[at].replace(/\.\d*/gu, '').replaceAll(':', '/')}`)
|
|
55
|
-
.join('');
|
|
56
|
-
}
|
|
57
|
-
function plainObject(value) {
|
|
58
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
59
|
-
}
|
|
60
|
-
function compared(reading, exact, value) {
|
|
61
|
-
if (!reading.references.has(exact))
|
|
24
|
+
function byKey(_key, value) {
|
|
25
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
62
26
|
return value;
|
|
63
|
-
return (
|
|
27
|
+
return Object.fromEntries(Object.entries(value).sort(([one], [other]) => byCodePoint(one, other)));
|
|
64
28
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return 'undefined';
|
|
68
|
-
if (value === null)
|
|
69
|
-
return 'null';
|
|
70
|
-
if (Array.isArray(value))
|
|
71
|
-
return 'array';
|
|
72
|
-
if (typeof value === 'object')
|
|
73
|
-
return 'object';
|
|
74
|
-
return typeof value;
|
|
75
|
-
}
|
|
76
|
-
function scalarOf(value) {
|
|
77
|
-
if (typeof value === 'string' || typeof value === 'number')
|
|
78
|
-
return value;
|
|
79
|
-
if (typeof value === 'boolean')
|
|
80
|
-
return value ? 1 : 0;
|
|
81
|
-
if (Array.isArray(value))
|
|
82
|
-
return JSON.stringify(value);
|
|
83
|
-
return null;
|
|
29
|
+
function fieldsText(fields) {
|
|
30
|
+
return JSON.stringify(fields, byKey);
|
|
84
31
|
}
|
|
85
|
-
function
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
item: -1,
|
|
90
|
-
kind: kindOf(value),
|
|
91
|
-
value: scalarOf(value),
|
|
92
|
-
size: Array.isArray(value) ? value.length : null,
|
|
32
|
+
export function writtenFacts(path, content, composition) {
|
|
33
|
+
const model = governing(composition, path);
|
|
34
|
+
const facts = documentFacts(path, parse(content, path, definitionsAt(composition, path)), {
|
|
35
|
+
types: model.status === 'unavailable' ? {} : model.types,
|
|
93
36
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const itemKind = kindOf(item);
|
|
98
|
-
reading.values.push({
|
|
99
|
-
keys,
|
|
100
|
-
places,
|
|
101
|
-
item: index,
|
|
102
|
-
kind: itemKind,
|
|
103
|
-
value: itemKind === 'array' ? null : scalarOf(item),
|
|
104
|
-
size: null,
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
function record(reading, node, at) {
|
|
109
|
-
const value = Array.isArray(node)
|
|
110
|
-
? node.map((item, index) => compared(reading, `${at.exact}/${index}`, item))
|
|
111
|
-
: compared(reading, at.exact, node);
|
|
112
|
-
const places = placesOf(at);
|
|
113
|
-
held(reading, at.keys, places, value);
|
|
114
|
-
if (typeof value !== 'string' || !reading.references.has(at.exact))
|
|
115
|
-
return;
|
|
116
|
-
reading.links.push({
|
|
117
|
-
kind: 'field',
|
|
118
|
-
keys: at.keys,
|
|
119
|
-
places,
|
|
120
|
-
target: value,
|
|
121
|
-
field: throughOf(at.keys, places),
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
function walk(reading, node, at) {
|
|
125
|
-
record(reading, node, at);
|
|
126
|
-
if (Array.isArray(node)) {
|
|
127
|
-
node.forEach((item, index) => walk(reading, item, { ...at, tail: `${at.tail}.${index}`, exact: `${at.exact}/${index}` }));
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
if (!plainObject(node))
|
|
131
|
-
return;
|
|
132
|
-
for (const [key, value] of Object.entries(node)) {
|
|
133
|
-
const segment = escapePointer(key);
|
|
134
|
-
const exact = `${at.exact}/${segment}`;
|
|
135
|
-
walk(reading, value, ARRAY_INDEX.test(segment)
|
|
136
|
-
? { ...at, head: `${at.head}${at.tail.replaceAll('.', ':')}:${segment}`, tail: '', exact }
|
|
137
|
-
: { keys: `${at.keys}/${segment}`, done: placesOf(at), head: '', tail: '', exact });
|
|
138
|
-
}
|
|
37
|
+
return facts === null
|
|
38
|
+
? null
|
|
39
|
+
: { ...facts, fields: JSON.parse(fieldsText(facts.fields)) };
|
|
139
40
|
}
|
|
140
|
-
function
|
|
141
|
-
const seen = new Set();
|
|
142
|
-
const found = [];
|
|
143
|
-
for (const { target: reached } of bodyLinks(bodyAfterFrontmatter(content), path)) {
|
|
144
|
-
if (seen.has(reached))
|
|
145
|
-
continue;
|
|
146
|
-
seen.add(reached);
|
|
147
|
-
found.push({ kind: 'body', keys: '', places: '', target: reached, field: '' });
|
|
148
|
-
}
|
|
149
|
-
return found;
|
|
150
|
-
}
|
|
151
|
-
function typedRows(path, content, document, composition) {
|
|
152
|
-
const definition = definitionOf(governing(composition, path), document.type);
|
|
153
|
-
const reading = {
|
|
154
|
-
path,
|
|
155
|
-
references: new Set(definition === undefined ? [] : references(document, definition).map((one) => one.pointer)),
|
|
156
|
-
values: [],
|
|
157
|
-
links: [],
|
|
158
|
-
};
|
|
159
|
-
for (const [name, value] of Object.entries(document.fields)) {
|
|
160
|
-
const segment = escapePointer(name);
|
|
161
|
-
walk(reading, value, {
|
|
162
|
-
keys: `/${segment}`,
|
|
163
|
-
done: '',
|
|
164
|
-
head: '',
|
|
165
|
-
tail: '',
|
|
166
|
-
exact: `/${segment}`,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
const links = reading.links;
|
|
170
|
-
if (definition !== undefined) {
|
|
171
|
-
const sectioned = new Set();
|
|
172
|
-
for (const { target: reached } of sectionReferences(path, content, definition)) {
|
|
173
|
-
if (reached === null || sectioned.has(reached))
|
|
174
|
-
continue;
|
|
175
|
-
sectioned.add(reached);
|
|
176
|
-
links.push({ kind: 'section', keys: '', places: '', target: reached, field: '' });
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return { values: reading.values, links: [...links, ...bodyTargets(path, content)] };
|
|
180
|
-
}
|
|
181
|
-
function read(path, content) {
|
|
41
|
+
export function described(path, content, facts) {
|
|
182
42
|
const folder = folderOf(path);
|
|
183
|
-
const unread = {
|
|
184
|
-
if (content === null)
|
|
185
|
-
return {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (!markdownPath(path) || !parsed.ok) {
|
|
190
|
-
return { described: { ...unread, declared, queried: !markdownPath(path) }, document: null };
|
|
191
|
-
}
|
|
192
|
-
const document = parsed.frontmatter;
|
|
43
|
+
const unread = { type: null, fields: null, links: null, folder };
|
|
44
|
+
if (content === null || facts === null)
|
|
45
|
+
return { ...unread, declared: null };
|
|
46
|
+
const links = JSON.stringify(facts.links);
|
|
47
|
+
if (!markdownPath(path))
|
|
48
|
+
return { ...unread, declared: facts.type, links };
|
|
193
49
|
return {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
fields: JSON.stringify(document.fields),
|
|
200
|
-
},
|
|
201
|
-
document,
|
|
50
|
+
type: facts.type,
|
|
51
|
+
declared: facts.type,
|
|
52
|
+
folder,
|
|
53
|
+
fields: fieldsText(facts.fields),
|
|
54
|
+
links,
|
|
202
55
|
};
|
|
203
56
|
}
|
|
204
|
-
export function
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
|
|
57
|
+
export function heldOf(path, content, facts) {
|
|
58
|
+
if (content === null || facts === null)
|
|
59
|
+
return { type: null, fields: null, links: [] };
|
|
60
|
+
return markdownPath(path)
|
|
61
|
+
? { type: facts.type, fields: facts.fields, links: facts.links }
|
|
62
|
+
: { type: null, fields: null, links: facts.links };
|
|
63
|
+
}
|
|
64
|
+
export function derived(path, held, composition) {
|
|
65
|
+
const stored = held.links.map((target) => ({
|
|
66
|
+
kind: 'link',
|
|
67
|
+
keys: '',
|
|
68
|
+
places: '',
|
|
69
|
+
target,
|
|
70
|
+
field: '',
|
|
71
|
+
}));
|
|
72
|
+
if (held.type === null || held.fields === null)
|
|
73
|
+
return { values: [], links: stored };
|
|
74
|
+
const definition = definitionsAt(composition, path)(held.type);
|
|
75
|
+
const { values, links: fields } = indexed(path, held.fields, definition);
|
|
76
|
+
return { values, links: [...fields, ...stored] };
|
|
214
77
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { RoomDeclaration, TypedPath } from './adapter.js';
|
|
2
|
+
import type { RuntimeShell } from './durability.js';
|
|
3
|
+
import type { LiveConversations } from './conversation-live.js';
|
|
4
|
+
import type { WriteRule } from './declaration.js';
|
|
5
|
+
import type { FiguresRead } from './figures.js';
|
|
6
|
+
import type { LiveQueries } from './live.js';
|
|
7
|
+
import type { ModelState } from './model.js';
|
|
8
|
+
import type { Presence } from './presence.js';
|
|
9
|
+
import type { ReadAnswers } from './reads.js';
|
|
10
|
+
import type { Recovery } from './recovery.js';
|
|
11
|
+
import type { Retries } from './retried.js';
|
|
12
|
+
import type { RuntimeSocket } from './socket.js';
|
|
13
|
+
import type { HeldCover, Store } from './store.js';
|
|
14
|
+
import type { schemaTypes } from './attached-model.js';
|
|
15
|
+
export type Runtime = {
|
|
16
|
+
readonly store: Store;
|
|
17
|
+
readonly socket: RuntimeSocket;
|
|
18
|
+
readonly presence: Presence;
|
|
19
|
+
readonly recovery: Recovery;
|
|
20
|
+
readonly retries: Retries;
|
|
21
|
+
readonly shell: RuntimeShell;
|
|
22
|
+
readonly localSaves: boolean;
|
|
23
|
+
readonly roomTypes: Parameters<typeof schemaTypes>[1];
|
|
24
|
+
readonly builtIn: ModelState;
|
|
25
|
+
readonly typedPaths: readonly TypedPath[];
|
|
26
|
+
readonly writeRule: (declaration: RoomDeclaration) => WriteRule;
|
|
27
|
+
readonly usableWhenHeld: readonly string[];
|
|
28
|
+
readonly build: string;
|
|
29
|
+
readonly conversations: LiveConversations;
|
|
30
|
+
readonly liveQueries: LiveQueries<HeldCover>;
|
|
31
|
+
readonly figures: FiguresRead;
|
|
32
|
+
readonly lastAnswers: ReadAnswers;
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@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