@agentshouse/mdruntime 0.1.0-cf281e8224a5d → 0.1.0-cf4cf1851ebaa
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 +21 -19
- package/dist/acceptance.d.ts +0 -3
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +72 -158
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +142 -72
- package/dist/adapter.d.ts +120 -58
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +0 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +0 -5
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/bootstrap.d.ts +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +6 -19
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/change.d.ts +4 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +3 -0
- package/dist/chat-types.d.ts +0 -2
- package/dist/chat-types.d.ts.map +1 -1
- package/dist/chat-types.js +0 -2
- package/dist/client.d.ts +16 -20
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +41 -56
- package/dist/collection.d.ts +26 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +28 -10
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +2 -0
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +17 -5
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +35 -26
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +28 -12
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +25 -12
- package/dist/conversation-row.d.ts +8 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +20 -7
- package/dist/conversation.d.ts +37 -12
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +325 -234
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +47 -47
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +5 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +14 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +45 -16
- package/dist/expectation.d.ts +25 -14
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +51 -20
- package/dist/failure.d.ts +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +8 -0
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +4 -2
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- package/dist/host.d.ts +23 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +84 -19
- package/dist/house-query.d.ts +15 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +43 -0
- package/dist/index.d.ts +20 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -7
- package/dist/install.d.ts +10 -6
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +92 -109
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +75 -53
- package/dist/listing.d.ts +29 -22
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +71 -79
- package/dist/live.d.ts +5 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +74 -31
- package/dist/loaded.d.ts +5 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +40 -0
- package/dist/locks.d.ts +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +12 -39
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +11 -23
- package/dist/media.d.ts +18 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +114 -24
- package/dist/memory.d.ts +9 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +93 -32
- package/dist/messages.d.ts +12 -6
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +29 -27
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +4 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -5
- package/dist/models.d.ts +4 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +97 -139
- package/dist/observation.d.ts +29 -12
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +206 -69
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opened.d.ts +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +2 -2
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +22 -10
- package/dist/outcome.d.ts +13 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +32 -2
- package/dist/overlay.d.ts +6 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +37 -24
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +5 -59
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +32 -122
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +210 -92
- package/dist/presence.d.ts +58 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +231 -0
- package/dist/queries.d.ts +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +85 -70
- package/dist/questions.d.ts +1 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -8
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +480 -0
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +177 -33
- package/dist/react.d.ts +11 -5
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +28 -5
- package/dist/readiness.d.ts +20 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +17 -10
- package/dist/reads.d.ts +4 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +11 -4
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/refresh.js +2 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +5 -5
- package/dist/replica.d.ts +5 -11
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +14 -16
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +30 -5
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +270 -63
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +8 -5
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +45 -0
- package/dist/rows.d.ts +2 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +9 -10
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runtime.d.ts +11 -19
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +42 -90
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +326 -223
- package/dist/saves.d.ts +4 -40
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +142 -710
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +4 -4
- package/dist/shown.d.ts +9 -5
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +94 -60
- package/dist/socket/lanes.d.ts +12 -4
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +34 -8
- package/dist/socket/session.d.ts +4 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +4 -6
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +4 -14
- package/dist/source.d.ts +5 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +13 -2
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +21 -6
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +59 -22
- package/dist/store/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -0
- package/dist/store.d.ts +25 -15
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +50 -18
- package/dist/stored.d.ts +32 -14
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +187 -51
- package/dist/surface.d.ts +12 -6
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +66 -34
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +126 -101
- package/dist/tables.d.ts +16 -56
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +86 -327
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +1 -2
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +4 -10
- package/dist/wire.d.ts +66 -7
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +25 -9
- package/package.json +3 -2
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/job.d.ts +0 -33
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -54
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/socket/rooms.d.ts +0 -44
- package/dist/socket/rooms.d.ts.map +0 -1
- package/dist/socket/rooms.js +0 -90
- package/dist/store/fences.d.ts +0 -16
- package/dist/store/fences.d.ts.map +0 -1
- package/dist/store/fences.js +0 -26
package/dist/save.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { ancestors, authoredAt, covered, normalize } from './paths.js';
|
|
1
|
+
import { apply, ARRAY_INDEX, ATTACHMENT, create, links, parse, pointerSegments, references, relative, relativize, retarget, roomReferences, serialize, target, } from '@agentshouse/mdmodel';
|
|
2
|
+
import { immutable, isPart, leaving, queuedFile, departure, } from './change.js';
|
|
3
|
+
import { collectionOf, definitionsAt, documentsOf, governing, textType, typedText, } from './collection.js';
|
|
4
|
+
import { changeBatchIdentity, roomDraftRevision } from './identity.js';
|
|
5
|
+
import { composed, overlaying } from './overlay.js';
|
|
6
|
+
import { ancestors } from './paths.js';
|
|
8
7
|
import { entriesIn, sorting } from './shared.js';
|
|
8
|
+
import { applyParts, changedParts, changesOf, moveTarget, partsBetween, withdrawnDrafts, } from './room-draft.js';
|
|
9
9
|
import { paced, ROW_WEIGHT, stepped } from './turn.js';
|
|
10
10
|
import { validatedCollection } from './validation.js';
|
|
11
|
-
function refuse(code, file, location) {
|
|
11
|
+
function refuse(code, file, location, line) {
|
|
12
12
|
return {
|
|
13
13
|
kind: 'refused',
|
|
14
14
|
refusal: {
|
|
@@ -16,9 +16,13 @@ function refuse(code, file, location) {
|
|
|
16
16
|
retryable: false,
|
|
17
17
|
...(file === undefined ? {} : { file }),
|
|
18
18
|
...(location === undefined ? {} : { location }),
|
|
19
|
+
...(line === undefined ? {} : { line }),
|
|
19
20
|
},
|
|
20
21
|
};
|
|
21
22
|
}
|
|
23
|
+
function refusedBy(refusal, file) {
|
|
24
|
+
return refuse(refusal.rule, file, refusal.location, refusal.line);
|
|
25
|
+
}
|
|
22
26
|
function repointed(document, definition, from, to, moves, settled) {
|
|
23
27
|
const changes = [];
|
|
24
28
|
const names = new Set();
|
|
@@ -42,43 +46,13 @@ function repointed(document, definition, from, to, moves, settled) {
|
|
|
42
46
|
}
|
|
43
47
|
if (changes.length === 0)
|
|
44
48
|
return [];
|
|
45
|
-
const applied = apply(document, changes);
|
|
49
|
+
const applied = apply(document, changes, definition);
|
|
46
50
|
if (applied.outcome !== 'applied')
|
|
47
51
|
return [];
|
|
48
52
|
const next = applied.document;
|
|
49
53
|
return [...names].map((name) => ({ kind: 'field', path: from, name, value: next.fields[name] }));
|
|
50
54
|
}
|
|
51
|
-
function
|
|
52
|
-
const parts = new Map();
|
|
53
|
-
for (const change of changes) {
|
|
54
|
-
if (change.kind === 'preamble')
|
|
55
|
-
parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
|
|
56
|
-
if (change.kind === 'section')
|
|
57
|
-
parts.set(`section ${change.name}`, {
|
|
58
|
-
kind: 'section',
|
|
59
|
-
name: change.name,
|
|
60
|
-
value: change.value,
|
|
61
|
-
prior: document.sections[change.name] ?? '',
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
if (parts.size === 0)
|
|
65
|
-
return document;
|
|
66
|
-
const applied = apply(document, [...parts.values()]);
|
|
67
|
-
return applied.outcome === 'applied' ? applied.document : document;
|
|
68
|
-
}
|
|
69
|
-
function bodies(path, before, after) {
|
|
70
|
-
const changes = [];
|
|
71
|
-
if (after.preamble !== before.preamble) {
|
|
72
|
-
changes.push({ kind: 'preamble', path, value: after.preamble });
|
|
73
|
-
}
|
|
74
|
-
for (const [name, value] of Object.entries(after.sections)) {
|
|
75
|
-
if (before.sections[name] === value)
|
|
76
|
-
continue;
|
|
77
|
-
changes.push({ kind: 'section', path, name, value });
|
|
78
|
-
}
|
|
79
|
-
return changes;
|
|
80
|
-
}
|
|
81
|
-
function relinks(path, moved, before, moves) {
|
|
55
|
+
function relinks(path, moved, before, moves, definition) {
|
|
82
56
|
const changes = [];
|
|
83
57
|
for (const link of links(before, path)) {
|
|
84
58
|
const destination = moves.get(link.target) ?? link.target;
|
|
@@ -91,28 +65,30 @@ function relinks(path, moved, before, moves) {
|
|
|
91
65
|
}
|
|
92
66
|
if (changes.length === 0)
|
|
93
67
|
return { kind: 'changes', changes: [] };
|
|
94
|
-
const applied = apply(before, changes);
|
|
95
|
-
if (applied.outcome === 'refuse')
|
|
96
|
-
return
|
|
97
|
-
kind: 'refused',
|
|
98
|
-
refusal: {
|
|
99
|
-
code: applied.refusal.rule,
|
|
100
|
-
retryable: false,
|
|
101
|
-
file: path,
|
|
102
|
-
...(applied.refusal.location === undefined ? {} : { location: applied.refusal.location }),
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
}
|
|
68
|
+
const applied = apply(before, changes, definition);
|
|
69
|
+
if (applied.outcome === 'refuse')
|
|
70
|
+
return refusedBy(applied.refusal, path);
|
|
106
71
|
const after = applied.document;
|
|
107
72
|
if (after === before)
|
|
108
73
|
return { kind: 'changes', changes: [] };
|
|
109
74
|
if (before.type === undefined) {
|
|
110
75
|
return { kind: 'changes', changes: [{ kind: 'replace', path, content: serialize(after) }] };
|
|
111
76
|
}
|
|
112
|
-
return { kind: 'changes', changes:
|
|
77
|
+
return { kind: 'changes', changes: partsBetween(path, before, after) };
|
|
113
78
|
}
|
|
114
79
|
function partKey(change) {
|
|
115
|
-
return change.kind === 'section'
|
|
80
|
+
return change.kind === 'section' || change.kind === 'field'
|
|
81
|
+
? `${change.kind} ${change.name}`
|
|
82
|
+
: change.kind;
|
|
83
|
+
}
|
|
84
|
+
const NAMES_A_SKIP_TESTS = 64;
|
|
85
|
+
const ENCODED = /[%&\\]/u;
|
|
86
|
+
function movedNames(moves) {
|
|
87
|
+
const names = new Set([...moves.keys()].map((path) => path.slice(path.lastIndexOf('/') + 1)));
|
|
88
|
+
return names.size > NAMES_A_SKIP_TESTS ? null : [...names];
|
|
89
|
+
}
|
|
90
|
+
function cannotLink(text, names) {
|
|
91
|
+
return names !== null && !ENCODED.test(text) && !names.some((name) => text.includes(name));
|
|
116
92
|
}
|
|
117
93
|
function* rewrites(changes, visible) {
|
|
118
94
|
const moves = new Map();
|
|
@@ -139,17 +115,21 @@ function* rewrites(changes, visible) {
|
|
|
139
115
|
}
|
|
140
116
|
if (moves.size === 0)
|
|
141
117
|
return { kind: 'changes', changes };
|
|
118
|
+
const names = movedNames(moves);
|
|
142
119
|
const merged = [...changes];
|
|
143
120
|
const added = [];
|
|
144
121
|
for (const [path, document] of yield* documentsOf(visible.collection)) {
|
|
145
122
|
if (settled.has(path))
|
|
146
123
|
continue;
|
|
147
124
|
const moved = moves.get(path) ?? path;
|
|
148
|
-
const definition =
|
|
125
|
+
const definition = definitionsAt(visible.collection.composition, path)(document.type);
|
|
149
126
|
const repointing = repointed(document, definition, path, moved, moves, settled);
|
|
150
127
|
added.push(...repointing);
|
|
151
128
|
const own = parts.get(path) ?? [];
|
|
152
|
-
const
|
|
129
|
+
const edited = applyParts(document, own.map((index) => merged[index]), definition);
|
|
130
|
+
const relinked = moved === path && own.length === 0 && cannotLink(document.content, names)
|
|
131
|
+
? { kind: 'changes', changes: [] }
|
|
132
|
+
: relinks(path, moved, edited.outcome === 'applied' ? edited.document : document, moves, definition);
|
|
153
133
|
if (relinked.kind === 'refused')
|
|
154
134
|
return relinked;
|
|
155
135
|
const keyed = new Map();
|
|
@@ -162,7 +142,7 @@ function* rewrites(changes, visible) {
|
|
|
162
142
|
if (change.kind === 'replace') {
|
|
163
143
|
for (const index of own) {
|
|
164
144
|
const kind = merged[index]?.kind;
|
|
165
|
-
if (kind === 'section' || kind === 'preamble')
|
|
145
|
+
if (kind === 'field' || kind === 'section' || kind === 'preamble')
|
|
166
146
|
merged[index] = null;
|
|
167
147
|
}
|
|
168
148
|
added.push(change);
|
|
@@ -218,25 +198,21 @@ function crossed(document, definition, path, to) {
|
|
|
218
198
|
}
|
|
219
199
|
return changes;
|
|
220
200
|
}
|
|
221
|
-
function rewritten(path, document, changes) {
|
|
201
|
+
function rewritten(path, document, changes, definition) {
|
|
222
202
|
if (changes.length === 0)
|
|
223
203
|
return [];
|
|
224
|
-
const applied = apply(document, changes);
|
|
204
|
+
const applied = apply(document, changes, definition);
|
|
225
205
|
if (applied.outcome !== 'applied')
|
|
226
206
|
return [];
|
|
227
207
|
const after = applied.document;
|
|
228
208
|
if (document.type === undefined)
|
|
229
209
|
return [{ kind: 'replace', path, content: serialize(after) }];
|
|
230
|
-
|
|
231
|
-
return [
|
|
232
|
-
...[...names].map((name) => ({ kind: 'field', path, name, value: after.fields[name] })),
|
|
233
|
-
...bodies(path, document, after),
|
|
234
|
-
];
|
|
210
|
+
return partsBetween(path, document, after);
|
|
235
211
|
}
|
|
236
212
|
function roomPathOf(handle, path) {
|
|
237
213
|
return `/rooms/${handle}/${path}`;
|
|
238
214
|
}
|
|
239
|
-
|
|
215
|
+
function* leavingRewritten(batch, visible) {
|
|
240
216
|
const between = batch.between;
|
|
241
217
|
if (between === undefined)
|
|
242
218
|
return batch;
|
|
@@ -245,8 +221,8 @@ export function* leavingRewritten(batch, visible) {
|
|
|
245
221
|
for (const [path, document] of yield* documentsOf(visible.collection)) {
|
|
246
222
|
if (moved.has(path))
|
|
247
223
|
continue;
|
|
248
|
-
const definition =
|
|
249
|
-
derived.push(...rewritten(path, document, crossed(document, definition, path, (named) => moved.get(named))));
|
|
224
|
+
const definition = definitionsAt(visible.collection.composition, path)(document.type);
|
|
225
|
+
derived.push(...rewritten(path, document, crossed(document, definition, path, (named) => moved.get(named)), definition));
|
|
250
226
|
yield ROW_WEIGHT + visible.collection.text[path].length;
|
|
251
227
|
}
|
|
252
228
|
if (derived.length === 0)
|
|
@@ -288,7 +264,7 @@ function* incoming(collection, removed, candidates) {
|
|
|
288
264
|
for (const [path, document] of candidates === null
|
|
289
265
|
? yield* documentsOf(collection)
|
|
290
266
|
: read(candidates)) {
|
|
291
|
-
const definition =
|
|
267
|
+
const definition = definitionsAt(collection.composition, path)(document.type);
|
|
292
268
|
for (const { value, to } of definition === undefined ? [] : references(document, definition)) {
|
|
293
269
|
if (to.includes(ATTACHMENT))
|
|
294
270
|
continue;
|
|
@@ -331,18 +307,9 @@ function guard(changes, input, removing) {
|
|
|
331
307
|
const occupied = (path) => input.folders.has(path) ? path : (ancestors(path).find((one) => existing.has(one)) ?? null);
|
|
332
308
|
for (const [index, change] of changes.entries()) {
|
|
333
309
|
for (const path of affected(change)) {
|
|
334
|
-
const
|
|
335
|
-
if (
|
|
336
|
-
return refuse(
|
|
337
|
-
if (covered(input.providerOwnedPaths, normalized) ||
|
|
338
|
-
(input.authoredPaths !== undefined && !authoredAt(input.authoredPaths, normalized))) {
|
|
339
|
-
return refuse('provider-owned-path', normalized);
|
|
340
|
-
}
|
|
341
|
-
if (!input.pathRule(normalized))
|
|
342
|
-
return refuse('invalid-path', normalized);
|
|
343
|
-
for (const operation of change.kind === 'remove' ? removing : WRITE)
|
|
344
|
-
if (!input.local && !covered(input.operations[operation], normalized))
|
|
345
|
-
return refuse(`${operation}-grant`, normalized);
|
|
310
|
+
const refused = input.rule(path, change.kind === 'remove' ? removing : WRITE);
|
|
311
|
+
if (refused !== null)
|
|
312
|
+
return refuse(refused.code, refused.path);
|
|
346
313
|
}
|
|
347
314
|
if (change.kind === 'create' || change.kind === 'arrival') {
|
|
348
315
|
const taken = existing.has(change.path) ? change.path : occupied(change.path);
|
|
@@ -403,9 +370,9 @@ function guard(changes, input, removing) {
|
|
|
403
370
|
return null;
|
|
404
371
|
}
|
|
405
372
|
function unrevised(input, path) {
|
|
406
|
-
return
|
|
373
|
+
return !input.local && !input.queued.has(path) && input.visible.revisions[path] === undefined;
|
|
407
374
|
}
|
|
408
|
-
|
|
375
|
+
function queuedDocuments(queue) {
|
|
409
376
|
const paths = new Set();
|
|
410
377
|
for (const batch of queue) {
|
|
411
378
|
for (const change of batch.changes) {
|
|
@@ -450,7 +417,7 @@ function* preconditionsOf(changes, visible, bases) {
|
|
|
450
417
|
};
|
|
451
418
|
for (const change of changes) {
|
|
452
419
|
yield ROW_WEIGHT;
|
|
453
|
-
if (change
|
|
420
|
+
if (isPart(change)) {
|
|
454
421
|
const based = bases.find((base) => sameTarget(base, change));
|
|
455
422
|
if (based !== undefined) {
|
|
456
423
|
add(based);
|
|
@@ -541,93 +508,101 @@ function* exceeding(limits, changes, effective, resulting) {
|
|
|
541
508
|
function shellRelative(text, path, handle, definition) {
|
|
542
509
|
if (!text.includes(`/rooms/${handle}/`))
|
|
543
510
|
return null;
|
|
544
|
-
const parsed = parse(text, path);
|
|
511
|
+
const parsed = parse(text, path, definition);
|
|
545
512
|
if (!parsed.ok)
|
|
546
513
|
return null;
|
|
547
514
|
const result = relativize(parsed.document, path, handle, definition(parsed.document.type));
|
|
548
515
|
return result.outcome === 'applied' && result.document.content !== text ? result.document : null;
|
|
549
516
|
}
|
|
550
517
|
function relativeField(path, name, value, handle, definition) {
|
|
551
|
-
|
|
552
|
-
if (definition === undefined ||
|
|
553
|
-
!opened.ok ||
|
|
554
|
-
!JSON.stringify(value ?? null).includes(`/rooms/${handle}/`))
|
|
518
|
+
if (definition === undefined || !JSON.stringify(value ?? null).includes(`/rooms/${handle}/`))
|
|
555
519
|
return value;
|
|
556
|
-
const held = apply(
|
|
520
|
+
const held = apply(create(definition.name, definition), [{ kind: 'field', name, value, prior: undefined }], definition);
|
|
557
521
|
if (held.outcome !== 'applied')
|
|
558
522
|
return value;
|
|
559
523
|
const result = relativize(held.document, path, handle, definition);
|
|
560
524
|
return result.outcome === 'applied' ? result.document.fields[name] : value;
|
|
561
525
|
}
|
|
562
526
|
function relativeChanges(input) {
|
|
527
|
+
const changes = [];
|
|
528
|
+
for (const change of input.changes) {
|
|
529
|
+
const next = relativeChange(change, input);
|
|
530
|
+
if ('refusal' in next)
|
|
531
|
+
return next;
|
|
532
|
+
changes.push(next.change);
|
|
533
|
+
}
|
|
534
|
+
return { kind: 'changes', changes };
|
|
535
|
+
}
|
|
536
|
+
function relativeChange(change, input) {
|
|
563
537
|
const { handle, composition, visible } = input;
|
|
564
|
-
const typed = (path) => (type) => definitionOf(governing(composition, path), type);
|
|
565
538
|
const body = (path, text) => shellRelative(text, path, handle, () => undefined)?.content ?? text;
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
539
|
+
const definition = definitionsAt(composition, change.path);
|
|
540
|
+
if (change.kind === 'field') {
|
|
541
|
+
const type = visible.collection.document(change.path)?.type;
|
|
542
|
+
const value = relativeField(change.path, change.name, change.value, handle, definition(type));
|
|
543
|
+
return { change: value === change.value ? change : { ...change, value } };
|
|
544
|
+
}
|
|
545
|
+
if (change.kind === 'section' || change.kind === 'preamble') {
|
|
546
|
+
const value = body(change.path, change.value);
|
|
547
|
+
return { change: value === change.value ? change : { ...change, value } };
|
|
548
|
+
}
|
|
549
|
+
if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
|
|
550
|
+
const content = shellRelative(change.content, change.path, handle, definition)?.content ?? change.content;
|
|
551
|
+
return { change: content === change.content ? change : { ...change, content } };
|
|
552
|
+
}
|
|
553
|
+
if (change.kind !== 'create')
|
|
554
|
+
return { change };
|
|
555
|
+
const type = typeof change.fields.type === 'string' ? change.fields.type : undefined;
|
|
556
|
+
const fields = Object.fromEntries(Object.entries(change.fields).map(([name, value]) => [
|
|
557
|
+
name,
|
|
558
|
+
relativeField(change.path, name, value, handle, definition(type)),
|
|
559
|
+
]));
|
|
560
|
+
const sections = Object.fromEntries(Object.entries(change.sections).map(([name, value]) => [name, body(change.path, value)]));
|
|
561
|
+
const written = composed(change.path, fields, sections, composition);
|
|
562
|
+
if (written.outcome === 'refuse')
|
|
563
|
+
return refusedBy(written.refusal, change.path);
|
|
564
|
+
if (written.outcome === 'stale')
|
|
565
|
+
throw new Error(`the creation of ${change.path} is stale`);
|
|
566
|
+
if (Object.keys(sections).length === 0)
|
|
567
|
+
return { change: { ...change, fields, sections } };
|
|
568
|
+
return {
|
|
569
|
+
change: { kind: 'create', path: change.path, content: serialize(written.document) },
|
|
570
|
+
};
|
|
591
571
|
}
|
|
592
572
|
function unqueueable(file) {
|
|
593
|
-
return
|
|
594
|
-
}
|
|
595
|
-
function isPart(change) {
|
|
596
|
-
return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
|
|
573
|
+
return refuse('unknown-revision', file);
|
|
597
574
|
}
|
|
598
575
|
function touched(change) {
|
|
599
576
|
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
600
577
|
}
|
|
601
|
-
function partsApplied(content, path, changes) {
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
const
|
|
578
|
+
function partsApplied(content, path, changes, composition) {
|
|
579
|
+
const applied = partsResult(content, path, changes, composition);
|
|
580
|
+
return applied?.outcome === 'applied' ? serialize(applied.document) : null;
|
|
581
|
+
}
|
|
582
|
+
function unapplied(changes, visible, composition) {
|
|
583
|
+
const parted = new Map();
|
|
607
584
|
for (const change of changes) {
|
|
608
|
-
if (change
|
|
609
|
-
|
|
610
|
-
kind: 'field',
|
|
611
|
-
name: change.name,
|
|
612
|
-
value: change.value,
|
|
613
|
-
prior: document.fields[change.name],
|
|
614
|
-
});
|
|
615
|
-
else if (change.kind === 'section')
|
|
616
|
-
parts.set(`section ${change.name}`, {
|
|
617
|
-
kind: 'section',
|
|
618
|
-
name: change.name,
|
|
619
|
-
value: change.value,
|
|
620
|
-
prior: document.sections[change.name] ?? '',
|
|
621
|
-
});
|
|
622
|
-
else
|
|
623
|
-
parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
|
|
585
|
+
if (isPart(change))
|
|
586
|
+
parted.set(change.path, [...(parted.get(change.path) ?? []), change]);
|
|
624
587
|
}
|
|
625
|
-
const
|
|
626
|
-
|
|
588
|
+
for (const [path, parts] of parted) {
|
|
589
|
+
const content = visible.documents[path];
|
|
590
|
+
if (content === undefined)
|
|
591
|
+
continue;
|
|
592
|
+
const applied = partsResult(content, path, parts, composition);
|
|
593
|
+
if (applied?.outcome === 'refuse')
|
|
594
|
+
return refusedBy(applied.refusal, path);
|
|
595
|
+
}
|
|
596
|
+
return null;
|
|
627
597
|
}
|
|
628
|
-
function
|
|
598
|
+
function partsResult(content, path, changes, composition) {
|
|
599
|
+
const definitions = definitionsAt(composition, path);
|
|
600
|
+
const parsed = parse(content, path, definitions);
|
|
601
|
+
return parsed.ok ? applyParts(parsed.document, changes, definitions(parsed.document.type)) : null;
|
|
602
|
+
}
|
|
603
|
+
function settledParts(changes, deferred, composition) {
|
|
629
604
|
for (const [held, parts] of deferred) {
|
|
630
|
-
const content = partsApplied(held.content, held.path, parts);
|
|
605
|
+
const content = partsApplied(held.content, held.path, parts, composition);
|
|
631
606
|
if (content === null)
|
|
632
607
|
return held.path;
|
|
633
608
|
changes[changes.indexOf(held)] = { ...held, content };
|
|
@@ -702,7 +677,9 @@ function* relinked(batch, move, before, after, appending) {
|
|
|
702
677
|
for (const change of derived.changes) {
|
|
703
678
|
if (change === move)
|
|
704
679
|
continue;
|
|
705
|
-
const unsettled = isPart(change)
|
|
680
|
+
const unsettled = isPart(change)
|
|
681
|
+
? null
|
|
682
|
+
: settledParts(changes, deferred, after.collection.composition);
|
|
706
683
|
if (unsettled !== null)
|
|
707
684
|
return unqueueable(unsettled);
|
|
708
685
|
const outcome = folded(changes, change, appending, deferred);
|
|
@@ -713,7 +690,7 @@ function* relinked(batch, move, before, after, appending) {
|
|
|
713
690
|
if (outcome !== 'skipped')
|
|
714
691
|
changed = true;
|
|
715
692
|
}
|
|
716
|
-
const unsettled = settledParts(changes, deferred);
|
|
693
|
+
const unsettled = settledParts(changes, deferred, after.collection.composition);
|
|
717
694
|
if (unsettled !== null)
|
|
718
695
|
return unqueueable(unsettled);
|
|
719
696
|
if (!changed)
|
|
@@ -774,11 +751,10 @@ function withdrawnFile(batch, change, at) {
|
|
|
774
751
|
];
|
|
775
752
|
return immutable({ ...batch, id: changeBatchIdentity(), changes, preconditions });
|
|
776
753
|
}
|
|
777
|
-
|
|
754
|
+
function* requeuing(queue, changes, visible, changeable, state) {
|
|
778
755
|
const next = [...queue];
|
|
779
756
|
const origins = new Map();
|
|
780
757
|
const withdrawn = new Map();
|
|
781
|
-
const owners = new Set();
|
|
782
758
|
const queued = new Set();
|
|
783
759
|
const kept = [];
|
|
784
760
|
const originOf = (batch) => origins.get(batch) ?? batch.id;
|
|
@@ -824,7 +800,6 @@ export function* requeuing(queue, changes, visible, changeable, state) {
|
|
|
824
800
|
if (replaced !== null)
|
|
825
801
|
origins.set(replaced, origin);
|
|
826
802
|
}
|
|
827
|
-
owners.add(originOf(owner));
|
|
828
803
|
next.splice(index, following.length, ...rebuilt.filter((batch) => batch !== null));
|
|
829
804
|
queued.add(change.path);
|
|
830
805
|
}
|
|
@@ -834,62 +809,16 @@ export function* requeuing(queue, changes, visible, changeable, state) {
|
|
|
834
809
|
changes: kept,
|
|
835
810
|
queued,
|
|
836
811
|
withdrawn,
|
|
837
|
-
owners,
|
|
838
812
|
};
|
|
839
813
|
}
|
|
840
|
-
function
|
|
841
|
-
return precondition.kind === 'field' ||
|
|
842
|
-
precondition.kind === 'section' ||
|
|
843
|
-
precondition.kind === 'preamble'
|
|
844
|
-
? identity(precondition)
|
|
845
|
-
: `path ${precondition.path}`;
|
|
846
|
-
}
|
|
847
|
-
export function joined(queue, owner, extra) {
|
|
848
|
-
const later = new Set(queue.slice(queue.indexOf(owner) + 1).flatMap((batch) => batch.changes.flatMap(touched)));
|
|
849
|
-
const clash = extra.changes.flatMap(touched).find((path) => later.has(path));
|
|
850
|
-
if (clash !== undefined)
|
|
851
|
-
return unqueueable(clash);
|
|
852
|
-
const changes = [...owner.changes];
|
|
853
|
-
const deferred = new Map();
|
|
854
|
-
for (const change of extra.changes) {
|
|
855
|
-
const unsettled = isPart(change) ? null : settledParts(changes, deferred);
|
|
856
|
-
if (unsettled !== null)
|
|
857
|
-
return unqueueable(unsettled);
|
|
858
|
-
if (folded(changes, change, true, deferred) === 'refused')
|
|
859
|
-
return unqueueable(change.path);
|
|
860
|
-
}
|
|
861
|
-
const unsettled = settledParts(changes, deferred);
|
|
862
|
-
if (unsettled !== null)
|
|
863
|
-
return unqueueable(unsettled);
|
|
864
|
-
const held = new Set(owner.preconditions.map(covering));
|
|
865
|
-
const written = new Set(owner.changes.flatMap((change) => change.kind === 'create' || change.kind === 'replace' ? [change.path] : []));
|
|
866
|
-
const preconditions = [
|
|
867
|
-
...owner.preconditions,
|
|
868
|
-
...extra.preconditions.filter((precondition) => {
|
|
869
|
-
const key = covering(precondition);
|
|
870
|
-
return (!held.has(key) && (key === `path ${precondition.path}` || !written.has(precondition.path)));
|
|
871
|
-
}),
|
|
872
|
-
];
|
|
873
|
-
const batch = immutable({
|
|
874
|
-
...owner,
|
|
875
|
-
...(extra.validation === undefined ? {} : { validation: extra.validation }),
|
|
876
|
-
id: changeBatchIdentity(),
|
|
877
|
-
changes,
|
|
878
|
-
preconditions,
|
|
879
|
-
});
|
|
880
|
-
return { kind: 'joined', batch, queue: queue.map((item) => (item === owner ? batch : item)) };
|
|
881
|
-
}
|
|
882
|
-
export function* limiting(queue, batch, limits, state) {
|
|
814
|
+
function* limiting(queue, batch, limits, state) {
|
|
883
815
|
const at = queue.indexOf(batch);
|
|
884
816
|
const rewritten = yield* providerRewritten(batch, yield* state(queue.slice(0, at)));
|
|
885
817
|
const limited = yield* exceeding(limits, batch.changes, rewritten.changes, yield* state(queue.slice(0, at + 1)));
|
|
886
818
|
return limited?.refusal ?? null;
|
|
887
819
|
}
|
|
888
|
-
function
|
|
889
|
-
|
|
890
|
-
return false;
|
|
891
|
-
const parsed = parse(content);
|
|
892
|
-
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
820
|
+
function typedContent(content) {
|
|
821
|
+
return content !== undefined && typedText(parse(content));
|
|
893
822
|
}
|
|
894
823
|
function touchedLibrary(resulting, touched, composition) {
|
|
895
824
|
const entries = touched
|
|
@@ -909,9 +838,9 @@ function touchedLibrary(resulting, touched, composition) {
|
|
|
909
838
|
if (binaries.has(path))
|
|
910
839
|
known.set(path, { type: undefined, binary: true });
|
|
911
840
|
else if (content !== undefined && content !== null) {
|
|
912
|
-
const
|
|
913
|
-
if (
|
|
914
|
-
known.set(path, { type
|
|
841
|
+
const type = textType(parse(content, path, definitionsAt(composition, path)));
|
|
842
|
+
if (type !== undefined)
|
|
843
|
+
known.set(path, { type, binary: false });
|
|
915
844
|
await pace(content.length + ROW_WEIGHT);
|
|
916
845
|
}
|
|
917
846
|
}
|
|
@@ -929,7 +858,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
|
|
|
929
858
|
for (const path of touched) {
|
|
930
859
|
const before = visible.documents[path];
|
|
931
860
|
const after = resulting.documents[path];
|
|
932
|
-
if (
|
|
861
|
+
if (typedContent(before) || typedContent(after))
|
|
933
862
|
typedPaths.push(path);
|
|
934
863
|
await pace((before?.length ?? 0) + (after?.length ?? 0) + ROW_WEIGHT);
|
|
935
864
|
}
|
|
@@ -947,6 +876,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
|
|
|
947
876
|
retryable: false,
|
|
948
877
|
file: verdict.file,
|
|
949
878
|
...(verdict.location === undefined ? {} : { location: verdict.location }),
|
|
879
|
+
...(verdict.line === undefined ? {} : { line: verdict.line }),
|
|
950
880
|
...(verdict.referrers === undefined ? {} : { referrers: verdict.referrers }),
|
|
951
881
|
},
|
|
952
882
|
};
|
|
@@ -962,8 +892,6 @@ function placed(reference) {
|
|
|
962
892
|
const key = roomPathOf(reference.handle, reference.path);
|
|
963
893
|
if (reference.kind === 'link')
|
|
964
894
|
return `link ${key}`;
|
|
965
|
-
if (reference.kind === 'item')
|
|
966
|
-
return `section ${reference.section} ${key}`;
|
|
967
895
|
const pointer = reference.pointer
|
|
968
896
|
.split('/')
|
|
969
897
|
.map((segment) => (ARRAY_INDEX.test(segment) ? '-' : segment))
|
|
@@ -973,10 +901,11 @@ function placed(reference) {
|
|
|
973
901
|
function roomReferencesIn(path, content, composition) {
|
|
974
902
|
if (content === undefined)
|
|
975
903
|
return [];
|
|
976
|
-
const
|
|
904
|
+
const definitions = definitionsAt(composition, path);
|
|
905
|
+
const parsed = parse(content, path, definitions);
|
|
977
906
|
if (!parsed.ok)
|
|
978
907
|
return [];
|
|
979
|
-
return roomReferences(parsed.document,
|
|
908
|
+
return roomReferences(parsed.document, definitions(parsed.document.type));
|
|
980
909
|
}
|
|
981
910
|
function* admittedRooms(changes, visible, resulting, composition) {
|
|
982
911
|
const from = new Map();
|
|
@@ -994,7 +923,7 @@ function* admittedRooms(changes, visible, resulting, composition) {
|
|
|
994
923
|
continue;
|
|
995
924
|
if (held.has(placed(reference)))
|
|
996
925
|
continue;
|
|
997
|
-
return refuse('unresolved-reference', path, reference.
|
|
926
|
+
return refuse('unresolved-reference', path, reference.pointer);
|
|
998
927
|
}
|
|
999
928
|
yield ROW_WEIGHT + now.length;
|
|
1000
929
|
}
|
|
@@ -1012,7 +941,10 @@ function validationOf(validated) {
|
|
|
1012
941
|
};
|
|
1013
942
|
}
|
|
1014
943
|
async function batching(input) {
|
|
1015
|
-
const
|
|
944
|
+
const relative = relativeChanges(input);
|
|
945
|
+
if (relative.kind === 'refused')
|
|
946
|
+
return relative;
|
|
947
|
+
const { changes } = relative;
|
|
1016
948
|
const structural = changes.find((change) => change.kind === 'move' || change.kind === 'remove');
|
|
1017
949
|
if (structural !== undefined && input.unmodeled) {
|
|
1018
950
|
return refuse('model-unavailable', structural.path);
|
|
@@ -1022,12 +954,12 @@ async function batching(input) {
|
|
|
1022
954
|
const rewritten = await stepped(rewrites(changes, input.visible));
|
|
1023
955
|
if (rewritten.kind === 'refused')
|
|
1024
956
|
return rewritten;
|
|
1025
|
-
const refusal = guard(changes, input, WRITE);
|
|
957
|
+
const refusal = guard(changes, input, WRITE) ?? unapplied(changes, input.visible, input.composition);
|
|
1026
958
|
if (refusal !== null)
|
|
1027
959
|
return refusal;
|
|
1028
960
|
const preconditions = await stepped(preconditionsOf(changes, input.visible, input.bases));
|
|
1029
961
|
const predicted = await stepped(anticipated(changes, preconditions, rewritten.changes, input.visible));
|
|
1030
|
-
const resulting = await stepped(overlaying(input.visible, [{ id: '', baseRoomVersion: input.baseRoomVersion, ...predicted }]));
|
|
962
|
+
const resulting = await stepped(overlaying(input.visible, [{ id: '', baseRoomVersion: input.baseRoomVersion, ...predicted }], input.composition));
|
|
1031
963
|
const judged = await judging(input.visible, resulting, input.composition, input.validate, new Set(changes.filter((change) => change.kind === 'remove').map((change) => change.path)), [...new Set(predicted.changes.flatMap(affected))]);
|
|
1032
964
|
if (judged.kind === 'refused')
|
|
1033
965
|
return judged;
|
|
@@ -1049,7 +981,7 @@ async function batching(input) {
|
|
|
1049
981
|
}),
|
|
1050
982
|
};
|
|
1051
983
|
}
|
|
1052
|
-
|
|
984
|
+
const MOVE_DOCUMENTS = 'move-documents';
|
|
1053
985
|
function heldAt(visible, path) {
|
|
1054
986
|
return visible.documents[path] !== undefined || visible.binaries[path] !== undefined;
|
|
1055
987
|
}
|
|
@@ -1058,7 +990,7 @@ function arrivingText(path, to, source, moved) {
|
|
|
1058
990
|
const document = source.visible.collection.document(path);
|
|
1059
991
|
if (document === undefined)
|
|
1060
992
|
return content;
|
|
1061
|
-
const definition =
|
|
993
|
+
const definition = definitionsAt(source.composition, path)(document.type);
|
|
1062
994
|
const changes = crossed(document, definition, path, (named, href) => {
|
|
1063
995
|
const at = moved.get(named);
|
|
1064
996
|
if (at !== undefined)
|
|
@@ -1067,7 +999,7 @@ function arrivingText(path, to, source, moved) {
|
|
|
1067
999
|
});
|
|
1068
1000
|
if (changes.length === 0)
|
|
1069
1001
|
return content;
|
|
1070
|
-
const applied = apply(document, changes);
|
|
1002
|
+
const applied = apply(document, changes, definition);
|
|
1071
1003
|
return applied.outcome === 'applied' ? serialize(applied.document) : content;
|
|
1072
1004
|
}
|
|
1073
1005
|
function arrivalOf({ path, to }, source, moved) {
|
|
@@ -1100,9 +1032,9 @@ function arrivalOf({ path, to }, source, moved) {
|
|
|
1100
1032
|
};
|
|
1101
1033
|
}
|
|
1102
1034
|
async function moving(input) {
|
|
1103
|
-
const { source, destination, moves
|
|
1035
|
+
const { source, destination, moves } = input;
|
|
1104
1036
|
const removals = moves.map(({ path }) => ({ kind: 'remove', path }));
|
|
1105
|
-
const leaves = guard(removals, { ...source, local: input.local, bases: []
|
|
1037
|
+
const leaves = guard(removals, { ...source, local: input.local, bases: [] }, MOVE_OUT);
|
|
1106
1038
|
if (leaves !== null)
|
|
1107
1039
|
return leaves;
|
|
1108
1040
|
const uploading = moves.find(({ path }) => source.visible.binaries[path]?.state === 'pending');
|
|
@@ -1110,7 +1042,7 @@ async function moving(input) {
|
|
|
1110
1042
|
return refuse('unknown-revision', uploading.path);
|
|
1111
1043
|
const moved = new Map(moves.map(({ path, to }) => [path, to]));
|
|
1112
1044
|
const arrivals = moves.map((move) => arrivalOf(move, source, moved));
|
|
1113
|
-
const arrives = guard(arrivals, { ...destination, local: input.local, bases: []
|
|
1045
|
+
const arrives = guard(arrivals, { ...destination, local: input.local, bases: [] }, WRITE);
|
|
1114
1046
|
if (arrives !== null)
|
|
1115
1047
|
return arrives;
|
|
1116
1048
|
const bound = input.providerLimits.find((limit) => limit.name === MOVE_DOCUMENTS)?.value;
|
|
@@ -1139,7 +1071,7 @@ async function moving(input) {
|
|
|
1139
1071
|
between,
|
|
1140
1072
|
};
|
|
1141
1073
|
const effective = await stepped(leavingRewritten(leavingBatch, source.visible));
|
|
1142
|
-
const left = await stepped(overlaying(source.visible, [effective]));
|
|
1074
|
+
const left = await stepped(overlaying(source.visible, [effective], source.composition));
|
|
1143
1075
|
const sourceJudged = await judging(source.visible, left, source.composition, source.validate, new Set(moves.map(({ path }) => path)), [...new Set(effective.changes.map((change) => change.path))]);
|
|
1144
1076
|
if (sourceJudged.kind === 'refused')
|
|
1145
1077
|
return sourceJudged;
|
|
@@ -1151,7 +1083,7 @@ async function moving(input) {
|
|
|
1151
1083
|
...written,
|
|
1152
1084
|
between,
|
|
1153
1085
|
};
|
|
1154
|
-
const arrived = await stepped(overlaying(destination.visible, [arrivingBatch]));
|
|
1086
|
+
const arrived = await stepped(overlaying(destination.visible, [arrivingBatch], destination.composition));
|
|
1155
1087
|
const destinationJudged = await judging(destination.visible, arrived, destination.composition, destination.validate, new Set(), moves.map(({ to }) => to));
|
|
1156
1088
|
if (destinationJudged.kind === 'refused')
|
|
1157
1089
|
return destinationJudged;
|
|
@@ -1161,9 +1093,180 @@ async function moving(input) {
|
|
|
1161
1093
|
return limited;
|
|
1162
1094
|
return { kind: 'moved', leaving: immutable(leavingBatch), arriving: immutable(arrivingBatch) };
|
|
1163
1095
|
}
|
|
1164
|
-
|
|
1165
|
-
|
|
1096
|
+
function unreadable(saved, visible, composition) {
|
|
1097
|
+
const path = saved.find(({ path: at, parts }) => (parts.fields !== undefined ||
|
|
1098
|
+
parts.sections !== undefined ||
|
|
1099
|
+
parts.preamble !== undefined) &&
|
|
1100
|
+
typedContent(visible.documents[at]) &&
|
|
1101
|
+
governing(composition, at).status === 'unavailable')?.path;
|
|
1102
|
+
return path === undefined ? null : refuse('model-unavailable', path);
|
|
1103
|
+
}
|
|
1104
|
+
function changedUnderneath(saved, visible) {
|
|
1105
|
+
const parts = saved.flatMap(({ path, parts: held }) => changedParts(path, held, visible));
|
|
1106
|
+
return parts.length === 0
|
|
1107
|
+
? null
|
|
1108
|
+
: { kind: 'refused', refusal: { code: 'changed-underneath', retryable: false, parts } };
|
|
1109
|
+
}
|
|
1110
|
+
function sideOf(room, visible) {
|
|
1111
|
+
const { record } = room;
|
|
1112
|
+
return {
|
|
1113
|
+
room: record.locator,
|
|
1114
|
+
handle: record.declaration.handle,
|
|
1115
|
+
baseRoomVersion: record.roomVersion,
|
|
1116
|
+
composition: room.composition,
|
|
1117
|
+
rule: room.rule,
|
|
1118
|
+
visible,
|
|
1119
|
+
folders: room.folders,
|
|
1120
|
+
queued: queuedDocuments(room.queue),
|
|
1121
|
+
unmodeled: !room.modelled,
|
|
1122
|
+
validate: room.validate,
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
function carriedDrafts(ask, from, into) {
|
|
1126
|
+
return new Map(ask.saved.flatMap(({ path, parts }) => {
|
|
1127
|
+
const record = from.drafts.get(path);
|
|
1128
|
+
if (parts.move === undefined || record === undefined || ask.consumed.has(path))
|
|
1129
|
+
return [];
|
|
1130
|
+
const to = moveTarget(parts.move);
|
|
1131
|
+
if (into.drafts.has(to))
|
|
1132
|
+
return [];
|
|
1133
|
+
const locator = into.record.locator;
|
|
1134
|
+
return [[path, { ...record, locator, path: to, revision: roomDraftRevision() }]];
|
|
1135
|
+
}));
|
|
1136
|
+
}
|
|
1137
|
+
async function plannedMove(ask, source, into) {
|
|
1138
|
+
const destination = into.record.locator;
|
|
1139
|
+
const mixed = ask.saved.find(({ parts }) => Object.keys(parts).length !== 1 || parts.move?.room !== destination);
|
|
1140
|
+
if (mixed !== undefined)
|
|
1141
|
+
return refuse('mixed-room-move', mixed.path);
|
|
1142
|
+
const leavingVisible = await stepped(source.replay(source.queue));
|
|
1143
|
+
const changed = changedUnderneath(ask.saved, leavingVisible);
|
|
1144
|
+
if (changed !== null)
|
|
1145
|
+
return changed;
|
|
1146
|
+
const moves = ask.saved.map(({ path, parts }) => ({ path, to: moveTarget(parts.move) }));
|
|
1147
|
+
const built = await moving({
|
|
1148
|
+
source: sideOf(source, leavingVisible),
|
|
1149
|
+
destination: sideOf(into, await stepped(into.replay(into.queue))),
|
|
1150
|
+
moves,
|
|
1151
|
+
providerLimits: ask.providerLimits,
|
|
1152
|
+
local: ask.local,
|
|
1153
|
+
...(ask.writtenBy === undefined ? {} : { writtenBy: ask.writtenBy }),
|
|
1154
|
+
});
|
|
1155
|
+
if (built.kind === 'refused')
|
|
1156
|
+
return built;
|
|
1157
|
+
const { id } = built.leaving;
|
|
1158
|
+
const carried = carriedDrafts(ask, source, into);
|
|
1159
|
+
return {
|
|
1160
|
+
kind: 'planned',
|
|
1161
|
+
identifier: id,
|
|
1162
|
+
rooms: [
|
|
1163
|
+
{
|
|
1164
|
+
locator: source.record.locator,
|
|
1165
|
+
queue: [...source.queue, built.leaving],
|
|
1166
|
+
saved: new Map([[id, ask.saved]]),
|
|
1167
|
+
consumed: [...ask.consumed, ...carried.keys()],
|
|
1168
|
+
carried: [],
|
|
1169
|
+
},
|
|
1170
|
+
{
|
|
1171
|
+
locator: destination,
|
|
1172
|
+
queue: [...into.queue, built.arriving],
|
|
1173
|
+
saved: new Map([
|
|
1174
|
+
[id, [...carried.values()].map(({ path }) => ({ path, parts: {} }))],
|
|
1175
|
+
]),
|
|
1176
|
+
consumed: [],
|
|
1177
|
+
carried: [...carried.values()],
|
|
1178
|
+
},
|
|
1179
|
+
],
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
async function plannedWithin(ask, room) {
|
|
1183
|
+
const { record } = room;
|
|
1184
|
+
const visible = await stepped(room.replay(room.queue));
|
|
1185
|
+
const changed = unreadable(ask.saved, visible, room.composition) ?? changedUnderneath(ask.saved, visible);
|
|
1186
|
+
if (changed !== null)
|
|
1187
|
+
return changed;
|
|
1188
|
+
const parts = ask.saved.map(({ path, parts: held }) => changesOf(path, held));
|
|
1189
|
+
const changes = parts.flatMap(({ changes: made }) => made);
|
|
1190
|
+
const requeue = await stepped(requeuing(room.queue, changes, visible, (batch) => room.changeable.has(batch.id), room.replay));
|
|
1191
|
+
if (requeue.kind === 'refused')
|
|
1192
|
+
return requeue;
|
|
1193
|
+
const foreign = [...requeue.withdrawn.keys()].some((origin) => {
|
|
1194
|
+
const writer = room.queue.find((batch) => batch.id === origin)?.writtenBy;
|
|
1195
|
+
return writer?.app !== ask.writtenBy?.app || writer?.release !== ask.writtenBy?.release;
|
|
1196
|
+
});
|
|
1197
|
+
if (foreign)
|
|
1198
|
+
return unqueueable([...requeue.queued].at(-1));
|
|
1199
|
+
const input = {
|
|
1200
|
+
local: ask.local,
|
|
1201
|
+
baseRoomVersion: record.roomVersion,
|
|
1202
|
+
composition: room.composition,
|
|
1203
|
+
rule: room.rule,
|
|
1204
|
+
providerLimits: ask.providerLimits,
|
|
1205
|
+
handle: record.declaration.handle,
|
|
1206
|
+
visible,
|
|
1207
|
+
folders: room.folders,
|
|
1208
|
+
changes,
|
|
1209
|
+
bases: parts.flatMap(({ bases }) => bases),
|
|
1210
|
+
queued: queuedDocuments(room.queue),
|
|
1211
|
+
writtenBy: ask.writtenBy,
|
|
1212
|
+
unmodeled: !room.modelled,
|
|
1213
|
+
validate: room.validate,
|
|
1214
|
+
};
|
|
1215
|
+
const rewritten = requeue.withdrawn.size > 0;
|
|
1216
|
+
if (rewritten) {
|
|
1217
|
+
const whole = await batching({
|
|
1218
|
+
...input,
|
|
1219
|
+
providerLimits: [],
|
|
1220
|
+
queued: new Set([...input.queued, ...requeue.queued]),
|
|
1221
|
+
});
|
|
1222
|
+
if (whole.kind === 'refused')
|
|
1223
|
+
return whole;
|
|
1224
|
+
}
|
|
1225
|
+
const own = !rewritten
|
|
1226
|
+
? await batching(input)
|
|
1227
|
+
: requeue.changes.length === 0
|
|
1228
|
+
? null
|
|
1229
|
+
: await batching({
|
|
1230
|
+
...input,
|
|
1231
|
+
visible: await stepped(room.replay(requeue.queue)),
|
|
1232
|
+
changes: requeue.changes,
|
|
1233
|
+
queued: queuedDocuments(requeue.queue),
|
|
1234
|
+
});
|
|
1235
|
+
if (own?.kind === 'refused')
|
|
1236
|
+
return own;
|
|
1237
|
+
const queue = own === null ? requeue.queue : [...requeue.queue, own.batch];
|
|
1238
|
+
const saved = new Map();
|
|
1239
|
+
for (const [origin, rebuilt] of requeue.withdrawn) {
|
|
1240
|
+
if (rebuilt === null)
|
|
1241
|
+
continue;
|
|
1242
|
+
const limited = await stepped(limiting(queue, rebuilt, ask.providerLimits, room.replay));
|
|
1243
|
+
if (limited !== null)
|
|
1244
|
+
return { kind: 'refused', refusal: limited };
|
|
1245
|
+
saved.set(rebuilt.id, withdrawnDrafts(room.saved.get(origin) ?? [], changes));
|
|
1246
|
+
}
|
|
1247
|
+
if (own !== null) {
|
|
1248
|
+
saved.set(own.batch.id, ask.saved.filter(({ path }) => !requeue.queued.has(path)));
|
|
1249
|
+
}
|
|
1250
|
+
const carried = carriedDrafts(ask, room, room);
|
|
1251
|
+
return {
|
|
1252
|
+
kind: 'planned',
|
|
1253
|
+
identifier: own?.batch.id ??
|
|
1254
|
+
[...requeue.withdrawn].map(([origin, rebuilt]) => rebuilt?.id ?? origin).at(-1),
|
|
1255
|
+
rooms: [
|
|
1256
|
+
{
|
|
1257
|
+
locator: record.locator,
|
|
1258
|
+
queue,
|
|
1259
|
+
saved,
|
|
1260
|
+
consumed: [...ask.consumed, ...carried.keys()],
|
|
1261
|
+
carried: [...carried.values()],
|
|
1262
|
+
},
|
|
1263
|
+
],
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
export function destination(locator, saved) {
|
|
1267
|
+
const into = saved.find(({ parts }) => parts.move?.room !== undefined && parts.move.room !== locator);
|
|
1268
|
+
return into?.parts.move?.room ?? null;
|
|
1166
1269
|
}
|
|
1167
|
-
export function
|
|
1168
|
-
return
|
|
1270
|
+
export function planSave(ask, room, into) {
|
|
1271
|
+
return into === undefined ? plannedWithin(ask, room) : plannedMove(ask, room, into);
|
|
1169
1272
|
}
|