@agentshouse/mdruntime 0.1.0-cb2e390ee7b89 → 0.1.0-cb9c79aee537a
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 +28 -28
- package/README.md +8 -8
- package/dist/adapter.d.ts +7 -6
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.js +1 -1
- package/dist/chat/markdown.d.ts +1 -0
- package/dist/chat/markdown.d.ts.map +1 -1
- package/dist/chat/markdown.js +78 -20
- package/dist/chat/pieces.d.ts +51 -0
- package/dist/chat/pieces.d.ts.map +1 -0
- package/dist/chat/pieces.js +797 -0
- package/dist/chat/provider.d.ts.map +1 -1
- package/dist/chat/provider.js +3 -10
- package/dist/chat.d.ts +1 -1
- package/dist/chat.d.ts.map +1 -1
- package/dist/chat.js +1 -1
- package/dist/client.d.ts +3 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -0
- package/dist/collection.d.ts +4 -3
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +128 -63
- package/dist/connection.d.ts +6 -3
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +124 -121
- package/dist/conversation.d.ts +1 -0
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +49 -29
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +2 -1
- package/dist/host.d.ts +0 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +4 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/memory.d.ts +2 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +7 -9
- package/dist/overlay.d.ts +1 -0
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +7 -3
- package/dist/query.d.ts +5 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +5 -3
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +10 -0
- package/dist/react.d.ts +1 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +2 -14
- package/dist/read-side.d.ts +3 -1
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +87 -24
- package/dist/refresh.js +1 -1
- package/dist/replica.d.ts +5 -4
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +35 -25
- package/dist/rows.d.ts +1 -0
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +5 -0
- package/dist/save.d.ts +2 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +25 -19
- package/dist/shared.d.ts +3 -0
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +58 -32
- package/dist/store.d.ts +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +2 -6
- package/dist/turn.d.ts +5 -3
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +25 -6
- package/dist/windows.d.ts +8 -0
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +13 -0
- package/dist/wire.d.ts +8 -0
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +2 -0
- package/package.json +2 -2
- package/dist/acquisition.d.ts +0 -14
- package/dist/acquisition.d.ts.map +0 -1
- package/dist/acquisition.js +0 -24
package/dist/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
-
import { failed
|
|
2
|
+
import { failed } from './failure.js';
|
|
3
3
|
const LOADING = { state: 'loading' };
|
|
4
4
|
export function useObserve(client, topic, ...input) {
|
|
5
5
|
const key = JSON.stringify([topic, ...input]);
|
|
@@ -33,18 +33,6 @@ export function useObserve(client, topic, ...input) {
|
|
|
33
33
|
return held !== null && held.client === client && held.key === key ? held.observed : LOADING;
|
|
34
34
|
}
|
|
35
35
|
const IDLE = { busy: false, outcome: null, failure: null };
|
|
36
|
-
export async function saveRoomDrafts(client, room, roomDrafts) {
|
|
37
|
-
const kept = [];
|
|
38
|
-
for (const [path, parts] of roomDrafts) {
|
|
39
|
-
const prior = await client.roomDraft.read(room, path);
|
|
40
|
-
const write = await client.roomDraft.write(room, path, prior?.revision ?? null, parts);
|
|
41
|
-
if (write.outcome !== 'written' || write.roomDraft === null) {
|
|
42
|
-
throw runtimeError(write.outcome === 'stale' ? write.code : 'room-draft-unwritten', `the Room Draft at ${path} was not written`);
|
|
43
|
-
}
|
|
44
|
-
kept.push({ path, revision: write.roomDraft.revision });
|
|
45
|
-
}
|
|
46
|
-
return client.save(room, kept);
|
|
47
|
-
}
|
|
48
36
|
export function useSave(client) {
|
|
49
37
|
const [state, setState] = useState(IDLE);
|
|
50
38
|
const settled = useCallback(async (saving) => {
|
|
@@ -60,7 +48,7 @@ export function useSave(client) {
|
|
|
60
48
|
throw failure;
|
|
61
49
|
}
|
|
62
50
|
}, []);
|
|
63
|
-
const save = useCallback((room,
|
|
51
|
+
const save = useCallback((room, parts) => settled(() => client.saveParts(room, [...parts].map(([path, one]) => ({ path, parts: one })))), [client, settled]);
|
|
64
52
|
const saveWritten = useCallback((room, roomDrafts) => settled(() => client.save(room, roomDrafts)), [client, settled]);
|
|
65
53
|
return { ...state, save, saveWritten };
|
|
66
54
|
}
|
package/dist/read-side.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { ChangeSet } from './change-set.js';
|
|
2
2
|
import { type KeyedResult, type QueryMessage } from './observation.js';
|
|
3
3
|
import type { PendingResult, Plan, QueryCoverage, QueryRows } from './query.js';
|
|
4
|
+
import { type Later } from './turn.js';
|
|
4
5
|
import type { SearchedDocument } from './search.js';
|
|
5
6
|
export type Cover = {
|
|
6
7
|
coverage: QueryCoverage;
|
|
7
8
|
} | PendingResult;
|
|
8
9
|
export type ReadSide = {
|
|
9
|
-
apply(set: ChangeSet): void
|
|
10
|
+
apply(set: ChangeSet, next?: () => void): Later<void>;
|
|
10
11
|
recover(): void;
|
|
12
|
+
settled(): Promise<void>;
|
|
11
13
|
query<T>(plan: Plan, at: () => T): Promise<{
|
|
12
14
|
rows: QueryRows;
|
|
13
15
|
at: T;
|
package/dist/read-side.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-side.d.ts","sourceRoot":"","sources":["../src/read-side.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,KAAK,WAAW,EAEhB,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAOV,aAAa,EACb,IAAI,EAEJ,aAAa,EAGb,SAAS,EAIV,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"read-side.d.ts","sourceRoot":"","sources":["../src/read-side.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,KAAK,WAAW,EAEhB,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAOV,aAAa,EACb,IAAI,EAEJ,aAAa,EAGb,SAAS,EAIV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAA8B,KAAK,KAAK,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAkDpD,MAAM,MAAM,KAAK,GAAG;IAAE,QAAQ,EAAE,aAAa,CAAA;CAAE,GAAG,aAAa,CAAC;AAwBhE,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IACtD,OAAO,IAAI,IAAI,CAAC;IAChB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,EAAE,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC;IACvE,KAAK,CACH,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,KAAK,EAClB,OAAO,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,GACvC,MAAM,IAAI,CAAC;IACd,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAC9D,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAucF,wBAAgB,UAAU,CACxB,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,WAAW,GAChB;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,GAAG,IAAI,CA+CtD;AA4BD,wBAAgB,cAAc,IAAI,QAAQ,CA8WzC"}
|
package/dist/read-side.js
CHANGED
|
@@ -60,11 +60,12 @@ function reached(reach, room, document) {
|
|
|
60
60
|
? []
|
|
61
61
|
: [or(inArray(room, [...reach.rooms]), inArray(document, [...reach.documents]))];
|
|
62
62
|
}
|
|
63
|
-
function scoped(scope, row, rooms, reach, paths = null) {
|
|
63
|
+
function scoped(scope, row, rooms, reach, paths = null, folder = null) {
|
|
64
64
|
return every([
|
|
65
65
|
eq(row.kind, 'document'),
|
|
66
66
|
...(rooms === null ? [] : [inArray(row.room, [...rooms])]),
|
|
67
67
|
...(paths === null ? [] : [inArray(row.path, [...paths])]),
|
|
68
|
+
...(folder === null ? [] : [eq(row.folder, folder)]),
|
|
68
69
|
...reached(reach, row.room, row.key),
|
|
69
70
|
...(scope.types === null ? [] : [inArray(row.type, [...scope.types])]),
|
|
70
71
|
...(scope.pathPrefix === null ? [] : [inArray(scope.pathPrefix, row.directories)]),
|
|
@@ -92,7 +93,7 @@ function related(q, rows, scope, field, kept, reach) {
|
|
|
92
93
|
}
|
|
93
94
|
function filtered(q, rows, plan) {
|
|
94
95
|
const from = q.from({ d: rows });
|
|
95
|
-
let query = narrowed(from.where(({ d }) => scoped(plan.root, d, plan.rooms, plan.reach, plan.paths)), plan.root.where, 'd');
|
|
96
|
+
let query = narrowed(from.where(({ d }) => scoped(plan.root, d, plan.rooms, plan.reach, plan.paths, plan.folder)), plan.root.where, 'd');
|
|
96
97
|
if (plan.hop !== null) {
|
|
97
98
|
const hop = related(q, rows, plan.hop, plan.hop.field, 'source', plan.reach);
|
|
98
99
|
query = query.innerJoin({ h: hop }, ({ d, h }) => eq(d.key, h.key));
|
|
@@ -453,6 +454,9 @@ export function createReadSide() {
|
|
|
453
454
|
},
|
|
454
455
|
});
|
|
455
456
|
const shared = new Map();
|
|
457
|
+
let writing = false;
|
|
458
|
+
let publishing = null;
|
|
459
|
+
let closed = false;
|
|
456
460
|
function searched(row) {
|
|
457
461
|
const read = row.text === null ? null : parse(row.text, row.path);
|
|
458
462
|
if (read === null || !read.ok)
|
|
@@ -555,7 +559,8 @@ export function createReadSide() {
|
|
|
555
559
|
.then((window) => {
|
|
556
560
|
if (entry.listeners.size > 0)
|
|
557
561
|
delivered(entry, current(entry, window, cover.coverage));
|
|
558
|
-
|
|
562
|
+
entry.running = false;
|
|
563
|
+
wake(entry);
|
|
559
564
|
})
|
|
560
565
|
.catch(() => {
|
|
561
566
|
entry.running = false;
|
|
@@ -567,7 +572,7 @@ export function createReadSide() {
|
|
|
567
572
|
entry.running = false;
|
|
568
573
|
}
|
|
569
574
|
function wake(entry) {
|
|
570
|
-
if (entry.subscription === null || entry.running)
|
|
575
|
+
if (entry.subscription === null || entry.running || writing || publishing !== null)
|
|
571
576
|
return;
|
|
572
577
|
entry.running = true;
|
|
573
578
|
try {
|
|
@@ -593,36 +598,88 @@ export function createReadSide() {
|
|
|
593
598
|
wake(entry);
|
|
594
599
|
}
|
|
595
600
|
}
|
|
601
|
+
function committed(next) {
|
|
602
|
+
if (closed || next.size === 0)
|
|
603
|
+
return;
|
|
604
|
+
sync.begin();
|
|
605
|
+
for (const [key, row] of next) {
|
|
606
|
+
if (row === null) {
|
|
607
|
+
if (rows.has(key))
|
|
608
|
+
sync.write({ type: 'delete', key });
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
sync.write({ type: rows.has(key) ? 'update' : 'insert', value: row });
|
|
612
|
+
}
|
|
613
|
+
sync.commit();
|
|
614
|
+
}
|
|
615
|
+
function published(set) {
|
|
616
|
+
let unit = new Map();
|
|
617
|
+
return inUnits(set.documents, (change) => {
|
|
618
|
+
if (closed)
|
|
619
|
+
return 0;
|
|
620
|
+
let spent = 0;
|
|
621
|
+
for (const row of change.before) {
|
|
622
|
+
unit.set(row.key, null);
|
|
623
|
+
spent += ROW_WEIGHT;
|
|
624
|
+
}
|
|
625
|
+
for (const row of change.after) {
|
|
626
|
+
unit.set(row.key, row);
|
|
627
|
+
spent += weight(row);
|
|
628
|
+
}
|
|
629
|
+
return spent;
|
|
630
|
+
}, () => {
|
|
631
|
+
committed(unit);
|
|
632
|
+
unit = new Map();
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
function released() {
|
|
636
|
+
recover();
|
|
637
|
+
for (const entry of shared.values())
|
|
638
|
+
wake(entry);
|
|
639
|
+
}
|
|
640
|
+
function publishedLater(applied) {
|
|
641
|
+
const fence = applied.then(() => { }, () => { });
|
|
642
|
+
publishing = fence;
|
|
643
|
+
void fence.then(() => {
|
|
644
|
+
if (publishing !== fence)
|
|
645
|
+
return;
|
|
646
|
+
publishing = null;
|
|
647
|
+
released();
|
|
648
|
+
});
|
|
649
|
+
return applied;
|
|
650
|
+
}
|
|
651
|
+
async function settled() {
|
|
652
|
+
while (publishing !== null)
|
|
653
|
+
await publishing;
|
|
654
|
+
}
|
|
596
655
|
return {
|
|
597
|
-
apply(set) {
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
next.set(row.key, null);
|
|
602
|
-
for (const row of change.after)
|
|
603
|
-
next.set(row.key, row);
|
|
656
|
+
apply(set, next = () => { }) {
|
|
657
|
+
const pending = publishing;
|
|
658
|
+
if (pending !== null) {
|
|
659
|
+
return publishedLater(pending.then(() => after(published(set), next)));
|
|
604
660
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
}
|
|
613
|
-
sync.write({ type: rows.has(key) ? 'update' : 'insert', value: row });
|
|
614
|
-
}
|
|
615
|
-
sync.commit();
|
|
661
|
+
writing = true;
|
|
662
|
+
let applied;
|
|
663
|
+
try {
|
|
664
|
+
applied = published(set);
|
|
665
|
+
}
|
|
666
|
+
finally {
|
|
667
|
+
writing = false;
|
|
616
668
|
}
|
|
617
|
-
|
|
669
|
+
if (applied instanceof Promise)
|
|
670
|
+
return publishedLater(applied.then(next));
|
|
671
|
+
released();
|
|
672
|
+
next();
|
|
618
673
|
},
|
|
619
674
|
recover,
|
|
675
|
+
settled,
|
|
620
676
|
async query(plan, at) {
|
|
621
677
|
const { live: collection, count, dispose } = built(rows, plan);
|
|
622
678
|
try {
|
|
623
679
|
await collection.toArrayWhenReady();
|
|
624
680
|
if (count !== null)
|
|
625
681
|
await count.toArrayWhenReady();
|
|
682
|
+
await settled();
|
|
626
683
|
const entries = [...collection.entries()];
|
|
627
684
|
const held = at();
|
|
628
685
|
const found = await rowsOfPlan(plan, entries, count?.size, null, structuredClone);
|
|
@@ -653,7 +710,9 @@ export function createReadSide() {
|
|
|
653
710
|
running: false,
|
|
654
711
|
};
|
|
655
712
|
created.built.live.on('status:change', ({ status }) => {
|
|
656
|
-
if (status
|
|
713
|
+
if (status !== 'cleaned-up' || created.listeners.size > 0)
|
|
714
|
+
return;
|
|
715
|
+
if (shared.get(identity) === created)
|
|
657
716
|
shared.delete(identity);
|
|
658
717
|
});
|
|
659
718
|
shared.set(identity, created);
|
|
@@ -704,6 +763,9 @@ export function createReadSide() {
|
|
|
704
763
|
observed.bodies.clear();
|
|
705
764
|
observed.dirty.clear();
|
|
706
765
|
observed.whole = true;
|
|
766
|
+
if (shared.get(identity) === observed)
|
|
767
|
+
shared.delete(identity);
|
|
768
|
+
observed.built.dispose();
|
|
707
769
|
};
|
|
708
770
|
},
|
|
709
771
|
room(room) {
|
|
@@ -714,6 +776,7 @@ export function createReadSide() {
|
|
|
714
776
|
return row === undefined || row.type === null ? null : searched(row);
|
|
715
777
|
},
|
|
716
778
|
close() {
|
|
779
|
+
closed = true;
|
|
717
780
|
for (const entry of shared.values()) {
|
|
718
781
|
entry.listeners.clear();
|
|
719
782
|
entry.fresh.clear();
|
package/dist/refresh.js
CHANGED
|
@@ -90,6 +90,6 @@ export async function refreshRoom(adapter, authorization, confirmed, remodel, co
|
|
|
90
90
|
const advanced = await advancement(adapter, authorization, confirmed.record, remodel, continuing);
|
|
91
91
|
if (advanced.kind !== 'advanced')
|
|
92
92
|
return advanced;
|
|
93
|
-
const staged = readStaged(advanced.record, confirmed);
|
|
93
|
+
const staged = await readStaged(advanced.record, confirmed);
|
|
94
94
|
return staged.kind === 'staged' ? { kind: 'advanced', confirmed: staged.confirmed } : staged;
|
|
95
95
|
}
|
package/dist/replica.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { type Layer } from './overlay.js';
|
|
|
4
4
|
import type { MutationResult } from './adapter.js';
|
|
5
5
|
import type { ReplicaRecord } from './store.js';
|
|
6
6
|
import type { Refused } from './transfer.js';
|
|
7
|
+
import { type Later } from './turn.js';
|
|
7
8
|
export type ConfirmedLayer = {
|
|
8
9
|
record: ReplicaRecord;
|
|
9
10
|
collection: Collection;
|
|
@@ -31,14 +32,14 @@ type ReplayStep = {
|
|
|
31
32
|
export declare function compositionOf(record: ReplicaRecord): Composition;
|
|
32
33
|
export declare function confirmedOf(record: ReplicaRecord, previous?: ConfirmedLayer): ConfirmedLayer;
|
|
33
34
|
export declare function sameMembership(record: ReplicaRecord, other: ReplicaRecord): boolean;
|
|
34
|
-
export declare function readStaged(staged: ReplicaRecord, previous?: ConfirmedLayer): Staged
|
|
35
|
-
export declare function readReclassified(record: ReplicaRecord, previous: ConfirmedLayer): Staged | {
|
|
35
|
+
export declare function readStaged(staged: ReplicaRecord, previous?: ConfirmedLayer): Later<Staged>;
|
|
36
|
+
export declare function readReclassified(record: ReplicaRecord, previous: ConfirmedLayer): Later<Staged | {
|
|
36
37
|
kind: 'deferred';
|
|
37
|
-
}
|
|
38
|
+
}>;
|
|
38
39
|
type Accepted = Extract<MutationResult, {
|
|
39
40
|
kind: 'accepted';
|
|
40
41
|
}>;
|
|
41
|
-
export declare function applyReturned(confirmed: ConfirmedLayer, submitted: ChangeBatch, accepted: Accepted, roomVersion: string, writtenAt: string): Staged
|
|
42
|
+
export declare function applyReturned(confirmed: ConfirmedLayer, submitted: ChangeBatch, accepted: Accepted, roomVersion: string, writtenAt: string): Later<Staged>;
|
|
42
43
|
export declare function replicaOf(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[], previous?: Replica): Replica;
|
|
43
44
|
export declare function landed(batch: ChangeBatch, confirmed: ConfirmedLayer, current?: Readonly<Record<string, string>>): boolean;
|
|
44
45
|
export type Standing = {
|
package/dist/replica.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replica.d.ts","sourceRoot":"","sources":["../src/replica.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,KAAK,WAAW,EAAqB,MAAM,aAAa,CAAC;AACnG,OAAO,
|
|
1
|
+
{"version":3,"file":"replica.d.ts","sourceRoot":"","sources":["../src/replica.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,KAAK,WAAW,EAAqB,MAAM,aAAa,CAAC;AACnG,OAAO,EAML,KAAK,UAAU,EACf,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAOL,KAAK,KAAK,EACX,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,c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BAAgB,gBAAgB,CAC9B,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,cAAc,GACvB,KAAK,CAAC,MAAM,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAEtC;AAoBD,KAAK,QAAQ,GAAG,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC;AAE9D,wBAAgB,aAAa,CAC3B,SAAS,EAAE,cAAc,EACzB,SAAS,EAAE,WAAW,EACtB,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,KAAK,CAAC,MAAM,CAAC,CAoCf;AAgDD,wBAAgB,SAAS,CACvB,SAAS,EAAE,cAAc,EACzB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,QAAQ,CAAC,EAAE,OAAO,GACjB,OAAO,CA+BT;AA0ED,wBAAgB,MAAM,CACpB,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,cAAc,EACzB,OAAO,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM,GAC7C,OAAO,CAoBT;AAgBD,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,SAAS,EAAE,SAAS,WAAW,EAAE,CAAC;IAC3C,QAAQ,CAAC,IAAI,EAAE,SAAS,WAAW,EAAE,CAAC;CACvC,CAAC;AAEF,wBAAgB,QAAQ,CACtB,SAAS,EAAE,cAAc,EACzB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,YAAY,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,EAC7C,KAAK,EAAE,OAAO,GACb,QAAQ,CA6BV"}
|
package/dist/replica.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { equalValue, parse } from '@agentshouse/mdmodel';
|
|
2
2
|
import { immutable, landing } from './change.js';
|
|
3
|
-
import { changedCleanly, collectionOf, unreadable, validateCollection, } from './collection.js';
|
|
4
|
-
import { acceptedBinaries, overlay, overlayChanged, sameLayerText, } from './overlay.js';
|
|
3
|
+
import { changedCleanly, collecting, collectionOf, unreadable, validateCollection, } from './collection.js';
|
|
4
|
+
import { acceptedBinaries, overlay, overlayChanged, sameLayerText, sameText, } from './overlay.js';
|
|
5
5
|
import { providerRewritten } from './save.js';
|
|
6
|
-
import { drafted, patched, settled,
|
|
6
|
+
import { drafted, patched, settled, sharing } from './shared.js';
|
|
7
|
+
import { finished, stepped } from './turn.js';
|
|
7
8
|
export function compositionOf(record) {
|
|
8
9
|
return {
|
|
9
10
|
model: record.model,
|
|
@@ -12,13 +13,13 @@ export function compositionOf(record) {
|
|
|
12
13
|
: { roots: record.typedSelection.roots, model: record.selectionModel },
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
const documents =
|
|
17
|
-
const binaries =
|
|
18
|
-
const revisions =
|
|
19
|
-
const fileIds =
|
|
20
|
-
const changes =
|
|
21
|
-
const written =
|
|
16
|
+
function* holding(record) {
|
|
17
|
+
const documents = yield* sharing(record.documents);
|
|
18
|
+
const binaries = yield* sharing(record.binaries);
|
|
19
|
+
const revisions = yield* sharing(record.revisions);
|
|
20
|
+
const fileIds = yield* sharing(record.fileIds);
|
|
21
|
+
const changes = yield* sharing(record.changes);
|
|
22
|
+
const written = yield* sharing(record.written);
|
|
22
23
|
return documents === record.documents &&
|
|
23
24
|
binaries === record.binaries &&
|
|
24
25
|
revisions === record.revisions &&
|
|
@@ -29,56 +30,65 @@ function held(record) {
|
|
|
29
30
|
: { ...record, documents, binaries, revisions, fileIds, changes, written };
|
|
30
31
|
}
|
|
31
32
|
export function confirmedOf(record, previous) {
|
|
32
|
-
|
|
33
|
+
return finished(confirming(record, previous));
|
|
34
|
+
}
|
|
35
|
+
function* confirming(record, previous) {
|
|
36
|
+
const kept = yield* holding(record);
|
|
33
37
|
return {
|
|
34
38
|
record: kept,
|
|
35
|
-
collection:
|
|
39
|
+
collection: yield* collecting(kept.documents, compositionOf(kept), previous?.collection),
|
|
36
40
|
};
|
|
37
41
|
}
|
|
38
42
|
export function sameMembership(record, other) {
|
|
39
43
|
return (JSON.stringify(record.typedSelection?.roots ?? null) ===
|
|
40
44
|
JSON.stringify(other.typedSelection?.roots ?? null));
|
|
41
45
|
}
|
|
42
|
-
function cleanly(record, previous) {
|
|
46
|
+
function* cleanly(record, previous) {
|
|
43
47
|
if (previous === undefined)
|
|
44
48
|
return false;
|
|
45
49
|
const before = previous.record;
|
|
46
|
-
return changedCleanly({ text: record.documents, binaries: record.binaries }, { text: before.documents, binaries: before.binaries, composition: compositionOf(before) }, compositionOf(record));
|
|
50
|
+
return yield* changedCleanly({ text: record.documents, binaries: record.binaries }, { text: before.documents, binaries: before.binaries, composition: compositionOf(before) }, compositionOf(record));
|
|
47
51
|
}
|
|
48
|
-
|
|
49
|
-
const record =
|
|
50
|
-
const textChanged = previous === undefined || !
|
|
52
|
+
function* staging(staged, previous) {
|
|
53
|
+
const record = yield* holding(staged);
|
|
54
|
+
const textChanged = previous === undefined || !(yield* sameText(record, previous.record));
|
|
51
55
|
const modeled = record.model.status !== 'unavailable' || record.selectionModel.status !== 'unavailable';
|
|
52
56
|
if (modeled &&
|
|
53
57
|
(textChanged ||
|
|
54
58
|
record.model !== previous?.record.model ||
|
|
55
59
|
record.selectionModel !== previous?.record.selectionModel) &&
|
|
56
|
-
!cleanly(record, previous)) {
|
|
57
|
-
const verdict = validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
|
|
60
|
+
!(yield* cleanly(record, previous))) {
|
|
61
|
+
const verdict = yield* validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
|
|
58
62
|
if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') {
|
|
59
63
|
return { kind: 'refused', refusal: verdict };
|
|
60
64
|
}
|
|
61
65
|
if (verdict.verdict === 'refuse') {
|
|
62
|
-
const refused = unreadable(record.documents, previous?.record.documents);
|
|
66
|
+
const refused = yield* unreadable(record.documents, previous?.record.documents);
|
|
63
67
|
if (refused !== null)
|
|
64
68
|
return refused;
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
else if (textChanged) {
|
|
68
|
-
const refused = unreadable(record.documents, previous?.record.documents);
|
|
72
|
+
const refused = yield* unreadable(record.documents, previous?.record.documents);
|
|
69
73
|
if (refused !== null)
|
|
70
74
|
return refused;
|
|
71
75
|
}
|
|
72
|
-
return { kind: 'staged', confirmed:
|
|
76
|
+
return { kind: 'staged', confirmed: yield* confirming(record, previous) };
|
|
73
77
|
}
|
|
74
|
-
export function
|
|
75
|
-
|
|
78
|
+
export function readStaged(staged, previous) {
|
|
79
|
+
return stepped(staging(staged, previous));
|
|
80
|
+
}
|
|
81
|
+
function* reclassifying(record, previous) {
|
|
82
|
+
const verdict = yield* validateCollection(record.documents, Object.keys(record.binaries), compositionOf(record));
|
|
76
83
|
if (verdict.verdict !== 'refuse')
|
|
77
|
-
return { kind: 'staged', confirmed:
|
|
84
|
+
return { kind: 'staged', confirmed: yield* confirming(record, previous) };
|
|
78
85
|
return verdict.rule === 'model-unavailable'
|
|
79
86
|
? { kind: 'deferred' }
|
|
80
87
|
: { kind: 'refused', refusal: verdict };
|
|
81
88
|
}
|
|
89
|
+
export function readReclassified(record, previous) {
|
|
90
|
+
return stepped(reclassifying(record, previous));
|
|
91
|
+
}
|
|
82
92
|
function returnedBinaries(held, submitted, accepted) {
|
|
83
93
|
const binaries = drafted(held);
|
|
84
94
|
for (const change of submitted.changes) {
|
package/dist/rows.d.ts
CHANGED
package/dist/rows.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EA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,SAAS,MAAM,EAAE,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,GAAG,GAAG,WAAW,GAAG,YAAY,CAAC;AAM7C,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAuFD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,WAAW,GAAG,IAAI,EAC5B,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,UAAU,GAAG,IAAI,EACzB,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,MAAM,EAAE,gBAAgB,GAAG,IAAI,GAC9B,SAAS,GAAG,EAAE,CAmEhB"}
|
package/dist/rows.js
CHANGED
|
@@ -64,6 +64,9 @@ function walk(reading, node, forms, exact) {
|
|
|
64
64
|
: [{ text: `${form.text}/${segment}`, through: form.through, pending: false }]), `${exact}/${segment}`);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
+
function folderOf(path) {
|
|
68
|
+
return path.slice(0, Math.max(path.lastIndexOf('/'), 0));
|
|
69
|
+
}
|
|
67
70
|
function directoriesOf(path) {
|
|
68
71
|
const parts = path.split('/').slice(0, -1);
|
|
69
72
|
return ['', ...parts.map((_, index) => parts.slice(0, index + 1).join('/'))];
|
|
@@ -85,6 +88,7 @@ export function rowsOf(room, path, document, composition, change, fileId, binary
|
|
|
85
88
|
values: {},
|
|
86
89
|
reached: {},
|
|
87
90
|
directories: directoriesOf(path),
|
|
91
|
+
folder: folderOf(path),
|
|
88
92
|
text: null,
|
|
89
93
|
change,
|
|
90
94
|
fileId,
|
|
@@ -117,6 +121,7 @@ export function rowsOf(room, path, document, composition, change, fileId, binary
|
|
|
117
121
|
values,
|
|
118
122
|
reached,
|
|
119
123
|
directories: directoriesOf(path),
|
|
124
|
+
folder: folderOf(path),
|
|
120
125
|
text: document.content,
|
|
121
126
|
change,
|
|
122
127
|
fileId,
|
package/dist/save.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type Change, type ChangeBatch, type Precondition, type WrittenBy } from
|
|
|
3
3
|
import { type Composition } from './collection.js';
|
|
4
4
|
import type { VisibleLayer } from './replica.js';
|
|
5
5
|
import type { ChangedPart } from './room-draft.js';
|
|
6
|
+
import { type Later } from './turn.js';
|
|
6
7
|
export type SaveRefusal = {
|
|
7
8
|
code: string;
|
|
8
9
|
retryable: boolean;
|
|
@@ -61,5 +62,5 @@ export type Joining = {
|
|
|
61
62
|
export declare function requeued(queue: readonly ChangeBatch[], changes: readonly Change[], visible: VisibleLayer, changeable: (batch: ChangeBatch) => boolean, state: (queue: readonly ChangeBatch[]) => VisibleLayer): Requeued;
|
|
62
63
|
export declare function joined(queue: readonly ChangeBatch[], owner: ChangeBatch, extra: ChangeBatch): Joining;
|
|
63
64
|
export declare function limitedIn(queue: readonly ChangeBatch[], batch: ChangeBatch, limits: readonly ProviderLimit[], state: (queue: readonly ChangeBatch[]) => VisibleLayer): SaveRefusal | null;
|
|
64
|
-
export declare function buildBatch(input: SaveInput): BatchResult
|
|
65
|
+
export declare function buildBatch(input: SaveInput): Later<BatchResult>;
|
|
65
66
|
//# sourceMappingURL=save.d.ts.map
|
package/dist/save.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../src/save.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAIL,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EASL,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AE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAiM9C,wBAAgB,QAAQ,CACtB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,EAC3C,KAAK,EAAE,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,KAAK,YAAY,GACrD,QAAQ,CA+DV;AAUD,wBAAgB,MAAM,CACpB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,WAAW,GACjB,OAAO,CAiCT;AAED,wBAAgB,SAAS,CACvB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,KAAK,EAAE,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,KAAK,YAAY,GACrD,WAAW,GAAG,IAAI,CASpB;AA+GD,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,CAE/D"}
|
package/dist/save.js
CHANGED
|
@@ -5,6 +5,8 @@ import { available, changedCleanly, collectionOf, documentsOf, governing, referr
|
|
|
5
5
|
import { changeBatchIdentity } from './identity.js';
|
|
6
6
|
import { overlay } from './overlay.js';
|
|
7
7
|
import { covered, normalize } from './paths.js';
|
|
8
|
+
import { differences } from './shared.js';
|
|
9
|
+
import { ROW_WEIGHT, stepped } from './turn.js';
|
|
8
10
|
function refuse(code, file, location) {
|
|
9
11
|
return {
|
|
10
12
|
kind: 'refused',
|
|
@@ -177,7 +179,7 @@ export function providerRewritten(batch, visible) {
|
|
|
177
179
|
...anticipated(batch.changes, batch.preconditions, rewritten.changes, visible),
|
|
178
180
|
};
|
|
179
181
|
}
|
|
180
|
-
function incoming(collection, removed, candidates) {
|
|
182
|
+
function* incoming(collection, removed, candidates) {
|
|
181
183
|
const found = new Map();
|
|
182
184
|
const note = (target, file) => {
|
|
183
185
|
if (!removed.has(target))
|
|
@@ -186,13 +188,14 @@ function incoming(collection, removed, candidates) {
|
|
|
186
188
|
referrers.add(file);
|
|
187
189
|
found.set(target, referrers);
|
|
188
190
|
};
|
|
189
|
-
const read =
|
|
190
|
-
|
|
191
|
-
: [...new Set(candidates)].sort().flatMap((path) => {
|
|
191
|
+
const read = function* (paths) {
|
|
192
|
+
for (const path of [...new Set(paths)].sort()) {
|
|
192
193
|
const document = collection.document(path);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
if (document !== undefined)
|
|
195
|
+
yield [path, document];
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
for (const [path, document] of candidates === null ? documentsOf(collection) : read(candidates)) {
|
|
196
199
|
const definition = definitionOf(governing(collection.composition, path), document.type);
|
|
197
200
|
for (const { value, to } of definition === undefined ? [] : references(document, definition)) {
|
|
198
201
|
if (to.includes(ATTACHMENT))
|
|
@@ -201,6 +204,7 @@ function incoming(collection, removed, candidates) {
|
|
|
201
204
|
if (named !== null)
|
|
202
205
|
note(named, path);
|
|
203
206
|
}
|
|
207
|
+
yield ROW_WEIGHT + collection.text[path].length;
|
|
204
208
|
}
|
|
205
209
|
const [first] = [...found.keys()].sort();
|
|
206
210
|
if (first === undefined)
|
|
@@ -474,7 +478,7 @@ function relativeChanges(input) {
|
|
|
474
478
|
return { ...change, fields, sections };
|
|
475
479
|
});
|
|
476
480
|
}
|
|
477
|
-
function unmodeledType(collection, composition) {
|
|
481
|
+
function* unmodeledType(collection, composition) {
|
|
478
482
|
if (available(composition))
|
|
479
483
|
return false;
|
|
480
484
|
for (const [path, document] of documentsOf(collection)) {
|
|
@@ -482,6 +486,7 @@ function unmodeledType(collection, composition) {
|
|
|
482
486
|
document.type !== 'any' &&
|
|
483
487
|
governing(composition, path).status === 'unavailable')
|
|
484
488
|
return true;
|
|
489
|
+
yield ROW_WEIGHT + collection.text[path].length;
|
|
485
490
|
}
|
|
486
491
|
return false;
|
|
487
492
|
}
|
|
@@ -749,10 +754,11 @@ export function limitedIn(queue, batch, limits, state) {
|
|
|
749
754
|
const limited = exceeded(limits, batch.changes, providerRewritten(batch, state(queue.slice(0, at))).changes, state(queue.slice(0, at + 1)));
|
|
750
755
|
return limited?.kind === 'refused' ? limited.refusal : null;
|
|
751
756
|
}
|
|
752
|
-
|
|
757
|
+
function* batching(input) {
|
|
753
758
|
const changes = relativeChanges(input);
|
|
754
759
|
const structural = changes.find((change) => change.kind === 'move' || change.kind === 'remove');
|
|
755
|
-
if (structural !== undefined &&
|
|
760
|
+
if (structural !== undefined &&
|
|
761
|
+
(yield* unmodeledType(input.visible.collection, input.composition)))
|
|
756
762
|
return refuse('model-unavailable', structural.path);
|
|
757
763
|
if (changes.length === 0)
|
|
758
764
|
return refuse('no-change');
|
|
@@ -767,16 +773,13 @@ export function buildBatch(input) {
|
|
|
767
773
|
const resulting = overlay(input.visible, [
|
|
768
774
|
{ id: '', baseRoomVersion: input.baseRoomVersion, ...predicted },
|
|
769
775
|
]);
|
|
770
|
-
const clean = input.clean !== undefined &&
|
|
771
|
-
input.clean.text === input.visible.documents &&
|
|
772
|
-
input.clean.binaries === input.visible.binaries &&
|
|
773
|
-
available(input.composition)
|
|
774
|
-
? input.clean
|
|
775
|
-
: null;
|
|
776
|
+
const clean = input.clean !== undefined && available(input.composition) ? input.clean : null;
|
|
776
777
|
const removed = new Set(changes.filter((change) => change.kind === 'remove').map((change) => change.path));
|
|
777
778
|
if (removed.size > 0) {
|
|
778
779
|
const referrers = clean === null ? null : referring(clean, input.composition, removed);
|
|
779
|
-
const referenced = incoming(collectionOf(resulting.documents, input.composition), removed,
|
|
780
|
+
const referenced = yield* incoming(collectionOf(resulting.documents, input.composition), removed, clean === null || referrers === null
|
|
781
|
+
? null
|
|
782
|
+
: [...referrers, ...(yield* differences(clean.text, resulting.documents))]);
|
|
780
783
|
if (referenced !== null)
|
|
781
784
|
return referenced;
|
|
782
785
|
}
|
|
@@ -793,9 +796,9 @@ export function buildBatch(input) {
|
|
|
793
796
|
if (withoutModel !== undefined)
|
|
794
797
|
return refuse('model-unavailable', withoutModel);
|
|
795
798
|
const verdict = clean !== null &&
|
|
796
|
-
changedCleanly({ text: resulting.documents, binaries: resulting.binaries }, clean, input.composition)
|
|
799
|
+
(yield* changedCleanly({ text: resulting.documents, binaries: resulting.binaries }, clean, input.composition))
|
|
797
800
|
? { verdict: 'accept' }
|
|
798
|
-
: validateCollection(needsModel
|
|
801
|
+
: yield* validateCollection(needsModel
|
|
799
802
|
? resulting.documents
|
|
800
803
|
: Object.fromEntries(touched.flatMap((path) => resulting.documents[path] === undefined
|
|
801
804
|
? []
|
|
@@ -838,3 +841,6 @@ export function buildBatch(input) {
|
|
|
838
841
|
}),
|
|
839
842
|
};
|
|
840
843
|
}
|
|
844
|
+
export function buildBatch(input) {
|
|
845
|
+
return stepped(batching(input));
|
|
846
|
+
}
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export type Paths<V> = Readonly<Record<string, V>>;
|
|
2
2
|
type Weigh<V> = (key: string, value: V) => number;
|
|
3
|
+
export declare function sharing<V>(map: Paths<V>): Generator<number, Paths<V>, void>;
|
|
3
4
|
export declare function shared<V>(map: Paths<V>): Paths<V>;
|
|
4
5
|
export declare function patched<V>(base: Paths<V>, set: Iterable<readonly [string, V]>, removed?: Iterable<string>): Paths<V>;
|
|
6
|
+
export declare function patching<V>(base: Paths<V>, set: Iterable<readonly [string, V]>, removed?: Iterable<string>): Generator<number, Paths<V>, void>;
|
|
5
7
|
export declare function tally<V>(map: Paths<V>, weigh: Weigh<V>): number;
|
|
6
8
|
export declare function sizeOf<V>(map: Paths<V>): number;
|
|
9
|
+
export declare function differences<V>(left: Paths<V>, right: Paths<V>, same?: (left: V, right: V) => boolean): Generator<number, ReadonlySet<string>, void>;
|
|
7
10
|
export declare function differing<V>(left: Paths<V>, right: Paths<V>, same?: (left: V, right: V) => boolean): ReadonlySet<string>;
|
|
8
11
|
export declare function drafted<V>(base: Paths<V>): Record<string, V>;
|
|
9
12
|
export declare function settled<V>(draft: Record<string, V>): Paths<V>;
|
package/dist/shared.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AAkBnD,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC;AA8LlD,wBAAiB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAE5E;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAEjD;AAED,wBAAgB,OAAO,CAAC,CAAC,EACvB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EACd,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EACnC,OAAO,GAAE,QAAQ,CAAC,MAAM,CAAM,GAC7B,KAAK,CAAC,CAAC,CAAC,CAEV;AAED,wBAAiB,QAAQ,CAAC,CAAC,EACzB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EACd,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EACnC,OAAO,GAAE,Q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