@agentshouse/mdruntime 0.1.0-cff1b70c6ad46 → 0.1.0-cffcba9cd9c2f

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.
Files changed (134) hide show
  1. package/dist/acceptance.d.ts +0 -3
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +48 -124
  4. package/dist/actions.js +2 -2
  5. package/dist/adapter.d.ts +16 -44
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/bootstrap.d.ts +1 -1
  8. package/dist/bootstrap.d.ts.map +1 -1
  9. package/dist/bootstrap.js +6 -19
  10. package/dist/change-set.d.ts +4 -0
  11. package/dist/change-set.d.ts.map +1 -1
  12. package/dist/change-set.js +6 -0
  13. package/dist/client.d.ts +3 -1
  14. package/dist/client.d.ts.map +1 -1
  15. package/dist/client.js +5 -3
  16. package/dist/collection.d.ts +22 -4
  17. package/dist/collection.d.ts.map +1 -1
  18. package/dist/collection.js +12 -2
  19. package/dist/connection.d.ts.map +1 -1
  20. package/dist/connection.js +13 -13
  21. package/dist/conversation-live.d.ts +3 -4
  22. package/dist/conversation-live.d.ts.map +1 -1
  23. package/dist/conversation-live.js +2 -3
  24. package/dist/conversation.d.ts +4 -6
  25. package/dist/conversation.d.ts.map +1 -1
  26. package/dist/conversation.js +43 -71
  27. package/dist/declaration.d.ts +10 -0
  28. package/dist/declaration.d.ts.map +1 -0
  29. package/dist/declaration.js +24 -0
  30. package/dist/discovery.d.ts.map +1 -1
  31. package/dist/discovery.js +5 -3
  32. package/dist/failure.d.ts +1 -0
  33. package/dist/failure.d.ts.map +1 -1
  34. package/dist/failure.js +3 -0
  35. package/dist/host.d.ts +17 -2
  36. package/dist/host.d.ts.map +1 -1
  37. package/dist/host.js +16 -4
  38. package/dist/index.d.ts +3 -2
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +2 -1
  41. package/dist/install.d.ts +0 -1
  42. package/dist/install.d.ts.map +1 -1
  43. package/dist/install.js +46 -57
  44. package/dist/job.d.ts +1 -29
  45. package/dist/job.d.ts.map +1 -1
  46. package/dist/job.js +2 -49
  47. package/dist/lifecycle.d.ts.map +1 -1
  48. package/dist/lifecycle.js +9 -6
  49. package/dist/listing.d.ts +3 -4
  50. package/dist/listing.d.ts.map +1 -1
  51. package/dist/listing.js +14 -22
  52. package/dist/live.d.ts.map +1 -1
  53. package/dist/live.js +3 -1
  54. package/dist/locks.d.ts.map +1 -1
  55. package/dist/locks.js +2 -1
  56. package/dist/lost.d.ts.map +1 -1
  57. package/dist/lost.js +3 -3
  58. package/dist/memory.d.ts +4 -2
  59. package/dist/memory.d.ts.map +1 -1
  60. package/dist/memory.js +8 -6
  61. package/dist/messages.d.ts +0 -3
  62. package/dist/messages.d.ts.map +1 -1
  63. package/dist/messages.js +0 -14
  64. package/dist/model.d.ts +0 -1
  65. package/dist/model.d.ts.map +1 -1
  66. package/dist/model.js +0 -5
  67. package/dist/models.d.ts +4 -8
  68. package/dist/models.d.ts.map +1 -1
  69. package/dist/models.js +101 -126
  70. package/dist/opening.d.ts.map +1 -1
  71. package/dist/opening.js +6 -4
  72. package/dist/overlay.d.ts +2 -1
  73. package/dist/overlay.d.ts.map +1 -1
  74. package/dist/overlay.js +32 -21
  75. package/dist/parts.d.ts +3 -52
  76. package/dist/parts.d.ts.map +1 -1
  77. package/dist/parts.js +15 -120
  78. package/dist/preparation.d.ts.map +1 -1
  79. package/dist/preparation.js +10 -3
  80. package/dist/queue.d.ts +32 -0
  81. package/dist/queue.d.ts.map +1 -0
  82. package/dist/queue.js +402 -0
  83. package/dist/reach.d.ts.map +1 -1
  84. package/dist/reach.js +5 -4
  85. package/dist/reads.d.ts.map +1 -1
  86. package/dist/reads.js +4 -1
  87. package/dist/refresh.js +2 -2
  88. package/dist/refusal.d.ts.map +1 -1
  89. package/dist/refusal.js +3 -1
  90. package/dist/replica.d.ts +5 -11
  91. package/dist/replica.d.ts.map +1 -1
  92. package/dist/replica.js +12 -14
  93. package/dist/room-draft.d.ts +3 -2
  94. package/dist/room-draft.d.ts.map +1 -1
  95. package/dist/room-draft.js +33 -20
  96. package/dist/room-drafts.js +3 -3
  97. package/dist/rows.d.ts.map +1 -1
  98. package/dist/rows.js +3 -4
  99. package/dist/runtime.d.ts +5 -16
  100. package/dist/runtime.d.ts.map +1 -1
  101. package/dist/save.d.ts +5 -10
  102. package/dist/save.d.ts.map +1 -1
  103. package/dist/save.js +59 -56
  104. package/dist/saves.d.ts +2 -40
  105. package/dist/saves.d.ts.map +1 -1
  106. package/dist/saves.js +23 -349
  107. package/dist/shown.d.ts +2 -1
  108. package/dist/shown.d.ts.map +1 -1
  109. package/dist/shown.js +13 -6
  110. package/dist/socket/rooms.d.ts +1 -4
  111. package/dist/socket/rooms.d.ts.map +1 -1
  112. package/dist/socket.d.ts +0 -1
  113. package/dist/socket.d.ts.map +1 -1
  114. package/dist/store/records.d.ts +0 -2
  115. package/dist/store/records.d.ts.map +1 -1
  116. package/dist/store/records.js +0 -3
  117. package/dist/store.d.ts +1 -1
  118. package/dist/store.d.ts.map +1 -1
  119. package/dist/store.js +1 -1
  120. package/dist/stored.d.ts.map +1 -1
  121. package/dist/stored.js +3 -3
  122. package/dist/surface.d.ts.map +1 -1
  123. package/dist/surface.js +2 -1
  124. package/dist/sync.d.ts.map +1 -1
  125. package/dist/sync.js +18 -20
  126. package/dist/tables.d.ts +0 -4
  127. package/dist/tables.d.ts.map +1 -1
  128. package/dist/tables.js +1 -4
  129. package/dist/validation.d.ts.map +1 -1
  130. package/dist/validation.js +2 -2
  131. package/dist/wire.d.ts +4 -4
  132. package/dist/wire.d.ts.map +1 -1
  133. package/dist/wire.js +3 -3
  134. package/package.json +3 -2
