@agentshouse/mdruntime 0.1.0-ca7c26c6bc27e → 0.1.0-ca8707258fdde
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 +25 -12
- package/dist/acceptance.d.ts +26 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +384 -0
- package/dist/adapter.d.ts +200 -54
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -9
- package/dist/attached-model.d.ts +7 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +40 -28
- 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 +37 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +336 -51
- 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 -56
- package/dist/change.d.ts +46 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +34 -0
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +2 -0
- package/dist/client.d.ts +50 -18
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +162 -30
- package/dist/collection.d.ts +13 -14
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +52 -56
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +717 -0
- package/dist/connection.d.ts +61 -43
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +2377 -1476
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +47 -0
- package/dist/conversation.d.ts +71 -22
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +996 -273
- 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 +161 -0
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/figures.d.ts +48 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -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 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +134 -34
- package/dist/identity.d.ts +3 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +13 -1
- package/dist/index.d.ts +31 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/install.d.ts +86 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +537 -0
- package/dist/job.d.ts +33 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +54 -0
- package/dist/live.d.ts +23 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +165 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- 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 +22 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +299 -94
- package/dist/messages.d.ts +52 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +168 -0
- package/dist/model.d.ts +17 -12
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +9 -9
- 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/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- 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 +73 -5
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +84 -1
- package/dist/overlay.d.ts +16 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +147 -180
- package/dist/parts.d.ts +59 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +118 -0
- package/dist/paths.d.ts +1 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -16
- package/dist/query.d.ts +52 -181
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -423
- package/dist/questions.d.ts +32 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +118 -0
- package/dist/reach.d.ts +19 -5
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +309 -92
- package/dist/react.d.ts +46 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +54 -0
- 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 +50 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +27 -0
- package/dist/reads.d.ts +35 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +128 -0
- package/dist/recovery.d.ts +26 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +232 -0
- package/dist/refresh.d.ts +20 -7
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +155 -59
- package/dist/replica.d.ts +58 -34
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +355 -162
- package/dist/room-draft.d.ts +59 -11
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +276 -80
- package/dist/room-drafts.d.ts +29 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +216 -0
- package/dist/rows.d.ts +32 -34
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +65 -87
- package/dist/save.d.ts +74 -6
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +902 -182
- package/dist/saves.d.ts +96 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +999 -0
- package/dist/search.d.ts +15 -54
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -121
- package/dist/seed.d.ts +30 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +141 -0
- package/dist/shared.d.ts +15 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +421 -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/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket.d.ts +43 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +96 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +81 -0
- package/dist/status.d.ts +7 -4
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -15
- 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/records.d.ts +212 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +408 -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/watchers.d.ts +15 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +36 -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 +77 -93
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +118 -389
- package/dist/stored.d.ts +156 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +637 -0
- package/dist/tables.d.ts +407 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +724 -0
- 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/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 +185 -45
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +75 -46
- package/package.json +33 -10
- package/AGENTS.md +0 -215
- 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 -377
package/dist/replica.js
CHANGED
|
@@ -1,163 +1,215 @@
|
|
|
1
|
-
import { parse } from '@agentshouse/mdmodel';
|
|
2
|
-
import { immutable } from './change.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
1
|
+
import { equalValue, parse } from '@agentshouse/mdmodel';
|
|
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 { 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) {
|
|
9
10
|
return {
|
|
10
11
|
model: record.model,
|
|
11
12
|
selection: record.typedSelection === null
|
|
12
13
|
? null
|
|
13
|
-
: { roots: record.typedSelection.roots, model:
|
|
14
|
+
: { roots: record.typedSelection.roots, model: builtIn },
|
|
15
|
+
typedPaths,
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
|
-
export function
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
: { text: previous.record.documents, collection: previous.collection });
|
|
20
|
-
return read.kind === 'read'
|
|
21
|
-
? { kind: 'staged', confirmed: { record, collection: read.collection } }
|
|
22
|
-
: read;
|
|
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
|
-
|
|
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}`);
|
|
32
|
+
}
|
|
27
33
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
(
|
|
31
|
-
|
|
32
|
-
record.model !== previous.record.model ||
|
|
33
|
-
record.selectionModel !== previous.record.selectionModel)) {
|
|
34
|
-
const verdict = validateCollection(record.documents, record.binaryTargets, compositionOf(record));
|
|
35
|
-
if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') {
|
|
36
|
-
return { kind: 'refused', refusal: verdict };
|
|
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);
|
|
37
38
|
}
|
|
38
|
-
}
|
|
39
|
-
return
|
|
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
|
+
});
|
|
40
54
|
}
|
|
41
|
-
export function
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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 created = {};
|
|
64
|
+
const changes = {};
|
|
65
|
+
const written = {};
|
|
66
|
+
const facts = {};
|
|
67
|
+
for (const entry of entries) {
|
|
68
|
+
if (entry.facts !== null)
|
|
69
|
+
facts[entry.path] = entry.facts;
|
|
70
|
+
if (entry.binary !== null)
|
|
71
|
+
binaries[entry.path] = entry.binary;
|
|
72
|
+
else if (entry.content !== null)
|
|
73
|
+
documents[entry.path] = entry.content;
|
|
74
|
+
if (entry.revision !== null)
|
|
75
|
+
revisions[entry.path] = entry.revision;
|
|
76
|
+
if (entry.fileId !== null)
|
|
77
|
+
fileIds[entry.path] = entry.fileId;
|
|
78
|
+
if (entry.created !== null)
|
|
79
|
+
created[entry.path] = entry.created;
|
|
80
|
+
if (entry.change !== null)
|
|
81
|
+
changes[entry.path] = entry.change;
|
|
82
|
+
if (entry.written !== null)
|
|
83
|
+
written[entry.path] = entry.written;
|
|
84
|
+
yield ROW_WEIGHT;
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
documents: strict(documents, held),
|
|
88
|
+
binaries: strict(binaries, held),
|
|
89
|
+
revisions: strict(revisions, held),
|
|
90
|
+
fileIds: strict(fileIds, held),
|
|
91
|
+
created: strict(created, held),
|
|
92
|
+
changes: strict(changes, held),
|
|
93
|
+
written: strict(written, held),
|
|
94
|
+
facts: strict(facts, held),
|
|
95
|
+
held,
|
|
96
|
+
};
|
|
48
97
|
}
|
|
49
|
-
export function
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
98
|
+
export function entryAt(layer, path) {
|
|
99
|
+
const content = layer.documents[path];
|
|
100
|
+
const binary = layer.binaries[path];
|
|
101
|
+
if (content === undefined && binary === undefined)
|
|
102
|
+
return null;
|
|
103
|
+
return {
|
|
104
|
+
path,
|
|
105
|
+
content: content ?? null,
|
|
106
|
+
binary: binary ?? null,
|
|
107
|
+
revision: layer.revisions[path] ?? null,
|
|
108
|
+
fileId: layer.fileIds[path] ?? null,
|
|
109
|
+
created: layer.created[path] ?? null,
|
|
110
|
+
change: layer.changes[path] ?? null,
|
|
111
|
+
written: layer.written?.[path] ?? null,
|
|
56
112
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
113
|
+
}
|
|
114
|
+
export function* slicingWith(slice, set, removed) {
|
|
115
|
+
const entries = new Map();
|
|
116
|
+
for (const path of slice.held) {
|
|
117
|
+
const entry = entryAt(slice, path);
|
|
118
|
+
if (entry !== null) {
|
|
119
|
+
entries.set(path, { ...entry, type: null, facts: slice.facts[path] ?? null });
|
|
120
|
+
}
|
|
121
|
+
yield ROW_WEIGHT;
|
|
61
122
|
}
|
|
62
|
-
for (const path of
|
|
63
|
-
delete
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
123
|
+
for (const path of removed)
|
|
124
|
+
entries.delete(path);
|
|
125
|
+
for (const entry of set)
|
|
126
|
+
entries.set(entry.path, { ...entry, type: null });
|
|
127
|
+
return yield* slicing([...entries.values()], [...slice.held, ...set.map(({ path }) => path), ...removed]);
|
|
128
|
+
}
|
|
129
|
+
function changePaths(change) {
|
|
130
|
+
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
131
|
+
}
|
|
132
|
+
export function touchedBy(queue) {
|
|
133
|
+
const paths = new Set();
|
|
134
|
+
for (const batch of queue) {
|
|
135
|
+
for (const change of batch.changes)
|
|
136
|
+
for (const path of changePaths(change))
|
|
137
|
+
paths.add(path);
|
|
138
|
+
for (const precondition of batch.preconditions)
|
|
139
|
+
paths.add(precondition.path);
|
|
140
|
+
for (const move of batch.between?.moves ?? [])
|
|
141
|
+
paths.add(move.path);
|
|
68
142
|
}
|
|
69
|
-
return
|
|
70
|
-
...confirmed.record,
|
|
71
|
-
roomVersion,
|
|
72
|
-
documents: nextDocuments,
|
|
73
|
-
revisions: nextRevisions,
|
|
74
|
-
changes: nextChanges,
|
|
75
|
-
written: nextWritten,
|
|
76
|
-
binaryTargets: [...binaryTargets].sort(),
|
|
77
|
-
attachments: attachments === undefined
|
|
78
|
-
? confirmed.record.attachments
|
|
79
|
-
: declaredAttachments([attachments]),
|
|
80
|
-
}, confirmed);
|
|
143
|
+
return paths;
|
|
81
144
|
}
|
|
82
|
-
function
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
old.collection.composition.selection?.model === composition.selection?.model &&
|
|
95
|
-
JSON.stringify(old.collection.composition.selection?.roots) ===
|
|
96
|
-
JSON.stringify(composition.selection?.roots);
|
|
97
|
-
const collection = hasMove
|
|
98
|
-
? reuseRewrite
|
|
99
|
-
? old.collection
|
|
100
|
-
: parseCollection(before.documents, composition, old?.collection === undefined
|
|
101
|
-
? { text: confirmed.record.documents, collection: confirmed.collection }
|
|
102
|
-
: { text: old.before.documents, collection: old.collection })
|
|
103
|
-
: undefined;
|
|
104
|
-
const effective = collection === undefined
|
|
105
|
-
? batch
|
|
106
|
-
: reuseRewrite
|
|
107
|
-
? old.effective
|
|
108
|
-
: providerRewritten(batch, { ...before, collection });
|
|
109
|
-
layer =
|
|
110
|
-
old === undefined
|
|
111
|
-
? overlay(before, [effective])
|
|
112
|
-
: overlayChanged(before, [effective], old.before, [old.effective], old.after);
|
|
113
|
-
replay.push({
|
|
114
|
-
id: batch.id,
|
|
115
|
-
before,
|
|
116
|
-
after: layer,
|
|
117
|
-
effective,
|
|
118
|
-
...(collection === undefined ? {} : { collection }),
|
|
119
|
-
});
|
|
145
|
+
export function movedBy(queue, locator) {
|
|
146
|
+
const paths = new Set();
|
|
147
|
+
for (const batch of queue) {
|
|
148
|
+
if (!rewriting(batch, locator))
|
|
149
|
+
continue;
|
|
150
|
+
for (const change of batch.changes)
|
|
151
|
+
if (change.kind === 'move')
|
|
152
|
+
paths.add(change.path);
|
|
153
|
+
if (batch.between?.source.room === locator) {
|
|
154
|
+
for (const move of batch.between.moves)
|
|
155
|
+
paths.add(move.path);
|
|
156
|
+
}
|
|
120
157
|
}
|
|
121
|
-
return
|
|
158
|
+
return paths;
|
|
122
159
|
}
|
|
123
|
-
export function
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
160
|
+
export function* replaying(confirmed, queue, locator, composition) {
|
|
161
|
+
let layer = confirmed;
|
|
162
|
+
const touched = new Set();
|
|
163
|
+
for (const batch of queue) {
|
|
164
|
+
const effective = rewriting(batch, locator)
|
|
165
|
+
? yield* effectiveIn(batch, locator, {
|
|
166
|
+
...layer,
|
|
167
|
+
collection: collectionOf(layer.documents, composition),
|
|
168
|
+
})
|
|
169
|
+
: batch;
|
|
170
|
+
for (const change of effective.changes)
|
|
171
|
+
for (const path of changePaths(change))
|
|
172
|
+
touched.add(path);
|
|
173
|
+
layer = yield* overlaying(layer, [effective]);
|
|
174
|
+
yield ROW_WEIGHT;
|
|
138
175
|
}
|
|
139
|
-
const predictedState = rewriting === 'provider' ? predicted(confirmed, batches, previous) : null;
|
|
140
|
-
const layer = rewriting === 'provider'
|
|
141
|
-
? predictedState.layer
|
|
142
|
-
: previous === undefined
|
|
143
|
-
? overlay(confirmed.record, batches)
|
|
144
|
-
: overlayChanged(confirmed.record, batches, previous.confirmed.record, previous.queue, previous.visible);
|
|
145
176
|
return {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
replay: predictedState?.replay ?? [],
|
|
149
|
-
visible: {
|
|
150
|
-
...layer,
|
|
151
|
-
collection: parseCollection(layer.documents, compositionOf(confirmed.record), previous === undefined
|
|
152
|
-
? undefined
|
|
153
|
-
: { text: previous.visible.documents, collection: previous.visible.collection }),
|
|
154
|
-
},
|
|
177
|
+
visible: { ...layer, collection: collectionOf(layer.documents, composition) },
|
|
178
|
+
touched,
|
|
155
179
|
};
|
|
156
180
|
}
|
|
181
|
+
export function* overlayOf(visible, touched) {
|
|
182
|
+
const rows = [];
|
|
183
|
+
for (const path of touched) {
|
|
184
|
+
const entry = entryAt(visible, path);
|
|
185
|
+
yield ROW_WEIGHT + (entry?.content?.length ?? 0);
|
|
186
|
+
const text = entry?.binary === null ? entry.content : null;
|
|
187
|
+
rows.push(entry === null
|
|
188
|
+
? {
|
|
189
|
+
path,
|
|
190
|
+
present: false,
|
|
191
|
+
content: null,
|
|
192
|
+
binary: null,
|
|
193
|
+
revision: null,
|
|
194
|
+
fileId: null,
|
|
195
|
+
created: null,
|
|
196
|
+
change: null,
|
|
197
|
+
written: null,
|
|
198
|
+
facts: null,
|
|
199
|
+
}
|
|
200
|
+
: {
|
|
201
|
+
...entry,
|
|
202
|
+
written: null,
|
|
203
|
+
present: true,
|
|
204
|
+
facts: text === null ? null : writtenFacts(path, text, visible.collection.composition),
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return rows;
|
|
208
|
+
}
|
|
157
209
|
function present(layer, path) {
|
|
158
|
-
return layer.documents[path] !== undefined || layer.
|
|
210
|
+
return layer.documents[path] !== undefined || layer.binaries[path] !== undefined;
|
|
159
211
|
}
|
|
160
|
-
function holds(layer, preconditions) {
|
|
212
|
+
export function holds(layer, preconditions) {
|
|
161
213
|
const parsed = new Map();
|
|
162
214
|
const documentAt = (path) => {
|
|
163
215
|
if (!parsed.has(path)) {
|
|
@@ -176,6 +228,8 @@ function holds(layer, preconditions) {
|
|
|
176
228
|
if (precondition.kind === 'revision') {
|
|
177
229
|
return present(layer, path) && layer.revisions[path] === precondition.revision;
|
|
178
230
|
}
|
|
231
|
+
if (precondition.kind === 'content')
|
|
232
|
+
return layer.documents[path] === precondition.content;
|
|
179
233
|
const document = documentAt(path);
|
|
180
234
|
if (document === null)
|
|
181
235
|
return false;
|
|
@@ -220,53 +274,192 @@ function effects(change) {
|
|
|
220
274
|
{ kind: 'present', path: change.to },
|
|
221
275
|
];
|
|
222
276
|
}
|
|
277
|
+
if (change.kind === 'binary' || change.kind === 'arrival')
|
|
278
|
+
return [{ kind: 'present', path }];
|
|
223
279
|
return [{ kind: 'absent', path }];
|
|
224
280
|
}
|
|
225
|
-
function
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
return at;
|
|
236
|
-
}
|
|
237
|
-
export function landed(batch, confirmed) {
|
|
238
|
-
const layer = confirmed.record;
|
|
281
|
+
export function landed(batch, confirmed, current = {}) {
|
|
282
|
+
const documents = new Proxy(confirmed.documents, {
|
|
283
|
+
get(target, property, receiver) {
|
|
284
|
+
if (typeof property === 'string' && Object.hasOwn(current, property))
|
|
285
|
+
return current[property];
|
|
286
|
+
return Reflect.get(target, property, receiver);
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
const layer = { ...confirmed, documents };
|
|
239
290
|
return batch.changes.every((change, index) => {
|
|
240
291
|
if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
|
|
241
|
-
const at =
|
|
292
|
+
const at = landing(batch.changes, index, change.path);
|
|
242
293
|
return at === null || layer.documents[at] === change.content;
|
|
243
294
|
}
|
|
295
|
+
if (change.kind === 'binary') {
|
|
296
|
+
const at = landing(batch.changes, index, change.path);
|
|
297
|
+
return at === null || layer.binaries[at]?.sha256 === change.sha256;
|
|
298
|
+
}
|
|
244
299
|
return effects(change).every((effect) => {
|
|
245
300
|
if (effect.kind === 'absent')
|
|
246
301
|
return holds(layer, [effect]);
|
|
247
|
-
const at =
|
|
302
|
+
const at = landing(batch.changes, index, effect.path);
|
|
248
303
|
return at === null || holds(layer, [{ ...effect, path: at }]);
|
|
249
304
|
});
|
|
250
305
|
});
|
|
251
306
|
}
|
|
252
|
-
|
|
307
|
+
function founded(batch, layer) {
|
|
308
|
+
let changed = false;
|
|
309
|
+
const preconditions = batch.preconditions.map((precondition) => {
|
|
310
|
+
if (precondition.kind !== 'content')
|
|
311
|
+
return precondition;
|
|
312
|
+
const revision = layer.revisions[precondition.path];
|
|
313
|
+
if (revision === undefined || layer.documents[precondition.path] !== precondition.content) {
|
|
314
|
+
return precondition;
|
|
315
|
+
}
|
|
316
|
+
changed = true;
|
|
317
|
+
return { kind: 'revision', path: precondition.path, revision };
|
|
318
|
+
});
|
|
319
|
+
return changed ? immutable({ ...batch, preconditions }) : batch;
|
|
320
|
+
}
|
|
321
|
+
export function* standing(confirmed, queue, withdrawable, local, locator, composition) {
|
|
253
322
|
if (!queue.some(withdrawable))
|
|
254
|
-
return [];
|
|
255
|
-
|
|
256
|
-
let layer = confirmed.record;
|
|
323
|
+
return { withdrawn: [], kept: queue };
|
|
324
|
+
let layer = confirmed;
|
|
257
325
|
const withdrawn = [];
|
|
326
|
+
const kept = [];
|
|
258
327
|
for (const batch of queue) {
|
|
259
328
|
if (withdrawable(batch) && !holds(layer, batch.preconditions)) {
|
|
260
329
|
withdrawn.push(batch);
|
|
261
330
|
continue;
|
|
262
331
|
}
|
|
263
|
-
const effective = rewriting
|
|
264
|
-
?
|
|
332
|
+
const effective = rewriting(batch, locator)
|
|
333
|
+
? yield* effectiveIn(batch, locator, {
|
|
265
334
|
...layer,
|
|
266
|
-
collection:
|
|
335
|
+
collection: collectionOf(layer.documents, composition),
|
|
267
336
|
})
|
|
268
337
|
: batch;
|
|
269
|
-
|
|
338
|
+
let unapplied = false;
|
|
339
|
+
const next = yield* overlaying(layer, [effective], () => {
|
|
340
|
+
unapplied = true;
|
|
341
|
+
});
|
|
342
|
+
if (local && unapplied) {
|
|
343
|
+
withdrawn.push(batch);
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
kept.push(local || !withdrawable(batch) ? batch : founded(batch, layer));
|
|
347
|
+
layer = next;
|
|
348
|
+
}
|
|
349
|
+
return { withdrawn, kept };
|
|
350
|
+
}
|
|
351
|
+
export function returnedPaths(submitted, accepted) {
|
|
352
|
+
const paths = new Set([
|
|
353
|
+
...Object.keys(accepted.documents),
|
|
354
|
+
...Object.keys(accepted.revisions),
|
|
355
|
+
...Object.keys(accepted.fileIds ?? {}),
|
|
356
|
+
...Object.keys(accepted.changes),
|
|
357
|
+
...Object.keys(accepted.binaryFiles ?? {}),
|
|
358
|
+
...accepted.removals,
|
|
359
|
+
]);
|
|
360
|
+
for (const change of submitted.changes) {
|
|
361
|
+
if (change.kind === 'move') {
|
|
362
|
+
paths.add(change.path);
|
|
363
|
+
paths.add(change.to);
|
|
364
|
+
}
|
|
365
|
+
if (change.kind === 'arrival')
|
|
366
|
+
paths.add(change.path);
|
|
367
|
+
}
|
|
368
|
+
return paths;
|
|
369
|
+
}
|
|
370
|
+
export function* returning(confirmed, submitted, accepted, writtenAt, composition) {
|
|
371
|
+
const documents = new Map();
|
|
372
|
+
const binaries = new Map();
|
|
373
|
+
const revisions = new Map();
|
|
374
|
+
const fileIds = new Map();
|
|
375
|
+
const created = new Map();
|
|
376
|
+
const changes = new Map();
|
|
377
|
+
const written = new Map();
|
|
378
|
+
const facts = new Map();
|
|
379
|
+
const read = (changed, held, path) => (changed.has(path) ? changed.get(path) : held[path]);
|
|
380
|
+
for (const [path, content] of Object.entries(accepted.documents)) {
|
|
381
|
+
yield ROW_WEIGHT + content.length;
|
|
382
|
+
documents.set(path, content);
|
|
383
|
+
facts.set(path, writtenFacts(path, content, composition));
|
|
384
|
+
fileIds.set(path, undefined);
|
|
385
|
+
written.set(path, writtenAt);
|
|
386
|
+
}
|
|
387
|
+
for (const [path, revision] of Object.entries(accepted.revisions)) {
|
|
388
|
+
yield ROW_WEIGHT;
|
|
389
|
+
revisions.set(path, revision);
|
|
390
|
+
fileIds.set(path, undefined);
|
|
391
|
+
if (confirmed.revisions[path] !== revision)
|
|
392
|
+
changes.set(path, undefined);
|
|
393
|
+
}
|
|
394
|
+
for (const [path, fileId] of Object.entries(accepted.fileIds ?? {}))
|
|
395
|
+
fileIds.set(path, fileId);
|
|
396
|
+
for (const [path, change] of Object.entries(accepted.changes))
|
|
397
|
+
changes.set(path, change);
|
|
398
|
+
for (const path of accepted.removals) {
|
|
399
|
+
documents.set(path, undefined);
|
|
400
|
+
revisions.set(path, undefined);
|
|
401
|
+
fileIds.set(path, undefined);
|
|
402
|
+
changes.set(path, undefined);
|
|
403
|
+
written.set(path, undefined);
|
|
404
|
+
}
|
|
405
|
+
for (const change of submitted.changes) {
|
|
406
|
+
if (change.kind === 'arrival') {
|
|
407
|
+
if (accepted.revisions[change.path] === undefined)
|
|
408
|
+
continue;
|
|
409
|
+
created.set(change.path, change.created);
|
|
410
|
+
if ('binary' in change)
|
|
411
|
+
binaries.set(change.path, { state: 'accepted', ...change.binary });
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
if (change.kind !== 'move' || accepted.revisions[change.to] === undefined)
|
|
415
|
+
continue;
|
|
416
|
+
created.set(change.to, read(created, confirmed.created, change.path));
|
|
417
|
+
created.set(change.path, undefined);
|
|
418
|
+
const moved = read(binaries, confirmed.binaries, change.path);
|
|
419
|
+
if (moved === undefined)
|
|
420
|
+
continue;
|
|
421
|
+
binaries.set(change.to, moved);
|
|
422
|
+
binaries.set(change.path, undefined);
|
|
423
|
+
}
|
|
424
|
+
for (const [path, binary] of acceptedBinaries(accepted.binaryFiles ?? {}))
|
|
425
|
+
binaries.set(path, binary);
|
|
426
|
+
for (const path of accepted.removals) {
|
|
427
|
+
binaries.set(path, undefined);
|
|
428
|
+
created.set(path, undefined);
|
|
429
|
+
}
|
|
430
|
+
const paths = new Set([
|
|
431
|
+
...documents.keys(),
|
|
432
|
+
...binaries.keys(),
|
|
433
|
+
...revisions.keys(),
|
|
434
|
+
...fileIds.keys(),
|
|
435
|
+
...created.keys(),
|
|
436
|
+
...changes.keys(),
|
|
437
|
+
...written.keys(),
|
|
438
|
+
]);
|
|
439
|
+
const set = [];
|
|
440
|
+
const removed = [];
|
|
441
|
+
for (const path of paths) {
|
|
442
|
+
const content = read(documents, confirmed.documents, path);
|
|
443
|
+
const binary = read(binaries, confirmed.binaries, path);
|
|
444
|
+
yield ROW_WEIGHT;
|
|
445
|
+
if (content === undefined && binary === undefined) {
|
|
446
|
+
removed.push(path);
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
const text = binary === undefined ? (content ?? null) : null;
|
|
450
|
+
const fresh = confirmed.documents[path] === undefined && confirmed.binaries[path] === undefined;
|
|
451
|
+
set.push({
|
|
452
|
+
path,
|
|
453
|
+
content: text,
|
|
454
|
+
facts: text === null ? null : (read(facts, confirmed.facts, path) ?? null),
|
|
455
|
+
binary: binary ?? null,
|
|
456
|
+
revision: read(revisions, confirmed.revisions, path) ?? null,
|
|
457
|
+
fileId: read(fileIds, confirmed.fileIds, path) ?? null,
|
|
458
|
+
created: read(created, confirmed.created, path) ??
|
|
459
|
+
(fresh ? (read(changes, confirmed.changes, path)?.time ?? null) : null),
|
|
460
|
+
change: read(changes, confirmed.changes, path) ?? null,
|
|
461
|
+
written: read(written, confirmed.written, path) ?? null,
|
|
462
|
+
});
|
|
270
463
|
}
|
|
271
|
-
return
|
|
464
|
+
return { set, removed };
|
|
272
465
|
}
|