@agentshouse/mdruntime 0.1.0-cefbc8bb8a1c0 → 0.1.0-cf08ada271a7f
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 +10 -10
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +309 -0
- package/dist/actions.d.ts +20 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +251 -0
- package/dist/adapter.d.ts +95 -104
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +3 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +21 -56
- package/dist/bootstrap.d.ts +11 -10
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +205 -88
- 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 +1 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +4 -2
- package/dist/chat-types.d.ts +5 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +13 -0
- package/dist/client.d.ts +24 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +9 -5
- package/dist/collection.d.ts +23 -7
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +13 -19
- package/dist/compile.d.ts +6 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +272 -334
- package/dist/connection.d.ts +5 -143
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +101 -5310
- 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 +135 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +247 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +53 -0
- package/dist/conversation.d.ts +41 -47
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +873 -912
- 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 +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +177 -0
- package/dist/durability.d.ts +15 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +2 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +17 -7
- package/dist/expectation.d.ts +4 -2
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +33 -11
- package/dist/failure.d.ts +1 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- 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 +20 -8
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +38 -33
- 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 +27 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/install.d.ts +55 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +543 -0
- package/dist/job.d.ts +5 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +7 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +271 -0
- package/dist/listing.d.ts +53 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +169 -0
- package/dist/live.d.ts +5 -4
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +64 -23
- package/dist/locks.d.ts +9 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +62 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +61 -0
- package/dist/media.d.ts +1 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +3 -3
- package/dist/memory.d.ts +14 -5
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +177 -85
- package/dist/messages.d.ts +24 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +89 -31
- package/dist/model.d.ts +2 -11
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -23
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +170 -0
- package/dist/observation.d.ts +2 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +14 -14
- package/dist/opened.js +3 -3
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +59 -0
- package/dist/outcome.d.ts +4 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +3 -0
- package/dist/overlay.d.ts +3 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +43 -21
- package/dist/parts.d.ts +11 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +21 -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 +20 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +233 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +272 -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 +34 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +122 -0
- package/dist/queue.d.ts +39 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +455 -0
- package/dist/reach.d.ts +15 -13
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +187 -140
- package/dist/react.d.ts +14 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +10 -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 +2 -16
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +4 -10
- package/dist/reads.d.ts +36 -10
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +160 -77
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +9 -1
- package/dist/refresh.d.ts +7 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +35 -7
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +57 -0
- package/dist/replica.d.ts +11 -17
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +64 -34
- package/dist/room-draft.d.ts +7 -8
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +100 -103
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +217 -0
- package/dist/rows.d.ts +14 -21
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +49 -186
- package/dist/runtime.d.ts +32 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +41 -86
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +239 -116
- package/dist/saves.d.ts +32 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +413 -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 -7
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -105
- package/dist/shown.d.ts +32 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +299 -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 +20 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +77 -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/rooms.d.ts +41 -0
- package/dist/socket/rooms.d.ts.map +1 -0
- package/dist/socket/rooms.js +90 -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 +69 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +175 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +82 -0
- package/dist/status.d.ts +0 -6
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -6
- package/dist/store/fences.d.ts +16 -0
- package/dist/store/fences.d.ts.map +1 -0
- package/dist/store/fences.js +26 -0
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +34 -0
- package/dist/store/readiness.d.ts +10 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +52 -0
- package/dist/store/records.d.ts +210 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +428 -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/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 +107 -157
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +143 -395
- package/dist/stored.d.ts +59 -38
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +279 -210
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +224 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +530 -0
- package/dist/tables.d.ts +116 -56
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +214 -98
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/validation.d.ts +3 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +42 -100
- 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 +21 -9
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +10 -4
- package/package.json +3 -2
- 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/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -156
package/dist/room-draft.js
CHANGED
|
@@ -1,60 +1,68 @@
|
|
|
1
|
-
import { apply, equalValue, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
|
|
1
|
+
import { apply, create, equalValue, frontmatterValue, parse, serialize, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { runtimeError } from './failure.js';
|
|
3
3
|
import { sha256 } from './digest.js';
|
|
4
4
|
import { binaryLocalId } from './identity.js';
|
|
5
5
|
import { normalize } from './paths.js';
|
|
6
|
-
export function returnedBy(
|
|
7
|
-
return { kind, code:
|
|
6
|
+
export function returnedBy() {
|
|
7
|
+
return { kind: 'withdrawn', code: 'withdrawn', fields: {}, retryable: false };
|
|
8
8
|
}
|
|
9
9
|
export function staleWrite(current) {
|
|
10
|
-
return { outcome: 'stale',
|
|
10
|
+
return { outcome: 'stale', current };
|
|
11
11
|
}
|
|
12
|
-
function malformed() {
|
|
13
|
-
throw runtimeError('room-draft-malformed');
|
|
12
|
+
function malformed(at, needs) {
|
|
13
|
+
throw runtimeError('room-draft-malformed', at === undefined ? 'room-draft-malformed' : `room-draft-malformed at ${at}: ${needs}`);
|
|
14
14
|
}
|
|
15
15
|
function plain(value) {
|
|
16
16
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
17
17
|
}
|
|
18
|
-
function text(value) {
|
|
19
|
-
return typeof value === 'string' ? value : malformed();
|
|
18
|
+
function text(value, at) {
|
|
19
|
+
return typeof value === 'string' ? value : malformed(at, 'text');
|
|
20
20
|
}
|
|
21
|
-
function optionalText(value) {
|
|
22
|
-
return value === undefined ? undefined : text(value);
|
|
21
|
+
function optionalText(value, at) {
|
|
22
|
+
return value === undefined ? undefined : text(value, at);
|
|
23
23
|
}
|
|
24
|
-
function markdownBase(value) {
|
|
25
|
-
return value === null ? null : optionalText(value);
|
|
24
|
+
function markdownBase(value, at) {
|
|
25
|
+
return value === null ? null : optionalText(value, at);
|
|
26
26
|
}
|
|
27
|
-
function entries(value, each) {
|
|
27
|
+
function entries(value, at, each) {
|
|
28
28
|
if (!plain(value))
|
|
29
|
-
malformed();
|
|
29
|
+
malformed(at, 'an object of named values');
|
|
30
30
|
const read = {};
|
|
31
31
|
for (const [name, item] of Object.entries(value))
|
|
32
|
-
read[name] = each(item);
|
|
32
|
+
read[name] = each(item, `${at}.${name}`);
|
|
33
33
|
return read;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function frontmatter(item, at) {
|
|
36
|
+
return frontmatterValue(item) ? item : malformed(at, 'a frontmatter value');
|
|
37
|
+
}
|
|
38
|
+
function fieldValue(value, at) {
|
|
36
39
|
if (value === null)
|
|
37
40
|
return null;
|
|
38
41
|
if (!plain(value) || !Object.hasOwn(value, 'value') || !frontmatterValue(value.value)) {
|
|
39
|
-
malformed();
|
|
42
|
+
malformed(at, '{ value } with a frontmatter value, or null where the document lacks it');
|
|
40
43
|
}
|
|
41
44
|
return { value: value.value };
|
|
42
45
|
}
|
|
43
|
-
function textPart(value) {
|
|
46
|
+
function textPart(value, at) {
|
|
44
47
|
if (!plain(value))
|
|
45
|
-
malformed();
|
|
46
|
-
const base = optionalText(value.base);
|
|
47
|
-
return { value: text(value.value), ...(base === undefined ? {} : { base }) };
|
|
48
|
+
malformed(at, '{ value, base }');
|
|
49
|
+
const base = optionalText(value.base, `${at}.base`);
|
|
50
|
+
return { value: text(value.value, `${at}.value`), ...(base === undefined ? {} : { base }) };
|
|
48
51
|
}
|
|
49
|
-
function creationOf(value) {
|
|
52
|
+
function creationOf(value, at) {
|
|
50
53
|
if (!plain(value))
|
|
51
|
-
malformed();
|
|
54
|
+
malformed(at, '{ type, fields, sections }, or { markdown }');
|
|
52
55
|
if (Object.hasOwn(value, 'markdown'))
|
|
53
|
-
return { markdown: text(value.markdown) };
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
return { markdown: text(value.markdown, `${at}.markdown`) };
|
|
57
|
+
if (typeof value.type !== 'string')
|
|
58
|
+
malformed(`${at}.type`, 'a type name, or markdown in place of type, fields and sections');
|
|
59
|
+
return {
|
|
60
|
+
type: value.type,
|
|
61
|
+
fields: entries(value.fields, `${at}.fields`, frontmatter),
|
|
62
|
+
sections: entries(value.sections, `${at}.sections`, text),
|
|
63
|
+
};
|
|
56
64
|
}
|
|
57
|
-
const PART_NAMES =
|
|
65
|
+
const PART_NAMES = [
|
|
58
66
|
'fields',
|
|
59
67
|
'sections',
|
|
60
68
|
'preamble',
|
|
@@ -63,52 +71,56 @@ const PART_NAMES = new Set([
|
|
|
63
71
|
'move',
|
|
64
72
|
'removal',
|
|
65
73
|
'file',
|
|
66
|
-
]
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
];
|
|
75
|
+
const NAMED_PARTS = `a part named ${PART_NAMES.slice(0, -1).join(', ')} or ${PART_NAMES.at(-1)}`;
|
|
76
|
+
export function readParts(value, path) {
|
|
77
|
+
if (!plain(value))
|
|
78
|
+
malformed(path, 'an object of parts');
|
|
79
|
+
const unknown = Object.keys(value).find((name) => !PART_NAMES.includes(name));
|
|
80
|
+
if (unknown !== undefined)
|
|
81
|
+
malformed(`${path} ${unknown}`, NAMED_PARTS);
|
|
70
82
|
const parts = {};
|
|
71
83
|
if (value.fields !== undefined) {
|
|
72
|
-
parts.fields = entries(value.fields, (item) => {
|
|
84
|
+
parts.fields = entries(value.fields, `${path} fields`, (item, at) => {
|
|
73
85
|
if (!plain(item) || !Object.hasOwn(item, 'value') || !frontmatterValue(item.value)) {
|
|
74
|
-
malformed();
|
|
86
|
+
malformed(at, '{ value, base } with a frontmatter value');
|
|
75
87
|
}
|
|
76
88
|
return item.base === undefined
|
|
77
89
|
? { value: item.value }
|
|
78
|
-
: { value: item.value, base: fieldValue(item.base) };
|
|
90
|
+
: { value: item.value, base: fieldValue(item.base, `${at}.base`) };
|
|
79
91
|
});
|
|
80
92
|
}
|
|
81
93
|
if (value.sections !== undefined)
|
|
82
|
-
parts.sections = entries(value.sections, textPart);
|
|
94
|
+
parts.sections = entries(value.sections, `${path} sections`, textPart);
|
|
83
95
|
if (value.preamble !== undefined)
|
|
84
|
-
parts.preamble = textPart(value.preamble);
|
|
96
|
+
parts.preamble = textPart(value.preamble, `${path} preamble`);
|
|
85
97
|
if (value.markdown !== undefined)
|
|
86
|
-
parts.markdown = textPart(value.markdown);
|
|
98
|
+
parts.markdown = textPart(value.markdown, `${path} markdown`);
|
|
87
99
|
if (value.creation !== undefined)
|
|
88
|
-
parts.creation = creationOf(value.creation);
|
|
100
|
+
parts.creation = creationOf(value.creation, `${path} creation`);
|
|
89
101
|
if (value.move !== undefined) {
|
|
90
102
|
if (!plain(value.move))
|
|
91
|
-
malformed();
|
|
92
|
-
const base = markdownBase(value.move.base);
|
|
93
|
-
const room = optionalText(value.move.room);
|
|
103
|
+
malformed(`${path} move`, '{ to, room, base }');
|
|
104
|
+
const base = markdownBase(value.move.base, `${path} move.base`);
|
|
105
|
+
const room = optionalText(value.move.room, `${path} move.room`);
|
|
94
106
|
parts.move = {
|
|
95
|
-
to: text(value.move.to),
|
|
107
|
+
to: text(value.move.to, `${path} move.to`),
|
|
96
108
|
...(room === undefined ? {} : { room }),
|
|
97
109
|
...(base === undefined ? {} : { base }),
|
|
98
110
|
};
|
|
99
111
|
}
|
|
100
112
|
if (value.removal !== undefined) {
|
|
101
113
|
if (!plain(value.removal))
|
|
102
|
-
malformed();
|
|
103
|
-
const base = markdownBase(value.removal.base);
|
|
114
|
+
malformed(`${path} removal`, '{ base }');
|
|
115
|
+
const base = markdownBase(value.removal.base, `${path} removal.base`);
|
|
104
116
|
parts.removal = base === undefined ? {} : { base };
|
|
105
117
|
}
|
|
106
118
|
if (value.file !== undefined) {
|
|
107
119
|
if (!plain(value.file) || !(value.file.blob instanceof Blob))
|
|
108
|
-
malformed();
|
|
120
|
+
malformed(`${path} file`, '{ blob, base } with a Blob');
|
|
109
121
|
if (Object.keys(value).length > 1)
|
|
110
122
|
throw runtimeError('room-draft-file-exclusive');
|
|
111
|
-
const base = markdownBase(value.file.base);
|
|
123
|
+
const base = markdownBase(value.file.base, `${path} file.base`);
|
|
112
124
|
parts.file = base === undefined ? { blob: value.file.blob } : { blob: value.file.blob, base };
|
|
113
125
|
}
|
|
114
126
|
return parts;
|
|
@@ -318,33 +330,46 @@ function joined(existing, returned) {
|
|
|
318
330
|
merged[name] = part;
|
|
319
331
|
return Object.keys(merged).length === 0 ? undefined : merged;
|
|
320
332
|
}
|
|
321
|
-
function
|
|
333
|
+
export function lineEnded(text) {
|
|
322
334
|
return text === '' || text.endsWith('\n') ? text : `${text}\n`;
|
|
323
335
|
}
|
|
324
|
-
function
|
|
325
|
-
const
|
|
326
|
-
if (!opened.ok)
|
|
327
|
-
return malformed();
|
|
328
|
-
const next = apply(opened.document, fields.map(([name, part]) => ({
|
|
329
|
-
kind: 'field',
|
|
330
|
-
name,
|
|
331
|
-
value: part.value,
|
|
332
|
-
prior: undefined,
|
|
333
|
-
})));
|
|
336
|
+
function written(start, changes, definition) {
|
|
337
|
+
const next = apply(start, changes, definition);
|
|
334
338
|
return next.outcome === 'applied' ? serialize(next.document) : malformed();
|
|
335
339
|
}
|
|
336
|
-
|
|
340
|
+
function empty(definition) {
|
|
341
|
+
const parsed = parse('', '', definition);
|
|
342
|
+
return parsed.ok ? parsed.document : malformed();
|
|
343
|
+
}
|
|
344
|
+
export function partsAfter(markdown, parts, definitions) {
|
|
337
345
|
const fields = named(parts.fields);
|
|
346
|
+
const sections = named(parts.sections);
|
|
347
|
+
if (fields.length === 0 && sections.length === 0 && parts.preamble === undefined)
|
|
348
|
+
return markdown;
|
|
349
|
+
const whole = parse(markdown, '', definitions);
|
|
350
|
+
const definition = whole.ok ? definitions?.(whole.document.type) : undefined;
|
|
351
|
+
const head = [
|
|
352
|
+
...fields.map(([name, part]) => ({
|
|
353
|
+
kind: 'field',
|
|
354
|
+
name,
|
|
355
|
+
value: part.value,
|
|
356
|
+
prior: undefined,
|
|
357
|
+
})),
|
|
358
|
+
...(parts.preamble === undefined
|
|
359
|
+
? []
|
|
360
|
+
: [{ kind: 'preamble', value: lineEnded(parts.preamble.value), prior: '' }]),
|
|
361
|
+
];
|
|
338
362
|
const pieces = [
|
|
339
|
-
...(
|
|
340
|
-
|
|
341
|
-
|
|
363
|
+
...(head.length === 0
|
|
364
|
+
? []
|
|
365
|
+
: [
|
|
366
|
+
written(fields.length === 0 ? empty(definition) : create(undefined, definition), head, definition),
|
|
367
|
+
]),
|
|
368
|
+
...sections.map(([name, part]) => written(empty(definition), [{ kind: 'section', name, value: lineEnded(part.value), prior: undefined }], definition)),
|
|
342
369
|
];
|
|
343
|
-
|
|
344
|
-
return markdown;
|
|
345
|
-
return `${ended(markdown)}\n${pieces.map(ended).join('')}`;
|
|
370
|
+
return `${lineEnded(markdown)}\n${pieces.join('')}`;
|
|
346
371
|
}
|
|
347
|
-
export function returnedInto(existing, returned) {
|
|
372
|
+
export function returnedInto(existing, returned, definitions) {
|
|
348
373
|
if (existing === undefined)
|
|
349
374
|
return returned;
|
|
350
375
|
const next = { ...existing };
|
|
@@ -364,7 +389,7 @@ export function returnedInto(existing, returned) {
|
|
|
364
389
|
delete next.fields;
|
|
365
390
|
delete next.sections;
|
|
366
391
|
delete next.preamble;
|
|
367
|
-
const value = partsAfter(whole.value, existing.markdown === undefined ? existing : returned);
|
|
392
|
+
const value = partsAfter(whole.value, existing.markdown === undefined ? existing : returned, definitions);
|
|
368
393
|
next.markdown = { value, base: whole.base };
|
|
369
394
|
}
|
|
370
395
|
const creation = existing.creation ?? returned.creation;
|
|
@@ -386,12 +411,13 @@ export function moveTarget(move) {
|
|
|
386
411
|
return to === null || to === '' ? move.to : to;
|
|
387
412
|
}
|
|
388
413
|
export function readSavedParts(named) {
|
|
389
|
-
const read = named.map(({ path, parts }) => ({ path, parts: readParts(parts) }));
|
|
390
|
-
|
|
391
|
-
normalize(path) !== path
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
414
|
+
const read = named.map(({ path, parts }) => ({ path, parts: readParts(parts, path) }));
|
|
415
|
+
read.forEach(({ path }, at) => {
|
|
416
|
+
if (path === '' || normalize(path) !== path)
|
|
417
|
+
malformed(path, 'a path inside the Room, such as notes/a.md');
|
|
418
|
+
if (read.findIndex((one) => one.path === path) !== at)
|
|
419
|
+
malformed(path, 'each path once in one save');
|
|
420
|
+
});
|
|
395
421
|
return read;
|
|
396
422
|
}
|
|
397
423
|
export function partsChanges(named) {
|
|
@@ -433,11 +459,11 @@ export function changesOf(path, parts) {
|
|
|
433
459
|
bases.push({ kind: 'field', path, name, value: part.base?.value });
|
|
434
460
|
}
|
|
435
461
|
for (const [name, part] of named(parts.sections)) {
|
|
436
|
-
changes.push({ kind: 'section', path, name, value: part.value });
|
|
462
|
+
changes.push({ kind: 'section', path, name, value: lineEnded(part.value) });
|
|
437
463
|
bases.push({ kind: 'section', path, name, value: part.base });
|
|
438
464
|
}
|
|
439
465
|
if (parts.preamble !== undefined) {
|
|
440
|
-
changes.push({ kind: 'preamble', path, value: parts.preamble.value });
|
|
466
|
+
changes.push({ kind: 'preamble', path, value: lineEnded(parts.preamble.value) });
|
|
441
467
|
bases.push({ kind: 'preamble', path, value: parts.preamble.base });
|
|
442
468
|
}
|
|
443
469
|
if (parts.markdown !== undefined) {
|
|
@@ -461,35 +487,6 @@ export function changesOf(path, parts) {
|
|
|
461
487
|
changes.push({ kind: 'remove', path });
|
|
462
488
|
return { changes, bases };
|
|
463
489
|
}
|
|
464
|
-
function rebased(before, after) {
|
|
465
|
-
return before === undefined ? after : { ...after, base: before.base };
|
|
466
|
-
}
|
|
467
|
-
function rebasedAll(before, after) {
|
|
468
|
-
return {
|
|
469
|
-
...before,
|
|
470
|
-
...Object.fromEntries(Object.entries(after).map(([name, part]) => [name, rebased(before?.[name], part)])),
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
export function joinedDraft(carried, saved) {
|
|
474
|
-
const draft = saved.find((item) => item.path === carried.path);
|
|
475
|
-
if (draft === undefined)
|
|
476
|
-
return carried;
|
|
477
|
-
const held = carried.parts;
|
|
478
|
-
const next = draft.parts;
|
|
479
|
-
return {
|
|
480
|
-
path: carried.path,
|
|
481
|
-
parts: {
|
|
482
|
-
...held,
|
|
483
|
-
...next,
|
|
484
|
-
...(next.fields === undefined ? {} : { fields: rebasedAll(held.fields, next.fields) }),
|
|
485
|
-
...(next.sections === undefined
|
|
486
|
-
? {}
|
|
487
|
-
: { sections: rebasedAll(held.sections, next.sections) }),
|
|
488
|
-
...(next.preamble === undefined ? {} : { preamble: rebased(held.preamble, next.preamble) }),
|
|
489
|
-
...(next.markdown === undefined ? {} : { markdown: rebased(held.markdown, next.markdown) }),
|
|
490
|
-
},
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
490
|
export function withdrawnDrafts(drafts, changes) {
|
|
494
491
|
return drafts.flatMap((draft) => {
|
|
495
492
|
const file = draft.parts.file;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ChangeSet } from './change-set.js';
|
|
2
|
+
import { type VisibleLayer } from './replica.js';
|
|
3
|
+
import { type RoomDraft, type RoomDraftWrite } from './room-draft.js';
|
|
4
|
+
import type { Runtime } from './runtime.js';
|
|
5
|
+
import type { Store } from './store.js';
|
|
6
|
+
export type RoomDraftSurface = {
|
|
7
|
+
list(): Promise<readonly RoomDraft[]>;
|
|
8
|
+
read(room: string, path: string): Promise<RoomDraft | null>;
|
|
9
|
+
write(room: string, path: string, revision: string | null, parts: unknown, next?: string): Promise<RoomDraftWrite>;
|
|
10
|
+
discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;
|
|
11
|
+
};
|
|
12
|
+
export type PresentationSurface = {
|
|
13
|
+
read(app: string): Promise<unknown>;
|
|
14
|
+
write(app: string, value: unknown): Promise<void>;
|
|
15
|
+
edit(app: string, members: Readonly<Record<string, unknown>>): Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
export declare function visibleOf(store: Store, locator: string, paths: readonly string[]): Promise<VisibleLayer | undefined>;
|
|
18
|
+
export declare function publishRoomDrafts({ store, socket }: Runtime, waitingOnly: boolean, touched?: ChangeSet['documents'] | null): Promise<void>;
|
|
19
|
+
export declare function emitPresentation({ store, socket }: Runtime, app: string): Promise<void>;
|
|
20
|
+
export declare function roomDraftSurface(runtime: Runtime): RoomDraftSurface;
|
|
21
|
+
export declare function presentationSurface(runtime: Runtime): PresentationSurface;
|
|
22
|
+
export declare function watchRoomDrafts({ store, socket }: Runtime, deliver: (value: unknown) => void): () => void;
|
|
23
|
+
export declare function watchPresentation({ store, socket }: Runtime, app: string, deliver: (value: unknown) => void): () => void;
|
|
24
|
+
//# sourceMappingURL=room-drafts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room-drafts.d.ts","sourceRoot":"","sources":["../src/room-drafts.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK5D,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAQL,KAAK,SAAS,EAEd,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,IAAI,OAAO,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;IACtC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAC5D,KAAK,CACH,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,KAAK,EAAE,OAAO,EACd,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3B,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAChF,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9E,CAAC;AAMF,wBAAsB,SAAS,CAC7B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,SAAS,MAAM,EAAE,GACvB,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAMnC;AA0CD,wBAAgB,iBAAiB,CAC/B,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAC1B,WAAW,EAAE,OAAO,EACpB,OAAO,GAAE,SAAS,CAAC,WAAW,CAAC,GAAG,IAAW,GAC5C,OAAO,CAAC,IAAI,CAAC,CAuBf;AAOD,wBAAgB,gBAAgB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUvF;AAoDD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAkDnE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,mBAAmB,CA8BzE;AAED,wBAAgB,eAAe,CAC7B,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAChC,MAAM,IAAI,CAiBZ;AAED,wBAAgB,iBAAiB,CAC/B,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAChC,MAAM,IAAI,CASZ"}
|
|
@@ -0,0 +1,217 @@
|
|
|
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, 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
|
+
returned: record.returned,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async function roomDraftsOf(store, records) {
|
|
31
|
+
const rooms = new Map();
|
|
32
|
+
for (const record of records) {
|
|
33
|
+
const paths = rooms.get(record.locator) ?? [];
|
|
34
|
+
paths.push(record.path);
|
|
35
|
+
rooms.set(record.locator, paths);
|
|
36
|
+
}
|
|
37
|
+
const layers = new Map();
|
|
38
|
+
for (const [locator, paths] of rooms) {
|
|
39
|
+
layers.set(locator, await visibleOf(store, locator, paths));
|
|
40
|
+
}
|
|
41
|
+
return records.map((record) => roomDraftOf(record, layers.get(record.locator)));
|
|
42
|
+
}
|
|
43
|
+
function inOrder(records) {
|
|
44
|
+
return [...records].sort((left, right) => {
|
|
45
|
+
if (left.locator !== right.locator)
|
|
46
|
+
return left.locator < right.locator ? -1 : 1;
|
|
47
|
+
if (left.path !== right.path)
|
|
48
|
+
return left.path < right.path ? -1 : 1;
|
|
49
|
+
return 0;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async function snapshotRoomDrafts(store) {
|
|
53
|
+
return roomDraftsOf(store, inOrder(await store.drafts()));
|
|
54
|
+
}
|
|
55
|
+
export function publishRoomDrafts({ store, socket }, waitingOnly, touched = null) {
|
|
56
|
+
const unwatched = () => socket.closed() || store.watching(ROOM_DRAFTS).length === 0;
|
|
57
|
+
if (unwatched())
|
|
58
|
+
return Promise.resolve();
|
|
59
|
+
return store.publication(async () => {
|
|
60
|
+
if (unwatched())
|
|
61
|
+
return;
|
|
62
|
+
const records = await store.drafts();
|
|
63
|
+
if (socket.closed())
|
|
64
|
+
return;
|
|
65
|
+
if (touched !== null &&
|
|
66
|
+
!records.some((record) => touched.some(({ locator, path }) => locator === record.locator && (path === null || path === record.path)))) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const value = await roomDraftsOf(store, inOrder(records));
|
|
70
|
+
if (socket.closed())
|
|
71
|
+
return;
|
|
72
|
+
const answered = store.watching(ROOM_DRAFTS, waitingOnly ? 'waiting' : 'all');
|
|
73
|
+
for (const watcher of answered)
|
|
74
|
+
watcher.answer(value);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async function presentationOf(store, app) {
|
|
78
|
+
const value = await (await store.open()).presentation(app);
|
|
79
|
+
return value === undefined ? null : structuredClone(value);
|
|
80
|
+
}
|
|
81
|
+
export function emitPresentation({ store, socket }, app) {
|
|
82
|
+
const topic = presentationTopic(app);
|
|
83
|
+
const listening = () => store.watching(topic, 'ready');
|
|
84
|
+
if (socket.closed() || listening().length === 0)
|
|
85
|
+
return Promise.resolve();
|
|
86
|
+
return store.publication(async () => {
|
|
87
|
+
if (socket.closed() || listening().length === 0)
|
|
88
|
+
return;
|
|
89
|
+
const value = await presentationOf(store, app);
|
|
90
|
+
if (socket.closed())
|
|
91
|
+
return;
|
|
92
|
+
for (const watcher of listening())
|
|
93
|
+
watcher.answer(value);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async function writtenRoomDraft({ store }, room, path, revision, input, next) {
|
|
97
|
+
const parts = readParts(input, path);
|
|
98
|
+
if (path === '' || normalize(path) !== path)
|
|
99
|
+
throw runtimeError('room-draft-malformed', `room-draft-malformed at ${path}: a path inside the Room, such as notes/a.md`);
|
|
100
|
+
const local = await store.open();
|
|
101
|
+
const current = await store.draft(room, path);
|
|
102
|
+
if ((current?.revision ?? null) !== revision) {
|
|
103
|
+
return staleWrite(current === undefined ? null : (await roomDraftsOf(store, [current]))[0]);
|
|
104
|
+
}
|
|
105
|
+
const file = parts.file === undefined
|
|
106
|
+
? undefined
|
|
107
|
+
: await heldFile(parts.file.blob, parts.file.base === undefined
|
|
108
|
+
? binaryBase(await visibleOf(store, room, [path]), path)
|
|
109
|
+
: parts.file.base);
|
|
110
|
+
const record = {
|
|
111
|
+
locator: room,
|
|
112
|
+
path,
|
|
113
|
+
revision: next,
|
|
114
|
+
parts: held(current?.parts, parts, file),
|
|
115
|
+
returned: current?.returned ?? null,
|
|
116
|
+
};
|
|
117
|
+
await local.keepRoomDraft(record, parts.file === undefined || file === undefined
|
|
118
|
+
? []
|
|
119
|
+
: [{ key: file.localId, blob: parts.file.blob }]);
|
|
120
|
+
await store.changed(changeSet(room, { drafts: [path] }));
|
|
121
|
+
return { outcome: 'written', roomDraft: (await roomDraftsOf(store, [record]))[0] };
|
|
122
|
+
}
|
|
123
|
+
async function keptPresentation({ store }, app, value) {
|
|
124
|
+
await (await store.open()).present({ app, value });
|
|
125
|
+
await store.changed(changeSet('', { presentation: app }));
|
|
126
|
+
}
|
|
127
|
+
export function roomDraftSurface(runtime) {
|
|
128
|
+
const { store } = runtime;
|
|
129
|
+
return {
|
|
130
|
+
list() {
|
|
131
|
+
return store
|
|
132
|
+
.exclusive(async () => {
|
|
133
|
+
await store.open();
|
|
134
|
+
return snapshotRoomDrafts(store);
|
|
135
|
+
})
|
|
136
|
+
.then((listed) => {
|
|
137
|
+
publishRoomDrafts(runtime, true);
|
|
138
|
+
return listed;
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
async read(room, path) {
|
|
142
|
+
const record = await store.draft(room, path);
|
|
143
|
+
return record === undefined ? null : (await roomDraftsOf(store, [record]))[0];
|
|
144
|
+
},
|
|
145
|
+
write(room, path, revision, input, next = roomDraftRevision()) {
|
|
146
|
+
if (typeof next !== 'string' || next === '')
|
|
147
|
+
return Promise.reject(runtimeError('room-draft-malformed'));
|
|
148
|
+
return store.gathered(`room-draft\u0000${room}\u0000${path}`, { revision, input, next }, (earlier, later) => {
|
|
149
|
+
if (later.revision !== earlier.next)
|
|
150
|
+
return null;
|
|
151
|
+
const parts = gatheredParts(earlier.input, later.input);
|
|
152
|
+
return parts === null
|
|
153
|
+
? null
|
|
154
|
+
: { revision: earlier.revision, input: parts, next: later.next };
|
|
155
|
+
}, (written) => writtenRoomDraft(runtime, room, path, written.revision, written.input, written.next));
|
|
156
|
+
},
|
|
157
|
+
discard(room, path, revision) {
|
|
158
|
+
return store.exclusive(async () => {
|
|
159
|
+
const local = await store.open();
|
|
160
|
+
const current = await store.draft(room, path);
|
|
161
|
+
if (current === undefined || current.revision !== revision) {
|
|
162
|
+
return staleWrite(current === undefined ? null : (await roomDraftsOf(store, [current]))[0]);
|
|
163
|
+
}
|
|
164
|
+
await local.discardRoomDraft(room, path);
|
|
165
|
+
await store.changed(changeSet(room, { drafts: [path] }));
|
|
166
|
+
return { outcome: 'written', roomDraft: null };
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
export function presentationSurface(runtime) {
|
|
172
|
+
const { store } = runtime;
|
|
173
|
+
return {
|
|
174
|
+
read(app) {
|
|
175
|
+
return store.exclusive(() => presentationOf(store, app));
|
|
176
|
+
},
|
|
177
|
+
write(app, value) {
|
|
178
|
+
return store.exclusive(() => keptPresentation(runtime, app, structuredClone(value)));
|
|
179
|
+
},
|
|
180
|
+
edit(app, members) {
|
|
181
|
+
return store.gathered(`presentation\u0000${app}`, structuredClone(members), (earlier, later) => ({ ...earlier, ...later }), async (edited) => {
|
|
182
|
+
const kept = await (await store.open()).presentation(app);
|
|
183
|
+
await keptPresentation(runtime, app, Object.fromEntries([
|
|
184
|
+
...Object.entries(plain(kept) ? kept : {}).filter(([member]) => !Object.hasOwn(edited, member)),
|
|
185
|
+
...Object.entries(edited).filter(([, value]) => value !== null),
|
|
186
|
+
]));
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export function watchRoomDrafts({ store, socket }, deliver) {
|
|
192
|
+
const watcher = store.watch(ROOM_DRAFTS, deliver);
|
|
193
|
+
const unwatched = () => socket.closed() || !watcher.held();
|
|
194
|
+
void store
|
|
195
|
+
.exclusive(async () => {
|
|
196
|
+
await store.open();
|
|
197
|
+
})
|
|
198
|
+
.then(() => store.publication(async () => {
|
|
199
|
+
if (unwatched())
|
|
200
|
+
return;
|
|
201
|
+
const value = await snapshotRoomDrafts(store);
|
|
202
|
+
if (!unwatched())
|
|
203
|
+
watcher.answer(value);
|
|
204
|
+
}), uncaught);
|
|
205
|
+
return watcher.stop;
|
|
206
|
+
}
|
|
207
|
+
export function watchPresentation({ store, socket }, app, deliver) {
|
|
208
|
+
const watcher = store.watch(presentationTopic(app), deliver);
|
|
209
|
+
void store
|
|
210
|
+
.exclusive(async () => {
|
|
211
|
+
const value = await presentationOf(store, app);
|
|
212
|
+
if (!socket.closed() && watcher.held())
|
|
213
|
+
watcher.answer(value);
|
|
214
|
+
})
|
|
215
|
+
.catch(uncaught);
|
|
216
|
+
return watcher.stop;
|
|
217
|
+
}
|
package/dist/rows.d.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
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 HeldValue = {
|
|
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
|
+
type LinkKind = 'field' | 'link';
|
|
12
5
|
type HeldLink = {
|
|
13
6
|
readonly kind: LinkKind;
|
|
14
7
|
readonly keys: string;
|
|
@@ -22,8 +15,14 @@ export type Described = {
|
|
|
22
15
|
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
|
};
|
|
@@ -32,15 +31,9 @@ export declare function roomOfKey(key: string): string;
|
|
|
32
31
|
export declare function pathOfKey(key: string): string;
|
|
33
32
|
export declare function markdownPath(path: string): boolean;
|
|
34
33
|
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;
|
|
34
|
+
export declare function writtenFacts(path: string, content: string, composition: Composition): SavedFacts | null;
|
|
35
|
+
export declare function described(path: string, content: string | null, facts: SavedFacts | null): Described;
|
|
36
|
+
export declare function heldOf(path: string, content: string | null, facts: SavedFacts | null): Held;
|
|
37
|
+
export declare function derived(path: string, held: Held, composition: Composition): Derived;
|
|
45
38
|
export {};
|
|
46
39
|
//# 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.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8C,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAClG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAA4B,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE7E,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjC,KAAK,QAAQ,GAAG;IACd,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAC1D,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IACtC,QAAQ,CAAC,KAAK,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,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,CAeX;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"}
|