@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c04b3fdfb64c6
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 +297 -71
- package/README.md +32 -0
- package/dist/actions.d.ts +66 -13
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +279 -354
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +480 -218
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +24 -34
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +157 -230
- package/dist/gather.d.ts +4 -0
- package/dist/gather.d.ts.map +1 -0
- package/dist/gather.js +45 -0
- package/dist/handed.d.ts +15 -0
- package/dist/handed.d.ts.map +1 -0
- package/dist/handed.js +38 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -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/read.d.ts +62 -29
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +290 -203
- package/dist/referrer.d.ts +7 -0
- package/dist/referrer.d.ts.map +1 -0
- package/dist/referrer.js +35 -0
- package/dist/refusal.d.ts +5 -7
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +47 -68
- package/dist/site.d.ts +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +242 -155
- package/dist/stream.d.ts +18 -6
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +532 -212
- package/dist/transport.d.ts +119 -35
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +4 -3
- 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 +7 -8
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +201 -207
- 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,226 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { DECIMAL, readPosition, roomVersion } from './version.js';
|
|
2
|
+
const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
|
|
3
|
+
export function identities(revisions) {
|
|
4
|
+
const fileIds = Object.fromEntries(Object.entries(revisions).flatMap(([path, revision]) => {
|
|
5
|
+
const file = REVISION_FILE.exec(revision)?.[1];
|
|
6
|
+
return file === undefined ? [] : [[path, file]];
|
|
7
|
+
}));
|
|
8
|
+
return Object.keys(fileIds).length === 0 ? {} : { fileIds };
|
|
9
|
+
}
|
|
3
10
|
export function authorityRoot(handle) {
|
|
4
|
-
return
|
|
11
|
+
return `/rooms/${handle}`;
|
|
5
12
|
}
|
|
6
|
-
export
|
|
7
|
-
export function selectionRoots(tracked) {
|
|
8
|
-
if (tracked.handle === undefined) {
|
|
9
|
-
return [
|
|
10
|
-
tracked.collectionRoot,
|
|
11
|
-
...PROVIDER_SELECTION_ROOTS
|
|
12
|
-
];
|
|
13
|
-
}
|
|
13
|
+
export function contentPrefixes(tracked) {
|
|
14
14
|
return [
|
|
15
|
-
|
|
16
|
-
tracked.
|
|
15
|
+
authorityRoot(tracked.handle),
|
|
16
|
+
...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
|
|
17
17
|
];
|
|
18
18
|
}
|
|
19
|
-
export function
|
|
20
|
-
|
|
21
|
-
return selectionRoots(tracked).filter((entry)=>entry !== ROOM_README).map((entry)=>`${root}/${entry}`);
|
|
22
|
-
}
|
|
23
|
-
export function modelPrefix(tracked, modelRoot) {
|
|
24
|
-
return `${authorityRoot(tracked.handle)}/${modelRoot}`;
|
|
19
|
+
export function schemaPath(handle, schema) {
|
|
20
|
+
return `${authorityRoot(handle)}/${schema}`;
|
|
25
21
|
}
|
|
26
22
|
export function parseGrant(body) {
|
|
27
|
-
if (typeof body !== 'object' || body === null)
|
|
23
|
+
if (typeof body !== 'object' || body === null)
|
|
24
|
+
return null;
|
|
28
25
|
if (!('transfer' in body) || typeof body.transfer !== 'object' || body.transfer === null) {
|
|
29
26
|
return null;
|
|
30
27
|
}
|
|
31
28
|
const transfer = body.transfer;
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
method: transfer.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
29
|
+
if (typeof transfer.url !== 'string')
|
|
30
|
+
return null;
|
|
31
|
+
if (transfer.method === 'GET')
|
|
32
|
+
return { method: 'GET', url: transfer.url };
|
|
33
|
+
if (transfer.method !== 'POST' || typeof transfer.operation !== 'string')
|
|
34
|
+
return null;
|
|
35
|
+
return { method: 'POST', operation: transfer.operation, url: transfer.url };
|
|
36
|
+
}
|
|
37
|
+
function changeAuthor(value) {
|
|
38
|
+
if (typeof value !== 'object' || value === null)
|
|
39
|
+
return null;
|
|
40
|
+
const { user, site, name } = value;
|
|
41
|
+
if (typeof name !== 'string')
|
|
42
|
+
return null;
|
|
43
|
+
if (typeof user === 'string' && site === undefined)
|
|
44
|
+
return { kind: 'user', id: user, name };
|
|
45
|
+
if (typeof site === 'string' && user === undefined)
|
|
46
|
+
return { kind: 'site', id: site, name };
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
export function headChange(held) {
|
|
50
|
+
const author = held.author === undefined ? null : changeAuthor(held.author);
|
|
51
|
+
if (held.author !== undefined && author === null)
|
|
52
|
+
return null;
|
|
53
|
+
if (held.created_at === undefined)
|
|
54
|
+
return undefined;
|
|
55
|
+
if (typeof held.created_at !== 'string')
|
|
56
|
+
return null;
|
|
57
|
+
return { author, time: held.created_at };
|
|
58
|
+
}
|
|
59
|
+
function headed(head) {
|
|
60
|
+
return head === undefined ? {} : { head };
|
|
61
|
+
}
|
|
62
|
+
export function binaryFileOf(held) {
|
|
63
|
+
if (held.file === undefined)
|
|
64
|
+
return undefined;
|
|
65
|
+
const { file, bytes, media_type: mediaType, sha256 } = held;
|
|
66
|
+
if (typeof file !== 'string' ||
|
|
67
|
+
typeof bytes !== 'number' ||
|
|
68
|
+
typeof mediaType !== 'string' ||
|
|
69
|
+
typeof sha256 !== 'string')
|
|
70
|
+
return null;
|
|
71
|
+
return { fileRef: file, byteLength: bytes, mediaType, sha256 };
|
|
72
|
+
}
|
|
73
|
+
function binaried(binary) {
|
|
74
|
+
return binary === undefined ? {} : { binary };
|
|
39
75
|
}
|
|
40
76
|
function parseFile(value, mode) {
|
|
41
|
-
if (typeof value !== 'object' || value === null)
|
|
77
|
+
if (typeof value !== 'object' || value === null)
|
|
78
|
+
return null;
|
|
42
79
|
const file = value;
|
|
43
|
-
if (typeof file.path !== 'string')
|
|
80
|
+
if (typeof file.path !== 'string')
|
|
81
|
+
return null;
|
|
82
|
+
const head = headChange(file);
|
|
83
|
+
const binary = binaryFileOf(file);
|
|
84
|
+
if (head === null || binary === null)
|
|
85
|
+
return null;
|
|
44
86
|
if (mode === 'site') {
|
|
45
|
-
if (typeof file.sha256 !== 'string')
|
|
87
|
+
if (typeof file.sha256 !== 'string')
|
|
88
|
+
return null;
|
|
46
89
|
return {
|
|
47
90
|
path: file.path,
|
|
48
|
-
revision:
|
|
49
|
-
version: file.sha256
|
|
91
|
+
revision: binary?.sha256,
|
|
92
|
+
version: file.sha256,
|
|
93
|
+
...headed(head),
|
|
94
|
+
...binaried(binary),
|
|
50
95
|
};
|
|
51
96
|
}
|
|
52
|
-
if (typeof file.revision !== 'string')
|
|
97
|
+
if (typeof file.revision !== 'string')
|
|
98
|
+
return null;
|
|
53
99
|
return {
|
|
54
100
|
path: file.path,
|
|
55
101
|
revision: file.revision,
|
|
56
|
-
version: file.revision
|
|
102
|
+
version: file.revision,
|
|
103
|
+
...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
|
|
104
|
+
...headed(head),
|
|
105
|
+
...binaried(binary),
|
|
57
106
|
};
|
|
58
107
|
}
|
|
59
108
|
function parseScope(value, mode) {
|
|
60
|
-
if (typeof value !== 'object' || value === null)
|
|
109
|
+
if (typeof value !== 'object' || value === null)
|
|
110
|
+
return null;
|
|
61
111
|
const held = value;
|
|
62
|
-
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
63
|
-
|
|
112
|
+
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
113
|
+
return null;
|
|
114
|
+
if (!Array.isArray(held.contents))
|
|
115
|
+
return null;
|
|
64
116
|
const manifest = held.manifest;
|
|
65
|
-
if (manifest.scope !== 'room'
|
|
117
|
+
if (manifest.scope !== 'room')
|
|
118
|
+
return null;
|
|
66
119
|
const at = readPosition(manifest);
|
|
67
|
-
if (typeof manifest.anchor !== 'string' || at === null)
|
|
68
|
-
|
|
120
|
+
if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)
|
|
121
|
+
return null;
|
|
122
|
+
if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
|
|
123
|
+
return null;
|
|
124
|
+
if (!Array.isArray(manifest.files))
|
|
125
|
+
return null;
|
|
69
126
|
const files = [];
|
|
70
|
-
for (const entry of manifest.files){
|
|
127
|
+
for (const entry of manifest.files) {
|
|
71
128
|
const file = parseFile(entry, mode);
|
|
72
|
-
if (file === null)
|
|
129
|
+
if (file === null)
|
|
130
|
+
return null;
|
|
73
131
|
files.push(file);
|
|
74
132
|
}
|
|
75
133
|
const contents = [];
|
|
76
|
-
for (const entry of held.contents){
|
|
77
|
-
if (typeof entry !== 'object' || entry === null)
|
|
134
|
+
for (const entry of held.contents) {
|
|
135
|
+
if (typeof entry !== 'object' || entry === null)
|
|
136
|
+
return null;
|
|
78
137
|
const content = entry;
|
|
79
|
-
if (typeof content.path !== 'string' || typeof content.content !== 'string')
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
content: content.content
|
|
83
|
-
});
|
|
138
|
+
if (typeof content.path !== 'string' || typeof content.content !== 'string')
|
|
139
|
+
return null;
|
|
140
|
+
contents.push({ path: content.path, content: content.content });
|
|
84
141
|
}
|
|
85
|
-
return {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
142
|
+
return { anchor: manifest.anchor, ...at, files, contents };
|
|
143
|
+
}
|
|
144
|
+
function parseCut(value) {
|
|
145
|
+
if (value === undefined)
|
|
146
|
+
return undefined;
|
|
147
|
+
if (typeof value !== 'object' || value === null)
|
|
148
|
+
return null;
|
|
149
|
+
const { position, log_epoch: logEpoch } = value;
|
|
150
|
+
if (typeof position !== 'string' || typeof logEpoch !== 'string')
|
|
151
|
+
return null;
|
|
152
|
+
return { position, log_epoch: logEpoch };
|
|
153
|
+
}
|
|
154
|
+
function parseCursor(value) {
|
|
155
|
+
if (typeof value !== 'object' || value === null)
|
|
156
|
+
return null;
|
|
157
|
+
const { room, path, cut } = value;
|
|
158
|
+
if (typeof room !== 'string' || (path !== null && typeof path !== 'string'))
|
|
159
|
+
return null;
|
|
160
|
+
const parsed = parseCut(cut);
|
|
161
|
+
if (parsed === null)
|
|
162
|
+
return null;
|
|
163
|
+
return { room, path, ...(parsed === undefined ? {} : { cut: parsed }) };
|
|
93
164
|
}
|
|
94
165
|
export function parseEnvelope(body) {
|
|
95
|
-
if (typeof body !== 'object' || body === null)
|
|
96
|
-
|
|
166
|
+
if (typeof body !== 'object' || body === null)
|
|
167
|
+
return null;
|
|
168
|
+
if (!('scopes' in body) || !Array.isArray(body.scopes))
|
|
169
|
+
return null;
|
|
97
170
|
const scopes = [];
|
|
98
|
-
for (const entry of body.scopes){
|
|
171
|
+
for (const entry of body.scopes) {
|
|
99
172
|
const scope = parseScope(entry, 'credential');
|
|
100
|
-
if (scope === null)
|
|
173
|
+
if (scope === null)
|
|
174
|
+
return null;
|
|
101
175
|
scopes.push(scope);
|
|
102
176
|
}
|
|
103
|
-
|
|
104
|
-
scopes
|
|
105
|
-
|
|
177
|
+
if (!('next' in body) || body.next === undefined)
|
|
178
|
+
return { scopes };
|
|
179
|
+
const next = parseCursor(body.next);
|
|
180
|
+
return next === null ? null : { scopes, next };
|
|
106
181
|
}
|
|
107
182
|
export function parseSiteBootstrap(body) {
|
|
108
|
-
|
|
109
|
-
|
|
183
|
+
return parseScope(body, 'site');
|
|
184
|
+
}
|
|
185
|
+
export function siteBootstrapNext(body) {
|
|
186
|
+
if (typeof body !== 'object' || body === null || !('next' in body))
|
|
187
|
+
return null;
|
|
188
|
+
return typeof body.next === 'string' && body.next.length > 0 ? body.next : null;
|
|
189
|
+
}
|
|
190
|
+
export function siteBootstrapOffset(body) {
|
|
191
|
+
if (typeof body !== 'object' || body === null || !('offset' in body))
|
|
192
|
+
return null;
|
|
193
|
+
return Number.isSafeInteger(body.offset) && body.offset > 0
|
|
194
|
+
? body.offset
|
|
195
|
+
: null;
|
|
110
196
|
}
|
|
111
197
|
function parseChange(value, mode) {
|
|
112
|
-
if (typeof value !== 'object' || value === null)
|
|
198
|
+
if (typeof value !== 'object' || value === null)
|
|
199
|
+
return null;
|
|
113
200
|
const held = value;
|
|
114
|
-
if (typeof held.path !== 'string')
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
removed: true
|
|
118
|
-
|
|
201
|
+
if (typeof held.path !== 'string')
|
|
202
|
+
return null;
|
|
203
|
+
if (held.removed === true)
|
|
204
|
+
return { path: held.path, removed: true };
|
|
205
|
+
const head = headChange(held);
|
|
206
|
+
const binary = binaryFileOf(held);
|
|
207
|
+
if (head === null || binary === null)
|
|
208
|
+
return null;
|
|
209
|
+
if (binary !== undefined) {
|
|
210
|
+
if (mode === 'credential' && typeof held.revision !== 'string')
|
|
211
|
+
return null;
|
|
212
|
+
const revision = typeof held.revision === 'string' ? held.revision : binary.sha256;
|
|
213
|
+
return { path: held.path, binary, revision, version: revision, ...headed(head) };
|
|
214
|
+
}
|
|
119
215
|
if (mode === 'site') {
|
|
120
|
-
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
216
|
+
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
217
|
+
return null;
|
|
121
218
|
return {
|
|
122
219
|
path: held.path,
|
|
123
220
|
content: held.content,
|
|
124
221
|
revision: undefined,
|
|
125
|
-
version: held.sha256
|
|
222
|
+
version: held.sha256,
|
|
223
|
+
...headed(head),
|
|
126
224
|
};
|
|
127
225
|
}
|
|
128
226
|
if (typeof held.content === 'string' && typeof held.revision === 'string') {
|
|
@@ -130,197 +228,186 @@ function parseChange(value, mode) {
|
|
|
130
228
|
path: held.path,
|
|
131
229
|
content: held.content,
|
|
132
230
|
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
|
-
}
|
|
231
|
+
version: held.revision,
|
|
232
|
+
...headed(head),
|
|
144
233
|
};
|
|
145
234
|
}
|
|
146
235
|
return null;
|
|
147
236
|
}
|
|
148
237
|
export function parseEnumeration(body, mode) {
|
|
149
|
-
if (typeof body !== 'object' || body === null)
|
|
150
|
-
|
|
238
|
+
if (typeof body !== 'object' || body === null)
|
|
239
|
+
return null;
|
|
240
|
+
if (!('authorities' in body) || !Array.isArray(body.authorities))
|
|
241
|
+
return null;
|
|
151
242
|
const authorities = [];
|
|
152
|
-
for (const entry of body.authorities){
|
|
153
|
-
if (typeof entry !== 'object' || entry === null)
|
|
243
|
+
for (const entry of body.authorities) {
|
|
244
|
+
if (typeof entry !== 'object' || entry === null)
|
|
245
|
+
return null;
|
|
154
246
|
const held = entry;
|
|
155
247
|
const at = readPosition(held);
|
|
156
|
-
if (typeof held.authority !== 'string' || at === null)
|
|
157
|
-
|
|
248
|
+
if (typeof held.authority !== 'string' || at === null)
|
|
249
|
+
return null;
|
|
250
|
+
if (!Array.isArray(held.changes))
|
|
251
|
+
return null;
|
|
158
252
|
const changes = [];
|
|
159
|
-
for (const change of held.changes){
|
|
253
|
+
for (const change of held.changes) {
|
|
160
254
|
const mapped = parseChange(change, mode);
|
|
161
|
-
if (mapped === null)
|
|
255
|
+
if (mapped === null)
|
|
256
|
+
return null;
|
|
162
257
|
changes.push(mapped);
|
|
163
258
|
}
|
|
259
|
+
const next = held.next === undefined ? undefined : readPage(held.next);
|
|
260
|
+
if (next === null)
|
|
261
|
+
return null;
|
|
164
262
|
authorities.push({
|
|
165
263
|
authority: held.authority,
|
|
166
264
|
...at,
|
|
167
|
-
changes
|
|
265
|
+
changes,
|
|
266
|
+
...(next === undefined ? {} : { next }),
|
|
168
267
|
});
|
|
169
268
|
}
|
|
269
|
+
return { authorities };
|
|
270
|
+
}
|
|
271
|
+
function readPage(held) {
|
|
272
|
+
if (typeof held !== 'object' || held === null)
|
|
273
|
+
return null;
|
|
274
|
+
const { after, through, read } = held;
|
|
275
|
+
if (typeof after !== 'string' || !DECIMAL.test(after))
|
|
276
|
+
return null;
|
|
277
|
+
if (typeof through !== 'string' || !DECIMAL.test(through))
|
|
278
|
+
return null;
|
|
279
|
+
if (typeof read !== 'number' || !Number.isSafeInteger(read) || read < 0)
|
|
280
|
+
return null;
|
|
281
|
+
return { after, through, read };
|
|
282
|
+
}
|
|
283
|
+
function advances(asked, next) {
|
|
284
|
+
const moved = BigInt(next.through) - BigInt(asked.through);
|
|
285
|
+
return moved > 0n || (moved === 0n && next.after === asked.after && next.read > asked.read);
|
|
286
|
+
}
|
|
287
|
+
export async function wholeView(first, more) {
|
|
288
|
+
const changes = new Map(first.changes.map((change) => [change.path, change]));
|
|
289
|
+
let view = first;
|
|
290
|
+
while (view.next !== undefined) {
|
|
291
|
+
const asked = view.next;
|
|
292
|
+
const page = await more(asked);
|
|
293
|
+
if ('kind' in page)
|
|
294
|
+
return page;
|
|
295
|
+
if (page.position !== asked.through ||
|
|
296
|
+
page.logEpoch !== first.logEpoch ||
|
|
297
|
+
(page.next !== undefined && !advances(asked, page.next))) {
|
|
298
|
+
return { kind: 'transport-uncertainty' };
|
|
299
|
+
}
|
|
300
|
+
for (const change of page.changes) {
|
|
301
|
+
changes.delete(change.path);
|
|
302
|
+
changes.set(change.path, change);
|
|
303
|
+
}
|
|
304
|
+
view = page;
|
|
305
|
+
}
|
|
170
306
|
return {
|
|
171
|
-
|
|
307
|
+
authority: first.authority,
|
|
308
|
+
position: view.position,
|
|
309
|
+
logEpoch: first.logEpoch,
|
|
310
|
+
changes: [...changes.values()],
|
|
172
311
|
};
|
|
173
312
|
}
|
|
174
313
|
export function advancedScope(scope, view) {
|
|
175
|
-
const files = new Map(scope.files.map((file)=>[
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
]));
|
|
179
|
-
const contents = new Map(scope.contents.map((entry)=>[
|
|
180
|
-
entry.path,
|
|
181
|
-
entry.content
|
|
182
|
-
]));
|
|
183
|
-
for (const change of view.changes){
|
|
314
|
+
const files = new Map(scope.files.map((file) => [file.path, file]));
|
|
315
|
+
const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
|
|
316
|
+
for (const change of view.changes) {
|
|
184
317
|
files.delete(change.path);
|
|
185
318
|
contents.delete(change.path);
|
|
186
|
-
if ('removed' in change)
|
|
187
|
-
if ('content' in change) {
|
|
188
|
-
files.set(change.path, {
|
|
189
|
-
path: change.path,
|
|
190
|
-
revision: change.revision,
|
|
191
|
-
version: change.version
|
|
192
|
-
});
|
|
193
|
-
contents.set(change.path, change.content);
|
|
319
|
+
if ('removed' in change)
|
|
194
320
|
continue;
|
|
195
|
-
}
|
|
196
|
-
const { revision } = change.reference;
|
|
197
321
|
files.set(change.path, {
|
|
198
322
|
path: change.path,
|
|
199
|
-
revision,
|
|
200
|
-
version:
|
|
323
|
+
revision: change.revision,
|
|
324
|
+
version: change.version,
|
|
325
|
+
...headed(change.head),
|
|
326
|
+
...('binary' in change ? { binary: change.binary } : {}),
|
|
201
327
|
});
|
|
328
|
+
if ('content' in change)
|
|
329
|
+
contents.set(change.path, change.content);
|
|
202
330
|
}
|
|
203
331
|
return {
|
|
204
332
|
...scope,
|
|
205
333
|
position: view.position,
|
|
206
334
|
logEpoch: view.logEpoch,
|
|
207
|
-
files: [
|
|
208
|
-
|
|
209
|
-
],
|
|
210
|
-
contents: [
|
|
211
|
-
...contents
|
|
212
|
-
].map(([path, content])=>({
|
|
213
|
-
path,
|
|
214
|
-
content
|
|
215
|
-
}))
|
|
335
|
+
files: [...files.values()],
|
|
336
|
+
contents: [...contents].map(([path, content]) => ({ path, content })),
|
|
216
337
|
};
|
|
217
338
|
}
|
|
218
339
|
export function matchesScope(scope, tracked) {
|
|
219
|
-
|
|
220
|
-
return scope.roomHandle === tracked.handle || scope.anchor === tracked.authority;
|
|
221
|
-
}
|
|
222
|
-
export function withinRoot(path, root) {
|
|
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));
|
|
340
|
+
return scope.anchor === tracked.authority;
|
|
228
341
|
}
|
|
229
|
-
export function
|
|
230
|
-
const
|
|
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
|
-
]));
|
|
342
|
+
export function bootstrapOf(scope) {
|
|
343
|
+
const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
|
|
242
344
|
const documents = {};
|
|
243
345
|
const revisions = {};
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (file.revision !== undefined)
|
|
346
|
+
const changes = {};
|
|
347
|
+
const binaryFiles = {};
|
|
348
|
+
for (const file of scope.files) {
|
|
349
|
+
if (file.revision !== undefined)
|
|
350
|
+
revisions[file.path] = file.revision;
|
|
351
|
+
if (file.head !== undefined)
|
|
352
|
+
changes[file.path] = file.head;
|
|
248
353
|
const content = contents.get(file.path);
|
|
249
|
-
if (
|
|
250
|
-
|
|
354
|
+
if (file.binary !== undefined)
|
|
355
|
+
binaryFiles[file.path] = file.binary;
|
|
356
|
+
else if (content !== undefined)
|
|
357
|
+
documents[file.path] = content;
|
|
251
358
|
}
|
|
252
359
|
return {
|
|
253
360
|
kind: 'bootstrap',
|
|
254
361
|
roomVersion: roomVersion(scope),
|
|
255
362
|
documents,
|
|
256
363
|
revisions,
|
|
257
|
-
|
|
364
|
+
...identities(revisions),
|
|
365
|
+
changes,
|
|
366
|
+
binaryFiles,
|
|
258
367
|
};
|
|
259
368
|
}
|
|
260
|
-
export
|
|
261
|
-
|
|
262
|
-
|
|
369
|
+
export function schemaOf(scope, schema) {
|
|
370
|
+
const file = scope.files.find((entry) => entry.path === schema);
|
|
371
|
+
if (file === undefined)
|
|
372
|
+
return { schema: null, version: null, revision: null };
|
|
373
|
+
const content = scope.contents.find((entry) => entry.path === schema);
|
|
374
|
+
return content === undefined
|
|
375
|
+
? null
|
|
376
|
+
: { schema: content.content, version: file.version, revision: file.revision ?? null };
|
|
263
377
|
}
|
|
264
|
-
export function
|
|
265
|
-
|
|
266
|
-
if (scope === undefined) return null;
|
|
267
|
-
return definitionsOf(scope, modelRoot);
|
|
378
|
+
export function viewOf(enumeration, tracked) {
|
|
379
|
+
return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
|
|
268
380
|
}
|
|
269
|
-
export function
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
entry.content
|
|
273
|
-
]));
|
|
274
|
-
const definitions = {};
|
|
275
|
-
const versions = [];
|
|
276
|
-
for (const file of scope.files){
|
|
277
|
-
if (!withinRoot(file.path, modelRoot)) continue;
|
|
278
|
-
const content = contents.get(file.path);
|
|
279
|
-
const address = definitionAddress(file.path);
|
|
280
|
-
if (content === undefined || Object.hasOwn(definitions, address)) return null;
|
|
281
|
-
definitions[address] = content;
|
|
282
|
-
versions.push(`${file.path} ${file.version}`);
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
definitions,
|
|
286
|
-
versions: versions.sort()
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
export function refreshFrom(enumeration, tracked, fromRoomVersion) {
|
|
290
|
-
const view = enumeration.authorities.find((entry)=>entry.authority === tracked.authority);
|
|
291
|
-
if (view === undefined) return {
|
|
292
|
-
kind: 'room-not-readable',
|
|
293
|
-
locator: tracked.locator
|
|
294
|
-
};
|
|
295
|
-
if (roomVersion(view) === fromRoomVersion) return {
|
|
296
|
-
kind: 'still-current'
|
|
297
|
-
};
|
|
381
|
+
export function refreshFrom(view, fromRoomVersion) {
|
|
382
|
+
if (roomVersion(view) === fromRoomVersion)
|
|
383
|
+
return { kind: 'still-current' };
|
|
298
384
|
const documents = {};
|
|
299
385
|
const revisions = {};
|
|
300
|
-
const
|
|
386
|
+
const changes = {};
|
|
387
|
+
const binaryFiles = {};
|
|
301
388
|
const removals = [];
|
|
302
|
-
for (const change of view.changes){
|
|
303
|
-
if (!selects(tracked, change.path)) continue;
|
|
389
|
+
for (const change of view.changes) {
|
|
304
390
|
if ('removed' in change) {
|
|
305
391
|
removals.push(change.path);
|
|
306
392
|
continue;
|
|
307
393
|
}
|
|
308
|
-
if ('content' in change)
|
|
394
|
+
if ('content' in change)
|
|
309
395
|
documents[change.path] = change.content;
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
396
|
+
else
|
|
397
|
+
binaryFiles[change.path] = change.binary;
|
|
398
|
+
if (change.revision !== undefined)
|
|
399
|
+
revisions[change.path] = change.revision;
|
|
400
|
+
if (change.head !== undefined)
|
|
401
|
+
changes[change.path] = change.head;
|
|
315
402
|
}
|
|
316
403
|
return {
|
|
317
404
|
kind: 'net-advancement',
|
|
318
405
|
roomVersion: roomVersion(view),
|
|
319
406
|
documents,
|
|
320
407
|
revisions,
|
|
321
|
-
|
|
322
|
-
|
|
408
|
+
...identities(revisions),
|
|
409
|
+
changes,
|
|
410
|
+
binaryFiles,
|
|
411
|
+
removals: removals.sort(),
|
|
323
412
|
};
|
|
324
413
|
}
|
|
325
|
-
|
|
326
|
-
//# sourceMappingURL=read.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TrackedAuthority } from './discovery.js';
|
|
2
|
+
export type HouseReferrer = {
|
|
3
|
+
locator: string;
|
|
4
|
+
referrer: Readonly<Record<string, string>>;
|
|
5
|
+
};
|
|
6
|
+
export declare function houseReferrer(referrer: unknown, tracked: ReadonlyMap<string, TrackedAuthority>): HouseReferrer | null;
|
|
7
|
+
//# sourceMappingURL=referrer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"referrer.d.ts","sourceRoot":"","sources":["../src/referrer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC;AAgB5F,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAC7C,aAAa,GAAG,IAAI,CAqBtB"}
|
package/dist/referrer.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function fields(value) {
|
|
2
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
3
|
+
? value
|
|
4
|
+
: null;
|
|
5
|
+
}
|
|
6
|
+
function named(held, ...keys) {
|
|
7
|
+
const present = Object.keys(held);
|
|
8
|
+
return (present.length === keys.length &&
|
|
9
|
+
keys.every((key) => typeof held[key] === 'string' && held[key] !== ''));
|
|
10
|
+
}
|
|
11
|
+
export function houseReferrer(referrer, tracked) {
|
|
12
|
+
const held = fields(referrer);
|
|
13
|
+
if (held === null)
|
|
14
|
+
return null;
|
|
15
|
+
if (named(held, 'room', 'path')) {
|
|
16
|
+
const entry = tracked.get(held.room);
|
|
17
|
+
if (entry === undefined)
|
|
18
|
+
return null;
|
|
19
|
+
return {
|
|
20
|
+
locator: entry.locator,
|
|
21
|
+
referrer: { room_ref: entry.authority, path: held.path },
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (named(held, 'room_ref', 'record')) {
|
|
25
|
+
const roomRef = held.room_ref;
|
|
26
|
+
const entry = [...tracked.values()].find((candidate) => candidate.authority === roomRef);
|
|
27
|
+
return {
|
|
28
|
+
locator: entry?.locator ?? roomRef,
|
|
29
|
+
referrer: { room_ref: roomRef, record: held.record },
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (named(held, 'message'))
|
|
33
|
+
return { locator: '', referrer: { message: held.message } };
|
|
34
|
+
return null;
|
|
35
|
+
}
|