@agentshouse/mdruntime 0.1.0-c450c0a30a409 → 0.1.0-c4566b4b35aaa
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 +24 -19
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +299 -0
- 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 +26 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +313 -0
- package/dist/adapter.d.ts +212 -117
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +6 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +35 -41
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- 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 +30 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +305 -140
- 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 +10 -16
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +17 -90
- package/dist/change.d.ts +5 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +8 -3
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +11 -0
- package/dist/client.d.ts +42 -26
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +88 -26
- package/dist/collection.d.ts +32 -21
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +53 -368
- 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 +18 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +723 -0
- package/dist/connection.d.ts +7 -139
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +112 -4163
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/{chat/context.js → context.js} +2 -5
- package/dist/conversation-live.d.ts +150 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +259 -0
- package/dist/conversation-row.d.ts +40 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +66 -0
- package/dist/conversation.d.ts +73 -50
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1029 -838
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- 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 +12 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +162 -0
- 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 +21 -4
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +12 -0
- package/dist/entry.d.ts +10 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +47 -32
- package/dist/expectation.d.ts +26 -13
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +72 -19
- 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 +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +199 -0
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +8 -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 +22 -8
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +125 -51
- package/dist/house-query.d.ts +21 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +41 -0
- package/dist/identity.d.ts +0 -2
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -6
- package/dist/index.d.ts +44 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -6
- package/dist/install.d.ts +60 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +537 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +287 -0
- package/dist/listing.d.ts +60 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +168 -0
- package/dist/live.d.ts +25 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +206 -0
- 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 +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +32 -0
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +49 -0
- package/dist/media.d.ts +25 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +296 -0
- package/dist/memory.d.ts +21 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +305 -117
- package/dist/messages.d.ts +58 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +164 -0
- 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 +12 -13
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +11 -22
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +153 -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 +40 -10
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +265 -44
- 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 +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 +53 -0
- package/dist/outcome.d.ts +38 -10
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +49 -2
- package/dist/overlay.d.ts +7 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +50 -176
- 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 +6 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +36 -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 +41 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +314 -0
- 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 +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +285 -0
- package/dist/query.d.ts +20 -207
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -494
- package/dist/{chat/questions.d.ts → questions.d.ts} +6 -7
- package/dist/questions.d.ts.map +1 -0
- package/dist/{chat/questions.js → questions.js} +12 -7
- 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 +28 -15
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +360 -166
- package/dist/react.d.ts +21 -3
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- 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 +22 -20
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +5 -13
- package/dist/reads.d.ts +38 -10
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +163 -83
- package/dist/recovery.d.ts +4 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +59 -2
- package/dist/refresh.d.ts +18 -15
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +145 -79
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +55 -0
- package/dist/replica.d.ts +50 -38
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +319 -229
- 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 +53 -13
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +402 -116
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +220 -0
- 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 +32 -31
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +59 -124
- 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 +35 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +44 -87
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +391 -279
- package/dist/saves.d.ts +34 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +437 -0
- package/dist/search.d.ts +12 -95
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -317
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/shared.d.ts +1 -10
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -135
- package/dist/shown.d.ts +35 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +313 -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 +28 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +103 -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/session.d.ts +39 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +24 -0
- package/dist/socket.d.ts +68 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +165 -0
- package/dist/source.d.ts +59 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +93 -0
- package/dist/status.d.ts +4 -5
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -7
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +40 -0
- package/dist/store/readiness.d.ts +11 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +68 -0
- package/dist/store/records.d.ts +226 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +468 -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/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/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 +114 -165
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +162 -804
- package/dist/stored.d.ts +167 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +700 -0
- package/dist/surface.d.ts +94 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +255 -0
- package/dist/sync.d.ts +20 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +549 -0
- package/dist/tables.d.ts +376 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +499 -0
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +128 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/turn.d.ts +1 -1
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +28 -20
- package/dist/validation.d.ts +29 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +98 -0
- package/dist/windows.d.ts +1 -11
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -70
- package/dist/wire.d.ts +88 -9
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +31 -6
- package/package.json +19 -19
- package/AGENTS.md +0 -304
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- 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/earlier.d.ts +0 -10
- package/dist/chat/earlier.d.ts.map +0 -1
- package/dist/chat/earlier.js +0 -54
- package/dist/chat/house.d.ts +0 -25
- package/dist/chat/house.d.ts.map +0 -1
- package/dist/chat/house.js +0 -38
- package/dist/chat/input.d.ts +0 -11
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -99
- package/dist/chat/kit.d.ts +0 -61
- 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 -28
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -103
- package/dist/chat/markdown.d.ts +0 -21
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -246
- package/dist/chat/message.d.ts +0 -7
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -221
- package/dist/chat/messages.d.ts +0 -30
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -198
- package/dist/chat/name.d.ts +0 -7
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -12
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -19
- package/dist/chat/overlay.d.ts +0 -32
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -107
- 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/pieces.d.ts +0 -62
- package/dist/chat/pieces.d.ts.map +0 -1
- package/dist/chat/pieces.js +0 -1110
- 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 -66
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -643
- package/dist/chat/question.d.ts +0 -9
- package/dist/chat/question.d.ts.map +0 -1
- package/dist/chat/question.js +0 -69
- 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 -36
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -93
- package/dist/chat/steady.d.ts +0 -3
- package/dist/chat/steady.d.ts.map +0 -1
- package/dist/chat/steady.js +0 -26
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -305
- package/dist/chat.d.ts +0 -15
- 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/log.d.ts +0 -5
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/read-side.d.ts +0 -27
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -1179
package/dist/save.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { ROW_WEIGHT, stepped } from './turn.js';
|
|
10
|
-
|
|
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';
|
|
7
|
+
import { entriesIn, sorting } from './shared.js';
|
|
8
|
+
import { applyParts, changedParts, changesOf, moveTarget, partsBetween, withdrawnDrafts, } from './room-draft.js';
|
|
9
|
+
import { paced, ROW_WEIGHT, stepped } from './turn.js';
|
|
10
|
+
import { validatedCollection } from './validation.js';
|
|
11
|
+
function refuse(code, file, location, line) {
|
|
11
12
|
return {
|
|
12
13
|
kind: 'refused',
|
|
13
14
|
refusal: {
|
|
@@ -15,13 +16,14 @@ function refuse(code, file, location) {
|
|
|
15
16
|
retryable: false,
|
|
16
17
|
...(file === undefined ? {} : { file }),
|
|
17
18
|
...(location === undefined ? {} : { location }),
|
|
19
|
+
...(line === undefined ? {} : { line }),
|
|
18
20
|
},
|
|
19
21
|
};
|
|
20
22
|
}
|
|
23
|
+
function refusedBy(refusal, file) {
|
|
24
|
+
return refuse(refusal.rule, file, refusal.location, refusal.line);
|
|
25
|
+
}
|
|
21
26
|
function repointed(document, definition, from, to, moves, settled) {
|
|
22
|
-
const parsed = parse(document.content, from);
|
|
23
|
-
if (!parsed.ok)
|
|
24
|
-
return [];
|
|
25
27
|
const changes = [];
|
|
26
28
|
const names = new Set();
|
|
27
29
|
for (const { pointer, value } of definition === undefined
|
|
@@ -44,43 +46,13 @@ function repointed(document, definition, from, to, moves, settled) {
|
|
|
44
46
|
}
|
|
45
47
|
if (changes.length === 0)
|
|
46
48
|
return [];
|
|
47
|
-
const applied = apply(
|
|
49
|
+
const applied = apply(document, changes, definition);
|
|
48
50
|
if (applied.outcome !== 'applied')
|
|
49
51
|
return [];
|
|
50
52
|
const next = applied.document;
|
|
51
53
|
return [...names].map((name) => ({ kind: 'field', path: from, name, value: next.fields[name] }));
|
|
52
54
|
}
|
|
53
|
-
function
|
|
54
|
-
const parts = new Map();
|
|
55
|
-
for (const change of changes) {
|
|
56
|
-
if (change.kind === 'preamble')
|
|
57
|
-
parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
|
|
58
|
-
if (change.kind === 'section')
|
|
59
|
-
parts.set(`section ${change.name}`, {
|
|
60
|
-
kind: 'section',
|
|
61
|
-
name: change.name,
|
|
62
|
-
value: change.value,
|
|
63
|
-
prior: document.sections[change.name] ?? '',
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
if (parts.size === 0)
|
|
67
|
-
return document;
|
|
68
|
-
const applied = apply(document, [...parts.values()]);
|
|
69
|
-
return applied.outcome === 'applied' ? applied.document : document;
|
|
70
|
-
}
|
|
71
|
-
function bodies(path, before, after) {
|
|
72
|
-
const changes = [];
|
|
73
|
-
if (after.preamble !== before.preamble) {
|
|
74
|
-
changes.push({ kind: 'preamble', path, value: after.preamble });
|
|
75
|
-
}
|
|
76
|
-
for (const [name, value] of Object.entries(after.sections)) {
|
|
77
|
-
if (before.sections[name] === value)
|
|
78
|
-
continue;
|
|
79
|
-
changes.push({ kind: 'section', path, name, value });
|
|
80
|
-
}
|
|
81
|
-
return changes;
|
|
82
|
-
}
|
|
83
|
-
function relinks(path, moved, before, moves) {
|
|
55
|
+
function relinks(path, moved, before, moves, definition) {
|
|
84
56
|
const changes = [];
|
|
85
57
|
for (const link of links(before, path)) {
|
|
86
58
|
const destination = moves.get(link.target) ?? link.target;
|
|
@@ -93,28 +65,30 @@ function relinks(path, moved, before, moves) {
|
|
|
93
65
|
}
|
|
94
66
|
if (changes.length === 0)
|
|
95
67
|
return { kind: 'changes', changes: [] };
|
|
96
|
-
const applied = apply(before, changes);
|
|
97
|
-
if (applied.outcome === 'refuse')
|
|
98
|
-
return
|
|
99
|
-
kind: 'refused',
|
|
100
|
-
refusal: {
|
|
101
|
-
code: applied.refusal.rule,
|
|
102
|
-
retryable: false,
|
|
103
|
-
file: path,
|
|
104
|
-
...(applied.refusal.location === undefined ? {} : { location: applied.refusal.location }),
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
}
|
|
68
|
+
const applied = apply(before, changes, definition);
|
|
69
|
+
if (applied.outcome === 'refuse')
|
|
70
|
+
return refusedBy(applied.refusal, path);
|
|
108
71
|
const after = applied.document;
|
|
109
72
|
if (after === before)
|
|
110
73
|
return { kind: 'changes', changes: [] };
|
|
111
74
|
if (before.type === undefined) {
|
|
112
75
|
return { kind: 'changes', changes: [{ kind: 'replace', path, content: serialize(after) }] };
|
|
113
76
|
}
|
|
114
|
-
return { kind: 'changes', changes:
|
|
77
|
+
return { kind: 'changes', changes: partsBetween(path, before, after) };
|
|
115
78
|
}
|
|
116
79
|
function partKey(change) {
|
|
117
|
-
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));
|
|
118
92
|
}
|
|
119
93
|
function* rewrites(changes, visible) {
|
|
120
94
|
const moves = new Map();
|
|
@@ -141,17 +115,21 @@ function* rewrites(changes, visible) {
|
|
|
141
115
|
}
|
|
142
116
|
if (moves.size === 0)
|
|
143
117
|
return { kind: 'changes', changes };
|
|
118
|
+
const names = movedNames(moves);
|
|
144
119
|
const merged = [...changes];
|
|
145
120
|
const added = [];
|
|
146
121
|
for (const [path, document] of yield* documentsOf(visible.collection)) {
|
|
147
122
|
if (settled.has(path))
|
|
148
123
|
continue;
|
|
149
124
|
const moved = moves.get(path) ?? path;
|
|
150
|
-
const definition =
|
|
125
|
+
const definition = definitionsAt(visible.collection.composition, path)(document.type);
|
|
151
126
|
const repointing = repointed(document, definition, path, moved, moves, settled);
|
|
152
127
|
added.push(...repointing);
|
|
153
128
|
const own = parts.get(path) ?? [];
|
|
154
|
-
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);
|
|
155
133
|
if (relinked.kind === 'refused')
|
|
156
134
|
return relinked;
|
|
157
135
|
const keyed = new Map();
|
|
@@ -164,7 +142,7 @@ function* rewrites(changes, visible) {
|
|
|
164
142
|
if (change.kind === 'replace') {
|
|
165
143
|
for (const index of own) {
|
|
166
144
|
const kind = merged[index]?.kind;
|
|
167
|
-
if (kind === 'section' || kind === 'preamble')
|
|
145
|
+
if (kind === 'field' || kind === 'section' || kind === 'preamble')
|
|
168
146
|
merged[index] = null;
|
|
169
147
|
}
|
|
170
148
|
added.push(change);
|
|
@@ -220,25 +198,21 @@ function crossed(document, definition, path, to) {
|
|
|
220
198
|
}
|
|
221
199
|
return changes;
|
|
222
200
|
}
|
|
223
|
-
function rewritten(path, document, changes) {
|
|
201
|
+
function rewritten(path, document, changes, definition) {
|
|
224
202
|
if (changes.length === 0)
|
|
225
203
|
return [];
|
|
226
|
-
const applied = apply(document, changes);
|
|
204
|
+
const applied = apply(document, changes, definition);
|
|
227
205
|
if (applied.outcome !== 'applied')
|
|
228
206
|
return [];
|
|
229
207
|
const after = applied.document;
|
|
230
208
|
if (document.type === undefined)
|
|
231
209
|
return [{ kind: 'replace', path, content: serialize(after) }];
|
|
232
|
-
|
|
233
|
-
return [
|
|
234
|
-
...[...names].map((name) => ({ kind: 'field', path, name, value: after.fields[name] })),
|
|
235
|
-
...bodies(path, document, after),
|
|
236
|
-
];
|
|
210
|
+
return partsBetween(path, document, after);
|
|
237
211
|
}
|
|
238
212
|
function roomPathOf(handle, path) {
|
|
239
213
|
return `/rooms/${handle}/${path}`;
|
|
240
214
|
}
|
|
241
|
-
|
|
215
|
+
function* leavingRewritten(batch, visible) {
|
|
242
216
|
const between = batch.between;
|
|
243
217
|
if (between === undefined)
|
|
244
218
|
return batch;
|
|
@@ -247,8 +221,8 @@ export function* leavingRewritten(batch, visible) {
|
|
|
247
221
|
for (const [path, document] of yield* documentsOf(visible.collection)) {
|
|
248
222
|
if (moved.has(path))
|
|
249
223
|
continue;
|
|
250
|
-
const definition =
|
|
251
|
-
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));
|
|
252
226
|
yield ROW_WEIGHT + visible.collection.text[path].length;
|
|
253
227
|
}
|
|
254
228
|
if (derived.length === 0)
|
|
@@ -267,10 +241,6 @@ export function* effectiveIn(batch, locator, visible) {
|
|
|
267
241
|
? yield* leavingRewritten(batch, visible)
|
|
268
242
|
: yield* providerRewritten(batch, visible);
|
|
269
243
|
}
|
|
270
|
-
function* chained(...sets) {
|
|
271
|
-
for (const set of sets)
|
|
272
|
-
yield* set;
|
|
273
|
-
}
|
|
274
244
|
function* incoming(collection, removed, candidates) {
|
|
275
245
|
const found = new Map();
|
|
276
246
|
const note = (target, file) => {
|
|
@@ -294,7 +264,7 @@ function* incoming(collection, removed, candidates) {
|
|
|
294
264
|
for (const [path, document] of candidates === null
|
|
295
265
|
? yield* documentsOf(collection)
|
|
296
266
|
: read(candidates)) {
|
|
297
|
-
const definition =
|
|
267
|
+
const definition = definitionsAt(collection.composition, path)(document.type);
|
|
298
268
|
for (const { value, to } of definition === undefined ? [] : references(document, definition)) {
|
|
299
269
|
if (to.includes(ATTACHMENT))
|
|
300
270
|
continue;
|
|
@@ -324,6 +294,8 @@ function* incoming(collection, removed, candidates) {
|
|
|
324
294
|
function affected(change) {
|
|
325
295
|
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
326
296
|
}
|
|
297
|
+
const WRITE = ['write'];
|
|
298
|
+
const MOVE_OUT = ['write', 'erase'];
|
|
327
299
|
function guard(changes, input, removing) {
|
|
328
300
|
const overridden = new Map();
|
|
329
301
|
const existing = {
|
|
@@ -332,21 +304,17 @@ function guard(changes, input, removing) {
|
|
|
332
304
|
add: (path) => void overridden.set(path, true),
|
|
333
305
|
delete: (path) => void overridden.set(path, false),
|
|
334
306
|
};
|
|
307
|
+
const occupied = (path) => input.folders.has(path) ? path : (ancestors(path).find((one) => existing.has(one)) ?? null);
|
|
335
308
|
for (const [index, change] of changes.entries()) {
|
|
336
309
|
for (const path of affected(change)) {
|
|
337
|
-
const
|
|
338
|
-
if (
|
|
339
|
-
return refuse(
|
|
340
|
-
if (covered(input.providerOwnedPaths, normalized)) {
|
|
341
|
-
return refuse('provider-owned-path', normalized);
|
|
342
|
-
}
|
|
343
|
-
const operation = 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
|
-
|
|
349
|
-
|
|
315
|
+
const taken = existing.has(change.path) ? change.path : occupied(change.path);
|
|
316
|
+
if (taken !== null)
|
|
317
|
+
return refuse('path-collision', taken);
|
|
350
318
|
existing.add(change.path);
|
|
351
319
|
continue;
|
|
352
320
|
}
|
|
@@ -356,6 +324,9 @@ function guard(changes, input, removing) {
|
|
|
356
324
|
input.bases.some((base) => base.kind === 'absent' && base.path === change.path))) {
|
|
357
325
|
return refuse('path-collision', change.path);
|
|
358
326
|
}
|
|
327
|
+
const taken = occupied(change.path);
|
|
328
|
+
if (taken !== null)
|
|
329
|
+
return refuse('path-collision', taken);
|
|
359
330
|
if (!input.local &&
|
|
360
331
|
existing.has(change.path) &&
|
|
361
332
|
input.visible.revisions[departure(changes, index)] === undefined) {
|
|
@@ -367,8 +338,9 @@ function guard(changes, input, removing) {
|
|
|
367
338
|
if (change.kind === 'move') {
|
|
368
339
|
if (!existing.has(change.path))
|
|
369
340
|
return refuse('path-absent', change.path);
|
|
370
|
-
|
|
371
|
-
|
|
341
|
+
const taken = existing.has(change.to) ? change.to : occupied(change.to);
|
|
342
|
+
if (taken !== null)
|
|
343
|
+
return refuse('path-collision', taken);
|
|
372
344
|
if (unrevised(input, change.path)) {
|
|
373
345
|
return refuse('unknown-revision', change.path);
|
|
374
346
|
}
|
|
@@ -398,9 +370,9 @@ function guard(changes, input, removing) {
|
|
|
398
370
|
return null;
|
|
399
371
|
}
|
|
400
372
|
function unrevised(input, path) {
|
|
401
|
-
return
|
|
373
|
+
return !input.local && !input.queued.has(path) && input.visible.revisions[path] === undefined;
|
|
402
374
|
}
|
|
403
|
-
|
|
375
|
+
function queuedDocuments(queue) {
|
|
404
376
|
const paths = new Set();
|
|
405
377
|
for (const batch of queue) {
|
|
406
378
|
for (const change of batch.changes) {
|
|
@@ -445,7 +417,7 @@ function* preconditionsOf(changes, visible, bases) {
|
|
|
445
417
|
};
|
|
446
418
|
for (const change of changes) {
|
|
447
419
|
yield ROW_WEIGHT;
|
|
448
|
-
if (change
|
|
420
|
+
if (isPart(change)) {
|
|
449
421
|
const based = bases.find((base) => sameTarget(base, change));
|
|
450
422
|
if (based !== undefined) {
|
|
451
423
|
add(based);
|
|
@@ -536,105 +508,101 @@ function* exceeding(limits, changes, effective, resulting) {
|
|
|
536
508
|
function shellRelative(text, path, handle, definition) {
|
|
537
509
|
if (!text.includes(`/rooms/${handle}/`))
|
|
538
510
|
return null;
|
|
539
|
-
const parsed = parse(text, path);
|
|
511
|
+
const parsed = parse(text, path, definition);
|
|
540
512
|
if (!parsed.ok)
|
|
541
513
|
return null;
|
|
542
514
|
const result = relativize(parsed.document, path, handle, definition(parsed.document.type));
|
|
543
515
|
return result.outcome === 'applied' && result.document.content !== text ? result.document : null;
|
|
544
516
|
}
|
|
545
517
|
function relativeField(path, name, value, handle, definition) {
|
|
546
|
-
|
|
547
|
-
if (definition === undefined ||
|
|
548
|
-
!opened.ok ||
|
|
549
|
-
!JSON.stringify(value ?? null).includes(`/rooms/${handle}/`))
|
|
518
|
+
if (definition === undefined || !JSON.stringify(value ?? null).includes(`/rooms/${handle}/`))
|
|
550
519
|
return value;
|
|
551
|
-
const held = apply(
|
|
520
|
+
const held = apply(create(definition.name, definition), [{ kind: 'field', name, value, prior: undefined }], definition);
|
|
552
521
|
if (held.outcome !== 'applied')
|
|
553
522
|
return value;
|
|
554
523
|
const result = relativize(held.document, path, handle, definition);
|
|
555
524
|
return result.outcome === 'applied' ? result.document.fields[name] : value;
|
|
556
525
|
}
|
|
557
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) {
|
|
558
537
|
const { handle, composition, visible } = input;
|
|
559
|
-
const typed = (path) => (type) => definitionOf(governing(composition, path), type);
|
|
560
538
|
const body = (path, text) => shellRelative(text, path, handle, () => undefined)?.content ?? text;
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
return value === change.value ? change : { ...change, value };
|
|
571
|
-
}
|
|
572
|
-
if (change.kind === 'replace' || (change.kind === 'create' && 'content' in change)) {
|
|
573
|
-
const content = shellRelative(change.content, change.path, handle, definition)?.content ?? change.content;
|
|
574
|
-
return content === change.content ? change : { ...change, content };
|
|
575
|
-
}
|
|
576
|
-
if (change.kind !== 'create')
|
|
577
|
-
return change;
|
|
578
|
-
const type = typeof change.fields.type === 'string' ? change.fields.type : undefined;
|
|
579
|
-
const fields = Object.fromEntries(Object.entries(change.fields).map(([name, value]) => [
|
|
580
|
-
name,
|
|
581
|
-
relativeField(change.path, name, value, handle, definition(type)),
|
|
582
|
-
]));
|
|
583
|
-
const sections = Object.fromEntries(Object.entries(change.sections).map(([name, value]) => [name, body(change.path, value)]));
|
|
584
|
-
return { ...change, fields, sections };
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
function* unmodeledType(collection, composition) {
|
|
588
|
-
if (available(composition))
|
|
589
|
-
return false;
|
|
590
|
-
for (const [path, document] of yield* documentsOf(collection)) {
|
|
591
|
-
if (document.type !== undefined &&
|
|
592
|
-
document.type !== 'any' &&
|
|
593
|
-
governing(composition, path).status === 'unavailable')
|
|
594
|
-
return true;
|
|
595
|
-
yield ROW_WEIGHT + collection.text[path].length;
|
|
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 } };
|
|
596
548
|
}
|
|
597
|
-
|
|
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
|
+
};
|
|
598
571
|
}
|
|
599
572
|
function unqueueable(file) {
|
|
600
|
-
return
|
|
601
|
-
}
|
|
602
|
-
function isPart(change) {
|
|
603
|
-
return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
|
|
573
|
+
return refuse('unknown-revision', file);
|
|
604
574
|
}
|
|
605
575
|
function touched(change) {
|
|
606
576
|
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
607
577
|
}
|
|
608
|
-
function partsApplied(content, path, changes) {
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
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();
|
|
614
584
|
for (const change of changes) {
|
|
615
|
-
if (change
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
name: change.name,
|
|
626
|
-
value: change.value,
|
|
627
|
-
prior: document.sections[change.name] ?? '',
|
|
628
|
-
});
|
|
629
|
-
else
|
|
630
|
-
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]);
|
|
587
|
+
}
|
|
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);
|
|
631
595
|
}
|
|
632
|
-
|
|
633
|
-
|
|
596
|
+
return null;
|
|
597
|
+
}
|
|
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;
|
|
634
602
|
}
|
|
635
|
-
function settledParts(changes, deferred) {
|
|
603
|
+
function settledParts(changes, deferred, composition) {
|
|
636
604
|
for (const [held, parts] of deferred) {
|
|
637
|
-
const content = partsApplied(held.content, held.path, parts);
|
|
605
|
+
const content = partsApplied(held.content, held.path, parts, composition);
|
|
638
606
|
if (content === null)
|
|
639
607
|
return held.path;
|
|
640
608
|
changes[changes.indexOf(held)] = { ...held, content };
|
|
@@ -709,7 +677,9 @@ function* relinked(batch, move, before, after, appending) {
|
|
|
709
677
|
for (const change of derived.changes) {
|
|
710
678
|
if (change === move)
|
|
711
679
|
continue;
|
|
712
|
-
const unsettled = isPart(change)
|
|
680
|
+
const unsettled = isPart(change)
|
|
681
|
+
? null
|
|
682
|
+
: settledParts(changes, deferred, after.collection.composition);
|
|
713
683
|
if (unsettled !== null)
|
|
714
684
|
return unqueueable(unsettled);
|
|
715
685
|
const outcome = folded(changes, change, appending, deferred);
|
|
@@ -720,7 +690,7 @@ function* relinked(batch, move, before, after, appending) {
|
|
|
720
690
|
if (outcome !== 'skipped')
|
|
721
691
|
changed = true;
|
|
722
692
|
}
|
|
723
|
-
const unsettled = settledParts(changes, deferred);
|
|
693
|
+
const unsettled = settledParts(changes, deferred, after.collection.composition);
|
|
724
694
|
if (unsettled !== null)
|
|
725
695
|
return unqueueable(unsettled);
|
|
726
696
|
if (!changed)
|
|
@@ -781,11 +751,10 @@ function withdrawnFile(batch, change, at) {
|
|
|
781
751
|
];
|
|
782
752
|
return immutable({ ...batch, id: changeBatchIdentity(), changes, preconditions });
|
|
783
753
|
}
|
|
784
|
-
|
|
754
|
+
function* requeuing(queue, changes, visible, changeable, state) {
|
|
785
755
|
const next = [...queue];
|
|
786
756
|
const origins = new Map();
|
|
787
757
|
const withdrawn = new Map();
|
|
788
|
-
const owners = new Set();
|
|
789
758
|
const queued = new Set();
|
|
790
759
|
const kept = [];
|
|
791
760
|
const originOf = (batch) => origins.get(batch) ?? batch.id;
|
|
@@ -831,7 +800,6 @@ export function* requeuing(queue, changes, visible, changeable, state) {
|
|
|
831
800
|
if (replaced !== null)
|
|
832
801
|
origins.set(replaced, origin);
|
|
833
802
|
}
|
|
834
|
-
owners.add(originOf(owner));
|
|
835
803
|
next.splice(index, following.length, ...rebuilt.filter((batch) => batch !== null));
|
|
836
804
|
queued.add(change.path);
|
|
837
805
|
}
|
|
@@ -841,91 +809,65 @@ export function* requeuing(queue, changes, visible, changeable, state) {
|
|
|
841
809
|
changes: kept,
|
|
842
810
|
queued,
|
|
843
811
|
withdrawn,
|
|
844
|
-
owners,
|
|
845
812
|
};
|
|
846
813
|
}
|
|
847
|
-
function
|
|
848
|
-
return precondition.kind === 'field' ||
|
|
849
|
-
precondition.kind === 'section' ||
|
|
850
|
-
precondition.kind === 'preamble'
|
|
851
|
-
? identity(precondition)
|
|
852
|
-
: `path ${precondition.path}`;
|
|
853
|
-
}
|
|
854
|
-
export function joined(queue, owner, extra) {
|
|
855
|
-
const later = new Set(queue.slice(queue.indexOf(owner) + 1).flatMap((batch) => batch.changes.flatMap(touched)));
|
|
856
|
-
const clash = extra.changes.flatMap(touched).find((path) => later.has(path));
|
|
857
|
-
if (clash !== undefined)
|
|
858
|
-
return unqueueable(clash);
|
|
859
|
-
const changes = [...owner.changes];
|
|
860
|
-
const deferred = new Map();
|
|
861
|
-
for (const change of extra.changes) {
|
|
862
|
-
const unsettled = isPart(change) ? null : settledParts(changes, deferred);
|
|
863
|
-
if (unsettled !== null)
|
|
864
|
-
return unqueueable(unsettled);
|
|
865
|
-
if (folded(changes, change, true, deferred) === 'refused')
|
|
866
|
-
return unqueueable(change.path);
|
|
867
|
-
}
|
|
868
|
-
const unsettled = settledParts(changes, deferred);
|
|
869
|
-
if (unsettled !== null)
|
|
870
|
-
return unqueueable(unsettled);
|
|
871
|
-
const held = new Set(owner.preconditions.map(covering));
|
|
872
|
-
const written = new Set(owner.changes.flatMap((change) => change.kind === 'create' || change.kind === 'replace' ? [change.path] : []));
|
|
873
|
-
const preconditions = [
|
|
874
|
-
...owner.preconditions,
|
|
875
|
-
...extra.preconditions.filter((precondition) => {
|
|
876
|
-
const key = covering(precondition);
|
|
877
|
-
return (!held.has(key) && (key === `path ${precondition.path}` || !written.has(precondition.path)));
|
|
878
|
-
}),
|
|
879
|
-
];
|
|
880
|
-
const batch = immutable({
|
|
881
|
-
...owner,
|
|
882
|
-
...(extra.validation === undefined ? {} : { validation: extra.validation }),
|
|
883
|
-
id: changeBatchIdentity(),
|
|
884
|
-
changes,
|
|
885
|
-
preconditions,
|
|
886
|
-
});
|
|
887
|
-
return { kind: 'joined', batch, queue: queue.map((item) => (item === owner ? batch : item)) };
|
|
888
|
-
}
|
|
889
|
-
export function* limiting(queue, batch, limits, state) {
|
|
814
|
+
function* limiting(queue, batch, limits, state) {
|
|
890
815
|
const at = queue.indexOf(batch);
|
|
891
816
|
const rewritten = yield* providerRewritten(batch, yield* state(queue.slice(0, at)));
|
|
892
817
|
const limited = yield* exceeding(limits, batch.changes, rewritten.changes, yield* state(queue.slice(0, at + 1)));
|
|
893
|
-
return limited?.
|
|
818
|
+
return limited?.refusal ?? null;
|
|
894
819
|
}
|
|
895
|
-
function
|
|
896
|
-
|
|
897
|
-
return false;
|
|
898
|
-
const parsed = parse(content);
|
|
899
|
-
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
820
|
+
function typedContent(content) {
|
|
821
|
+
return content !== undefined && typedText(parse(content));
|
|
900
822
|
}
|
|
901
|
-
function
|
|
823
|
+
function touchedLibrary(resulting, touched, composition) {
|
|
824
|
+
const entries = touched
|
|
825
|
+
.flatMap((path) => {
|
|
826
|
+
const content = resulting.documents[path];
|
|
827
|
+
const binary = resulting.binaries[path] !== undefined;
|
|
828
|
+
return content === undefined && !binary ? [] : [{ path, content: content ?? null }];
|
|
829
|
+
})
|
|
830
|
+
.sort((left, right) => (left.path < right.path ? -1 : left.path > right.path ? 1 : 0));
|
|
831
|
+
const contents = new Map(entries.map(({ path, content }) => [path, content]));
|
|
832
|
+
const binaries = new Set(Array.from(entriesIn(resulting.binaries), ([path]) => path));
|
|
833
|
+
return validatedCollection(() => Promise.resolve({ entries, next: null }), async (paths) => {
|
|
834
|
+
const known = new Map();
|
|
835
|
+
const pace = paced();
|
|
836
|
+
for (const path of paths) {
|
|
837
|
+
const content = contents.get(path);
|
|
838
|
+
if (binaries.has(path))
|
|
839
|
+
known.set(path, { type: undefined, binary: true });
|
|
840
|
+
else if (content !== undefined && content !== null) {
|
|
841
|
+
const type = textType(parse(content, path, definitionsAt(composition, path)));
|
|
842
|
+
if (type !== undefined)
|
|
843
|
+
known.set(path, { type, binary: false });
|
|
844
|
+
await pace(content.length + ROW_WEIGHT);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
return known;
|
|
848
|
+
}, composition);
|
|
849
|
+
}
|
|
850
|
+
async function judging(visible, resulting, composition, validate, removed, touched) {
|
|
902
851
|
if (removed.size > 0) {
|
|
903
|
-
const
|
|
904
|
-
const referenced = yield* incoming(collectionOf(resulting.documents, composition), removed, clean === null || referrers === null
|
|
905
|
-
? null
|
|
906
|
-
: chained(referrers, yield* differences(clean.text, resulting.documents)));
|
|
852
|
+
const referenced = await stepped(incoming(collectionOf(resulting.documents, composition), removed, null));
|
|
907
853
|
if (referenced !== null)
|
|
908
854
|
return referenced;
|
|
909
855
|
}
|
|
910
856
|
const typedPaths = [];
|
|
857
|
+
const pace = paced();
|
|
911
858
|
for (const path of touched) {
|
|
912
859
|
const before = visible.documents[path];
|
|
913
860
|
const after = resulting.documents[path];
|
|
914
|
-
if (
|
|
861
|
+
if (typedContent(before) || typedContent(after))
|
|
915
862
|
typedPaths.push(path);
|
|
916
|
-
|
|
863
|
+
await pace((before?.length ?? 0) + (after?.length ?? 0) + ROW_WEIGHT);
|
|
917
864
|
}
|
|
918
865
|
const withoutModel = typedPaths.find((path) => governing(composition, path).status === 'unavailable');
|
|
919
866
|
if (withoutModel !== undefined)
|
|
920
867
|
return refuse('model-unavailable', withoutModel);
|
|
921
|
-
const verdict =
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
: yield* validateCollection(typedPaths.length > 0
|
|
925
|
-
? resulting.documents
|
|
926
|
-
: Object.fromEntries(touched.flatMap((path) => resulting.documents[path] === undefined
|
|
927
|
-
? []
|
|
928
|
-
: [[path, resulting.documents[path]]])), Object.keys(resulting.binaries), composition);
|
|
868
|
+
const verdict = typedPaths.length > 0
|
|
869
|
+
? await validate(resulting, touched)
|
|
870
|
+
: await touchedLibrary(resulting, touched, composition);
|
|
929
871
|
if (verdict.verdict === 'refuse') {
|
|
930
872
|
return {
|
|
931
873
|
kind: 'refused',
|
|
@@ -934,6 +876,7 @@ function* judging(visible, resulting, composition, clean, removed, touched) {
|
|
|
934
876
|
retryable: false,
|
|
935
877
|
file: verdict.file,
|
|
936
878
|
...(verdict.location === undefined ? {} : { location: verdict.location }),
|
|
879
|
+
...(verdict.line === undefined ? {} : { line: verdict.line }),
|
|
937
880
|
...(verdict.referrers === undefined ? {} : { referrers: verdict.referrers }),
|
|
938
881
|
},
|
|
939
882
|
};
|
|
@@ -949,8 +892,6 @@ function placed(reference) {
|
|
|
949
892
|
const key = roomPathOf(reference.handle, reference.path);
|
|
950
893
|
if (reference.kind === 'link')
|
|
951
894
|
return `link ${key}`;
|
|
952
|
-
if (reference.kind === 'item')
|
|
953
|
-
return `section ${reference.section} ${key}`;
|
|
954
895
|
const pointer = reference.pointer
|
|
955
896
|
.split('/')
|
|
956
897
|
.map((segment) => (ARRAY_INDEX.test(segment) ? '-' : segment))
|
|
@@ -960,10 +901,11 @@ function placed(reference) {
|
|
|
960
901
|
function roomReferencesIn(path, content, composition) {
|
|
961
902
|
if (content === undefined)
|
|
962
903
|
return [];
|
|
963
|
-
const
|
|
904
|
+
const definitions = definitionsAt(composition, path);
|
|
905
|
+
const parsed = parse(content, path, definitions);
|
|
964
906
|
if (!parsed.ok)
|
|
965
907
|
return [];
|
|
966
|
-
return roomReferences(
|
|
908
|
+
return roomReferences(parsed.document, definitions(parsed.document.type));
|
|
967
909
|
}
|
|
968
910
|
function* admittedRooms(changes, visible, resulting, composition) {
|
|
969
911
|
const from = new Map();
|
|
@@ -981,7 +923,7 @@ function* admittedRooms(changes, visible, resulting, composition) {
|
|
|
981
923
|
continue;
|
|
982
924
|
if (held.has(placed(reference)))
|
|
983
925
|
continue;
|
|
984
|
-
return refuse('unresolved-reference', path, reference.
|
|
926
|
+
return refuse('unresolved-reference', path, reference.pointer);
|
|
985
927
|
}
|
|
986
928
|
yield ROW_WEIGHT + now.length;
|
|
987
929
|
}
|
|
@@ -998,32 +940,33 @@ function validationOf(validated) {
|
|
|
998
940
|
},
|
|
999
941
|
};
|
|
1000
942
|
}
|
|
1001
|
-
function
|
|
1002
|
-
const
|
|
943
|
+
async function batching(input) {
|
|
944
|
+
const relative = relativeChanges(input);
|
|
945
|
+
if (relative.kind === 'refused')
|
|
946
|
+
return relative;
|
|
947
|
+
const { changes } = relative;
|
|
1003
948
|
const structural = changes.find((change) => change.kind === 'move' || change.kind === 'remove');
|
|
1004
|
-
if (structural !== undefined &&
|
|
1005
|
-
(yield* unmodeledType(input.visible.collection, input.composition)))
|
|
949
|
+
if (structural !== undefined && input.unmodeled) {
|
|
1006
950
|
return refuse('model-unavailable', structural.path);
|
|
951
|
+
}
|
|
1007
952
|
if (changes.length === 0)
|
|
1008
953
|
return refuse('no-change');
|
|
1009
|
-
const rewritten =
|
|
954
|
+
const rewritten = await stepped(rewrites(changes, input.visible));
|
|
1010
955
|
if (rewritten.kind === 'refused')
|
|
1011
956
|
return rewritten;
|
|
1012
|
-
const refusal = guard(changes, input,
|
|
957
|
+
const refusal = guard(changes, input, WRITE) ?? unapplied(changes, input.visible, input.composition);
|
|
1013
958
|
if (refusal !== null)
|
|
1014
959
|
return refusal;
|
|
1015
|
-
const preconditions =
|
|
1016
|
-
const predicted =
|
|
1017
|
-
const resulting =
|
|
1018
|
-
|
|
1019
|
-
]);
|
|
1020
|
-
const judged = yield* judging(input.visible, resulting, input.composition, input.clean !== undefined && available(input.composition) ? input.clean : null, new Set(changes.filter((change) => change.kind === 'remove').map((change) => change.path)), [...new Set(predicted.changes.flatMap(affected))]);
|
|
960
|
+
const preconditions = await stepped(preconditionsOf(changes, input.visible, input.bases));
|
|
961
|
+
const predicted = await stepped(anticipated(changes, preconditions, rewritten.changes, input.visible));
|
|
962
|
+
const resulting = await stepped(overlaying(input.visible, [{ id: '', baseRoomVersion: input.baseRoomVersion, ...predicted }], input.composition));
|
|
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))]);
|
|
1021
964
|
if (judged.kind === 'refused')
|
|
1022
965
|
return judged;
|
|
1023
|
-
const crossing =
|
|
966
|
+
const crossing = await stepped(admittedRooms(changes, input.visible, resulting, input.composition));
|
|
1024
967
|
if (crossing !== null)
|
|
1025
968
|
return crossing;
|
|
1026
|
-
const limited =
|
|
969
|
+
const limited = await stepped(exceeding(input.providerLimits, changes, predicted.changes, resulting));
|
|
1027
970
|
if (limited !== null)
|
|
1028
971
|
return limited;
|
|
1029
972
|
return {
|
|
@@ -1038,7 +981,7 @@ function* batching(input) {
|
|
|
1038
981
|
}),
|
|
1039
982
|
};
|
|
1040
983
|
}
|
|
1041
|
-
|
|
984
|
+
const MOVE_DOCUMENTS = 'move-documents';
|
|
1042
985
|
function heldAt(visible, path) {
|
|
1043
986
|
return visible.documents[path] !== undefined || visible.binaries[path] !== undefined;
|
|
1044
987
|
}
|
|
@@ -1047,7 +990,7 @@ function arrivingText(path, to, source, moved) {
|
|
|
1047
990
|
const document = source.visible.collection.document(path);
|
|
1048
991
|
if (document === undefined)
|
|
1049
992
|
return content;
|
|
1050
|
-
const definition =
|
|
993
|
+
const definition = definitionsAt(source.composition, path)(document.type);
|
|
1051
994
|
const changes = crossed(document, definition, path, (named, href) => {
|
|
1052
995
|
const at = moved.get(named);
|
|
1053
996
|
if (at !== undefined)
|
|
@@ -1056,13 +999,14 @@ function arrivingText(path, to, source, moved) {
|
|
|
1056
999
|
});
|
|
1057
1000
|
if (changes.length === 0)
|
|
1058
1001
|
return content;
|
|
1059
|
-
const applied = apply(document, changes);
|
|
1002
|
+
const applied = apply(document, changes, definition);
|
|
1060
1003
|
return applied.outcome === 'applied' ? serialize(applied.document) : content;
|
|
1061
1004
|
}
|
|
1062
1005
|
function arrivalOf({ path, to }, source, moved) {
|
|
1063
|
-
const { documents, revisions, fileIds, changes, binaries } = source.visible;
|
|
1006
|
+
const { documents, revisions, fileIds, created, changes, binaries } = source.visible;
|
|
1064
1007
|
const kept = {
|
|
1065
1008
|
...(fileIds[path] === undefined ? {} : { fileId: fileIds[path] }),
|
|
1009
|
+
...(created[path] === undefined ? {} : { created: created[path] }),
|
|
1066
1010
|
...(changes[path] === undefined ? {} : { change: changes[path] }),
|
|
1067
1011
|
};
|
|
1068
1012
|
const heads = {
|
|
@@ -1071,11 +1015,11 @@ function arrivalOf({ path, to }, source, moved) {
|
|
|
1071
1015
|
};
|
|
1072
1016
|
const binary = binaries[path];
|
|
1073
1017
|
if (binary?.state === 'accepted') {
|
|
1074
|
-
const {
|
|
1018
|
+
const { byteLength, mediaType, sha256 } = binary;
|
|
1075
1019
|
return {
|
|
1076
1020
|
kind: 'arrival',
|
|
1077
1021
|
path: to,
|
|
1078
|
-
binary: {
|
|
1022
|
+
binary: { byteLength, mediaType, sha256 },
|
|
1079
1023
|
...heads,
|
|
1080
1024
|
};
|
|
1081
1025
|
}
|
|
@@ -1087,12 +1031,10 @@ function arrivalOf({ path, to }, source, moved) {
|
|
|
1087
1031
|
...(content === documents[path] ? heads : kept),
|
|
1088
1032
|
};
|
|
1089
1033
|
}
|
|
1090
|
-
function
|
|
1034
|
+
async function moving(input) {
|
|
1091
1035
|
const { source, destination, moves } = input;
|
|
1092
|
-
if (moves.length === 0)
|
|
1093
|
-
return refuse('no-change');
|
|
1094
1036
|
const removals = moves.map(({ path }) => ({ kind: 'remove', path }));
|
|
1095
|
-
const leaves = guard(removals, { ...source, local: input.local, bases: [] },
|
|
1037
|
+
const leaves = guard(removals, { ...source, local: input.local, bases: [] }, MOVE_OUT);
|
|
1096
1038
|
if (leaves !== null)
|
|
1097
1039
|
return leaves;
|
|
1098
1040
|
const uploading = moves.find(({ path }) => source.visible.binaries[path]?.state === 'pending');
|
|
@@ -1100,16 +1042,15 @@ function* moving(input) {
|
|
|
1100
1042
|
return refuse('unknown-revision', uploading.path);
|
|
1101
1043
|
const moved = new Map(moves.map(({ path, to }) => [path, to]));
|
|
1102
1044
|
const arrivals = moves.map((move) => arrivalOf(move, source, moved));
|
|
1103
|
-
const arrives = guard(arrivals, { ...destination, local: input.local, bases: [] },
|
|
1045
|
+
const arrives = guard(arrivals, { ...destination, local: input.local, bases: [] }, WRITE);
|
|
1104
1046
|
if (arrives !== null)
|
|
1105
1047
|
return arrives;
|
|
1106
1048
|
const bound = input.providerLimits.find((limit) => limit.name === MOVE_DOCUMENTS)?.value;
|
|
1107
1049
|
if (typeof bound === 'number' && moves.length > bound) {
|
|
1108
1050
|
return refuse('provider-limit', undefined, MOVE_DOCUMENTS);
|
|
1109
1051
|
}
|
|
1110
|
-
if (
|
|
1052
|
+
if (source.unmodeled)
|
|
1111
1053
|
return refuse('model-unavailable', moves[0].path);
|
|
1112
|
-
}
|
|
1113
1054
|
const id = changeBatchIdentity();
|
|
1114
1055
|
const between = {
|
|
1115
1056
|
source: { room: source.room, baseRoomVersion: source.baseRoomVersion },
|
|
@@ -1129,9 +1070,9 @@ function* moving(input) {
|
|
|
1129
1070
|
...written,
|
|
1130
1071
|
between,
|
|
1131
1072
|
};
|
|
1132
|
-
const effective =
|
|
1133
|
-
const left =
|
|
1134
|
-
const sourceJudged =
|
|
1073
|
+
const effective = await stepped(leavingRewritten(leavingBatch, source.visible));
|
|
1074
|
+
const left = await stepped(overlaying(source.visible, [effective], source.composition));
|
|
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))]);
|
|
1135
1076
|
if (sourceJudged.kind === 'refused')
|
|
1136
1077
|
return sourceJudged;
|
|
1137
1078
|
const arrivingBatch = {
|
|
@@ -1142,19 +1083,190 @@ function* moving(input) {
|
|
|
1142
1083
|
...written,
|
|
1143
1084
|
between,
|
|
1144
1085
|
};
|
|
1145
|
-
const arrived =
|
|
1146
|
-
const destinationJudged =
|
|
1086
|
+
const arrived = await stepped(overlaying(destination.visible, [arrivingBatch], destination.composition));
|
|
1087
|
+
const destinationJudged = await judging(destination.visible, arrived, destination.composition, destination.validate, new Set(), moves.map(({ to }) => to));
|
|
1147
1088
|
if (destinationJudged.kind === 'refused')
|
|
1148
1089
|
return destinationJudged;
|
|
1149
|
-
const limited = (
|
|
1150
|
-
(
|
|
1090
|
+
const limited = (await stepped(exceeding(input.providerLimits, removals, effective.changes, left))) ??
|
|
1091
|
+
(await stepped(exceeding(input.providerLimits, arrivals, arrivals, arrived)));
|
|
1151
1092
|
if (limited !== null)
|
|
1152
1093
|
return limited;
|
|
1153
1094
|
return { kind: 'moved', leaving: immutable(leavingBatch), arriving: immutable(arrivingBatch) };
|
|
1154
1095
|
}
|
|
1155
|
-
|
|
1156
|
-
|
|
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;
|
|
1157
1269
|
}
|
|
1158
|
-
export function
|
|
1159
|
-
return
|
|
1270
|
+
export function planSave(ask, room, into) {
|
|
1271
|
+
return into === undefined ? plannedWithin(ask, room) : plannedMove(ask, room, into);
|
|
1160
1272
|
}
|