@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c9f1e531ad7c8
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 +157 -26
- package/README.md +32 -0
- package/dist/actions.d.ts +4 -12
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +239 -332
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +258 -193
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +20 -18
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +182 -210
- 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 +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/links.d.ts +12 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +66 -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 +2 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +21 -39
- package/dist/read.d.ts +29 -23
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +222 -195
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +30 -51
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +110 -124
- package/dist/stream.d.ts +11 -5
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +211 -213
- package/dist/transport.d.ts +46 -28
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +3 -3
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +23 -18
- package/dist/write.d.ts +3 -3
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +120 -203
- 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,EAad,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAad,MAAM,wBAAwB,CAAC;AA0ChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAuBxB,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;AAiCjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAkZpF"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,61 +1,91 @@
|
|
|
1
|
-
import { DISCOVER_PREFIXES,
|
|
2
|
-
import { MODEL_ABSENT, failedModel, heldModel, modelKey, modelShelf } from './model.js';
|
|
1
|
+
import { DISCOVER_PREFIXES, HOUSE_SCHEMA, capabilities, discoveredRoom, locatorOf, mapDiscovery, parseDiscovery, providerSelection, trackedFrom, } from './discovery.js';
|
|
2
|
+
import { MODEL_ABSENT, failedModel, heldModel, modelKey, modelShelf, } 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, schemaFrom, schemaPath, viewOf, } from './read.js';
|
|
6
|
+
import { enumeratedLinks, 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, operationHead, 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, DOOR_SELECTION_MAX, PRIVATE_LOCATOR, } from './transport.js';
|
|
11
|
+
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
12
|
+
import { 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
18
|
function modelFailure(classified, envelope) {
|
|
24
19
|
if (classified === null) {
|
|
25
|
-
return envelope === null ? {
|
|
26
|
-
kind: 'transport-uncertainty'
|
|
27
|
-
} : MODEL_ABSENT;
|
|
20
|
+
return envelope === null ? { kind: 'transport-uncertainty' } : MODEL_ABSENT;
|
|
28
21
|
}
|
|
29
22
|
return failedModel(classified);
|
|
30
23
|
}
|
|
31
24
|
export function createAgentsHouseAdapter(options) {
|
|
32
|
-
if ('site' in options)
|
|
25
|
+
if ('site' in options)
|
|
26
|
+
return createSiteAdapter(options.site);
|
|
33
27
|
const transport = options.transport;
|
|
34
28
|
const notifications = houseNotifications(transport, 'credential');
|
|
35
29
|
const tracked = new Map();
|
|
30
|
+
const handed = new Map();
|
|
36
31
|
const models = modelShelf();
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
function bootstrappedRoom(envelope, entry) {
|
|
33
|
+
const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
|
|
34
|
+
if (scope === undefined)
|
|
35
|
+
return { kind: 'room-not-readable', locator: entry.locator };
|
|
36
|
+
handed.set(entry.locator, scopeLinks(scope));
|
|
37
|
+
notifications.hold(entry.authority, scope);
|
|
38
|
+
return bootstrapOf(scope, entry);
|
|
39
|
+
}
|
|
40
|
+
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.hold(ask.entry.authority, view);
|
|
45
|
+
const answer = refreshFrom(view, ask.entry, ask.fromRoomVersion);
|
|
46
|
+
if (answer.kind === 'net-advancement') {
|
|
47
|
+
handed.set(ask.entry.locator, enumeratedLinks(view, handed.get(ask.entry.locator)));
|
|
48
|
+
}
|
|
49
|
+
return answer;
|
|
50
|
+
}
|
|
51
|
+
function streamed(entry, request, from) {
|
|
52
|
+
const links = handed.get(entry.locator);
|
|
53
|
+
if (links?.roomVersion !== request.fromRoomVersion)
|
|
54
|
+
return null;
|
|
55
|
+
const advanced = notifications.advance(entry, from, (path, revision) => links.revisions.get(path) === revision);
|
|
56
|
+
if (advanced === null)
|
|
57
|
+
return null;
|
|
58
|
+
if (request.minPosition !== undefined &&
|
|
59
|
+
!reachedVersion(advanced.page.roomVersion, request.minPosition, entry.logEpoch))
|
|
60
|
+
return null;
|
|
61
|
+
const relinked = streamedLinks(links, advanced);
|
|
62
|
+
if (relinked === null)
|
|
63
|
+
return null;
|
|
64
|
+
handed.set(entry.locator, relinked);
|
|
65
|
+
return advanced.page;
|
|
66
|
+
}
|
|
67
|
+
function held(envelope, entry, schema, failure) {
|
|
68
|
+
return heldModel(envelope === null ? null : schemaFrom(envelope, entry, schema), schemaPath(entry.handle, schema), failure);
|
|
69
|
+
}
|
|
70
|
+
function modelPrefixes(entry) {
|
|
71
|
+
return entry.schemas.map((schema) => schemaPath(entry.handle, schema));
|
|
40
72
|
}
|
|
41
73
|
async function acquireModels(entries) {
|
|
42
74
|
const acquired = new Map();
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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));
|
|
75
|
+
for (const part of selections(entries, (entry) => modelPrefixes(entry).length, DOOR_SELECTION_MAX)) {
|
|
76
|
+
const privateEntry = part.find((entry) => entry.locator === PRIVATE_LOCATOR);
|
|
77
|
+
const answer = await transport.door(DOOR_BOOTSTRAP, {
|
|
78
|
+
prefixes: part.flatMap((entry) => modelPrefixes(entry)),
|
|
79
|
+
});
|
|
80
|
+
const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
|
|
81
|
+
const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;
|
|
82
|
+
const failure = modelFailure(classified, envelope);
|
|
83
|
+
for (const entry of part) {
|
|
84
|
+
acquired.set(modelKey(entry.locator, 'collection'), await held(envelope, entry, entry.schema, failure));
|
|
85
|
+
}
|
|
86
|
+
if (privateEntry !== undefined) {
|
|
87
|
+
acquired.set(modelKey(privateEntry.locator, 'typed-selection'), await held(envelope, privateEntry, HOUSE_SCHEMA, failure));
|
|
88
|
+
}
|
|
59
89
|
}
|
|
60
90
|
return acquired;
|
|
61
91
|
}
|
|
@@ -63,7 +93,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
63
93
|
const locator = locatorOf(authority);
|
|
64
94
|
const key = modelKey(locator, 'collection');
|
|
65
95
|
const collection = models.retain(key, acquired.get(key));
|
|
66
|
-
if (
|
|
96
|
+
if (locator !== PRIVATE_LOCATOR) {
|
|
67
97
|
return discoveredRoom(authority, collection?.identity ?? null, undefined);
|
|
68
98
|
}
|
|
69
99
|
const selection = models.retain(modelKey(locator, 'typed-selection'), acquired.get(modelKey(locator, 'typed-selection')));
|
|
@@ -72,214 +102,249 @@ export function createAgentsHouseAdapter(options) {
|
|
|
72
102
|
function authorityFor(locator) {
|
|
73
103
|
return tracked.get(locator);
|
|
74
104
|
}
|
|
105
|
+
function withAt(result) {
|
|
106
|
+
if (result.kind !== 'action')
|
|
107
|
+
return result;
|
|
108
|
+
const body = result.result;
|
|
109
|
+
if (typeof body !== 'object' || body === null)
|
|
110
|
+
return result;
|
|
111
|
+
const { authority, position, log_epoch: logEpoch } = body;
|
|
112
|
+
if (typeof position !== 'string' || typeof logEpoch !== 'string')
|
|
113
|
+
return result;
|
|
114
|
+
const locator = authority === undefined
|
|
115
|
+
? PRIVATE_LOCATOR
|
|
116
|
+
: [...tracked.values()].find((entry) => entry.authority === authority)?.locator;
|
|
117
|
+
if (locator === undefined)
|
|
118
|
+
return result;
|
|
119
|
+
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
120
|
+
}
|
|
75
121
|
async function bundled(body) {
|
|
76
122
|
const grant = parseGrant(body);
|
|
77
|
-
if (grant === null)
|
|
78
|
-
|
|
123
|
+
if (grant === null)
|
|
124
|
+
return body;
|
|
125
|
+
if (grant.method !== 'GET')
|
|
126
|
+
return null;
|
|
79
127
|
const answer = await transport.transfer({
|
|
80
|
-
act: '
|
|
128
|
+
act: 'local_copy_bundle',
|
|
81
129
|
method: 'GET',
|
|
82
|
-
url: grant.url
|
|
130
|
+
url: grant.url,
|
|
131
|
+
answer: 'json',
|
|
83
132
|
});
|
|
84
133
|
return answer.status === 200 ? answer.body : null;
|
|
85
134
|
}
|
|
86
|
-
|
|
135
|
+
function weight(entry) {
|
|
136
|
+
return contentPrefixes(entry).length;
|
|
137
|
+
}
|
|
138
|
+
async function bootstrapped(entries) {
|
|
139
|
+
const answers = [];
|
|
140
|
+
for (const part of selections(entries, weight, DOOR_SELECTION_MAX)) {
|
|
141
|
+
const answer = await transport.door(DOOR_BOOTSTRAP, {
|
|
142
|
+
prefixes: part.flatMap((entry) => contentPrefixes(entry)),
|
|
143
|
+
});
|
|
144
|
+
const classified = part.map((entry) => classifyDoor(answer.status, answer.body, entry.locator));
|
|
145
|
+
const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;
|
|
146
|
+
part.forEach((entry, index) => {
|
|
147
|
+
const failure = classified[index];
|
|
148
|
+
if (failure === null || failure === undefined) {
|
|
149
|
+
answers.push(envelope === null ? UNCERTAIN_READ : bootstrappedRoom(envelope, entry));
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
answers.push(failure.kind === 'beyond-horizon' ? UNCERTAIN_READ : failure);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return answers;
|
|
156
|
+
}
|
|
157
|
+
function layered(asks) {
|
|
158
|
+
const depths = new Map();
|
|
159
|
+
const layers = [];
|
|
160
|
+
for (const ask of asks) {
|
|
161
|
+
const depth = depths.get(ask.entry.authority) ?? 0;
|
|
162
|
+
depths.set(ask.entry.authority, depth + 1);
|
|
163
|
+
(layers[depth] ??= []).push(ask);
|
|
164
|
+
}
|
|
165
|
+
return layers;
|
|
166
|
+
}
|
|
167
|
+
async function enumerated(asks) {
|
|
168
|
+
const answers = new Map();
|
|
169
|
+
const parts = layered(asks).flatMap((layer) => selections(layer, (ask) => weight(ask.entry), DOOR_SELECTION_MAX));
|
|
170
|
+
for (const part of parts) {
|
|
171
|
+
let open = [...part];
|
|
172
|
+
while (open.length > 0) {
|
|
173
|
+
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
174
|
+
prefixes: open.flatMap((ask) => contentPrefixes(ask.entry)),
|
|
175
|
+
positions: open.map((ask) => ({
|
|
176
|
+
...presented(ask.entry.authority, ask.from),
|
|
177
|
+
...(ask.minPosition === undefined ? {} : { min_position: ask.minPosition }),
|
|
178
|
+
})),
|
|
179
|
+
});
|
|
180
|
+
const refusal = doorRefusal(answer.body);
|
|
181
|
+
if (refusal?.code === 'replica_behind') {
|
|
182
|
+
const named = open.filter((ask) => ask.entry.authority === refusal.fields.authority);
|
|
183
|
+
const behind = named.length === 0 ? open : named;
|
|
184
|
+
for (const ask of behind)
|
|
185
|
+
answers.set(ask, { kind: 'retryable-refusal', ...refusal });
|
|
186
|
+
open = open.filter((ask) => !behind.includes(ask));
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const classified = open.map((ask) => classifyDoor(answer.status, answer.body, ask.entry.locator));
|
|
190
|
+
if (classified[0]?.kind === 'beyond-horizon') {
|
|
191
|
+
const named = doorRefusal(answer.body)?.fields.authority;
|
|
192
|
+
const expired = open.filter((ask) => ask.entry.authority === named);
|
|
193
|
+
const answered = expired.length === 0 ? UNCERTAIN_READ : { kind: 'beyond-horizon' };
|
|
194
|
+
const gone = expired.length === 0 ? open : expired;
|
|
195
|
+
for (const ask of gone)
|
|
196
|
+
answers.set(ask, answered);
|
|
197
|
+
open = open.filter((ask) => !gone.includes(ask));
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
|
|
201
|
+
open.forEach((ask, index) => {
|
|
202
|
+
const failure = classified[index];
|
|
203
|
+
if (failure !== null && failure !== undefined) {
|
|
204
|
+
answers.set(ask, failure);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
answers.set(ask, enumeration === null ? UNCERTAIN_READ : enumeratedRoom(enumeration, ask));
|
|
208
|
+
});
|
|
209
|
+
open = [];
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return asks.map((ask) => answers.get(ask) ?? UNCERTAIN_READ);
|
|
213
|
+
}
|
|
214
|
+
const bootstrapTogether = gathered(bootstrapped);
|
|
215
|
+
const enumerateTogether = gathered(enumerated);
|
|
216
|
+
async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
|
|
87
217
|
const paths = batchPaths(changes);
|
|
88
218
|
const sha256 = await deltaDigest(delta);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
93
|
-
const minted = await transport.door(DOOR_BATCH_UPLOAD, {
|
|
94
|
-
...head,
|
|
95
|
-
paths,
|
|
96
|
-
bytes,
|
|
97
|
-
sha256
|
|
98
|
-
});
|
|
219
|
+
if (handed !== undefined && handed.sha256 === sha256) {
|
|
220
|
+
return { body: { ...head, paths, upload: handed } };
|
|
221
|
+
}
|
|
222
|
+
const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });
|
|
99
223
|
if (minted.status !== 200) {
|
|
100
|
-
return {
|
|
101
|
-
outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle)
|
|
102
|
-
};
|
|
224
|
+
return { outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle) };
|
|
103
225
|
}
|
|
104
226
|
const grant = parseGrant(minted.body);
|
|
105
|
-
if (grant === null || grant.method !== 'POST')
|
|
106
|
-
outcome: UNCERTAIN
|
|
107
|
-
};
|
|
227
|
+
if (grant === null || grant.method !== 'POST')
|
|
228
|
+
return { outcome: UNCERTAIN };
|
|
108
229
|
const delivered = await transport.transfer({
|
|
109
230
|
act: 'authored_batch_upload',
|
|
110
231
|
method: 'POST',
|
|
111
232
|
url: grant.url,
|
|
112
|
-
|
|
233
|
+
answer: 'json',
|
|
234
|
+
body: `${grant.operation}\n${delta}`,
|
|
113
235
|
});
|
|
114
|
-
if (delivered.status !== 200)
|
|
115
|
-
outcome: UNCERTAIN
|
|
116
|
-
};
|
|
236
|
+
if (delivered.status !== 200)
|
|
237
|
+
return { outcome: UNCERTAIN };
|
|
117
238
|
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(head.operation_id, {
|
|
132
|
-
sha256,
|
|
133
|
-
body
|
|
134
|
-
});
|
|
135
|
-
return {
|
|
136
|
-
body
|
|
137
|
-
};
|
|
239
|
+
if (holding === null || holding.method !== 'POST')
|
|
240
|
+
return { outcome: UNCERTAIN };
|
|
241
|
+
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
242
|
+
await keep(upload);
|
|
243
|
+
return { body: { ...head, paths, upload } };
|
|
138
244
|
}
|
|
139
|
-
async function submit(head, changes, delta, bytes, entry) {
|
|
140
|
-
const prepared = uploadable(bytes)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
};
|
|
146
|
-
if ('outcome' in prepared) return prepared.outcome;
|
|
245
|
+
async function submit(head, changes, delta, bytes, entry, handed, keep) {
|
|
246
|
+
const prepared = uploadable(bytes)
|
|
247
|
+
? await uploaded(head, changes, delta, bytes, entry, handed, keep)
|
|
248
|
+
: { body: { ...head, changes } };
|
|
249
|
+
if ('outcome' in prepared)
|
|
250
|
+
return prepared.outcome;
|
|
147
251
|
const answer = await transport.door(DOOR_BATCH, prepared.body);
|
|
148
252
|
return mutationOutcome(answer.status, answer.body, entry.locator, entry.handle);
|
|
149
253
|
}
|
|
150
254
|
return {
|
|
151
|
-
async authorize
|
|
255
|
+
async authorize() {
|
|
152
256
|
return options.authorize();
|
|
153
257
|
},
|
|
154
|
-
async model
|
|
258
|
+
async model(_authorization, request) {
|
|
155
259
|
return models.answer(request);
|
|
156
260
|
},
|
|
157
|
-
async discover
|
|
158
|
-
const answer = await transport.door(DOOR_DISCOVER, {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
});
|
|
163
|
-
const classified = classifyDoor(answer.status, answer.body, PRIVATE_AUTHORITY);
|
|
164
|
-
if (classified !== null) return discoveryFailure(classified);
|
|
261
|
+
async discover(_authorization) {
|
|
262
|
+
const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });
|
|
263
|
+
const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
|
|
264
|
+
if (classified !== null)
|
|
265
|
+
return discoveryFailure(classified);
|
|
165
266
|
const document = parseDiscovery(answer.body);
|
|
166
|
-
if (document === null)
|
|
167
|
-
kind: 'transport-uncertainty'
|
|
168
|
-
};
|
|
267
|
+
if (document === null)
|
|
268
|
+
return { kind: 'transport-uncertainty' };
|
|
169
269
|
const entries = trackedFrom(document);
|
|
170
270
|
tracked.clear();
|
|
171
|
-
for (const entry of entries)
|
|
271
|
+
for (const entry of entries)
|
|
272
|
+
tracked.set(entry.locator, entry);
|
|
273
|
+
for (const locator of handed.keys())
|
|
274
|
+
if (!tracked.has(locator))
|
|
275
|
+
handed.delete(locator);
|
|
172
276
|
notifications.track(entries);
|
|
173
277
|
const acquired = await acquireModels(entries);
|
|
174
|
-
models.keep(entries.map((entry)=>entry.locator));
|
|
175
|
-
return mapDiscovery(document, document.authorities.map((authority)=>roomOf(authority, acquired)), capabilities());
|
|
278
|
+
models.keep(entries.map((entry) => entry.locator));
|
|
279
|
+
return mapDiscovery(document, document.authorities.map((authority) => roomOf(authority, acquired)), capabilities(document.actions));
|
|
176
280
|
},
|
|
177
|
-
async bootstrap
|
|
281
|
+
async bootstrap(_authorization, request) {
|
|
178
282
|
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);
|
|
283
|
+
if (entry === undefined)
|
|
284
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
285
|
+
if (request.pageToken !== undefined)
|
|
286
|
+
return { kind: 'transport-uncertainty' };
|
|
287
|
+
return bootstrapTogether(entry);
|
|
202
288
|
},
|
|
203
|
-
async refresh
|
|
289
|
+
async refresh(_authorization, request) {
|
|
204
290
|
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
|
-
};
|
|
291
|
+
if (entry === undefined)
|
|
292
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
293
|
+
if (request.pageToken !== undefined)
|
|
294
|
+
return { kind: 'transport-uncertainty' };
|
|
212
295
|
const from = logPosition(request.fromRoomVersion);
|
|
213
|
-
if (from === null)
|
|
214
|
-
kind: 'beyond-horizon'
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
]
|
|
296
|
+
if (from === null)
|
|
297
|
+
return { kind: 'beyond-horizon' };
|
|
298
|
+
const answered = streamed(entry, request, from);
|
|
299
|
+
if (answered !== null)
|
|
300
|
+
return answered;
|
|
301
|
+
const minPosition = request.minPosition === undefined ? null : logPosition(request.minPosition);
|
|
302
|
+
return enumerateTogether({
|
|
303
|
+
entry,
|
|
304
|
+
from,
|
|
305
|
+
fromRoomVersion: request.fromRoomVersion,
|
|
306
|
+
...(minPosition?.logEpoch === from.logEpoch ? { minPosition: minPosition.position } : {}),
|
|
225
307
|
});
|
|
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);
|
|
233
308
|
},
|
|
234
|
-
async mutate
|
|
309
|
+
async mutate(_authorization, request, keep) {
|
|
235
310
|
const entry = authorityFor(request.locator);
|
|
236
|
-
if (entry === undefined)
|
|
237
|
-
kind: 'room-not-readable',
|
|
238
|
-
locator: request.locator
|
|
239
|
-
};
|
|
311
|
+
if (entry === undefined)
|
|
312
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
240
313
|
const mapped = houseChanges(request.changeBatch, entry.handle);
|
|
241
|
-
if (mapped.kind === 'unmapped')
|
|
314
|
+
if (mapped.kind === 'unmapped')
|
|
315
|
+
return rejectedMapping(mapped);
|
|
242
316
|
const head = operationHead(request.changeBatch);
|
|
243
317
|
const delta = deltaBody(mapped.changes);
|
|
244
318
|
const bytes = deltaBytes(delta);
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
if (
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
if (RESOLVED_OUTCOMES.has(outcome.kind)) submissions.delete(head.operation_id);
|
|
252
|
-
return outcome;
|
|
319
|
+
const handed = request.upload;
|
|
320
|
+
const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);
|
|
321
|
+
if (handed === undefined || !lapsedGrant(outcome))
|
|
322
|
+
return outcome;
|
|
323
|
+
return submit(head, mapped.changes, delta, bytes, entry, undefined, keep);
|
|
253
324
|
},
|
|
254
|
-
async history
|
|
325
|
+
async history(_authorization, request) {
|
|
255
326
|
const entry = authorityFor(request.locator);
|
|
256
|
-
if (entry === undefined)
|
|
257
|
-
kind: 'room-not-readable',
|
|
258
|
-
locator: request.locator
|
|
259
|
-
};
|
|
327
|
+
if (entry === undefined)
|
|
328
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
260
329
|
const answer = await transport.door(DOOR_REVISIONS, revisionBody({
|
|
261
330
|
path: request.path,
|
|
262
331
|
handle: entry.handle,
|
|
263
|
-
...request.revision === undefined ? {} : {
|
|
264
|
-
|
|
265
|
-
},
|
|
266
|
-
...request.pageToken === undefined ? {} : {
|
|
267
|
-
pageToken: request.pageToken
|
|
268
|
-
}
|
|
332
|
+
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
333
|
+
...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),
|
|
269
334
|
}));
|
|
270
335
|
return historyOutcome(answer.status, answer.body, entry.locator, {
|
|
271
336
|
path: request.path,
|
|
272
|
-
...request.revision === undefined ? {} : {
|
|
273
|
-
revision: request.revision
|
|
274
|
-
}
|
|
337
|
+
...(request.revision === undefined ? {} : { revision: request.revision }),
|
|
275
338
|
});
|
|
276
339
|
},
|
|
277
|
-
|
|
278
|
-
return
|
|
340
|
+
reached(locator, version, target) {
|
|
341
|
+
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
342
|
+
},
|
|
343
|
+
async action(_authorization, request) {
|
|
344
|
+
return withAt(await houseAction(transport, request));
|
|
279
345
|
},
|
|
280
346
|
roomVersions: notifications,
|
|
281
|
-
conversations: notifications.conversations
|
|
347
|
+
conversations: notifications.conversations,
|
|
348
|
+
serviceMode: notifications.serviceMode,
|
|
282
349
|
};
|
|
283
350
|
}
|
|
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
|
package/dist/discovery.d.ts
CHANGED
|
@@ -7,10 +7,14 @@ export declare const PROVIDER_ACTIONS = "provider-actions";
|
|
|
7
7
|
export declare const MOVE_REFERENCE_REWRITES = "move-reference-rewrites";
|
|
8
8
|
export declare const DISCOVER_PREFIXES: readonly string[];
|
|
9
9
|
export declare const PROVIDER_SELECTION_ROOTS: readonly string[];
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const UNTYPED_FOLDERS: readonly string[];
|
|
11
|
+
export declare const RESERVED_NAMES: readonly string[];
|
|
12
|
+
export declare const HOUSE_SCHEMA = "house/schema.yaml";
|
|
13
|
+
export declare const PRIVATE_HANDLE = "private";
|
|
11
14
|
export type HouseBounds = {
|
|
12
15
|
max_authored_file_bytes: number;
|
|
13
16
|
max_batch_operations: number;
|
|
17
|
+
max_batch_documents: number;
|
|
14
18
|
max_path_length: number;
|
|
15
19
|
max_path_depth: number;
|
|
16
20
|
max_mount_files: number;
|
|
@@ -25,12 +29,10 @@ export type HouseOperations = {
|
|
|
25
29
|
delete: readonly string[];
|
|
26
30
|
};
|
|
27
31
|
export type HouseAuthority = LogPosition & {
|
|
28
|
-
kind: 'room' | 'private';
|
|
29
32
|
roomRef: string;
|
|
30
|
-
roomHandle: string
|
|
33
|
+
roomHandle: string;
|
|
31
34
|
name: string;
|
|
32
|
-
|
|
33
|
-
modelRoot: string;
|
|
35
|
+
schema: string;
|
|
34
36
|
managedReplication: 'admitted' | 'unavailable';
|
|
35
37
|
protectedPaths: readonly string[];
|
|
36
38
|
operations: HouseOperations;
|
|
@@ -39,24 +41,27 @@ export type HouseDiscoveryDocument = {
|
|
|
39
41
|
bounds: HouseBounds;
|
|
40
42
|
mdModelVersion: string;
|
|
41
43
|
authorities: readonly HouseAuthority[];
|
|
44
|
+
actions: readonly string[];
|
|
42
45
|
};
|
|
43
46
|
export type TrackedAuthority = LogPosition & {
|
|
44
47
|
locator: string;
|
|
45
48
|
authority: string;
|
|
46
|
-
handle: string
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
handle: string;
|
|
50
|
+
schema: string;
|
|
51
|
+
schemas: readonly string[];
|
|
52
|
+
};
|
|
53
|
+
export type HouseSiteEntry = {
|
|
54
|
+
roomRef: string;
|
|
55
|
+
segment: string;
|
|
50
56
|
};
|
|
51
57
|
export type HouseSiteSlot = {
|
|
52
58
|
slot: string;
|
|
53
|
-
|
|
59
|
+
entries: readonly HouseSiteEntry[];
|
|
54
60
|
};
|
|
55
61
|
export type HouseSiteAuthority = LogPosition & {
|
|
56
62
|
roomRef: string;
|
|
57
63
|
roomHandle: string;
|
|
58
|
-
|
|
59
|
-
modelRoot: string;
|
|
64
|
+
schema: string;
|
|
60
65
|
};
|
|
61
66
|
export type HouseSiteDiscovery = {
|
|
62
67
|
bounds: HouseBounds;
|
|
@@ -64,18 +69,15 @@ export type HouseSiteDiscovery = {
|
|
|
64
69
|
slots: readonly HouseSiteSlot[];
|
|
65
70
|
authorities: readonly HouseSiteAuthority[];
|
|
66
71
|
};
|
|
67
|
-
export type SiteTracked = TrackedAuthority & {
|
|
68
|
-
slot: string;
|
|
69
|
-
};
|
|
70
72
|
export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
|
|
71
73
|
export declare function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null;
|
|
72
|
-
export declare function
|
|
73
|
-
export declare function
|
|
74
|
+
export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthority[];
|
|
75
|
+
export declare function siteSlots(document: HouseSiteDiscovery): Discovery['slots'];
|
|
74
76
|
export declare function locatorOf(authority: HouseAuthority): string;
|
|
75
77
|
export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
|
|
76
78
|
export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
|
|
77
79
|
export declare function declaredRetention(bounds: HouseBounds): Retention;
|
|
78
|
-
export declare function capabilities(): readonly Capability[];
|
|
80
|
+
export declare function capabilities(actions: readonly string[]): readonly Capability[];
|
|
79
81
|
export declare function siteCapabilities(): readonly Capability[];
|
|
80
82
|
export declare function providerSelection(attachedModel: TypedSelection['attachedModel']): TypedSelection;
|
|
81
83
|
export declare function discoveredRoom(authority: HouseAuthority, attachedModel: DiscoveredRoom['attachedModel'], typedSelection: TypedSelection | undefined): DiscoveredRoom;
|