@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c055ce6f0fdd0

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.
Files changed (61) hide show
  1. package/AGENTS.md +186 -34
  2. package/README.md +32 -0
  3. package/dist/actions.d.ts +5 -13
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +241 -334
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +255 -215
  8. package/dist/digest.js +1 -5
  9. package/dist/discovery.d.ts +23 -33
  10. package/dist/discovery.d.ts.map +1 -1
  11. package/dist/discovery.js +143 -230
  12. package/dist/gather.d.ts +3 -0
  13. package/dist/gather.d.ts.map +1 -0
  14. package/dist/gather.js +40 -0
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -3
  18. package/dist/links.d.ts +20 -0
  19. package/dist/links.d.ts.map +1 -0
  20. package/dist/links.js +104 -0
  21. package/dist/map.d.ts +2 -2
  22. package/dist/map.d.ts.map +1 -1
  23. package/dist/map.js +6 -7
  24. package/dist/model.d.ts +7 -18
  25. package/dist/model.d.ts.map +1 -1
  26. package/dist/model.js +48 -59
  27. package/dist/read.d.ts +31 -26
  28. package/dist/read.d.ts.map +1 -1
  29. package/dist/read.js +205 -199
  30. package/dist/refusal.d.ts +3 -1
  31. package/dist/refusal.d.ts.map +1 -1
  32. package/dist/refusal.js +27 -62
  33. package/dist/site.d.ts.map +1 -1
  34. package/dist/site.js +103 -151
  35. package/dist/stream.d.ts +16 -6
  36. package/dist/stream.d.ts.map +1 -1
  37. package/dist/stream.js +238 -214
  38. package/dist/transport.d.ts +69 -30
  39. package/dist/transport.d.ts.map +1 -1
  40. package/dist/transport.js +2 -3
  41. package/dist/version.d.ts +2 -0
  42. package/dist/version.d.ts.map +1 -1
  43. package/dist/version.js +32 -18
  44. package/dist/write.d.ts +13 -8
  45. package/dist/write.d.ts.map +1 -1
  46. package/dist/write.js +132 -215
  47. package/package.json +4 -12
  48. package/dist/actions.js.map +0 -1
  49. package/dist/adapter.js.map +0 -1
  50. package/dist/digest.js.map +0 -1
  51. package/dist/discovery.js.map +0 -1
  52. package/dist/index.js.map +0 -1
  53. package/dist/map.js.map +0 -1
  54. package/dist/model.js.map +0 -1
  55. package/dist/read.js.map +0 -1
  56. package/dist/refusal.js.map +0 -1
  57. package/dist/site.js.map +0 -1
  58. package/dist/stream.js.map +0 -1
  59. package/dist/transport.js.map +0 -1
  60. package/dist/version.js.map +0 -1
  61. package/dist/write.js.map +0 -1
package/dist/read.js CHANGED
@@ -1,128 +1,179 @@
1
- import { PROVIDER_SELECTION_ROOTS } from './discovery.js';
2
1
  import { readPosition, roomVersion } from './version.js';
3
2
  export function authorityRoot(handle) {
4
- return handle === undefined ? '/private' : `/rooms/${handle}`;
3
+ return `/rooms/${handle}`;
5
4
  }
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
- }
5
+ export function contentPrefixes(tracked) {
14
6
  return [
15
- ROOM_README,
16
- tracked.collectionRoot
7
+ authorityRoot(tracked.handle),
8
+ ...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
17
9
  ];
18
10
  }
