@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c506c7d6e6199
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 +156 -27
- package/README.md +32 -0
- package/dist/actions.d.ts +4 -12
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +239 -332
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +271 -197
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +22 -26
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +154 -223
- package/dist/gather.d.ts +3 -0
- package/dist/gather.d.ts.map +1 -0
- package/dist/gather.js +40 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -3
- package/dist/links.d.ts +12 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +66 -0
- 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 +2 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +21 -39
- package/dist/read.d.ts +31 -26
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +208 -199
- package/dist/refusal.d.ts +3 -1
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +27 -62
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +110 -124
- package/dist/stream.d.ts +11 -5
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +209 -213
- package/dist/transport.d.ts +45 -28
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +2 -3
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +23 -18
- package/dist/write.d.ts +5 -7
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +127 -215
- package/package.json +4 -12
- 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,176 @@
|
|
|
1
|
-
import { PROVIDER_SELECTION_ROOTS } from './discovery.js';
|
|
2
1
|
import { readPosition, roomVersion } from './version.js';
|
|
3
2
|
export function authorityRoot(handle) {
|
|
4
|
-
return
|
|
5
|
-
}
|
|
6
|
-
export const ROOM_README = 'ROOM.md';
|
|
7
|
-
export function selectionRoots(tracked) {
|
|
8
|
-
if (tracked.handle === undefined) {
|
|
9
|
-
return [
|
|
10
|
-
tracked.collectionRoot,
|
|
11
|
-
...PROVIDER_SELECTION_ROOTS
|
|
12
|
-
];
|
|
13
|
-
}
|
|
14
|
-
return [
|
|
15
|
-
ROOM_README,
|
|
16
|
-
tracked.collectionRoot
|
|
17
|
-
];
|
|
3
|
+
return `/rooms/${handle}`;
|
|
18
4
|
}
|
|
19
5
|
export function contentPrefixes(tracked) {
|
|
20
|
-
|
|
21
|
-
return selectionRoots(tracked).filter((entry)=>entry !== ROOM_README).map((entry)=>`${root}/${entry}`);
|
|
6
|
+
return [authorityRoot(tracked.handle)];
|
|
22
7
|
}
|
|
23
|
-
export function
|
|
24
|
-
return `${authorityRoot(
|
|
8
|
+
export function schemaPath(handle, schema) {
|
|
9
|
+
return `${authorityRoot(handle)}/${schema}`;
|
|
25
10
|
}
|
|
26
11
|
export function parseGrant(body) {
|
|
27
|
-
if (typeof body !== 'object' || body === null)
|
|
12
|
+
if (typeof body !== 'object' || body === null)
|
|
13
|
+
return null;
|
|
28
14
|
if (!('transfer' in body) || typeof body.transfer !== 'object' || body.transfer === null) {
|
|
29
15
|
return null;
|
|
30
16
|
}
|
|
31
17
|
const transfer = body.transfer;
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
method: transfer.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
18
|
+
if (typeof transfer.url !== 'string')
|
|
19
|
+
return null;
|
|
20
|
+
if (transfer.method === 'GET')
|
|
21
|
+
return { method: 'GET', url: transfer.url };
|
|
22
|
+
if (transfer.method !== 'POST' || typeof transfer.operation !== 'string')
|
|
23
|
+
return null;
|
|
24
|
+
return { method: 'POST', operation: transfer.operation, url: transfer.url };
|
|
25
|
+
}
|
|
26
|
+
function changeAuthor(value) {
|
|
27
|
+
if (typeof value !== 'object' || value === null)
|
|
28
|
+
return null;
|
|
29
|
+
const { user, site, name } = value;
|
|
30
|
+
if (typeof name !== 'string')
|
|
31
|
+
return null;
|
|
32
|
+
if (typeof user === 'string' && site === undefined)
|
|
33
|
+
return { kind: 'user', id: user, name };
|
|
34
|
+
if (typeof site === 'string' && user === undefined)
|
|
35
|
+
return { kind: 'site', id: site, name };
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
export function headChange(held) {
|
|
39
|
+
const author = held.author === undefined ? null : changeAuthor(held.author);
|
|
40
|
+
if (held.author !== undefined && author === null)
|
|
41
|
+
return null;
|
|
42
|
+
if (held.created_at === undefined)
|
|
43
|
+
return undefined;
|
|
44
|
+
if (typeof held.created_at !== 'string')
|
|
45
|
+
return null;
|
|
46
|
+
return { author, time: held.created_at };
|
|
47
|
+
}
|
|
48
|
+
function headed(head) {
|
|
49
|
+
return head === undefined ? {} : { head };
|
|
50
|
+
}
|
|
51
|
+
function parseOriginal(value) {
|
|
52
|
+
if (typeof value !== 'object' || value === null)
|
|
53
|
+
return null;
|
|
54
|
+
const { attachment, name, bytes, media_type: mediaType } = value;
|
|
55
|
+
if (typeof attachment !== 'string' || typeof name !== 'string')
|
|
56
|
+
return null;
|
|
57
|
+
if (typeof bytes !== 'number' || !Number.isSafeInteger(bytes) || bytes < 0)
|
|
58
|
+
return null;
|
|
59
|
+
if (mediaType !== null && typeof mediaType !== 'string')
|
|
60
|
+
return null;
|
|
61
|
+
return { reference: attachment, name, byteLength: bytes, mediaType, entry: value };
|
|
62
|
+
}
|
|
63
|
+
function parseOriginals(value) {
|
|
64
|
+
if (!Array.isArray(value))
|
|
65
|
+
return null;
|
|
66
|
+
const attachments = [];
|
|
67
|
+
for (const entry of value) {
|
|
68
|
+
const attachment = parseOriginal(entry);
|
|
69
|
+
if (attachment === null)
|
|
70
|
+
return null;
|
|
71
|
+
attachments.push(attachment);
|
|
72
|
+
}
|
|
73
|
+
return attachments;
|
|
74
|
+
}
|
|
75
|
+
function declared(attachments) {
|
|
76
|
+
return attachments === undefined ? {} : { attachments };
|
|
39
77
|
}
|
|
40
78
|
function parseFile(value, mode) {
|
|
41
|
-
if (typeof value !== 'object' || value === null)
|
|
79
|
+
if (typeof value !== 'object' || value === null)
|
|
80
|
+
return null;
|
|
42
81
|
const file = value;
|
|
43
|
-
if (typeof file.path !== 'string')
|
|
82
|
+
if (typeof file.path !== 'string')
|
|
83
|
+
return null;
|
|
84
|
+
const head = headChange(file);
|
|
85
|
+
if (head === null)
|
|
86
|
+
return null;
|
|
44
87
|
if (mode === 'site') {
|
|
45
|
-
if (typeof file.sha256 !== 'string')
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
revision: undefined,
|
|
49
|
-
version: file.sha256
|
|
50
|
-
};
|
|
88
|
+
if (typeof file.sha256 !== 'string')
|
|
89
|
+
return null;
|
|
90
|
+
return { path: file.path, revision: undefined, version: file.sha256, ...headed(head) };
|
|
51
91
|
}
|
|
52
|
-
if (typeof file.revision !== 'string')
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
revision: file.revision,
|
|
56
|
-
version: file.revision
|
|
57
|
-
};
|
|
92
|
+
if (typeof file.revision !== 'string')
|
|
93
|
+
return null;
|
|
94
|
+
return { path: file.path, revision: file.revision, version: file.revision, ...headed(head) };
|
|
58
95
|
}
|
|
59
96
|
function parseScope(value, mode) {
|
|
60
|
-
if (typeof value !== 'object' || value === null)
|
|
97
|
+
if (typeof value !== 'object' || value === null)
|
|
98
|
+
return null;
|
|
61
99
|
const held = value;
|
|
62
|
-
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
63
|
-
|
|
100
|
+
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
101
|
+
return null;
|
|
102
|
+
if (!Array.isArray(held.contents))
|
|
103
|
+
return null;
|
|
64
104
|
const manifest = held.manifest;
|
|
65
|
-
if (manifest.scope !== 'room'
|
|
105
|
+
if (manifest.scope !== 'room')
|
|
106
|
+
return null;
|
|
66
107
|
const at = readPosition(manifest);
|
|
67
|
-
if (typeof manifest.anchor !== 'string' || at === null)
|
|
68
|
-
|
|
108
|
+
if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)
|
|
109
|
+
return null;
|
|
110
|
+
if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
|
|
111
|
+
return null;
|
|
112
|
+
if (!Array.isArray(manifest.files))
|
|
113
|
+
return null;
|
|
69
114
|
const files = [];
|
|
70
|
-
for (const entry of manifest.files){
|
|
115
|
+
for (const entry of manifest.files) {
|
|
71
116
|
const file = parseFile(entry, mode);
|
|
72
|
-
if (file === null)
|
|
117
|
+
if (file === null)
|
|
118
|
+
return null;
|
|
73
119
|
files.push(file);
|
|
74
120
|
}
|
|
75
121
|
const contents = [];
|
|
76
|
-
for (const entry of held.contents){
|
|
77
|
-
if (typeof entry !== 'object' || entry === null)
|
|
122
|
+
for (const entry of held.contents) {
|
|
123
|
+
if (typeof entry !== 'object' || entry === null)
|
|
124
|
+
return null;
|
|
78
125
|
const content = entry;
|
|
79
|
-
if (typeof content.path !== 'string' || typeof content.content !== 'string')
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
content: content.content
|
|
83
|
-
});
|
|
126
|
+
if (typeof content.path !== 'string' || typeof content.content !== 'string')
|
|
127
|
+
return null;
|
|
128
|
+
contents.push({ path: content.path, content: content.content });
|
|
84
129
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
contents
|
|
92
|
-
};
|
|
130
|
+
if (mode === 'site')
|
|
131
|
+
return { anchor: manifest.anchor, ...at, files, contents };
|
|
132
|
+
const attachments = parseOriginals(held.originals);
|
|
133
|
+
if (attachments === null)
|
|
134
|
+
return null;
|
|
135
|
+
return { anchor: manifest.anchor, ...at, files, contents, attachments };
|
|
93
136
|
}
|
|
94
137
|
export function parseEnvelope(body) {
|
|
95
|
-
if (typeof body !== 'object' || body === null)
|
|
96
|
-
|
|
138
|
+
if (typeof body !== 'object' || body === null)
|
|
139
|
+
return null;
|
|
140
|
+
if (!('scopes' in body) || !Array.isArray(body.scopes))
|
|
141
|
+
return null;
|
|
97
142
|
const scopes = [];
|
|
98
|
-
for (const entry of body.scopes){
|
|
143
|
+
for (const entry of body.scopes) {
|
|
99
144
|
const scope = parseScope(entry, 'credential');
|
|
100
|
-
if (scope === null)
|
|
145
|
+
if (scope === null)
|
|
146
|
+
return null;
|
|
101
147
|
scopes.push(scope);
|
|
102
148
|
}
|
|
103
|
-
return {
|
|
104
|
-
scopes
|
|
105
|
-
};
|
|
149
|
+
return { scopes };
|
|
106
150
|
}
|
|
107
151
|
export function parseSiteBootstrap(body) {
|
|
108
|
-
|
|
109
|
-
return scope !== null && scope.scope === 'room' ? scope : null;
|
|
152
|
+
return parseScope(body, 'site');
|
|
110
153
|
}
|
|
111
154
|
function parseChange(value, mode) {
|
|
112
|
-
if (typeof value !== 'object' || value === null)
|
|
155
|
+
if (typeof value !== 'object' || value === null)
|
|
156
|
+
return null;
|
|
113
157
|
const held = value;
|
|
114
|
-
if (typeof held.path !== 'string')
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
removed: true
|
|
118
|
-
|
|
158
|
+
if (typeof held.path !== 'string')
|
|
159
|
+
return null;
|
|
160
|
+
if (held.removed === true)
|
|
161
|
+
return { path: held.path, removed: true };
|
|
162
|
+
const head = headChange(held);
|
|
163
|
+
if (head === null)
|
|
164
|
+
return null;
|
|
119
165
|
if (mode === 'site') {
|
|
120
|
-
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
166
|
+
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
167
|
+
return null;
|
|
121
168
|
return {
|
|
122
169
|
path: held.path,
|
|
123
170
|
content: held.content,
|
|
124
171
|
revision: undefined,
|
|
125
|
-
version: held.sha256
|
|
172
|
+
version: held.sha256,
|
|
173
|
+
...headed(head),
|
|
126
174
|
};
|
|
127
175
|
}
|
|
128
176
|
if (typeof held.content === 'string' && typeof held.revision === 'string') {
|
|
@@ -130,184 +178,145 @@ function parseChange(value, mode) {
|
|
|
130
178
|
path: held.path,
|
|
131
179
|
content: held.content,
|
|
132
180
|
revision: held.revision,
|
|
133
|
-
version: held.revision
|
|
181
|
+
version: held.revision,
|
|
182
|
+
...headed(head),
|
|
134
183
|
};
|
|
135
184
|
}
|
|
136
185
|
if (typeof held.reference === 'object' && held.reference !== null) {
|
|
137
186
|
const reference = held.reference;
|
|
138
|
-
if (typeof reference.revision !== 'string')
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
reference: {
|
|
142
|
-
revision: reference.revision
|
|
143
|
-
}
|
|
144
|
-
};
|
|
187
|
+
if (typeof reference.revision !== 'string')
|
|
188
|
+
return null;
|
|
189
|
+
return { path: held.path, reference: { revision: reference.revision } };
|
|
145
190
|
}
|
|
146
191
|
return null;
|
|
147
192
|
}
|
|
148
193
|
export function parseEnumeration(body, mode) {
|
|
149
|
-
if (typeof body !== 'object' || body === null)
|
|
150
|
-
|
|
194
|
+
if (typeof body !== 'object' || body === null)
|
|
195
|
+
return null;
|
|
196
|
+
if (!('authorities' in body) || !Array.isArray(body.authorities))
|
|
197
|
+
return null;
|
|
151
198
|
const authorities = [];
|
|
152
|
-
for (const entry of body.authorities){
|
|
153
|
-
if (typeof entry !== 'object' || entry === null)
|
|
199
|
+
for (const entry of body.authorities) {
|
|
200
|
+
if (typeof entry !== 'object' || entry === null)
|
|
201
|
+
return null;
|
|
154
202
|
const held = entry;
|
|
155
203
|
const at = readPosition(held);
|
|
156
|
-
if (typeof held.authority !== 'string' || at === null)
|
|
157
|
-
|
|
204
|
+
if (typeof held.authority !== 'string' || at === null)
|
|
205
|
+
return null;
|
|
206
|
+
if (!Array.isArray(held.changes))
|
|
207
|
+
return null;
|
|
158
208
|
const changes = [];
|
|
159
|
-
for (const change of held.changes){
|
|
209
|
+
for (const change of held.changes) {
|
|
160
210
|
const mapped = parseChange(change, mode);
|
|
161
|
-
if (mapped === null)
|
|
211
|
+
if (mapped === null)
|
|
212
|
+
return null;
|
|
162
213
|
changes.push(mapped);
|
|
163
214
|
}
|
|
164
|
-
|
|
165
|
-
authority: held.authority,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
215
|
+
if (mode === 'site') {
|
|
216
|
+
authorities.push({ authority: held.authority, ...at, changes });
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const attachments = parseOriginals(held.originals);
|
|
220
|
+
if (attachments === null)
|
|
221
|
+
return null;
|
|
222
|
+
authorities.push({ authority: held.authority, ...at, changes, attachments });
|
|
169
223
|
}
|
|
170
|
-
return {
|
|
171
|
-
authorities
|
|
172
|
-
};
|
|
224
|
+
return { authorities };
|
|
173
225
|
}
|
|
174
226
|
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){
|
|
227
|
+
const files = new Map(scope.files.map((file) => [file.path, file]));
|
|
228
|
+
const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
|
|
229
|
+
for (const change of view.changes) {
|
|
184
230
|
files.delete(change.path);
|
|
185
231
|
contents.delete(change.path);
|
|
186
|
-
if ('removed' in change)
|
|
232
|
+
if ('removed' in change)
|
|
233
|
+
continue;
|
|
187
234
|
if ('content' in change) {
|
|
188
235
|
files.set(change.path, {
|
|
189
236
|
path: change.path,
|
|
190
237
|
revision: change.revision,
|
|
191
|
-
version: change.version
|
|
238
|
+
version: change.version,
|
|
239
|
+
...headed(change.head),
|
|
192
240
|
});
|
|
193
241
|
contents.set(change.path, change.content);
|
|
194
242
|
continue;
|
|
195
243
|
}
|
|
196
244
|
const { revision } = change.reference;
|
|
197
|
-
files.set(change.path, {
|
|
198
|
-
path: change.path,
|
|
199
|
-
revision,
|
|
200
|
-
version: revision
|
|
201
|
-
});
|
|
245
|
+
files.set(change.path, { path: change.path, revision, version: revision });
|
|
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 = {};
|
|
262
|
+
const changes = {};
|
|
244
263
|
const binaryTargets = [];
|
|
245
|
-
for (const file of scope.files){
|
|
246
|
-
if (
|
|
247
|
-
|
|
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 (content === undefined)
|
|
250
|
-
|
|
270
|
+
if (content === undefined)
|
|
271
|
+
binaryTargets.push(file.path);
|
|
272
|
+
else
|
|
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
|
+
binaryTargets: binaryTargets.sort(),
|
|
282
|
+
...declared(scope.attachments),
|
|
258
283
|
};
|
|
259
284
|
}
|
|
260
|
-
export
|
|
261
|
-
|
|
262
|
-
|
|
285
|
+
export function schemaFrom(envelope, tracked, schema) {
|
|
286
|
+
const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));
|
|
287
|
+
if (scope === undefined)
|
|
288
|
+
return null;
|
|
289
|
+
return schemaOf(scope, schema);
|
|
263
290
|
}
|
|
264
|
-
export function
|
|
265
|
-
const
|
|
266
|
-
if (
|
|
267
|
-
|
|
291
|
+
export function schemaOf(scope, schema) {
|
|
292
|
+
const file = scope.files.find((entry) => entry.path === schema);
|
|
293
|
+
if (file === undefined)
|
|
294
|
+
return { schema: null, version: null };
|
|
295
|
+
const content = scope.contents.find((entry) => entry.path === schema);
|
|
296
|
+
return content === undefined ? null : { schema: content.content, version: file.version };
|
|
268
297
|
}
|
|
269
|
-
export function
|
|
270
|
-
|
|
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;
|
|
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
|
-
};
|
|
298
|
+
export function viewOf(enumeration, tracked) {
|
|
299
|
+
return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
|
|
288
300
|
}
|
|
289
|
-
export function refreshFrom(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
kind: 'room-not-readable',
|
|
293
|
-
locator: tracked.locator
|
|
294
|
-
};
|
|
295
|
-
if (roomVersion(view) === fromRoomVersion) return {
|
|
296
|
-
kind: 'still-current'
|
|
297
|
-
};
|
|
301
|
+
export function refreshFrom(view, fromRoomVersion) {
|
|
302
|
+
if (roomVersion(view) === fromRoomVersion)
|
|
303
|
+
return { kind: 'still-current' };
|
|
298
304
|
const documents = {};
|
|
299
305
|
const revisions = {};
|
|
306
|
+
const changes = {};
|
|
300
307
|
const binaryTargets = [];
|
|
301
308
|
const removals = [];
|
|
302
|
-
for (const change of view.changes){
|
|
303
|
-
if (!selects(tracked, change.path)) continue;
|
|
309
|
+
for (const change of view.changes) {
|
|
304
310
|
if ('removed' in change) {
|
|
305
311
|
removals.push(change.path);
|
|
306
312
|
continue;
|
|
307
313
|
}
|
|
308
314
|
if ('content' in change) {
|
|
309
315
|
documents[change.path] = change.content;
|
|
310
|
-
if (change.revision !== undefined)
|
|
316
|
+
if (change.revision !== undefined)
|
|
317
|
+
revisions[change.path] = change.revision;
|
|
318
|
+
if (change.head !== undefined)
|
|
319
|
+
changes[change.path] = change.head;
|
|
311
320
|
continue;
|
|
312
321
|
}
|
|
313
322
|
binaryTargets.push(change.path);
|
|
@@ -318,9 +327,9 @@ export function refreshFrom(enumeration, tracked, fromRoomVersion) {
|
|
|
318
327
|
roomVersion: roomVersion(view),
|
|
319
328
|
documents,
|
|
320
329
|
revisions,
|
|
330
|
+
changes,
|
|
321
331
|
binaryTargets: binaryTargets.sort(),
|
|
322
|
-
removals: removals.sort()
|
|
332
|
+
removals: removals.sort(),
|
|
333
|
+
...declared(view.attachments),
|
|
323
334
|
};
|
|
324
335
|
}
|
|
325
|
-
|
|
326
|
-
//# sourceMappingURL=read.js.map
|
package/dist/refusal.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal } from '@agentshouse/mdruntime';
|
|
2
|
-
export type DoorRefusal = ProviderRefusal
|
|
2
|
+
export type DoorRefusal = ProviderRefusal & {
|
|
3
|
+
retryable: boolean;
|
|
4
|
+
};
|
|
3
5
|
export declare function doorRefusal(body: unknown): DoorRefusal | null;
|
|
4
6
|
export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: DoorRefusal): ScopedRefusal;
|
|
5
7
|
export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | {
|
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,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAEnE,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAO7D;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,WAAW,GACnB,aAAa,CAEf;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,CAapD;AAED,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,cAAc,GAAG;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GACtD,cAAc,CAMhB"}
|
package/dist/refusal.js
CHANGED
|
@@ -1,78 +1,43 @@
|
|
|
1
|
-
const RETRYABLE_CODES = new Set([
|
|
2
|
-
'auth_unavailable',
|
|
3
|
-
'replica_behind',
|
|
4
|
-
'read_replica_unavailable',
|
|
5
|
-
'read_replica_lagging',
|
|
6
|
-
'read_pool_acquisition_timed_out',
|
|
7
|
-
'sync_unavailable',
|
|
8
|
-
'sync_failed',
|
|
9
|
-
'rate_limited',
|
|
10
|
-
'operation_contended',
|
|
11
|
-
'service_mode_write_halted',
|
|
12
|
-
'transaction_budget_exceeded'
|
|
13
|
-
]);
|
|
14
1
|
export function doorRefusal(body) {
|
|
15
|
-
if (typeof body !== 'object' || body === null)
|
|
16
|
-
|
|
2
|
+
if (typeof body !== 'object' || body === null)
|
|
3
|
+
return null;
|
|
4
|
+
if (!('error' in body) || typeof body.error !== 'object' || body.error === null)
|
|
5
|
+
return null;
|
|
17
6
|
const error = body.error;
|
|
18
|
-
if (typeof error.code !== 'string')
|
|
7
|
+
if (typeof error.code !== 'string')
|
|
8
|
+
return null;
|
|
19
9
|
const { code, ...fields } = error;
|
|
20
|
-
return {
|
|
21
|
-
code,
|
|
22
|
-
fields
|
|
23
|
-
};
|
|
10
|
+
return { code, fields, retryable: error.retryable === true };
|
|
24
11
|
}
|
|
25
12
|
export function scopedRefusal(locator, scope, refusal) {
|
|
26
|
-
return {
|
|
27
|
-
kind: 'scoped-refusal',
|
|
28
|
-
locator,
|
|
29
|
-
scope,
|
|
30
|
-
code: refusal.code,
|
|
31
|
-
fields: refusal.fields
|
|
32
|
-
};
|
|
13
|
+
return { kind: 'scoped-refusal', locator, scope, code: refusal.code, fields: refusal.fields };
|
|
33
14
|
}
|
|
34
15
|
export function classifyDoor(status, body, locator) {
|
|
35
|
-
if (status === 0)
|
|
36
|
-
kind: 'transport-uncertainty'
|
|
37
|
-
};
|
|
16
|
+
if (status === 0)
|
|
17
|
+
return { kind: 'transport-uncertainty' };
|
|
38
18
|
const refusal = doorRefusal(body);
|
|
39
|
-
if (status === 401)
|
|
40
|
-
kind: 'revoked-authorization'
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (refusal !== null && refusal.code === 'position_expired') return {
|
|
46
|
-
kind: 'beyond-horizon'
|
|
47
|
-
};
|
|
19
|
+
if (status === 401)
|
|
20
|
+
return { kind: 'revoked-authorization' };
|
|
21
|
+
if (refusal?.retryable === true)
|
|
22
|
+
return { kind: 'transport-uncertainty' };
|
|
23
|
+
if (refusal !== null && refusal.code === 'position_expired')
|
|
24
|
+
return { kind: 'beyond-horizon' };
|
|
48
25
|
if (status === 404 || refusal?.code === 'room_not_found') {
|
|
49
|
-
return {
|
|
50
|
-
kind: 'room-not-readable',
|
|
51
|
-
locator
|
|
52
|
-
};
|
|
26
|
+
return { kind: 'room-not-readable', locator };
|
|
53
27
|
}
|
|
54
|
-
if (status
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
if (status === 403) return scopedRefusal(locator, 'operation', refusal);
|
|
28
|
+
if (status < 400)
|
|
29
|
+
return null;
|
|
30
|
+
if (refusal === null)
|
|
31
|
+
return { kind: 'transport-uncertainty' };
|
|
32
|
+
if (status === 403)
|
|
33
|
+
return scopedRefusal(locator, 'operation', refusal);
|
|
62
34
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
63
35
|
}
|
|
64
36
|
export function discoveryFailure(classified) {
|
|
65
|
-
if (classified.kind === 'revoked-authorization')
|
|
37
|
+
if (classified.kind === 'revoked-authorization')
|
|
38
|
+
return classified;
|
|
66
39
|
if (classified.kind === 'scoped-refusal') {
|
|
67
|
-
return {
|
|
68
|
-
kind: 'contract-unavailable',
|
|
69
|
-
code: classified.code,
|
|
70
|
-
fields: classified.fields
|
|
71
|
-
};
|
|
40
|
+
return { kind: 'contract-unavailable', code: classified.code, fields: classified.fields };
|
|
72
41
|
}
|
|
73
|
-
return {
|
|
74
|
-
kind: 'transport-uncertainty'
|
|
75
|
-
};
|
|
42
|
+
return { kind: 'transport-uncertainty' };
|
|
76
43
|
}
|
|
77
|
-
|
|
78
|
-
//# sourceMappingURL=refusal.js.map
|
package/dist/site.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,
|
|
1
|
+
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAQR,MAAM,wBAAwB,CAAC;AA+BhC,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAsCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAuKxE"}
|