@agentshouse/mdruntime 0.1.0-ce5c5bb29be5a → 0.1.0-ce6bc9239a3ee
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 +2 -2
- package/dist/acceptance.d.ts +26 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +384 -0
- package/dist/adapter.d.ts +81 -49
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +3 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +21 -56
- package/dist/bootstrap.d.ts +9 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +209 -75
- 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 +16 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -1
- package/dist/collection.d.ts +2 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/compile.d.ts +6 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +262 -318
- package/dist/connection.d.ts +20 -44
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1438 -3393
- 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 +26 -17
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +441 -307
- package/dist/durability.d.ts +6 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +2 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +17 -7
- package/dist/figures.d.ts +48 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/host.d.ts +4 -6
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +22 -26
- 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 +18 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/install.d.ts +86 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +537 -0
- 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 +63 -22
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/memory.d.ts +11 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +171 -81
- 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 +2 -9
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -9
- package/dist/observation.d.ts +2 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +7 -2
- package/dist/outcome.d.ts +1 -0
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +3 -0
- 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/query.d.ts +14 -209
- 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 +12 -12
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +182 -136
- package/dist/react.d.ts +5 -2
- 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 +0 -2
- package/dist/readiness.d.ts.map +1 -1
- package/dist/reads.d.ts +36 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +136 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +9 -1
- package/dist/refresh.d.ts +6 -4
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +32 -4
- package/dist/replica.d.ts +8 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +50 -15
- package/dist/room-draft.d.ts +4 -3
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +65 -52
- package/dist/room-drafts.d.ts +29 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +216 -0
- package/dist/rows.d.ts +14 -21
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +48 -184
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +11 -8
- package/dist/saves.d.ts +96 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +999 -0
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/seed.d.ts +16 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +66 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket.d.ts +43 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +96 -0
- 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 +0 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -6
- package/dist/store/fences.d.ts +16 -0
- package/dist/store/fences.d.ts.map +1 -0
- package/dist/store/fences.js +26 -0
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +34 -0
- package/dist/store/records.d.ts +212 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +408 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- package/dist/store/watchers.d.ts +15 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +36 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +78 -145
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +117 -367
- package/dist/stored.d.ts +58 -32
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +264 -187
- package/dist/tables.d.ts +107 -25
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +193 -47
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +7 -4
- 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 +15 -4
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +6 -1
- package/package.json +2 -2
- 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 -370
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -156
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
|
@@ -6,13 +6,11 @@ export type RoomCoverage = {
|
|
|
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'>;
|
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,CAAC,UAAU,GAAG,WAAW,GAAG,WAAW,GAAG,YAAY,CAAC,CAAC;AAE1F,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE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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/reads.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type CallResult } from './outcome.js';
|
|
2
|
+
import type { Recovery } from './recovery.js';
|
|
3
|
+
import type { Connection, RuntimeDatabase } from './tables.js';
|
|
4
|
+
export declare const READ_TABLES: readonly string[];
|
|
5
|
+
export type ReadAt = {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly input: string;
|
|
8
|
+
readonly build: string;
|
|
9
|
+
};
|
|
10
|
+
export type ObservedRead = {
|
|
11
|
+
readonly answer: unknown;
|
|
12
|
+
readonly failure: CallResult | null;
|
|
13
|
+
readonly kept: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type ReadAnswers = {
|
|
16
|
+
watch(name: string, input: unknown, deliver: (read: ObservedRead) => void): () => void;
|
|
17
|
+
again(): void;
|
|
18
|
+
reopened(): void;
|
|
19
|
+
};
|
|
20
|
+
export type ReadAnswersOptions = {
|
|
21
|
+
readonly database: RuntimeDatabase;
|
|
22
|
+
readonly build: string;
|
|
23
|
+
readonly unkept: readonly string[];
|
|
24
|
+
readonly leading: readonly string[];
|
|
25
|
+
readonly recovery: Recovery;
|
|
26
|
+
call(name: string, input: unknown): Promise<CallResult>;
|
|
27
|
+
online(): boolean;
|
|
28
|
+
closed(): boolean;
|
|
29
|
+
full(): boolean;
|
|
30
|
+
filled(): void;
|
|
31
|
+
};
|
|
32
|
+
export declare function storedRead(connection: Connection, { name, input, build }: ReadAt): string | null;
|
|
33
|
+
export declare function keptRead(connection: Connection, { name, input, build }: ReadAt, answer: string): null;
|
|
34
|
+
export declare function readsOfOtherBuildsForgotten(connection: Connection, build: string): null;
|
|
35
|
+
export declare function readAnswers(options: ReadAnswersOptions): ReadAnswers;
|
|
36
|
+
//# sourceMappingURL=reads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reads.d.ts","sourceRoot":"","sources":["../src/reads.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE/D,eAAO,MAAM,WAAW,EAAE,SAAS,MAAM,EAExC,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACvF,KAAK,IAAI,IAAI,CAAC;IACd,QAAQ,IAAI,IAAI,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACxD,MAAM,IAAI,OAAO,CAAC;IAClB,MAAM,IAAI,OAAO,CAAC;IAClB,IAAI,IAAI,OAAO,CAAC;IAChB,MAAM,IAAI,IAAI,CAAC;CAChB,CAAC;AAaF,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMhG;AAED,wBAAgB,QAAQ,CACtB,UAAU,EAAE,UAAU,EACtB,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,MAAM,EAC9B,MAAM,EAAE,MAAM,GACb,IAAI,CAMN;AAED,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAGvF;AAMD,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAgHpE"}
|
package/dist/reads.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { refusedForSpace } from './durability.js';
|
|
2
|
+
import { answeredResult, UNCERTAIN } from './outcome.js';
|
|
3
|
+
export const READ_TABLES = [
|
|
4
|
+
'CREATE TABLE read_answers (name TEXT NOT NULL, input TEXT NOT NULL, build TEXT NOT NULL, answer TEXT NOT NULL, PRIMARY KEY (name, input)) WITHOUT ROWID',
|
|
5
|
+
];
|
|
6
|
+
export function storedRead(connection, { name, input, build }) {
|
|
7
|
+
const [held] = connection.rows('SELECT answer FROM read_answers WHERE name = ? AND input = ? AND build = ?', [name, input, build]);
|
|
8
|
+
return held === undefined ? null : String(held.answer);
|
|
9
|
+
}
|
|
10
|
+
export function keptRead(connection, { name, input, build }, answer) {
|
|
11
|
+
connection.run('INSERT OR REPLACE INTO read_answers (name, input, build, answer) VALUES (?, ?, ?, ?)', [name, input, build, answer]);
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
export function readsOfOtherBuildsForgotten(connection, build) {
|
|
15
|
+
connection.run('DELETE FROM read_answers WHERE build <> ?', [build]);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
function answered(result) {
|
|
19
|
+
return result.kind === 'action' && answeredResult(result.result);
|
|
20
|
+
}
|
|
21
|
+
export function readAnswers(options) {
|
|
22
|
+
const { database, build, recovery } = options;
|
|
23
|
+
const unkept = new Set(options.unkept);
|
|
24
|
+
const leading = new Set(options.leading);
|
|
25
|
+
const reads = new Map();
|
|
26
|
+
function leads(read) {
|
|
27
|
+
return leading.has(read.at.name);
|
|
28
|
+
}
|
|
29
|
+
function show(read, shown) {
|
|
30
|
+
read.shown = shown;
|
|
31
|
+
for (const deliver of read.observers)
|
|
32
|
+
deliver(shown);
|
|
33
|
+
}
|
|
34
|
+
async function kept(read, answer) {
|
|
35
|
+
if (!read.shown.kept || options.full())
|
|
36
|
+
return;
|
|
37
|
+
await database.ask({ kind: 'read.keep', ...read.at, answer }).catch((error) => {
|
|
38
|
+
if (refusedForSpace(error))
|
|
39
|
+
options.filled();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async function asked(read, led) {
|
|
43
|
+
if (!options.online()) {
|
|
44
|
+
read.owed = true;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const result = await options.call(read.at.name, read.asked).catch(() => UNCERTAIN);
|
|
48
|
+
if (options.closed())
|
|
49
|
+
return;
|
|
50
|
+
read.owed = !answered(result);
|
|
51
|
+
if (read.owed) {
|
|
52
|
+
show(read, { ...read.shown, failure: result });
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const answer = result.result;
|
|
56
|
+
const text = JSON.stringify(answer);
|
|
57
|
+
if (text === read.text && read.shown.failure === null)
|
|
58
|
+
return;
|
|
59
|
+
read.text = text;
|
|
60
|
+
await kept(read, text);
|
|
61
|
+
await led;
|
|
62
|
+
if (!options.closed())
|
|
63
|
+
show(read, { ...read.shown, answer, failure: null });
|
|
64
|
+
}
|
|
65
|
+
function forgotten(read) {
|
|
66
|
+
read.text = null;
|
|
67
|
+
read.shown = { ...read.shown, answer: null, failure: null };
|
|
68
|
+
}
|
|
69
|
+
function ask(read, led) {
|
|
70
|
+
return recovery.attempt(read.key, async () => {
|
|
71
|
+
await asked(read, led);
|
|
72
|
+
return 'done';
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function opened(name, input, key) {
|
|
76
|
+
const held = !unkept.has(name);
|
|
77
|
+
const read = {
|
|
78
|
+
key,
|
|
79
|
+
at: { name, input: JSON.stringify(input ?? null), build },
|
|
80
|
+
asked: input,
|
|
81
|
+
observers: new Set(),
|
|
82
|
+
stored: Promise.resolve(),
|
|
83
|
+
text: null,
|
|
84
|
+
shown: { answer: null, failure: null, kept: held },
|
|
85
|
+
owed: false,
|
|
86
|
+
};
|
|
87
|
+
if (held) {
|
|
88
|
+
read.stored = database.ask({ kind: 'read.stored', ...read.at }).then((text) => {
|
|
89
|
+
if (text === null || read.text !== null)
|
|
90
|
+
return;
|
|
91
|
+
read.text = text;
|
|
92
|
+
read.shown = { ...read.shown, answer: JSON.parse(text) };
|
|
93
|
+
}, () => { });
|
|
94
|
+
}
|
|
95
|
+
reads.set(key, read);
|
|
96
|
+
return read;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
watch(name, input, deliver) {
|
|
100
|
+
const key = JSON.stringify([name, input ?? null]);
|
|
101
|
+
const read = reads.get(key) ?? opened(name, input, key);
|
|
102
|
+
read.observers.add(deliver);
|
|
103
|
+
void read.stored.then(() => {
|
|
104
|
+
if (!read.observers.has(deliver))
|
|
105
|
+
return;
|
|
106
|
+
if (!read.shown.kept)
|
|
107
|
+
forgotten(read);
|
|
108
|
+
deliver(read.shown);
|
|
109
|
+
void ask(read);
|
|
110
|
+
});
|
|
111
|
+
return () => {
|
|
112
|
+
read.observers.delete(deliver);
|
|
113
|
+
if (read.observers.size === 0 && reads.get(key) === read)
|
|
114
|
+
reads.delete(key);
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
again() {
|
|
118
|
+
const all = [...reads.values()];
|
|
119
|
+
const led = Promise.all(all.filter(leads).map((read) => ask(read)));
|
|
120
|
+
for (const read of all)
|
|
121
|
+
if (!leads(read))
|
|
122
|
+
void ask(read, led);
|
|
123
|
+
},
|
|
124
|
+
reopened() {
|
|
125
|
+
for (const read of reads.values()) {
|
|
126
|
+
if (read.text === null) {
|
|
127
|
+
if (read.owed)
|
|
128
|
+
void ask(read);
|
|
129
|
+
}
|
|
130
|
+
else if (read.shown.failure?.kind === 'transport-uncertainty') {
|
|
131
|
+
show(read, { ...read.shown, failure: null });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
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,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ff.attempts) {
|
|
109
|
-
|
|
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);
|
|
110
118
|
return;
|
|
111
119
|
}
|
|
112
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
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,EACb,gBAAgB,EACjB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAG9D,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAE,GACzE;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B,gBAAgB,GAChB,WAAW,GACX,cAAc,CAAC;AAEnB,MAAM,MAAM,SAAS,GAAG,CACtB,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,cAAc,KACpB,OAAO,CAAC,aAAa,CAAC,CAAC;AAE5B,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IACzE,KAAK,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACnF,KAAK,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9C,CAAC;AASF,KAAK,WAAW,GAAG,IAAI,CACrB,WAAW,EACX,WAAW,GAAG,OAAO,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,aAAa,CACxF,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,
|
|
@@ -124,7 +152,7 @@ export async function advancement(adapter, authorization, held, remodel, continu
|
|
|
124
152
|
await staging.turn();
|
|
125
153
|
if (!continuing())
|
|
126
154
|
return unconfirmed;
|
|
127
|
-
const page = await
|
|
155
|
+
const page = await refresh(authorization, {
|
|
128
156
|
locator,
|
|
129
157
|
selection: held.replica.selection,
|
|
130
158
|
fromRoomVersion,
|
package/dist/replica.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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
5
|
import { type ModelState } from './model.js';
|
|
@@ -22,23 +23,22 @@ export type HeldReplica = {
|
|
|
22
23
|
readonly record: ReplicaRecord;
|
|
23
24
|
readonly queue: readonly ChangeBatch[];
|
|
24
25
|
readonly overlaid: ReadonlySet<string>;
|
|
25
|
-
readonly count: number;
|
|
26
|
-
readonly confirmed: number;
|
|
27
|
-
readonly indexed: boolean;
|
|
28
26
|
};
|
|
29
27
|
export type VisibleLayer = Layer & {
|
|
30
28
|
readonly collection: Collection;
|
|
31
29
|
};
|
|
32
30
|
export type Slice = Layer & {
|
|
33
31
|
readonly written: Readonly<Record<string, string>>;
|
|
32
|
+
readonly facts: Readonly<Record<string, SavedFacts>>;
|
|
34
33
|
readonly held: ReadonlySet<string>;
|
|
35
34
|
};
|
|
36
|
-
export declare function compositionOf(record: Pick<ReplicaRecord, 'model' | 'typedSelection'>, builtIn: ModelState): Composition;
|
|
35
|
+
export declare function compositionOf(record: Pick<ReplicaRecord, 'model' | 'typedSelection'>, builtIn: ModelState, typedPaths: readonly TypedPath[]): Composition;
|
|
37
36
|
export declare function storedRecord(record: ReplicaRecord): string;
|
|
38
37
|
export declare function slicing(entries: readonly HeldEntry[], paths: Iterable<string>): Generator<number, Slice, void>;
|
|
38
|
+
export type LayerEntry = Omit<StoredEntry, 'facts'>;
|
|
39
39
|
export declare function entryAt(layer: Layer & {
|
|
40
40
|
readonly written?: Readonly<Record<string, string>>;
|
|
41
|
-
}, path: string):
|
|
41
|
+
}, path: string): LayerEntry | null;
|
|
42
42
|
export declare function slicingWith(slice: Slice, set: readonly StoredEntry[], removed: readonly string[]): Generator<number, Slice, void>;
|
|
43
43
|
export declare function touchedBy(queue: readonly ChangeBatch[]): Set<string>;
|
|
44
44
|
export declare function movedBy(queue: readonly ChangeBatch[], locator: string): Set<string>;
|
|
@@ -47,7 +47,7 @@ export type Replayed = {
|
|
|
47
47
|
readonly touched: ReadonlySet<string>;
|
|
48
48
|
};
|
|
49
49
|
export declare function replaying(confirmed: Slice, queue: readonly ChangeBatch[], locator: string, composition: Composition): Generator<number, Replayed, void>;
|
|
50
|
-
export declare function overlayOf(visible:
|
|
50
|
+
export declare function overlayOf(visible: VisibleLayer, touched: Iterable<string>): Generator<number, OverlayEntry[], void>;
|
|
51
51
|
export declare function holds(layer: Layer, preconditions: readonly Precondition[]): boolean;
|
|
52
52
|
export declare function landed(batch: ChangeBatch, confirmed: Layer, current?: Readonly<Record<string, string>>): boolean;
|
|
53
53
|
export type Standing = {
|
|
@@ -63,6 +63,6 @@ export type Returned = {
|
|
|
63
63
|
readonly removed: readonly string[];
|
|
64
64
|
};
|
|
65
65
|
export declare function returnedPaths(submitted: ChangeBatch, accepted: Accepted): Set<string>;
|
|
66
|
-
export declare function returning(confirmed: Slice, submitted: ChangeBatch, accepted: Accepted, writtenAt: string): Generator<number, Returned, void>;
|
|
66
|
+
export declare function returning(confirmed: Slice, submitted: ChangeBatch, accepted: Accepted, writtenAt: string, composition: Composition): Generator<number, Returned, void>;
|
|
67
67
|
export {};
|
|
68
68
|
//# 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,M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EAAE,OAAO,EACd,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW,GACvB,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CA4BnC;AAED,KAAK,QAAQ,GAAG,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC;AAE9D,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,GAAG,EAAE,SAAS,WAAW,EAAE,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC,CAAC;AAEF,wBAAgB,aAAa,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,CAiBrF;AAED,wBAAiB,SAAS,CACxB,SAAS,EAAE,KAAK,EAChB,SAAS,EAAE,WAAW,EACtB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,WAAW,GACvB,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CA6FnC"}
|
package/dist/replica.js
CHANGED
|
@@ -3,14 +3,16 @@ import { immutable, landing } from './change.js';
|
|
|
3
3
|
import { collectionOf } from './collection.js';
|
|
4
4
|
import { storedModel } from './model.js';
|
|
5
5
|
import { acceptedBinaries, overlaying } from './overlay.js';
|
|
6
|
+
import { writtenFacts } from './rows.js';
|
|
6
7
|
import { effectiveIn, rewriting } from './save.js';
|
|
7
8
|
import { ROW_WEIGHT } from './turn.js';
|
|
8
|
-
export function compositionOf(record, builtIn) {
|
|
9
|
+
export function compositionOf(record, builtIn, typedPaths) {
|
|
9
10
|
return {
|
|
10
11
|
model: record.model,
|
|
11
12
|
selection: record.typedSelection === null
|
|
12
13
|
? null
|
|
13
14
|
: { roots: record.typedSelection.roots, model: builtIn },
|
|
15
|
+
typedPaths,
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
18
|
export function storedRecord(record) {
|
|
@@ -58,9 +60,13 @@ export function* slicing(entries, paths) {
|
|
|
58
60
|
const binaries = {};
|
|
59
61
|
const revisions = {};
|
|
60
62
|
const fileIds = {};
|
|
63
|
+
const created = {};
|
|
61
64
|
const changes = {};
|
|
62
65
|
const written = {};
|
|
66
|
+
const facts = {};
|
|
63
67
|
for (const entry of entries) {
|
|
68
|
+
if (entry.facts !== null)
|
|
69
|
+
facts[entry.path] = entry.facts;
|
|
64
70
|
if (entry.binary !== null)
|
|
65
71
|
binaries[entry.path] = entry.binary;
|
|
66
72
|
else if (entry.content !== null)
|
|
@@ -69,6 +75,8 @@ export function* slicing(entries, paths) {
|
|
|
69
75
|
revisions[entry.path] = entry.revision;
|
|
70
76
|
if (entry.fileId !== null)
|
|
71
77
|
fileIds[entry.path] = entry.fileId;
|
|
78
|
+
if (entry.created !== null)
|
|
79
|
+
created[entry.path] = entry.created;
|
|
72
80
|
if (entry.change !== null)
|
|
73
81
|
changes[entry.path] = entry.change;
|
|
74
82
|
if (entry.written !== null)
|
|
@@ -80,8 +88,10 @@ export function* slicing(entries, paths) {
|
|
|
80
88
|
binaries: strict(binaries, held),
|
|
81
89
|
revisions: strict(revisions, held),
|
|
82
90
|
fileIds: strict(fileIds, held),
|
|
91
|
+
created: strict(created, held),
|
|
83
92
|
changes: strict(changes, held),
|
|
84
93
|
written: strict(written, held),
|
|
94
|
+
facts: strict(facts, held),
|
|
85
95
|
held,
|
|
86
96
|
};
|
|
87
97
|
}
|
|
@@ -96,6 +106,7 @@ export function entryAt(layer, path) {
|
|
|
96
106
|
binary: binary ?? null,
|
|
97
107
|
revision: layer.revisions[path] ?? null,
|
|
98
108
|
fileId: layer.fileIds[path] ?? null,
|
|
109
|
+
created: layer.created[path] ?? null,
|
|
99
110
|
change: layer.changes[path] ?? null,
|
|
100
111
|
written: layer.written?.[path] ?? null,
|
|
101
112
|
};
|
|
@@ -104,8 +115,9 @@ export function* slicingWith(slice, set, removed) {
|
|
|
104
115
|
const entries = new Map();
|
|
105
116
|
for (const path of slice.held) {
|
|
106
117
|
const entry = entryAt(slice, path);
|
|
107
|
-
if (entry !== null)
|
|
108
|
-
entries.set(path, { ...entry, type: null });
|
|
118
|
+
if (entry !== null) {
|
|
119
|
+
entries.set(path, { ...entry, type: null, facts: slice.facts[path] ?? null });
|
|
120
|
+
}
|
|
109
121
|
yield ROW_WEIGHT;
|
|
110
122
|
}
|
|
111
123
|
for (const path of removed)
|
|
@@ -169,8 +181,9 @@ export function* replaying(confirmed, queue, locator, composition) {
|
|
|
169
181
|
export function* overlayOf(visible, touched) {
|
|
170
182
|
const rows = [];
|
|
171
183
|
for (const path of touched) {
|
|
172
|
-
yield ROW_WEIGHT;
|
|
173
184
|
const entry = entryAt(visible, path);
|
|
185
|
+
yield ROW_WEIGHT + (entry?.content?.length ?? 0);
|
|
186
|
+
const text = entry?.binary === null ? entry.content : null;
|
|
174
187
|
rows.push(entry === null
|
|
175
188
|
? {
|
|
176
189
|
path,
|
|
@@ -179,10 +192,17 @@ export function* overlayOf(visible, touched) {
|
|
|
179
192
|
binary: null,
|
|
180
193
|
revision: null,
|
|
181
194
|
fileId: null,
|
|
195
|
+
created: null,
|
|
182
196
|
change: null,
|
|
183
197
|
written: null,
|
|
198
|
+
facts: null,
|
|
184
199
|
}
|
|
185
|
-
: {
|
|
200
|
+
: {
|
|
201
|
+
...entry,
|
|
202
|
+
written: null,
|
|
203
|
+
present: true,
|
|
204
|
+
facts: text === null ? null : writtenFacts(path, text, visible.collection.composition),
|
|
205
|
+
});
|
|
186
206
|
}
|
|
187
207
|
return rows;
|
|
188
208
|
}
|
|
@@ -347,17 +367,20 @@ export function returnedPaths(submitted, accepted) {
|
|
|
347
367
|
}
|
|
348
368
|
return paths;
|
|
349
369
|
}
|
|
350
|
-
export function* returning(confirmed, submitted, accepted, writtenAt) {
|
|
370
|
+
export function* returning(confirmed, submitted, accepted, writtenAt, composition) {
|
|
351
371
|
const documents = new Map();
|
|
352
372
|
const binaries = new Map();
|
|
353
373
|
const revisions = new Map();
|
|
354
374
|
const fileIds = new Map();
|
|
375
|
+
const created = new Map();
|
|
355
376
|
const changes = new Map();
|
|
356
377
|
const written = new Map();
|
|
378
|
+
const facts = new Map();
|
|
357
379
|
const read = (changed, held, path) => (changed.has(path) ? changed.get(path) : held[path]);
|
|
358
380
|
for (const [path, content] of Object.entries(accepted.documents)) {
|
|
359
|
-
yield ROW_WEIGHT;
|
|
381
|
+
yield ROW_WEIGHT + content.length;
|
|
360
382
|
documents.set(path, content);
|
|
383
|
+
facts.set(path, writtenFacts(path, content, composition));
|
|
361
384
|
fileIds.set(path, undefined);
|
|
362
385
|
written.set(path, writtenAt);
|
|
363
386
|
}
|
|
@@ -380,48 +403,60 @@ export function* returning(confirmed, submitted, accepted, writtenAt) {
|
|
|
380
403
|
written.set(path, undefined);
|
|
381
404
|
}
|
|
382
405
|
for (const change of submitted.changes) {
|
|
383
|
-
if (change.kind === 'arrival'
|
|
384
|
-
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)
|
|
385
411
|
binaries.set(change.path, { state: 'accepted', ...change.binary });
|
|
386
|
-
}
|
|
387
412
|
continue;
|
|
388
413
|
}
|
|
389
|
-
if (change.kind !== 'move')
|
|
414
|
+
if (change.kind !== 'move' || accepted.revisions[change.to] === undefined)
|
|
390
415
|
continue;
|
|
416
|
+
created.set(change.to, read(created, confirmed.created, change.path));
|
|
417
|
+
created.set(change.path, undefined);
|
|
391
418
|
const moved = read(binaries, confirmed.binaries, change.path);
|
|
392
|
-
if (moved === undefined
|
|
419
|
+
if (moved === undefined)
|
|
393
420
|
continue;
|
|
394
421
|
binaries.set(change.to, moved);
|
|
395
422
|
binaries.set(change.path, undefined);
|
|
396
423
|
}
|
|
397
424
|
for (const [path, binary] of acceptedBinaries(accepted.binaryFiles ?? {}))
|
|
398
425
|
binaries.set(path, binary);
|
|
399
|
-
for (const path of accepted.removals)
|
|
426
|
+
for (const path of accepted.removals) {
|
|
400
427
|
binaries.set(path, undefined);
|
|
428
|
+
created.set(path, undefined);
|
|
429
|
+
}
|
|
401
430
|
const paths = new Set([
|
|
402
431
|
...documents.keys(),
|
|
403
432
|
...binaries.keys(),
|
|
404
433
|
...revisions.keys(),
|
|
405
434
|
...fileIds.keys(),
|
|
435
|
+
...created.keys(),
|
|
406
436
|
...changes.keys(),
|
|
407
437
|
...written.keys(),
|
|
408
438
|
]);
|
|
409
439
|
const set = [];
|
|
410
440
|
const removed = [];
|
|
411
441
|
for (const path of paths) {
|
|
412
|
-
yield ROW_WEIGHT;
|
|
413
442
|
const content = read(documents, confirmed.documents, path);
|
|
414
443
|
const binary = read(binaries, confirmed.binaries, path);
|
|
444
|
+
yield ROW_WEIGHT;
|
|
415
445
|
if (content === undefined && binary === undefined) {
|
|
416
446
|
removed.push(path);
|
|
417
447
|
continue;
|
|
418
448
|
}
|
|
449
|
+
const text = binary === undefined ? (content ?? null) : null;
|
|
450
|
+
const fresh = confirmed.documents[path] === undefined && confirmed.binaries[path] === undefined;
|
|
419
451
|
set.push({
|
|
420
452
|
path,
|
|
421
|
-
content:
|
|
453
|
+
content: text,
|
|
454
|
+
facts: text === null ? null : (read(facts, confirmed.facts, path) ?? null),
|
|
422
455
|
binary: binary ?? null,
|
|
423
456
|
revision: read(revisions, confirmed.revisions, path) ?? null,
|
|
424
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),
|
|
425
460
|
change: read(changes, confirmed.changes, path) ?? null,
|
|
426
461
|
written: read(written, confirmed.written, path) ?? null,
|
|
427
462
|
});
|