19
- export function contentPrefixes(tracked) {
20
- const root = authorityRoot(tracked.handle);
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) return 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 (transfer.method !== 'GET' && transfer.method !== 'POST') return null;
33
- if (typeof transfer.operation !== 'string' || typeof transfer.url !== 'string') return null;
34
- return {
35
- method: transfer.method,
36
- operation: transfer.operation,
37
- url: transfer.url
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
+ function parseOriginal(value) {
55
+ if (typeof value !== 'object' || value === null)
56
+ return null;
57
+ const { attachment, name, bytes, media_type: mediaType } = value;
58
+ if (typeof attachment !== 'string' || typeof name !== 'string')
59
+ return null;
60
+ if (typeof bytes !== 'number' || !Number.isSafeInteger(bytes) || bytes < 0)
61
+ return null;
62
+ if (mediaType !== null && typeof mediaType !== 'string')
63
+ return null;
64
+ return { reference: attachment, name, byteLength: bytes, mediaType, entry: value };
65
+ }
66
+ export function parseOriginals(value) {
67
+ if (!Array.isArray(value))
68
+ return null;
69
+ const attachments = [];
70
+ for (const entry of value) {
71
+ const attachment = parseOriginal(entry);
72
+ if (attachment === null)
73
+ return null;
74
+ attachments.push(attachment);
75
+ }
76
+ return attachments;
77
+ }
78
+ function declared(attachments) {
79
+ return attachments === undefined ? {} : { attachments };
39
80
  }
40
81
  function parseFile(value, mode) {
41
- if (typeof value !== 'object' || value === null) return null;
82
+ if (typeof value !== 'object' || value === null)
83
+ return null;
42
84
  const file = value;
43
- if (typeof file.path !== 'string') return null;
85
+ if (typeof file.path !== 'string')
86
+ return null;
87
+ const head = headChange(file);
88
+ if (head === null)
89
+ return null;
44
90
  if (mode === 'site') {
45
- if (typeof file.sha256 !== 'string') return null;
46
- return {
47
- path: file.path,
48
- revision: undefined,
49
- version: file.sha256
50
- };
91
+ if (typeof file.sha256 !== 'string')
92
+ return null;
93
+ return { path: file.path, revision: undefined, version: file.sha256, ...headed(head) };
51
94
  }
52
- if (typeof file.revision !== 'string') return null;
53
- return {
54
- path: file.path,
55
- revision: file.revision,
56
- version: file.revision
57
- };
95
+ if (typeof file.revision !== 'string')
96
+ return null;
97
+ return { path: file.path, revision: file.revision, version: file.revision, ...headed(head) };
58
98
  }
59
99
  function parseScope(value, mode) {
60
- if (typeof value !== 'object' || value === null) return 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) return null;
63
- if (!Array.isArray(held.contents)) return null;
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' && manifest.scope !== 'private') return null;
108
+ if (manifest.scope !== 'room')
109
+ return null;
66
110
  const at = readPosition(manifest);
67
- if (typeof manifest.anchor !== 'string' || at === null) return null;
68
- if (!Array.isArray(manifest.files)) return null;
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) return 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) return 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') return null;
80
- contents.push({
81
- path: content.path,
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
- scope: manifest.scope,
87
- anchor: manifest.anchor,
88
- roomHandle: typeof manifest.room_handle === 'string' ? manifest.room_handle : undefined,
89
- ...at,
90
- files,
91
- contents
92
- };
133
+ if (mode === 'site')
134
+ return { anchor: manifest.anchor, ...at, files, contents };
135
+ const attachments = parseOriginals(held.originals);
136
+ if (attachments === null)
137
+ return null;
138
+ return { anchor: manifest.anchor, ...at, files, contents, attachments };
93
139
  }
94
140
  export function parseEnvelope(body) {
95
- if (typeof body !== 'object' || body === null) return null;
96
- if (!('scopes' in body) || !Array.isArray(body.scopes)) return null;
141
+ if (typeof body !== 'object' || body === null)
142
+ return null;
143
+ if (!('scopes' in body) || !Array.isArray(body.scopes))
144
+ return null;
97
145
  const scopes = [];
98
- for (const entry of body.scopes){
146
+ for (const entry of body.scopes) {
99
147
  const scope = parseScope(entry, 'credential');
100
- if (scope === null) return null;
148
+ if (scope === null)
149
+ return null;
101
150
  scopes.push(scope);
102
151
  }
103
- return {
104
- scopes
105
- };
152
+ return { scopes };
106
153
  }
107
154
  export function parseSiteBootstrap(body) {
108
- const scope = parseScope(body, 'site');
109
- return scope !== null && scope.scope === 'room' ? scope : null;
155
+ return parseScope(body, 'site');
110
156
  }
111
157
  function parseChange(value, mode) {
112
- if (typeof value !== 'object' || value === null) return null;
158
+ if (typeof value !== 'object' || value === null)
159
+ return null;
113
160
  const held = value;
114
- if (typeof held.path !== 'string') return null;
115
- if (held.removed === true) return {
116
- path: held.path,
117
- removed: true
118
- };
161
+ if (typeof held.path !== 'string')
162
+ return null;
163
+ if (held.removed === true)
164
+ return { path: held.path, removed: true };
165
+ const head = headChange(held);
166
+ if (head === null)
167
+ return null;
119
168
  if (mode === 'site') {
120
- if (typeof held.content !== 'string' || typeof held.sha256 !== 'string') return null;
169
+ if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
170
+ return null;
121
171
  return {
122
172
  path: held.path,
123
173
  content: held.content,
124
174
  revision: undefined,
125
- version: held.sha256
175
+ version: held.sha256,
176
+ ...headed(head),
126
177
  };
127
178
  }
128
179
  if (typeof held.content === 'string' && typeof held.revision === 'string') {
@@ -130,184 +181,139 @@ function parseChange(value, mode) {
130
181
  path: held.path,
131
182
  content: held.content,
132
183
  revision: held.revision,
133
- version: held.revision
184
+ version: held.revision,
185
+ ...headed(head),
134
186
  };
135
187
  }
136
188
  if (typeof held.reference === 'object' && held.reference !== null) {
137
189
  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
- }
144
- };
190
+ if (typeof reference.revision !== 'string')
191
+ return null;
192
+ return { path: held.path, reference: { revision: reference.revision } };
145
193
  }
