@agentshouse/mdruntime-adapter 0.1.0-alpha.8 → 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.
- package/AGENTS.md +186 -34
- package/README.md +32 -0
- package/dist/actions.d.ts +5 -13
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +241 -334
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +256 -216
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +23 -33
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +143 -230
- package/dist/gather.d.ts +3 -0
- package/dist/gather.d.ts.map +1 -0
- package/dist/gather.js +40 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/links.d.ts +20 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +104 -0
- package/dist/map.d.ts +2 -2
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +6 -7
- package/dist/model.d.ts +7 -18
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +48 -59
- package/dist/read.d.ts +31 -26
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +205 -199
- package/dist/refusal.d.ts +3 -1
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +27 -62
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +103 -151
- package/dist/stream.d.ts +16 -6
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +238 -214
- package/dist/transport.d.ts +69 -30
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +2 -3
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +32 -18
- package/dist/write.d.ts +19 -8
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +135 -208
- package/package.json +4 -12
- package/dist/actions.js.map +0 -1
- package/dist/adapter.js.map +0 -1
- package/dist/digest.js.map +0 -1
- package/dist/discovery.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/map.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/read.js.map +0 -1
- package/dist/refusal.js.map +0 -1
- package/dist/site.js.map +0 -1
- package/dist/stream.js.map +0 -1
- package/dist/transport.js.map +0 -1
- package/dist/version.js.map +0 -1
- package/dist/write.js.map +0 -1
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,EAGV,OAAO,EACP,aAAa,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAWd,MAAM,wBAAwB,CAAC;AAqChC,OAAO,EAQL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAyBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAsBjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA0WpF"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,285 +1,325 @@
|
|
|
1
|
-
import { DISCOVER_PREFIXES,
|
|
2
|
-
import {
|
|
1
|
+
import { DISCOVER_PREFIXES, capabilities, discoveredRoom, mapDiscovery, parseDiscovery, trackedFrom, } from './discovery.js';
|
|
2
|
+
import { scopeModels, streamedModels, viewModels } from './model.js';
|
|
3
|
+
import { gathered, selections } from './gather.js';
|
|
3
4
|
import { createSiteAdapter } from './site.js';
|
|
4
|
-
import {
|
|
5
|
+
import { bootstrapOf, contentPrefixes, matchesScope, parseEnumeration, parseEnvelope, parseGrant, refreshFrom, viewOf, } from './read.js';
|
|
6
|
+
import { acceptedLinks, enumeratedLinks, heldLinks, scopeLinks, streamedLinks, } from './links.js';
|
|
5
7
|
import { houseAction } from './actions.js';
|
|
6
|
-
import { classifyDoor, discoveryFailure } from './refusal.js';
|
|
8
|
+
import { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';
|
|
7
9
|
import { houseNotifications } from './stream.js';
|
|
8
|
-
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_REVISIONS,
|
|
9
|
-
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, rejectedMapping, revisionBody, uploadable } from './write.js';
|
|
10
|
-
import { logPosition, presented } from './version.js';
|
|
11
|
-
const UNCERTAIN = {
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
const RESOLVED_OUTCOMES = new Set([
|
|
15
|
-
'accepted',
|
|
16
|
-
'conflicted',
|
|
17
|
-
'rejected',
|
|
18
|
-
'expired'
|
|
19
|
-
]);
|
|
10
|
+
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_REVISIONS, PRIVATE_LOCATOR, } from './transport.js';
|
|
11
|
+
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
12
|
+
import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
13
|
+
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
14
|
+
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
20
15
|
function lapsedGrant(outcome) {
|
|
21
16
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
22
17
|
}
|
|
23
|
-
function modelFailure(classified, envelope) {
|
|
24
|
-
if (classified === null) {
|
|
25
|
-
return envelope === null ? {
|
|
26
|
-
kind: 'transport-uncertainty'
|
|
27
|
-
} : MODEL_ABSENT;
|
|
28
|
-
}
|
|
29
|
-
return failedModel(classified);
|
|
30
|
-
}
|
|
31
18
|
export function createAgentsHouseAdapter(options) {
|
|
32
|
-
if ('site' in options)
|
|
19
|
+
if ('site' in options)
|
|
20
|
+
return createSiteAdapter(options.site);
|
|
33
21
|
const transport = options.transport;
|
|
34
22
|
const notifications = houseNotifications(transport, 'credential');
|
|
35
23
|
const tracked = new Map();
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
function
|
|
39
|
-
|
|
24
|
+
const handed = new Map();
|
|
25
|
+
let bounds;
|
|
26
|
+
function declared() {
|
|
27
|
+
if (bounds === undefined)
|
|
28
|
+
throw new Error('no Discovery declared the bounds');
|
|
29
|
+
return bounds;
|
|
40
30
|
}
|
|
41
|
-
async function
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
31
|
+
async function bootstrappedRoom(envelope, entry) {
|
|
32
|
+
const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
|
|
33
|
+
if (scope === undefined)
|
|
34
|
+
return { kind: 'room-not-readable', locator: entry.locator };
|
|
35
|
+
handed.set(entry.locator, scopeLinks(scope));
|
|
36
|
+
notifications.reach(entry.authority, scope);
|
|
37
|
+
const models = await scopeModels(scope, entry);
|
|
38
|
+
return { ...bootstrapOf(scope), ...(models === undefined ? {} : { models }) };
|
|
39
|
+
}
|
|
40
|
+
async function enumeratedRoom(enumeration, ask) {
|
|
41
|
+
const view = viewOf(enumeration, ask.entry);
|
|
42
|
+
if (view === undefined)
|
|
43
|
+
return { kind: 'room-not-readable', locator: ask.entry.locator };
|
|
44
|
+
notifications.reach(ask.entry.authority, view);
|
|
45
|
+
const answer = refreshFrom(view, ask.fromRoomVersion);
|
|
46
|
+
if (answer.kind !== 'net-advancement')
|
|
47
|
+
return answer;
|
|
48
|
+
handed.set(ask.entry.locator, enumeratedLinks(view, handed.get(ask.entry.locator)));
|
|
49
|
+
const models = await viewModels(view, ask.entry);
|
|
50
|
+
return models === undefined ? answer : { ...answer, models };
|
|
51
|
+
}
|
|
52
|
+
async function streamed(entry, request, from) {
|
|
53
|
+
const links = handed.get(entry.locator);
|
|
54
|
+
if (links?.roomVersion !== request.fromRoomVersion)
|
|
55
|
+
return null;
|
|
56
|
+
const advanced = notifications.advance(entry, from, (path, revision) => links.revisions.get(path) === revision);
|
|
57
|
+
if (advanced === null)
|
|
58
|
+
return null;
|
|
59
|
+
const relinked = streamedLinks(links, advanced);
|
|
60
|
+
if (relinked === null)
|
|
61
|
+
return null;
|
|
62
|
+
handed.set(entry.locator, relinked);
|
|
63
|
+
const models = await streamedModels(advanced.schemas, entry, 'credential');
|
|
64
|
+
return models === undefined ? advanced.page : { ...advanced.page, models };
|
|
65
|
+
}
|
|
66
|
+
function held(rooms) {
|
|
67
|
+
const kept = rooms.flatMap((room) => {
|
|
68
|
+
const entry = tracked.get(room.locator);
|
|
69
|
+
const at = logPosition(room.roomVersion);
|
|
70
|
+
if (entry === undefined || at === null)
|
|
71
|
+
return [];
|
|
72
|
+
handed.set(room.locator, heldLinks(room));
|
|
73
|
+
notifications.reach(entry.authority, at);
|
|
74
|
+
return [presented(entry.authority, at)];
|
|
50
75
|
});
|
|
51
|
-
|
|
52
|
-
const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;
|
|
53
|
-
const failure = modelFailure(classified, envelope);
|
|
54
|
-
for (const entry of entries){
|
|
55
|
-
acquired.set(modelKey(entry.locator, 'collection'), await held(envelope, entry, entry.modelRoot, `${authorityRoot(entry.handle)}/${entry.modelRoot}`, failure));
|
|
56
|
-
}
|
|
57
|
-
if (privateEntry !== undefined) {
|
|
58
|
-
acquired.set(modelKey(privateEntry.locator, 'typed-selection'), await held(envelope, privateEntry, PROVIDER_SELECTION_MODEL_ROOT, `${authorityRoot(undefined)}/${PROVIDER_SELECTION_MODEL_ROOT}`, failure));
|
|
59
|
-
}
|
|
60
|
-
return acquired;
|
|
76
|
+
notifications.send(kept);
|
|
61
77
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
78
|
+
function adopted(entry, outcome) {
|
|
79
|
+
if (outcome.kind !== 'accepted')
|
|
80
|
+
return outcome;
|
|
81
|
+
const { originals, ...accepted } = outcome;
|
|
82
|
+
const links = handed.get(entry.locator);
|
|
83
|
+
if (links === undefined)
|
|
84
|
+
return accepted;
|
|
85
|
+
const follows = followsVersion(links.roomVersion, accepted.roomVersion);
|
|
86
|
+
const relinked = acceptedLinks(links, accepted, follows ? accepted.roomVersion : links.roomVersion, originals);
|
|
87
|
+
handed.set(entry.locator, relinked.links);
|
|
88
|
+
const at = logPosition(accepted.roomVersion);
|
|
89
|
+
if (follows && at !== null)
|
|
90
|
+
notifications.reach(entry.authority, at);
|
|
91
|
+
return relinked.attachments === undefined
|
|
92
|
+
? accepted
|
|
93
|
+
: { ...accepted, attachments: relinked.attachments };
|
|
71
94
|
}
|
|
72
95
|
function authorityFor(locator) {
|
|
73
96
|
return tracked.get(locator);
|
|
74
97
|
}
|
|
98
|
+
function withAt(result) {
|
|
99
|
+
if (result.kind !== 'action')
|
|
100
|
+
return result;
|
|
101
|
+
const body = result.result;
|
|
102
|
+
if (typeof body !== 'object' || body === null)
|
|
103
|
+
return result;
|
|
104
|
+
const { authority, position, log_epoch: logEpoch } = body;
|
|
105
|
+
if (typeof position !== 'string' || typeof logEpoch !== 'string')
|
|
106
|
+
return result;
|
|
107
|
+
const locator = authority === undefined
|
|
108
|
+
? PRIVATE_LOCATOR
|
|
109
|
+
: [...tracked.values()].find((entry) => entry.authority === authority)?.locator;
|
|
110
|
+
if (locator === undefined)
|
|
111
|
+
return result;
|
|
112
|
+
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
113
|
+
}
|
|
75
114
|
async function bundled(body) {
|
|
76
115
|
const grant = parseGrant(body);
|
|
77
|
-
if (grant === null)
|
|
78
|
-
|
|
116
|
+
if (grant === null)
|
|
117
|
+
return body;
|
|
118
|
+
if (grant.method !== 'GET')
|
|
119
|
+
return null;
|
|
79
120
|
const answer = await transport.transfer({
|
|
80
|
-
act: '
|
|
121
|
+
act: 'local_copy_bundle',
|
|
81
122
|
method: 'GET',
|
|
82
|
-
url: grant.url
|
|
123
|
+
url: grant.url,
|
|
124
|
+
answer: 'json',
|
|
83
125
|
});
|
|
84
126
|
return answer.status === 200 ? answer.body : null;
|
|
85
127
|
}
|
|
86
|
-
|
|
128
|
+
function weight(entry) {
|
|
129
|
+
return contentPrefixes(entry).length;
|
|
130
|
+
}
|
|
131
|
+
async function bootstrapped(entries) {
|
|
132
|
+
const answers = [];
|
|
133
|
+
for (const part of selections(entries, weight, declared().max_prefixes)) {
|
|
134
|
+
const answer = await transport.door(DOOR_BOOTSTRAP, {
|
|
135
|
+
prefixes: part.flatMap((entry) => contentPrefixes(entry)),
|
|
136
|
+
});
|
|
137
|
+
const classified = part.map((entry) => classifyDoor(answer.status, answer.body, entry.locator));
|
|
138
|
+
const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;
|
|
139
|
+
for (const [index, entry] of part.entries()) {
|
|
140
|
+
const failure = classified[index];
|
|
141
|
+
if (failure === null || failure === undefined) {
|
|
142
|
+
answers.push(envelope === null ? UNCERTAIN_READ : await bootstrappedRoom(envelope, entry));
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
answers.push(failure.kind === 'beyond-horizon' ? UNCERTAIN_READ : failure);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return answers;
|
|
149
|
+
}
|
|
150
|
+
function layered(asks) {
|
|
151
|
+
const depths = new Map();
|
|
152
|
+
const layers = [];
|
|
153
|
+
for (const ask of asks) {
|
|
154
|
+
const depth = depths.get(ask.entry.authority) ?? 0;
|
|
155
|
+
depths.set(ask.entry.authority, depth + 1);
|
|
156
|
+
(layers[depth] ??= []).push(ask);
|
|
157
|
+
}
|
|
158
|
+
return layers;
|
|
159
|
+
}
|
|
160
|
+
async function enumerated(asks) {
|
|
161
|
+
const answers = new Map();
|
|
162
|
+
const parts = layered(asks).flatMap((layer) => selections(layer, (ask) => weight(ask.entry), declared().max_prefixes));
|
|
163
|
+
for (const part of parts) {
|
|
164
|
+
let open = [...part];
|
|
165
|
+
while (open.length > 0) {
|
|
166
|
+
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
167
|
+
prefixes: open.flatMap((ask) => contentPrefixes(ask.entry)),
|
|
168
|
+
positions: open.map((ask) => presented(ask.entry.authority, ask.from)),
|
|
169
|
+
});
|
|
170
|
+
const classified = open.map((ask) => classifyDoor(answer.status, answer.body, ask.entry.locator));
|
|
171
|
+
if (classified[0]?.kind === 'beyond-horizon') {
|
|
172
|
+
const named = doorRefusal(answer.body)?.fields.authority;
|
|
173
|
+
const expired = open.filter((ask) => ask.entry.authority === named);
|
|
174
|
+
const answered = expired.length === 0 ? UNCERTAIN_READ : { kind: 'beyond-horizon' };
|
|
175
|
+
const gone = expired.length === 0 ? open : expired;
|
|
176
|
+
for (const ask of gone)
|
|
177
|
+
answers.set(ask, answered);
|
|
178
|
+
open = open.filter((ask) => !gone.includes(ask));
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
|
|
182
|
+
for (const [index, ask] of open.entries()) {
|
|
183
|
+
const failure = classified[index];
|
|
184
|
+
if (failure !== null && failure !== undefined) {
|
|
185
|
+
answers.set(ask, failure);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
answers.set(ask, enumeration === null ? UNCERTAIN_READ : await enumeratedRoom(enumeration, ask));
|
|
189
|
+
}
|
|
190
|
+
open = [];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return asks.map((ask) => answers.get(ask) ?? UNCERTAIN_READ);
|
|
194
|
+
}
|
|
195
|
+
const bootstrapTogether = gathered(bootstrapped);
|
|
196
|
+
const enumerateTogether = gathered(enumerated);
|
|
197
|
+
async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
|
|
87
198
|
const paths = batchPaths(changes);
|
|
88
199
|
const sha256 = await deltaDigest(delta);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
93
|
-
const minted = await transport.door(DOOR_BATCH_UPLOAD, {
|
|
94
|
-
operation_id: identity,
|
|
95
|
-
paths,
|
|
96
|
-
bytes,
|
|
97
|
-
sha256
|
|
98
|
-
});
|
|
200
|
+
if (handed !== undefined && handed.sha256 === sha256) {
|
|
201
|
+
return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
|
|
202
|
+
}
|
|
203
|
+
const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });
|
|
99
204
|
if (minted.status !== 200) {
|
|
100
|
-
return {
|
|
101
|
-
outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)
|
|
102
|
-
};
|
|
205
|
+
return { outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle) };
|
|
103
206
|
}
|
|
104
207
|
const grant = parseGrant(minted.body);
|
|
105
|
-
if (grant === null || grant.method !== 'POST')
|
|
106
|
-
outcome: UNCERTAIN
|
|
107
|
-
};
|
|
208
|
+
if (grant === null || grant.method !== 'POST')
|
|
209
|
+
return { outcome: UNCERTAIN };
|
|
108
210
|
const delivered = await transport.transfer({
|
|
109
211
|
act: 'authored_batch_upload',
|
|
110
212
|
method: 'POST',
|
|
111
213
|
url: grant.url,
|
|
112
|
-
|
|
214
|
+
answer: 'json',
|
|
215
|
+
body: `${grant.operation}\n${delta}`,
|
|
113
216
|
});
|
|
114
|
-
if (delivered.status !== 200)
|
|
115
|
-
outcome: UNCERTAIN
|
|
116
|
-
};
|
|
217
|
+
if (delivered.status !== 200)
|
|
218
|
+
return { outcome: UNCERTAIN };
|
|
117
219
|
const holding = parseGrant(delivered.body);
|
|
118
|
-
if (holding === null
|
|
119
|
-
outcome: UNCERTAIN
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
paths,
|
|
124
|
-
upload: {
|
|
125
|
-
url: holding.url,
|
|
126
|
-
operation: holding.operation,
|
|
127
|
-
bytes,
|
|
128
|
-
sha256
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
submissions.set(identity, {
|
|
132
|
-
sha256,
|
|
133
|
-
body
|
|
134
|
-
});
|
|
135
|
-
return {
|
|
136
|
-
body
|
|
137
|
-
};
|
|
220
|
+
if (holding === null || holding.method !== 'POST')
|
|
221
|
+
return { outcome: UNCERTAIN };
|
|
222
|
+
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
223
|
+
await keep(upload);
|
|
224
|
+
return { body: { ...head, paths, upload, runtime: notifications.runtime } };
|
|
138
225
|
}
|
|
139
|
-
async function submit(
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if ('outcome' in prepared) return prepared.outcome;
|
|
226
|
+
async function submit(head, changes, delta, bytes, entry, handed, keep) {
|
|
227
|
+
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
228
|
+
const prepared = uploadable(inline, bytes, declared())
|
|
229
|
+
? await uploaded(head, changes, delta, bytes, entry, handed, keep)
|
|
230
|
+
: { body: inline };
|
|
231
|
+
if ('outcome' in prepared)
|
|
232
|
+
return prepared.outcome;
|
|
147
233
|
const answer = await transport.door(DOOR_BATCH, prepared.body);
|
|
148
234
|
return mutationOutcome(answer.status, answer.body, entry.locator, entry.handle);
|
|
149
235
|
}
|
|
150
236
|
return {
|
|
151
|
-
async authorize
|
|
237
|
+
async authorize() {
|
|
152
238
|
return options.authorize();
|
|
153
239
|
},
|
|
154
|
-
async
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
prefixes: [
|
|
160
|
-
...DISCOVER_PREFIXES
|
|
161
|
-
]
|
|
162
|
-
});
|
|
163
|
-
const classified = classifyDoor(answer.status, answer.body, PRIVATE_AUTHORITY);
|
|
164
|
-
if (classified !== null) return discoveryFailure(classified);
|
|
240
|
+
async discover(_authorization) {
|
|
241
|
+
const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });
|
|
242
|
+
const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
|
|
243
|
+
if (classified !== null)
|
|
244
|
+
return discoveryFailure(classified);
|
|
165
245
|
const document = parseDiscovery(answer.body);
|
|
166
|
-
if (document === null)
|
|
167
|
-
kind: 'transport-uncertainty'
|
|
168
|
-
|
|
246
|
+
if (document === null)
|
|
247
|
+
return { kind: 'transport-uncertainty' };
|
|
248
|
+
bounds = document.bounds;
|
|
169
249
|
const entries = trackedFrom(document);
|
|
170
250
|
tracked.clear();
|
|
171
|
-
for (const entry of entries)
|
|
251
|
+
for (const entry of entries)
|
|
252
|
+
tracked.set(entry.locator, entry);
|
|
253
|
+
for (const locator of handed.keys())
|
|
254
|
+
if (!tracked.has(locator))
|
|
255
|
+
handed.delete(locator);
|
|
172
256
|
notifications.track(entries);
|
|
173
|
-
|
|
174
|
-
models.keep(entries.map((entry)=>entry.locator));
|
|
175
|
-
return mapDiscovery(document, document.authorities.map((authority)=>roomOf(authority, acquired)), capabilities());
|
|
257
|
+
return mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions));
|
|
176
258
|
},
|
|
177
|
-
async bootstrap
|
|
259
|
+
async bootstrap(_authorization, request) {
|
|
178
260
|
const entry = authorityFor(request.locator);
|
|
179
|
-
if (entry === undefined)
|
|
180
|
-
kind: 'room-not-readable',
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
kind: 'transport-uncertainty'
|
|
185
|
-
};
|
|
186
|
-
const answer = await transport.door(DOOR_BOOTSTRAP, {
|
|
187
|
-
prefixes: [
|
|
188
|
-
...contentPrefixes(entry)
|
|
189
|
-
]
|
|
190
|
-
});
|
|
191
|
-
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
192
|
-
if (classified !== null) {
|
|
193
|
-
return classified.kind === 'beyond-horizon' ? {
|
|
194
|
-
kind: 'transport-uncertainty'
|
|
195
|
-
} : classified;
|
|
196
|
-
}
|
|
197
|
-
const envelope = parseEnvelope(await bundled(answer.body));
|
|
198
|
-
if (envelope === null) return {
|
|
199
|
-
kind: 'transport-uncertainty'
|
|
200
|
-
};
|
|
201
|
-
return bootstrapFrom(envelope, entry);
|
|
261
|
+
if (entry === undefined)
|
|
262
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
263
|
+
if (request.pageToken !== undefined)
|
|
264
|
+
return { kind: 'transport-uncertainty' };
|
|
265
|
+
return bootstrapTogether(entry);
|
|
202
266
|
},
|
|
203
|
-
async refresh
|
|
267
|
+
async refresh(_authorization, request) {
|
|
204
268
|
const entry = authorityFor(request.locator);
|
|
205
|
-
if (entry === undefined)
|
|
206
|
-
kind: 'room-not-readable',
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (request.pageToken !== undefined) return {
|
|
210
|
-
kind: 'transport-uncertainty'
|
|
211
|
-
};
|
|
269
|
+
if (entry === undefined)
|
|
270
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
271
|
+
if (request.pageToken !== undefined)
|
|
272
|
+
return { kind: 'transport-uncertainty' };
|
|
212
273
|
const from = logPosition(request.fromRoomVersion);
|
|
213
|
-
if (from === null)
|
|
214
|
-
kind: 'beyond-horizon'
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
prefixes: [
|
|
220
|
-
...contentPrefixes(entry)
|
|
221
|
-
],
|
|
222
|
-
positions: [
|
|
223
|
-
presented(entry.authority, from)
|
|
224
|
-
]
|
|
225
|
-
});
|
|
226
|
-
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
227
|
-
if (classified !== null) return classified;
|
|
228
|
-
const enumeration = parseEnumeration(answer.body, 'credential');
|
|
229
|
-
if (enumeration === null) return {
|
|
230
|
-
kind: 'transport-uncertainty'
|
|
231
|
-
};
|
|
232
|
-
return refreshFrom(enumeration, entry, request.fromRoomVersion);
|
|
274
|
+
if (from === null)
|
|
275
|
+
return { kind: 'beyond-horizon' };
|
|
276
|
+
const answered = await streamed(entry, request, from);
|
|
277
|
+
if (answered !== null)
|
|
278
|
+
return answered;
|
|
279
|
+
return enumerateTogether({ entry, from, fromRoomVersion: request.fromRoomVersion });
|
|
233
280
|
},
|
|
234
|
-
async mutate
|
|
281
|
+
async mutate(_authorization, request, keep) {
|
|
235
282
|
const entry = authorityFor(request.locator);
|
|
236
|
-
if (entry === undefined)
|
|
237
|
-
kind: 'room-not-readable',
|
|
238
|
-
locator: request.locator
|
|
239
|
-
};
|
|
283
|
+
if (entry === undefined)
|
|
284
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
240
285
|
const mapped = houseChanges(request.changeBatch, entry.handle);
|
|
241
|
-
if (mapped.kind === 'unmapped')
|
|
242
|
-
|
|
286
|
+
if (mapped.kind === 'unmapped')
|
|
287
|
+
return rejectedMapping(mapped);
|
|
288
|
+
const head = operationHead(request.changeBatch);
|
|
243
289
|
const delta = deltaBody(mapped.changes);
|
|
244
290
|
const bytes = deltaBytes(delta);
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
if (
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
if (RESOLVED_OUTCOMES.has(outcome.kind)) submissions.delete(identity);
|
|
252
|
-
return outcome;
|
|
291
|
+
const handed = request.upload;
|
|
292
|
+
const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);
|
|
293
|
+
if (handed === undefined || !lapsedGrant(outcome))
|
|
294
|
+
return adopted(entry, outcome);
|
|
295
|
+
return adopted(entry, await submit(head, mapped.changes, delta, bytes, entry, undefined, keep));
|
|
253
296
|
},
|
|
254
|
-
async history
|
|
297
|
+
async history(_authorization, request) {
|
|
255
298
|
const entry = authorityFor(request.locator);
|
|
256
|
-
if (entry === undefined)
|
|
257
|
-
kind: 'room-not-readable',
|
|
258
|
-
locator: request.locator
|
|
259
|
-
};
|
|
299
|
+
if (entry === undefined)
|
|
300
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
260
301
|
const answer = await transport.door(DOOR_REVISIONS, revisionBody({
|
|
261
302
|
path: request.path,
|
|
262
303
|
handle: entry.handle,
|
|
263
|
-
...request.revision === undefined ? {} : {
|
|
264
|
-
|
|
265
|
-
},
|
|
266
|
-
...request.pageToken === undefined ? {} : {
|
|
267
|
-
pageToken: request.pageToken
|
|
268
|
-
}
|
|
304
|
+
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
305
|
+
...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),
|
|
269
306
|
}));
|
|
270
307
|
return historyOutcome(answer.status, answer.body, entry.locator, {
|
|
271
308
|
path: request.path,
|
|
272
|
-
...request.revision === undefined ? {} : {
|
|
273
|
-
revision: request.revision
|
|
274
|
-
}
|
|
309
|
+
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
275
310
|
});
|
|
276
311
|
},
|
|
277
|
-
|
|
278
|
-
return
|
|
312
|
+
reached(locator, version, target) {
|
|
313
|
+
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
314
|
+
},
|
|
315
|
+
follows(_locator, version, next) {
|
|
316
|
+
return followsVersion(version, next);
|
|
317
|
+
},
|
|
318
|
+
async action(_authorization, request) {
|
|
319
|
+
return withAt(await houseAction(transport, request));
|
|
279
320
|
},
|
|
280
|
-
|
|
281
|
-
conversations: notifications.conversations
|
|
321
|
+
roomStream: { hold: held, observe: notifications.observe },
|
|
322
|
+
conversations: notifications.conversations,
|
|
323
|
+
serviceMode: notifications.serviceMode,
|
|
282
324
|
};
|
|
283
325
|
}
|
|
284
|
-
|
|
285
|
-
//# sourceMappingURL=adapter.js.map
|
package/dist/digest.js
CHANGED
|
@@ -3,9 +3,5 @@ export function textBytes(value) {
|
|
|
3
3
|
}
|
|
4
4
|
export async function sha256Hex(value) {
|
|
5
5
|
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(value));
|
|
6
|
-
return [
|
|
7
|
-
...new Uint8Array(digest)
|
|
8
|
-
].map((byte)=>byte.toString(16).padStart(2, '0')).join('');
|
|
6
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
9
7
|
}
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=digest.js.map
|