@agentshouse/mdruntime 0.1.0-c0bed82db8d73 → 0.1.0-c0c1e81da9166
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/adapter.d.ts +101 -71
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +4 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +35 -46
- package/dist/bootstrap.d.ts +16 -15
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +273 -131
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/change.d.ts +1 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +2 -0
- package/dist/client.d.ts +15 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +54 -6
- package/dist/collection.d.ts +7 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +24 -19
- package/dist/compile.d.ts +6 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +278 -282
- package/dist/connection.d.ts +16 -11
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +2312 -1988
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +47 -0
- package/dist/conversation.d.ts +27 -18
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +489 -260
- package/dist/durability.d.ts +6 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +3 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +18 -8
- package/dist/figures.d.ts +48 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/file.d.ts +2 -11
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +6 -4
- package/dist/host.d.ts +3 -7
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +26 -29
- package/dist/identity.d.ts +0 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -3
- package/dist/index.d.ts +16 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/job.d.ts +33 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +54 -0
- package/dist/live.d.ts +5 -4
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +62 -20
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +13 -6
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +218 -91
- package/dist/messages.d.ts +27 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +97 -19
- package/dist/model.d.ts +8 -10
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -18
- package/dist/observation.d.ts +3 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +8 -3
- package/dist/outcome.d.ts +13 -5
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +16 -2
- package/dist/overlay.d.ts +1 -0
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +11 -0
- package/dist/parts.d.ts +59 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +118 -0
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -0
- package/dist/query.d.ts +18 -207
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/questions.d.ts +32 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +118 -0
- package/dist/reach.d.ts +18 -11
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +201 -126
- package/dist/react.d.ts +3 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +3 -17
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +4 -10
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +35 -1
- package/dist/refresh.d.ts +7 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +34 -10
- package/dist/replica.d.ts +10 -9
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +53 -21
- package/dist/room-draft.d.ts +21 -5
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +98 -51
- package/dist/rows.d.ts +18 -16
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +45 -153
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +22 -13
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/shared.d.ts +0 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +0 -10
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +81 -0
- package/dist/status.d.ts +4 -5
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -7
- package/dist/store.d.ts +104 -62
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +159 -161
- package/dist/stored.d.ts +66 -55
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +343 -273
- package/dist/tables.d.ts +110 -65
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +188 -99
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/validation.d.ts +3 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +42 -100
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +18 -8
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +6 -2
- package/package.json +2 -3
- package/AGENTS.md +0 -312
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -368
- package/dist/reads.d.ts +0 -11
- package/dist/reads.d.ts.map +0 -1
- package/dist/reads.js +0 -100
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -150
package/dist/read.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const EXCERPT = 512;
|
|
2
|
+
export function excerpt(said) {
|
|
3
|
+
return [...said.slice(0, EXCERPT * 2)].slice(0, EXCERPT).join('');
|
|
4
|
+
}
|
|
5
|
+
export function record(entry) {
|
|
6
|
+
return typeof entry === 'object' && entry !== null && !Array.isArray(entry)
|
|
7
|
+
? entry
|
|
8
|
+
: {};
|
|
9
|
+
}
|
|
10
|
+
export function text(fields, name) {
|
|
11
|
+
const value = fields[name];
|
|
12
|
+
return typeof value === 'string' && value !== '' ? value : null;
|
|
13
|
+
}
|
|
14
|
+
export function list(fields, name) {
|
|
15
|
+
const value = fields[name];
|
|
16
|
+
return Array.isArray(value) ? value : [];
|
|
17
|
+
}
|
package/dist/readiness.d.ts
CHANGED
|
@@ -1,46 +1,33 @@
|
|
|
1
1
|
import type { Open } from './open.js';
|
|
2
2
|
export type CodeAvailability = Open<'stored' | 'absent'>;
|
|
3
|
-
export type RoomPreparation = Open<'complete' | 'acquiring' | 'preparing' | '
|
|
3
|
+
export type RoomPreparation = Open<'complete' | 'acquiring' | 'preparing' | 'unadmitted'>;
|
|
4
4
|
export type RoomCoverage = {
|
|
5
5
|
readonly room: string;
|
|
6
6
|
readonly state: RoomPreparation;
|
|
7
7
|
};
|
|
8
8
|
export type ConversationCoverage = Open<'complete' | 'acquiring' | 'undeclared'>;
|
|
9
|
-
export type SearchObligation = Open<'required' | 'unused'>;
|
|
10
9
|
export type TargetCoverage = {
|
|
11
10
|
readonly complete: boolean;
|
|
12
11
|
readonly listed: boolean;
|
|
13
12
|
readonly rooms: readonly RoomCoverage[];
|
|
14
13
|
readonly conversations: ConversationCoverage;
|
|
15
|
-
readonly search: SearchObligation;
|
|
16
14
|
};
|
|
17
15
|
export type Persistence = Open<'granted' | 'denied' | 'unavailable'>;
|
|
18
16
|
export type Durability = Open<'persistent' | 'best-effort'>;
|
|
19
17
|
export type ConnectionAvailability = Open<'connected' | 'connecting' | 'unreachable'>;
|
|
20
18
|
export type HouseOutcome = Open<'open' | 'write-halted' | 'refused'>;
|
|
21
19
|
export type Space = Open<'full'>;
|
|
22
|
-
export type
|
|
23
|
-
readonly room: string;
|
|
24
|
-
readonly name: string;
|
|
25
|
-
readonly file: string;
|
|
26
|
-
readonly rule: string;
|
|
27
|
-
readonly location: string | null;
|
|
28
|
-
};
|
|
29
|
-
export type InstallationStep = Open<'listing' | 'downloading' | 'writing' | 'replaying'>;
|
|
30
|
-
export type InstallationPause = Open<'hidden'>;
|
|
20
|
+
export type InstallationStep = Open<'downloading' | 'writing' | 'replaying'>;
|
|
31
21
|
export type InstallationAmount = {
|
|
32
22
|
readonly done: number;
|
|
33
23
|
readonly total: number;
|
|
34
24
|
};
|
|
35
25
|
export type Installation = {
|
|
36
26
|
readonly step: InstallationStep | null;
|
|
37
|
-
readonly paused: InstallationPause | null;
|
|
38
27
|
readonly rooms: InstallationAmount;
|
|
39
|
-
readonly parts: InstallationAmount;
|
|
40
28
|
readonly bytes: InstallationAmount;
|
|
41
|
-
readonly received: InstallationAmount;
|
|
42
29
|
};
|
|
43
|
-
export type ReadinessStatus = Open<'preparing' | 'paused' | '
|
|
30
|
+
export type ReadinessStatus = Open<'preparing' | 'paused' | 'ready' | 'lost'>;
|
|
44
31
|
export type Readiness = {
|
|
45
32
|
readonly status: ReadinessStatus;
|
|
46
33
|
readonly ready: boolean;
|
|
@@ -53,7 +40,6 @@ export type Readiness = {
|
|
|
53
40
|
readonly house: HouseOutcome;
|
|
54
41
|
readonly space: Space | null;
|
|
55
42
|
readonly installation: Installation;
|
|
56
|
-
readonly refused: readonly RefusedRoom[];
|
|
57
43
|
readonly lost: boolean;
|
|
58
44
|
};
|
|
59
45
|
export type ReadinessFacts = Omit<Readiness, 'status' | 'ready' | 'usable' | 'durability' | 'coverage'> & {
|
package/dist/readiness.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readiness.d.ts","sourceRoot":"","sources":["../src/readiness.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;AAEzD,MAAM,MAAM,eAAe,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"readiness.d.ts","sourceRoot":"","sources":["../src/readiness.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;AAEzD,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,UAAU,GAAG,WAAW,GAAG,WAAW,GAAG,YAAY,CAAC,CAAC;AAE1F,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAA;CAAE,CAAC;AAEtF,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC,CAAC;AAEjF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CA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,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,sBAAsB,CAAC;IAC5C,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,IAAI,CAC/B,SAAS,EACT,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,YAAY,GAAG,UAAU,CAC1D,GAAG;IACF,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;IACpD,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B,CAAC;AAIF,wBAAgB,WAAW,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,CA2B5D"}
|
package/dist/readiness.js
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
const COMPLETE_ROOMS = new Set(['complete', 'unadmitted']);
|
|
2
|
-
const SETTLED_ROOMS = new Set([...COMPLETE_ROOMS, 'refused']);
|
|
3
2
|
export function readinessOf(facts) {
|
|
4
3
|
const { established, coverage: held, ...reported } = facts;
|
|
5
4
|
const settledConversations = held.conversations === 'complete' || held.conversations === 'undeclared';
|
|
6
5
|
const complete = held.listed &&
|
|
7
6
|
settledConversations &&
|
|
8
7
|
held.rooms.every((room) => COMPLETE_ROOMS.has(room.state));
|
|
9
|
-
const settled = held.listed &&
|
|
10
|
-
settledConversations &&
|
|
11
|
-
held.rooms.every((room) => SETTLED_ROOMS.has(room.state));
|
|
12
8
|
const coverage = { ...held, complete };
|
|
13
9
|
const stored = facts.code === 'stored';
|
|
14
10
|
const ready = stored && complete;
|
|
15
11
|
const usable = stored && (ready || established);
|
|
16
12
|
const status = ready
|
|
17
13
|
? 'ready'
|
|
18
|
-
: facts.space !== null
|
|
14
|
+
: facts.space !== null
|
|
19
15
|
? 'paused'
|
|
20
|
-
:
|
|
21
|
-
? '
|
|
22
|
-
:
|
|
23
|
-
? 'lost'
|
|
24
|
-
: 'preparing';
|
|
16
|
+
: facts.lost && !established
|
|
17
|
+
? 'lost'
|
|
18
|
+
: 'preparing';
|
|
25
19
|
return {
|
|
26
20
|
...reported,
|
|
27
21
|
coverage,
|
package/dist/recovery.d.ts
CHANGED
|
@@ -21,5 +21,6 @@ export type Recovery = {
|
|
|
21
21
|
retire(): Promise<void>;
|
|
22
22
|
};
|
|
23
23
|
export declare function retryDelay(tries: number, firstMs?: number, maxMs?: number): number;
|
|
24
|
+
export declare function untilAnswered<T>(ask: () => Promise<T>, signal: AbortSignal, answered?: (answer: T) => boolean): Promise<T>;
|
|
24
25
|
export declare function createRecovery(options?: RecoveryOptions): Recovery;
|
|
25
26
|
//# sourceMappingURL=recovery.d.ts.map
|
package/dist/recovery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../src/recovery.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;AAElE,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEhF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,E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AAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAClF,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IACjC,MAAM,IAAI,IAAI,CAAC;IACf,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IACnC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB,CAAC;AAsBF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,SAAW,EAAE,KAAK,SAAS,GAAG,MAAM,CAGpF;AAED,wBAAsB,aAAa,CAAC,CAAC,EACnC,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACrB,MAAM,EAAE,WAAW,EACnB,QAAQ,GAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAoB,GAC5C,OAAO,CAAC,CAAC,CAAC,CAsBZ;AA8KD,wBAAgB,cAAc,CAAC,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAStE"}
|
package/dist/recovery.js
CHANGED
|
@@ -7,6 +7,32 @@ export function retryDelay(tries, firstMs = FIRST_MS, maxMs = MAX_MS) {
|
|
|
7
7
|
const longest = Math.min(maxMs, firstMs * 2 ** tries);
|
|
8
8
|
return longest / 2 + (Math.random() * longest) / 2;
|
|
9
9
|
}
|
|
10
|
+
export async function untilAnswered(ask, signal, answered = () => true) {
|
|
11
|
+
for (let tries = 0;; tries += 1) {
|
|
12
|
+
try {
|
|
13
|
+
const answer = await ask();
|
|
14
|
+
if (answered(answer) || signal.aborted)
|
|
15
|
+
return answer;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (signal.aborted)
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
await new Promise((resume) => {
|
|
22
|
+
const stop = () => {
|
|
23
|
+
clearTimeout(again);
|
|
24
|
+
resume();
|
|
25
|
+
};
|
|
26
|
+
// A read that failed is asked again on the doubling backoff, so its asker is answered once the failure clears.
|
|
27
|
+
const again = setTimeout(() => {
|
|
28
|
+
signal.removeEventListener('abort', stop);
|
|
29
|
+
resume();
|
|
30
|
+
}, retryDelay(tries));
|
|
31
|
+
signal.addEventListener('abort', stop, { once: true });
|
|
32
|
+
});
|
|
33
|
+
signal.throwIfAborted();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
10
36
|
function owner(backoff, inFlight, release = () => { }) {
|
|
11
37
|
const intents = new Map();
|
|
12
38
|
const children = new Set();
|
|
@@ -80,7 +106,15 @@ function owner(backoff, inFlight, release = () => { }) {
|
|
|
80
106
|
}
|
|
81
107
|
intent.tries += 1;
|
|
82
108
|
if (intent.tries >= backoff.attempts) {
|
|
83
|
-
|
|
109
|
+
if (again === null) {
|
|
110
|
+
finish(key, intent, false);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
intent.tries = 0;
|
|
114
|
+
if (again === 'now')
|
|
115
|
+
launch(key, intent);
|
|
116
|
+
else
|
|
117
|
+
wait(key, intent, again, true);
|
|
84
118
|
return;
|
|
85
119
|
}
|
|
86
120
|
if (result === 'again') {
|
package/dist/refresh.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AdapterFailure, Authorization, RefreshPage, RetryableRefusal } from './adapter.js';
|
|
2
|
-
import type {
|
|
1
|
+
import type { AdapterFailure, Authorization, RefreshPage, RefreshRequest, RefreshResult, RetryableRefusal } from './adapter.js';
|
|
2
|
+
import type { Remodel } from './bootstrap.js';
|
|
3
3
|
import type { ReplicaRecord } from './replica.js';
|
|
4
4
|
import type { RefreshedPage } from './store.js';
|
|
5
5
|
import type { HeldEntry, StoredEntry } from './tables.js';
|
|
@@ -13,13 +13,15 @@ export type Advancement = {
|
|
|
13
13
|
} | {
|
|
14
14
|
kind: 'beyond-horizon';
|
|
15
15
|
} | RetryableRefusal | Unconfirmed | AdapterFailure;
|
|
16
|
+
export type Refresher = (authorization: Authorization, request: RefreshRequest) => Promise<RefreshResult>;
|
|
16
17
|
export type Refreshing = {
|
|
17
|
-
turn():
|
|
18
|
+
turn(): void;
|
|
18
19
|
prior(paths: readonly string[]): Promise<ReadonlyMap<string, HeldEntry>>;
|
|
20
|
+
later(paths: readonly string[], roomVersion: string): Promise<ReadonlySet<string>>;
|
|
19
21
|
stage(page: RefreshedPage): Promise<boolean>;
|
|
20
22
|
};
|
|
21
|
-
type PageContent = Pick<RefreshPage, 'documents' | 'revisions' | 'fileIds' | 'changes' | 'binaryFiles'>;
|
|
23
|
+
type PageContent = Pick<RefreshPage, 'documents' | 'facts' | 'revisions' | 'fileIds' | 'created' | 'changes' | 'binaryFiles'>;
|
|
22
24
|
export declare function pageEntries(page: PageContent, removals: readonly string[], roomVersion: string, prior: (paths: readonly string[]) => Promise<ReadonlyMap<string, HeldEntry>>): Promise<StoredEntry[]>;
|
|
23
|
-
export declare function advancement(
|
|
25
|
+
export declare function advancement(refresh: Refresher, authorization: Authorization, held: ReplicaRecord, remodel: Remodel, continuing: () => boolean, staging: Refreshing): Promise<Advancement>;
|
|
24
26
|
export {};
|
|
25
27
|
//# 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,
|
|
1
|
+
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,WAAW,EACX,cAAc,EACd,aAAa,E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,CAAC;AAwFF,wBAAsB,WAAW,CAC/B,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,GAC3E,OAAO,CAAC,WAAW,EAAE,CAAC,CAKxB;AAgDD,wBAAsB,WAAW,CAC/B,OAAO,EAAE,SAAS,EAClB,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,OAAO,EACzB,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,WAAW,CAAC,CA8CtB"}
|
package/dist/refresh.js
CHANGED
|
@@ -45,9 +45,11 @@ function* entering(page, roomVersion, listed, prior) {
|
|
|
45
45
|
entries.push({
|
|
46
46
|
path,
|
|
47
47
|
content: page.documents[path],
|
|
48
|
+
facts: page.facts[path] ?? null,
|
|
48
49
|
binary: null,
|
|
49
50
|
revision: page.revisions[path] ?? prior.get(path)?.revision ?? null,
|
|
50
51
|
fileId: page.fileIds?.[path] ?? null,
|
|
52
|
+
created: page.created?.[path] ?? null,
|
|
51
53
|
change: page.changes[path] ?? null,
|
|
52
54
|
written: roomVersion,
|
|
53
55
|
});
|
|
@@ -57,9 +59,11 @@ function* entering(page, roomVersion, listed, prior) {
|
|
|
57
59
|
entries.push({
|
|
58
60
|
path,
|
|
59
61
|
content: null,
|
|
62
|
+
facts: null,
|
|
60
63
|
binary: { state: 'accepted', ...page.binaryFiles[path] },
|
|
61
64
|
revision: page.revisions[path] ?? prior.get(path)?.revision ?? null,
|
|
62
65
|
fileId: page.fileIds?.[path] ?? null,
|
|
66
|
+
created: page.created?.[path] ?? null,
|
|
63
67
|
change: page.changes[path] ?? null,
|
|
64
68
|
written: null,
|
|
65
69
|
});
|
|
@@ -74,6 +78,7 @@ function* entering(page, roomVersion, listed, prior) {
|
|
|
74
78
|
...kept,
|
|
75
79
|
revision: page.revisions[path] ?? held.revision,
|
|
76
80
|
fileId: page.fileIds?.[path] ?? held.fileId,
|
|
81
|
+
created: page.created?.[path] ?? held.created,
|
|
77
82
|
change: page.changes[path] ?? held.change,
|
|
78
83
|
});
|
|
79
84
|
}
|
|
@@ -85,7 +90,30 @@ export async function pageEntries(page, removals, roomVersion, prior) {
|
|
|
85
90
|
const held = listed.asked.length === 0 ? new Map() : await prior(listed.asked);
|
|
86
91
|
return stepped(entering(page, roomVersion, listed, held));
|
|
87
92
|
}
|
|
88
|
-
|
|
93
|
+
function without(named, kept) {
|
|
94
|
+
return Object.fromEntries(Object.entries(named).filter(([path]) => !kept.has(path)));
|
|
95
|
+
}
|
|
96
|
+
function unwritten(page, kept) {
|
|
97
|
+
if (kept.size === 0)
|
|
98
|
+
return page;
|
|
99
|
+
return {
|
|
100
|
+
...page,
|
|
101
|
+
documents: without(page.documents, kept),
|
|
102
|
+
facts: without(page.facts, kept),
|
|
103
|
+
revisions: without(page.revisions, kept),
|
|
104
|
+
...(page.fileIds === undefined ? {} : { fileIds: without(page.fileIds, kept) }),
|
|
105
|
+
...(page.created === undefined ? {} : { created: without(page.created, kept) }),
|
|
106
|
+
changes: without(page.changes, kept),
|
|
107
|
+
binaryFiles: without(page.binaryFiles, kept),
|
|
108
|
+
removals: page.removals.filter((path) => !kept.has(path)),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
async function pageOf(answered, roomVersion, staging) {
|
|
112
|
+
const page = unwritten(answered, await staging.later([
|
|
113
|
+
...Object.keys(answered.documents),
|
|
114
|
+
...Object.keys(answered.binaryFiles),
|
|
115
|
+
...answered.removals,
|
|
116
|
+
], roomVersion));
|
|
89
117
|
return {
|
|
90
118
|
entries: await pageEntries(page, page.removals, roomVersion, (paths) => staging.prior(paths)),
|
|
91
119
|
removals: page.removals,
|
|
@@ -93,13 +121,13 @@ async function pageOf(page, roomVersion, staging) {
|
|
|
93
121
|
folderRemovals: page.folderRemovals ?? [],
|
|
94
122
|
};
|
|
95
123
|
}
|
|
96
|
-
export async function advancement(
|
|
124
|
+
export async function advancement(refresh, authorization, held, remodel, continuing, staging) {
|
|
97
125
|
const locator = held.locator;
|
|
98
126
|
const fromRoomVersion = held.roomVersion;
|
|
99
|
-
|
|
127
|
+
staging.turn();
|
|
100
128
|
if (!continuing())
|
|
101
129
|
return unconfirmed;
|
|
102
|
-
const first = await
|
|
130
|
+
const first = await refresh(authorization, {
|
|
103
131
|
locator,
|
|
104
132
|
selection: held.replica.selection,
|
|
105
133
|
fromRoomVersion,
|
|
@@ -107,10 +135,7 @@ export async function advancement(adapter, authorization, held, remodel, continu
|
|
|
107
135
|
if (first.kind !== 'net-advancement')
|
|
108
136
|
return first;
|
|
109
137
|
const roomVersion = first.roomVersion;
|
|
110
|
-
const models = remodel(first.models, {
|
|
111
|
-
collection: held.model,
|
|
112
|
-
selection: held.selectionModel,
|
|
113
|
-
});
|
|
138
|
+
const models = remodel(first.models, { collection: held.model });
|
|
114
139
|
const changed = new Set();
|
|
115
140
|
const staged = async (page) => {
|
|
116
141
|
const read = await pageOf(page, roomVersion, staging);
|
|
@@ -127,7 +152,7 @@ export async function advancement(adapter, authorization, held, remodel, continu
|
|
|
127
152
|
await staging.turn();
|
|
128
153
|
if (!continuing())
|
|
129
154
|
return unconfirmed;
|
|
130
|
-
const page = await
|
|
155
|
+
const page = await refresh(authorization, {
|
|
131
156
|
locator,
|
|
132
157
|
selection: held.replica.selection,
|
|
133
158
|
fromRoomVersion,
|
|
@@ -148,7 +173,6 @@ export async function advancement(adapter, authorization, held, remodel, continu
|
|
|
148
173
|
record: {
|
|
149
174
|
...held,
|
|
150
175
|
model: models.collection,
|
|
151
|
-
selectionModel: models.selection,
|
|
152
176
|
roomVersion,
|
|
153
177
|
},
|
|
154
178
|
changed,
|
package/dist/replica.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type TypedPath } from '@agentshouse/mdmodel';
|
|
2
|
+
import type { BootstrapInventory, SavedFacts, MutationResult, OperationScopes, ReplicaAdmission, TypedSelection } from './adapter.js';
|
|
2
3
|
import { type ChangeBatch, type Precondition } from './change.js';
|
|
3
4
|
import { type Collection, type Composition } from './collection.js';
|
|
4
|
-
import type
|
|
5
|
+
import { type ModelState } from './model.js';
|
|
5
6
|
import { type Layer } from './overlay.js';
|
|
6
7
|
import type { HeldEntry, OverlayEntry, StoredEntry } from './tables.js';
|
|
7
8
|
export type ReplicaRecord = {
|
|
@@ -12,11 +13,10 @@ export type ReplicaRecord = {
|
|
|
12
13
|
readonly replica: ReplicaAdmission;
|
|
13
14
|
readonly model: ModelState;
|
|
14
15
|
readonly typedSelection: TypedSelection | null;
|
|
15
|
-
readonly selectionModel: ModelState;
|
|
16
16
|
readonly providerOwnedPaths: readonly string[];
|
|
17
17
|
readonly roomVersion: string;
|
|
18
18
|
readonly transfer: string;
|
|
19
|
-
readonly inventory: BootstrapInventory
|
|
19
|
+
readonly inventory: BootstrapInventory;
|
|
20
20
|
readonly key: number;
|
|
21
21
|
};
|
|
22
22
|
export type HeldReplica = {
|
|
@@ -32,15 +32,16 @@ export type VisibleLayer = Layer & {
|
|
|
32
32
|
};
|
|
33
33
|
export type Slice = Layer & {
|
|
34
34
|
readonly written: Readonly<Record<string, string>>;
|
|
35
|
+
readonly facts: Readonly<Record<string, SavedFacts>>;
|
|
35
36
|
readonly held: ReadonlySet<string>;
|
|
36
37
|
};
|
|
37
|
-
export declare function compositionOf(record: Pick<ReplicaRecord, 'model' | 'typedSelection'
|
|
38
|
-
export declare function sameMembership(record: Pick<ReplicaRecord, 'typedSelection'>, other: Pick<ReplicaRecord, 'typedSelection'>): boolean;
|
|
38
|
+
export declare function compositionOf(record: Pick<ReplicaRecord, 'model' | 'typedSelection'>, builtIn: ModelState, typedPaths: readonly TypedPath[]): Composition;
|
|
39
39
|
export declare function storedRecord(record: ReplicaRecord): string;
|
|
40
40
|
export declare function slicing(entries: readonly HeldEntry[], paths: Iterable<string>): Generator<number, Slice, void>;
|
|
41
|
+
export type LayerEntry = Omit<StoredEntry, 'facts'>;
|
|
41
42
|
export declare function entryAt(layer: Layer & {
|
|
42
43
|
readonly written?: Readonly<Record<string, string>>;
|
|
43
|
-
}, path: string):
|
|
44
|
+
}, path: string): LayerEntry | null;
|
|
44
45
|
export declare function slicingWith(slice: Slice, set: readonly StoredEntry[], removed: readonly string[]): Generator<number, Slice, void>;
|
|
45
46
|
export declare function touchedBy(queue: readonly ChangeBatch[]): Set<string>;
|
|
46
47
|
export declare function movedBy(queue: readonly ChangeBatch[], locator: string): Set<string>;
|
|
@@ -49,7 +50,7 @@ export type Replayed = {
|
|
|
49
50
|
readonly touched: ReadonlySet<string>;
|
|
50
51
|
};
|
|
51
52
|
export declare function replaying(confirmed: Slice, queue: readonly ChangeBatch[], locator: string, composition: Composition): Generator<number, Replayed, void>;
|
|
52
|
-
export declare function overlayOf(visible:
|
|
53
|
+
export declare function overlayOf(visible: VisibleLayer, touched: Iterable<string>): Generator<number, OverlayEntry[], void>;
|
|
53
54
|
export declare function holds(layer: Layer, preconditions: readonly Precondition[]): boolean;
|
|
54
55
|
export declare function landed(batch: ChangeBatch, confirmed: Layer, current?: Readonly<Record<string, string>>): boolean;
|
|
55
56
|
export type Standing = {
|
|
@@ -65,6 +66,6 @@ export type Returned = {
|
|
|
65
66
|
readonly removed: readonly string[];
|
|
66
67
|
};
|
|
67
68
|
export declare function returnedPaths(submitted: ChangeBatch, accepted: Accepted): Set<string>;
|
|
68
|
-
export declare function returning(confirmed: Slice, submitted: ChangeBatch, accepted: Accepted, writtenAt: string): Generator<number, Returned, void>;
|
|
69
|
+
export declare function returning(confirmed: Slice, submitted: ChangeBatch, accepted: Accepted, writtenAt: string, composition: Composition): Generator<number, Returned, void>;
|
|
69
70
|
export {};
|
|
70
71
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"replica.d.ts","sourceRoot":"","sources":["../src/replica.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EAEV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAmC,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAgB,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAiD,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAGzF,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGxE,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;IAC/C,QAAQ,CAAC,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAC;I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dmodel';
|
|
2
2
|
import { immutable, landing } from './change.js';
|
|
3
3
|
import { collectionOf } from './collection.js';
|
|
4
|
+
import { storedModel } from './model.js';
|
|
4
5
|
import { acceptedBinaries, overlaying } from './overlay.js';
|
|
6
|
+
import { writtenFacts } from './rows.js';
|
|
5
7
|
import { effectiveIn, rewriting } from './save.js';
|
|
6
8
|
import { ROW_WEIGHT } from './turn.js';
|
|
7
|
-
export function compositionOf(record) {
|
|
9
|
+
export function compositionOf(record, builtIn, typedPaths) {
|
|
8
10
|
return {
|
|
9
11
|
model: record.model,
|
|
10
12
|
selection: record.typedSelection === null
|
|
11
13
|
? null
|
|
12
|
-
: { roots: record.typedSelection.roots, model:
|
|
14
|
+
: { roots: record.typedSelection.roots, model: builtIn },
|
|
15
|
+
typedPaths,
|
|
13
16
|
};
|
|
14
17
|
}
|
|
15
|
-
export function sameMembership(record, other) {
|
|
16
|
-
return (JSON.stringify(record.typedSelection?.roots ?? null) ===
|
|
17
|
-
JSON.stringify(other.typedSelection?.roots ?? null));
|
|
18
|
-
}
|
|
19
18
|
export function storedRecord(record) {
|
|
20
19
|
const { key: _key, ...stored } = record;
|
|
21
|
-
return JSON.stringify(stored);
|
|
20
|
+
return JSON.stringify({ ...stored, model: storedModel(stored.model) });
|
|
22
21
|
}
|
|
23
22
|
const PROBES = new Set([
|
|
24
23
|
'then',
|
|
@@ -61,9 +60,13 @@ export function* slicing(entries, paths) {
|
|
|
61
60
|
const binaries = {};
|
|
62
61
|
const revisions = {};
|
|
63
62
|
const fileIds = {};
|
|
63
|
+
const created = {};
|
|
64
64
|
const changes = {};
|
|
65
65
|
const written = {};
|
|
66
|
+
const facts = {};
|
|
66
67
|
for (const entry of entries) {
|
|
68
|
+
if (entry.facts !== null)
|
|
69
|
+
facts[entry.path] = entry.facts;
|
|
67
70
|
if (entry.binary !== null)
|
|
68
71
|
binaries[entry.path] = entry.binary;
|
|
69
72
|
else if (entry.content !== null)
|
|
@@ -72,6 +75,8 @@ export function* slicing(entries, paths) {
|
|
|
72
75
|
revisions[entry.path] = entry.revision;
|
|
73
76
|
if (entry.fileId !== null)
|
|
74
77
|
fileIds[entry.path] = entry.fileId;
|
|
78
|
+
if (entry.created !== null)
|
|
79
|
+
created[entry.path] = entry.created;
|
|
75
80
|
if (entry.change !== null)
|
|
76
81
|
changes[entry.path] = entry.change;
|
|
77
82
|
if (entry.written !== null)
|
|
@@ -83,8 +88,10 @@ export function* slicing(entries, paths) {
|
|
|
83
88
|
binaries: strict(binaries, held),
|
|
84
89
|
revisions: strict(revisions, held),
|
|
85
90
|
fileIds: strict(fileIds, held),
|
|
91
|
+
created: strict(created, held),
|
|
86
92
|
changes: strict(changes, held),
|
|
87
93
|
written: strict(written, held),
|
|
94
|
+
facts: strict(facts, held),
|
|
88
95
|
held,
|
|
89
96
|
};
|
|
90
97
|
}
|
|
@@ -99,6 +106,7 @@ export function entryAt(layer, path) {
|
|
|
99
106
|
binary: binary ?? null,
|
|
100
107
|
revision: layer.revisions[path] ?? null,
|
|
101
108
|
fileId: layer.fileIds[path] ?? null,
|
|
109
|
+
created: layer.created[path] ?? null,
|
|
102
110
|
change: layer.changes[path] ?? null,
|
|
103
111
|
written: layer.written?.[path] ?? null,
|
|
104
112
|
};
|
|
@@ -107,8 +115,9 @@ export function* slicingWith(slice, set, removed) {
|
|
|
107
115
|
const entries = new Map();
|
|
108
116
|
for (const path of slice.held) {
|
|
109
117
|
const entry = entryAt(slice, path);
|
|
110
|
-
if (entry !== null)
|
|
111
|
-
entries.set(path, { ...entry, type: null });
|
|
118
|
+
if (entry !== null) {
|
|
119
|
+
entries.set(path, { ...entry, type: null, facts: slice.facts[path] ?? null });
|
|
120
|
+
}
|
|
112
121
|
yield ROW_WEIGHT;
|
|
113
122
|
}
|
|
114
123
|
for (const path of removed)
|
|
@@ -172,8 +181,9 @@ export function* replaying(confirmed, queue, locator, composition) {
|
|
|
172
181
|
export function* overlayOf(visible, touched) {
|
|
173
182
|
const rows = [];
|
|
174
183
|
for (const path of touched) {
|
|
175
|
-
yield ROW_WEIGHT;
|
|
176
184
|
const entry = entryAt(visible, path);
|
|
185
|
+
yield ROW_WEIGHT + (entry?.content?.length ?? 0);
|
|
186
|
+
const text = entry?.binary === null ? entry.content : null;
|
|
177
187
|
rows.push(entry === null
|
|
178
188
|
? {
|
|
179
189
|
path,
|
|
@@ -182,10 +192,17 @@ export function* overlayOf(visible, touched) {
|
|
|
182
192
|
binary: null,
|
|
183
193
|
revision: null,
|
|
184
194
|
fileId: null,
|
|
195
|
+
created: null,
|
|
185
196
|
change: null,
|
|
186
197
|
written: null,
|
|
198
|
+
facts: null,
|
|
187
199
|
}
|
|
188
|
-
: {
|
|
200
|
+
: {
|
|
201
|
+
...entry,
|
|
202
|
+
written: null,
|
|
203
|
+
present: true,
|
|
204
|
+
facts: text === null ? null : writtenFacts(path, text, visible.collection.composition),
|
|
205
|
+
});
|
|
189
206
|
}
|
|
190
207
|
return rows;
|
|
191
208
|
}
|
|
@@ -350,17 +367,20 @@ export function returnedPaths(submitted, accepted) {
|
|
|
350
367
|
}
|
|
351
368
|
return paths;
|
|
352
369
|
}
|
|
353
|
-
export function* returning(confirmed, submitted, accepted, writtenAt) {
|
|
370
|
+
export function* returning(confirmed, submitted, accepted, writtenAt, composition) {
|
|
354
371
|
const documents = new Map();
|
|
355
372
|
const binaries = new Map();
|
|
356
373
|
const revisions = new Map();
|
|
357
374
|
const fileIds = new Map();
|
|
375
|
+
const created = new Map();
|
|
358
376
|
const changes = new Map();
|
|
359
377
|
const written = new Map();
|
|
378
|
+
const facts = new Map();
|
|
360
379
|
const read = (changed, held, path) => (changed.has(path) ? changed.get(path) : held[path]);
|
|
361
380
|
for (const [path, content] of Object.entries(accepted.documents)) {
|
|
362
|
-
yield ROW_WEIGHT;
|
|
381
|
+
yield ROW_WEIGHT + content.length;
|
|
363
382
|
documents.set(path, content);
|
|
383
|
+
facts.set(path, writtenFacts(path, content, composition));
|
|
364
384
|
fileIds.set(path, undefined);
|
|
365
385
|
written.set(path, writtenAt);
|
|
366
386
|
}
|
|
@@ -383,48 +403,60 @@ export function* returning(confirmed, submitted, accepted, writtenAt) {
|
|
|
383
403
|
written.set(path, undefined);
|
|
384
404
|
}
|
|
385
405
|
for (const change of submitted.changes) {
|
|
386
|
-
if (change.kind === 'arrival'
|
|
387
|
-
if (accepted.revisions[change.path]
|
|
406
|
+
if (change.kind === 'arrival') {
|
|
407
|
+
if (accepted.revisions[change.path] === undefined)
|
|
408
|
+
continue;
|
|
409
|
+
created.set(change.path, change.created);
|
|
410
|
+
if ('binary' in change)
|
|
388
411
|
binaries.set(change.path, { state: 'accepted', ...change.binary });
|
|
389
|
-
}
|
|
390
412
|
continue;
|
|
391
413
|
}
|
|
392
|
-
if (change.kind !== 'move')
|
|
414
|
+
if (change.kind !== 'move' || accepted.revisions[change.to] === undefined)
|
|
393
415
|
continue;
|
|
416
|
+
created.set(change.to, read(created, confirmed.created, change.path));
|
|
417
|
+
created.set(change.path, undefined);
|
|
394
418
|
const moved = read(binaries, confirmed.binaries, change.path);
|
|
395
|
-
if (moved === undefined
|
|
419
|
+
if (moved === undefined)
|
|
396
420
|
continue;
|
|
397
421
|
binaries.set(change.to, moved);
|
|
398
422
|
binaries.set(change.path, undefined);
|
|
399
423
|
}
|
|
400
424
|
for (const [path, binary] of acceptedBinaries(accepted.binaryFiles ?? {}))
|
|
401
425
|
binaries.set(path, binary);
|
|
402
|
-
for (const path of accepted.removals)
|
|
426
|
+
for (const path of accepted.removals) {
|
|
403
427
|
binaries.set(path, undefined);
|
|
428
|
+
created.set(path, undefined);
|
|
429
|
+
}
|
|
404
430
|
const paths = new Set([
|
|
405
431
|
...documents.keys(),
|
|
406
432
|
...binaries.keys(),
|
|
407
433
|
...revisions.keys(),
|
|
408
434
|
...fileIds.keys(),
|
|
435
|
+
...created.keys(),
|
|
409
436
|
...changes.keys(),
|
|
410
437
|
...written.keys(),
|
|
411
438
|
]);
|
|
412
439
|
const set = [];
|
|
413
440
|
const removed = [];
|
|
414
441
|
for (const path of paths) {
|
|
415
|
-
yield ROW_WEIGHT;
|
|
416
442
|
const content = read(documents, confirmed.documents, path);
|
|
417
443
|
const binary = read(binaries, confirmed.binaries, path);
|
|
444
|
+
yield ROW_WEIGHT;
|
|
418
445
|
if (content === undefined && binary === undefined) {
|
|
419
446
|
removed.push(path);
|
|
420
447
|
continue;
|
|
421
448
|
}
|
|
449
|
+
const text = binary === undefined ? (content ?? null) : null;
|
|
450
|
+
const fresh = confirmed.documents[path] === undefined && confirmed.binaries[path] === undefined;
|
|
422
451
|
set.push({
|
|
423
452
|
path,
|
|
424
|
-
content:
|
|
453
|
+
content: text,
|
|
454
|
+
facts: text === null ? null : (read(facts, confirmed.facts, path) ?? null),
|
|
425
455
|
binary: binary ?? null,
|
|
426
456
|
revision: read(revisions, confirmed.revisions, path) ?? null,
|
|
427
457
|
fileId: read(fileIds, confirmed.fileIds, path) ?? null,
|
|
458
|
+
created: read(created, confirmed.created, path) ??
|
|
459
|
+
(fresh ? (read(changes, confirmed.changes, path)?.time ?? null) : null),
|
|
428
460
|
change: read(changes, confirmed.changes, path) ?? null,
|
|
429
461
|
written: read(written, confirmed.written, path) ?? null,
|
|
430
462
|
});
|