@agentshouse/mdruntime-adapter 0.1.0-c55b0f26f7582 → 0.1.0-c57d433251ca5
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 +286 -209
- package/dist/actions.d.ts +69 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +197 -198
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +392 -113
- package/dist/discovery.d.ts +7 -6
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +50 -18
- package/dist/gather.d.ts +2 -1
- package/dist/gather.d.ts.map +1 -1
- package/dist/gather.js +15 -20
- package/dist/handed.d.ts +15 -0
- package/dist/handed.d.ts.map +1 -0
- package/dist/handed.js +45 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/model.d.ts +1 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +21 -7
- package/dist/part.d.ts +13 -0
- package/dist/part.d.ts.map +1 -0
- package/dist/part.js +80 -0
- package/dist/read.d.ts +54 -16
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +269 -149
- package/dist/referrer.d.ts +7 -0
- package/dist/referrer.d.ts.map +1 -0
- package/dist/referrer.js +33 -0
- package/dist/refusal.d.ts +5 -9
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +31 -17
- package/dist/site.d.ts +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +181 -62
- package/dist/stream.d.ts +6 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +374 -42
- package/dist/transport.d.ts +83 -12
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +3 -1
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/write.d.ts +14 -9
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +161 -43
- package/package.json +3 -4
- package/dist/links.d.ts +0 -20
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -104
package/dist/read.d.ts
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AdapterFailure, type BinaryFile, type BootstrapPage, type RefreshResult, type TransportUncertainty } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
+
import { type HousePart } from './part.js';
|
|
3
4
|
import type { HouseMode } from './transport.js';
|
|
4
5
|
import { type LogPosition } from './version.js';
|
|
5
6
|
export type HeadChange = BootstrapPage['changes'][string];
|
|
7
|
+
export type Answered = {
|
|
8
|
+
readonly documents: Map<string, string>;
|
|
9
|
+
readonly revisions: Map<string, string>;
|
|
10
|
+
readonly fileIds: Map<string, string>;
|
|
11
|
+
readonly changes: Map<string, HeadChange>;
|
|
12
|
+
readonly binaryFiles: Map<string, BinaryFile>;
|
|
13
|
+
readonly removals: Set<string>;
|
|
14
|
+
};
|
|
15
|
+
export declare function answering(): Answered;
|
|
16
|
+
export declare function revised(answer: Answered, path: string, revision: string): void;
|
|
17
|
+
export declare function forgotten(answer: Answered, path: string): void;
|
|
18
|
+
export declare function answered(answer: Answered): Generator<number, {
|
|
19
|
+
documents: Readonly<Record<string, string>>;
|
|
20
|
+
revisions: Readonly<Record<string, string>>;
|
|
21
|
+
fileIds?: Readonly<Record<string, string>>;
|
|
22
|
+
changes: Readonly<Record<string, HeadChange>>;
|
|
23
|
+
binaryFiles: Readonly<Record<string, BinaryFile>>;
|
|
24
|
+
removals: readonly string[];
|
|
25
|
+
}, void>;
|
|
6
26
|
export type HouseManifestFile = {
|
|
7
27
|
path: string;
|
|
8
28
|
revision: string | undefined;
|
|
9
29
|
version: string;
|
|
30
|
+
sha256?: string;
|
|
10
31
|
head?: HeadChange;
|
|
32
|
+
binary?: BinaryFile;
|
|
11
33
|
};
|
|
12
34
|
export type HouseContent = {
|
|
13
35
|
path: string;
|
|
@@ -17,10 +39,14 @@ export type HouseScope = LogPosition & {
|
|
|
17
39
|
anchor: string;
|
|
18
40
|
files: readonly HouseManifestFile[];
|
|
19
41
|
contents: readonly HouseContent[];
|
|
20
|
-
attachments?: readonly RoomAttachment[];
|
|
21
42
|
};
|
|
22
|
-
export type
|
|
23
|
-
|
|
43
|
+
export type HouseRoomParts = LogPosition & {
|
|
44
|
+
anchor: string;
|
|
45
|
+
parts: readonly HousePart[];
|
|
46
|
+
};
|
|
47
|
+
export type HouseParted = {
|
|
48
|
+
rooms: readonly HouseRoomParts[];
|
|
49
|
+
next?: string;
|
|
24
50
|
};
|
|
25
51
|
export type HouseGrant = {
|
|
26
52
|
method: 'GET';
|
|
@@ -41,38 +67,50 @@ export type HouseChange = {
|
|
|
41
67
|
head?: HeadChange;
|
|
42
68
|
} | {
|
|
43
69
|
path: string;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
70
|
+
binary: BinaryFile;
|
|
71
|
+
revision: string | undefined;
|
|
72
|
+
version: string;
|
|
73
|
+
head?: HeadChange;
|
|
74
|
+
};
|
|
75
|
+
export type HousePage = {
|
|
76
|
+
after: string;
|
|
77
|
+
through: string;
|
|
78
|
+
read: number;
|
|
47
79
|
};
|
|
48
80
|
export type HouseView = LogPosition & {
|
|
49
81
|
authority: string;
|
|
50
82
|
changes: readonly HouseChange[];
|
|
51
|
-
|
|
83
|
+
next?: HousePage;
|
|
84
|
+
};
|
|
85
|
+
type PageFailure = AdapterFailure | {
|
|
86
|
+
kind: 'beyond-horizon';
|
|
52
87
|
};
|
|
53
88
|
export type HouseEnumeration = {
|
|
54
89
|
authorities: readonly HouseView[];
|
|
55
90
|
};
|
|
56
91
|
export declare function authorityRoot(handle: string): string;
|
|
57
|
-
export declare function contentPrefixes(tracked: TrackedAuthority): readonly string[];
|
|
58
92
|
export declare function schemaPath(handle: string, schema: string): string;
|
|
59
93
|
export declare function parseGrant(body: unknown): HouseGrant | null;
|
|
60
94
|
export declare function headChange(held: {
|
|
61
95
|
readonly author?: unknown;
|
|
62
96
|
readonly created_at?: unknown;
|
|
63
97
|
}): HeadChange | undefined | null;
|
|
64
|
-
export declare function
|
|
65
|
-
export declare function
|
|
66
|
-
export declare function
|
|
98
|
+
export declare function binaryFileOf(held: Readonly<Record<string, unknown>>): BinaryFile | undefined | null;
|
|
99
|
+
export declare function parseParted(body: unknown): HouseParted | null;
|
|
100
|
+
export declare function parseSiteParted(body: unknown): HouseRoomParts | null;
|
|
101
|
+
export declare function emptyScope(room: HouseRoomParts): HouseScope;
|
|
102
|
+
export declare function housePart(room: HouseRoomParts, body: unknown, listed: HousePart, mode: HouseMode): Promise<HouseScope | TransportUncertainty | null>;
|
|
67
103
|
export declare function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null;
|
|
68
|
-
export declare function
|
|
69
|
-
export declare function
|
|
70
|
-
export declare function
|
|
104
|
+
export declare function wholeView(first: HouseView, more: (page: HousePage) => Promise<HouseView | PageFailure>): Promise<HouseView | PageFailure>;
|
|
105
|
+
export declare function advancedScope(scope: HouseScope, view: HouseView): Generator<number, HouseScope, void>;
|
|
106
|
+
export declare function bootstrapping(scope: HouseScope): Generator<number, BootstrapPage, void>;
|
|
71
107
|
export type HouseSchema = {
|
|
72
108
|
schema: string | null;
|
|
73
109
|
version: string | null;
|
|
110
|
+
revision: string | null;
|
|
74
111
|
};
|
|
75
112
|
export declare function schemaOf(scope: HouseScope, schema: string): HouseSchema | null;
|
|
76
113
|
export declare function viewOf(enumeration: HouseEnumeration, tracked: TrackedAuthority): HouseView | undefined;
|
|
77
|
-
export declare function refreshFrom(view: HouseView, fromRoomVersion: string): RefreshResult
|
|
114
|
+
export declare function refreshFrom(view: HouseView, fromRoomVersion: string): Promise<RefreshResult>;
|
|
115
|
+
export {};
|
|
78
116
|
//# sourceMappingURL=read.d.ts.map
|
package/dist/read.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":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,OAAO,CAAC,SAAS,GAAG,WAAW,CAAC,CA0BlC;AAED,wBAAiB,aAAa,CAC5B,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,GACd,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAqCrC;AAED,wBAAiB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,CAAC,CAiBxF;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAO9E;AAED,wBAAgB,MAAM,CACpB,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,gBAAgB,GACxB,SAAS,GAAG,SAAS,CAEvB;AAsBD,wBAAsB,WAAW,CAC/B,IAAI,EAAE,SAAS,EACf,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,aAAa,CAAC,CAExB"}
|
package/dist/read.js
CHANGED
|
@@ -1,13 +1,52 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { patching, ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { checkedPayload, gunzipped, parsePart } from './part.js';
|
|
3
|
+
import { DECIMAL, readPosition, roomVersion } from './version.js';
|
|
4
|
+
const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
|
|
5
|
+
function fileOf(revision) {
|
|
6
|
+
return REVISION_FILE.exec(revision)?.[1];
|
|
7
|
+
}
|
|
8
|
+
export function answering() {
|
|
9
|
+
return {
|
|
10
|
+
documents: new Map(),
|
|
11
|
+
revisions: new Map(),
|
|
12
|
+
fileIds: new Map(),
|
|
13
|
+
changes: new Map(),
|
|
14
|
+
binaryFiles: new Map(),
|
|
15
|
+
removals: new Set(),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function revised(answer, path, revision) {
|
|
19
|
+
answer.revisions.set(path, revision);
|
|
20
|
+
const file = fileOf(revision);
|
|
21
|
+
if (file !== undefined)
|
|
22
|
+
answer.fileIds.set(path, file);
|
|
23
|
+
}
|
|
24
|
+
export function forgotten(answer, path) {
|
|
25
|
+
answer.documents.delete(path);
|
|
26
|
+
answer.revisions.delete(path);
|
|
27
|
+
answer.fileIds.delete(path);
|
|
28
|
+
answer.changes.delete(path);
|
|
29
|
+
answer.binaryFiles.delete(path);
|
|
30
|
+
answer.removals.delete(path);
|
|
31
|
+
}
|
|
32
|
+
export function* answered(answer) {
|
|
33
|
+
const removals = [];
|
|
34
|
+
for (const path of answer.removals) {
|
|
35
|
+
removals.push(path);
|
|
36
|
+
yield ROW_WEIGHT;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
documents: yield* patching({}, answer.documents),
|
|
40
|
+
revisions: yield* patching({}, answer.revisions),
|
|
41
|
+
...(answer.fileIds.size === 0 ? {} : { fileIds: yield* patching({}, answer.fileIds) }),
|
|
42
|
+
changes: yield* patching({}, answer.changes),
|
|
43
|
+
binaryFiles: yield* patching({}, answer.binaryFiles),
|
|
44
|
+
removals,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
2
47
|
export function authorityRoot(handle) {
|
|
3
48
|
return `/rooms/${handle}`;
|
|
4
49
|
}
|
|
5
|
-
export function contentPrefixes(tracked) {
|
|
6
|
-
return [
|
|
7
|
-
authorityRoot(tracked.handle),
|
|
8
|
-
...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
|
|
9
|
-
];
|
|
10
|
-
}
|
|
11
50
|
export function schemaPath(handle, schema) {
|
|
12
51
|
return `${authorityRoot(handle)}/${schema}`;
|
|
13
52
|
}
|
|
@@ -51,32 +90,19 @@ export function headChange(held) {
|
|
|
51
90
|
function headed(head) {
|
|
52
91
|
return head === undefined ? {} : { head };
|
|
53
92
|
}
|
|
54
|
-
function
|
|
55
|
-
if (
|
|
56
|
-
return
|
|
57
|
-
const {
|
|
58
|
-
if (typeof
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (mediaType !== null && typeof mediaType !== 'string')
|
|
63
|
-
return null;
|
|
64
|
-
return { reference: attachment, name, byteLength: bytes, mediaType, entry: value };
|
|
65
|
-
}
|
|
66
|
-
export function parseOriginals(value) {
|
|
67
|
-
if (!Array.isArray(value))
|
|
93
|
+
export function binaryFileOf(held) {
|
|
94
|
+
if (held.file === undefined)
|
|
95
|
+
return undefined;
|
|
96
|
+
const { file, bytes, media_type: mediaType, sha256 } = held;
|
|
97
|
+
if (typeof file !== 'string' ||
|
|
98
|
+
typeof bytes !== 'number' ||
|
|
99
|
+
typeof mediaType !== 'string' ||
|
|
100
|
+
typeof sha256 !== 'string')
|
|
68
101
|
return null;
|
|
69
|
-
|
|
70
|
-
for (const entry of value) {
|
|
71
|
-
const attachment = parseOriginal(entry);
|
|
72
|
-
if (attachment === null)
|
|
73
|
-
return null;
|
|
74
|
-
attachments.push(attachment);
|
|
75
|
-
}
|
|
76
|
-
return attachments;
|
|
102
|
+
return { fileRef: file, byteLength: bytes, mediaType, sha256 };
|
|
77
103
|
}
|
|
78
|
-
function
|
|
79
|
-
return
|
|
104
|
+
function binaried(binary) {
|
|
105
|
+
return binary === undefined ? {} : { binary };
|
|
80
106
|
}
|
|
81
107
|
function parseFile(value, mode) {
|
|
82
108
|
if (typeof value !== 'object' || value === null)
|
|
@@ -85,24 +111,38 @@ function parseFile(value, mode) {
|
|
|
85
111
|
if (typeof file.path !== 'string')
|
|
86
112
|
return null;
|
|
87
113
|
const head = headChange(file);
|
|
88
|
-
|
|
114
|
+
const binary = binaryFileOf(file);
|
|
115
|
+
if (head === null || binary === null)
|
|
89
116
|
return null;
|
|
90
117
|
if (mode === 'site') {
|
|
91
118
|
if (typeof file.sha256 !== 'string')
|
|
92
119
|
return null;
|
|
93
|
-
return {
|
|
120
|
+
return {
|
|
121
|
+
path: file.path,
|
|
122
|
+
revision: binary?.sha256,
|
|
123
|
+
version: file.sha256,
|
|
124
|
+
...headed(head),
|
|
125
|
+
...binaried(binary),
|
|
126
|
+
};
|
|
94
127
|
}
|
|
95
128
|
if (typeof file.revision !== 'string')
|
|
96
129
|
return null;
|
|
97
|
-
return {
|
|
130
|
+
return {
|
|
131
|
+
path: file.path,
|
|
132
|
+
revision: file.revision,
|
|
133
|
+
version: file.revision,
|
|
134
|
+
...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
|
|
135
|
+
...headed(head),
|
|
136
|
+
...binaried(binary),
|
|
137
|
+
};
|
|
98
138
|
}
|
|
99
|
-
function
|
|
139
|
+
function parseRoomParts(value) {
|
|
100
140
|
if (typeof value !== 'object' || value === null)
|
|
101
141
|
return null;
|
|
102
142
|
const held = value;
|
|
103
143
|
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
104
144
|
return null;
|
|
105
|
-
if (!Array.isArray(held.
|
|
145
|
+
if (!Array.isArray(held.parts))
|
|
106
146
|
return null;
|
|
107
147
|
const manifest = held.manifest;
|
|
108
148
|
if (manifest.scope !== 'room')
|
|
@@ -112,47 +152,89 @@ function parseScope(value, mode) {
|
|
|
112
152
|
return null;
|
|
113
153
|
if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
|
|
114
154
|
return null;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const file = parseFile(entry, mode);
|
|
120
|
-
if (file === null)
|
|
121
|
-
return null;
|
|
122
|
-
files.push(file);
|
|
123
|
-
}
|
|
124
|
-
const contents = [];
|
|
125
|
-
for (const entry of held.contents) {
|
|
126
|
-
if (typeof entry !== 'object' || entry === null)
|
|
127
|
-
return null;
|
|
128
|
-
const content = entry;
|
|
129
|
-
if (typeof content.path !== 'string' || typeof content.content !== 'string')
|
|
155
|
+
const parts = [];
|
|
156
|
+
for (const entry of held.parts) {
|
|
157
|
+
const part = parsePart(entry);
|
|
158
|
+
if (part === null)
|
|
130
159
|
return null;
|
|
131
|
-
|
|
160
|
+
parts.push(part);
|
|
132
161
|
}
|
|
133
|
-
|
|
134
|
-
return { anchor: manifest.anchor, ...at, files, contents };
|
|
135
|
-
const attachments = parseOriginals(held.originals);
|
|
136
|
-
if (attachments === null)
|
|
137
|
-
return null;
|
|
138
|
-
return { anchor: manifest.anchor, ...at, files, contents, attachments };
|
|
162
|
+
return { anchor: manifest.anchor, ...at, parts };
|
|
139
163
|
}
|
|
140
|
-
export function
|
|
164
|
+
export function parseParted(body) {
|
|
141
165
|
if (typeof body !== 'object' || body === null)
|
|
142
166
|
return null;
|
|
143
167
|
if (!('scopes' in body) || !Array.isArray(body.scopes))
|
|
144
168
|
return null;
|
|
145
|
-
const
|
|
169
|
+
const rooms = [];
|
|
146
170
|
for (const entry of body.scopes) {
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
171
|
+
const room = parseRoomParts(entry);
|
|
172
|
+
if (room === null)
|
|
149
173
|
return null;
|
|
150
|
-
|
|
174
|
+
rooms.push(room);
|
|
151
175
|
}
|
|
152
|
-
|
|
176
|
+
if (!('next' in body) || body.next === undefined)
|
|
177
|
+
return { rooms };
|
|
178
|
+
const next = body.next;
|
|
179
|
+
if (typeof next !== 'object' || next === null || typeof next.room !== 'string')
|
|
180
|
+
return null;
|
|
181
|
+
return { rooms, next: next.room };
|
|
182
|
+
}
|
|
183
|
+
export function parseSiteParted(body) {
|
|
184
|
+
return parseRoomParts(body);
|
|
153
185
|
}
|
|
154
|
-
export function
|
|
155
|
-
return
|
|
186
|
+
export function emptyScope(room) {
|
|
187
|
+
return {
|
|
188
|
+
anchor: room.anchor,
|
|
189
|
+
position: room.position,
|
|
190
|
+
logEpoch: room.logEpoch,
|
|
191
|
+
files: [],
|
|
192
|
+
contents: [],
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function* partLines(text, mode) {
|
|
196
|
+
const files = [];
|
|
197
|
+
const contents = [];
|
|
198
|
+
let start = 0;
|
|
199
|
+
while (start < text.length) {
|
|
200
|
+
const end = text.indexOf('\n', start);
|
|
201
|
+
if (end === -1)
|
|
202
|
+
return null;
|
|
203
|
+
let entry;
|
|
204
|
+
try {
|
|
205
|
+
entry = JSON.parse(text.slice(start, end));
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
start = end + 1;
|
|
211
|
+
if (folderLine(entry))
|
|
212
|
+
continue;
|
|
213
|
+
const file = parseFile(entry, mode);
|
|
214
|
+
if (file === null)
|
|
215
|
+
return null;
|
|
216
|
+
files.push(file);
|
|
217
|
+
const { content } = entry;
|
|
218
|
+
if (typeof content === 'string')
|
|
219
|
+
contents.push({ path: file.path, content });
|
|
220
|
+
else if (content !== undefined)
|
|
221
|
+
return null;
|
|
222
|
+
yield ROW_WEIGHT;
|
|
223
|
+
}
|
|
224
|
+
return { files, contents };
|
|
225
|
+
}
|
|
226
|
+
function folderLine(entry) {
|
|
227
|
+
if (typeof entry !== 'object' || entry === null || !('folder' in entry))
|
|
228
|
+
return false;
|
|
229
|
+
return typeof entry.folder === 'string' && Object.keys(entry).length === 1;
|
|
230
|
+
}
|
|
231
|
+
export async function housePart(room, body, listed, mode) {
|
|
232
|
+
const payload = await checkedPayload(body, listed);
|
|
233
|
+
if (payload === null)
|
|
234
|
+
return null;
|
|
235
|
+
const text = await gunzipped(payload);
|
|
236
|
+
const read = text === null ? null : await stepped(partLines(text, mode));
|
|
237
|
+
return read === null ? { kind: 'transport-uncertainty' } : { ...emptyScope(room), ...read };
|
|
156
238
|
}
|
|
157
239
|
function parseChange(value, mode) {
|
|
158
240
|
if (typeof value !== 'object' || value === null)
|
|
@@ -163,8 +245,15 @@ function parseChange(value, mode) {
|
|
|
163
245
|
if (held.removed === true)
|
|
164
246
|
return { path: held.path, removed: true };
|
|
165
247
|
const head = headChange(held);
|
|
166
|
-
|
|
248
|
+
const binary = binaryFileOf(held);
|
|
249
|
+
if (head === null || binary === null)
|
|
167
250
|
return null;
|
|
251
|
+
if (binary !== undefined) {
|
|
252
|
+
if (mode === 'credential' && typeof held.revision !== 'string')
|
|
253
|
+
return null;
|
|
254
|
+
const revision = typeof held.revision === 'string' ? held.revision : binary.sha256;
|
|
255
|
+
return { path: held.path, binary, revision, version: revision, ...headed(head) };
|
|
256
|
+
}
|
|
168
257
|
if (mode === 'site') {
|
|
169
258
|
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
170
259
|
return null;
|
|
@@ -185,12 +274,6 @@ function parseChange(value, mode) {
|
|
|
185
274
|
...headed(head),
|
|
186
275
|
};
|
|
187
276
|
}
|
|
188
|
-
if (typeof held.reference === 'object' && held.reference !== null) {
|
|
189
|
-
const reference = held.reference;
|
|
190
|
-
if (typeof reference.revision !== 'string')
|
|
191
|
-
return null;
|
|
192
|
-
return { path: held.path, reference: { revision: reference.revision } };
|
|
193
|
-
}
|
|
194
277
|
return null;
|
|
195
278
|
}
|
|
196
279
|
export function parseEnumeration(body, mode) {
|
|
@@ -215,118 +298,155 @@ export function parseEnumeration(body, mode) {
|
|
|
215
298
|
return null;
|
|
216
299
|
changes.push(mapped);
|
|
217
300
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
const attachments = parseOriginals(held.originals);
|
|
223
|
-
if (attachments === null)
|
|
301
|
+
const next = held.next === undefined ? undefined : readPage(held.next);
|
|
302
|
+
if (next === null)
|
|
224
303
|
return null;
|
|
225
|
-
authorities.push({
|
|
304
|
+
authorities.push({
|
|
305
|
+
authority: held.authority,
|
|
306
|
+
...at,
|
|
307
|
+
changes,
|
|
308
|
+
...(next === undefined ? {} : { next }),
|
|
309
|
+
});
|
|
226
310
|
}
|
|
227
311
|
return { authorities };
|
|
228
312
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
313
|
+
function readPage(held) {
|
|
314
|
+
if (typeof held !== 'object' || held === null)
|
|
315
|
+
return null;
|
|
316
|
+
const { after, through, read } = held;
|
|
317
|
+
if (typeof after !== 'string' || !DECIMAL.test(after))
|
|
318
|
+
return null;
|
|
319
|
+
if (typeof through !== 'string' || !DECIMAL.test(through))
|
|
320
|
+
return null;
|
|
321
|
+
if (typeof read !== 'number' || !Number.isSafeInteger(read) || read < 0)
|
|
322
|
+
return null;
|
|
323
|
+
return { after, through, read };
|
|
324
|
+
}
|
|
325
|
+
function advances(asked, next) {
|
|
326
|
+
const moved = BigInt(next.through) - BigInt(asked.through);
|
|
327
|
+
return moved > 0n || (moved === 0n && next.after === asked.after && next.read > asked.read);
|
|
328
|
+
}
|
|
329
|
+
export async function wholeView(first, more) {
|
|
330
|
+
const changes = new Map(first.changes.map((change) => [change.path, change]));
|
|
331
|
+
let view = first;
|
|
332
|
+
while (view.next !== undefined) {
|
|
333
|
+
const asked = view.next;
|
|
334
|
+
const page = await more(asked);
|
|
335
|
+
if ('kind' in page)
|
|
336
|
+
return page;
|
|
337
|
+
if (page.position !== asked.through ||
|
|
338
|
+
page.logEpoch !== first.logEpoch ||
|
|
339
|
+
(page.next !== undefined && !advances(asked, page.next))) {
|
|
340
|
+
return { kind: 'transport-uncertainty' };
|
|
341
|
+
}
|
|
342
|
+
for (const change of page.changes) {
|
|
343
|
+
changes.delete(change.path);
|
|
344
|
+
changes.set(change.path, change);
|
|
345
|
+
}
|
|
346
|
+
view = page;
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
authority: first.authority,
|
|
350
|
+
position: view.position,
|
|
351
|
+
logEpoch: first.logEpoch,
|
|
352
|
+
changes: [...changes.values()],
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
export function* advancedScope(scope, view) {
|
|
356
|
+
const files = new Map();
|
|
357
|
+
for (const file of scope.files) {
|
|
358
|
+
files.set(file.path, file);
|
|
359
|
+
yield ROW_WEIGHT;
|
|
360
|
+
}
|
|
361
|
+
const contents = new Map();
|
|
362
|
+
for (const entry of scope.contents) {
|
|
363
|
+
contents.set(entry.path, entry.content);
|
|
364
|
+
yield ROW_WEIGHT;
|
|
365
|
+
}
|
|
232
366
|
for (const change of view.changes) {
|
|
233
367
|
files.delete(change.path);
|
|
234
368
|
contents.delete(change.path);
|
|
369
|
+
yield ROW_WEIGHT;
|
|
235
370
|
if ('removed' in change)
|
|
236
371
|
continue;
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
372
|
+
files.set(change.path, {
|
|
373
|
+
path: change.path,
|
|
374
|
+
revision: change.revision,
|
|
375
|
+
version: change.version,
|
|
376
|
+
...headed(change.head),
|
|
377
|
+
...('binary' in change ? { binary: change.binary } : {}),
|
|
378
|
+
});
|
|
379
|
+
if ('content' in change)
|
|
244
380
|
contents.set(change.path, change.content);
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
381
|
+
}
|
|
382
|
+
const listed = [];
|
|
383
|
+
for (const [path, content] of contents) {
|
|
384
|
+
listed.push({ path, content });
|
|
385
|
+
yield ROW_WEIGHT;
|
|
249
386
|
}
|
|
250
387
|
return {
|
|
251
388
|
...scope,
|
|
252
389
|
position: view.position,
|
|
253
390
|
logEpoch: view.logEpoch,
|
|
254
391
|
files: [...files.values()],
|
|
255
|
-
contents:
|
|
392
|
+
contents: listed,
|
|
256
393
|
};
|
|
257
394
|
}
|
|
258
|
-
export function
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
const changes = {};
|
|
266
|
-
const binaryTargets = [];
|
|
395
|
+
export function* bootstrapping(scope) {
|
|
396
|
+
const contents = new Map();
|
|
397
|
+
for (const entry of scope.contents) {
|
|
398
|
+
contents.set(entry.path, entry.content);
|
|
399
|
+
yield ROW_WEIGHT;
|
|
400
|
+
}
|
|
401
|
+
const answer = answering();
|
|
267
402
|
for (const file of scope.files) {
|
|
268
|
-
|
|
269
|
-
revisions[file.path] = file.revision;
|
|
403
|
+
yield ROW_WEIGHT;
|
|
270
404
|
if (file.head !== undefined)
|
|
271
|
-
changes
|
|
405
|
+
answer.changes.set(file.path, file.head);
|
|
272
406
|
const content = contents.get(file.path);
|
|
273
|
-
if (
|
|
274
|
-
|
|
275
|
-
else
|
|
276
|
-
documents
|
|
407
|
+
if (file.binary !== undefined)
|
|
408
|
+
answer.binaryFiles.set(file.path, file.binary);
|
|
409
|
+
else if (content !== undefined)
|
|
410
|
+
answer.documents.set(file.path, content);
|
|
411
|
+
if (file.revision !== undefined)
|
|
412
|
+
revised(answer, file.path, file.revision);
|
|
277
413
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
roomVersion: roomVersion(scope),
|
|
281
|
-
documents,
|
|
282
|
-
revisions,
|
|
283
|
-
changes,
|
|
284
|
-
binaryTargets: binaryTargets.sort(),
|
|
285
|
-
...declared(scope.attachments),
|
|
286
|
-
};
|
|
414
|
+
const { removals: _removals, ...page } = yield* answered(answer);
|
|
415
|
+
return { kind: 'bootstrap', roomVersion: roomVersion(scope), ...page };
|
|
287
416
|
}
|
|
288
417
|
export function schemaOf(scope, schema) {
|
|
289
418
|
const file = scope.files.find((entry) => entry.path === schema);
|
|
290
419
|
if (file === undefined)
|
|
291
|
-
return { schema: null, version: null };
|
|
420
|
+
return { schema: null, version: null, revision: null };
|
|
292
421
|
const content = scope.contents.find((entry) => entry.path === schema);
|
|
293
|
-
return content === undefined
|
|
422
|
+
return content === undefined
|
|
423
|
+
? null
|
|
424
|
+
: { schema: content.content, version: file.version, revision: file.revision ?? null };
|
|
294
425
|
}
|
|
295
426
|
export function viewOf(enumeration, tracked) {
|
|
296
427
|
return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
|
|
297
428
|
}
|
|
298
|
-
|
|
429
|
+
function* refreshing(view, fromRoomVersion) {
|
|
299
430
|
if (roomVersion(view) === fromRoomVersion)
|
|
300
431
|
return { kind: 'still-current' };
|
|
301
|
-
const
|
|
302
|
-
const revisions = {};
|
|
303
|
-
const changes = {};
|
|
304
|
-
const binaryTargets = [];
|
|
305
|
-
const removals = [];
|
|
432
|
+
const answer = answering();
|
|
306
433
|
for (const change of view.changes) {
|
|
434
|
+
yield ROW_WEIGHT;
|
|
307
435
|
if ('removed' in change) {
|
|
308
|
-
removals.
|
|
436
|
+
answer.removals.add(change.path);
|
|
309
437
|
continue;
|
|
310
438
|
}
|
|
311
|
-
if ('content' in change)
|
|
312
|
-
documents
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
binaryTargets.push(change.path);
|
|
320
|
-
revisions[change.path] = change.reference.revision;
|
|
439
|
+
if ('content' in change)
|
|
440
|
+
answer.documents.set(change.path, change.content);
|
|
441
|
+
else
|
|
442
|
+
answer.binaryFiles.set(change.path, change.binary);
|
|
443
|
+
if (change.head !== undefined)
|
|
444
|
+
answer.changes.set(change.path, change.head);
|
|
445
|
+
if (change.revision !== undefined)
|
|
446
|
+
revised(answer, change.path, change.revision);
|
|
321
447
|
}
|
|
322
|
-
return {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
revisions,
|
|
327
|
-
changes,
|
|
328
|
-
binaryTargets: binaryTargets.sort(),
|
|
329
|
-
removals: removals.sort(),
|
|
330
|
-
...declared(view.attachments),
|
|
331
|
-
};
|
|
448
|
+
return { kind: 'net-advancement', roomVersion: roomVersion(view), ...(yield* answered(answer)) };
|
|
449
|
+
}
|
|
450
|
+
export async function refreshFrom(view, fromRoomVersion) {
|
|
451
|
+
return stepped(refreshing(view, fromRoomVersion));
|
|
332
452
|
}
|