@agentshouse/mdruntime 0.1.0-ca9afacd5aebd → 0.1.0-cac707d698ca2
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 +19 -16
- package/dist/adapter.d.ts +153 -57
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +7 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +40 -41
- package/dist/attempt.d.ts.map +1 -1
- package/dist/attempt.js +14 -1
- 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 +27 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +185 -81
- 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 +9 -14
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -63
- package/dist/change.d.ts +31 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +10 -1
- package/dist/client.d.ts +32 -16
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +100 -12
- package/dist/collection.d.ts +11 -7
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +38 -79
- package/dist/compile.d.ts +11 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +586 -0
- package/dist/connection.d.ts +47 -17
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +3601 -992
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/{chat/context.js → context.js} +1 -4
- package/dist/conversation.d.ts +39 -17
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +691 -259
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/durability.d.ts +10 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +20 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +160 -0
- package/dist/fence.d.ts +6 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +10 -0
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- package/dist/host.d.ts +11 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +126 -19
- package/dist/index.d.ts +20 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/job.d.ts +14 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +28 -0
- package/dist/live.d.ts +23 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +127 -0
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +18 -5
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +245 -94
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +89 -0
- package/dist/model.d.ts +11 -9
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +8 -5
- 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 +22 -4
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +120 -14
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/outcome.d.ts +49 -7
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +40 -0
- package/dist/overlay.d.ts +3 -4
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +100 -182
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -0
- package/dist/query.d.ts +40 -183
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -464
- package/dist/reach.d.ts +18 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +223 -80
- package/dist/react.d.ts +10 -6
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +7 -17
- package/dist/readiness.d.ts +50 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +27 -0
- package/dist/recovery.d.ts +26 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +224 -0
- package/dist/refresh.d.ts +17 -14
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +139 -51
- package/dist/replica.d.ts +58 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +315 -165
- package/dist/room-draft.d.ts +37 -6
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +161 -74
- package/dist/rows.d.ts +30 -37
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +59 -126
- package/dist/save.d.ts +52 -9
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +539 -171
- package/dist/search.d.ts +15 -55
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -121
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +75 -0
- package/dist/shared.d.ts +15 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +421 -0
- package/dist/status.d.ts +5 -0
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -1
- package/dist/store.d.ts +100 -76
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +309 -443
- package/dist/stored.d.ts +129 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +506 -0
- package/dist/tables.d.ts +327 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +587 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/turn.d.ts +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +75 -0
- package/dist/validation.d.ts +29 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +104 -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 +173 -32
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +58 -31
- package/package.json +27 -24
- package/AGENTS.md +0 -318
- package/dist/chat/acts.d.ts +0 -34
- 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 -20
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -59
- package/dist/chat/markdown.d.ts +0 -19
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -187
- 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 -645
- 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 +0 -31
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/questions.js +0 -111
- package/dist/chat/read.d.ts +0 -5
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat/read.js +0 -13
- package/dist/chat/ready.d.ts +0 -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/read-side.d.ts +0 -18
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -440
package/dist/replica.js
CHANGED
|
@@ -1,185 +1,209 @@
|
|
|
1
1
|
import { equalValue, parse } from '@agentshouse/mdmodel';
|
|
2
2
|
import { immutable, landing } from './change.js';
|
|
3
|
-
import { collectionOf
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
3
|
+
import { collectionOf } from './collection.js';
|
|
4
|
+
import { storedModel } from './model.js';
|
|
5
|
+
import { acceptedBinaries, overlaying } from './overlay.js';
|
|
6
|
+
import { writtenFacts } from './rows.js';
|
|
7
|
+
import { effectiveIn, rewriting } from './save.js';
|
|
8
|
+
import { ROW_WEIGHT } from './turn.js';
|
|
9
|
+
export function compositionOf(record, builtIn, typedPaths) {
|
|
7
10
|
return {
|
|
8
11
|
model: record.model,
|
|
9
12
|
selection: record.typedSelection === null
|
|
10
13
|
? null
|
|
11
|
-
: { roots: record.typedSelection.roots, model:
|
|
14
|
+
: { roots: record.typedSelection.roots, model: builtIn },
|
|
15
|
+
typedPaths,
|
|
12
16
|
};
|
|
13
17
|
}
|
|
14
|
-
export function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
collection: collectionOf(record.documents, compositionOf(record), previous?.collection),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export function sameMembership(record, other) {
|
|
21
|
-
return (JSON.stringify(record.typedSelection?.roots ?? null) ===
|
|
22
|
-
JSON.stringify(other.typedSelection?.roots ?? null));
|
|
18
|
+
export function storedRecord(record) {
|
|
19
|
+
const { key: _key, ...stored } = record;
|
|
20
|
+
return JSON.stringify({ ...stored, model: storedModel(stored.model) });
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
if (verdict.verdict === 'refuse') {
|
|
36
|
-
const refused = unreadable(record.documents, previous?.record.documents);
|
|
37
|
-
if (refused !== null)
|
|
38
|
-
return refused;
|
|
39
|
-
}
|
|
22
|
+
const PROBES = new Set([
|
|
23
|
+
'then',
|
|
24
|
+
'toJSON',
|
|
25
|
+
'constructor',
|
|
26
|
+
'valueOf',
|
|
27
|
+
'toString',
|
|
28
|
+
]);
|
|
29
|
+
class UnreadPath extends Error {
|
|
30
|
+
constructor(path) {
|
|
31
|
+
super(`the replica slice holds no row for ${path}`);
|
|
40
32
|
}
|
|
41
|
-
else if (textChanged) {
|
|
42
|
-
const refused = unreadable(record.documents, previous?.record.documents);
|
|
43
|
-
if (refused !== null)
|
|
44
|
-
return refused;
|
|
45
|
-
}
|
|
46
|
-
return { kind: 'staged', confirmed: confirmedOf(record, previous) };
|
|
47
33
|
}
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
34
|
+
function strict(values, held) {
|
|
35
|
+
const guard = (property) => {
|
|
36
|
+
if (typeof property === 'string' && !held.has(property) && !PROBES.has(property)) {
|
|
37
|
+
throw new UnreadPath(property);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return new Proxy(values, {
|
|
41
|
+
get(target, property, receiver) {
|
|
42
|
+
guard(property);
|
|
43
|
+
return Reflect.get(target, property, receiver);
|
|
44
|
+
},
|
|
45
|
+
has(target, property) {
|
|
46
|
+
guard(property);
|
|
47
|
+
return Reflect.has(target, property);
|
|
48
|
+
},
|
|
49
|
+
getOwnPropertyDescriptor(target, property) {
|
|
50
|
+
guard(property);
|
|
51
|
+
return Reflect.getOwnPropertyDescriptor(target, property);
|
|
52
|
+
},
|
|
53
|
+
});
|
|
55
54
|
}
|
|
56
|
-
function
|
|
57
|
-
const
|
|
58
|
-
for (const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
export function* slicing(entries, paths) {
|
|
56
|
+
const held = new Set(paths);
|
|
57
|
+
for (const entry of entries)
|
|
58
|
+
held.add(entry.path);
|
|
59
|
+
const documents = {};
|
|
60
|
+
const binaries = {};
|
|
61
|
+
const revisions = {};
|
|
62
|
+
const fileIds = {};
|
|
63
|
+
const changes = {};
|
|
64
|
+
const written = {};
|
|
65
|
+
const facts = {};
|
|
66
|
+
for (const entry of entries) {
|
|
67
|
+
if (entry.facts !== null)
|
|
68
|
+
facts[entry.path] = entry.facts;
|
|
69
|
+
if (entry.binary !== null)
|
|
70
|
+
binaries[entry.path] = entry.binary;
|
|
71
|
+
else if (entry.content !== null)
|
|
72
|
+
documents[entry.path] = entry.content;
|
|
73
|
+
if (entry.revision !== null)
|
|
74
|
+
revisions[entry.path] = entry.revision;
|
|
75
|
+
if (entry.fileId !== null)
|
|
76
|
+
fileIds[entry.path] = entry.fileId;
|
|
77
|
+
if (entry.change !== null)
|
|
78
|
+
changes[entry.path] = entry.change;
|
|
79
|
+
if (entry.written !== null)
|
|
80
|
+
written[entry.path] = entry.written;
|
|
81
|
+
yield ROW_WEIGHT;
|
|
66
82
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
for (const path of accepted.removals)
|
|
80
|
-
delete binaries[path];
|
|
81
|
-
return binaries;
|
|
83
|
+
return {
|
|
84
|
+
documents: strict(documents, held),
|
|
85
|
+
binaries: strict(binaries, held),
|
|
86
|
+
revisions: strict(revisions, held),
|
|
87
|
+
fileIds: strict(fileIds, held),
|
|
88
|
+
changes: strict(changes, held),
|
|
89
|
+
written: strict(written, held),
|
|
90
|
+
facts: strict(facts, held),
|
|
91
|
+
held,
|
|
92
|
+
};
|
|
82
93
|
}
|
|
83
|
-
export function
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
export function entryAt(layer, path) {
|
|
95
|
+
const content = layer.documents[path];
|
|
96
|
+
const binary = layer.binaries[path];
|
|
97
|
+
if (content === undefined && binary === undefined)
|
|
98
|
+
return null;
|
|
99
|
+
return {
|
|
100
|
+
path,
|
|
101
|
+
content: content ?? null,
|
|
102
|
+
binary: binary ?? null,
|
|
103
|
+
revision: layer.revisions[path] ?? null,
|
|
104
|
+
fileId: layer.fileIds[path] ?? null,
|
|
105
|
+
change: layer.changes[path] ?? null,
|
|
106
|
+
written: layer.written?.[path] ?? null,
|
|
91
107
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
108
|
+
}
|
|
109
|
+
export function* slicingWith(slice, set, removed) {
|
|
110
|
+
const entries = new Map();
|
|
111
|
+
for (const path of slice.held) {
|
|
112
|
+
const entry = entryAt(slice, path);
|
|
113
|
+
if (entry !== null) {
|
|
114
|
+
entries.set(path, { ...entry, type: null, facts: slice.facts[path] ?? null });
|
|
115
|
+
}
|
|
116
|
+
yield ROW_WEIGHT;
|
|
95
117
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
118
|
+
for (const path of removed)
|
|
119
|
+
entries.delete(path);
|
|
120
|
+
for (const entry of set)
|
|
121
|
+
entries.set(entry.path, { ...entry, type: null });
|
|
122
|
+
return yield* slicing([...entries.values()], [...slice.held, ...set.map(({ path }) => path), ...removed]);
|
|
123
|
+
}
|
|
124
|
+
function changePaths(change) {
|
|
125
|
+
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
126
|
+
}
|
|
127
|
+
export function touchedBy(queue) {
|
|
128
|
+
const paths = new Set();
|
|
129
|
+
for (const batch of queue) {
|
|
130
|
+
for (const change of batch.changes)
|
|
131
|
+
for (const path of changePaths(change))
|
|
132
|
+
paths.add(path);
|
|
133
|
+
for (const precondition of batch.preconditions)
|
|
134
|
+
paths.add(precondition.path);
|
|
135
|
+
for (const move of batch.between?.moves ?? [])
|
|
136
|
+
paths.add(move.path);
|
|
102
137
|
}
|
|
103
|
-
return
|
|
104
|
-
...confirmed.record,
|
|
105
|
-
roomVersion,
|
|
106
|
-
documents: nextDocuments,
|
|
107
|
-
revisions: nextRevisions,
|
|
108
|
-
changes: nextChanges,
|
|
109
|
-
written: nextWritten,
|
|
110
|
-
binaries: returnedBinaries(confirmed.record.binaries, submitted, accepted),
|
|
111
|
-
}, confirmed);
|
|
138
|
+
return paths;
|
|
112
139
|
}
|
|
113
|
-
function
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
old.collection.composition.selection?.model === composition.selection?.model &&
|
|
126
|
-
JSON.stringify(old.collection.composition.selection?.roots) ===
|
|
127
|
-
JSON.stringify(composition.selection?.roots);
|
|
128
|
-
const collection = hasMove
|
|
129
|
-
? reuseRewrite
|
|
130
|
-
? old.collection
|
|
131
|
-
: collectionOf(before.documents, composition, old?.collection ?? confirmed.collection)
|
|
132
|
-
: undefined;
|
|
133
|
-
const effective = collection === undefined
|
|
134
|
-
? batch
|
|
135
|
-
: reuseRewrite
|
|
136
|
-
? old.effective
|
|
137
|
-
: providerRewritten(batch, { ...before, collection });
|
|
138
|
-
layer =
|
|
139
|
-
old === undefined
|
|
140
|
-
? overlay(before, [effective])
|
|
141
|
-
: overlayChanged(before, [effective], old.before, [old.effective], old.after);
|
|
142
|
-
replay.push({
|
|
143
|
-
id: batch.id,
|
|
144
|
-
before,
|
|
145
|
-
after: layer,
|
|
146
|
-
effective,
|
|
147
|
-
...(collection === undefined ? {} : { collection }),
|
|
148
|
-
});
|
|
140
|
+
export function movedBy(queue, locator) {
|
|
141
|
+
const paths = new Set();
|
|
142
|
+
for (const batch of queue) {
|
|
143
|
+
if (!rewriting(batch, locator))
|
|
144
|
+
continue;
|
|
145
|
+
for (const change of batch.changes)
|
|
146
|
+
if (change.kind === 'move')
|
|
147
|
+
paths.add(change.path);
|
|
148
|
+
if (batch.between?.source.room === locator) {
|
|
149
|
+
for (const move of batch.between.moves)
|
|
150
|
+
paths.add(move.path);
|
|
151
|
+
}
|
|
149
152
|
}
|
|
150
|
-
return
|
|
153
|
+
return paths;
|
|
151
154
|
}
|
|
152
|
-
export function
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
155
|
+
export function* replaying(confirmed, queue, locator, composition) {
|
|
156
|
+
let layer = confirmed;
|
|
157
|
+
const touched = new Set();
|
|
158
|
+
for (const batch of queue) {
|
|
159
|
+
const effective = rewriting(batch, locator)
|
|
160
|
+
? yield* effectiveIn(batch, locator, {
|
|
161
|
+
...layer,
|
|
162
|
+
collection: collectionOf(layer.documents, composition),
|
|
163
|
+
})
|
|
164
|
+
: batch;
|
|
165
|
+
for (const change of effective.changes)
|
|
166
|
+
for (const path of changePaths(change))
|
|
167
|
+
touched.add(path);
|
|
168
|
+
layer = yield* overlaying(layer, [effective]);
|
|
169
|
+
yield ROW_WEIGHT;
|
|
167
170
|
}
|
|
168
|
-
const { layer, replay } = predicted(confirmed, batches, previous);
|
|
169
171
|
return {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
replay,
|
|
173
|
-
visible: {
|
|
174
|
-
...layer,
|
|
175
|
-
collection: collectionOf(layer.documents, compositionOf(confirmed.record), previous?.visible.collection ?? confirmed.collection),
|
|
176
|
-
},
|
|
172
|
+
visible: { ...layer, collection: collectionOf(layer.documents, composition) },
|
|
173
|
+
touched,
|
|
177
174
|
};
|
|
178
175
|
}
|
|
176
|
+
export function* overlayOf(visible, touched) {
|
|
177
|
+
const rows = [];
|
|
178
|
+
for (const path of touched) {
|
|
179
|
+
const entry = entryAt(visible, path);
|
|
180
|
+
yield ROW_WEIGHT + (entry?.content?.length ?? 0);
|
|
181
|
+
const text = entry?.binary === null ? entry.content : null;
|
|
182
|
+
rows.push(entry === null
|
|
183
|
+
? {
|
|
184
|
+
path,
|
|
185
|
+
present: false,
|
|
186
|
+
content: null,
|
|
187
|
+
binary: null,
|
|
188
|
+
revision: null,
|
|
189
|
+
fileId: null,
|
|
190
|
+
change: null,
|
|
191
|
+
written: null,
|
|
192
|
+
facts: null,
|
|
193
|
+
}
|
|
194
|
+
: {
|
|
195
|
+
...entry,
|
|
196
|
+
written: null,
|
|
197
|
+
present: true,
|
|
198
|
+
facts: text === null ? null : writtenFacts(path, text, visible.collection.composition),
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
return rows;
|
|
202
|
+
}
|
|
179
203
|
function present(layer, path) {
|
|
180
204
|
return layer.documents[path] !== undefined || layer.binaries[path] !== undefined;
|
|
181
205
|
}
|
|
182
|
-
function holds(layer, preconditions) {
|
|
206
|
+
export function holds(layer, preconditions) {
|
|
183
207
|
const parsed = new Map();
|
|
184
208
|
const documentAt = (path) => {
|
|
185
209
|
if (!parsed.has(path)) {
|
|
@@ -244,12 +268,19 @@ function effects(change) {
|
|
|
244
268
|
{ kind: 'present', path: change.to },
|
|
245
269
|
];
|
|
246
270
|
}
|
|
247
|
-
if (change.kind === 'binary')
|
|
271
|
+
if (change.kind === 'binary' || change.kind === 'arrival')
|
|
248
272
|
return [{ kind: 'present', path }];
|
|
249
273
|
return [{ kind: 'absent', path }];
|
|
250
274
|
}
|
|
251
275
|
export function landed(batch, confirmed, current = {}) {
|
|
252
|
-
const
|
|
276
|
+
const documents = new Proxy(confirmed.documents, {
|
|
277
|
+
get(target, property, receiver) {
|
|
278
|
+
if (typeof property === 'string' && Object.hasOwn(current, property))
|
|
279
|
+
return current[property];
|
|
280
|
+
return Reflect.get(target, property, receiver);
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
const layer = { ...confirmed, documents };
|
|
253
284
|
return batch.changes.every((change, index) => {
|
|
254
285
|
if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
|
|
255
286
|
const at = landing(batch.changes, index, change.path);
|
|
@@ -267,32 +298,151 @@ export function landed(batch, confirmed, current = {}) {
|
|
|
267
298
|
});
|
|
268
299
|
});
|
|
269
300
|
}
|
|
270
|
-
|
|
301
|
+
function founded(batch, layer) {
|
|
302
|
+
let changed = false;
|
|
303
|
+
const preconditions = batch.preconditions.map((precondition) => {
|
|
304
|
+
if (precondition.kind !== 'content')
|
|
305
|
+
return precondition;
|
|
306
|
+
const revision = layer.revisions[precondition.path];
|
|
307
|
+
if (revision === undefined || layer.documents[precondition.path] !== precondition.content) {
|
|
308
|
+
return precondition;
|
|
309
|
+
}
|
|
310
|
+
changed = true;
|
|
311
|
+
return { kind: 'revision', path: precondition.path, revision };
|
|
312
|
+
});
|
|
313
|
+
return changed ? immutable({ ...batch, preconditions }) : batch;
|
|
314
|
+
}
|
|
315
|
+
export function* standing(confirmed, queue, withdrawable, local, locator, composition) {
|
|
271
316
|
if (!queue.some(withdrawable))
|
|
272
|
-
return [];
|
|
273
|
-
|
|
274
|
-
let layer = confirmed.record;
|
|
317
|
+
return { withdrawn: [], kept: queue };
|
|
318
|
+
let layer = confirmed;
|
|
275
319
|
const withdrawn = [];
|
|
320
|
+
const kept = [];
|
|
276
321
|
for (const batch of queue) {
|
|
277
322
|
if (withdrawable(batch) && !holds(layer, batch.preconditions)) {
|
|
278
323
|
withdrawn.push(batch);
|
|
279
324
|
continue;
|
|
280
325
|
}
|
|
281
|
-
const effective = batch
|
|
282
|
-
?
|
|
326
|
+
const effective = rewriting(batch, locator)
|
|
327
|
+
? yield* effectiveIn(batch, locator, {
|
|
283
328
|
...layer,
|
|
284
329
|
collection: collectionOf(layer.documents, composition),
|
|
285
330
|
})
|
|
286
331
|
: batch;
|
|
287
332
|
let unapplied = false;
|
|
288
|
-
const next =
|
|
333
|
+
const next = yield* overlaying(layer, [effective], () => {
|
|
289
334
|
unapplied = true;
|
|
290
335
|
});
|
|
291
336
|
if (local && unapplied) {
|
|
292
337
|
withdrawn.push(batch);
|
|
293
338
|
continue;
|
|
294
339
|
}
|
|
340
|
+
kept.push(local || !withdrawable(batch) ? batch : founded(batch, layer));
|
|
295
341
|
layer = next;
|
|
296
342
|
}
|
|
297
|
-
return withdrawn;
|
|
343
|
+
return { withdrawn, kept };
|
|
344
|
+
}
|
|
345
|
+
export function returnedPaths(submitted, accepted) {
|
|
346
|
+
const paths = new Set([
|
|
347
|
+
...Object.keys(accepted.documents),
|
|
348
|
+
...Object.keys(accepted.revisions),
|
|
349
|
+
...Object.keys(accepted.fileIds ?? {}),
|
|
350
|
+
...Object.keys(accepted.changes),
|
|
351
|
+
...Object.keys(accepted.binaryFiles ?? {}),
|
|
352
|
+
...accepted.removals,
|
|
353
|
+
]);
|
|
354
|
+
for (const change of submitted.changes) {
|
|
355
|
+
if (change.kind === 'move') {
|
|
356
|
+
paths.add(change.path);
|
|
357
|
+
paths.add(change.to);
|
|
358
|
+
}
|
|
359
|
+
if (change.kind === 'arrival')
|
|
360
|
+
paths.add(change.path);
|
|
361
|
+
}
|
|
362
|
+
return paths;
|
|
363
|
+
}
|
|
364
|
+
export function* returning(confirmed, submitted, accepted, writtenAt, composition) {
|
|
365
|
+
const documents = new Map();
|
|
366
|
+
const binaries = new Map();
|
|
367
|
+
const revisions = new Map();
|
|
368
|
+
const fileIds = new Map();
|
|
369
|
+
const changes = new Map();
|
|
370
|
+
const written = new Map();
|
|
371
|
+
const facts = new Map();
|
|
372
|
+
const read = (changed, held, path) => (changed.has(path) ? changed.get(path) : held[path]);
|
|
373
|
+
for (const [path, content] of Object.entries(accepted.documents)) {
|
|
374
|
+
yield ROW_WEIGHT + content.length;
|
|
375
|
+
documents.set(path, content);
|
|
376
|
+
facts.set(path, writtenFacts(path, content, composition));
|
|
377
|
+
fileIds.set(path, undefined);
|
|
378
|
+
written.set(path, writtenAt);
|
|
379
|
+
}
|
|
380
|
+
for (const [path, revision] of Object.entries(accepted.revisions)) {
|
|
381
|
+
yield ROW_WEIGHT;
|
|
382
|
+
revisions.set(path, revision);
|
|
383
|
+
fileIds.set(path, undefined);
|
|
384
|
+
if (confirmed.revisions[path] !== revision)
|
|
385
|
+
changes.set(path, undefined);
|
|
386
|
+
}
|
|
387
|
+
for (const [path, fileId] of Object.entries(accepted.fileIds ?? {}))
|
|
388
|
+
fileIds.set(path, fileId);
|
|
389
|
+
for (const [path, change] of Object.entries(accepted.changes))
|
|
390
|
+
changes.set(path, change);
|
|
391
|
+
for (const path of accepted.removals) {
|
|
392
|
+
documents.set(path, undefined);
|
|
393
|
+
revisions.set(path, undefined);
|
|
394
|
+
fileIds.set(path, undefined);
|
|
395
|
+
changes.set(path, undefined);
|
|
396
|
+
written.set(path, undefined);
|
|
397
|
+
}
|
|
398
|
+
for (const change of submitted.changes) {
|
|
399
|
+
if (change.kind === 'arrival' && 'binary' in change) {
|
|
400
|
+
if (accepted.revisions[change.path] !== undefined) {
|
|
401
|
+
binaries.set(change.path, { state: 'accepted', ...change.binary });
|
|
402
|
+
}
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
if (change.kind !== 'move')
|
|
406
|
+
continue;
|
|
407
|
+
const moved = read(binaries, confirmed.binaries, change.path);
|
|
408
|
+
if (moved === undefined || accepted.revisions[change.to] === undefined)
|
|
409
|
+
continue;
|
|
410
|
+
binaries.set(change.to, moved);
|
|
411
|
+
binaries.set(change.path, undefined);
|
|
412
|
+
}
|
|
413
|
+
for (const [path, binary] of acceptedBinaries(accepted.binaryFiles ?? {}))
|
|
414
|
+
binaries.set(path, binary);
|
|
415
|
+
for (const path of accepted.removals)
|
|
416
|
+
binaries.set(path, undefined);
|
|
417
|
+
const paths = new Set([
|
|
418
|
+
...documents.keys(),
|
|
419
|
+
...binaries.keys(),
|
|
420
|
+
...revisions.keys(),
|
|
421
|
+
...fileIds.keys(),
|
|
422
|
+
...changes.keys(),
|
|
423
|
+
...written.keys(),
|
|
424
|
+
]);
|
|
425
|
+
const set = [];
|
|
426
|
+
const removed = [];
|
|
427
|
+
for (const path of paths) {
|
|
428
|
+
const content = read(documents, confirmed.documents, path);
|
|
429
|
+
const binary = read(binaries, confirmed.binaries, path);
|
|
430
|
+
yield ROW_WEIGHT;
|
|
431
|
+
if (content === undefined && binary === undefined) {
|
|
432
|
+
removed.push(path);
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
const text = binary === undefined ? (content ?? null) : null;
|
|
436
|
+
set.push({
|
|
437
|
+
path,
|
|
438
|
+
content: text,
|
|
439
|
+
facts: text === null ? null : (read(facts, confirmed.facts, path) ?? null),
|
|
440
|
+
binary: binary ?? null,
|
|
441
|
+
revision: read(revisions, confirmed.revisions, path) ?? null,
|
|
442
|
+
fileId: read(fileIds, confirmed.fileIds, path) ?? null,
|
|
443
|
+
change: read(changes, confirmed.changes, path) ?? null,
|
|
444
|
+
written: read(written, confirmed.written, path) ?? null,
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
return { set, removed };
|
|
298
448
|
}
|
package/dist/room-draft.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export type RoomDraftParts = {
|
|
|
32
32
|
readonly creation?: RoomDraftCreation;
|
|
33
33
|
readonly move?: {
|
|
34
34
|
readonly to: string;
|
|
35
|
+
readonly room?: string;
|
|
35
36
|
readonly base?: string | null;
|
|
36
37
|
};
|
|
37
38
|
readonly removal?: {
|
|
@@ -39,11 +40,12 @@ export type RoomDraftParts = {
|
|
|
39
40
|
};
|
|
40
41
|
readonly file?: {
|
|
41
42
|
readonly blob: Blob;
|
|
43
|
+
readonly base?: string | null;
|
|
42
44
|
};
|
|
43
45
|
};
|
|
44
46
|
export type HeldFile = {
|
|
45
|
-
readonly blob: Blob;
|
|
46
47
|
readonly localId: string;
|
|
48
|
+
readonly name?: string;
|
|
47
49
|
readonly byteLength: number;
|
|
48
50
|
readonly mediaType: string;
|
|
49
51
|
readonly sha256: string;
|
|
@@ -69,6 +71,7 @@ type HeldParts = {
|
|
|
69
71
|
readonly creation?: RoomDraftCreation;
|
|
70
72
|
readonly move?: {
|
|
71
73
|
readonly to: string;
|
|
74
|
+
readonly room?: string;
|
|
72
75
|
readonly base: string | null;
|
|
73
76
|
};
|
|
74
77
|
readonly removal?: {
|
|
@@ -87,9 +90,9 @@ type ChangedUnderneath = {
|
|
|
87
90
|
readonly file?: string | null;
|
|
88
91
|
};
|
|
89
92
|
export type ReturnReason = ProviderRefusal & {
|
|
90
|
-
readonly kind: 'conflicted' | 'rejected' | '
|
|
93
|
+
readonly kind: Open<'conflicted' | 'rejected' | 'withdrawn'>;
|
|
91
94
|
};
|
|
92
|
-
export declare function returnedBy(kind: '
|
|
95
|
+
export declare function returnedBy(kind: 'withdrawn'): ReturnReason;
|
|
93
96
|
export type RoomDraft = {
|
|
94
97
|
readonly room: string;
|
|
95
98
|
readonly path: string;
|
|
@@ -110,7 +113,7 @@ export type RoomDraftWrite = {
|
|
|
110
113
|
export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
|
|
111
114
|
export type ChangedPart = {
|
|
112
115
|
readonly path: string;
|
|
113
|
-
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | '
|
|
116
|
+
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'move' | 'removal' | 'file'>;
|
|
114
117
|
readonly name?: string;
|
|
115
118
|
};
|
|
116
119
|
export type RoomDraftRecord = {
|
|
@@ -124,16 +127,44 @@ export type SavedDraft = {
|
|
|
124
127
|
readonly path: string;
|
|
125
128
|
readonly parts: HeldParts;
|
|
126
129
|
};
|
|
127
|
-
export declare function readParts(value: unknown): RoomDraftParts;
|
|
130
|
+
export declare function readParts(value: unknown, path: string): RoomDraftParts;
|
|
131
|
+
export declare function gatheredParts(earlier: unknown, later: unknown): unknown;
|
|
128
132
|
export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
|
|
129
133
|
export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
|
|
130
134
|
export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
|
|
131
135
|
export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
|
|
132
|
-
export declare function changedParts(path: string,
|
|
136
|
+
export declare function changedParts(path: string, parts: HeldParts, visible: VisibleLayer | undefined): readonly ChangedPart[];
|
|
137
|
+
export declare function lineEnded(text: string): string;
|
|
138
|
+
export type TextParts = {
|
|
139
|
+
readonly fields?: Readonly<Record<string, {
|
|
140
|
+
readonly value: unknown;
|
|
141
|
+
}>>;
|
|
142
|
+
readonly sections?: Readonly<Record<string, {
|
|
143
|
+
readonly value: string;
|
|
144
|
+
}>>;
|
|
145
|
+
readonly preamble?: {
|
|
146
|
+
readonly value: string;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
export declare function partsAfter(markdown: string, parts: TextParts): string;
|
|
133
150
|
export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts): HeldParts;
|
|
134
151
|
export declare function moveTarget(move: {
|
|
135
152
|
readonly to: string;
|
|
136
153
|
}): string;
|
|
154
|
+
export declare function readSavedParts(named: readonly {
|
|
155
|
+
readonly path: string;
|
|
156
|
+
readonly parts: unknown;
|
|
157
|
+
}[]): readonly {
|
|
158
|
+
readonly path: string;
|
|
159
|
+
readonly parts: RoomDraftParts;
|
|
160
|
+
}[];
|
|
161
|
+
export declare function partsChanges(named: readonly {
|
|
162
|
+
readonly path: string;
|
|
163
|
+
readonly parts: unknown;
|
|
164
|
+
}[]): {
|
|
165
|
+
readonly changes: readonly Change[];
|
|
166
|
+
readonly preconditions: readonly Precondition[];
|
|
167
|
+
};
|
|
137
168
|
export declare function changesOf(path: string, parts: HeldParts): {
|
|
138
169
|
changes: readonly Change[];
|
|
139
170
|
bases: readonly Precondition[];
|