@agentshouse/mdruntime-adapter 0.1.0-c6ddfd288ac81 → 0.1.0-c7c29ea9ca063

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 (51) hide show
  1. package/AGENTS.md +269 -177
  2. package/README.md +3 -3
  3. package/dist/actions.d.ts +63 -2
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +154 -138
  6. package/dist/adapter.d.ts +1 -0
  7. package/dist/adapter.d.ts.map +1 -1
  8. package/dist/adapter.js +335 -165
  9. package/dist/discovery.d.ts +15 -27
  10. package/dist/discovery.d.ts.map +1 -1
  11. package/dist/discovery.js +57 -102
  12. package/dist/gather.d.ts +1 -0
  13. package/dist/gather.d.ts.map +1 -1
  14. package/dist/gather.js +11 -6
  15. package/dist/handed.d.ts +15 -0
  16. package/dist/handed.d.ts.map +1 -0
  17. package/dist/handed.js +38 -0
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/model.d.ts +7 -18
  22. package/dist/model.d.ts.map +1 -1
  23. package/dist/model.js +60 -39
  24. package/dist/read.d.ts +35 -11
  25. package/dist/read.d.ts.map +1 -1
  26. package/dist/read.js +156 -106
  27. package/dist/referrer.d.ts +7 -0
  28. package/dist/referrer.d.ts.map +1 -0
  29. package/dist/referrer.js +35 -0
  30. package/dist/refusal.d.ts +5 -7
  31. package/dist/refusal.d.ts.map +1 -1
  32. package/dist/refusal.js +31 -31
  33. package/dist/site.d.ts +1 -1
  34. package/dist/site.d.ts.map +1 -1
  35. package/dist/site.js +192 -106
  36. package/dist/stream.d.ts +12 -4
  37. package/dist/stream.d.ts.map +1 -1
  38. package/dist/stream.js +437 -105
  39. package/dist/transport.d.ts +83 -23
  40. package/dist/transport.d.ts.map +1 -1
  41. package/dist/transport.js +3 -2
  42. package/dist/version.d.ts +2 -0
  43. package/dist/version.d.ts.map +1 -1
  44. package/dist/version.js +10 -1
  45. package/dist/write.d.ts +4 -5
  46. package/dist/write.d.ts.map +1 -1
  47. package/dist/write.js +101 -25
  48. package/package.json +3 -4
  49. package/dist/links.d.ts +0 -11
  50. package/dist/links.d.ts.map +0 -1
  51. package/dist/links.js +0 -51
package/dist/model.js CHANGED
@@ -1,46 +1,67 @@
1
1
  import { sha256Hex } from './digest.js';
