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