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

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 +279 -181
  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 +156 -138
  6. package/dist/adapter.d.ts +1 -0
  7. package/dist/adapter.d.ts.map +1 -1
  8. package/dist/adapter.js +347 -166
  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 +38 -11
  25. package/dist/read.d.ts.map +1 -1
  26. package/dist/read.js +166 -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 +209 -106
  36. package/dist/stream.d.ts +12 -4
  37. package/dist/stream.d.ts.map +1 -1
  38. package/dist/stream.js +442 -105
  39. package/dist/transport.d.ts +89 -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 +103 -26
  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,13 +1,18 @@
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];
6
+ export declare function identities(revisions: Readonly<Record<string, string>>): {
7
+ fileIds?: Record<string, string>;
8
+ };
6
9
  export type HouseManifestFile = {
7
10
  path: string;
8
11
  revision: string | undefined;
9
12
  version: string;
13
+ sha256?: string;
10
14
  head?: HeadChange;
15
+ binary?: BinaryFile;
11
16
  };
12
17
  export type HouseContent = {
13
18
  path: string;
@@ -17,10 +22,19 @@ export type HouseScope = LogPosition & {
17
22
  anchor: string;
18
23
  files: readonly HouseManifestFile[];
19
24
  contents: readonly HouseContent[];
20
- attachments?: readonly RoomAttachment[];
25
+ };
26
+ export type HouseCut = {
27
+ position: string;
28
+ log_epoch: string;
29
+ };
30
+ export type HouseCursor = {
31
+ room: string;
32
+ path: string | null;
33
+ cut?: HouseCut;
21
34
  };
22
35
  export type HouseEnvelope = {
23
36
  scopes: readonly HouseScope[];
37
+ next?: HouseCursor;
24
38
  };
25
39
  export type HouseGrant = {
26
40
  method: 'GET';
@@ -41,14 +55,23 @@ export type HouseChange = {
41
55
  head?: HeadChange;
42
56
  } | {
43
57
  path: string;
44
- reference: {
45
- revision: string;
46
- };
58
+ binary: BinaryFile;
59
+ revision: string | undefined;
60
+ version: string;
61
+ head?: HeadChange;
62
+ };
63
+ export type HousePage = {
64
+ after: string;
65
+ through: string;
66
+ read: number;
47
67
  };
48
68
  export type HouseView = LogPosition & {
49
69
  authority: string;
50
70
  changes: readonly HouseChange[];
51
- attachments?: readonly RoomAttachment[];
71
+ next?: HousePage;
72
+ };
73
+ type PageFailure = AdapterFailure | {
74
+ kind: 'beyond-horizon';
52
75
  };
53
76
  export type HouseEnumeration = {
54
77
  authorities: readonly HouseView[];
@@ -61,19 +84,23 @@ export declare function headChange(held: {
61
84
  readonly author?: unknown;
62
85
  readonly created_at?: unknown;
63
86
  }): HeadChange | undefined | null;
87
+ export declare function binaryFileOf(held: Readonly<Record<string, unknown>>): BinaryFile | undefined | null;
64
88
  export declare function parseEnvelope(body: unknown): HouseEnvelope | null;
65
89
  export declare function parseSiteBootstrap(body: unknown): HouseScope | null;
90
+ export declare function siteBootstrapNext(body: unknown): string | null;
91
+ export declare function siteBootstrapOffset(body: unknown): number | null;
66
92
  export declare function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null;
93
+ export declare function wholeView(first: HouseView, more: (page: HousePage) => Promise<HouseView | PageFailure>): Promise<HouseView | PageFailure>;
67
94
  export declare function advancedScope(scope: HouseScope, view: HouseView): HouseScope;
68
95
  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;
96
+ export declare function bootstrapOf(scope: HouseScope): BootstrapPage;
71
97
  export type HouseSchema = {
72
98
  schema: string | null;
73
99
  version: string | null;
100
+ revision: string | null;
74
101
  };
75
- export declare function schemaFrom(envelope: HouseEnvelope, tracked: TrackedAuthority, schema: string): HouseSchema | null;
76
102
  export declare function schemaOf(scope: HouseScope, schema: string): HouseSchema | null;
77
103
  export declare function viewOf(enumeration: HouseEnumeration, tracked: TrackedAuthority): HouseView | undefined;
78
- export declare function refreshFrom(view: HouseView, tracked: TrackedAuthority, fromRoomVersion: string): RefreshResult;
104
+ export declare function refreshFrom(view: HouseView, fromRoomVersion: string): RefreshResult;
105
+ export {};
79
106
  //# 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,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AAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,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,CA2BnF"}
package/dist/read.js CHANGED
@@ -1,10 +1,20 @@
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';
2
+ const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
3
+ export function identities(revisions) {
4
+ const fileIds = Object.fromEntries(Object.entries(revisions).flatMap(([path, revision]) => {
5
+ const file = REVISION_FILE.exec(revision)?.[1];
6
+ return file === undefined ? [] : [[path, file]];
7
+ }));
8
+ return Object.keys(fileIds).length === 0 ? {} : { fileIds };
9
+ }
3
10
  export function authorityRoot(handle) {
4
11
  return `/rooms/${handle}`;
5
12
  }
6
13
  export function contentPrefixes(tracked) {
7
- return [authorityRoot(tracked.handle)];
14
+ return [
15
+ authorityRoot(tracked.handle),
16
+ ...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
17
+ ];
8
18
  }
9
19
  export function schemaPath(handle, schema) {
10
20
  return `${authorityRoot(handle)}/${schema}`;
@@ -49,32 +59,19 @@ export function headChange(held) {
49
59
  function headed(head) {
50
60
  return head === undefined ? {} : { head };
51
61
  }
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')
62
+ export function binaryFileOf(held) {
63
+ if (held.file === undefined)
64
+ return undefined;
65
+ const { file, bytes, media_type: mediaType, sha256 } = held;
66
+ if (typeof file !== 'string' ||
67
+ typeof bytes !== 'number' ||
68
+ typeof mediaType !== 'string' ||
69
+ typeof sha256 !== 'string')
61
70
  return null;
62
- return { reference: attachment, name, byteLength: bytes, mediaType, entry: value };
71
+ return { fileRef: file, byteLength: bytes, mediaType, sha256 };
63
72
  }
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 };
73
+ function binaried(binary) {
74
+ return binary === undefined ? {} : { binary };
78
75
  }
79
76
  function parseFile(value, mode) {
80
77
  if (typeof value !== 'object' || value === null)
@@ -83,16 +80,30 @@ function parseFile(value, mode) {
83
80
  if (typeof file.path !== 'string')
84
81
  return null;
85
82
  const head = headChange(file);
86
- if (head === null)
83
+ const binary = binaryFileOf(file);
84
+ if (head === null || binary === null)
87
85
  return null;
88
86
  if (mode === 'site') {
89
87
  if (typeof file.sha256 !== 'string')
90
88
  return null;
91
- return { path: file.path, revision: undefined, version: file.sha256, ...headed(head) };
89
+ return {
90
+ path: file.path,
91
+ revision: binary?.sha256,
92
+ version: file.sha256,
93
+ ...headed(head),
94
+ ...binaried(binary),
95
+ };
92
96
  }
93
97
  if (typeof file.revision !== 'string')
94
98
  return null;
95
- return { path: file.path, revision: file.revision, version: file.revision, ...headed(head) };
99
+ return {
100
+ path: file.path,
101
+ revision: file.revision,
102
+ version: file.revision,
103
+ ...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
104
+ ...headed(head),
105
+ ...binaried(binary),
106
+ };
96
107
  }
97
108
  function parseScope(value, mode) {
98
109
  if (typeof value !== 'object' || value === null)
@@ -128,12 +139,28 @@ function parseScope(value, mode) {
128
139
  return null;
129
140
  contents.push({ path: content.path, content: content.content });
130
141
  }
131
- if (mode === 'site')
132
- return { anchor: manifest.anchor, ...at, files, contents };
133
- const attachments = parseOriginals(held.originals);
134
- if (attachments === null)
142
+ return { anchor: manifest.anchor, ...at, files, contents };
143
+ }
144
+ function parseCut(value) {
145
+ if (value === undefined)
146
+ return undefined;
147
+ if (typeof value !== 'object' || value === null)
148
+ return null;
149
+ const { position, log_epoch: logEpoch } = value;
150
+ if (typeof position !== 'string' || typeof logEpoch !== 'string')
135
151
  return null;
136
- return { anchor: manifest.anchor, ...at, files, contents, attachments };
152
+ return { position, log_epoch: logEpoch };
153
+ }
154
+ function parseCursor(value) {
155
+ if (typeof value !== 'object' || value === null)
156
+ return null;
157
+ const { room, path, cut } = value;
158
+ if (typeof room !== 'string' || (path !== null && typeof path !== 'string'))
159
+ return null;
160
+ const parsed = parseCut(cut);
161
+ if (parsed === null)
162
+ return null;
163
+ return { room, path, ...(parsed === undefined ? {} : { cut: parsed }) };
137
164
  }
138
165
  export function parseEnvelope(body) {
139
166
  if (typeof body !== 'object' || body === null)
@@ -147,11 +174,26 @@ export function parseEnvelope(body) {
147
174
  return null;
148
175
  scopes.push(scope);
149
176
  }
150
- return { scopes };
177
+ if (!('next' in body) || body.next === undefined)
178
+ return { scopes };
179
+ const next = parseCursor(body.next);
180
+ return next === null ? null : { scopes, next };
151
181
  }
152
182
  export function parseSiteBootstrap(body) {
153
183
  return parseScope(body, 'site');
154
184
  }
185
+ export function siteBootstrapNext(body) {
186
+ if (typeof body !== 'object' || body === null || !('next' in body))
187
+ return null;
188
+ return typeof body.next === 'string' && body.next.length > 0 ? body.next : null;
189
+ }
190
+ export function siteBootstrapOffset(body) {
191
+ if (typeof body !== 'object' || body === null || !('offset' in body))
192
+ return null;
193
+ return Number.isSafeInteger(body.offset) && body.offset > 0
194
+ ? body.offset
195
+ : null;
196
+ }
155
197
  function parseChange(value, mode) {
156
198
  if (typeof value !== 'object' || value === null)
157
199
  return null;
@@ -161,8 +203,15 @@ function parseChange(value, mode) {
161
203
  if (held.removed === true)
162
204
  return { path: held.path, removed: true };
163
205
  const head = headChange(held);
164
- if (head === null)
206
+ const binary = binaryFileOf(held);
207
+ if (head === null || binary === null)
165
208
  return null;
209
+ if (binary !== undefined) {
210
+ if (mode === 'credential' && typeof held.revision !== 'string')
211
+ return null;
212
+ const revision = typeof held.revision === 'string' ? held.revision : binary.sha256;
213
+ return { path: held.path, binary, revision, version: revision, ...headed(head) };
214
+ }
166
215
  if (mode === 'site') {
167
216
  if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
168
217
  return null;
@@ -183,12 +232,6 @@ function parseChange(value, mode) {
183
232
  ...headed(head),
184
233
  };
185
234
  }
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
235
  return null;
193
236
  }
194
237
  export function parseEnumeration(body, mode) {
@@ -213,17 +256,60 @@ export function parseEnumeration(body, mode) {
213
256
  return null;
214
257
  changes.push(mapped);
215
258
  }
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)
259
+ const next = held.next === undefined ? undefined : readPage(held.next);
260
+ if (next === null)
222
261
  return null;
223
- authorities.push({ authority: held.authority, ...at, changes, attachments });
262
+ authorities.push({
263
+ authority: held.authority,
264
+ ...at,
265
+ changes,
266
+ ...(next === undefined ? {} : { next }),
267
+ });
224
268
  }
225
269
  return { authorities };
226
270
  }
271
+ function readPage(held) {
272
+ if (typeof held !== 'object' || held === null)
273
+ return null;
274
+ const { after, through, read } = held;
275
+ if (typeof after !== 'string' || !DECIMAL.test(after))
276
+ return null;
277
+ if (typeof through !== 'string' || !DECIMAL.test(through))
278
+ return null;
279
+ if (typeof read !== 'number' || !Number.isSafeInteger(read) || read < 0)
280
+ return null;
281
+ return { after, through, read };
282
+ }
283
+ function advances(asked, next) {
284
+ const moved = BigInt(next.through) - BigInt(asked.through);
285
+ return moved > 0n || (moved === 0n && next.after === asked.after && next.read > asked.read);
286
+ }
287
+ export async function wholeView(first, more) {
288
+ const changes = new Map(first.changes.map((change) => [change.path, change]));
289
+ let view = first;
290
+ while (view.next !== undefined) {
291
+ const asked = view.next;
292
+ const page = await more(asked);
293
+ if ('kind' in page)
294
+ return page;
295
+ if (page.position !== asked.through ||
296
+ page.logEpoch !== first.logEpoch ||
297
+ (page.next !== undefined && !advances(asked, page.next))) {
298
+ return { kind: 'transport-uncertainty' };
299
+ }
300
+ for (const change of page.changes) {
301
+ changes.delete(change.path);
302
+ changes.set(change.path, change);
303
+ }
304
+ view = page;
305
+ }
306
+ return {
307
+ authority: first.authority,
308
+ position: view.position,
309
+ logEpoch: first.logEpoch,
310
+ changes: [...changes.values()],
311
+ };
312
+ }
227
313
  export function advancedScope(scope, view) {
228
314
  const files = new Map(scope.files.map((file) => [file.path, file]));
229
315
  const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
@@ -232,18 +318,15 @@ export function advancedScope(scope, view) {
232
318
  contents.delete(change.path);
233
319
  if ('removed' in change)
234
320
  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
- });
321
+ files.set(change.path, {
322
+ path: change.path,
323
+ revision: change.revision,
324
+ version: change.version,
325
+ ...headed(change.head),
326
+ ...('binary' in change ? { binary: change.binary } : {}),
327
+ });
328
+ if ('content' in change)
242
329
  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
330
  }
248
331
  return {
249
332
  ...scope,
@@ -256,36 +339,21 @@ export function advancedScope(scope, view) {
256
339
  export function matchesScope(scope, tracked) {
257
340
  return scope.anchor === tracked.authority;
258
341
  }
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) {
342
+ export function bootstrapOf(scope) {
273
343
  const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
274
344
  const documents = {};
275
345
  const revisions = {};
276
346
  const changes = {};
277
- const binaryTargets = [];
347
+ const binaryFiles = {};
278
348
  for (const file of scope.files) {
279
- if (!selects(tracked, file.path))
280
- continue;
281
349
  if (file.revision !== undefined)
282
350
  revisions[file.path] = file.revision;
283
351
  if (file.head !== undefined)
284
352
  changes[file.path] = file.head;
285
353
  const content = contents.get(file.path);
286
- if (content === undefined)
287
- binaryTargets.push(file.path);
288
- else
354
+ if (file.binary !== undefined)
355
+ binaryFiles[file.path] = file.binary;
356
+ else if (content !== undefined)
289
357
  documents[file.path] = content;
290
358
  }
291
359
  return {
@@ -293,61 +361,53 @@ export function bootstrapOf(scope, tracked) {
293
361
  roomVersion: roomVersion(scope),
294
362
  documents,
295
363
  revisions,
364
+ ...identities(revisions),
296
365
  changes,
297
- binaryTargets: binaryTargets.sort(),
298
- ...declared(scope.attachments),
366
+ binaryFiles,
299
367
  };
300
368
  }
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
369
  export function schemaOf(scope, schema) {
308
370
  const file = scope.files.find((entry) => entry.path === schema);
309
371
  if (file === undefined)
310
- return { schema: null, version: null };
372
+ return { schema: null, version: null, revision: null };
311
373
  const content = scope.contents.find((entry) => entry.path === schema);
312
- return content === undefined ? null : { schema: content.content, version: file.version };
374
+ return content === undefined
375
+ ? null
376
+ : { schema: content.content, version: file.version, revision: file.revision ?? null };
313
377
  }
314
378
  export function viewOf(enumeration, tracked) {
315
379
  return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
316
380
  }
317
- export function refreshFrom(view, tracked, fromRoomVersion) {
381
+ export function refreshFrom(view, fromRoomVersion) {
318
382
  if (roomVersion(view) === fromRoomVersion)
319
383
  return { kind: 'still-current' };
320
384
  const documents = {};
321
385
  const revisions = {};
322
386
  const changes = {};
323
- const binaryTargets = [];
387
+ const binaryFiles = {};
324
388
  const removals = [];
325
389
  for (const change of view.changes) {
326
- if (!selects(tracked, change.path))
327
- continue;
328
390
  if ('removed' in change) {
329
391
  removals.push(change.path);
330
392
  continue;
331
393
  }
332
- if ('content' in change) {
394
+ if ('content' in change)
333
395
  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;
396
+ else
397
+ binaryFiles[change.path] = change.binary;
398
+ if (change.revision !== undefined)
399
+ revisions[change.path] = change.revision;
400
+ if (change.head !== undefined)
401
+ changes[change.path] = change.head;
342
402
  }
343
403
  return {
344
404
  kind: 'net-advancement',
345
405
  roomVersion: roomVersion(view),
346
406
  documents,
347
407
  revisions,
408
+ ...identities(revisions),
348
409
  changes,
349
- binaryTargets: binaryTargets.sort(),
410
+ binaryFiles,
350
411
  removals: removals.sort(),
351
- ...declared(view.attachments),
352
412
  };
353
413
  }
@@ -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"}