@agentshouse/mdruntime-adapter 0.1.0-cf6a7cf003c4b → 0.1.0-cfdb3a66f1a92

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/dist/links.js DELETED
@@ -1,104 +0,0 @@
1
- import { roomVersion } from './version.js';
2
- const ATTACHMENT_REFERENCE = /at_[1-9a-hjkmnp-tv-z][0-9a-hjkmnp-tv-z]*\.[0-9a-hjkmnp-tv-z]/g;
3
- const NONE = new Set();
4
- function linkedBy(text) {
5
- if (text === null)
6
- return NONE;
7
- const references = new Set(Array.from(text.matchAll(ATTACHMENT_REFERENCE), ([found]) => found));
8
- return references.size === 0 ? NONE : references;
9
- }
10
- function handedOf(attachments) {
11
- return new Map((attachments ?? []).map((attachment) => [attachment.reference, attachment]));
12
- }
13
- export function scopeLinks(scope) {
14
- return {
15
- roomVersion: roomVersion(scope),
16
- handed: handedOf(scope.attachments),
17
- paths: new Map(scope.contents.map(({ path, content }) => [path, linkedBy(content)])),
18
- revisions: new Map(scope.files.flatMap(({ path, revision }) => revision === undefined ? [] : [[path, revision]])),
19
- };
20
- }
21
- function revised(revisions, path, revision) {
22
- if (revision === undefined)
23
- revisions.delete(path);
24
- else
25
- revisions.set(path, revision);
26
- }
27
- export function heldLinks(held) {
28
- return {
29
- roomVersion: held.roomVersion,
30
- handed: handedOf(held.attachments),
31
- paths: new Map(Object.entries(held.documents).map(([path, text]) => [path, linkedBy(text)])),
32
- revisions: new Map(Object.entries(held.revisions)),
33
- };
34
- }
35
- export function acceptedLinks(held, accepted, roomVersion, originals) {
36
- const paths = new Map(held.paths);
37
- const revisions = new Map(held.revisions);
38
- const handed = new Map(held.handed);
39
- const answered = handedOf(originals);
40
- for (const [path, text] of Object.entries(accepted.documents)) {
41
- const linked = linkedBy(text);
42
- for (const reference of linked) {
43
- const original = answered.get(reference);
44
- if (!handed.has(reference) && original !== undefined)
45
- handed.set(reference, original);
46
- }
47
- paths.set(path, linked);
48
- }
49
- for (const [path, revision] of Object.entries(accepted.revisions))
50
- revisions.set(path, revision);
51
- for (const path of accepted.removals) {
52
- paths.delete(path);
53
- revisions.delete(path);
54
- }
55
- const linked = new Set([...paths.values()].flatMap((references) => [...references]));
56
- for (const reference of held.handed.keys()) {
57
- const before = [...held.paths.values()].some((references) => references.has(reference));
58
- if (before && !linked.has(reference))
59
- handed.delete(reference);
60
- }
61
- const links = { roomVersion, handed, paths, revisions };
62
- const changed = handed.size !== held.handed.size || [...handed.keys()].some((key) => !held.handed.has(key));
63
- return changed ? { links, attachments: [...handed.values()] } : { links };
64
- }
65
- export function enumeratedLinks(view, earlier) {
66
- const paths = new Map(earlier?.paths);
67
- const revisions = new Map(earlier?.revisions);
68
- for (const change of view.changes) {
69
- paths.set(change.path, linkedBy('content' in change ? change.content : null));
70
- revised(revisions, change.path, 'removed' in change
71
- ? undefined
72
- : 'reference' in change
73
- ? change.reference.revision
74
- : change.revision);
75
- }
76
- return { roomVersion: roomVersion(view), handed: handedOf(view.attachments), paths, revisions };
77
- }
78
- export function streamedLinks(held, advanced) {
79
- const paths = new Map(held.paths);
80
- const revisions = new Map(held.revisions);
81
- const dropped = new Set();
82
- for (const entry of advanced.entries) {
83
- revised(revisions, entry.path, entry.kind === 'removed' ? undefined : entry.revision);
84
- const text = entry.kind === 'removed' ? null : entry.text;
85
- if (text === undefined)
86
- return null;
87
- const linked = linkedBy(text);
88
- for (const reference of linked)
89
- if (!held.handed.has(reference))
90
- return null;
91
- for (const reference of paths.get(entry.path) ?? held.handed.keys()) {
92
- if (held.handed.has(reference) && !linked.has(reference))
93
- dropped.add(reference);
94
- }
95
- paths.set(entry.path, linked);
96
- }
97
- for (const references of paths.values()) {
98
- for (const reference of references)
99
- dropped.delete(reference);
100
- }
101
- if (dropped.size > 0)
102
- return null;
103
- return { roomVersion: advanced.page.roomVersion, handed: held.handed, paths, revisions };
104
- }