2
- export const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
3
- export function failedModel(failure) {
4
- if (failure.kind === 'revoked-authorization')
5
- return { kind: 'revoked-authorization' };
6
- if (failure.kind === 'transport-uncertainty')
7
- return { kind: 'transport-uncertainty' };
8
- return MODEL_ABSENT;
9
- }
10
- export function modelKey(locator, attached) {
11
- return `${locator} ${attached}`;
12
- }
13
- export async function heldModel(read, identity, failure) {
2
+ import { schemaOf, schemaPath } from './read.js';
3
+ const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
4
+ const ABSENT_SCHEMA = { schema: null, version: null, revision: null };
5
+ async function heldModel(read, identity) {
14
6
  if (read === null)
15
- return { snapshot: failure, identity: null };
7
+ return MODEL_ABSENT;
16
8
  const version = await sha256Hex(JSON.stringify(read.version));
17
9
  return {
18
- snapshot: { kind: 'model', snapshot: { identity, version, schema: read.schema } },
19
- identity: { identity, version },
10
+ kind: 'model',
11
+ snapshot: { identity, version, schema: read.schema, revision: read.revision },
20
12
  };
21
13
  }
22
- export function modelShelf() {
23
- const models = new Map();
24
- return {
25
- retain(key, acquired) {
26
- if (acquired === undefined)
27
- return models.get(key);
28
- if (acquired.snapshot.kind === 'transport-uncertainty') {
29
- const previous = models.get(key);
30
- if (previous !== undefined && previous.identity !== null)
31
- return previous;
32
- }
33
- models.set(key, acquired);
34
- return acquired;
35
- },
36
- answer(request) {
37
- return models.get(modelKey(request.locator, request.attached))?.snapshot ?? MODEL_ABSENT;
38
- },
39
- keep(locators) {
40
- for (const key of [...models.keys()]) {
41
- if (!locators.some((locator) => key.startsWith(`${locator} `)))
42
- models.delete(key);
43
- }
44
- },
45
- };
14
+ async function modelsOf(tracked, read) {
15
+ const models = {};
16
+ const collection = read(tracked.schema);
17
+ if (collection !== undefined) {
18
+ models.collection = await heldModel(collection, schemaPath(tracked.handle, tracked.schema));
19
+ }
20
+ if (tracked.houseModel !== null) {
21
+ const root = tracked.houseModel.root;
22
+ const selection = read(root);
23
+ if (selection !== undefined) {
24
+ models.selection = await heldModel(selection, schemaPath(tracked.handle, root));
25
+ }
26
+ }
27
+ return models.collection === undefined && models.selection === undefined ? undefined : models;
28
+ }
29
+ export function partModels(scope, tracked, seen, final) {
30
+ return modelsOf(tracked, (schema) => {
31
+ if (scope.files.some((file) => file.path === schema))
32
+ return schemaOf(scope, schema);
33
+ return final && !seen.has(schema) ? ABSENT_SCHEMA : undefined;
34
+ });
35
+ }
36
+ export function viewModels(view, tracked) {
37
+ return modelsOf(tracked, (schema) => {
38
+ const change = view.changes.find((candidate) => candidate.path === schema);
39
+ if (change === undefined)
40
+ return undefined;
41
+ if ('removed' in change)
42
+ return ABSENT_SCHEMA;
43
+ if ('content' in change) {
44
+ return {
45
+ schema: change.content,
46
+ version: change.version,
47
+ revision: change.revision ?? null,
48
+ };
49
+ }
50
+ return null;
51
+ });
52
+ }
53
+ export function streamedModels(schemas, tracked, mode) {
54
+ return modelsOf(tracked, (schema) => {
55
+ const entry = schemas.get(schema);
56
+ if (entry === undefined)
57
+ return undefined;
58
+ if (entry.kind === 'removed')
59
+ return ABSENT_SCHEMA;
60
+ if (entry.text === undefined)
61
+ return null;
62
+ const version = mode === 'site' ? entry.sha256 : entry.revision;
63
+ return version === undefined
64
+ ? null
65
+ : { schema: entry.text, version, revision: mode === 'site' ? null : version };
66
+ });
46
67
  }
package/dist/read.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { BootstrapPage, RefreshResult, RoomAttachment } from '@agentshouse/mdruntime';
2
- import { type TrackedAuthority } from './discovery.js';
1
+ import type { AdapterFailure, BinaryFile, BootstrapPage, RefreshResult } from '@agentshouse/mdruntime';
2
+ import type { TrackedAuthority } from './discovery.js';
3
3
  import type { HouseMode } from './transport.js';
4
4
  import { type LogPosition } from './version.js';
5
5
  export type HeadChange = BootstrapPage['changes'][string];
@@ -7,7 +7,9 @@ export type HouseManifestFile = {
7
7
  path: string;
8
8
  revision: string | undefined;
9
9
  version: string;
10
+ sha256?: string;
10
11
  head?: HeadChange;
12
+ binary?: BinaryFile;
11
13
  };
12
14
  export type HouseContent = {
13
15
  path: string;
@@ -17,10 +19,19 @@ export type HouseScope = LogPosition & {
17
19
  anchor: string;
18
20
  files: readonly HouseManifestFile[];
19
21
  contents: readonly HouseContent[];
20
- attachments?: readonly RoomAttachment[];
22
+ };
23
+ export type HouseCut = {
24
+ position: string;
25
+ log_epoch: string;
26
+ };
27
+ export type HouseCursor = {
28
+ room: string;
29
+ path: string | null;
30
+ cut?: HouseCut;
21
31
  };
22
32
  export type HouseEnvelope = {
23
33
  scopes: readonly HouseScope[];
34
+ next?: HouseCursor;
24
35
  };
25
36
  export type HouseGrant = {
26
37
  method: 'GET';
@@ -41,14 +52,23 @@ export type HouseChange = {
41
52
  head?: HeadChange;
42
53
  } | {
43
54
  path: string;
44
- reference: {
45
- revision: string;
46
- };
55
+ binary: BinaryFile;
56
+ revision: string | undefined;
57
+ version: string;
58
+ head?: HeadChange;
59
+ };
60
+ export type HousePage = {
61
+ after: string;
62
+ through: string;
63
+ read: number;
47
64
  };
48
65
  export type HouseView = LogPosition & {
49
66
  authority: string;
50
67
  changes: readonly HouseChange[];
51
- attachments?: readonly RoomAttachment[];
68
+ next?: HousePage;
69
+ };
70
+ type PageFailure = AdapterFailure | {
71
+ kind: 'beyond-horizon';
52
72
  };
53
73
  export type HouseEnumeration = {
54
74
  authorities: readonly HouseView[];
@@ -61,19 +81,23 @@ export declare function headChange(held: {
61
81
  readonly author?: unknown;
62
82
  readonly created_at?: unknown;
63
83
  }): HeadChange | undefined | null;
84
+ export declare function binaryFileOf(held: Readonly<Record<string, unknown>>): BinaryFile | undefined | null;
64
85
  export declare function parseEnvelope(body: unknown): HouseEnvelope | null;
65
86
  export declare function parseSiteBootstrap(body: unknown): HouseScope | null;
87
+ export declare function siteBootstrapNext(body: unknown): string | null;
88
+ export declare function siteBootstrapOffset(body: unknown): number | null;
66
89
  export declare function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null;
90
+ export declare function wholeView(first: HouseView, more: (page: HousePage) => Promise<HouseView | PageFailure>): Promise<HouseView | PageFailure>;
67
91
  export declare function advancedScope(scope: HouseScope, view: HouseView): HouseScope;
68
92
  export declare function matchesScope(scope: HouseScope, tracked: TrackedAuthority): boolean;
69
- export declare function selects(tracked: TrackedAuthority, path: string): boolean;
70
- export declare function bootstrapOf(scope: HouseScope, tracked: TrackedAuthority): BootstrapPage;
93
+ export declare function bootstrapOf(scope: HouseScope): BootstrapPage;
71
94
  export type HouseSchema = {
72
95
  schema: string | null;
73
96
  version: string | null;
97
+ revision: string | null;
74
98
  };
75
- export declare function schemaFrom(envelope: HouseEnvelope, tracked: TrackedAuthority, schema: string): HouseSchema | null;
76
99
  export declare function schemaOf(scope: HouseScope, schema: string): HouseSchema | null;
77
100
  export declare function viewOf(enumeration: HouseEnumeration, tracked: TrackedAuthority): HouseView | undefined;
78
- export declare function refreshFrom(view: HouseView, tracked: TrackedAuthority, fromRoomVersion: string): RefreshResult;
101
+ export declare function refreshFrom(view: HouseView, fromRoomVersion: string): RefreshResult;
102
+ export {};
79
103
  //# sourceMappingURL=read.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAEb,aAAa,EACb,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAKL,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAA6B,KAAK,W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M,GAAG,WAAW,GAAG,IAAI,CAO9E;AAED,wBAAgB,MAAM,CACpB,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,gBAAgB,GACxB,SAAS,GAAG,SAAS,CAEvB;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,GAAG,aAAa,CA0BnF"}
package/dist/read.js CHANGED
@@ -1,10 +1,12 @@
1
- import { PRIVATE_HANDLE, UNTYPED_FOLDERS, PROVIDER_SELECTION_ROOTS, RESERVED_NAMES, } from './discovery.js';
2
- import { readPosition, roomVersion } from './version.js';
1
+ import { DECIMAL, 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 [authorityRoot(tracked.handle)];
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 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')
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')
61
62
  return null;
62
- return { reference: attachment, name, byteLength: bytes, mediaType, entry: value };
63
+ return { fileRef: file, byteLength: bytes, mediaType, sha256 };
63
64
  }
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 };
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,30 @@ function parseFile(value, mode) {
83
72
  if (typeof file.path !== 'string')
84
73
  return null;
85
74
  const head = headChange(file);
86
- if (head === null)
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 { path: file.path, revision: undefined, version: file.sha256, ...headed(head) };
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 { path: file.path, revision: file.revision, version: file.revision, ...headed(head) };
91
+ return {
92
+ path: file.path,
93
+ revision: file.revision,
94
+ version: file.revision,
95
+ ...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
96
+ ...headed(head),
97
+ ...binaried(binary),
98
+ };
96
99
  }
97
100
  function parseScope(value, mode) {
98
101
  if (typeof value !== 'object' || value === null)
@@ -128,12 +131,28 @@ function parseScope(value, mode) {
128
131
  return null;
129
132
  contents.push({ path: content.path, content: content.content });
130
133
  }
131
- if (mode === 'site')
132
- return { anchor: manifest.anchor, ...at, files, contents };
133
- const attachments = parseOriginals(held.originals);
134
- if (attachments === null)
134
+ return { anchor: manifest.anchor, ...at, files, contents };
135
+ }
136
+ function parseCut(value) {
137
+ if (value === undefined)
138
+ return undefined;
139
+ if (typeof value !== 'object' || value === null)
140
+ return null;
141
+ const { position, log_epoch: logEpoch } = value;
142
+ if (typeof position !== 'string' || typeof logEpoch !== 'string')
143
+ return null;
144
+ return { position, log_epoch: logEpoch };
145
+ }
146
+ function parseCursor(value) {
147
+ if (typeof value !== 'object' || value === null)
148
+ return null;
149
+ const { room, path, cut } = value;
150
+ if (typeof room !== 'string' || (path !== null && typeof path !== 'string'))
135
151
  return null;
136
- return { anchor: manifest.anchor, ...at, files, contents, attachments };
152
+ const parsed = parseCut(cut);
153
+ if (parsed === null)
154
+ return null;
155
+ return { room, path, ...(parsed === undefined ? {} : { cut: parsed }) };
137
156
  }
138
157
  export function parseEnvelope(body) {
139
158
  if (typeof body !== 'object' || body === null)
@@ -147,11 +166,26 @@ export function parseEnvelope(body) {
147
166
  return null;
148
167
  scopes.push(scope);
149
168
  }
150
- return { scopes };
169
+ if (!('next' in body) || body.next === undefined)
170
+ return { scopes };
171
+ const next = parseCursor(body.next);
172
+ return next === null ? null : { scopes, next };
151
173
  }
152
174
  export function parseSiteBootstrap(body) {
153
175
  return parseScope(body, 'site');
154
176
  }
177
+ export function siteBootstrapNext(body) {
178
+ if (typeof body !== 'object' || body === null || !('next' in body))
179
+ return null;
180
+ return typeof body.next === 'string' && body.next.length > 0 ? body.next : null;
181
+ }
182
+ export function siteBootstrapOffset(body) {
183
+ if (typeof body !== 'object' || body === null || !('offset' in body))
184
+ return null;
185
+ return Number.isSafeInteger(body.offset) && body.offset > 0
186
+ ? body.offset
187
+ : null;
188
+ }
155
189
  function parseChange(value, mode) {
156
190
  if (typeof value !== 'object' || value === null)
157
191
  return null;
@@ -161,8 +195,15 @@ function parseChange(value, mode) {
161
195
  if (held.removed === true)
162
196
  return { path: held.path, removed: true };
163
197
  const head = headChange(held);
164
- if (head === null)
198
+ const binary = binaryFileOf(held);
199
+ if (head === null || binary === null)
165
200
  return null;
201
+ if (binary !== undefined) {
202
+ if (mode === 'credential' && typeof held.revision !== 'string')
203
+ return null;
204
+ const revision = typeof held.revision === 'string' ? held.revision : binary.sha256;
205
+ return { path: held.path, binary, revision, version: revision, ...headed(head) };
206
+ }
166
207
  if (mode === 'site') {
167
208
  if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
168
209
  return null;
@@ -183,12 +224,6 @@ function parseChange(value, mode) {
183
224
  ...headed(head),
184
225
  };
185
226
  }
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
227
  return null;
193
228
  }
194
229
  export function parseEnumeration(body, mode) {
@@ -213,17 +248,60 @@ export function parseEnumeration(body, mode) {
213
248
  return null;
214
249
  changes.push(mapped);
215
250
  }
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)
251
+ const next = held.next === undefined ? undefined : readPage(held.next);
252
+ if (next === null)
222
253
  return null;
223
- authorities.push({ authority: held.authority, ...at, changes, attachments });
254
+ authorities.push({
255
+ authority: held.authority,
256
+ ...at,
257
+ changes,
258
+ ...(next === undefined ? {} : { next }),
259
+ });
224
260
  }
225
261
  return { authorities };
226
262
  }
263
+ function readPage(held) {
264
+ if (typeof held !== 'object' || held === null)
265
+ return null;
266
+ const { after, through, read } = held;
267
+ if (typeof after !== 'string' || !DECIMAL.test(after))
268
+ return null;
269
+ if (typeof through !== 'string' || !DECIMAL.test(through))
270
+ return null;
271
+ if (typeof read !== 'number' || !Number.isSafeInteger(read) || read < 0)
272
+ return null;
273
+ return { after, through, read };
274
+ }
275
+ function advances(asked, next) {
276
+ const moved = BigInt(next.through) - BigInt(asked.through);
277
+ return moved > 0n || (moved === 0n && next.after === asked.after && next.read > asked.read);
278
+ }
279
+ export async function wholeView(first, more) {
280
+ const changes = new Map(first.changes.map((change) => [change.path, change]));
281
+ let view = first;
282
+ while (view.next !== undefined) {
283
+ const asked = view.next;
284
+ const page = await more(asked);
285
+ if ('kind' in page)
286
+ return page;
287
+ if (page.position !== asked.through ||
288
+ page.logEpoch !== first.logEpoch ||
289
+ (page.next !== undefined && !advances(asked, page.next))) {
290
+ return { kind: 'transport-uncertainty' };
291
+ }
292
+ for (const change of page.changes) {
293
+ changes.delete(change.path);
294
+ changes.set(change.path, change);
295
+ }
296
+ view = page;
297
+ }
298
+ return {
299
+ authority: first.authority,
300
+ position: view.position,
301
+ logEpoch: first.logEpoch,
302
+ changes: [...changes.values()],
303
+ };
304
+ }
227
305
  export function advancedScope(scope, view) {
228
306
  const files = new Map(scope.files.map((file) => [file.path, file]));
229
307
  const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
@@ -232,18 +310,15 @@ export function advancedScope(scope, view) {
232
310
  contents.delete(change.path);
233
311
  if ('removed' in change)
234
312
  continue;
235
- if ('content' in change) {
236
- files.set(change.path, {
237
- path: change.path,
238
- revision: change.revision,
239
- version: change.version,
240
- ...headed(change.head),
241
- });
313
+ files.set(change.path, {
314
+ path: change.path,
315
+ revision: change.revision,
316
+ version: change.version,
317
+ ...headed(change.head),
318
+ ...('binary' in change ? { binary: change.binary } : {}),
319
+ });
320
+ if ('content' in change)
242
321
  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
322
  }
248
323
  return {
249
324
  ...scope,
@@ -256,36 +331,21 @@ export function advancedScope(scope, view) {
256
331
  export function matchesScope(scope, tracked) {
257
332
  return scope.anchor === tracked.authority;
258
333
  }
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;
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) {
334
+ export function bootstrapOf(scope) {
273
335
  const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
274
336
  const documents = {};
275
337
  const revisions = {};
276
338
  const changes = {};
277
- const binaryTargets = [];
339
+ const binaryFiles = {};
278
340
  for (const file of scope.files) {
279
- if (!selects(tracked, file.path))
280
- continue;
281
341
  if (file.revision !== undefined)
282
342
  revisions[file.path] = file.revision;
283
343
  if (file.head !== undefined)
284
344
  changes[file.path] = file.head;
285
345
  const content = contents.get(file.path);
286
- if (content === undefined)
287
- binaryTargets.push(file.path);
288
- else
346
+ if (file.binary !== undefined)
347
+ binaryFiles[file.path] = file.binary;
348
+ else if (content !== undefined)
289
349
  documents[file.path] = content;
290
350
  }
291
351
  return {
@@ -294,51 +354,42 @@ export function bootstrapOf(scope, tracked) {
294
354
  documents,
295
355
  revisions,
296
356
  changes,
297
- binaryTargets: binaryTargets.sort(),
298
- ...declared(scope.attachments),
357
+ binaryFiles,
299
358
  };
300
359
  }
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
360
  export function schemaOf(scope, schema) {
308
361
  const file = scope.files.find((entry) => entry.path === schema);
309
362
  if (file === undefined)
310
- return { schema: null, version: null };
363
+ return { schema: null, version: null, revision: null };
311
364
  const content = scope.contents.find((entry) => entry.path === schema);
312
- return content === undefined ? null : { schema: content.content, version: file.version };
365
+ return content === undefined
366
+ ? null
367
+ : { schema: content.content, version: file.version, revision: file.revision ?? null };
313
368
  }
314
369
  export function viewOf(enumeration, tracked) {
315
370
  return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
316
371
  }
317
- export function refreshFrom(view, tracked, fromRoomVersion) {
372
+ export function refreshFrom(view, fromRoomVersion) {
318
373
  if (roomVersion(view) === fromRoomVersion)
319
374
  return { kind: 'still-current' };
320
375
  const documents = {};
321
376
  const revisions = {};
322
377
  const changes = {};
323
- const binaryTargets = [];
378
+ const binaryFiles = {};
324
379
  const removals = [];
325
380
  for (const change of view.changes) {
326
- if (!selects(tracked, change.path))
327
- continue;
328
381
  if ('removed' in change) {
329
382
  removals.push(change.path);
330
383
  continue;
331
384
  }
332
- if ('content' in change) {
385
+ if ('content' in change)
333
386
  documents[change.path] = change.content;
334
- if (change.revision !== undefined)
335
- revisions[change.path] = change.revision;
336
- if (change.head !== undefined)
337
- changes[change.path] = change.head;
338
- continue;
339
- }
340
- binaryTargets.push(change.path);
341
- revisions[change.path] = change.reference.revision;
387
+ else
388
+ binaryFiles[change.path] = change.binary;
389
+ if (change.revision !== undefined)
390
+ revisions[change.path] = change.revision;
391
+ if (change.head !== undefined)
392
+ changes[change.path] = change.head;
342
393
  }
343
394
  return {
344
395
  kind: 'net-advancement',
@@ -346,8 +397,7 @@ export function refreshFrom(view, tracked, fromRoomVersion) {
346
397
  documents,
347
398
  revisions,
348
399
  changes,
349
- binaryTargets: binaryTargets.sort(),
400
+ binaryFiles,
350
401
  removals: removals.sort(),
351
- ...declared(view.attachments),
352
402
  };
353
403
  }
@@ -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"}
@@ -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
+ }