package/dist/save.js CHANGED
@@ -1,10 +1,9 @@
1
- import { definitionOf } from './model.js';
2
- import { apply, ARRAY_INDEX, ATTACHMENT, links, parse, pointerSegments, references, relative, relativize, retarget, roomReferences, serialize, target, } from '@agentshouse/mdmodel';
1
+ import { apply, ARRAY_INDEX, ATTACHMENT, create, links, parse, pointerSegments, references, relative, relativize, retarget, roomReferences, serialize, target, } from '@agentshouse/mdmodel';
3
2
  import { immutable, leaving, queuedFile, departure, } from './change.js';
4
- import { collectionOf, documentsOf, governing, } from './collection.js';
3
+ import { collectionOf, definitionsAt, documentsOf, governing, } from './collection.js';
5
4
  import { changeBatchIdentity } from './identity.js';
6
5
  import { overlaying } from './overlay.js';
7
- import { ancestors, authoredAt, covered, normalize } from './paths.js';
6
+ import { ancestors } from './paths.js';
8
7
  import { entriesIn, sorting } from './shared.js';
9
8
  import { paced, ROW_WEIGHT, stepped } from './turn.js';
10
9
  import { validatedCollection } from './validation.js';
@@ -42,13 +41,13 @@ function repointed(document, definition, from, to, moves, settled) {
42
41
  }