146
194
  return null;
147
195
  }
148
196
  export function parseEnumeration(body, mode) {
149
- if (typeof body !== 'object' || body === null) return null;
150
- if (!('authorities' in body) || !Array.isArray(body.authorities)) return null;
197
+ if (typeof body !== 'object' || body === null)
198
+ return null;
199
+ if (!('authorities' in body) || !Array.isArray(body.authorities))
200
+ return null;
151
201
  const authorities = [];
152
- for (const entry of body.authorities){
153
- if (typeof entry !== 'object' || entry === null) return null;
202
+ for (const entry of body.authorities) {
203
+ if (typeof entry !== 'object' || entry === null)
204
+ return null;
154
205
  const held = entry;
155
206
  const at = readPosition(held);
156
- if (typeof held.authority !== 'string' || at === null) return null;
157
- if (!Array.isArray(held.changes)) return null;
207
+ if (typeof held.authority !== 'string' || at === null)
208
+ return null;
209
+ if (!Array.isArray(held.changes))
210
+ return null;
158
211
  const changes = [];
159
- for (const change of held.changes){
212
+ for (const change of held.changes) {
160
213
  const mapped = parseChange(change, mode);
161
- if (mapped === null) return null;
214
+ if (mapped === null)
215
+ return null;
162
216
  changes.push(mapped);
163
217
  }
164
- authorities.push({
165
- authority: held.authority,
166
- ...at,
167
- changes
168
- });
218
+ if (mode === 'site') {
219
+ authorities.push({ authority: held.authority, ...at, changes });
220
+ continue;
221
+ }
222
+ const attachments = parseOriginals(held.originals);
223
+ if (attachments === null)
224
+ return null;
225
+ authorities.push({ authority: held.authority, ...at, changes, attachments });
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
- file.path,
177
- file
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) continue;
235
+ if ('removed' in change)
236
+ continue;
187
237
  if ('content' in change) {
188
238
  files.set(change.path, {
189
239
  path: change.path,
190
240
  revision: change.revision,
191
- version: change.version
241
+ version: change.version,
242
+ ...headed(change.head),
192
243
  });
193
244
  contents.set(change.path, change.content);
194
245
  continue;
195
246
  }
196
247
  const { revision } = change.reference;
197
- files.set(change.path, {
198
- path: change.path,
199
- revision,
200
- version: revision
201
- });
248
+ files.set(change.path, { path: change.path, revision, version: revision });
202
249
  }
203
250
  return {
204
251
  ...scope,
205
252
  position: view.position,
206
253
  logEpoch: view.logEpoch,
207
- files: [
208
- ...files.values()
209
- ],
210
- contents: [
211
- ...contents
212
- ].map(([path, content])=>({
213
- path,
214
- content
215
- }))
254
+ files: [...files.values()],
255
+ contents: [...contents].map(([path, content]) => ({ path, content })),
216
256
  };
217
257
  }
218
258
  export function matchesScope(scope, tracked) {
219
- if (tracked.handle === undefined) return scope.scope === 'private';
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);
259
+ return scope.anchor === tracked.authority;
236
260
  }
