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