@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c09c6f263662c
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 +272 -33
- package/README.md +32 -0
- package/dist/actions.d.ts +43 -13
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +270 -351
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +361 -221
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +23 -34
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +154 -231
- 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 +8 -18
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +63 -57
- package/dist/read.d.ts +40 -29
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +209 -208
- 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 -69
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +144 -153
- package/dist/stream.d.ts +17 -6
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +251 -215
- package/dist/transport.d.ts +81 -33
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +4 -3
- package/dist/version.d.ts +2 -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 +196 -206
- package/package.json +5 -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,192 @@
|
|
|
1
|
-
import { PROVIDER_SELECTION_ROOTS } from './discovery.js';
|
|
2
1
|
import { readPosition, roomVersion } from './version.js';
|
|
3
2
|
export function authorityRoot(handle) {
|
|
4
|
-
return
|
|
3
|
+
return `/rooms/${handle}`;
|
|
5
4
|
}
|
|
6
|
-
export
|
|
7
|
-
export function selectionRoots(tracked) {
|
|
8
|
-
if (tracked.handle === undefined) {
|
|
9
|
-
return [
|
|
10
|
-
tracked.collectionRoot,
|
|
11
|
-
...PROVIDER_SELECTION_ROOTS
|
|
12
|
-
];
|
|
13
|
-
}
|
|
5
|
+
export function contentPrefixes(tracked) {
|
|
14
6
|
return [
|
|
15
|
-
|
|
16
|
-
tracked.
|
|
7
|
+
authorityRoot(tracked.handle),
|
|
8
|
+
...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
|
|
17
9
|
];
|
|
18
10
|
}
|
|
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}`;
|
|
11
|
+
export function schemaPath(handle, schema) {
|
|
12
|
+
return `${authorityRoot(handle)}/${schema}`;
|
|
25
13
|
}
|
|
26
14
|
export function parseGrant(body) {
|
|
27
|
-
if (typeof body !== 'object' || body === null)
|
|
15
|
+
if (typeof body !== 'object' || body === null)
|
|
16
|
+
return null;
|
|
28
17
|
if (!('transfer' in body) || typeof body.transfer !== 'object' || body.transfer === null) {
|
|
29
18
|
return null;
|
|
30
19
|
}
|
|
31
20
|
const transfer = body.transfer;
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
method: transfer.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
21
|
+
if (typeof transfer.url !== 'string')
|
|
22
|
+
return null;
|
|
23
|
+
if (transfer.method === 'GET')
|
|
24
|
+
return { method: 'GET', url: transfer.url };
|
|
25
|
+
if (transfer.method !== 'POST' || typeof transfer.operation !== 'string')
|
|
26
|
+
return null;
|
|
27
|
+
return { method: 'POST', operation: transfer.operation, url: transfer.url };
|
|
28
|
+
}
|
|
29
|
+
function changeAuthor(value) {
|
|
30
|
+
if (typeof value !== 'object' || value === null)
|
|
31
|
+
return null;
|
|
32
|
+
const { user, site, name } = value;
|
|
33
|
+
if (typeof name !== 'string')
|
|
34
|
+
return null;
|
|
35
|
+
if (typeof user === 'string' && site === undefined)
|
|
36
|
+
return { kind: 'user', id: user, name };
|
|
37
|
+
if (typeof site === 'string' && user === undefined)
|
|
38
|
+
return { kind: 'site', id: site, name };
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
export function headChange(held) {
|
|
42
|
+
const author = held.author === undefined ? null : changeAuthor(held.author);
|
|
43
|
+
if (held.author !== undefined && author === null)
|
|
44
|
+
return null;
|
|
45
|
+
if (held.created_at === undefined)
|
|
46
|
+
return undefined;
|
|
47
|
+
if (typeof held.created_at !== 'string')
|
|
48
|
+
return null;
|
|
49
|
+
return { author, time: held.created_at };
|
|
50
|
+
}
|
|
51
|
+
function headed(head) {
|
|
52
|
+
return head === undefined ? {} : { head };
|
|
53
|
+
}
|
|
54
|
+
export function binaryFileOf(held) {
|
|
55
|
+
if (held.file === undefined)
|
|
56
|
+
return undefined;
|
|
57
|
+
const { file, bytes, media_type: mediaType, sha256 } = held;
|
|
58
|
+
if (typeof file !== 'string' ||
|
|
59
|
+
typeof bytes !== 'number' ||
|
|
60
|
+
typeof mediaType !== 'string' ||
|
|
61
|
+
typeof sha256 !== 'string')
|
|
62
|
+
return null;
|
|
63
|
+
return { fileRef: file, byteLength: bytes, mediaType, sha256 };
|
|
64
|
+
}
|
|
65
|
+
function binaried(binary) {
|
|
66
|
+
return binary === undefined ? {} : { binary };
|
|
39
67
|
}
|
|
40
68
|
function parseFile(value, mode) {
|
|
41
|
-
if (typeof value !== 'object' || value === null)
|
|
69
|
+
if (typeof value !== 'object' || value === null)
|
|
70
|
+
return null;
|
|
42
71
|
const file = value;
|
|
43
|
-
if (typeof file.path !== 'string')
|
|
72
|
+
if (typeof file.path !== 'string')
|
|
73
|
+
return null;
|
|
74
|
+
const head = headChange(file);
|
|
75
|
+
const binary = binaryFileOf(file);
|
|
76
|
+
if (head === null || binary === null)
|
|
77
|
+
return null;
|
|
44
78
|
if (mode === 'site') {
|
|
45
|
-
if (typeof file.sha256 !== 'string')
|
|
79
|
+
if (typeof file.sha256 !== 'string')
|
|
80
|
+
return null;
|
|
46
81
|
return {
|
|
47
82
|
path: file.path,
|
|
48
|
-
revision:
|
|
49
|
-
version: file.sha256
|
|
83
|
+
revision: binary?.sha256,
|
|
84
|
+
version: file.sha256,
|
|
85
|
+
...headed(head),
|
|
86
|
+
...binaried(binary),
|
|
50
87
|
};
|
|
51
88
|
}
|
|
52
|
-
if (typeof file.revision !== 'string')
|
|
89
|
+
if (typeof file.revision !== 'string')
|
|
90
|
+
return null;
|
|
53
91
|
return {
|
|
54
92
|
path: file.path,
|
|
55
93
|
revision: file.revision,
|
|
56
|
-
version: file.revision
|
|
94
|
+
version: file.revision,
|
|
95
|
+
...headed(head),
|
|
96
|
+
...binaried(binary),
|
|
57
97
|
};
|
|
58
98
|
}
|
|
59
99
|
function parseScope(value, mode) {
|
|
60
|
-
if (typeof value !== 'object' || value === null)
|
|
100
|
+
if (typeof value !== 'object' || value === null)
|
|
101
|
+
return null;
|
|
61
102
|
const held = value;
|
|
62
|
-
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
63
|
-
|
|
103
|
+
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
104
|
+
return null;
|
|
105
|
+
if (!Array.isArray(held.contents))
|
|
106
|
+
return null;
|
|
64
107
|
const manifest = held.manifest;
|
|
65
|
-
if (manifest.scope !== 'room'
|
|
108
|
+
if (manifest.scope !== 'room')
|
|
109
|
+
return null;
|
|
66
110
|
const at = readPosition(manifest);
|
|
67
|
-
if (typeof manifest.anchor !== 'string' || at === null)
|
|
68
|
-
|
|
111
|
+
if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)
|
|
112
|
+
return null;
|
|
113
|
+
if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
|
|
114
|
+
return null;
|
|
115
|
+
if (!Array.isArray(manifest.files))
|
|
116
|
+
return null;
|
|
69
117
|
const files = [];
|
|
70
|
-
for (const entry of manifest.files){
|
|
118
|
+
for (const entry of manifest.files) {
|
|
71
119
|
const file = parseFile(entry, mode);
|
|
72
|
-
if (file === null)
|
|
120
|
+
if (file === null)
|
|
121
|
+
return null;
|
|
73
122
|
files.push(file);
|
|
74
123
|
}
|
|
75
124
|
const contents = [];
|
|
76
|
-
for (const entry of held.contents){
|
|
77
|
-
if (typeof entry !== 'object' || entry === null)
|
|
125
|
+
for (const entry of held.contents) {
|
|
126
|
+
if (typeof entry !== 'object' || entry === null)
|
|
127
|
+
return null;
|
|
78
128
|
const content = entry;
|
|
79
|
-
if (typeof content.path !== 'string' || typeof content.content !== 'string')
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
content: content.content
|
|
83
|
-
});
|
|
129
|
+
if (typeof content.path !== 'string' || typeof content.content !== 'string')
|
|
130
|
+
return null;
|
|
131
|
+
contents.push({ path: content.path, content: content.content });
|
|
84
132
|
}
|
|
85
|
-
return {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
133
|
+
return { anchor: manifest.anchor, ...at, files, contents };
|
|
134
|
+
}
|
|
135
|
+
function parseCursor(value) {
|
|
136
|
+
if (typeof value !== 'object' || value === null)
|
|
137
|
+
return null;
|
|
138
|
+
const { room, path } = value;
|
|
139
|
+
if (typeof room !== 'string' || (path !== null && typeof path !== 'string'))
|
|
140
|
+
return null;
|
|
141
|
+
return { room, path };
|
|
93
142
|
}
|
|
94
143
|
export function parseEnvelope(body) {
|
|
95
|
-
if (typeof body !== 'object' || body === null)
|
|
96
|
-
|
|
144
|
+
if (typeof body !== 'object' || body === null)
|
|
145
|
+
return null;
|
|
146
|
+
if (!('scopes' in body) || !Array.isArray(body.scopes))
|
|
147
|
+
return null;
|
|
97
148
|
const scopes = [];
|
|
98
|
-
for (const entry of body.scopes){
|
|
149
|
+
for (const entry of body.scopes) {
|
|
99
150
|
const scope = parseScope(entry, 'credential');
|
|
100
|
-
if (scope === null)
|
|
151
|
+
if (scope === null)
|
|
152
|
+
return null;
|
|
101
153
|
scopes.push(scope);
|
|
102
154
|
}
|
|
103
|
-
|
|
104
|
-
scopes
|
|
105
|
-
|
|
155
|
+
if (!('next' in body) || body.next === undefined)
|
|
156
|
+
return { scopes };
|
|
157
|
+
const next = parseCursor(body.next);
|
|
158
|
+
return next === null ? null : { scopes, next };
|
|
106
159
|
}
|
|
107
160
|
export function parseSiteBootstrap(body) {
|
|
108
|
-
|
|
109
|
-
return scope !== null && scope.scope === 'room' ? scope : null;
|
|
161
|
+
return parseScope(body, 'site');
|
|
110
162
|
}
|
|
111
163
|
function parseChange(value, mode) {
|
|
112
|
-
if (typeof value !== 'object' || value === null)
|
|
164
|
+
if (typeof value !== 'object' || value === null)
|
|
165
|
+
return null;
|
|
113
166
|
const held = value;
|
|
114
|
-
if (typeof held.path !== 'string')
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
removed: true
|
|
118
|
-
|
|
167
|
+
if (typeof held.path !== 'string')
|
|
168
|
+
return null;
|
|
169
|
+
if (held.removed === true)
|
|
170
|
+
return { path: held.path, removed: true };
|
|
171
|
+
const head = headChange(held);
|
|
172
|
+
const binary = binaryFileOf(held);
|
|
173
|
+
if (head === null || binary === null)
|
|
174
|
+
return null;
|
|
175
|
+
if (binary !== undefined) {
|
|
176
|
+
if (mode === 'credential' && typeof held.revision !== 'string')
|
|
177
|
+
return null;
|
|
178
|
+
const revision = typeof held.revision === 'string' ? held.revision : binary.sha256;
|
|
179
|
+
return { path: held.path, binary, revision, version: revision, ...headed(head) };
|
|
180
|
+
}
|
|
119
181
|
if (mode === 'site') {
|
|
120
|
-
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
182
|
+
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
183
|
+
return null;
|
|
121
184
|
return {
|
|
122
185
|
path: held.path,
|
|
123
186
|
content: held.content,
|
|
124
187
|
revision: undefined,
|
|
125
|
-
version: held.sha256
|
|
188
|
+
version: held.sha256,
|
|
189
|
+
...headed(head),
|
|
126
190
|
};
|
|
127
191
|
}
|
|
128
192
|
if (typeof held.content === 'string' && typeof held.revision === 'string') {
|
|
@@ -130,197 +194,134 @@ function parseChange(value, mode) {
|
|
|
130
194
|
path: held.path,
|
|
131
195
|
content: held.content,
|
|
132
196
|
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
|
-
}
|
|
197
|
+
version: held.revision,
|
|
198
|
+
...headed(head),
|
|
144
199
|
};
|
|
145
200
|
}
|
|
146
201
|
return null;
|
|
147
202
|
}
|
|
148
203
|
export function parseEnumeration(body, mode) {
|
|
149
|
-
if (typeof body !== 'object' || body === null)
|
|
150
|
-
|
|
204
|
+
if (typeof body !== 'object' || body === null)
|
|
205
|
+
return null;
|
|
206
|
+
if (!('authorities' in body) || !Array.isArray(body.authorities))
|
|
207
|
+
return null;
|
|
151
208
|
const authorities = [];
|
|
152
|
-
for (const entry of body.authorities){
|
|
153
|
-
if (typeof entry !== 'object' || entry === null)
|
|
209
|
+
for (const entry of body.authorities) {
|
|
210
|
+
if (typeof entry !== 'object' || entry === null)
|
|
211
|
+
return null;
|
|
154
212
|
const held = entry;
|
|
155
213
|
const at = readPosition(held);
|
|
156
|
-
if (typeof held.authority !== 'string' || at === null)
|
|
157
|
-
|
|
214
|
+
if (typeof held.authority !== 'string' || at === null)
|
|
215
|
+
return null;
|
|
216
|
+
if (!Array.isArray(held.changes))
|
|
217
|
+
return null;
|
|
158
218
|
const changes = [];
|
|
159
|
-
for (const change of held.changes){
|
|
219
|
+
for (const change of held.changes) {
|
|
160
220
|
const mapped = parseChange(change, mode);
|
|
161
|
-
if (mapped === null)
|
|
221
|
+
if (mapped === null)
|
|
222
|
+
return null;
|
|
162
223
|
changes.push(mapped);
|
|
163
224
|
}
|
|
164
|
-
authorities.push({
|
|
165
|
-
authority: held.authority,
|
|
166
|
-
...at,
|
|
167
|
-
changes
|
|
168
|
-
});
|
|
225
|
+
authorities.push({ authority: held.authority, ...at, changes });
|
|
169
226
|
}
|
|
170
|
-
return {
|
|
171
|
-
authorities
|
|
172
|
-
};
|
|
227
|
+
return { authorities };
|
|
173
228
|
}
|
|
174
229
|
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){
|
|
230
|
+
const files = new Map(scope.files.map((file) => [file.path, file]));
|
|
231
|
+
const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
|
|
232
|
+
for (const change of view.changes) {
|
|
184
233
|
files.delete(change.path);
|
|
185
234
|
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);
|
|
235
|
+
if ('removed' in change)
|
|
194
236
|
continue;
|
|
195
|
-
}
|
|
196
|
-
const { revision } = change.reference;
|
|
197
237
|
files.set(change.path, {
|
|
198
238
|
path: change.path,
|
|
199
|
-
revision,
|
|
200
|
-
version:
|
|
239
|
+
revision: change.revision,
|
|
240
|
+
version: change.version,
|
|
241
|
+
...headed(change.head),
|
|
242
|
+
...('binary' in change ? { binary: change.binary } : {}),
|
|
201
243
|
});
|
|
244
|
+
if ('content' in change)
|
|
245
|
+
contents.set(change.path, change.content);
|
|
202
246
|
}
|
|
203
247
|
return {
|
|
204
248
|
...scope,
|
|
205
249
|
position: view.position,
|
|
206
250
|
logEpoch: view.logEpoch,
|
|
207
|
-
files: [
|
|
208
|
-
|
|
209
|
-
],
|
|
210
|
-
contents: [
|
|
211
|
-
...contents
|
|
212
|
-
].map(([path, content])=>({
|
|
213
|
-
path,
|
|
214
|
-
content
|
|
215
|
-
}))
|
|
251
|
+
files: [...files.values()],
|
|
252
|
+
contents: [...contents].map(([path, content]) => ({ path, content })),
|
|
216
253
|
};
|
|
217
254
|
}
|
|
218
255
|
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));
|
|
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);
|
|
256
|
+
return scope.anchor === tracked.authority;
|
|
236
257
|
}
|
|
237
|
-
export function bootstrapOf(scope
|
|
238
|
-
const contents = new Map(scope.contents.map((entry)=>[
|
|
239
|
-
entry.path,
|
|
240
|
-
entry.content
|
|
241
|
-
]));
|
|
258
|
+
export function bootstrapOf(scope) {
|
|
259
|
+
const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
|
|
242
260
|
const documents = {};
|
|
243
261
|
const revisions = {};
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (file.revision !== undefined)
|
|
262
|
+
const changes = {};
|
|
263
|
+
const binaryFiles = {};
|
|
264
|
+
for (const file of scope.files) {
|
|
265
|
+
if (file.revision !== undefined)
|
|
266
|
+
revisions[file.path] = file.revision;
|
|
267
|
+
if (file.head !== undefined)
|
|
268
|
+
changes[file.path] = file.head;
|
|
248
269
|
const content = contents.get(file.path);
|
|
249
|
-
if (
|
|
250
|
-
|
|
270
|
+
if (file.binary !== undefined)
|
|
271
|
+
binaryFiles[file.path] = file.binary;
|
|
272
|
+
else if (content !== undefined)
|
|
273
|
+
documents[file.path] = content;
|
|
251
274
|
}
|
|
252
275
|
return {
|
|
253
276
|
kind: 'bootstrap',
|
|
254
277
|
roomVersion: roomVersion(scope),
|
|
255
278
|
documents,
|
|
256
279
|
revisions,
|
|
257
|
-
|
|
280
|
+
changes,
|
|
281
|
+
binaryFiles,
|
|
258
282
|
};
|
|
259
283
|
}
|
|
260
|
-
export
|
|
261
|
-
|
|
262
|
-
|
|
284
|
+
export function schemaOf(scope, schema) {
|
|
285
|
+
const file = scope.files.find((entry) => entry.path === schema);
|
|
286
|
+
if (file === undefined)
|
|
287
|
+
return { schema: null, version: null, revision: null };
|
|
288
|
+
const content = scope.contents.find((entry) => entry.path === schema);
|
|
289
|
+
return content === undefined
|
|
290
|
+
? null
|
|
291
|
+
: { schema: content.content, version: file.version, revision: file.revision ?? null };
|
|
263
292
|
}
|
|
264
|
-
export function
|
|
265
|
-
|
|
266
|
-
if (scope === undefined) return null;
|
|
267
|
-
return definitionsOf(scope, modelRoot);
|
|
293
|
+
export function viewOf(enumeration, tracked) {
|
|
294
|
+
return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
|
|
268
295
|
}
|
|
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
|
-
};
|
|
296
|
+
export function refreshFrom(view, fromRoomVersion) {
|
|
297
|
+
if (roomVersion(view) === fromRoomVersion)
|
|
298
|
+
return { kind: 'still-current' };
|
|
298
299
|
const documents = {};
|
|
299
300
|
const revisions = {};
|
|
300
|
-
const
|
|
301
|
+
const changes = {};
|
|
302
|
+
const binaryFiles = {};
|
|
301
303
|
const removals = [];
|
|
302
|
-
for (const change of view.changes){
|
|
303
|
-
if (!selects(tracked, change.path)) continue;
|
|
304
|
+
for (const change of view.changes) {
|
|
304
305
|
if ('removed' in change) {
|
|
305
306
|
removals.push(change.path);
|
|
306
307
|
continue;
|
|
307
308
|
}
|
|
308
|
-
if ('content' in change)
|
|
309
|
+
if ('content' in change)
|
|
309
310
|
documents[change.path] = change.content;
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
311
|
+
else
|
|
312
|
+
binaryFiles[change.path] = change.binary;
|
|
313
|
+
if (change.revision !== undefined)
|
|
314
|
+
revisions[change.path] = change.revision;
|
|
315
|
+
if (change.head !== undefined)
|
|
316
|
+
changes[change.path] = change.head;
|
|
315
317
|
}
|
|
316
318
|
return {
|
|
317
319
|
kind: 'net-advancement',
|
|
318
320
|
roomVersion: roomVersion(view),
|
|
319
321
|
documents,
|
|
320
322
|
revisions,
|
|
321
|
-
|
|
322
|
-
|
|
323
|
+
changes,
|
|
324
|
+
binaryFiles,
|
|
325
|
+
removals: removals.sort(),
|
|
323
326
|
};
|
|
324
327
|
}
|
|
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
|
+
}
|
package/dist/refusal.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal } from '@agentshouse/mdruntime';
|
|
2
|
-
export
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
2
|
+
export declare function doorRefusal(body: unknown): ProviderRefusal | null;
|
|
3
|
+
export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: ProviderRefusal): ScopedRefusal;
|
|
4
|
+
export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | null;
|
|
5
|
+
export declare function classifyRead(status: number, body: unknown, locator: string): AdapterFailure | {
|
|
6
6
|
kind: 'beyond-horizon';
|
|
7
7
|
} | null;
|
|
8
|
-
export declare function discoveryFailure(
|
|
9
|
-
kind: 'beyond-horizon';
|
|
10
|
-
}): DiscoverResult;
|
|
8
|
+
export declare function discoveryFailure(status: number, body: unknown): DiscoverResult | null;
|
|
11
9
|
//# sourceMappingURL=refusal.d.ts.map
|
package/dist/refusal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACd,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACd,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAOjE;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,eAAe,GACvB,aAAa,CAEf;AAmBD,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,cAAc,GAAG,IAAI,CAMvB;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,cAAc,GAAG;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAAG,IAAI,CAGpD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAQrF"}
|