237
- export function bootstrapOf(scope, tracked) {
238
- const contents = new Map(scope.contents.map((entry)=>[
239
- entry.path,
240
- entry.content
241
- ]));
261
+ export function bootstrapOf(scope) {
262
+ const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
242
263
  const documents = {};
243
264
  const revisions = {};
265
+ const changes = {};
244
266
  const binaryTargets = [];
245
- for (const file of scope.files){
246
- if (!selects(tracked, file.path)) continue;
247
- if (file.revision !== undefined) revisions[file.path] = file.revision;
267
+ for (const file of scope.files) {
268
+ if (file.revision !== undefined)
269
+ revisions[file.path] = file.revision;
270
+ if (file.head !== undefined)
271
+ changes[file.path] = file.head;
248
272
  const content = contents.get(file.path);
249
- if (content === undefined) binaryTargets.push(file.path);
250
- else documents[file.path] = content;
273
+ if (content === undefined)
274
+ binaryTargets.push(file.path);
275
+ else
276
+ documents[file.path] = content;
251
277
  }
252
278
  return {
253
279
  kind: 'bootstrap',
254
280
  roomVersion: roomVersion(scope),
255
281
  documents,
256
282
  revisions,
257
- binaryTargets: binaryTargets.sort()
283
+ changes,
284
+ binaryTargets: binaryTargets.sort(),
285
+ ...declared(scope.attachments),
258
286
  };
259
287
  }
260
- export const MODEL_DEFINITION_ADDRESS = 'types';
261
- export function definitionAddress(path) {
262
- return `${MODEL_DEFINITION_ADDRESS}/${path.slice(path.lastIndexOf('/') + 1)}`;
288
+ export function schemaOf(scope, schema) {
289
+ const file = scope.files.find((entry) => entry.path === schema);
290
+ if (file === undefined)
291
+ return { schema: null, version: null };
292
+ const content = scope.contents.find((entry) => entry.path === schema);
293
+ return content === undefined ? null : { schema: content.content, version: file.version };
263
294
  }
264
- export function definitionsFrom(envelope, tracked, modelRoot) {
265
- const scope = envelope.scopes.find((entry)=>matchesScope(entry, tracked));
266
- if (scope === undefined) return null;
267
- return definitionsOf(scope, modelRoot);
295
+ export function viewOf(enumeration, tracked) {
296
+ return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
268
297
  }
269
- export function definitionsOf(scope, modelRoot) {
270
- const contents = new Map(scope.contents.map((entry)=>[
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
- };
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
- };
298
+ export function refreshFrom(view, fromRoomVersion) {
299
+ if (roomVersion(view) === fromRoomVersion)
300
+ return { kind: 'still-current' };
298
301
  const documents = {};
299
302
  const revisions = {};
303
+ const changes = {};
300
304
  const binaryTargets = [];
301
305
  const removals = [];
302
- for (const change of view.changes){
303
- if (!selects(tracked, change.path)) continue;
306
+ for (const change of view.changes) {
304
307
  if ('removed' in change) {
305
308
  removals.push(change.path);
306
309
  continue;
307
310
  }
308
311
  if ('content' in change) {
309
312
  documents[change.path] = change.content;
310
- if (change.revision !== undefined) revisions[change.path] = change.revision;
313
+ if (change.revision !== undefined)
314
+ revisions[change.path] = change.revision;
315
+ if (change.head !== undefined)
316
+ changes[change.path] = change.head;
311
317
  continue;
312
318
  }
313
319
  binaryTargets.push(change.path);
@@ -318,9 +324,9 @@ export function refreshFrom(enumeration, tracked, fromRoomVersion) {
318
324
  roomVersion: roomVersion(view),
319
325
  documents,
320
326
  revisions,
327
+ changes,
321
328
  binaryTargets: binaryTargets.sort(),
322
- removals: removals.sort()
329
+ removals: removals.sort(),
330
+ ...declared(view.attachments),
323
331
  };
324
332
  }
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 | {
@@ -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;AAgBhC,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"}
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) return null;
16
- if (!('error' in body) || typeof body.error !== 'object' || body.error === null) return null;
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') return null;
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) return {
36
- kind: 'transport-uncertainty'
37
- };
16
+ if (status === 0)
17
+ return { kind: 'transport-uncertainty' };
38
18
  const refusal = doorRefusal(body);
39
- if (status === 401) return {
40
- kind: 'revoked-authorization'
41
- };
42
- if (refusal !== null && RETRYABLE_CODES.has(refusal.code)) return {
43
- kind: 'transport-uncertainty'
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 >= 500) return {
55
- kind: 'transport-uncertainty'
56
- };
57
- if (status < 400) return null;
58
- if (refusal === null) return {
59
- kind: 'transport-uncertainty'
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') return classified;
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
@@ -1 +1 @@
1
- {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAOR,MAAM,wBAAwB,CAAC;AA8BhC,OAAO,EAKL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAgCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAuIxE"}
1
+ {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAMR,MAAM,wBAAwB,CAAC;AAsBhC,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AA+BxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAiIxE"}