@agentshouse/mdruntime 0.1.0-cd3486bd400ed → 0.1.0-cde2b99d2fcbc
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/AGENTS.md +70 -42
- package/README.md +11 -2
- package/dist/adapter.d.ts +34 -11
- package/dist/adapter.d.ts.map +1 -1
- package/dist/binary.d.ts +23 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +5 -8
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +8 -7
- package/dist/change.d.ts +11 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +26 -1
- package/dist/chat/context.d.ts +3 -0
- package/dist/chat/context.d.ts.map +1 -0
- package/dist/chat/context.js +10 -0
- package/dist/chat/input.d.ts +9 -0
- package/dist/chat/input.d.ts.map +1 -0
- package/dist/chat/input.js +99 -0
- package/dist/chat/kit.d.ts +60 -0
- package/dist/chat/kit.d.ts.map +1 -0
- package/dist/chat/kit.js +123 -0
- package/dist/chat/lasting.d.ts +6 -0
- package/dist/chat/lasting.d.ts.map +1 -0
- package/dist/chat/lasting.js +19 -0
- package/dist/chat/list.d.ts +20 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +59 -0
- package/dist/chat/markdown.d.ts +19 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +187 -0
- package/dist/chat/message.d.ts +6 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +192 -0
- package/dist/chat/name.d.ts +6 -0
- package/dist/chat/name.d.ts.map +1 -0
- package/dist/chat/name.js +37 -0
- package/dist/chat/opened.d.ts +11 -0
- package/dist/chat/opened.d.ts.map +1 -0
- package/dist/chat/opened.js +17 -0
- package/dist/chat/provider.d.ts +6 -0
- package/dist/chat/provider.d.ts.map +1 -1
- package/dist/chat/provider.js +9 -1
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +80 -0
- package/dist/chat/ready.d.ts +33 -0
- package/dist/chat/ready.d.ts.map +1 -0
- package/dist/chat/ready.js +91 -0
- package/dist/chat/style.d.ts +4 -0
- package/dist/chat/style.d.ts.map +1 -0
- package/dist/chat/style.js +302 -0
- package/dist/chat.d.ts +7 -0
- package/dist/chat.d.ts.map +1 -1
- package/dist/chat.js +6 -0
- package/dist/client.d.ts +7 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +10 -0
- package/dist/connection.d.ts +9 -4
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +184 -15
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +4 -0
- package/dist/identity.d.ts +1 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +3 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/memory.d.ts +3 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +31 -11
- package/dist/outcome.d.ts +7 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +6 -0
- package/dist/overlay.d.ts +13 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +56 -22
- package/dist/query.d.ts +2 -0
- package/dist/query.d.ts.map +1 -1
- package/dist/reach.d.ts +2 -0
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +23 -1
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +9 -2
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +12 -17
- package/dist/replica.d.ts +5 -2
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +43 -27
- package/dist/room-draft.d.ts +19 -2
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +119 -1
- package/dist/rows.d.ts +3 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +3 -1
- package/dist/save.d.ts +24 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +304 -14
- package/dist/store.d.ts +6 -7
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +79 -91
- package/dist/wire.d.ts +2 -0
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +2 -0
- package/package.json +11 -3
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
package/dist/save.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { definitionOf } from './model.js';
|
|
2
2
|
import { apply, ATTACHMENT, links, parse, pointerSegments, references, relative, relativize, retarget, serialize, target, } from '@agentshouse/mdmodel';
|
|
3
|
-
import { immutable, } from './change.js';
|
|
3
|
+
import { immutable, queuedFile, departure, } from './change.js';
|
|
4
4
|
import { collectionOf, documentsOf, governing, validateCollection, } from './collection.js';
|
|
5
5
|
import { changeBatchIdentity } from './identity.js';
|
|
6
6
|
import { overlay } from './overlay.js';
|
|
@@ -122,7 +122,10 @@ function rewrites(changes, visible) {
|
|
|
122
122
|
for (const change of changes) {
|
|
123
123
|
if (change.kind === 'move')
|
|
124
124
|
moves.set(change.path, change.to);
|
|
125
|
-
if (change.kind === 'remove' ||
|
|
125
|
+
if (change.kind === 'remove' ||
|
|
126
|
+
change.kind === 'replace' ||
|
|
127
|
+
change.kind === 'create' ||
|
|
128
|
+
change.kind === 'binary') {
|
|
126
129
|
settled.add(change.path);
|
|
127
130
|
}
|
|
128
131
|
if (change.kind === 'field')
|
|
@@ -216,9 +219,9 @@ function affected(change) {
|
|
|
216
219
|
function guard(changes, input) {
|
|
217
220
|
const existing = new Set([
|
|
218
221
|
...Object.keys(input.visible.documents),
|
|
219
|
-
...input.visible.
|
|
222
|
+
...Object.keys(input.visible.binaries),
|
|
220
223
|
]);
|
|
221
|
-
for (const change of changes) {
|
|
224
|
+
for (const [index, change] of changes.entries()) {
|
|
222
225
|
for (const path of affected(change)) {
|
|
223
226
|
const normalized = normalize(path);
|
|
224
227
|
if (normalized === null || normalized === '')
|
|
@@ -236,12 +239,26 @@ function guard(changes, input) {
|
|
|
236
239
|
existing.add(change.path);
|
|
237
240
|
continue;
|
|
238
241
|
}
|
|
242
|
+
if (change.kind === 'binary') {
|
|
243
|
+
if (input.visible.documents[change.path] !== undefined ||
|
|
244
|
+
(existing.has(change.path) &&
|
|
245
|
+
input.bases.some((base) => base.kind === 'absent' && base.path === change.path))) {
|
|
246
|
+
return refuse('path-collision', change.path);
|
|
247
|
+
}
|
|
248
|
+
if (!input.local &&
|
|
249
|
+
existing.has(change.path) &&
|
|
250
|
+
input.visible.revisions[departure(changes, index)] === undefined) {
|
|
251
|
+
return refuse('unknown-revision', change.path);
|
|
252
|
+
}
|
|
253
|
+
existing.add(change.path);
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
239
256
|
if (change.kind === 'move') {
|
|
240
257
|
if (!existing.has(change.path))
|
|
241
258
|
return refuse('path-absent', change.path);
|
|
242
259
|
if (existing.has(change.to))
|
|
243
260
|
return refuse('path-collision', change.to);
|
|
244
|
-
if (
|
|
261
|
+
if (unrevised(input, change.path)) {
|
|
245
262
|
return refuse('unknown-revision', change.path);
|
|
246
263
|
}
|
|
247
264
|
existing.delete(change.path);
|
|
@@ -251,7 +268,7 @@ function guard(changes, input) {
|
|
|
251
268
|
if (!existing.has(change.path))
|
|
252
269
|
return refuse('path-absent', change.path);
|
|
253
270
|
if (change.kind === 'remove') {
|
|
254
|
-
if (
|
|
271
|
+
if (unrevised(input, change.path)) {
|
|
255
272
|
return refuse('unknown-revision', change.path);
|
|
256
273
|
}
|
|
257
274
|
existing.delete(change.path);
|
|
@@ -269,8 +286,12 @@ function guard(changes, input) {
|
|
|
269
286
|
}
|
|
270
287
|
return null;
|
|
271
288
|
}
|
|
272
|
-
function
|
|
273
|
-
return visible.revisions[path] === undefined
|
|
289
|
+
function unrevised(input, path) {
|
|
290
|
+
return (!input.local && input.queued?.has(path) !== true && input.visible.revisions[path] === undefined);
|
|
291
|
+
}
|
|
292
|
+
function identity(precondition) {
|
|
293
|
+
const part = precondition.kind === 'field' || precondition.kind === 'section' ? precondition.name : '';
|
|
294
|
+
return `${precondition.kind} ${precondition.path} ${part}`;
|
|
274
295
|
}
|
|
275
296
|
function existence(visible, path) {
|
|
276
297
|
const revision = visible.revisions[path];
|
|
@@ -289,11 +310,10 @@ function preconditionsOf(changes, visible, bases) {
|
|
|
289
310
|
const preconditions = [];
|
|
290
311
|
const seen = new Set();
|
|
291
312
|
const add = (precondition) => {
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
if (seen.has(identity))
|
|
313
|
+
const held = identity(precondition);
|
|
314
|
+
if (seen.has(held))
|
|
295
315
|
return;
|
|
296
|
-
seen.add(
|
|
316
|
+
seen.add(held);
|
|
297
317
|
preconditions.push(precondition);
|
|
298
318
|
};
|
|
299
319
|
for (const change of changes) {
|
|
@@ -328,6 +348,13 @@ function preconditionsOf(changes, visible, bases) {
|
|
|
328
348
|
add({ kind: 'absent', path: change.path });
|
|
329
349
|
continue;
|
|
330
350
|
}
|
|
351
|
+
if (change.kind === 'binary') {
|
|
352
|
+
const revision = visible.revisions[change.path];
|
|
353
|
+
add(visible.binaries[change.path] === undefined || revision === undefined
|
|
354
|
+
? { kind: 'absent', path: change.path }
|
|
355
|
+
: { kind: 'revision', path: change.path, revision });
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
331
358
|
add(existence(visible, change.path));
|
|
332
359
|
if (change.kind === 'move')
|
|
333
360
|
add({ kind: 'absent', path: change.to });
|
|
@@ -340,7 +367,7 @@ function depth(path) {
|
|
|
340
367
|
function exceeded(limits, changes, resulting) {
|
|
341
368
|
const written = changes.map((change) => (change.kind === 'move' ? change.to : change.path));
|
|
342
369
|
const created = changes
|
|
343
|
-
.filter((change) => change.kind === 'create' || change.kind === 'move')
|
|
370
|
+
.filter((change) => change.kind === 'create' || change.kind === 'move' || change.kind === 'binary')
|
|
344
371
|
.map((change) => (change.kind === 'move' ? change.to : change.path));
|
|
345
372
|
for (const limit of limits) {
|
|
346
373
|
const value = limit.value;
|
|
@@ -431,6 +458,269 @@ function unmodeledType(collection, composition) {
|
|
|
431
458
|
}
|
|
432
459
|
return false;
|
|
433
460
|
}
|
|
461
|
+
function unqueueable(file) {
|
|
462
|
+
return { kind: 'refused', refusal: { code: 'unknown-revision', retryable: false, file } };
|
|
463
|
+
}
|
|
464
|
+
function isPart(change) {
|
|
465
|
+
return change.kind === 'field' || change.kind === 'section' || change.kind === 'preamble';
|
|
466
|
+
}
|
|
467
|
+
function touched(change) {
|
|
468
|
+
return change.kind === 'move' ? [change.path, change.to] : [change.path];
|
|
469
|
+
}
|
|
470
|
+
function partApplied(content, path, change) {
|
|
471
|
+
const parsed = parse(content, path);
|
|
472
|
+
if (!parsed.ok)
|
|
473
|
+
return null;
|
|
474
|
+
const document = parsed.document;
|
|
475
|
+
const applied = apply(document, change.kind === 'field'
|
|
476
|
+
? {
|
|
477
|
+
kind: 'field',
|
|
478
|
+
name: change.name,
|
|
479
|
+
value: change.value,
|
|
480
|
+
prior: document.fields[change.name],
|
|
481
|
+
}
|
|
482
|
+
: change.kind === 'section'
|
|
483
|
+
? {
|
|
484
|
+
kind: 'section',
|
|
485
|
+
name: change.name,
|
|
486
|
+
value: change.value,
|
|
487
|
+
prior: document.sections[change.name],
|
|
488
|
+
}
|
|
489
|
+
: { kind: 'preamble', value: change.value, prior: document.preamble });
|
|
490
|
+
return applied.outcome === 'applied' ? serialize(applied.document) : null;
|
|
491
|
+
}
|
|
492
|
+
function folded(changes, change, appending) {
|
|
493
|
+
const held = changes.find((item) => item.path === change.path && (item.kind === 'create' || item.kind === 'replace'));
|
|
494
|
+
const whole = held === undefined ? -1 : changes.indexOf(held);
|
|
495
|
+
const occupied = changes.some((item) => !isPart(item) && item !== held && touched(item).includes(change.path));
|
|
496
|
+
if (isPart(change)) {
|
|
497
|
+
const same = changes.findIndex((item) => item.kind === change.kind &&
|
|
498
|
+
item.path === change.path &&
|
|
499
|
+
(change.kind === 'preamble' || ('name' in item && item.name === change.name)));
|
|
500
|
+
if (same !== -1) {
|
|
501
|
+
changes[same] = change;
|
|
502
|
+
return 'folded';
|
|
503
|
+
}
|
|
504
|
+
if (held === undefined) {
|
|
505
|
+
if (!appending)
|
|
506
|
+
return 'skipped';
|
|
507
|
+
if (occupied)
|
|
508
|
+
return 'refused';
|
|
509
|
+
changes.push(change);
|
|
510
|
+
return 'appended';
|
|
511
|
+
}
|
|
512
|
+
if ('content' in held) {
|
|
513
|
+
const content = partApplied(held.content, held.path, change);
|
|
514
|
+
if (content === null)
|
|
515
|
+
return 'refused';
|
|
516
|
+
changes[whole] = { ...held, content };
|
|
517
|
+
return 'folded';
|
|
518
|
+
}
|
|
519
|
+
if (change.kind === 'preamble')
|
|
520
|
+
return 'refused';
|
|
521
|
+
changes[whole] =
|
|
522
|
+
change.kind === 'field'
|
|
523
|
+
? { ...held, fields: { ...held.fields, [change.name]: change.value } }
|
|
524
|
+
: { ...held, sections: { ...held.sections, [change.name]: change.value } };
|
|
525
|
+
return 'folded';
|
|
526
|
+
}
|
|
527
|
+
if (change.kind === 'replace') {
|
|
528
|
+
if (held !== undefined) {
|
|
529
|
+
if (!('content' in held))
|
|
530
|
+
return 'refused';
|
|
531
|
+
changes[whole] = { ...held, content: change.content };
|
|
532
|
+
return 'folded';
|
|
533
|
+
}
|
|
534
|
+
const parts = changes.filter((item) => isPart(item) && item.path === change.path);
|
|
535
|
+
if (parts.length === 0 && !appending)
|
|
536
|
+
return 'skipped';
|
|
537
|
+
if (occupied)
|
|
538
|
+
return 'refused';
|
|
539
|
+
changes.splice(0, changes.length, ...changes.filter((item) => !parts.includes(item)), change);
|
|
540
|
+
return 'appended';
|
|
541
|
+
}
|
|
542
|
+
if (changes.some((item) => touched(change).some((path) => touched(item).includes(path))))
|
|
543
|
+
return 'refused';
|
|
544
|
+
changes.push(change);
|
|
545
|
+
return 'appended';
|
|
546
|
+
}
|
|
547
|
+
function relinked(batch, move, before, after, appending) {
|
|
548
|
+
const derived = rewrites([move], after);
|
|
549
|
+
if (derived.kind === 'refused')
|
|
550
|
+
return derived;
|
|
551
|
+
const changes = [...batch.changes];
|
|
552
|
+
const appended = [];
|
|
553
|
+
let changed = false;
|
|
554
|
+
for (const change of derived.changes) {
|
|
555
|
+
if (change === move)
|
|
556
|
+
continue;
|
|
557
|
+
const outcome = folded(changes, change, appending);
|
|
558
|
+
if (outcome === 'refused')
|
|
559
|
+
return unqueueable(change.path);
|
|
560
|
+
if (outcome === 'appended')
|
|
561
|
+
appended.push(change);
|
|
562
|
+
if (outcome !== 'skipped')
|
|
563
|
+
changed = true;
|
|
564
|
+
}
|
|
565
|
+
if (!changed)
|
|
566
|
+
return { kind: 'relinked', batch };
|
|
567
|
+
const held = new Set(batch.preconditions.map(identity));
|
|
568
|
+
return {
|
|
569
|
+
kind: 'relinked',
|
|
570
|
+
batch: immutable({
|
|
571
|
+
...batch,
|
|
572
|
+
id: changeBatchIdentity(),
|
|
573
|
+
changes,
|
|
574
|
+
preconditions: [
|
|
575
|
+
...batch.preconditions,
|
|
576
|
+
...preconditionsOf(appended, before, []).filter((precondition) => !held.has(identity(precondition))),
|
|
577
|
+
],
|
|
578
|
+
}),
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function leading(changes, at) {
|
|
582
|
+
const from = departure(changes, at);
|
|
583
|
+
return new Set(changes.filter((change, index) => index < at && change.kind === 'move' && departure(changes, index) === from));
|
|
584
|
+
}
|
|
585
|
+
function created(batch, at) {
|
|
586
|
+
const file = batch.changes[at];
|
|
587
|
+
return (leading(batch.changes, at).size === 0 &&
|
|
588
|
+
batch.preconditions.some((precondition) => precondition.kind === 'absent' && precondition.path === file.path));
|
|
589
|
+
}
|
|
590
|
+
function withdrawnFile(batch, change, at) {
|
|
591
|
+
const file = batch.changes[at];
|
|
592
|
+
const from = departure(batch.changes, at);
|
|
593
|
+
const moves = leading(batch.changes, at);
|
|
594
|
+
const fresh = created(batch, at);
|
|
595
|
+
const vacated = new Set([...moves].map((move) => move.to));
|
|
596
|
+
if (fresh)
|
|
597
|
+
vacated.add(file.path);
|
|
598
|
+
const replaced = fresh
|
|
599
|
+
? change.kind === 'remove'
|
|
600
|
+
? []
|
|
601
|
+
: [{ ...file, path: change.to }]
|
|
602
|
+
: change.kind === 'remove'
|
|
603
|
+
? [{ kind: 'remove', path: from }]
|
|
604
|
+
: change.to === from
|
|
605
|
+
? [{ ...file, path: from }]
|
|
606
|
+
: [
|
|
607
|
+
{ kind: 'move', path: from, to: change.to },
|
|
608
|
+
{ ...file, path: change.to },
|
|
609
|
+
];
|
|
610
|
+
const added = change.kind === 'move' && (fresh || change.to !== from)
|
|
611
|
+
? [{ kind: 'absent', path: change.to }]
|
|
612
|
+
: [];
|
|
613
|
+
const changes = batch.changes.flatMap((item) => item === file ? replaced : item.kind === 'move' && moves.has(item) ? [] : [item]);
|
|
614
|
+
if (changes.length === 0)
|
|
615
|
+
return null;
|
|
616
|
+
const preconditions = [
|
|
617
|
+
...added,
|
|
618
|
+
...batch.preconditions.filter((precondition) => precondition.kind !== 'absent' || !vacated.has(precondition.path)),
|
|
619
|
+
];
|
|
620
|
+
return immutable({ ...batch, id: changeBatchIdentity(), changes, preconditions });
|
|
621
|
+
}
|
|
622
|
+
export function requeued(queue, changes, visible, changeable, state) {
|
|
623
|
+
const next = [...queue];
|
|
624
|
+
const origins = new Map();
|
|
625
|
+
const withdrawn = new Map();
|
|
626
|
+
const owners = new Set();
|
|
627
|
+
const queued = new Set();
|
|
628
|
+
const kept = [];
|
|
629
|
+
const originOf = (batch) => origins.get(batch) ?? batch.id;
|
|
630
|
+
const open = (batch) => origins.has(batch) || changeable(batch);
|
|
631
|
+
for (const change of changes) {
|
|
632
|
+
const held = visible.binaries[change.path];
|
|
633
|
+
if ((change.kind !== 'move' && change.kind !== 'remove') || held?.state !== 'pending') {
|
|
634
|
+
kept.push(change);
|
|
635
|
+
continue;
|
|
636
|
+
}
|
|
637
|
+
let index = next.length - 1;
|
|
638
|
+
while (index >= 0 && queuedFile(next[index], change.path, held.localId) === -1)
|
|
639
|
+
index -= 1;
|
|
640
|
+
const owner = next[index];
|
|
641
|
+
if (owner === undefined || !open(owner))
|
|
642
|
+
return unqueueable(change.path);
|
|
643
|
+
const following = next.slice(index);
|
|
644
|
+
const rebuilt = [];
|
|
645
|
+
let before = change.kind === 'move' ? state(next.slice(0, index)) : visible;
|
|
646
|
+
for (const [offset, batch] of following.entries()) {
|
|
647
|
+
let current = batch;
|
|
648
|
+
if (change.kind === 'move') {
|
|
649
|
+
const after = state(next.slice(0, index + offset + 1));
|
|
650
|
+
const appending = offset === 0 && created(batch, queuedFile(batch, change.path, held.localId));
|
|
651
|
+
const relinking = relinked(batch, change, before, after, appending);
|
|
652
|
+
if (relinking.kind === 'refused')
|
|
653
|
+
return relinking;
|
|
654
|
+
current = relinking.batch;
|
|
655
|
+
before = after;
|
|
656
|
+
}
|
|
657
|
+
if (current !== batch && !open(batch))
|
|
658
|
+
return unqueueable(change.path);
|
|
659
|
+
rebuilt.push(offset === 0
|
|
660
|
+
? withdrawnFile(current, change, queuedFile(current, change.path, held.localId))
|
|
661
|
+
: current);
|
|
662
|
+
}
|
|
663
|
+
for (const [offset, batch] of following.entries()) {
|
|
664
|
+
const replaced = rebuilt[offset];
|
|
665
|
+
if (replaced === batch)
|
|
666
|
+
continue;
|
|
667
|
+
const origin = originOf(batch);
|
|
668
|
+
withdrawn.set(origin, replaced);
|
|
669
|
+
if (replaced !== null)
|
|
670
|
+
origins.set(replaced, origin);
|
|
671
|
+
}
|
|
672
|
+
owners.add(originOf(owner));
|
|
673
|
+
next.splice(index, following.length, ...rebuilt.filter((batch) => batch !== null));
|
|
674
|
+
queued.add(change.path);
|
|
675
|
+
}
|
|
676
|
+
return {
|
|
677
|
+
kind: 'requeued',
|
|
678
|
+
queue: withdrawn.size === 0 ? queue : next,
|
|
679
|
+
changes: kept,
|
|
680
|
+
queued,
|
|
681
|
+
withdrawn,
|
|
682
|
+
owners,
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
function covering(precondition) {
|
|
686
|
+
return precondition.kind === 'field' ||
|
|
687
|
+
precondition.kind === 'section' ||
|
|
688
|
+
precondition.kind === 'preamble'
|
|
689
|
+
? identity(precondition)
|
|
690
|
+
: `path ${precondition.path}`;
|
|
691
|
+
}
|
|
692
|
+
export function joined(queue, owner, extra) {
|
|
693
|
+
const later = new Set(queue.slice(queue.indexOf(owner) + 1).flatMap((batch) => batch.changes.flatMap(touched)));
|
|
694
|
+
const clash = extra.changes.flatMap(touched).find((path) => later.has(path));
|
|
695
|
+
if (clash !== undefined)
|
|
696
|
+
return unqueueable(clash);
|
|
697
|
+
const changes = [...owner.changes];
|
|
698
|
+
for (const change of extra.changes) {
|
|
699
|
+
if (folded(changes, change, true) === 'refused')
|
|
700
|
+
return unqueueable(change.path);
|
|
701
|
+
}
|
|
702
|
+
const held = new Set(owner.preconditions.map(covering));
|
|
703
|
+
const written = new Set(owner.changes.flatMap((change) => change.kind === 'create' || change.kind === 'replace' ? [change.path] : []));
|
|
704
|
+
const preconditions = [
|
|
705
|
+
...owner.preconditions,
|
|
706
|
+
...extra.preconditions.filter((precondition) => {
|
|
707
|
+
const key = covering(precondition);
|
|
708
|
+
return (!held.has(key) && (key === `path ${precondition.path}` || !written.has(precondition.path)));
|
|
709
|
+
}),
|
|
710
|
+
];
|
|
711
|
+
const batch = immutable({
|
|
712
|
+
...owner,
|
|
713
|
+
...(extra.validation === undefined ? {} : { validation: extra.validation }),
|
|
714
|
+
id: changeBatchIdentity(),
|
|
715
|
+
changes,
|
|
716
|
+
preconditions,
|
|
717
|
+
});
|
|
718
|
+
return { kind: 'joined', batch, queue: queue.map((item) => (item === owner ? batch : item)) };
|
|
719
|
+
}
|
|
720
|
+
export function limitedIn(queue, batch, limits, state) {
|
|
721
|
+
const limited = exceeded(limits, batch.changes, state(queue.slice(0, queue.indexOf(batch) + 1)));
|
|
722
|
+
return limited?.kind === 'refused' ? limited.refusal : null;
|
|
723
|
+
}
|
|
434
724
|
export function buildBatch(input) {
|
|
435
725
|
const changes = relativeChanges(input);
|
|
436
726
|
const structural = changes.find((change) => change.kind === 'move' || change.kind === 'remove');
|
|
@@ -469,7 +759,7 @@ export function buildBatch(input) {
|
|
|
469
759
|
const validationText = needsModel
|
|
470
760
|
? resulting.documents
|
|
471
761
|
: Object.fromEntries(Object.entries(resulting.documents).filter(([path]) => predicted.changes.some((change) => affected(change).includes(path))));
|
|
472
|
-
const verdict = validateCollection(validationText, resulting.
|
|
762
|
+
const verdict = validateCollection(validationText, Object.keys(resulting.binaries), input.composition);
|
|
473
763
|
if (verdict.verdict === 'refuse') {
|
|
474
764
|
return {
|
|
475
765
|
kind: 'refused',
|
package/dist/store.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { ModelState } from './model.js';
|
|
2
|
-
import type { Capability, HeadChange, Member, OperationScopes, ProviderLimit, ReplicaAdmission,
|
|
2
|
+
import type { Capability, HeadChange, Member, OperationScopes, ProviderLimit, ReplicaAdmission, TypedSelection } from './adapter.js';
|
|
3
3
|
import type { AcceptedMessage } from './adapter.js';
|
|
4
4
|
import type { ChangeBatch } from './change.js';
|
|
5
|
+
import { type HeldBinary } from './overlay.js';
|
|
5
6
|
import type { ChatDraftFile } from './file.js';
|
|
6
7
|
import type { Submission } from './outcome.js';
|
|
7
8
|
import type { RoomDraftRecord, SavedDraft } from './room-draft.js';
|
|
8
|
-
export declare const STORE_SCHEMA =
|
|
9
|
+
export declare const STORE_SCHEMA = 22;
|
|
9
10
|
export type ReplicaRecord = {
|
|
10
11
|
locator: string;
|
|
11
12
|
name: string;
|
|
@@ -19,13 +20,12 @@ export type ReplicaRecord = {
|
|
|
19
20
|
roomVersion: string;
|
|
20
21
|
transfer: string;
|
|
21
22
|
documents: Readonly<Record<string, string>>;
|
|
22
|
-
|
|
23
|
+
binaries: Readonly<Record<string, HeldBinary>>;
|
|
23
24
|
revisions: Readonly<Record<string, string>>;
|
|
24
25
|
changes: Readonly<Record<string, HeadChange>>;
|
|
25
26
|
written: Readonly<Record<string, string>>;
|
|
26
|
-
attachments: readonly RoomAttachment[];
|
|
27
27
|
};
|
|
28
|
-
export type StagedLayer = Pick<ReplicaRecord, 'documents' | '
|
|
28
|
+
export type StagedLayer = Pick<ReplicaRecord, 'documents' | 'binaries' | 'revisions' | 'changes' | 'written'>;
|
|
29
29
|
export type TransferRecord = {
|
|
30
30
|
locator: string;
|
|
31
31
|
transfer: string;
|
|
@@ -37,7 +37,6 @@ export type TransferRecord = {
|
|
|
37
37
|
collection: ModelState;
|
|
38
38
|
selection: ModelState;
|
|
39
39
|
};
|
|
40
|
-
attachments: readonly (readonly RoomAttachment[])[];
|
|
41
40
|
};
|
|
42
41
|
export type PendingState = {
|
|
43
42
|
readonly drafts: readonly SavedDraft[];
|
|
@@ -81,7 +80,7 @@ export type RecordWrite = {
|
|
|
81
80
|
stored?: StagedLayer;
|
|
82
81
|
queue: readonly ChangeBatch[];
|
|
83
82
|
previousQueue?: readonly ChangeBatch[];
|
|
84
|
-
saved?: readonly SavedDraft[]
|
|
83
|
+
saved?: ReadonlyMap<string, readonly SavedDraft[]>;
|
|
85
84
|
roomDrafts?: readonly RoomDraftRecord[];
|
|
86
85
|
consumedRoomDrafts?: readonly string[];
|
|
87
86
|
};
|
package/dist/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,MAAM,EACN,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,cAAc,
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC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