43
42
  if (changes.length === 0)
44
43
  return [];
45
- const applied = apply(document, changes);
44
+ const applied = apply(document, changes, definition);
46
45
  if (applied.outcome !== 'applied')
47
46
  return [];
48
47
  const next = applied.document;
49
48
  return [...names].map((name) => ({ kind: 'field', path: from, name, value: next.fields[name] }));
50
49
  }
51
- function edited(document, changes) {
50
+ function edited(document, changes, definition) {
52
51
  const parts = new Map();
53
52
  for (const change of changes) {
54
53
  if (change.kind === 'preamble')
@@ -63,7 +62,7 @@ function edited(document, changes) {
63
62
  }
64
63
  if (parts.size === 0)
65
64
  return document;
66
- const applied = apply(document, [...parts.values()]);
65
+ const applied = apply(document, [...parts.values()], definition);
67
66
  return applied.outcome === 'applied' ? applied.document : document;
68
67
  }
69
68
  function bodies(path, before, after) {
@@ -78,7 +77,7 @@ function bodies(path, before, after) {
78
77
  }
79
78
  return changes;
80
79
  }
81
- function relinks(path, moved, before, moves) {
80
+ function relinks(path, moved, before, moves, definition) {
82
81
  const changes = [];
83
82
  for (const link of links(before, path)) {
84
83
  const destination = moves.get(link.target) ?? link.target;
@@ -91,7 +90,7 @@ function relinks(path, moved, before, moves) {
91
90
  }
92
91
  if (changes.length === 0)
93
92
  return { kind: 'changes', changes: [] };
94
- const applied = apply(before, changes);
93
+ const applied = apply(before, changes, definition);
95
94
  if (applied.outcome === 'refuse') {
96
95
  return {
97
96
  kind: 'refused',
@@ -114,6 +113,15 @@ function relinks(path, moved, before, moves) {
114
113
  function partKey(change) {
115
114
  return change.kind === 'section' ? `section ${change.name}` : change.kind;
116
115
  }
116
+ const NAMES_A_SKIP_TESTS = 64;
117
+ const ENCODED = /[%&\\]/u;
118
+ function movedNames(moves) {
119
+ const names = new Set([...moves.keys()].map((path) => path.slice(path.lastIndexOf('/') + 1)));
120
+ return names.size > NAMES_A_SKIP_TESTS ? null : [...names];
121
+ }
122
+ function cannotLink(text, names) {
123
+ return names !== null && !ENCODED.test(text) && !names.some((name) => text.includes(name));
124
+ }
117
125
  function* rewrites(changes, visible) {
118
126
  const moves = new Map();
119
127
  const settled = new Set();
@@ -139,17 +147,20 @@ function* rewrites(changes, visible) {
139
147
  }
140
148
  if (moves.size === 0)
141
149
  return { kind: 'changes', changes };
150
+ const names = movedNames(moves);
142
151
  const merged = [...changes];
143
152
  const added = [];
144
153
  for (const [path, document] of yield* documentsOf(visible.collection)) {
145
154
  if (settled.has(path))
146
155
  continue;
147
156
  const moved = moves.get(path) ?? path;
148
- const definition = definitionOf(governing(visible.collection.composition, path), document.type);
157
+ const definition = definitionsAt(visible.collection.composition, path)(document.type);
149
158
  const repointing = repointed(document, definition, path, moved, moves, settled);
150
159
  added.push(...repointing);
151
160
  const own = parts.get(path) ?? [];
152
- const relinked = relinks(path, moved, edited(document, own.map((index) => merged[index])), moves);
161
+ const relinked = moved === path && own.length === 0 && cannotLink(document.content, names)
162
+ ? { kind: 'changes', changes: [] }
163
+ : relinks(path, moved, edited(document, own.map((index) => merged[index]), definition), moves, definition);
153
164
  if (relinked.kind === 'refused')
154
165
  return relinked;
155
166
  const keyed = new Map();
@@ -218,10 +229,10 @@ function crossed(document, definition, path, to) {
218
229
  }
219
230
  return changes;
220
231
  }
221
- function rewritten(path, document, changes) {
232
+ function rewritten(path, document, changes, definition) {
222
233
  if (changes.length === 0)
223
234
  return [];
224
- const applied = apply(document, changes);
235
+ const applied = apply(document, changes, definition);
225
236
  if (applied.outcome !== 'applied')
226
237
  return [];
227
238
  const after = applied.document;
@@ -245,8 +256,8 @@ export function* leavingRewritten(batch, visible) {
245
256
  for (const [path, document] of yield* documentsOf(visible.collection)) {
246
257
  if (moved.has(path))
247
258
  continue;
248
- const definition = definitionOf(governing(visible.collection.composition, path), document.type);
249
- derived.push(...rewritten(path, document, crossed(document, definition, path, (named) => moved.get(named))));
259
+ const definition = definitionsAt(visible.collection.composition, path)(document.type);
260
+ derived.push(...rewritten(path, document, crossed(document, definition, path, (named) => moved.get(named)), definition));
250
261
  yield ROW_WEIGHT + visible.collection.text[path].length;
251
262
  }
252
263
  if (derived.length === 0)
@@ -288,7 +299,7 @@ function* incoming(collection, removed, candidates) {
288
299
  for (const [path, document] of candidates === null
289
300
  ? yield* documentsOf(collection)
290
301
  : read(candidates)) {
291
- const definition = definitionOf(governing(collection.composition, path), document.type);
302
+ const definition = definitionsAt(collection.composition, path)(document.type);
292
303
  for (const { value, to } of definition === undefined ? [] : references(document, definition)) {
293
304
  if (to.includes(ATTACHMENT))
294
305
  continue;
@@ -331,18 +342,9 @@ function guard(changes, input, removing) {
331
342
  const occupied = (path) => input.folders.has(path) ? path : (ancestors(path).find((one) => existing.has(one)) ?? null);
332
343
  for (const [index, change] of changes.entries()) {
333
344
  for (const path of affected(change)) {
334
- const normalized = normalize(path);
335
- if (normalized === null || normalized === '')
336
- return refuse('room-root', path);
337
- if (covered(input.providerOwnedPaths, normalized) ||
338
- (input.authoredPaths !== undefined && !authoredAt(input.authoredPaths, normalized))) {
339
- return refuse('provider-owned-path', normalized);
340
- }
341
- if (!input.pathRule(normalized))
342
- return refuse('invalid-path', normalized);
343
- for (const operation of change.kind === 'remove' ? removing : WRITE)
344
- if (!input.local && !covered(input.operations[operation], normalized))
345
- return refuse(`${operation}-grant`, normalized);
345
+ const refused = input.rule(path, change.kind === 'remove' ? removing : WRITE);
346
+ if (refused !== null)
347
+ return refuse(refused.code, refused.path);
346
348
  }
347
349
  if (change.kind === 'create' || change.kind === 'arrival') {
348
350
  const taken = existing.has(change.path) ? change.path : occupied(change.path);
@@ -541,19 +543,16 @@ function* exceeding(limits, changes, effective, resulting) {
541
543
  function shellRelative(text, path, handle, definition) {
542
544
  if (!text.includes(`/rooms/${handle}/`))
543
545
  return null;
544
- const parsed = parse(text, path);
546
+ const parsed = parse(text, path, definition);
545
547
  if (!parsed.ok)
546
548
  return null;
547
549
  const result = relativize(parsed.document, path, handle, definition(parsed.document.type));
548
550
  return result.outcome === 'applied' && result.document.content !== text ? result.document : null;
549
551
  }
550
552
  function relativeField(path, name, value, handle, definition) {
551
- const opened = parse('---\n---\n');
552
- if (definition === undefined ||
553
- !opened.ok ||
554
- !JSON.stringify(value ?? null).includes(`/rooms/${handle}/`))
553
+ if (definition === undefined || !JSON.stringify(value ?? null).includes(`/rooms/${handle}/`))
555
554
  return value;
556
- const held = apply(opened.document, [{ kind: 'field', name, value, prior: undefined }]);
555
+ const held = apply(create(definition.name, definition), [{ kind: 'field', name, value, prior: undefined }], definition);
557
556
  if (held.outcome !== 'applied')
558
557
  return value;
559
558
  const result = relativize(held.document, path, handle, definition);
@@ -561,7 +560,7 @@ function relativeField(path, name, value, handle, definition) {
561
560
  }
562
561
  function relativeChanges(input) {
563
562
  const { handle, composition, visible } = input;
564
- const typed = (path) => (type) => definitionOf(governing(composition, path), type);
563
+ const typed = (path) => definitionsAt(composition, path);
565
564
  const body = (path, text) => shellRelative(text, path, handle, () => undefined)?.content ?? text;
566
565
  return input.changes.map((change) => {
567
566
  const definition = typed(change.path);
@@ -598,8 +597,9 @@ function isPart(change) {
598
597
  function touched(change) {
599
598
  return change.kind === 'move' ? [change.path, change.to] : [change.path];
600
599
  }
601
- function partsApplied(content, path, changes) {
602
- const parsed = parse(content, path);
600
+ function partsApplied(content, path, changes, composition) {
601
+ const definitions = definitionsAt(composition, path);
602
+ const parsed = parse(content, path, definitions);
603
603
  if (!parsed.ok)
604
604
  return null;
605
605
  const document = parsed.document;
@@ -622,12 +622,12 @@ function partsApplied(content, path, changes) {
622
622
  else
623
623
  parts.set('preamble', { kind: 'preamble', value: change.value, prior: document.preamble });
624
624
  }
625
- const applied = apply(document, [...parts.values()]);
625
+ const applied = apply(document, [...parts.values()], definitions(document.type));
626
626
  return applied.outcome === 'applied' ? serialize(applied.document) : null;
627
627
  }
628
- function settledParts(changes, deferred) {
628
+ function settledParts(changes, deferred, composition) {
629
629
  for (const [held, parts] of deferred) {
630
- const content = partsApplied(held.content, held.path, parts);
630
+ const content = partsApplied(held.content, held.path, parts, composition);
631
631
  if (content === null)
632
632
  return held.path;
633
633
  changes[changes.indexOf(held)] = { ...held, content };
@@ -702,7 +702,9 @@ function* relinked(batch, move, before, after, appending) {
702
702
  for (const change of derived.changes) {
703
703
  if (change === move)
704
704
  continue;
705
- const unsettled = isPart(change) ? null : settledParts(changes, deferred);
705
+ const unsettled = isPart(change)
706
+ ? null
707
+ : settledParts(changes, deferred, after.collection.composition);
706
708
  if (unsettled !== null)
707
709
  return unqueueable(unsettled);
708
710
  const outcome = folded(changes, change, appending, deferred);
@@ -713,7 +715,7 @@ function* relinked(batch, move, before, after, appending) {
713
715
  if (outcome !== 'skipped')
714
716
  changed = true;
715
717
  }
716
- const unsettled = settledParts(changes, deferred);
718
+ const unsettled = settledParts(changes, deferred, after.collection.composition);
717
719
  if (unsettled !== null)
718
720
  return unqueueable(unsettled);
719
721
  if (!changed)
@@ -844,7 +846,7 @@ function covering(precondition) {
844
846
  ? identity(precondition)
845
847
  : `path ${precondition.path}`;
846
848
  }
847
- export function joined(queue, owner, extra) {
849
+ export function joined(queue, owner, extra, composition) {
848
850
  const later = new Set(queue.slice(queue.indexOf(owner) + 1).flatMap((batch) => batch.changes.flatMap(touched)));
849
851
  const clash = extra.changes.flatMap(touched).find((path) => later.has(path));
850
852
  if (clash !== undefined)
@@ -852,13 +854,13 @@ export function joined(queue, owner, extra) {
852
854
  const changes = [...owner.changes];
853
855
  const deferred = new Map();
854
856
  for (const change of extra.changes) {
855
- const unsettled = isPart(change) ? null : settledParts(changes, deferred);
857
+ const unsettled = isPart(change) ? null : settledParts(changes, deferred, composition);
856
858
  if (unsettled !== null)
857
859
  return unqueueable(unsettled);
858
860
  if (folded(changes, change, true, deferred) === 'refused')
859
861
  return unqueueable(change.path);
860
862
  }
861
- const unsettled = settledParts(changes, deferred);
863
+ const unsettled = settledParts(changes, deferred, composition);
862
864
  if (unsettled !== null)
863
865
  return unqueueable(unsettled);
864
866
  const held = new Set(owner.preconditions.map(covering));
@@ -909,7 +911,7 @@ function touchedLibrary(resulting, touched, composition) {
909
911
  if (binaries.has(path))
910
912
  known.set(path, { type: undefined, binary: true });
911
913
  else if (content !== undefined && content !== null) {
912
- const read = parse(content, path);
914
+ const read = parse(content, path, definitionsAt(composition, path));
913
915
  if (read.ok)
914
916
  known.set(path, { type: read.document.type ?? 'any', binary: false });
915
917
  await pace(content.length + ROW_WEIGHT);
@@ -973,10 +975,11 @@ function placed(reference) {
973
975
  function roomReferencesIn(path, content, composition) {
974
976
  if (content === undefined)
975
977
  return [];
976
- const parsed = parse(content, path);
978
+ const definitions = definitionsAt(composition, path);
979
+ const parsed = parse(content, path, definitions);
977
980
  if (!parsed.ok)
978
981
  return [];
979
- return roomReferences(parsed.document, definitionOf(governing(composition, path), parsed.document.type));
982
+ return roomReferences(parsed.document, definitions(parsed.document.type));
980
983
  }
981
984
  function* admittedRooms(changes, visible, resulting, composition) {
982
985
  const from = new Map();
@@ -1027,7 +1030,7 @@ async function batching(input) {
1027
1030
  return refusal;
1028
1031
  const preconditions = await stepped(preconditionsOf(changes, input.visible, input.bases));
1029
1032
  const predicted = await stepped(anticipated(changes, preconditions, rewritten.changes, input.visible));
1030
- const resulting = await stepped(overlaying(input.visible, [{ id: '', baseRoomVersion: input.baseRoomVersion, ...predicted }]));
1033
+ const resulting = await stepped(overlaying(input.visible, [{ id: '', baseRoomVersion: input.baseRoomVersion, ...predicted }], input.composition));
1031
1034
  const judged = await judging(input.visible, resulting, input.composition, input.validate, new Set(changes.filter((change) => change.kind === 'remove').map((change) => change.path)), [...new Set(predicted.changes.flatMap(affected))]);
1032
1035
  if (judged.kind === 'refused')
1033
1036
  return judged;
@@ -1058,7 +1061,7 @@ function arrivingText(path, to, source, moved) {
1058
1061
  const document = source.visible.collection.document(path);
1059
1062
  if (document === undefined)
1060
1063
  return content;
1061
- const definition = definitionOf(governing(source.composition, path), document.type);
1064
+ const definition = definitionsAt(source.composition, path)(document.type);
1062
1065
  const changes = crossed(document, definition, path, (named, href) => {
1063
1066
  const at = moved.get(named);
1064
1067
  if (at !== undefined)
@@ -1067,7 +1070,7 @@ function arrivingText(path, to, source, moved) {
1067
1070
  });
1068
1071
  if (changes.length === 0)
1069
1072
  return content;
1070
- const applied = apply(document, changes);
1073
+ const applied = apply(document, changes, definition);
1071
1074
  return applied.outcome === 'applied' ? serialize(applied.document) : content;
1072
1075
  }
1073
1076
  function arrivalOf({ path, to }, source, moved) {
@@ -1100,9 +1103,9 @@ function arrivalOf({ path, to }, source, moved) {
1100
1103
  };
1101
1104
  }
1102
1105
  async function moving(input) {
1103
- const { source, destination, moves, pathRule } = input;
1106
+ const { source, destination, moves } = input;
1104
1107
  const removals = moves.map(({ path }) => ({ kind: 'remove', path }));
1105
- const leaves = guard(removals, { ...source, local: input.local, bases: [], pathRule }, MOVE_OUT);
1108
+ const leaves = guard(removals, { ...source, local: input.local, bases: [] }, MOVE_OUT);
1106
1109
  if (leaves !== null)
1107
1110
  return leaves;
1108
1111
  const uploading = moves.find(({ path }) => source.visible.binaries[path]?.state === 'pending');
@@ -1110,7 +1113,7 @@ async function moving(input) {
1110
1113
  return refuse('unknown-revision', uploading.path);
1111
1114
  const moved = new Map(moves.map(({ path, to }) => [path, to]));
1112
1115
  const arrivals = moves.map((move) => arrivalOf(move, source, moved));
1113
- const arrives = guard(arrivals, { ...destination, local: input.local, bases: [], pathRule }, WRITE);
1116
+ const arrives = guard(arrivals, { ...destination, local: input.local, bases: [] }, WRITE);
1114
1117
  if (arrives !== null)
1115
1118
  return arrives;
1116
1119
  const bound = input.providerLimits.find((limit) => limit.name === MOVE_DOCUMENTS)?.value;
@@ -1139,7 +1142,7 @@ async function moving(input) {
1139
1142
  between,
1140
1143
  };
1141
1144
  const effective = await stepped(leavingRewritten(leavingBatch, source.visible));
1142
- const left = await stepped(overlaying(source.visible, [effective]));
1145
+ const left = await stepped(overlaying(source.visible, [effective], source.composition));
1143
1146
  const sourceJudged = await judging(source.visible, left, source.composition, source.validate, new Set(moves.map(({ path }) => path)), [...new Set(effective.changes.map((change) => change.path))]);
1144
1147
  if (sourceJudged.kind === 'refused')
1145
1148
  return sourceJudged;
@@ -1151,7 +1154,7 @@ async function moving(input) {
1151
1154
  ...written,
1152
1155
  between,
1153
1156
  };
1154
- const arrived = await stepped(overlaying(destination.visible, [arrivingBatch]));
1157
+ const arrived = await stepped(overlaying(destination.visible, [arrivingBatch], destination.composition));
1155
1158
  const destinationJudged = await judging(destination.visible, arrived, destination.composition, destination.validate, new Set(), moves.map(({ to }) => to));
1156
1159
  if (destinationJudged.kind === 'refused')
1157
1160
  return destinationJudged;
package/dist/saves.d.ts CHANGED
@@ -1,11 +1,9 @@
1
- import { type ChangeSet } from './change-set.js';
2
1
  import { type ChangeBatch, type WrittenBy } from './change.js';
3
2
  import { type AttachAnswer, type BinaryLinkAnswer, type HeldBinaryAnswer, type HeldShownAnswer } from './outcome.js';
4
- import { type HeldReplica, type ReplicaRecord, type Slice, type VisibleLayer } from './replica.js';
5
- import { type ReturnReason, type RoomDraftParts } from './room-draft.js';
3
+ import { type RoomDraftParts } from './room-draft.js';
6
4
  import type { Runtime } from './runtime.js';
7
5
  import { type SaveRefusal } from './save.js';
8
- import type { AuthoredWrite, CommittedWrite, PendingState, RoomCommit, RuntimeStore, Store, StoredEntry, View, Work } from './store.js';
6
+ import type { Store } from './store.js';
9
7
  export type SaveResult = {
10
8
  outcome: 'saved';
11
9
  identifier: string;
@@ -27,42 +25,6 @@ export type BinaryFileSurface = {
27
25
  attach(room: string, file: File): Promise<AttachAnswer>;
28
26
  part(file: string, part: number): Promise<Uint8Array | null>;
29
27
  };
30
- export type Leaving = {
31
- batch: ChangeBatch;
32
- returned: ReturnReason | null;
33
- };
34
- export declare function withdrawable(states: ReadonlyMap<string, PendingState>): (batch: ChangeBatch) => boolean;
35
- export declare function sliceAt(store: Store, record: ReplicaRecord, view: View, queue: readonly ChangeBatch[], extra?: Iterable<string>, moved?: Iterable<string>): Promise<Slice>;
36
- export declare function landedWhole(store: Store, locator: string, batch: ChangeBatch, confirmedLayer: Slice, current?: Readonly<Record<string, string>>): Promise<boolean>;
37
- export type Settling = {
38
- leaving?: readonly Leaving[];
39
- room?: boolean;
40
- view?: View;
41
- commit?: Pick<RoomCommit, 'published' | 'refreshed'>;
42
- changes?: {
43
- readonly set: readonly StoredEntry[];
44
- readonly removed: readonly string[];
45
- };
46
- };
47
- export declare function preparedAfter(runtime: Runtime, locator: string, answer: CommittedWrite): void;
48
- export declare function replayed(store: Store, record: ReplicaRecord, confirmedLayer: Slice, queue: readonly ChangeBatch[]): import("./turn.js").Later<import("./replica.js").Replayed>;
49
- export declare function overlayDiff(record: ReplicaRecord, before: HeldReplica | undefined, visible: VisibleLayer, touched: ReadonlySet<string>): Promise<{
50
- overlay: NonNullable<RoomCommit['overlay']>;
51
- touched: ReadonlySet<string>;
52
- }>;
53
- export type Settlement = {
54
- readonly locator: string;
55
- readonly left: readonly ChangeBatch[];
56
- readonly commit: {
57
- readonly rooms: readonly RoomCommit[];
58
- readonly writes: readonly AuthoredWrite[];
59
- };
60
- apply(answer: CommittedWrite): ChangeSet;
61
- };
62
- export declare function settle(runtime: Runtime, local: RuntimeStore, locator: string, work: Work, record: ReplicaRecord, queue: readonly ChangeBatch[], settling?: Settling): Promise<ChangeSet>;
63
- export declare function together(runtime: Runtime, local: RuntimeStore, settlements: readonly Settlement[]): Promise<ChangeSet>;
64
- export declare function settlement(runtime: Runtime, local: RuntimeStore, locator: string, work: Work, record: ReplicaRecord, queue: readonly ChangeBatch[], settling?: Settling): Promise<Settlement>;
65
- export declare function unpairing(runtime: Runtime, local: RuntimeStore, locator: string, batches: readonly ChangeBatch[]): Promise<Settlement>;
66
28
  export declare function saveRoomDrafts(runtime: Runtime, locator: string, named: readonly SavedRoomDraft[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
67
29
  export declare function saveParts(runtime: Runtime, locator: string, named: readonly SavedParts[], writtenBy: WrittenBy | undefined): Promise<SaveResult>;
68
30
  export declare function batchFile(store: Store, batch: ChangeBatch): (localId: string) => Promise<Blob>;
@@ -1 +1 @@
1
- {"version":3,"file":"saves.d.ts","sourceRoot":"","sources":["../src/saves.ts"],"names":[],"mappings":"AAGA,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AAQrB,OAAO,EAQL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,cAAc,CAAC;AAItB,OAAO,EAWL,KAAK,WAAW,EAEhB,KAAK,aAAa,EAClB,KAAK,KAAK,EACV,KAAK,YAAY,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAYL,KAAK,YAAY,EACjB,KAAK,cAAc,EAGpB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAQL,KAAK,WAAW,EAEjB,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EAEd,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,KAAK,EACL,WAAW,EAEX,IAAI,EACJ,IAAI,EACL,MAAM,YAAY,CAAC;AAKpB,MAAM,MAAM,UAAU,G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