@agentshouse/mdruntime-adapter 0.1.0-c9f1e531ad7c8 → 0.1.0-ca3a44982cbe7
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 +181 -92
- package/README.md +3 -3
- package/dist/actions.d.ts +43 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +141 -123
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +231 -156
- package/dist/discovery.d.ts +14 -27
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +56 -102
- package/dist/gather.d.ts +1 -0
- package/dist/gather.d.ts.map +1 -1
- package/dist/gather.js +11 -6
- 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 -1
- package/dist/model.d.ts +8 -18
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +63 -39
- package/dist/read.d.ts +16 -11
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +80 -106
- 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 +31 -32
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +89 -84
- package/dist/stream.d.ts +9 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +115 -77
- package/dist/transport.d.ts +50 -20
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +3 -2
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +9 -0
- package/dist/write.d.ts +4 -5
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +98 -25
- package/package.json +4 -4
- package/dist/links.d.ts +0 -12
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -66
package/dist/read.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { PRIVATE_HANDLE, UNTYPED_FOLDERS, PROVIDER_SELECTION_ROOTS, RESERVED_NAMES, } from './discovery.js';
|
|
2
1
|
import { readPosition, roomVersion } from './version.js';
|
|
3
2
|
export function authorityRoot(handle) {
|
|
4
3
|
return `/rooms/${handle}`;
|
|
5
4
|
}
|
|
6
5
|
export function contentPrefixes(tracked) {
|
|
7
|
-
return [
|
|
6
|
+
return [
|
|
7
|
+
authorityRoot(tracked.handle),
|
|
8
|
+
...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
|
|
9
|
+
];
|
|
8
10
|
}
|
|
9
11
|
export function schemaPath(handle, schema) {
|
|
10
12
|
return `${authorityRoot(handle)}/${schema}`;
|
|
@@ -49,32 +51,19 @@ export function headChange(held) {
|
|
|
49
51
|
function headed(head) {
|
|
50
52
|
return head === undefined ? {} : { head };
|
|
51
53
|
}
|
|
52
|
-
function
|
|
53
|
-
if (
|
|
54
|
-
return
|
|
55
|
-
const {
|
|
56
|
-
if (typeof
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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))
|
|
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')
|
|
66
62
|
return null;
|
|
67
|
-
|
|
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;
|
|
63
|
+
return { fileRef: file, byteLength: bytes, mediaType, sha256 };
|
|
75
64
|
}
|
|
76
|
-
function
|
|
77
|
-
return
|
|
65
|
+
function binaried(binary) {
|
|
66
|
+
return binary === undefined ? {} : { binary };
|
|
78
67
|
}
|
|
79
68
|
function parseFile(value, mode) {
|
|
80
69
|
if (typeof value !== 'object' || value === null)
|
|
@@ -83,16 +72,29 @@ function parseFile(value, mode) {
|
|
|
83
72
|
if (typeof file.path !== 'string')
|
|
84
73
|
return null;
|
|
85
74
|
const head = headChange(file);
|
|
86
|
-
|
|
75
|
+
const binary = binaryFileOf(file);
|
|
76
|
+
if (head === null || binary === null)
|
|
87
77
|
return null;
|
|
88
78
|
if (mode === 'site') {
|
|
89
79
|
if (typeof file.sha256 !== 'string')
|
|
90
80
|
return null;
|
|
91
|
-
return {
|
|
81
|
+
return {
|
|
82
|
+
path: file.path,
|
|
83
|
+
revision: binary?.sha256,
|
|
84
|
+
version: file.sha256,
|
|
85
|
+
...headed(head),
|
|
86
|
+
...binaried(binary),
|
|
87
|
+
};
|
|
92
88
|
}
|
|
93
89
|
if (typeof file.revision !== 'string')
|
|
94
90
|
return null;
|
|
95
|
-
return {
|
|
91
|
+
return {
|
|
92
|
+
path: file.path,
|
|
93
|
+
revision: file.revision,
|
|
94
|
+
version: file.revision,
|
|
95
|
+
...headed(head),
|
|
96
|
+
...binaried(binary),
|
|
97
|
+
};
|
|
96
98
|
}
|
|
97
99
|
function parseScope(value, mode) {
|
|
98
100
|
if (typeof value !== 'object' || value === null)
|
|
@@ -128,12 +130,15 @@ function parseScope(value, mode) {
|
|
|
128
130
|
return null;
|
|
129
131
|
contents.push({ path: content.path, content: content.content });
|
|
130
132
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (
|
|
133
|
+
return { anchor: manifest.anchor, ...at, files, contents };
|
|
134
|
+
}
|
|
135
|
+
function parseCursor(value) {
|
|
136
|
+
if (typeof value !== 'object' || value === null)
|
|
135
137
|
return null;
|
|
136
|
-
|
|
138
|
+
const { room, path } = value;
|
|
139
|
+
if (typeof room !== 'string' || (path !== null && typeof path !== 'string'))
|
|
140
|
+
return null;
|
|
141
|
+
return { room, path };
|
|
137
142
|
}
|
|
138
143
|
export function parseEnvelope(body) {
|
|
139
144
|
if (typeof body !== 'object' || body === null)
|
|
@@ -147,7 +152,10 @@ export function parseEnvelope(body) {
|
|
|
147
152
|
return null;
|
|
148
153
|
scopes.push(scope);
|
|
149
154
|
}
|
|
150
|
-
|
|
155
|
+
if (!('next' in body) || body.next === undefined)
|
|
156
|
+
return { scopes };
|
|
157
|
+
const next = parseCursor(body.next);
|
|
158
|
+
return next === null ? null : { scopes, next };
|
|
151
159
|
}
|
|
152
160
|
export function parseSiteBootstrap(body) {
|
|
153
161
|
return parseScope(body, 'site');
|
|
@@ -161,8 +169,15 @@ function parseChange(value, mode) {
|
|
|
161
169
|
if (held.removed === true)
|
|
162
170
|
return { path: held.path, removed: true };
|
|
163
171
|
const head = headChange(held);
|
|
164
|
-
|
|
172
|
+
const binary = binaryFileOf(held);
|
|
173
|
+
if (head === null || binary === null)
|
|
165
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
|
+
}
|
|
166
181
|
if (mode === 'site') {
|
|
167
182
|
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
168
183
|
return null;
|
|
@@ -183,12 +198,6 @@ function parseChange(value, mode) {
|
|
|
183
198
|
...headed(head),
|
|
184
199
|
};
|
|
185
200
|
}
|
|
186
|
-
if (typeof held.reference === 'object' && held.reference !== null) {
|
|
187
|
-
const reference = held.reference;
|
|
188
|
-
if (typeof reference.revision !== 'string')
|
|
189
|
-
return null;
|
|
190
|
-
return { path: held.path, reference: { revision: reference.revision } };
|
|
191
|
-
}
|
|
192
201
|
return null;
|
|
193
202
|
}
|
|
194
203
|
export function parseEnumeration(body, mode) {
|
|
@@ -213,14 +222,7 @@ export function parseEnumeration(body, mode) {
|
|
|
213
222
|
return null;
|
|
214
223
|
changes.push(mapped);
|
|
215
224
|
}
|
|
216
|
-
|
|
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 });
|
|
225
|
+
authorities.push({ authority: held.authority, ...at, changes });
|
|
224
226
|
}
|
|
225
227
|
return { authorities };
|
|
226
228
|
}
|
|
@@ -232,18 +234,15 @@ export function advancedScope(scope, view) {
|
|
|
232
234
|
contents.delete(change.path);
|
|
233
235
|
if ('removed' in change)
|
|
234
236
|
continue;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
237
|
+
files.set(change.path, {
|
|
238
|
+
path: change.path,
|
|
239
|
+
revision: change.revision,
|
|
240
|
+
version: change.version,
|
|
241
|
+
...headed(change.head),
|
|
242
|
+
...('binary' in change ? { binary: change.binary } : {}),
|
|
243
|
+
});
|
|
244
|
+
if ('content' in change)
|
|
242
245
|
contents.set(change.path, change.content);
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
const { revision } = change.reference;
|
|
246
|
-
files.set(change.path, { path: change.path, revision, version: revision });
|
|
247
246
|
}
|
|
248
247
|
return {
|
|
249
248
|
...scope,
|
|
@@ -256,36 +255,21 @@ export function advancedScope(scope, view) {
|
|
|
256
255
|
export function matchesScope(scope, tracked) {
|
|
257
256
|
return scope.anchor === tracked.authority;
|
|
258
257
|
}
|
|
259
|
-
|
|
260
|
-
function homes(tracked) {
|
|
261
|
-
return tracked.handle === PRIVATE_HANDLE
|
|
262
|
-
? [...ROOM_HOMES, ...PROVIDER_SELECTION_ROOTS]
|
|
263
|
-
: ROOM_HOMES;
|
|
264
|
-
}
|
|
265
|
-
export function selects(tracked, path) {
|
|
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}/`)));
|
|
271
|
-
}
|
|
272
|
-
export function bootstrapOf(scope, tracked) {
|
|
258
|
+
export function bootstrapOf(scope) {
|
|
273
259
|
const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
|
|
274
260
|
const documents = {};
|
|
275
261
|
const revisions = {};
|
|
276
262
|
const changes = {};
|
|
277
|
-
const
|
|
263
|
+
const binaryFiles = {};
|
|
278
264
|
for (const file of scope.files) {
|
|
279
|
-
if (!selects(tracked, file.path))
|
|
280
|
-
continue;
|
|
281
265
|
if (file.revision !== undefined)
|
|
282
266
|
revisions[file.path] = file.revision;
|
|
283
267
|
if (file.head !== undefined)
|
|
284
268
|
changes[file.path] = file.head;
|
|
285
269
|
const content = contents.get(file.path);
|
|
286
|
-
if (
|
|
287
|
-
|
|
288
|
-
else
|
|
270
|
+
if (file.binary !== undefined)
|
|
271
|
+
binaryFiles[file.path] = file.binary;
|
|
272
|
+
else if (content !== undefined)
|
|
289
273
|
documents[file.path] = content;
|
|
290
274
|
}
|
|
291
275
|
return {
|
|
@@ -294,51 +278,42 @@ export function bootstrapOf(scope, tracked) {
|
|
|
294
278
|
documents,
|
|
295
279
|
revisions,
|
|
296
280
|
changes,
|
|
297
|
-
|
|
298
|
-
...declared(scope.attachments),
|
|
281
|
+
binaryFiles,
|
|
299
282
|
};
|
|
300
283
|
}
|
|
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);
|
|
306
|
-
}
|
|
307
284
|
export function schemaOf(scope, schema) {
|
|
308
285
|
const file = scope.files.find((entry) => entry.path === schema);
|
|
309
286
|
if (file === undefined)
|
|
310
|
-
return { schema: null, version: null };
|
|
287
|
+
return { schema: null, version: null, revision: null };
|
|
311
288
|
const content = scope.contents.find((entry) => entry.path === schema);
|
|
312
|
-
return content === undefined
|
|
289
|
+
return content === undefined
|
|
290
|
+
? null
|
|
291
|
+
: { schema: content.content, version: file.version, revision: file.revision ?? null };
|
|
313
292
|
}
|
|
314
293
|
export function viewOf(enumeration, tracked) {
|
|
315
294
|
return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
|
|
316
295
|
}
|
|
317
|
-
export function refreshFrom(view,
|
|
296
|
+
export function refreshFrom(view, fromRoomVersion) {
|
|
318
297
|
if (roomVersion(view) === fromRoomVersion)
|
|
319
298
|
return { kind: 'still-current' };
|
|
320
299
|
const documents = {};
|
|
321
300
|
const revisions = {};
|
|
322
301
|
const changes = {};
|
|
323
|
-
const
|
|
302
|
+
const binaryFiles = {};
|
|
324
303
|
const removals = [];
|
|
325
304
|
for (const change of view.changes) {
|
|
326
|
-
if (!selects(tracked, change.path))
|
|
327
|
-
continue;
|
|
328
305
|
if ('removed' in change) {
|
|
329
306
|
removals.push(change.path);
|
|
330
307
|
continue;
|
|
331
308
|
}
|
|
332
|
-
if ('content' in change)
|
|
309
|
+
if ('content' in change)
|
|
333
310
|
documents[change.path] = change.content;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
binaryTargets.push(change.path);
|
|
341
|
-
revisions[change.path] = change.reference.revision;
|
|
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;
|
|
342
317
|
}
|
|
343
318
|
return {
|
|
344
319
|
kind: 'net-advancement',
|
|
@@ -346,8 +321,7 @@ export function refreshFrom(view, tracked, fromRoomVersion) {
|
|
|
346
321
|
documents,
|
|
347
322
|
revisions,
|
|
348
323
|
changes,
|
|
349
|
-
|
|
324
|
+
binaryFiles,
|
|
350
325
|
removals: removals.sort(),
|
|
351
|
-
...declared(view.attachments),
|
|
352
326
|
};
|
|
353
327
|
}
|
|
@@ -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"}
|
package/dist/refusal.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
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
|
-
'transaction_budget_exceeded',
|
|
12
|
-
]);
|
|
13
1
|
export function doorRefusal(body) {
|
|
14
2
|
if (typeof body !== 'object' || body === null)
|
|
15
3
|
return null;
|
|
@@ -18,40 +6,51 @@ export function doorRefusal(body) {
|
|
|
18
6
|
const error = body.error;
|
|
19
7
|
if (typeof error.code !== 'string')
|
|
20
8
|
return null;
|
|
21
|
-
const { code, ...fields } = error;
|
|
22
|
-
return { code, fields };
|
|
9
|
+
const { code, retryable, ...fields } = error;
|
|
10
|
+
return { code, fields, retryable: retryable === true };
|
|
23
11
|
}
|
|
24
12
|
export function scopedRefusal(locator, scope, refusal) {
|
|
25
|
-
return { kind: 'scoped-refusal', locator, scope,
|
|
13
|
+
return { kind: 'scoped-refusal', locator, scope, ...refusal };
|
|
26
14
|
}
|
|
27
|
-
|
|
15
|
+
function doorFailure(status, body) {
|
|
28
16
|
if (status === 0)
|
|
29
17
|
return { kind: 'transport-uncertainty' };
|
|
30
18
|
const refusal = doorRefusal(body);
|
|
31
19
|
if (status === 401)
|
|
32
20
|
return { kind: 'revoked-authorization' };
|
|
33
|
-
if (refusal
|
|
34
|
-
return { kind: 'transport-uncertainty' };
|
|
35
|
-
if (refusal !== null && refusal.code === 'position_expired')
|
|
36
|
-
return { kind: 'beyond-horizon' };
|
|
37
|
-
if (status === 404 || refusal?.code === 'room_not_found') {
|
|
38
|
-
return { kind: 'room-not-readable', locator };
|
|
39
|
-
}
|
|
40
|
-
if (status >= 500)
|
|
21
|
+
if (refusal?.retryable === true)
|
|
41
22
|
return { kind: 'transport-uncertainty' };
|
|
23
|
+
if (status === 404 || refusal?.code === 'room_not_found')
|
|
24
|
+
return { kind: 'room-not-readable' };
|
|
42
25
|
if (status < 400)
|
|
43
26
|
return null;
|
|
44
27
|
if (refusal === null)
|
|
45
28
|
return { kind: 'transport-uncertainty' };
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
29
|
+
return { kind: 'refused', scope: status === 403 ? 'operation' : 'undisclosed', refusal };
|
|
30
|
+
}
|
|
31
|
+
export function classifyDoor(status, body, locator) {
|
|
32
|
+
const failure = doorFailure(status, body);
|
|
33
|
+
if (failure === null)
|
|
34
|
+
return null;
|
|
35
|
+
if (failure.kind === 'room-not-readable')
|
|
36
|
+
return { kind: 'room-not-readable', locator };
|
|
37
|
+
if (failure.kind === 'refused')
|
|
38
|
+
return scopedRefusal(locator, failure.scope, failure.refusal);
|
|
39
|
+
return failure;
|
|
49
40
|
}
|
|
50
|
-
export function
|
|
51
|
-
if (
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
export function classifyRead(status, body, locator) {
|
|
42
|
+
if (doorRefusal(body)?.code === 'expired')
|
|
43
|
+
return { kind: 'beyond-horizon' };
|
|
44
|
+
return classifyDoor(status, body, locator);
|
|
45
|
+
}
|
|
46
|
+
export function discoveryFailure(status, body) {
|
|
47
|
+
const failure = doorFailure(status, body);
|
|
48
|
+
if (failure === null)
|
|
49
|
+
return null;
|
|
50
|
+
if (failure.kind === 'revoked-authorization')
|
|
51
|
+
return failure;
|
|
52
|
+
if (failure.kind === 'refused') {
|
|
53
|
+
return { kind: 'contract-unavailable', ...failure.refusal };
|
|
55
54
|
}
|
|
56
55
|
return { kind: 'transport-uncertainty' };
|
|
57
56
|
}
|
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,EAOR,MAAM,wBAAwB,CAAC;AAsBhC,OAAO,EAOL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAiCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CA8KxE"}
|