@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c023d3564cb7c
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 +312 -74
- package/README.md +32 -0
- package/dist/actions.d.ts +57 -13
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +274 -397
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +525 -216
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +27 -36
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +173 -228
- package/dist/gather.d.ts +4 -0
- package/dist/gather.d.ts.map +1 -0
- package/dist/gather.js +35 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/map.d.ts +2 -2
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +6 -7
- package/dist/model.d.ts +7 -18
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +60 -57
- package/dist/part.d.ts +15 -0
- package/dist/part.d.ts.map +1 -0
- package/dist/part.js +85 -0
- package/dist/read.d.ts +93 -35
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +415 -245
- package/dist/refusal.d.ts +5 -7
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +47 -68
- package/dist/room-types.d.ts +6 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +66 -0
- package/dist/site.d.ts +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +219 -161
- package/dist/stream.d.ts +18 -6
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +556 -214
- package/dist/transport.d.ts +131 -38
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +4 -3
- package/dist/upload.d.ts +12 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +52 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +32 -18
- package/dist/write.d.ts +18 -8
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +259 -228
- package/package.json +4 -13
- package/dist/actions.js.map +0 -1
- package/dist/adapter.js.map +0 -1
- package/dist/digest.js.map +0 -1
- package/dist/discovery.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/map.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/read.js.map +0 -1
- package/dist/refusal.js.map +0 -1
- package/dist/site.js.map +0 -1
- package/dist/stream.js.map +0 -1
- package/dist/transport.js.map +0 -1
- package/dist/version.js.map +0 -1
- package/dist/write.js.map +0 -1
package/dist/read.js
CHANGED
|
@@ -1,128 +1,333 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
folders: new Set(),
|
|
17
|
+
folderRemovals: new Set(),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function revised(answer, path, revision) {
|
|
21
|
+
answer.revisions.set(path, revision);
|
|
22
|
+
const file = fileOf(revision);
|
|
23
|
+
if (file !== undefined)
|
|
24
|
+
answer.fileIds.set(path, file);
|
|
25
|
+
}
|
|
26
|
+
export function forgotten(answer, path) {
|
|
27
|
+
answer.documents.delete(path);
|
|
28
|
+
answer.revisions.delete(path);
|
|
29
|
+
answer.fileIds.delete(path);
|
|
30
|
+
answer.changes.delete(path);
|
|
31
|
+
answer.binaryFiles.delete(path);
|
|
32
|
+
answer.removals.delete(path);
|
|
33
|
+
}
|
|
34
|
+
export function folded(answer, path, removed) {
|
|
35
|
+
if (removed) {
|
|
36
|
+
answer.folders.delete(path);
|
|
37
|
+
answer.folderRemovals.add(path);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
answer.folderRemovals.delete(path);
|
|
41
|
+
answer.folders.add(path);
|
|
13
42
|
}
|
|
14
|
-
return [
|
|
15
|
-
ROOM_README,
|
|
16
|
-
tracked.collectionRoot
|
|
17
|
-
];
|
|
18
43
|
}
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
44
|
+
function* pathsOf(paths) {
|
|
45
|
+
const list = [];
|
|
46
|
+
for (const path of paths) {
|
|
47
|
+
list.push(path);
|
|
48
|
+
yield ROW_WEIGHT;
|
|
49
|
+
}
|
|
50
|
+
return list;
|
|
51
|
+
}
|
|
52
|
+
export function* answered(answer) {
|
|
53
|
+
const removals = yield* pathsOf(answer.removals);
|
|
54
|
+
return {
|
|
55
|
+
documents: yield* patching({}, answer.documents),
|
|
56
|
+
revisions: yield* patching({}, answer.revisions),
|
|
57
|
+
...(answer.fileIds.size === 0 ? {} : { fileIds: yield* patching({}, answer.fileIds) }),
|
|
58
|
+
changes: yield* patching({}, answer.changes),
|
|
59
|
+
binaryFiles: yield* patching({}, answer.binaryFiles),
|
|
60
|
+
removals,
|
|
61
|
+
...(answer.folders.size === 0 ? {} : { folders: yield* pathsOf(answer.folders) }),
|
|
62
|
+
...(answer.folderRemovals.size === 0
|
|
63
|
+
? {}
|
|
64
|
+
: { folderRemovals: yield* pathsOf(answer.folderRemovals) }),
|
|
65
|
+
};
|
|
22
66
|
}
|
|
23
|
-
export function
|
|
24
|
-
return
|
|
67
|
+
export function authorityRoot(handle) {
|
|
68
|
+
return `/rooms/${handle}`;
|
|
69
|
+
}
|
|
70
|
+
export function schemaPath(handle, schema) {
|
|
71
|
+
return `${authorityRoot(handle)}/${schema}`;
|
|
25
72
|
}
|
|
26
73
|
export function parseGrant(body) {
|
|
27
|
-
if (typeof body !== 'object' || body === null)
|
|
74
|
+
if (typeof body !== 'object' || body === null)
|
|
75
|
+
return null;
|
|
28
76
|
if (!('transfer' in body) || typeof body.transfer !== 'object' || body.transfer === null) {
|
|
29
77
|
return null;
|
|
30
78
|
}
|
|
31
79
|
const transfer = body.transfer;
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
80
|
+
if (typeof transfer.url !== 'string')
|
|
81
|
+
return null;
|
|
82
|
+
if (transfer.method !== 'POST' || typeof transfer.operation !== 'string')
|
|
83
|
+
return null;
|
|
84
|
+
return { operation: transfer.operation, url: transfer.url };
|
|
85
|
+
}
|
|
86
|
+
export function parseFileAddress(body) {
|
|
87
|
+
if (typeof body !== 'object' || body === null)
|
|
88
|
+
return null;
|
|
89
|
+
const { download, name, sha256, media_type: mediaType } = body;
|
|
90
|
+
if (typeof download !== 'string' ||
|
|
91
|
+
typeof name !== 'string' ||
|
|
92
|
+
typeof sha256 !== 'string' ||
|
|
93
|
+
typeof mediaType !== 'string') {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return { url: download, name, sha256, mediaType };
|
|
97
|
+
}
|
|
98
|
+
function changeAuthor(value) {
|
|
99
|
+
if (typeof value !== 'object' || value === null)
|
|
100
|
+
return null;
|
|
101
|
+
const { user, site, inbox, name } = value;
|
|
102
|
+
if (typeof name !== 'string')
|
|
103
|
+
return null;
|
|
104
|
+
const named = [user, site, inbox].filter((id) => id !== undefined);
|
|
105
|
+
if (named.length !== 1)
|
|
106
|
+
return null;
|
|
107
|
+
if (typeof user === 'string')
|
|
108
|
+
return { kind: 'user', id: user, name };
|
|
109
|
+
if (typeof site === 'string')
|
|
110
|
+
return { kind: 'site', id: site, name };
|
|
111
|
+
if (typeof inbox === 'string')
|
|
112
|
+
return { kind: 'inbox', id: inbox, name };
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
export function headChange(held) {
|
|
116
|
+
const author = held.author === undefined ? null : changeAuthor(held.author);
|
|
117
|
+
if (held.author !== undefined && author === null)
|
|
118
|
+
return null;
|
|
119
|
+
if (held.created_at === undefined)
|
|
120
|
+
return undefined;
|
|
121
|
+
if (typeof held.created_at !== 'string')
|
|
122
|
+
return null;
|
|
123
|
+
return { author, time: held.created_at };
|
|
124
|
+
}
|
|
125
|
+
function headed(head) {
|
|
126
|
+
return head === undefined ? {} : { head };
|
|
127
|
+
}
|
|
128
|
+
export function binaryFileOf(held) {
|
|
129
|
+
if (held.media_type === undefined)
|
|
130
|
+
return undefined;
|
|
131
|
+
const { bytes, media_type: mediaType, sha256 } = held;
|
|
132
|
+
if (typeof bytes !== 'number' || typeof mediaType !== 'string' || typeof sha256 !== 'string')
|
|
133
|
+
return null;
|
|
134
|
+
return { byteLength: bytes, mediaType, sha256 };
|
|
135
|
+
}
|
|
136
|
+
function binaried(binary) {
|
|
137
|
+
return binary === undefined ? {} : { binary };
|
|
39
138
|
}
|
|
40
139
|
function parseFile(value, mode) {
|
|
41
|
-
if (typeof value !== 'object' || value === null)
|
|
140
|
+
if (typeof value !== 'object' || value === null)
|
|
141
|
+
return null;
|
|
42
142
|
const file = value;
|
|
43
|
-
if (typeof file.path !== 'string')
|
|
143
|
+
if (typeof file.path !== 'string')
|
|
144
|
+
return null;
|
|
145
|
+
const head = headChange(file);
|
|
146
|
+
const binary = binaryFileOf(file);
|
|
147
|
+
if (head === null || binary === null)
|
|
148
|
+
return null;
|
|
44
149
|
if (mode === 'site') {
|
|
45
|
-
if (typeof file.sha256 !== 'string')
|
|
150
|
+
if (typeof file.sha256 !== 'string')
|
|
151
|
+
return null;
|
|
46
152
|
return {
|
|
47
153
|
path: file.path,
|
|
48
|
-
revision:
|
|
49
|
-
version: file.sha256
|
|
154
|
+
revision: binary?.sha256,
|
|
155
|
+
version: file.sha256,
|
|
156
|
+
...headed(head),
|
|
157
|
+
...binaried(binary),
|
|
50
158
|
};
|
|
51
159
|
}
|
|
52
|
-
if (typeof file.revision !== 'string')
|
|
160
|
+
if (typeof file.revision !== 'string')
|
|
161
|
+
return null;
|
|
53
162
|
return {
|
|
54
163
|
path: file.path,
|
|
55
164
|
revision: file.revision,
|
|
56
|
-
version: file.revision
|
|
165
|
+
version: file.revision,
|
|
166
|
+
...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
|
|
167
|
+
...headed(head),
|
|
168
|
+
...binaried(binary),
|
|
57
169
|
};
|
|
58
170
|
}
|
|
59
|
-
function
|
|
60
|
-
if (typeof value !== 'object' || value === null)
|
|
171
|
+
function parseRoomParts(value) {
|
|
172
|
+
if (typeof value !== 'object' || value === null)
|
|
173
|
+
return null;
|
|
61
174
|
const held = value;
|
|
62
|
-
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
63
|
-
|
|
175
|
+
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
176
|
+
return null;
|
|
177
|
+
if (!Array.isArray(held.parts))
|
|
178
|
+
return null;
|
|
64
179
|
const manifest = held.manifest;
|
|
65
|
-
if (manifest.scope !== 'room'
|
|
180
|
+
if (manifest.scope !== 'room')
|
|
181
|
+
return null;
|
|
66
182
|
const at = readPosition(manifest);
|
|
67
|
-
if (typeof manifest.anchor !== 'string' || at === null)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
183
|
+
if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)
|
|
184
|
+
return null;
|
|
185
|
+
if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
|
|
186
|
+
return null;
|
|
187
|
+
const parts = [];
|
|
188
|
+
for (const entry of held.parts) {
|
|
189
|
+
const part = parsePart(entry);
|
|
190
|
+
if (part === null)
|
|
191
|
+
return null;
|
|
192
|
+
parts.push(part);
|
|
74
193
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
194
|
+
return { anchor: manifest.anchor, ...at, parts };
|
|
195
|
+
}
|
|
196
|
+
export function parseParted(body) {
|
|
197
|
+
if (typeof body !== 'object' || body === null)
|
|
198
|
+
return null;
|
|
199
|
+
if (!('scopes' in body) || !Array.isArray(body.scopes))
|
|
200
|
+
return null;
|
|
201
|
+
const rooms = [];
|
|
202
|
+
for (const entry of body.scopes) {
|
|
203
|
+
const room = parseRoomParts(entry);
|
|
204
|
+
if (room === null)
|
|
205
|
+
return null;
|
|
206
|
+
rooms.push(room);
|
|
84
207
|
}
|
|
208
|
+
if (!('next' in body) || body.next === undefined)
|
|
209
|
+
return { rooms };
|
|
210
|
+
const next = body.next;
|
|
211
|
+
if (typeof next !== 'object' || next === null || typeof next.room !== 'string')
|
|
212
|
+
return null;
|
|
213
|
+
return { rooms, next: next.room };
|
|
214
|
+
}
|
|
215
|
+
export function parseSiteParted(body) {
|
|
216
|
+
return parseRoomParts(body);
|
|
217
|
+
}
|
|
218
|
+
export function partInventory(room) {
|
|
85
219
|
return {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
roomHandle: typeof manifest.room_handle === 'string' ? manifest.room_handle : undefined,
|
|
89
|
-
...at,
|
|
90
|
-
files,
|
|
91
|
-
contents
|
|
220
|
+
parts: room.parts.length,
|
|
221
|
+
bytes: room.parts.reduce((sum, part) => sum + part.bytes, 0),
|
|
92
222
|
};
|
|
93
223
|
}
|
|
94
|
-
export function
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
224
|
+
export function manifested(room, inventory, pageToken) {
|
|
225
|
+
return {
|
|
226
|
+
kind: 'bootstrap',
|
|
227
|
+
roomVersion: roomVersion(room),
|
|
228
|
+
documents: {},
|
|
229
|
+
revisions: {},
|
|
230
|
+
changes: {},
|
|
231
|
+
binaryFiles: {},
|
|
232
|
+
inventory,
|
|
233
|
+
pageToken,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
export function emptyScope(room) {
|
|
103
237
|
return {
|
|
104
|
-
|
|
238
|
+
anchor: room.anchor,
|
|
239
|
+
position: room.position,
|
|
240
|
+
logEpoch: room.logEpoch,
|
|
241
|
+
files: [],
|
|
242
|
+
contents: [],
|
|
105
243
|
};
|
|
106
244
|
}
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
245
|
+
function* partLines(text, mode) {
|
|
246
|
+
const files = [];
|
|
247
|
+
const contents = [];
|
|
248
|
+
const folders = [];
|
|
249
|
+
let start = 0;
|
|
250
|
+
while (start < text.length) {
|
|
251
|
+
const end = text.indexOf('\n', start);
|
|
252
|
+
if (end === -1)
|
|
253
|
+
return null;
|
|
254
|
+
let entry;
|
|
255
|
+
try {
|
|
256
|
+
entry = JSON.parse(text.slice(start, end));
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
start = end + 1;
|
|
262
|
+
if (folderLine(entry)) {
|
|
263
|
+
folders.push(entry.folder);
|
|
264
|
+
yield ROW_WEIGHT;
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
const file = parseFile(entry, mode);
|
|
268
|
+
if (file === null)
|
|
269
|
+
return null;
|
|
270
|
+
files.push(file);
|
|
271
|
+
const { content } = entry;
|
|
272
|
+
if (typeof content === 'string')
|
|
273
|
+
contents.push({ path: file.path, content });
|
|
274
|
+
else if (content !== undefined)
|
|
275
|
+
return null;
|
|
276
|
+
yield ROW_WEIGHT;
|
|
277
|
+
}
|
|
278
|
+
return { files, contents, folders };
|
|
279
|
+
}
|
|
280
|
+
function folderLine(entry) {
|
|
281
|
+
if (typeof entry !== 'object' || entry === null || !('folder' in entry))
|
|
282
|
+
return false;
|
|
283
|
+
return typeof entry.folder === 'string' && Object.keys(entry).length === 1;
|
|
284
|
+
}
|
|
285
|
+
export async function housePart(room, frame, listed, mode) {
|
|
286
|
+
const payload = await checkedPayload(frame, listed);
|
|
287
|
+
if (payload === null)
|
|
288
|
+
return null;
|
|
289
|
+
const text = await gunzipped(payload);
|
|
290
|
+
const read = text === null ? null : await stepped(partLines(text, mode));
|
|
291
|
+
return read === null ? { kind: 'transport-uncertainty' } : { ...emptyScope(room), ...read };
|
|
292
|
+
}
|
|
293
|
+
function folderChange(value) {
|
|
294
|
+
if (typeof value !== 'object' || value === null)
|
|
295
|
+
return null;
|
|
296
|
+
const { path, folder, removed, ...rest } = value;
|
|
297
|
+
return typeof path === 'string' &&
|
|
298
|
+
folder === true &&
|
|
299
|
+
(removed === undefined || removed === true) &&
|
|
300
|
+
Object.keys(rest).length === 0
|
|
301
|
+
? { path, removed: removed === true }
|
|
302
|
+
: null;
|
|
110
303
|
}
|
|
111
304
|
function parseChange(value, mode) {
|
|
112
|
-
if (typeof value !== 'object' || value === null)
|
|
305
|
+
if (typeof value !== 'object' || value === null)
|
|
306
|
+
return null;
|
|
113
307
|
const held = value;
|
|
114
|
-
if (typeof held.path !== 'string')
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
removed: true
|
|
118
|
-
|
|
308
|
+
if (typeof held.path !== 'string')
|
|
309
|
+
return null;
|
|
310
|
+
if (held.removed === true)
|
|
311
|
+
return { path: held.path, removed: true };
|
|
312
|
+
const head = headChange(held);
|
|
313
|
+
const binary = binaryFileOf(held);
|
|
314
|
+
if (head === null || binary === null)
|
|
315
|
+
return null;
|
|
316
|
+
if (binary !== undefined) {
|
|
317
|
+
if (mode === 'credential' && typeof held.revision !== 'string')
|
|
318
|
+
return null;
|
|
319
|
+
const revision = typeof held.revision === 'string' ? held.revision : binary.sha256;
|
|
320
|
+
return { path: held.path, binary, revision, version: revision, ...headed(head) };
|
|
321
|
+
}
|
|
119
322
|
if (mode === 'site') {
|
|
120
|
-
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
323
|
+
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
324
|
+
return null;
|
|
121
325
|
return {
|
|
122
326
|
path: held.path,
|
|
123
327
|
content: held.content,
|
|
124
328
|
revision: undefined,
|
|
125
|
-
version: held.sha256
|
|
329
|
+
version: held.sha256,
|
|
330
|
+
...headed(head),
|
|
126
331
|
};
|
|
127
332
|
}
|
|
128
333
|
if (typeof held.content === 'string' && typeof held.revision === 'string') {
|
|
@@ -130,197 +335,162 @@ function parseChange(value, mode) {
|
|
|
130
335
|
path: held.path,
|
|
131
336
|
content: held.content,
|
|
132
337
|
revision: held.revision,
|
|
133
|
-
version: held.revision
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
if (typeof held.reference === 'object' && held.reference !== null) {
|
|
137
|
-
const reference = held.reference;
|
|
138
|
-
if (typeof reference.revision !== 'string') return null;
|
|
139
|
-
return {
|
|
140
|
-
path: held.path,
|
|
141
|
-
reference: {
|
|
142
|
-
revision: reference.revision
|
|
143
|
-
}
|
|
338
|
+
version: held.revision,
|
|
339
|
+
...headed(head),
|
|
144
340
|
};
|
|
145
341
|
}
|
|
146
342
|
return null;
|
|
147
343
|
}
|
|
148
344
|
export function parseEnumeration(body, mode) {
|
|
149
|
-
if (typeof body !== 'object' || body === null)
|
|
150
|
-
|
|
345
|
+
if (typeof body !== 'object' || body === null)
|
|
346
|
+
return null;
|
|
347
|
+
if (!('authorities' in body) || !Array.isArray(body.authorities))
|
|
348
|
+
return null;
|
|
151
349
|
const authorities = [];
|
|
152
|
-
for (const entry of body.authorities){
|
|
153
|
-
if (typeof entry !== 'object' || entry === null)
|
|
350
|
+
for (const entry of body.authorities) {
|
|
351
|
+
if (typeof entry !== 'object' || entry === null)
|
|
352
|
+
return null;
|
|
154
353
|
const held = entry;
|
|
155
354
|
const at = readPosition(held);
|
|
156
|
-
if (typeof held.authority !== 'string' || at === null)
|
|
157
|
-
|
|
355
|
+
if (typeof held.authority !== 'string' || at === null)
|
|
356
|
+
return null;
|
|
357
|
+
if (!Array.isArray(held.changes))
|
|
358
|
+
return null;
|
|
158
359
|
const changes = [];
|
|
159
|
-
|
|
360
|
+
const folders = [];
|
|
361
|
+
for (const change of held.changes) {
|
|
362
|
+
const folder = folderChange(change);
|
|
363
|
+
if (folder !== null) {
|
|
364
|
+
folders.push(folder);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
160
367
|
const mapped = parseChange(change, mode);
|
|
161
|
-
if (mapped === null)
|
|
368
|
+
if (mapped === null)
|
|
369
|
+
return null;
|
|
162
370
|
changes.push(mapped);
|
|
163
371
|
}
|
|
372
|
+
const next = held.next === undefined ? undefined : readPage(held.next);
|
|
373
|
+
if (next === null)
|
|
374
|
+
return null;
|
|
164
375
|
authorities.push({
|
|
165
376
|
authority: held.authority,
|
|
166
377
|
...at,
|
|
167
|
-
changes
|
|
378
|
+
changes,
|
|
379
|
+
...(folders.length === 0 ? {} : { folders }),
|
|
380
|
+
...(next === undefined ? {} : { next }),
|
|
168
381
|
});
|
|
169
382
|
}
|
|
170
|
-
return {
|
|
171
|
-
authorities
|
|
172
|
-
};
|
|
383
|
+
return { authorities };
|
|
173
384
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
385
|
+
function readPage(held) {
|
|
386
|
+
if (typeof held !== 'object' || held === null)
|
|
387
|
+
return null;
|
|
388
|
+
const { after, through, read } = held;
|
|
389
|
+
if (typeof after !== 'string' || !DECIMAL.test(after))
|
|
390
|
+
return null;
|
|
391
|
+
if (typeof through !== 'string' || !DECIMAL.test(through))
|
|
392
|
+
return null;
|
|
393
|
+
if (typeof read !== 'number' || !Number.isSafeInteger(read) || read < 0)
|
|
394
|
+
return null;
|
|
395
|
+
return { after, through, read };
|
|
396
|
+
}
|
|
397
|
+
function advances(asked, next) {
|
|
398
|
+
const moved = BigInt(next.through) - BigInt(asked.through);
|
|
399
|
+
return moved > 0n || (moved === 0n && next.after === asked.after && next.read > asked.read);
|
|
400
|
+
}
|
|
401
|
+
export async function wholeView(first, more) {
|
|
402
|
+
const changes = new Map(first.changes.map((change) => [change.path, change]));
|
|
403
|
+
const folders = new Map((first.folders ?? []).map((folder) => [folder.path, folder]));
|
|
404
|
+
let view = first;
|
|
405
|
+
while (view.next !== undefined) {
|
|
406
|
+
const asked = view.next;
|
|
407
|
+
const page = await more(asked);
|
|
408
|
+
if ('kind' in page)
|
|
409
|
+
return page;
|
|
410
|
+
if (page.position !== asked.through ||
|
|
411
|
+
page.logEpoch !== first.logEpoch ||
|
|
412
|
+
(page.next !== undefined && !advances(asked, page.next))) {
|
|
413
|
+
return { kind: 'transport-uncertainty' };
|
|
195
414
|
}
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
415
|
+
for (const change of page.changes) {
|
|
416
|
+
changes.delete(change.path);
|
|
417
|
+
changes.set(change.path, change);
|
|
418
|
+
}
|
|
419
|
+
for (const folder of page.folders ?? []) {
|
|
420
|
+
folders.delete(folder.path);
|
|
421
|
+
folders.set(folder.path, folder);
|
|
422
|
+
}
|
|
423
|
+
view = page;
|
|
202
424
|
}
|
|
203
425
|
return {
|
|
204
|
-
|
|
426
|
+
authority: first.authority,
|
|
205
427
|
position: view.position,
|
|
206
|
-
logEpoch:
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
],
|
|
210
|
-
contents: [
|
|
211
|
-
...contents
|
|
212
|
-
].map(([path, content])=>({
|
|
213
|
-
path,
|
|
214
|
-
content
|
|
215
|
-
}))
|
|
428
|
+
logEpoch: first.logEpoch,
|
|
429
|
+
changes: [...changes.values()],
|
|
430
|
+
...(folders.size === 0 ? {} : { folders: [...folders.values()] }),
|
|
216
431
|
};
|
|
217
432
|
}
|
|
218
|
-
export function
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return path === root || path.startsWith(`${root}/`);
|
|
224
|
-
}
|
|
225
|
-
export function selects(tracked, path) {
|
|
226
|
-
if (tracked.modelRoots.some((root)=>withinRoot(path, root))) return false;
|
|
227
|
-
return selectionRoots(tracked).some((root)=>withinRoot(path, root));
|
|
228
|
-
}
|
|
229
|
-
export function bootstrapFrom(envelope, tracked) {
|
|
230
|
-
const scope = envelope.scopes.find((entry)=>matchesScope(entry, tracked));
|
|
231
|
-
if (scope === undefined) return {
|
|
232
|
-
kind: 'room-not-readable',
|
|
233
|
-
locator: tracked.locator
|
|
234
|
-
};
|
|
235
|
-
return bootstrapOf(scope, tracked);
|
|
236
|
-
}
|
|
237
|
-
export function bootstrapOf(scope, tracked) {
|
|
238
|
-
const contents = new Map(scope.contents.map((entry)=>[
|
|
239
|
-
entry.path,
|
|
240
|
-
entry.content
|
|
241
|
-
]));
|
|
242
|
-
const documents = {};
|
|
243
|
-
const revisions = {};
|
|
244
|
-
const binaryTargets = [];
|
|
245
|
-
for (const file of scope.files){
|
|
246
|
-
if (!selects(tracked, file.path)) continue;
|
|
247
|
-
if (file.revision !== undefined) revisions[file.path] = file.revision;
|
|
248
|
-
const content = contents.get(file.path);
|
|
249
|
-
if (content === undefined) binaryTargets.push(file.path);
|
|
250
|
-
else documents[file.path] = content;
|
|
433
|
+
export function* bootstrapping(scope) {
|
|
434
|
+
const contents = new Map();
|
|
435
|
+
for (const entry of scope.contents) {
|
|
436
|
+
contents.set(entry.path, entry.content);
|
|
437
|
+
yield ROW_WEIGHT;
|
|
251
438
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
binaryTargets: binaryTargets.sort()
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
export const MODEL_DEFINITION_ADDRESS = 'types';
|
|
261
|
-
export function definitionAddress(path) {
|
|
262
|
-
return `${MODEL_DEFINITION_ADDRESS}/${path.slice(path.lastIndexOf('/') + 1)}`;
|
|
263
|
-
}
|
|
264
|
-
export function definitionsFrom(envelope, tracked, modelRoot) {
|
|
265
|
-
const scope = envelope.scopes.find((entry)=>matchesScope(entry, tracked));
|
|
266
|
-
if (scope === undefined) return null;
|
|
267
|
-
return definitionsOf(scope, modelRoot);
|
|
268
|
-
}
|
|
269
|
-
export function definitionsOf(scope, modelRoot) {
|
|
270
|
-
const contents = new Map(scope.contents.map((entry)=>[
|
|
271
|
-
entry.path,
|
|
272
|
-
entry.content
|
|
273
|
-
]));
|
|
274
|
-
const definitions = {};
|
|
275
|
-
const versions = [];
|
|
276
|
-
for (const file of scope.files){
|
|
277
|
-
if (!withinRoot(file.path, modelRoot)) continue;
|
|
439
|
+
const answer = answering();
|
|
440
|
+
for (const file of scope.files) {
|
|
441
|
+
yield ROW_WEIGHT;
|
|
442
|
+
if (file.head !== undefined)
|
|
443
|
+
answer.changes.set(file.path, file.head);
|
|
278
444
|
const content = contents.get(file.path);
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
445
|
+
if (file.binary !== undefined)
|
|
446
|
+
answer.binaryFiles.set(file.path, file.binary);
|
|
447
|
+
else if (content !== undefined)
|
|
448
|
+
answer.documents.set(file.path, content);
|
|
449
|
+
if (file.revision !== undefined)
|
|
450
|
+
revised(answer, file.path, file.revision);
|
|
283
451
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
};
|
|
452
|
+
for (const folder of scope.folders ?? [])
|
|
453
|
+
folded(answer, folder, false);
|
|
454
|
+
const { removals: _removals, folderRemovals: _folderRemovals, ...page } = yield* answered(answer);
|
|
455
|
+
return { kind: 'bootstrap', roomVersion: roomVersion(scope), ...page };
|
|
288
456
|
}
|
|
289
|
-
export function
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
457
|
+
export function schemaOf(scope, schema) {
|
|
458
|
+
const file = scope.files.find((entry) => entry.path === schema);
|
|
459
|
+
if (file === undefined)
|
|
460
|
+
return { schema: null, version: null, revision: null };
|
|
461
|
+
const content = scope.contents.find((entry) => entry.path === schema);
|
|
462
|
+
return content === undefined
|
|
463
|
+
? null
|
|
464
|
+
: { schema: content.content, version: file.version, revision: file.revision ?? null };
|
|
465
|
+
}
|
|
466
|
+
export function viewOf(enumeration, tracked) {
|
|
467
|
+
return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
|
|
468
|
+
}
|
|
469
|
+
function* refreshing(view, fromRoomVersion) {
|
|
470
|
+
if (roomVersion(view) === fromRoomVersion)
|
|
471
|
+
return { kind: 'still-current' };
|
|
472
|
+
const answer = answering();
|
|
473
|
+
for (const change of view.changes) {
|
|
474
|
+
yield ROW_WEIGHT;
|
|
304
475
|
if ('removed' in change) {
|
|
305
|
-
removals.
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
if ('content' in change) {
|
|
309
|
-
documents[change.path] = change.content;
|
|
310
|
-
if (change.revision !== undefined) revisions[change.path] = change.revision;
|
|
476
|
+
answer.removals.add(change.path);
|
|
311
477
|
continue;
|
|
312
478
|
}
|
|
313
|
-
|
|
314
|
-
|
|
479
|
+
if ('content' in change)
|
|
480
|
+
answer.documents.set(change.path, change.content);
|
|
481
|
+
else
|
|
482
|
+
answer.binaryFiles.set(change.path, change.binary);
|
|
483
|
+
if (change.head !== undefined)
|
|
484
|
+
answer.changes.set(change.path, change.head);
|
|
485
|
+
if (change.revision !== undefined)
|
|
486
|
+
revised(answer, change.path, change.revision);
|
|
315
487
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
488
|
+
for (const folder of view.folders ?? []) {
|
|
489
|
+
yield ROW_WEIGHT;
|
|
490
|
+
folded(answer, folder.path, folder.removed);
|
|
491
|
+
}
|
|
492
|
+
return { kind: 'net-advancement', roomVersion: roomVersion(view), ...(yield* answered(answer)) };
|
|
493
|
+
}
|
|
494
|
+
export async function refreshFrom(view, fromRoomVersion) {
|
|
495
|
+
return stepped(refreshing(view, fromRoomVersion));
|
|
324
496
|
}
|
|
325
|
-
|
|
326
|
-
//# sourceMappingURL=read.js.map
|