@agentshouse/mdruntime 0.1.0-c7f1d9323e816 → 0.1.0-c967d1ca66fee
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 +27 -11
- package/README.md +2 -2
- package/dist/adapter.d.ts +7 -3
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +17 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +88 -35
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +13 -7
- package/dist/change.d.ts +4 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/client.d.ts +4 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +50 -14
- package/dist/collection.d.ts +6 -11
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +56 -19
- package/dist/connection.d.ts +10 -5
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +189 -91
- package/dist/conversation.d.ts +2 -1
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +2 -1
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +3 -7
- package/dist/identity.d.ts +1 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +7 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +24 -11
- package/dist/model.d.ts +3 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/outcome.d.ts +22 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +35 -1
- package/dist/overlay.d.ts +1 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +19 -15
- package/dist/query.d.ts +2 -0
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -0
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +19 -17
- package/dist/react.d.ts +22 -15
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +8 -6
- package/dist/refresh.d.ts +10 -0
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +33 -24
- package/dist/replica.d.ts +4 -4
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +42 -27
- package/dist/room-draft.d.ts +8 -8
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +13 -22
- package/dist/rows.d.ts +2 -0
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +7 -1
- package/dist/save.d.ts +3 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +38 -21
- package/dist/search.d.ts +3 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/status.d.ts +2 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +21 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +194 -89
- package/dist/wire.d.ts +3 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +11 -2
- package/package.json +2 -2
package/dist/reach.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { unheldView } from './conversation.js';
|
|
2
2
|
import { modelTypes, NO_MODEL } from './model.js';
|
|
3
3
|
import { applied, observing } from './observation.js';
|
|
4
|
+
import { runtimeError } from './failure.js';
|
|
5
|
+
import { failure, undeclared } from './outcome.js';
|
|
4
6
|
import { beneath } from './paths.js';
|
|
5
7
|
import { reconciled } from './read-side.js';
|
|
6
|
-
import { moveTarget, readParts } from './room-draft.js';
|
|
8
|
+
import { moveTarget, readParts, staleWrite, } from './room-draft.js';
|
|
7
9
|
import { documentKey } from './rows.js';
|
|
8
10
|
const UNHELD_TYPES = { collection: modelTypes(NO_MODEL), typedSelection: null };
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return Promise.resolve(UNDECLARED);
|
|
11
|
+
function unconversed(name) {
|
|
12
|
+
return () => Promise.resolve(undeclared(name));
|
|
12
13
|
}
|
|
13
14
|
const NO_CONVERSATION = {
|
|
14
15
|
list: () => Promise.resolve([]),
|
|
15
16
|
read: (conversation) => Promise.resolve(unheldView(conversation)),
|
|
16
|
-
create:
|
|
17
|
-
send:
|
|
18
|
-
answer:
|
|
19
|
-
interrupt:
|
|
20
|
-
kill:
|
|
21
|
-
cancel:
|
|
22
|
-
delete:
|
|
17
|
+
create: unconversed('conversation.create'),
|
|
18
|
+
send: unconversed('conversation.send'),
|
|
19
|
+
answer: unconversed('conversation.answer'),
|
|
20
|
+
interrupt: unconversed('conversation.interrupt'),
|
|
21
|
+
kill: unconversed('conversation.kill'),
|
|
22
|
+
cancel: unconversed('conversation.cancel'),
|
|
23
|
+
delete: unconversed('conversation.delete'),
|
|
23
24
|
};
|
|
24
25
|
const NO_CHAT_DRAFT = {
|
|
25
26
|
write: () => Promise.resolve(),
|
|
@@ -88,7 +89,7 @@ function shownDraft(reach, draft) {
|
|
|
88
89
|
function writeWithin(reach, write) {
|
|
89
90
|
return write.outcome === 'written'
|
|
90
91
|
? { outcome: 'written', roomDraft: shownDraft(reach, write.roomDraft) }
|
|
91
|
-
:
|
|
92
|
+
: staleWrite(shownDraft(reach, write.current));
|
|
92
93
|
}
|
|
93
94
|
function savedWithin(reach, room, result) {
|
|
94
95
|
if (reach === null || result.outcome === 'saved')
|
|
@@ -115,7 +116,7 @@ function queueWithin(reach, room, entries) {
|
|
|
115
116
|
(change.kind !== 'move' || covers(reach, room, change.to))));
|
|
116
117
|
}
|
|
117
118
|
function unreached(room) {
|
|
118
|
-
return
|
|
119
|
+
return runtimeError('room-not-held', `No Local Replica for ${room}`);
|
|
119
120
|
}
|
|
120
121
|
export function narrowed(runtime, given) {
|
|
121
122
|
const { md, watch } = runtime;
|
|
@@ -216,13 +217,14 @@ export function narrowed(runtime, given) {
|
|
|
216
217
|
throw unreached(room);
|
|
217
218
|
const outside = roomDrafts.find(({ path }) => !covers(reach, room, path) ||
|
|
218
219
|
!moves(reach, room, md.roomDraft.read(room, path)?.parts.move));
|
|
219
|
-
if (outside !== undefined)
|
|
220
|
-
return { outcome: 'refused',
|
|
220
|
+
if (outside !== undefined) {
|
|
221
|
+
return { outcome: 'refused', code: 'stale', retryable: false, file: outside.path };
|
|
222
|
+
}
|
|
221
223
|
return savedWithin(reach, room, await md.save(room, roomDrafts, writtenBy));
|
|
222
224
|
},
|
|
223
225
|
history: (room, path, query) => covers(reach, room, path)
|
|
224
226
|
? md.history(room, path, query)
|
|
225
|
-
: Promise.resolve({ kind: 'room-not-readable', locator: room }),
|
|
227
|
+
: Promise.resolve(failure({ kind: 'room-not-readable', locator: room })),
|
|
226
228
|
reached: (room, roomVersion, path) => (path === undefined ? wholly(reach, room) : covers(reach, room, path)) &&
|
|
227
229
|
md.reached(room, roomVersion, path),
|
|
228
230
|
log: () => (reach === null ? md.log() : ''),
|
|
@@ -237,7 +239,7 @@ export function narrowed(runtime, given) {
|
|
|
237
239
|
},
|
|
238
240
|
async discard(room, path, revision) {
|
|
239
241
|
if (!covers(reach, room, path))
|
|
240
|
-
return
|
|
242
|
+
return staleWrite(null);
|
|
241
243
|
return writeWithin(reach, await md.roomDraft.discard(room, path, revision));
|
|
242
244
|
},
|
|
243
245
|
},
|
package/dist/react.d.ts
CHANGED
|
@@ -2,29 +2,36 @@ import type { MdRuntimeClient } from './client.js';
|
|
|
2
2
|
import type { AppRoom, ConnectionRefusal, SaveResult } from './connection.js';
|
|
3
3
|
import type { Member, ServiceMode } from './adapter.js';
|
|
4
4
|
import type { ConversationEntry, ConversationOptions, ConversationView } from './conversation.js';
|
|
5
|
+
import { type RuntimeError } from './failure.js';
|
|
5
6
|
import type { QueueEntry } from './outcome.js';
|
|
6
7
|
import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult } from './query.js';
|
|
7
8
|
import type { RoomDraft, RoomDraftParts } from './room-draft.js';
|
|
8
9
|
import type { SyncStatus } from './status.js';
|
|
9
10
|
type Client = MdRuntimeClient | null;
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export declare function useObserve(client: Client, topic: '
|
|
17
|
-
export declare function useObserve(client: Client, topic: '
|
|
18
|
-
export declare function useObserve(client: Client, topic: '
|
|
19
|
-
export declare function useObserve(client: Client, topic: '
|
|
20
|
-
export declare function useObserve(client: Client, topic: '
|
|
21
|
-
export declare function useObserve(client: Client, topic: '
|
|
22
|
-
export declare function useObserve(client: Client, topic: '
|
|
23
|
-
export declare function useObserve(client: Client, topic: '
|
|
11
|
+
export type Observed<T> = {
|
|
12
|
+
readonly state: 'loading';
|
|
13
|
+
} | {
|
|
14
|
+
readonly state: 'ready';
|
|
15
|
+
readonly value: T;
|
|
16
|
+
};
|
|
17
|
+
export declare function useObserve(client: Client, topic: 'deployment-facts'): Observed<unknown>;
|
|
18
|
+
export declare function useObserve(client: Client, topic: 'rooms'): Observed<readonly AppRoom[]>;
|
|
19
|
+
export declare function useObserve(client: Client, topic: 'connection-refusal'): Observed<ConnectionRefusal | null>;
|
|
20
|
+
export declare function useObserve(client: Client, topic: 'storage-loss'): Observed<string | null>;
|
|
21
|
+
export declare function useObserve(client: Client, topic: 'sync-status'): Observed<SyncStatus>;
|
|
22
|
+
export declare function useObserve(client: Client, topic: 'service-mode'): Observed<ServiceMode>;
|
|
23
|
+
export declare function useObserve(client: Client, topic: 'member'): Observed<Member | null>;
|
|
24
|
+
export declare function useObserve(client: Client, topic: 'query', query: DocumentQuery): Observed<DocumentResult>;
|
|
25
|
+
export declare function useObserve(client: Client, topic: 'query', query: GroupQuery): Observed<GroupResult>;
|
|
26
|
+
export declare function useObserve(client: Client, topic: 'queue', locator: string): Observed<readonly QueueEntry[]>;
|
|
27
|
+
export declare function useObserve(client: Client, topic: 'room-drafts'): Observed<readonly RoomDraft[]>;
|
|
28
|
+
export declare function useObserve(client: Client, topic: 'presentation'): Observed<unknown>;
|
|
29
|
+
export declare function useObserve(client: Client, topic: 'conversation', conversation: string, options: ConversationOptions): Observed<ConversationView>;
|
|
30
|
+
export declare function useObserve(client: Client, topic: 'conversations'): Observed<readonly ConversationEntry[]>;
|
|
24
31
|
export type Saving = {
|
|
25
32
|
readonly busy: boolean;
|
|
26
33
|
readonly outcome: SaveResult | null;
|
|
27
|
-
readonly failure:
|
|
34
|
+
readonly failure: RuntimeError | null;
|
|
28
35
|
save(room: string, roomDrafts: ReadonlyMap<string, RoomDraftParts>): Promise<SaveResult>;
|
|
29
36
|
};
|
|
30
37
|
export declare function saveRoomDrafts(client: MdRuntimeClient, room: string, roomDrafts: ReadonlyMap<string, RoomDraftParts>): Promise<SaveResult>;
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAkB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAkB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAClG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CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC1F,CAAC;AAMF,wBAAsB,cAAc,CAClC,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,GAC9C,OAAO,CAAC,UAAU,CAAC,CAcrB;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAkBvD"}
|
package/dist/react.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import { failed, runtimeError } from './failure.js';
|
|
3
|
+
const LOADING = { state: 'loading' };
|
|
2
4
|
export function useObserve(client, topic, ...input) {
|
|
3
5
|
const key = JSON.stringify([topic, ...input]);
|
|
4
6
|
const [held, setHeld] = useState(null);
|
|
5
7
|
const opened = useRef(input);
|
|
6
8
|
opened.current = input;
|
|
7
|
-
|
|
9
|
+
useLayoutEffect(() => {
|
|
8
10
|
if (client === null)
|
|
9
11
|
return;
|
|
10
12
|
let live = true;
|
|
@@ -18,7 +20,7 @@ export function useObserve(client, topic, ...input) {
|
|
|
18
20
|
observation = open;
|
|
19
21
|
const take = (value) => {
|
|
20
22
|
if (live)
|
|
21
|
-
setHeld({ client, key, value });
|
|
23
|
+
setHeld({ client, key, observed: { state: 'ready', value } });
|
|
22
24
|
};
|
|
23
25
|
take(open.current());
|
|
24
26
|
open.subscribe(take);
|
|
@@ -28,7 +30,7 @@ export function useObserve(client, topic, ...input) {
|
|
|
28
30
|
observation?.close();
|
|
29
31
|
};
|
|
30
32
|
}, [client, key]);
|
|
31
|
-
return held !== null && held.client === client && held.key === key ? held.
|
|
33
|
+
return held !== null && held.client === client && held.key === key ? held.observed : LOADING;
|
|
32
34
|
}
|
|
33
35
|
const IDLE = { busy: false, outcome: null, failure: null };
|
|
34
36
|
export async function saveRoomDrafts(client, room, roomDrafts) {
|
|
@@ -37,7 +39,7 @@ export async function saveRoomDrafts(client, room, roomDrafts) {
|
|
|
37
39
|
const prior = await client.roomDraft.read(room, path);
|
|
38
40
|
const write = await client.roomDraft.write(room, path, prior?.revision ?? null, parts);
|
|
39
41
|
if (write.outcome !== 'written' || write.roomDraft === null) {
|
|
40
|
-
throw
|
|
42
|
+
throw runtimeError(write.outcome === 'stale' ? write.code : 'room-draft-unwritten', `the Room Draft at ${path} was not written`);
|
|
41
43
|
}
|
|
42
44
|
kept.push({ path, revision: write.roomDraft.revision });
|
|
43
45
|
}
|
|
@@ -53,7 +55,7 @@ export function useSave(client) {
|
|
|
53
55
|
return outcome;
|
|
54
56
|
}
|
|
55
57
|
catch (error) {
|
|
56
|
-
const failure =
|
|
58
|
+
const failure = failed(error);
|
|
57
59
|
setState({ busy: false, outcome: null, failure });
|
|
58
60
|
throw failure;
|
|
59
61
|
}
|
package/dist/refresh.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import type { Adapter, AdapterFailure, Authorization, RetryableRefusal } from './adapter.js';
|
|
2
2
|
import type { Remodel } from './bootstrap.js';
|
|
3
3
|
import { type ConfirmedLayer } from './replica.js';
|
|
4
|
+
import type { ReplicaRecord } from './store.js';
|
|
4
5
|
import { type Refused, type Unconfirmed } from './transfer.js';
|
|
6
|
+
export type Advancement = {
|
|
7
|
+
kind: 'still-current';
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'advanced';
|
|
10
|
+
record: ReplicaRecord;
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'beyond-horizon';
|
|
13
|
+
} | RetryableRefusal | Unconfirmed | AdapterFailure;
|
|
5
14
|
export type RefreshOutcome = {
|
|
6
15
|
kind: 'still-current';
|
|
7
16
|
} | {
|
|
@@ -10,5 +19,6 @@ export type RefreshOutcome = {
|
|
|
10
19
|
} | {
|
|
11
20
|
kind: 'beyond-horizon';
|
|
12
21
|
} | RetryableRefusal | Unconfirmed | Refused | AdapterFailure;
|
|
22
|
+
export declare function advancement(adapter: Adapter, authorization: Authorization, held: ReplicaRecord, remodel: Remodel, continuing: () => boolean): Promise<Advancement>;
|
|
13
23
|
export declare function refreshRoom(adapter: Adapter, authorization: Authorization, confirmed: ConfirmedLayer, remodel: Remodel, continuing: () => boolean): Promise<RefreshOutcome>;
|
|
14
24
|
//# sourceMappingURL=refresh.d.ts.map
|
package/dist/refresh.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,aAAa,EAGb,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAe,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5E,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,cAAc,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B,gBAAgB,GAChB,WAAW,GACX,OAAO,GACP,cAAc,CAAC;AAEnB,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,OAAO,GACxB,OAAO,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAA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
|
|
2
2
|
import { readStaged } from './replica.js';
|
|
3
3
|
import { unconfirmed } from './transfer.js';
|
|
4
|
-
export async function
|
|
5
|
-
const locator =
|
|
6
|
-
const fromRoomVersion =
|
|
4
|
+
export async function advancement(adapter, authorization, held, remodel, continuing) {
|
|
5
|
+
const locator = held.locator;
|
|
6
|
+
const fromRoomVersion = held.roomVersion;
|
|
7
7
|
const first = await adapter.refresh(authorization, {
|
|
8
8
|
locator,
|
|
9
|
-
selection:
|
|
9
|
+
selection: held.replica.selection,
|
|
10
10
|
fromRoomVersion,
|
|
11
11
|
});
|
|
12
12
|
if (first.kind !== 'net-advancement')
|
|
13
13
|
return first;
|
|
14
14
|
const roomVersion = first.roomVersion;
|
|
15
15
|
const models = remodel(first.models, {
|
|
16
|
-
collection:
|
|
17
|
-
selection:
|
|
16
|
+
collection: held.model,
|
|
17
|
+
selection: held.selectionModel,
|
|
18
18
|
});
|
|
19
|
-
const documents = { ...
|
|
20
|
-
const revisions = { ...
|
|
21
|
-
const changes = { ...
|
|
22
|
-
const written = { ...
|
|
23
|
-
const binaryTargets = new Set(
|
|
19
|
+
const documents = { ...held.documents };
|
|
20
|
+
const revisions = { ...held.revisions };
|
|
21
|
+
const changes = { ...held.changes };
|
|
22
|
+
const written = { ...held.written };
|
|
23
|
+
const binaryTargets = new Set(held.binaryTargets);
|
|
24
24
|
const attachments = [];
|
|
25
25
|
const stage = (page) => {
|
|
26
26
|
if (page.attachments !== undefined)
|
|
@@ -55,7 +55,7 @@ export async function refreshRoom(adapter, authorization, confirmed, remodel, co
|
|
|
55
55
|
return unconfirmed;
|
|
56
56
|
const page = await adapter.refresh(authorization, {
|
|
57
57
|
locator,
|
|
58
|
-
selection:
|
|
58
|
+
selection: held.replica.selection,
|
|
59
59
|
fromRoomVersion,
|
|
60
60
|
pageToken,
|
|
61
61
|
});
|
|
@@ -68,17 +68,26 @@ export async function refreshRoom(adapter, authorization, confirmed, remodel, co
|
|
|
68
68
|
stage(page);
|
|
69
69
|
pageToken = page.pageToken;
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
return {
|
|
72
|
+
kind: 'advanced',
|
|
73
|
+
record: {
|
|
74
|
+
...held,
|
|
75
|
+
model: models.collection,
|
|
76
|
+
selectionModel: models.selection,
|
|
77
|
+
roomVersion,
|
|
78
|
+
documents,
|
|
79
|
+
binaryTargets: [...binaryTargets].sort(),
|
|
80
|
+
revisions,
|
|
81
|
+
changes,
|
|
82
|
+
written,
|
|
83
|
+
attachments: attachments.length === 0 ? held.attachments : declaredAttachments(attachments),
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export async function refreshRoom(adapter, authorization, confirmed, remodel, continuing) {
|
|
88
|
+
const advanced = await advancement(adapter, authorization, confirmed.record, remodel, continuing);
|
|
89
|
+
if (advanced.kind !== 'advanced')
|
|
90
|
+
return advanced;
|
|
91
|
+
const staged = readStaged(advanced.record, confirmed);
|
|
83
92
|
return staged.kind === 'staged' ? { kind: 'advanced', confirmed: staged.confirmed } : staged;
|
|
84
93
|
}
|
package/dist/replica.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ChangeBatch } from './change.js';
|
|
2
2
|
import { type Collection, type Composition } from './collection.js';
|
|
3
3
|
import { type Layer } from './overlay.js';
|
|
4
|
-
import type { RoomAttachment } from './adapter.js';
|
|
4
|
+
import type { HeadChange, RoomAttachment } from './adapter.js';
|
|
5
5
|
import type { ReplicaRecord } from './store.js';
|
|
6
6
|
import type { Refused } from './transfer.js';
|
|
7
7
|
export type ConfirmedLayer = {
|
|
@@ -29,15 +29,15 @@ type ReplayStep = {
|
|
|
29
29
|
collection?: Collection;
|
|
30
30
|
};
|
|
31
31
|
export declare function compositionOf(record: ReplicaRecord): Composition;
|
|
32
|
-
export declare function
|
|
32
|
+
export declare function confirmedOf(record: ReplicaRecord, previous?: ConfirmedLayer): ConfirmedLayer;
|
|
33
33
|
export declare function sameMembership(record: ReplicaRecord, other: ReplicaRecord): boolean;
|
|
34
34
|
export declare function readStaged(record: ReplicaRecord, previous?: ConfirmedLayer): Staged;
|
|
35
35
|
export declare function readReclassified(record: ReplicaRecord, previous: ConfirmedLayer): Staged | {
|
|
36
36
|
kind: 'deferred';
|
|
37
37
|
};
|
|
38
|
-
export declare function applyReturned(confirmed: ConfirmedLayer, documents: Readonly<Record<string, string>>, revisions: Readonly<Record<string, string>>, removals: readonly string[], attachments: readonly RoomAttachment[] | undefined, roomVersion: string, writtenAt: string): Staged;
|
|
38
|
+
export declare function applyReturned(confirmed: ConfirmedLayer, documents: Readonly<Record<string, string>>, revisions: Readonly<Record<string, string>>, changes: Readonly<Record<string, HeadChange>>, removals: readonly string[], attachments: readonly RoomAttachment[] | undefined, roomVersion: string, writtenAt: string): Staged;
|
|
39
39
|
export declare function replicaOf(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[], previous?: Replica): Replica;
|
|
40
40
|
export declare function landed(batch: ChangeBatch, confirmed: ConfirmedLayer, current?: Readonly<Record<string, string>>): boolean;
|
|
41
|
-
export declare function withdrawals(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[], withdrawable: (batch: ChangeBatch) => boolean): readonly ChangeBatch[];
|
|
41
|
+
export declare function withdrawals(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[], withdrawable: (batch: ChangeBatch) => boolean, local: boolean): readonly ChangeBatch[];
|
|
42
42
|
export {};
|
|
43
43
|
//# sourceMappingURL=replica.d.ts.map
|
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,EAA0B,KAAK,WAAW,EAAqB,MAAM,aAAa,CAAC;AAC1F,OAAO,EA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cAAc,EACzB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,YAAY,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,EAC7C,KAAK,EAAE,OAAO,GACb,SAAS,WAAW,EAAE,CA2BxB"}
|
package/dist/replica.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { parse } from '@agentshouse/mdmodel';
|
|
1
|
+
import { equalValue, parse } from '@agentshouse/mdmodel';
|
|
2
2
|
import { immutable } from './change.js';
|
|
3
|
-
import {
|
|
3
|
+
import { collectionOf, unreadable, validateCollection, } from './collection.js';
|
|
4
4
|
import { overlay, overlayChanged, sameLayerText } from './overlay.js';
|
|
5
5
|
import { providerRewritten } from './save.js';
|
|
6
|
-
import { equalValue } from './room-draft.js';
|
|
7
6
|
import { declaredAttachments } from './attachment.js';
|
|
8
7
|
export function compositionOf(record) {
|
|
9
8
|
return {
|
|
@@ -13,40 +12,49 @@ export function compositionOf(record) {
|
|
|
13
12
|
: { roots: record.typedSelection.roots, model: record.selectionModel },
|
|
14
13
|
};
|
|
15
14
|
}
|
|
16
|
-
export function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
:
|
|
20
|
-
|
|
21
|
-
? { kind: 'staged', confirmed: { record, collection: read.collection } }
|
|
22
|
-
: read;
|
|
15
|
+
export function confirmedOf(record, previous) {
|
|
16
|
+
return {
|
|
17
|
+
record,
|
|
18
|
+
collection: collectionOf(record.documents, compositionOf(record), previous?.collection),
|
|
19
|
+
};
|
|
23
20
|
}
|
|
24
21
|
export function sameMembership(record, other) {
|
|
25
22
|
return (JSON.stringify(record.typedSelection?.roots ?? null) ===
|
|
26
23
|
JSON.stringify(other.typedSelection?.roots ?? null));
|
|
27
24
|
}
|
|
28
25
|
export function readStaged(record, previous) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
record.
|
|
26
|
+
const textChanged = previous === undefined || !sameLayerText(record, previous.record);
|
|
27
|
+
const modeled = record.model.status !== 'unavailable' || record.selectionModel.status !== 'unavailable';
|
|
28
|
+
if (modeled &&
|
|
29
|
+
(textChanged ||
|
|
30
|
+
record.model !== previous?.record.model ||
|
|
31
|
+
record.selectionModel !== previous?.record.selectionModel)) {
|
|
34
32
|
const verdict = validateCollection(record.documents, record.binaryTargets, compositionOf(record));
|
|
35
33
|
if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') {
|
|
36
34
|
return { kind: 'refused', refusal: verdict };
|
|
37
35
|
}
|
|
36
|
+
if (verdict.verdict === 'refuse') {
|
|
37
|
+
const refused = unreadable(record.documents, previous?.record.documents);
|
|
38
|
+
if (refused !== null)
|
|
39
|
+
return refused;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (textChanged) {
|
|
43
|
+
const refused = unreadable(record.documents, previous?.record.documents);
|
|
44
|
+
if (refused !== null)
|
|
45
|
+
return refused;
|
|
38
46
|
}
|
|
39
|
-
return
|
|
47
|
+
return { kind: 'staged', confirmed: confirmedOf(record, previous) };
|
|
40
48
|
}
|
|
41
49
|
export function readReclassified(record, previous) {
|
|
42
50
|
const verdict = validateCollection(record.documents, record.binaryTargets, compositionOf(record));
|
|
43
51
|
if (verdict.verdict !== 'refuse')
|
|
44
|
-
return
|
|
52
|
+
return { kind: 'staged', confirmed: confirmedOf(record, previous) };
|
|
45
53
|
return verdict.rule === 'model-unavailable'
|
|
46
54
|
? { kind: 'deferred' }
|
|
47
55
|
: { kind: 'refused', refusal: verdict };
|
|
48
56
|
}
|
|
49
|
-
export function applyReturned(confirmed, documents, revisions, removals, attachments, roomVersion, writtenAt) {
|
|
57
|
+
export function applyReturned(confirmed, documents, revisions, changes, removals, attachments, roomVersion, writtenAt) {
|
|
50
58
|
const nextDocuments = { ...confirmed.record.documents, ...documents };
|
|
51
59
|
const nextRevisions = { ...confirmed.record.revisions, ...revisions };
|
|
52
60
|
const nextChanges = { ...confirmed.record.changes };
|
|
@@ -59,6 +67,7 @@ export function applyReturned(confirmed, documents, revisions, removals, attachm
|
|
|
59
67
|
if (confirmed.record.revisions[path] !== revision)
|
|
60
68
|
delete nextChanges[path];
|
|
61
69
|
}
|
|
70
|
+
Object.assign(nextChanges, changes);
|
|
62
71
|
for (const path of removals) {
|
|
63
72
|
delete nextDocuments[path];
|
|
64
73
|
delete nextRevisions[path];
|
|
@@ -97,9 +106,7 @@ function predicted(confirmed, batches, previous) {
|
|
|
97
106
|
const collection = hasMove
|
|
98
107
|
? reuseRewrite
|
|
99
108
|
? old.collection
|
|
100
|
-
:
|
|
101
|
-
? { text: confirmed.record.documents, collection: confirmed.collection }
|
|
102
|
-
: { text: old.before.documents, collection: old.collection })
|
|
109
|
+
: collectionOf(before.documents, composition, old?.collection ?? confirmed.collection)
|
|
103
110
|
: undefined;
|
|
104
111
|
const effective = collection === undefined
|
|
105
112
|
? batch
|
|
@@ -143,9 +150,7 @@ export function replicaOf(confirmed, queue, previous) {
|
|
|
143
150
|
replay,
|
|
144
151
|
visible: {
|
|
145
152
|
...layer,
|
|
146
|
-
collection:
|
|
147
|
-
? undefined
|
|
148
|
-
: { text: previous.visible.documents, collection: previous.visible.collection }),
|
|
153
|
+
collection: collectionOf(layer.documents, compositionOf(confirmed.record), previous?.visible.collection ?? confirmed.collection),
|
|
149
154
|
},
|
|
150
155
|
};
|
|
151
156
|
}
|
|
@@ -171,6 +176,8 @@ function holds(layer, preconditions) {
|
|
|
171
176
|
if (precondition.kind === 'revision') {
|
|
172
177
|
return present(layer, path) && layer.revisions[path] === precondition.revision;
|
|
173
178
|
}
|
|
179
|
+
if (precondition.kind === 'content')
|
|
180
|
+
return layer.documents[path] === precondition.content;
|
|
174
181
|
const document = documentAt(path);
|
|
175
182
|
if (document === null)
|
|
176
183
|
return false;
|
|
@@ -244,7 +251,7 @@ export function landed(batch, confirmed, current = {}) {
|
|
|
244
251
|
});
|
|
245
252
|
});
|
|
246
253
|
}
|
|
247
|
-
export function withdrawals(confirmed, queue, withdrawable) {
|
|
254
|
+
export function withdrawals(confirmed, queue, withdrawable, local) {
|
|
248
255
|
if (!queue.some(withdrawable))
|
|
249
256
|
return [];
|
|
250
257
|
const composition = compositionOf(confirmed.record);
|
|
@@ -258,10 +265,18 @@ export function withdrawals(confirmed, queue, withdrawable) {
|
|
|
258
265
|
const effective = batch.changes.some((change) => change.kind === 'move')
|
|
259
266
|
? providerRewritten(batch, {
|
|
260
267
|
...layer,
|
|
261
|
-
collection:
|
|
268
|
+
collection: collectionOf(layer.documents, composition),
|
|
262
269
|
})
|
|
263
270
|
: batch;
|
|
264
|
-
|
|
271
|
+
let unapplied = false;
|
|
272
|
+
const next = overlay(layer, [effective], () => {
|
|
273
|
+
unapplied = true;
|
|
274
|
+
});
|
|
275
|
+
if (local && unapplied) {
|
|
276
|
+
withdrawn.push(batch);
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
layer = next;
|
|
265
280
|
}
|
|
266
281
|
return withdrawn;
|
|
267
282
|
}
|
package/dist/room-draft.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ProviderRefusal } from './adapter.js';
|
|
2
|
+
import type { Open } from './open.js';
|
|
2
3
|
import type { Change, Precondition } from './change.js';
|
|
3
4
|
import type { VisibleLayer } from './replica.js';
|
|
4
5
|
export type FieldValue = {
|
|
@@ -72,13 +73,10 @@ type ChangedUnderneath = {
|
|
|
72
73
|
readonly move?: string | null;
|
|
73
74
|
readonly removal?: string | null;
|
|
74
75
|
};
|
|
75
|
-
export type ReturnReason =
|
|
76
|
-
readonly kind: 'conflicted' | 'rejected';
|
|
77
|
-
}) | {
|
|
78
|
-
readonly kind: 'expired';
|
|
79
|
-
} | {
|
|
80
|
-
readonly kind: 'withdrawn';
|
|
76
|
+
export type ReturnReason = ProviderRefusal & {
|
|
77
|
+
readonly kind: 'conflicted' | 'rejected' | 'expired' | 'withdrawn';
|
|
81
78
|
};
|
|
79
|
+
export declare function returnedBy(kind: 'expired' | 'withdrawn'): ReturnReason;
|
|
82
80
|
export type RoomDraft = {
|
|
83
81
|
readonly room: string;
|
|
84
82
|
readonly path: string;
|
|
@@ -92,11 +90,14 @@ export type RoomDraftWrite = {
|
|
|
92
90
|
readonly roomDraft: RoomDraft | null;
|
|
93
91
|
} | {
|
|
94
92
|
readonly outcome: 'stale';
|
|
93
|
+
readonly code: string;
|
|
94
|
+
readonly retryable: boolean;
|
|
95
95
|
readonly current: RoomDraft | null;
|
|
96
96
|
};
|
|
97
|
+
export declare function staleWrite(current: RoomDraft | null): RoomDraftWrite;
|
|
97
98
|
export type ChangedPart = {
|
|
98
99
|
readonly path: string;
|
|
99
|
-
readonly part: 'field' | 'section' | 'preamble' | 'markdown' | 'creation' | 'move' | 'removal'
|
|
100
|
+
readonly part: Open<'field' | 'section' | 'preamble' | 'markdown' | 'creation' | 'move' | 'removal'>;
|
|
100
101
|
readonly name?: string;
|
|
101
102
|
};
|
|
102
103
|
export type RoomDraftRecord = {
|
|
@@ -112,7 +113,6 @@ export type SavedDraft = {
|
|
|
112
113
|
};
|
|
113
114
|
export declare function readParts(value: unknown): RoomDraftParts;
|
|
114
115
|
export declare function held(current: HeldParts | undefined, parts: RoomDraftParts): HeldParts;
|
|
115
|
-
export declare function equalValue(left: unknown, right: unknown): boolean;
|
|
116
116
|
export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
|
|
117
117
|
export declare function changedParts(path: string, report: ChangedUnderneath): readonly ChangedPart[];
|
|
118
118
|
export declare function returnedInto(existing: HeldParts | undefined, returned: HeldParts): HeldParts;
|
package/dist/room-draft.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room-draft.d.ts","sourceRoot":"","sources":["../src/room-draft.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"room-draft.d.ts","sourceRoot":"","sources":["../src/room-draft.ts"],"names":[],"mappings":"AACA,OAA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