@agentshouse/mdruntime-adapter 0.1.0-c819869684b89 → 0.1.0-c82ec25e72f2f
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/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +75 -67
- package/dist/chunks.d.ts +28 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +206 -0
- package/dist/discovery.d.ts +1 -2
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +2 -3
- package/dist/house-model.d.ts +38 -308
- package/dist/house-model.d.ts.map +1 -1
- package/dist/house-model.js +26 -166
- package/dist/model.d.ts +4 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +29 -7
- package/dist/read.d.ts +12 -1
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +24 -2
- package/dist/room-stream.d.ts +2 -1
- package/dist/room-stream.d.ts.map +1 -1
- package/dist/room-stream.js +2 -2
- package/dist/room-types.d.ts.map +1 -1
- package/dist/room-types.js +0 -2
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +7 -11
- package/dist/space-schema.d.ts +7 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +18 -0
- package/dist/stream.d.ts +6 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +83 -14
- package/dist/transport.d.ts +4 -3
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +1 -0
- package/dist/write.js +1 -1
- package/package.json +2 -2
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,EAed,MAAM,wBAAwB,CAAC;AA0BhC,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAoBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAoBrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAqcpF"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { stepped } from '@agentshouse/mdruntime';
|
|
2
2
|
import { capabilities, discoveredRoom, mapDiscovery, parseAuthorityChange, parseDiscovery, trackedFrom, } from './discovery.js';
|
|
3
3
|
import { createSiteAdapter } from './site.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { bootstrapping, parseFileAddress, parseGrant } from './read.js';
|
|
5
|
+
import { chunkLister, chunkScope } from './chunks.js';
|
|
6
|
+
import { manifestedModels } from './model.js';
|
|
7
|
+
import { spaceSchemas } from './space-schema.js';
|
|
7
8
|
import { finishedUpload, houseUpload } from './upload.js';
|
|
8
9
|
import { houseAction } from './actions.js';
|
|
9
10
|
import { houseSearch } from './search.js';
|
|
@@ -13,7 +14,7 @@ import { houseDoorRoute, } from './transport.js';
|
|
|
13
14
|
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
14
15
|
import { HOUSE_TYPED_PATHS } from './house-model.js';
|
|
15
16
|
import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
|
|
16
|
-
import { followsVersion,
|
|
17
|
+
import { followsVersion, reachedVersion, roomVersion } from './version.js';
|
|
17
18
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
18
19
|
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
19
20
|
const OCTET_STREAM = 'application/octet-stream';
|
|
@@ -21,43 +22,20 @@ const EXPIRED_ADDRESS = 403;
|
|
|
21
22
|
function lapsedGrant(outcome) {
|
|
22
23
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
23
24
|
}
|
|
24
|
-
async function heldFiles(authority, held, bound) {
|
|
25
|
-
const listed = await held.files(null, bound + 1);
|
|
26
|
-
const files = listed.slice(0, bound);
|
|
27
|
-
const through = listed.length > bound ? (files.at(-1)?.path ?? null) : null;
|
|
28
|
-
return files.length === 0 ? null : { room: authority, through, files };
|
|
29
|
-
}
|
|
30
|
-
async function reused(scope, held) {
|
|
31
|
-
const sent = new Set(scope.contents.map((entry) => entry.path));
|
|
32
|
-
const contents = [...scope.contents];
|
|
33
|
-
const asked = scope.files.filter((file) => file.binary === undefined && !sent.has(file.path));
|
|
34
|
-
if (asked.length === 0)
|
|
35
|
-
return scope;
|
|
36
|
-
if (held === undefined)
|
|
37
|
-
return null;
|
|
38
|
-
const kept = await held.contents(asked.map(({ path }) => path));
|
|
39
|
-
for (const file of asked) {
|
|
40
|
-
const found = kept.get(file.path);
|
|
41
|
-
if (found === undefined ||
|
|
42
|
-
found.revision !== file.revision ||
|
|
43
|
-
(await sha256Hex(found.content)) !== file.sha256) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
contents.push({ path: file.path, content: found.content });
|
|
47
|
-
}
|
|
48
|
-
return { ...scope, contents };
|
|
49
|
-
}
|
|
50
25
|
export function createAgentsHouseAdapter(options) {
|
|
51
26
|
if ('site' in options)
|
|
52
27
|
return createSiteAdapter(options.site, options.snapshot === true);
|
|
53
28
|
const transport = options.transport;
|
|
29
|
+
const spaces = spaceSchemas();
|
|
54
30
|
const notifications = houseNotifications(transport, 'credential', {
|
|
55
31
|
opened: async (frame) => (frame === null ? null : opened(frame)),
|
|
56
32
|
changed,
|
|
57
|
-
|
|
33
|
+
expired: (authorities) => lister.askAll(authorities.flatMap((authority) => [...tracked.values()].filter((entry) => entry.authority === authority))),
|
|
34
|
+
}, spaces);
|
|
58
35
|
const tracked = new Map();
|
|
59
|
-
const
|
|
60
|
-
const
|
|
36
|
+
const lister = chunkLister(transport, () => declared().max_prefixes);
|
|
37
|
+
const chunked = new Map();
|
|
38
|
+
const renewals = new WeakMap();
|
|
61
39
|
let bounds;
|
|
62
40
|
function declared() {
|
|
63
41
|
if (bounds === undefined)
|
|
@@ -70,6 +48,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
70
48
|
return null;
|
|
71
49
|
bounds = document.bounds;
|
|
72
50
|
tracked.clear();
|
|
51
|
+
lister.forget();
|
|
73
52
|
for (const entry of trackedFrom(document))
|
|
74
53
|
tracked.set(entry.locator, entry);
|
|
75
54
|
notifications.track([...tracked.values()]);
|
|
@@ -94,42 +73,71 @@ export function createAgentsHouseAdapter(options) {
|
|
|
94
73
|
member: change.member,
|
|
95
74
|
};
|
|
96
75
|
}
|
|
97
|
-
async function
|
|
98
|
-
const
|
|
99
|
-
if ('kind' in
|
|
100
|
-
return
|
|
101
|
-
|
|
102
|
-
if (scope === null) {
|
|
103
|
-
unreused.add(entry.locator);
|
|
76
|
+
async function listedRoom(entry) {
|
|
77
|
+
const listed = await lister.list(entry);
|
|
78
|
+
if ('kind' in listed)
|
|
79
|
+
return listed;
|
|
80
|
+
if (listed.anchor !== entry.authority)
|
|
104
81
|
return UNCERTAIN_READ;
|
|
105
|
-
|
|
82
|
+
chunked.set(entry.locator, listed);
|
|
83
|
+
const { models } = await manifestedModels({
|
|
84
|
+
anchor: listed.anchor,
|
|
85
|
+
position: listed.position,
|
|
86
|
+
logEpoch: listed.logEpoch,
|
|
87
|
+
models: listed.models,
|
|
88
|
+
}, entry, spaces);
|
|
106
89
|
return {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
90
|
+
kind: 'bootstrap',
|
|
91
|
+
roomVersion: roomVersion(listed),
|
|
92
|
+
documents: {},
|
|
93
|
+
facts: {},
|
|
94
|
+
revisions: {},
|
|
95
|
+
changes: {},
|
|
96
|
+
binaryFiles: {},
|
|
97
|
+
parts: listed.parts,
|
|
98
|
+
...(models === undefined ? {} : { models }),
|
|
111
99
|
};
|
|
112
100
|
}
|
|
113
|
-
async function
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return
|
|
101
|
+
async function chunkRead(entry, id) {
|
|
102
|
+
const room = chunked.get(entry.locator);
|
|
103
|
+
const address = room?.chunks.get(id);
|
|
104
|
+
if (room === undefined || address === undefined)
|
|
105
|
+
return null;
|
|
106
|
+
const read = await transport.download(address.url);
|
|
107
|
+
if (read.status !== EXPIRED_ADDRESS)
|
|
108
|
+
return { room, read };
|
|
109
|
+
const renewed = await renewal(entry, room);
|
|
110
|
+
if ('kind' in renewed || !renewed.chunks.has(id))
|
|
111
|
+
return null;
|
|
112
|
+
chunked.set(entry.locator, renewed);
|
|
113
|
+
return { room: renewed, read: await transport.download(renewed.chunks.get(id).url) };
|
|
126
114
|
}
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
115
|
+
function renewal(entry, stale) {
|
|
116
|
+
const held = renewals.get(stale);
|
|
117
|
+
if (held !== undefined)
|
|
118
|
+
return held;
|
|
119
|
+
const renewed = lister.renew(entry, [...chunked.keys()].flatMap((locator) => tracked.get(locator) ?? []));
|
|
120
|
+
renewals.set(stale, renewed);
|
|
121
|
+
return renewed;
|
|
122
|
+
}
|
|
123
|
+
function hold(rooms) {
|
|
124
|
+
for (const room of rooms) {
|
|
125
|
+
const listed = chunked.get(room.locator);
|
|
126
|
+
if (listed !== undefined &&
|
|
127
|
+
room.roomVersion !== null &&
|
|
128
|
+
reachedVersion(room.roomVersion, roomVersion(listed), listed.logEpoch))
|
|
129
|
+
chunked.delete(room.locator);
|
|
130
|
+
}
|
|
131
|
+
notifications.send(rooms);
|
|
132
|
+
}
|
|
133
|
+
async function chunkPage(entry, id, arriving) {
|
|
134
|
+
const fetched = await chunkRead(entry, id);
|
|
135
|
+
if (fetched === null || fetched.read.status !== 200 || fetched.read.body === null)
|
|
136
|
+
return UNCERTAIN_READ;
|
|
137
|
+
const scope = await chunkScope(fetched.read.body, fetched.room, arriving).catch(() => null);
|
|
138
|
+
if (scope === null)
|
|
139
|
+
return UNCERTAIN_READ;
|
|
140
|
+
return { ...(await stepped(bootstrapping(scope))), bytes: fetched.room.chunks.get(id).bytes };
|
|
133
141
|
}
|
|
134
142
|
function authorityFor(locator) {
|
|
135
143
|
return tracked.get(locator);
|
|
@@ -297,8 +305,8 @@ export function createAgentsHouseAdapter(options) {
|
|
|
297
305
|
if (entry === undefined)
|
|
298
306
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
299
307
|
return request.pageToken === undefined
|
|
300
|
-
?
|
|
301
|
-
:
|
|
308
|
+
? listedRoom(entry)
|
|
309
|
+
: chunkPage(entry, request.pageToken, request.arriving);
|
|
302
310
|
},
|
|
303
311
|
async mutate(_authorization, request, keep) {
|
|
304
312
|
const entry = authorityFor(request.locator);
|
|
@@ -394,7 +402,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
394
402
|
return houseSearch(transport, [...tracked.values()], request);
|
|
395
403
|
},
|
|
396
404
|
roomStream: {
|
|
397
|
-
hold
|
|
405
|
+
hold,
|
|
398
406
|
observe: notifications.observe,
|
|
399
407
|
},
|
|
400
408
|
conversations: notifications.conversations,
|
package/dist/chunks.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type AdapterFailure, type BootstrapPart } from '@agentshouse/mdruntime';
|
|
2
|
+
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
+
import { type HouseModels, type HouseScope } from './read.js';
|
|
4
|
+
import { type HouseDoor } from './transport.js';
|
|
5
|
+
import { type LogPosition } from './version.js';
|
|
6
|
+
export type ChunkAddress = {
|
|
7
|
+
readonly url: string;
|
|
8
|
+
readonly bytes: number;
|
|
9
|
+
};
|
|
10
|
+
export type ChunkedRoom = LogPosition & {
|
|
11
|
+
readonly anchor: string;
|
|
12
|
+
readonly chunks: ReadonlyMap<string, ChunkAddress>;
|
|
13
|
+
readonly parts: readonly BootstrapPart[];
|
|
14
|
+
readonly names: ReadonlyMap<string, string>;
|
|
15
|
+
readonly models: HouseModels;
|
|
16
|
+
};
|
|
17
|
+
export type Listed = ChunkedRoom | {
|
|
18
|
+
readonly kind: 'not-ready';
|
|
19
|
+
} | AdapterFailure;
|
|
20
|
+
export declare function partId(logEpoch: string, hash: string): string;
|
|
21
|
+
export declare function chunkLister(transport: HouseDoor, most: () => number): {
|
|
22
|
+
askAll: (entries: readonly TrackedAuthority[]) => void;
|
|
23
|
+
list: (entry: TrackedAuthority) => Promise<Listed>;
|
|
24
|
+
renew(entry: TrackedAuthority, installing: readonly TrackedAuthority[]): Promise<Listed>;
|
|
25
|
+
forget(): void;
|
|
26
|
+
};
|
|
27
|
+
export declare function chunkScope(body: ReadableStream<Uint8Array>, room: ChunkedRoom, arriving: ((bytes: number) => void) | undefined): Promise<HouseScope | null>;
|
|
28
|
+
//# sourceMappingURL=chunks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunks.d.ts","sourceRoot":"","sources":["../src/chunks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACpG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAkB,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dist/chunks.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { paced, ROW_WEIGHT } from '@agentshouse/mdruntime';
|
|
2
|
+
import { authorityRoot, parseFile, } from './read.js';
|
|
3
|
+
import { classifyDoor } from './refusal.js';
|
|
4
|
+
import { houseDoorRoute } from './transport.js';
|
|
5
|
+
import { readPosition } from './version.js';
|
|
6
|
+
function authorKey(author) {
|
|
7
|
+
for (const kind of ['user', 'site', 'inbox']) {
|
|
8
|
+
if (typeof author[kind] === 'string')
|
|
9
|
+
return `${kind}:${author[kind]}`;
|
|
10
|
+
}
|
|
11
|
+
const { app, release, function: named } = author;
|
|
12
|
+
return typeof app === 'string' && typeof release === 'string' && typeof named === 'string'
|
|
13
|
+
? `app:${app}:${release}:${named}`
|
|
14
|
+
: null;
|
|
15
|
+
}
|
|
16
|
+
function namesOf(authors) {
|
|
17
|
+
if (!Array.isArray(authors))
|
|
18
|
+
return null;
|
|
19
|
+
const names = new Map();
|
|
20
|
+
for (const author of authors) {
|
|
21
|
+
const key = typeof author === 'object' && author !== null ? authorKey(author) : null;
|
|
22
|
+
if (key === null || typeof author.name !== 'string')
|
|
23
|
+
return null;
|
|
24
|
+
names.set(key, author.name);
|
|
25
|
+
}
|
|
26
|
+
return names;
|
|
27
|
+
}
|
|
28
|
+
function modelsOf(models) {
|
|
29
|
+
if (!Array.isArray(models))
|
|
30
|
+
return null;
|
|
31
|
+
const files = [];
|
|
32
|
+
const contents = [];
|
|
33
|
+
for (const entry of models) {
|
|
34
|
+
const file = parseFile(entry, 'credential');
|
|
35
|
+
if (file === null || typeof entry.content !== 'string')
|
|
36
|
+
return null;
|
|
37
|
+
files.push(file);
|
|
38
|
+
contents.push({ path: file.path, content: entry.content });
|
|
39
|
+
}
|
|
40
|
+
return { files, contents };
|
|
41
|
+
}
|
|
42
|
+
export function partId(logEpoch, hash) {
|
|
43
|
+
return `${logEpoch}:${hash}`;
|
|
44
|
+
}
|
|
45
|
+
function chunkedRoom(room) {
|
|
46
|
+
const at = readPosition(room);
|
|
47
|
+
const names = namesOf(room.authors);
|
|
48
|
+
const models = modelsOf(room.models);
|
|
49
|
+
if (at === null || names === null || models === null || !Array.isArray(room.chunks))
|
|
50
|
+
return null;
|
|
51
|
+
const chunks = new Map();
|
|
52
|
+
const parts = [];
|
|
53
|
+
for (const chunk of room.chunks) {
|
|
54
|
+
const { hash, bytes, download } = chunk;
|
|
55
|
+
if (typeof hash !== 'string' || typeof bytes !== 'number' || typeof download !== 'string')
|
|
56
|
+
return null;
|
|
57
|
+
const id = partId(at.logEpoch, hash);
|
|
58
|
+
chunks.set(id, { url: download, bytes });
|
|
59
|
+
parts.push({ id, bytes });
|
|
60
|
+
}
|
|
61
|
+
return { anchor: room.room_ref, ...at, chunks, parts, names, models };
|
|
62
|
+
}
|
|
63
|
+
function listedRooms(answer) {
|
|
64
|
+
const rooms = answer.body?.rooms;
|
|
65
|
+
if (!Array.isArray(rooms))
|
|
66
|
+
return null;
|
|
67
|
+
const listed = new Map();
|
|
68
|
+
for (const room of rooms) {
|
|
69
|
+
if (typeof room !== 'object' || room === null || typeof room.room_ref !== 'string')
|
|
70
|
+
return null;
|
|
71
|
+
if (room.ready === false) {
|
|
72
|
+
listed.set(room.room_ref, { kind: 'not-ready' });
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const chunked = room.ready === true ? chunkedRoom(room) : null;
|
|
76
|
+
if (chunked === null)
|
|
77
|
+
return null;
|
|
78
|
+
listed.set(room.room_ref, chunked);
|
|
79
|
+
}
|
|
80
|
+
return listed;
|
|
81
|
+
}
|
|
82
|
+
export function chunkLister(transport, most) {
|
|
83
|
+
const asked = new Map();
|
|
84
|
+
function answered(entries, whole) {
|
|
85
|
+
const prefixes = whole ? ['/'] : entries.map((entry) => authorityRoot(entry.handle));
|
|
86
|
+
return transport.door(houseDoorRoute('room-chunks/list'), { prefixes }).then((answer) => {
|
|
87
|
+
const failure = classifyDoor(answer.status, answer.body, '');
|
|
88
|
+
if (failure !== null)
|
|
89
|
+
return failed(entries, failure);
|
|
90
|
+
const listed = listedRooms(answer);
|
|
91
|
+
return listed ?? failed(entries, { kind: 'transport-uncertainty' });
|
|
92
|
+
}, () => failed(entries, { kind: 'transport-uncertainty' }));
|
|
93
|
+
}
|
|
94
|
+
function failed(entries, failure) {
|
|
95
|
+
return new Map(entries.map((entry) => [
|
|
96
|
+
entry.authority,
|
|
97
|
+
failure.kind === 'room-not-readable' || failure.kind === 'scoped-refusal'
|
|
98
|
+
? { ...failure, locator: entry.locator }
|
|
99
|
+
: failure,
|
|
100
|
+
]));
|
|
101
|
+
}
|
|
102
|
+
function settled(entry, lists) {
|
|
103
|
+
return lists.then((listed) => listed.get(entry.authority) ?? { kind: 'room-not-readable', locator: entry.locator });
|
|
104
|
+
}
|
|
105
|
+
function askAll(entries) {
|
|
106
|
+
if (entries.length === 0)
|
|
107
|
+
return;
|
|
108
|
+
const lists = answered(entries, entries.length > most());
|
|
109
|
+
for (const entry of entries) {
|
|
110
|
+
const listed = settled(entry, lists);
|
|
111
|
+
listed.catch(() => { });
|
|
112
|
+
asked.set(entry.authority, { entry, listed });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function list(entry) {
|
|
116
|
+
const held = asked.get(entry.authority);
|
|
117
|
+
asked.delete(entry.authority);
|
|
118
|
+
return held?.listed ?? settled(entry, answered([entry], false));
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
askAll,
|
|
122
|
+
list,
|
|
123
|
+
renew(entry, installing) {
|
|
124
|
+
if (!asked.has(entry.authority)) {
|
|
125
|
+
const waiting = [...asked.values()].map((held) => held.entry);
|
|
126
|
+
const due = new Map([entry, ...installing, ...waiting].map((held) => [held.authority, held]));
|
|
127
|
+
askAll([...due.values()]);
|
|
128
|
+
}
|
|
129
|
+
return list(entry);
|
|
130
|
+
},
|
|
131
|
+
forget() {
|
|
132
|
+
asked.clear();
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function folderLine(entry) {
|
|
137
|
+
return typeof entry.folder === 'string' && Object.keys(entry).length === 1 ? entry.folder : null;
|
|
138
|
+
}
|
|
139
|
+
function chunkEntry(line, room, read) {
|
|
140
|
+
let entry;
|
|
141
|
+
try {
|
|
142
|
+
entry = JSON.parse(line);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
if (typeof entry !== 'object' || entry === null)
|
|
148
|
+
return false;
|
|
149
|
+
const folder = folderLine(entry);
|
|
150
|
+
if (folder !== null) {
|
|
151
|
+
read.folders.push(folder);
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
const author = entry.author;
|
|
155
|
+
let named = entry;
|
|
156
|
+
if (author !== undefined) {
|
|
157
|
+
const key = typeof author === 'object' && author !== null ? authorKey(author) : null;
|
|
158
|
+
const name = key === null ? undefined : room.names.get(key);
|
|
159
|
+
if (name === undefined)
|
|
160
|
+
return false;
|
|
161
|
+
named = { ...entry, author: { ...author, name } };
|
|
162
|
+
}
|
|
163
|
+
const file = parseFile(named, 'credential');
|
|
164
|
+
if (file === null)
|
|
165
|
+
return false;
|
|
166
|
+
read.files.push(file);
|
|
167
|
+
if (typeof entry.content === 'string')
|
|
168
|
+
read.contents.push({ path: file.path, content: entry.content });
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
export async function chunkScope(body, room, arriving) {
|
|
172
|
+
const read = {
|
|
173
|
+
files: [],
|
|
174
|
+
contents: [],
|
|
175
|
+
folders: [],
|
|
176
|
+
};
|
|
177
|
+
const reader = body.getReader();
|
|
178
|
+
const decoder = new TextDecoder();
|
|
179
|
+
const pace = paced();
|
|
180
|
+
const unfinished = [];
|
|
181
|
+
let bytes = 0;
|
|
182
|
+
for (let chunk = await reader.read(); chunk.done !== true; chunk = await reader.read()) {
|
|
183
|
+
bytes += chunk.value.length;
|
|
184
|
+
arriving?.(bytes);
|
|
185
|
+
const text = decoder.decode(chunk.value, { stream: true });
|
|
186
|
+
let start = 0;
|
|
187
|
+
for (let end = text.indexOf('\n'); end !== -1; end = text.indexOf('\n', start)) {
|
|
188
|
+
const piece = text.slice(start, end);
|
|
189
|
+
const line = unfinished.length === 0 ? piece : unfinished.splice(0).join('') + piece;
|
|
190
|
+
start = end + 1;
|
|
191
|
+
if (line.length > 0 && !chunkEntry(line, room, read)) {
|
|
192
|
+
await reader.cancel();
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
const due = pace(line.length + ROW_WEIGHT);
|
|
196
|
+
if (due instanceof Promise)
|
|
197
|
+
await due;
|
|
198
|
+
}
|
|
199
|
+
if (start < text.length)
|
|
200
|
+
unfinished.push(text.slice(start));
|
|
201
|
+
}
|
|
202
|
+
const rest = unfinished.join('') + decoder.decode();
|
|
203
|
+
if (rest.length > 0 && !chunkEntry(rest, room, read))
|
|
204
|
+
return null;
|
|
205
|
+
return { anchor: room.anchor, position: room.position, logEpoch: room.logEpoch, ...read };
|
|
206
|
+
}
|
package/dist/discovery.d.ts
CHANGED
|
@@ -12,13 +12,12 @@ export type HouseBounds = {
|
|
|
12
12
|
max_inline_body_bytes: number;
|
|
13
13
|
max_upload_bytes: number;
|
|
14
14
|
max_prefixes: number;
|
|
15
|
-
max_held_files: number;
|
|
16
15
|
change_retention_seconds: number;
|
|
17
16
|
max_move_documents?: number;
|
|
18
17
|
};
|
|
19
18
|
export type HouseOperations = {
|
|
20
19
|
write: readonly string[];
|
|
21
|
-
|
|
20
|
+
erase: readonly string[];
|
|
22
21
|
};
|
|
23
22
|
export type HouseAccessLevel = 'search' | 'open' | 'keep';
|
|
24
23
|
export type HouseAuthority = LogPosition & {
|
package/dist/discovery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,MAAM,EACN,aAA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iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAKhE;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,sBAAsB,CAAC,SAAS,CAAC,GAAG,SAAS,UAAU,EAAE,CAE9F;AAED,wBAAgB,gBAAgB,IAAI,SAAS,UAAU,EAAE,CAOxD;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,cAAc,GAAG,cAAc,CAqBxE;AAED,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,IAAI,CAAC,sBAAsB,EAAE,QAAQ,CAAC,EAChD,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,QAAQ,EAAE,SAAS,UAAU,EAAE,GAC9B,SAAS,CAQX"}
|
package/dist/discovery.js
CHANGED
|
@@ -13,10 +13,9 @@ const BOUND_KEYS = [
|
|
|
13
13
|
'max_inline_body_bytes',
|
|
14
14
|
'max_upload_bytes',
|
|
15
15
|
'max_prefixes',
|
|
16
|
-
'max_held_files',
|
|
17
16
|
'change_retention_seconds',
|
|
18
17
|
];
|
|
19
|
-
const OPERATION_KEYS = ['write', '
|
|
18
|
+
const OPERATION_KEYS = ['write', 'erase'];
|
|
20
19
|
const ACCESS_LEVELS = ['search', 'open', 'keep'];
|
|
21
20
|
function stringList(value) {
|
|
22
21
|
if (!Array.isArray(value))
|
|
@@ -281,7 +280,7 @@ export function discoveredRoom(authority) {
|
|
|
281
280
|
roomVersion: roomVersion(authority),
|
|
282
281
|
operations: {
|
|
283
282
|
write: [...authority.operations.write],
|
|
284
|
-
|
|
283
|
+
erase: [...authority.operations.erase],
|
|
285
284
|
},
|
|
286
285
|
replica: {
|
|
287
286
|
selection: locator,
|