@agentshouse/mdruntime 0.1.0-cfe148b32e3d8 → 0.1.0-cfef69803eb1c
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 -20
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +328 -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 +345 -0
- package/dist/adapter.d.ts +304 -122
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +4 -11
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +33 -49
- package/dist/{binary.d.ts → attachment.d.ts} +8 -4
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +15 -0
- 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 +17 -16
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +269 -158
- 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 +3 -2
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- 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 +7 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +7 -2
- 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 +52 -29
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +65 -28
- package/dist/collection.d.ts +33 -7
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +50 -21
- 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 +10 -7
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +349 -315
- package/dist/connection.d.ts +6 -141
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +119 -5015
- 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 +260 -0
- package/dist/conversation-row.d.ts +55 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +82 -0
- package/dist/conversation.d.ts +84 -54
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +1045 -825
- 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 +12 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +175 -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 +20 -5
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +12 -0
- package/dist/entry.d.ts +29 -3
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +134 -34
- 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 -11
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -4
- 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 +25 -8
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +155 -59
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +102 -0
- package/dist/identity.d.ts +1 -2
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -4
- package/dist/index.d.ts +49 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -8
- 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 +292 -0
- package/dist/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +16 -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 +23 -6
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +138 -38
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +34 -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 +24 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +365 -0
- package/dist/memory.d.ts +21 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +300 -110
- package/dist/messages.d.ts +44 -5
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +129 -39
- 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 +15 -15
- 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 +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +31 -13
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +219 -82
- 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 +6 -6
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +7 -7
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +71 -0
- package/dist/outcome.d.ts +46 -15
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +52 -5
- package/dist/overlay.d.ts +24 -8
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +143 -48
- 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 +7 -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 +46 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +344 -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 +330 -0
- package/dist/query.d.ts +20 -210
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- 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} +14 -8
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +482 -0
- package/dist/reach.d.ts +31 -13
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +382 -135
- package/dist/react.d.ts +27 -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 +28 -28
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +20 -18
- package/dist/reads.d.ts +38 -10
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +174 -85
- 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 +10 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +92 -34
- 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 +13 -25
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +71 -40
- 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 +405 -115
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +222 -0
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +47 -0
- package/dist/rows.d.ts +28 -18
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +65 -160
- package/dist/run-tables.d.ts +25 -0
- package/dist/run-tables.d.ts.map +1 -0
- package/dist/run-tables.js +98 -0
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runs.d.ts +27 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +92 -0
- package/dist/runtime.d.ts +37 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +43 -84
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +342 -232
- package/dist/saves.d.ts +34 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +464 -0
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shared.d.ts +1 -7
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -105
- package/dist/shown.d.ts +35 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +327 -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 +41 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +26 -0
- package/dist/socket.d.ts +70 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +172 -0
- package/dist/source.d.ts +96 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +149 -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 +234 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +474 -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 -157
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +174 -400
- package/dist/stored.d.ts +96 -60
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +531 -291
- package/dist/surface.d.ts +100 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +258 -0
- package/dist/sync.d.ts +21 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +557 -0
- package/dist/tables.d.ts +162 -104
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +276 -332
- 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/validation.d.ts +5 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +87 -105
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +92 -16
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +38 -14
- package/package.json +13 -19
- package/AGENTS.md +0 -317
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- 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 -92
- 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 -20
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -229
- package/dist/chat/message.d.ts +0 -7
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -254
- package/dist/chat/messages.d.ts +0 -35
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -210
- 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 -103
- package/dist/chat/parts.d.ts +0 -58
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/parts.js +0 -120
- 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 -70
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -635
- 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 -37
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -93
- package/dist/chat/room-file.d.ts +0 -8
- package/dist/chat/room-file.d.ts.map +0 -1
- package/dist/chat/room-file.js +0 -72
- 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 -307
- 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/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -368
- package/dist/log.d.ts +0 -5
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -150
package/dist/save.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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, typeAt, UNTYPED, } 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
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,13 +16,14 @@ 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
|
-
const parsed = parse(document.content, from);
|
|
24
|
-
if (!parsed.ok)
|
|
25
|
-
return [];
|
|
26
27
|
const changes = [];
|
|
27
28
|
const names = new Set();
|
|
28
29
|
for (const { pointer, value } of definition === undefined
|
|
@@ -45,43 +46,13 @@ function repointed(document, definition, from, to, moves, settled) {
|
|
|
45
46
|
}
|
|
46
47
|
if (changes.length === 0)
|
|
47
48
|
return [];
|
|
48
|
-
const applied = apply(
|
|
49
|
+
const applied = apply(document, changes, definition);
|
|
49
50
|
if (applied.outcome !== 'applied')
|
|
50
51
|
return [];
|
|
51
52
|
const next = applied.document;
|
|
52
53
|
return [...names].map((name) => ({ kind: 'field', path: from, name, value: next.fields[name] }));
|
|
53
54
|
}
|
|
54
|
-
function
|
|
55
|
-
const parts = new Map();
|
|
56
|
-
for (const change of changes) {
|
|
57
|
-
if (change.kind === 'preamble')
|
|
58
|
-
parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
|
|
59
|
-
if (change.kind === 'section')
|
|
60
|
-
parts.set(`section ${change.name}`, {
|
|
61
|
-
kind: 'section',
|
|
62
|
-
name: change.name,
|
|
63
|
-
value: change.value,
|
|
64
|
-
prior: document.sections[change.name] ?? '',
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (parts.size === 0)
|
|
68
|
-
return document;
|
|
69
|
-
const applied = apply(document, [...parts.values()]);
|
|
70
|
-
return applied.outcome === 'applied' ? applied.document : document;
|
|
71
|
-
}
|
|
72
|
-
function bodies(path, before, after) {
|
|
73
|
-
const changes = [];
|
|
74
|
-
if (after.preamble !== before.preamble) {
|
|
75
|
-
changes.push({ kind: 'preamble', path, value: after.preamble });
|
|
76
|
-
}
|
|
77
|
-
for (const [name, value] of Object.entries(after.sections)) {
|
|
78
|
-
if (before.sections[name] === value)
|
|
79
|
-
continue;
|
|
80
|
-
changes.push({ kind: 'section', path, name, value });
|
|
81
|
-
}
|
|
82
|
-
return changes;
|
|
83
|
-
}
|
|
84
|
-
function relinks(path, moved, before, moves) {
|
|
55
|
+
function relinks(path, moved, before, moves, definition) {
|
|
85
56
|
const changes = [];
|
|
86
57
|
for (const link of links(before, path)) {
|
|
87
58
|
const destination = moves.get(link.target) ?? link.target;
|
|
@@ -94,28 +65,30 @@ function relinks(path, moved, before, moves) {
|
|
|
94
65
|
}
|
|
95
66
|
if (changes.length === 0)
|
|
96
67
|
return { kind: 'changes', changes: [] };
|
|
97
|
-
const applied = apply(before, changes);
|
|
98
|
-
if (applied.outcome === 'refuse')
|
|
99
|
-
return
|
|
100
|
-
kind: 'refused',
|
|
101
|
-
refusal: {
|
|
102
|
-
code: applied.refusal.rule,
|
|
103
|
-
retryable: false,
|
|
104
|
-
file: path,
|
|
105
|
-
...(applied.refusal.location === undefined ? {} : { location: applied.refusal.location }),
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
}
|
|
68
|
+
const applied = apply(before, changes, definition);
|
|
69
|
+
if (applied.outcome === 'refuse')
|
|
70
|
+
return refusedBy(applied.refusal, path);
|
|
109
71
|
const after = applied.document;
|
|
110
72
|
if (after === before)
|
|
111
73
|
return { kind: 'changes', changes: [] };
|
|
112
74
|
if (before.type === undefined) {
|
|
113
75
|
return { kind: 'changes', changes: [{ kind: 'replace', path, content: serialize(after) }] };
|
|
114
76
|
}
|
|
115
|
-
return { kind: 'changes', changes:
|
|
77
|
+
return { kind: 'changes', changes: partsBetween(path, before, after) };
|
|
116
78
|
}
|
|
117
79
|
function partKey(change) {
|
|
118
|
-
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));
|
|
119
92
|
}
|
|
120
93
|
function* rewrites(changes, visible) {
|
|
121
94
|
const moves = new Map();
|
|
@@ -142,17 +115,21 @@ function* rewrites(changes, visible) {
|
|
|
142
115
|
}
|
|
143
116
|
if (moves.size === 0)
|
|
144
117
|
return { kind: 'changes', changes };
|
|
118
|
+
const names = movedNames(moves);
|
|
145
119
|
const merged = [...changes];
|
|
146
120
|
const added = [];
|
|
147
121
|
for (const [path, document] of yield* documentsOf(visible.collection)) {
|
|
148
122
|
if (settled.has(path))
|
|
149
123
|
continue;
|
|
150
124
|
const moved = moves.get(path) ?? path;
|
|
151
|
-
const definition =
|
|
125
|
+
const definition = definitionsAt(visible.collection.composition, path)(document.type);
|
|
152
126
|
const repointing = repointed(document, definition, path, moved, moves, settled);
|
|
153
127
|
added.push(...repointing);
|
|
154
128
|
const own = parts.get(path) ?? [];
|
|
155
|
-
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);
|
|
156
133
|
if (relinked.kind === 'refused')
|
|
157
134
|
return relinked;
|
|
158
135
|
const keyed = new Map();
|
|
@@ -165,7 +142,7 @@ function* rewrites(changes, visible) {
|
|
|
165
142
|
if (change.kind === 'replace') {
|
|
166
143
|
for (const index of own) {
|
|
167
144
|
const kind = merged[index]?.kind;
|
|
168
|
-
if (kind === 'section' || kind === 'preamble')
|
|
145
|
+
if (kind === 'field' || kind === 'section' || kind === 'preamble')
|
|
169
146
|
merged[index] = null;
|
|
170
147
|
}
|
|
171
148
|
added.push(change);
|
|
@@ -221,25 +198,21 @@ function crossed(document, definition, path, to) {
|
|
|
221
198
|
}
|
|
222
199
|
return changes;
|
|
223
200
|
}
|
|
224
|
-
function rewritten(path, document, changes) {
|
|
201
|
+
function rewritten(path, document, changes, definition) {
|
|
225
202
|
if (changes.length === 0)
|
|
226
203
|
return [];
|
|
227
|
-
const applied = apply(document, changes);
|
|
204
|
+
const applied = apply(document, changes, definition);
|
|
228
205
|
if (applied.outcome !== 'applied')
|
|
229
206
|
return [];
|
|
230
207
|
const after = applied.document;
|
|
231
208
|
if (document.type === undefined)
|
|
232
209
|
return [{ kind: 'replace', path, content: serialize(after) }];
|
|
233
|
-
|
|
234
|
-
return [
|
|
235
|
-
...[...names].map((name) => ({ kind: 'field', path, name, value: after.fields[name] })),
|
|
236
|
-
...bodies(path, document, after),
|
|
237
|
-
];
|
|
210
|
+
return partsBetween(path, document, after);
|
|
238
211
|
}
|
|
239
212
|
function roomPathOf(handle, path) {
|
|
240
213
|
return `/rooms/${handle}/${path}`;
|
|
241
214
|
}
|
|
242
|
-
|
|
215
|
+
function* leavingRewritten(batch, visible) {
|
|
243
216
|
const between = batch.between;
|
|
244
217
|
if (between === undefined)
|
|
245
218
|
return batch;
|
|
@@ -248,8 +221,8 @@ export function* leavingRewritten(batch, visible) {
|
|
|
248
221
|
for (const [path, document] of yield* documentsOf(visible.collection)) {
|
|
249
222
|
if (moved.has(path))
|
|
250
223
|
continue;
|
|
251
|
-
const definition =
|
|
252
|
-
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));
|
|
253
226
|
yield ROW_WEIGHT + visible.collection.text[path].length;
|
|
254
227
|
}
|
|
255
228
|
if (derived.length === 0)
|
|
@@ -291,7 +264,7 @@ function* incoming(collection, removed, candidates) {
|
|
|
291
264
|
for (const [path, document] of candidates === null
|
|
292
265
|
? yield* documentsOf(collection)
|
|
293
266
|
: read(candidates)) {
|
|
294
|
-
const definition =
|
|
267
|
+
const definition = definitionsAt(collection.composition, path)(document.type);
|
|
295
268
|
for (const { value, to } of definition === undefined ? [] : references(document, definition)) {
|
|
296
269
|
if (to.includes(ATTACHMENT))
|
|
297
270
|
continue;
|
|
@@ -321,6 +294,8 @@ function* incoming(collection, removed, candidates) {
|
|
|
321
294
|
function affected(change) {
|
|
322
295
|
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
323
296
|
}
|
|
297
|
+
const WRITE = ['write'];
|
|
298
|
+
const MOVE_OUT = ['write', 'erase'];
|
|
324
299
|
function guard(changes, input, removing) {
|
|
325
300
|
const overridden = new Map();
|
|
326
301
|
const existing = {
|
|
@@ -329,21 +304,17 @@ function guard(changes, input, removing) {
|
|
|
329
304
|
add: (path) => void overridden.set(path, true),
|
|
330
305
|
delete: (path) => void overridden.set(path, false),
|
|
331
306
|
};
|
|
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
|
-
return refuse('provider-owned-path', normalized);
|
|
339
|
-
}
|
|
340
|
-
const operation = change.kind === 'remove' ? removing : 'write';
|
|
341
|
-
if (!input.local && !covered(input.operations[operation], normalized))
|
|
342
|
-
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);
|
|
343
313
|
}
|
|
344
314
|
if (change.kind === 'create' || change.kind === 'arrival') {
|
|
345
|
-
|
|
346
|
-
|
|
315
|
+
const taken = existing.has(change.path) ? change.path : occupied(change.path);
|
|
316
|
+
if (taken !== null)
|
|
317
|
+
return refuse('path-collision', taken);
|
|
347
318
|
existing.add(change.path);
|
|
348
319
|
continue;
|
|
349
320
|
}
|
|
@@ -353,6 +324,9 @@ function guard(changes, input, removing) {
|
|
|
353
324
|
input.bases.some((base) => base.kind === 'absent' && base.path === change.path))) {
|
|
354
325
|
return refuse('path-collision', change.path);
|
|
355
326
|
}
|
|
327
|
+
const taken = occupied(change.path);
|
|
328
|
+
if (taken !== null)
|
|
329
|
+
return refuse('path-collision', taken);
|
|
356
330
|
if (!input.local &&
|
|
357
331
|
existing.has(change.path) &&
|
|
358
332
|
input.visible.revisions[departure(changes, index)] === undefined) {
|
|
@@ -364,8 +338,9 @@ function guard(changes, input, removing) {
|
|
|
364
338
|
if (change.kind === 'move') {
|
|
365
339
|
if (!existing.has(change.path))
|
|
366
340
|
return refuse('path-absent', change.path);
|
|
367
|
-
|
|
368
|
-
|
|
341
|
+
const taken = existing.has(change.to) ? change.to : occupied(change.to);
|
|
342
|
+
if (taken !== null)
|
|
343
|
+
return refuse('path-collision', taken);
|
|
369
344
|
if (unrevised(input, change.path)) {
|
|
370
345
|
return refuse('unknown-revision', change.path);
|
|
371
346
|
}
|
|
@@ -395,9 +370,9 @@ function guard(changes, input, removing) {
|
|
|
395
370
|
return null;
|
|
396
371
|
}
|
|
397
372
|
function unrevised(input, path) {
|
|
398
|
-
return
|
|
373
|
+
return !input.local && !input.queued.has(path) && input.visible.revisions[path] === undefined;
|
|
399
374
|
}
|
|
400
|
-
|
|
375
|
+
function queuedDocuments(queue) {
|
|
401
376
|
const paths = new Set();
|
|
402
377
|
for (const batch of queue) {
|
|
403
378
|
for (const change of batch.changes) {
|
|
@@ -442,7 +417,7 @@ function* preconditionsOf(changes, visible, bases) {
|
|
|
442
417
|
};
|
|
443
418
|
for (const change of changes) {
|
|
444
419
|
yield ROW_WEIGHT;
|
|
445
|
-
if (change
|
|
420
|
+
if (isPart(change)) {
|
|
446
421
|
const based = bases.find((base) => sameTarget(base, change));
|
|
447
422
|
if (based !== undefined) {
|
|
448
423
|
add(based);
|
|
@@ -533,93 +508,101 @@ function* exceeding(limits, changes, effective, resulting) {
|
|
|
533
508
|
function shellRelative(text, path, handle, definition) {
|
|
534
509
|
if (!text.includes(`/rooms/${handle}/`))
|
|
535
510
|
return null;
|
|
536
|
-
const parsed = parse(text, path);
|
|
511
|
+
const parsed = parse(text, path, definition);
|
|
537
512
|
if (!parsed.ok)
|
|
538
513
|
return null;
|
|
539
514
|
const result = relativize(parsed.document, path, handle, definition(parsed.document.type));
|
|
540
515
|
return result.outcome === 'applied' && result.document.content !== text ? result.document : null;
|
|
541
516
|
}
|
|
542
517
|
function relativeField(path, name, value, handle, definition) {
|
|
543
|
-
|
|
544
|
-
if (definition === undefined ||
|
|
545
|
-
!opened.ok ||
|
|
546
|
-
!JSON.stringify(value ?? null).includes(`/rooms/${handle}/`))
|
|
518
|
+
if (definition === undefined || !JSON.stringify(value ?? null).includes(`/rooms/${handle}/`))
|
|
547
519
|
return value;
|
|
548
|
-
const held = apply(
|
|
520
|
+
const held = apply(create(definition.name, definition), [{ kind: 'field', name, value, prior: undefined }], definition);
|
|
549
521
|
if (held.outcome !== 'applied')
|
|
550
522
|
return value;
|
|
551
523
|
const result = relativize(held.document, path, handle, definition);
|
|
552
524
|
return result.outcome === 'applied' ? result.document.fields[name] : value;
|
|
553
525
|
}
|
|
554
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) {
|
|
555
537
|
const { handle, composition, visible } = input;
|
|
556
|
-
const typed = (path) => (type) => definitionOf(governing(composition, path), type);
|
|
557
538
|
const body = (path, text) => shellRelative(text, path, handle, () => undefined)?.content ?? text;
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
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
|
+
};
|
|
583
571
|
}
|
|
584
572
|
function unqueueable(file) {
|
|
585
|
-
return
|
|
586
|
-
}
|
|
587
|
-
function isPart(change) {
|
|
588
|
-
return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
|
|
573
|
+
return refuse('unknown-revision', file);
|
|
589
574
|
}
|
|
590
575
|
function touched(change) {
|
|
591
576
|
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
592
577
|
}
|
|
593
|
-
function partsApplied(content, path, changes) {
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
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();
|
|
599
584
|
for (const change of changes) {
|
|
600
|
-
if (change
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
name: change.name,
|
|
611
|
-
value: change.value,
|
|
612
|
-
prior: document.sections[change.name] ?? '',
|
|
613
|
-
});
|
|
614
|
-
else
|
|
615
|
-
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);
|
|
616
595
|
}
|
|
617
|
-
|
|
618
|
-
|
|
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;
|
|
619
602
|
}
|
|
620
|
-
function settledParts(changes, deferred) {
|
|
603
|
+
function settledParts(changes, deferred, composition) {
|
|
621
604
|
for (const [held, parts] of deferred) {
|
|
622
|
-
const content = partsApplied(held.content, held.path, parts);
|
|
605
|
+
const content = partsApplied(held.content, held.path, parts, composition);
|
|
623
606
|
if (content === null)
|
|
624
607
|
return held.path;
|
|
625
608
|
changes[changes.indexOf(held)] = { ...held, content };
|
|
@@ -694,7 +677,9 @@ function* relinked(batch, move, before, after, appending) {
|
|
|
694
677
|
for (const change of derived.changes) {
|
|
695
678
|
if (change === move)
|
|
696
679
|
continue;
|
|
697
|
-
const unsettled = isPart(change)
|
|
680
|
+
const unsettled = isPart(change)
|
|
681
|
+
? null
|
|
682
|
+
: settledParts(changes, deferred, after.collection.composition);
|
|
698
683
|
if (unsettled !== null)
|
|
699
684
|
return unqueueable(unsettled);
|
|
700
685
|
const outcome = folded(changes, change, appending, deferred);
|
|
@@ -705,7 +690,7 @@ function* relinked(batch, move, before, after, appending) {
|
|
|
705
690
|
if (outcome !== 'skipped')
|
|
706
691
|
changed = true;
|
|
707
692
|
}
|
|
708
|
-
const unsettled = settledParts(changes, deferred);
|
|
693
|
+
const unsettled = settledParts(changes, deferred, after.collection.composition);
|
|
709
694
|
if (unsettled !== null)
|
|
710
695
|
return unqueueable(unsettled);
|
|
711
696
|
if (!changed)
|
|
@@ -766,11 +751,10 @@ function withdrawnFile(batch, change, at) {
|
|
|
766
751
|
];
|
|
767
752
|
return immutable({ ...batch, id: changeBatchIdentity(), changes, preconditions });
|
|
768
753
|
}
|
|
769
|
-
|
|
754
|
+
function* requeuing(queue, changes, visible, changeable, state) {
|
|
770
755
|
const next = [...queue];
|
|
771
756
|
const origins = new Map();
|
|
772
757
|
const withdrawn = new Map();
|
|
773
|
-
const owners = new Set();
|
|
774
758
|
const queued = new Set();
|
|
775
759
|
const kept = [];
|
|
776
760
|
const originOf = (batch) => origins.get(batch) ?? batch.id;
|
|
@@ -816,7 +800,6 @@ export function* requeuing(queue, changes, visible, changeable, state) {
|
|
|
816
800
|
if (replaced !== null)
|
|
817
801
|
origins.set(replaced, origin);
|
|
818
802
|
}
|
|
819
|
-
owners.add(originOf(owner));
|
|
820
803
|
next.splice(index, following.length, ...rebuilt.filter((batch) => batch !== null));
|
|
821
804
|
queued.add(change.path);
|
|
822
805
|
}
|
|
@@ -826,62 +809,16 @@ export function* requeuing(queue, changes, visible, changeable, state) {
|
|
|
826
809
|
changes: kept,
|
|
827
810
|
queued,
|
|
828
811
|
withdrawn,
|
|
829
|
-
owners,
|
|
830
812
|
};
|
|
831
813
|
}
|
|
832
|
-
function
|
|
833
|
-
return precondition.kind === 'field' ||
|
|
834
|
-
precondition.kind === 'section' ||
|
|
835
|
-
precondition.kind === 'preamble'
|
|
836
|
-
? identity(precondition)
|
|
837
|
-
: `path ${precondition.path}`;
|
|
838
|
-
}
|
|
839
|
-
export function joined(queue, owner, extra) {
|
|
840
|
-
const later = new Set(queue.slice(queue.indexOf(owner) + 1).flatMap((batch) => batch.changes.flatMap(touched)));
|
|
841
|
-
const clash = extra.changes.flatMap(touched).find((path) => later.has(path));
|
|
842
|
-
if (clash !== undefined)
|
|
843
|
-
return unqueueable(clash);
|
|
844
|
-
const changes = [...owner.changes];
|
|
845
|
-
const deferred = new Map();
|
|
846
|
-
for (const change of extra.changes) {
|
|
847
|
-
const unsettled = isPart(change) ? null : settledParts(changes, deferred);
|
|
848
|
-
if (unsettled !== null)
|
|
849
|
-
return unqueueable(unsettled);
|
|
850
|
-
if (folded(changes, change, true, deferred) === 'refused')
|
|
851
|
-
return unqueueable(change.path);
|
|
852
|
-
}
|
|
853
|
-
const unsettled = settledParts(changes, deferred);
|
|
854
|
-
if (unsettled !== null)
|
|
855
|
-
return unqueueable(unsettled);
|
|
856
|
-
const held = new Set(owner.preconditions.map(covering));
|
|
857
|
-
const written = new Set(owner.changes.flatMap((change) => change.kind === 'create' || change.kind === 'replace' ? [change.path] : []));
|
|
858
|
-
const preconditions = [
|
|
859
|
-
...owner.preconditions,
|
|
860
|
-
...extra.preconditions.filter((precondition) => {
|
|
861
|
-
const key = covering(precondition);
|
|
862
|
-
return (!held.has(key) && (key === `path ${precondition.path}` || !written.has(precondition.path)));
|
|
863
|
-
}),
|
|
864
|
-
];
|
|
865
|
-
const batch = immutable({
|
|
866
|
-
...owner,
|
|
867
|
-
...(extra.validation === undefined ? {} : { validation: extra.validation }),
|
|
868
|
-
id: changeBatchIdentity(),
|
|
869
|
-
changes,
|
|
870
|
-
preconditions,
|
|
871
|
-
});
|
|
872
|
-
return { kind: 'joined', batch, queue: queue.map((item) => (item === owner ? batch : item)) };
|
|
873
|
-
}
|
|
874
|
-
export function* limiting(queue, batch, limits, state) {
|
|
814
|
+
function* limiting(queue, batch, limits, state) {
|
|
875
815
|
const at = queue.indexOf(batch);
|
|
876
816
|
const rewritten = yield* providerRewritten(batch, yield* state(queue.slice(0, at)));
|
|
877
817
|
const limited = yield* exceeding(limits, batch.changes, rewritten.changes, yield* state(queue.slice(0, at + 1)));
|
|
878
|
-
return limited?.
|
|
818
|
+
return limited?.refusal ?? null;
|
|
879
819
|
}
|
|
880
|
-
function
|
|
881
|
-
|
|
882
|
-
return false;
|
|
883
|
-
const parsed = parse(content);
|
|
884
|
-
return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
|
|
820
|
+
function typedContent(composition, path, content) {
|
|
821
|
+
return (content !== undefined && (typeAt(composition, path, parse(content)) ?? UNTYPED) !== UNTYPED);
|
|
885
822
|
}
|
|
886
823
|
function touchedLibrary(resulting, touched, composition) {
|
|
887
824
|
const entries = touched
|
|
@@ -892,7 +829,7 @@ function touchedLibrary(resulting, touched, composition) {
|
|
|
892
829
|
})
|
|
893
830
|
.sort((left, right) => (left.path < right.path ? -1 : left.path > right.path ? 1 : 0));
|
|
894
831
|
const contents = new Map(entries.map(({ path, content }) => [path, content]));
|
|
895
|
-
const binaries = new Set(
|
|
832
|
+
const binaries = new Set(Array.from(entriesIn(resulting.binaries), ([path]) => path));
|
|
896
833
|
return validatedCollection(() => Promise.resolve({ entries, next: null }), async (paths) => {
|
|
897
834
|
const known = new Map();
|
|
898
835
|
const pace = paced();
|
|
@@ -901,9 +838,9 @@ function touchedLibrary(resulting, touched, composition) {
|
|
|
901
838
|
if (binaries.has(path))
|
|
902
839
|
known.set(path, { type: undefined, binary: true });
|
|
903
840
|
else if (content !== undefined && content !== null) {
|
|
904
|
-
const
|
|
905
|
-
if (
|
|
906
|
-
known.set(path, { type
|
|
841
|
+
const type = typeAt(composition, path, parse(content, path, definitionsAt(composition, path)));
|
|
842
|
+
if (type !== undefined)
|
|
843
|
+
known.set(path, { type, binary: false });
|
|
907
844
|
await pace(content.length + ROW_WEIGHT);
|
|
908
845
|
}
|
|
909
846
|
}
|
|
@@ -921,7 +858,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
|
|
|
921
858
|
for (const path of touched) {
|
|
922
859
|
const before = visible.documents[path];
|
|
923
860
|
const after = resulting.documents[path];
|
|
924
|
-
if (
|
|
861
|
+
if (typedContent(composition, path, before) || typedContent(composition, path, after))
|
|
925
862
|
typedPaths.push(path);
|
|
926
863
|
await pace((before?.length ?? 0) + (after?.length ?? 0) + ROW_WEIGHT);
|
|
927
864
|
}
|
|
@@ -939,6 +876,7 @@ async function judging(visible, resulting, composition, validate, removed, touch
|
|
|
939
876
|
retryable: false,
|
|
940
877
|
file: verdict.file,
|
|
941
878
|
...(verdict.location === undefined ? {} : { location: verdict.location }),
|
|
879
|
+
...(verdict.line === undefined ? {} : { line: verdict.line }),
|
|
942
880
|
...(verdict.referrers === undefined ? {} : { referrers: verdict.referrers }),
|
|
943
881
|
},
|
|
944
882
|
};
|
|
@@ -954,8 +892,6 @@ function placed(reference) {
|
|
|
954
892
|
const key = roomPathOf(reference.handle, reference.path);
|
|
955
893
|
if (reference.kind === 'link')
|
|
956
894
|
return `link ${key}`;
|
|
957
|
-
if (reference.kind === 'item')
|
|
958
|
-
return `section ${reference.section} ${key}`;
|
|
959
895
|
const pointer = reference.pointer
|
|
960
896
|
.split('/')
|
|
961
897
|
.map((segment) => (ARRAY_INDEX.test(segment) ? '-' : segment))
|
|
@@ -965,10 +901,11 @@ function placed(reference) {
|
|
|
965
901
|
function roomReferencesIn(path, content, composition) {
|
|
966
902
|
if (content === undefined)
|
|
967
903
|
return [];
|
|
968
|
-
const
|
|
904
|
+
const definitions = definitionsAt(composition, path);
|
|
905
|
+
const parsed = parse(content, path, definitions);
|
|
969
906
|
if (!parsed.ok)
|
|
970
907
|
return [];
|
|
971
|
-
return roomReferences(
|
|
908
|
+
return roomReferences(parsed.document, { path }, definitions(parsed.document.type));
|
|
972
909
|
}
|
|
973
910
|
function* admittedRooms(changes, visible, resulting, composition) {
|
|
974
911
|
const from = new Map();
|
|
@@ -986,7 +923,7 @@ function* admittedRooms(changes, visible, resulting, composition) {
|
|
|
986
923
|
continue;
|
|
987
924
|
if (held.has(placed(reference)))
|
|
988
925
|
continue;
|
|
989
|
-
return refuse('unresolved-reference', path, reference.
|
|
926
|
+
return refuse('unresolved-reference', path, reference.pointer);
|
|
990
927
|
}
|
|
991
928
|
yield ROW_WEIGHT + now.length;
|
|
992
929
|
}
|
|
@@ -1004,7 +941,10 @@ function validationOf(validated) {
|
|
|
1004
941
|
};
|
|
1005
942
|
}
|
|
1006
943
|
async function batching(input) {
|
|
1007
|
-
const
|
|
944
|
+
const relative = relativeChanges(input);
|
|
945
|
+
if (relative.kind === 'refused')
|
|
946
|
+
return relative;
|
|
947
|
+
const { changes } = relative;
|
|
1008
948
|
const structural = changes.find((change) => change.kind === 'move' || change.kind === 'remove');
|
|
1009
949
|
if (structural !== undefined && input.unmodeled) {
|
|
1010
950
|
return refuse('model-unavailable', structural.path);
|
|
@@ -1014,12 +954,12 @@ async function batching(input) {
|
|
|
1014
954
|
const rewritten = await stepped(rewrites(changes, input.visible));
|
|
1015
955
|
if (rewritten.kind === 'refused')
|
|
1016
956
|
return rewritten;
|
|
1017
|
-
const refusal = guard(changes, input,
|
|
957
|
+
const refusal = guard(changes, input, WRITE) ?? unapplied(changes, input.visible, input.composition);
|
|
1018
958
|
if (refusal !== null)
|
|
1019
959
|
return refusal;
|
|
1020
960
|
const preconditions = await stepped(preconditionsOf(changes, input.visible, input.bases));
|
|
1021
961
|
const predicted = await stepped(anticipated(changes, preconditions, rewritten.changes, input.visible));
|
|
1022
|
-
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));
|
|
1023
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))]);
|
|
1024
964
|
if (judged.kind === 'refused')
|
|
1025
965
|
return judged;
|
|
@@ -1041,7 +981,7 @@ async function batching(input) {
|
|
|
1041
981
|
}),
|
|
1042
982
|
};
|
|
1043
983
|
}
|
|
1044
|
-
|
|
984
|
+
const MOVE_DOCUMENTS = 'move-documents';
|
|
1045
985
|
function heldAt(visible, path) {
|
|
1046
986
|
return visible.documents[path] !== undefined || visible.binaries[path] !== undefined;
|
|
1047
987
|
}
|
|
@@ -1050,7 +990,7 @@ function arrivingText(path, to, source, moved) {
|
|
|
1050
990
|
const document = source.visible.collection.document(path);
|
|
1051
991
|
if (document === undefined)
|
|
1052
992
|
return content;
|
|
1053
|
-
const definition =
|
|
993
|
+
const definition = definitionsAt(source.composition, path)(document.type);
|
|
1054
994
|
const changes = crossed(document, definition, path, (named, href) => {
|
|
1055
995
|
const at = moved.get(named);
|
|
1056
996
|
if (at !== undefined)
|
|
@@ -1059,13 +999,14 @@ function arrivingText(path, to, source, moved) {
|
|
|
1059
999
|
});
|
|
1060
1000
|
if (changes.length === 0)
|
|
1061
1001
|
return content;
|
|
1062
|
-
const applied = apply(document, changes);
|
|
1002
|
+
const applied = apply(document, changes, definition);
|
|
1063
1003
|
return applied.outcome === 'applied' ? serialize(applied.document) : content;
|
|
1064
1004
|
}
|
|
1065
1005
|
function arrivalOf({ path, to }, source, moved) {
|
|
1066
|
-
const { documents, revisions, fileIds, changes, binaries } = source.visible;
|
|
1006
|
+
const { documents, revisions, fileIds, created, changes, binaries } = source.visible;
|
|
1067
1007
|
const kept = {
|
|
1068
1008
|
...(fileIds[path] === undefined ? {} : { fileId: fileIds[path] }),
|
|
1009
|
+
...(created[path] === undefined ? {} : { created: created[path] }),
|
|
1069
1010
|
...(changes[path] === undefined ? {} : { change: changes[path] }),
|
|
1070
1011
|
};
|
|
1071
1012
|
const heads = {
|
|
@@ -1092,10 +1033,8 @@ function arrivalOf({ path, to }, source, moved) {
|
|
|
1092
1033
|
}
|
|
1093
1034
|
async function moving(input) {
|
|
1094
1035
|
const { source, destination, moves } = input;
|
|
1095
|
-
if (moves.length === 0)
|
|
1096
|
-
return refuse('no-change');
|
|
1097
1036
|
const removals = moves.map(({ path }) => ({ kind: 'remove', path }));
|
|
1098
|
-
const leaves = guard(removals, { ...source, local: input.local, bases: [] },
|
|
1037
|
+
const leaves = guard(removals, { ...source, local: input.local, bases: [] }, MOVE_OUT);
|
|
1099
1038
|
if (leaves !== null)
|
|
1100
1039
|
return leaves;
|
|
1101
1040
|
const uploading = moves.find(({ path }) => source.visible.binaries[path]?.state === 'pending');
|
|
@@ -1103,7 +1042,7 @@ async function moving(input) {
|
|
|
1103
1042
|
return refuse('unknown-revision', uploading.path);
|
|
1104
1043
|
const moved = new Map(moves.map(({ path, to }) => [path, to]));
|
|
1105
1044
|
const arrivals = moves.map((move) => arrivalOf(move, source, moved));
|
|
1106
|
-
const arrives = guard(arrivals, { ...destination, local: input.local, bases: [] },
|
|
1045
|
+
const arrives = guard(arrivals, { ...destination, local: input.local, bases: [] }, WRITE);
|
|
1107
1046
|
if (arrives !== null)
|
|
1108
1047
|
return arrives;
|
|
1109
1048
|
const bound = input.providerLimits.find((limit) => limit.name === MOVE_DOCUMENTS)?.value;
|
|
@@ -1132,7 +1071,7 @@ async function moving(input) {
|
|
|
1132
1071
|
between,
|
|
1133
1072
|
};
|
|
1134
1073
|
const effective = await stepped(leavingRewritten(leavingBatch, source.visible));
|
|
1135
|
-
const left = await stepped(overlaying(source.visible, [effective]));
|
|
1074
|
+
const left = await stepped(overlaying(source.visible, [effective], source.composition));
|
|
1136
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))]);
|
|
1137
1076
|
if (sourceJudged.kind === 'refused')
|
|
1138
1077
|
return sourceJudged;
|
|
@@ -1144,7 +1083,7 @@ async function moving(input) {
|
|
|
1144
1083
|
...written,
|
|
1145
1084
|
between,
|
|
1146
1085
|
};
|
|
1147
|
-
const arrived = await stepped(overlaying(destination.visible, [arrivingBatch]));
|
|
1086
|
+
const arrived = await stepped(overlaying(destination.visible, [arrivingBatch], destination.composition));
|
|
1148
1087
|
const destinationJudged = await judging(destination.visible, arrived, destination.composition, destination.validate, new Set(), moves.map(({ to }) => to));
|
|
1149
1088
|
if (destinationJudged.kind === 'refused')
|
|
1150
1089
|
return destinationJudged;
|
|
@@ -1154,9 +1093,180 @@ async function moving(input) {
|
|
|
1154
1093
|
return limited;
|
|
1155
1094
|
return { kind: 'moved', leaving: immutable(leavingBatch), arriving: immutable(arrivingBatch) };
|
|
1156
1095
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
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(composition, at, 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;
|
|
1159
1269
|
}
|
|
1160
|
-
export function
|
|
1161
|
-
return
|
|
1270
|
+
export function planSave(ask, room, into) {
|
|
1271
|
+
return into === undefined ? plannedWithin(ask, room) : plannedMove(ask, room, into);
|
|
1162
1272
|
}
|