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