@agentshouse/mdruntime-adapter 0.1.0-cf863e7a50d6e → 0.1.0-cfcea2fad4cce
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/README.md +2 -2
- package/dist/actions.d.ts +3 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +26 -9
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +120 -109
- package/dist/app-reference.d.ts +0 -1
- package/dist/authored-path.d.ts +10 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +35 -0
- package/dist/chunks.d.ts +37 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +254 -0
- package/dist/crockford.d.ts +0 -1
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +11 -6
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +39 -13
- package/dist/history.d.ts +1 -7
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +24 -30
- package/dist/house-model.d.ts +239 -368
- package/dist/house-model.d.ts.map +1 -1
- package/dist/house-model.js +231 -288
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +5 -8
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +30 -18
- package/dist/read.d.ts +19 -10
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +46 -143
- package/dist/refusal.d.ts +3 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +17 -7
- package/dist/room-types.d.ts +0 -3
- package/dist/room-types.d.ts.map +1 -1
- package/dist/room-types.js +68 -57
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/bounds.d.ts +7 -0
- package/dist/session-content/check.d.ts +18 -0
- package/dist/session-content/index.d.ts +7 -0
- package/dist/session-content/parts.d.ts +102 -0
- package/dist/session-content/state.d.ts +61 -0
- package/dist/session-content/turn.d.ts +328 -0
- package/dist/site.d.ts +0 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +47 -49
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +18 -0
- package/dist/stream.d.ts +6 -5
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +133 -38
- package/dist/transport.d.ts +26 -23
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +13 -12
- package/dist/uncertain.d.ts +5 -0
- package/dist/uncertain.d.ts.map +1 -0
- package/dist/uncertain.js +11 -0
- package/dist/upload.d.ts +3 -2
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +8 -6
- package/dist/version.d.ts +0 -1
- package/dist/write.d.ts +0 -2
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +24 -38
- package/package.json +2 -2
- package/dist/part.d.ts +0 -14
- package/dist/part.d.ts.map +0 -1
- package/dist/part.js +0 -90
- package/dist/room-stream.d.ts +0 -19
- package/dist/room-stream.d.ts.map +0 -1
- package/dist/room-stream.js +0 -57
package/dist/write.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,WAAW,EAEhB,KAAK,aAAa,EAElB,KAAK,cAAc,EAEpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,WAAW,EAEhB,KAAK,aAAa,EAElB,KAAK,cAAc,EAEpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAQlD,MAAM,M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c,CAC5B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7B,aAAa,CA+Cf"}
|
package/dist/write.js
CHANGED
|
@@ -2,8 +2,9 @@ import { departure, partsChanges, ROW_WEIGHT, } from '@agentshouse/mdruntime';
|
|
|
2
2
|
import { answered, answering, binaryFileOf, headChange, revised } from './read.js';
|
|
3
3
|
import { sha256Hex, textBytes } from './digest.js';
|
|
4
4
|
import { nativePath, roomLocalPath } from './map.js';
|
|
5
|
-
import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
|
|
5
|
+
import { answeredFailure, classifyDoor, doorRefusal, resetOf, scopedRefusal } from './refusal.js';
|
|
6
6
|
import { readPosition, roomVersion } from './version.js';
|
|
7
|
+
import { unusable } from './uncertain.js';
|
|
7
8
|
function priorField(batch, path, name) {
|
|
8
9
|
return batch.preconditions.find((precondition) => precondition.kind === 'field' && precondition.path === path && precondition.name === name);
|
|
9
10
|
}
|
|
@@ -28,7 +29,7 @@ function created(change, path) {
|
|
|
28
29
|
const { type, ...fields } = change.fields;
|
|
29
30
|
if (typeof type !== 'string' || type.length === 0)
|
|
30
31
|
return null;
|
|
31
|
-
return { op: 'create_typed', path, type, fields
|
|
32
|
+
return { op: 'create_typed', path, type, fields };
|
|
32
33
|
}
|
|
33
34
|
function operationOf(batch, change, handle) {
|
|
34
35
|
const path = nativePath(change.path, handle);
|
|
@@ -230,7 +231,7 @@ function* acceptedOf(at, contents) {
|
|
|
230
231
|
answer.changes.set(entry.path, entry.head);
|
|
231
232
|
}
|
|
232
233
|
const unbinaried = answer.binaryFiles.size === 0;
|
|
233
|
-
const { binaryFiles, ...room } = yield* answered(answer);
|
|
234
|
+
const { binaryFiles, facts: _facts, ...room } = yield* answered(answer);
|
|
234
235
|
return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { binaryFiles }) };
|
|
235
236
|
}
|
|
236
237
|
function* movedOutcome(held, move) {
|
|
@@ -244,12 +245,12 @@ function* movedOutcome(held, move) {
|
|
|
244
245
|
const left = at(move.source.authority);
|
|
245
246
|
const arrived = at(move.destination.authority);
|
|
246
247
|
if (left === null || arrived === null)
|
|
247
|
-
return
|
|
248
|
+
return unusable();
|
|
248
249
|
const under = (handle) => (path) => path.startsWith(`/rooms/${handle}/`);
|
|
249
250
|
const leaving = yield* material(held.contents, move.source.handle, under(move.source.handle));
|
|
250
251
|
const arriving = yield* material(held.contents, move.destination.handle, under(move.destination.handle));
|
|
251
252
|
if (leaving === null || arriving === null)
|
|
252
|
-
return
|
|
253
|
+
return unusable();
|
|
253
254
|
return {
|
|
254
255
|
kind: 'accepted',
|
|
255
256
|
...(yield* acceptedOf(left, leaving)),
|
|
@@ -261,11 +262,6 @@ export function* mutationOutcome(status, body, locator, handle, move) {
|
|
|
261
262
|
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
262
263
|
return { kind: 'write-halted' };
|
|
263
264
|
}
|
|
264
|
-
if (refusal !== null && refusal.code === 'expired') {
|
|
265
|
-
return refusal.fields.restored === true
|
|
266
|
-
? { kind: 'expired', restored: true }
|
|
267
|
-
: { kind: 'expired' };
|
|
268
|
-
}
|
|
269
265
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
270
266
|
const { current, ...fields } = refusal.fields;
|
|
271
267
|
const held = (yield* material(current, handle)) ?? [];
|
|
@@ -281,10 +277,8 @@ export function* mutationOutcome(status, body, locator, handle, move) {
|
|
|
281
277
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
282
278
|
}
|
|
283
279
|
const classified = classifyDoor(status, body, locator);
|
|
284
|
-
const reset = refusal
|
|
285
|
-
if (refusal?.
|
|
286
|
-
typeof reset === 'string' &&
|
|
287
|
-
classified?.kind === 'transport-uncertainty') {
|
|
280
|
+
const reset = resetOf(refusal);
|
|
281
|
+
if (refusal !== null && reset !== undefined && classified?.kind === 'transport-uncertainty') {
|
|
288
282
|
return {
|
|
289
283
|
kind: 'retryable-refusal',
|
|
290
284
|
code: refusal.code,
|
|
@@ -307,18 +301,19 @@ export function* mutationOutcome(status, body, locator, handle, move) {
|
|
|
307
301
|
retryable: refusal.retryable,
|
|
308
302
|
};
|
|
309
303
|
}
|
|
310
|
-
if (status !== 200
|
|
311
|
-
return
|
|
312
|
-
|
|
304
|
+
if (status !== 200)
|
|
305
|
+
return answeredFailure(status, body);
|
|
306
|
+
if (typeof body !== 'object' || body === null)
|
|
307
|
+
return unusable();
|
|
313
308
|
const held = body;
|
|
314
309
|
if (move !== undefined)
|
|
315
310
|
return yield* movedOutcome(held, move);
|
|
316
311
|
const at = readPosition(held);
|
|
317
312
|
if (at === null)
|
|
318
|
-
return
|
|
313
|
+
return unusable();
|
|
319
314
|
const contents = yield* material(held.contents, handle);
|
|
320
315
|
if (contents === null)
|
|
321
|
-
return
|
|
316
|
+
return unusable();
|
|
322
317
|
return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
|
|
323
318
|
}
|
|
324
319
|
export function rejectedMapping(mapping) {
|
|
@@ -339,6 +334,7 @@ export function revisionBody(input) {
|
|
|
339
334
|
}
|
|
340
335
|
function revisionAuthor(entry) {
|
|
341
336
|
const user = entry.author_user;
|
|
337
|
+
const userName = entry.author_user_name;
|
|
342
338
|
const site = entry.author_site;
|
|
343
339
|
const siteName = entry.author_site_name;
|
|
344
340
|
const inbox = entry.author_inbox;
|
|
@@ -346,9 +342,9 @@ function revisionAuthor(entry) {
|
|
|
346
342
|
const app = entry.author_app;
|
|
347
343
|
const appName = entry.author_app_name;
|
|
348
344
|
const named = [site, siteName, inbox, inboxName, app, appName].filter((held) => held !== undefined);
|
|
349
|
-
if (typeof user === 'string' && named.length === 0)
|
|
350
|
-
return { kind: 'user', id: user };
|
|
351
|
-
if (user !== null || named.length !== 2)
|
|
345
|
+
if (typeof user === 'string' && typeof userName === 'string' && named.length === 0)
|
|
346
|
+
return { kind: 'user', id: user, name: userName };
|
|
347
|
+
if (user !== null || userName !== undefined || named.length !== 2)
|
|
352
348
|
return null;
|
|
353
349
|
if (typeof site === 'string' && typeof siteName === 'string') {
|
|
354
350
|
return { kind: 'site', id: site, name: siteName };
|
|
@@ -366,35 +362,25 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
366
362
|
if (classified !== null)
|
|
367
363
|
return classified;
|
|
368
364
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
369
|
-
return
|
|
365
|
+
return unusable();
|
|
370
366
|
}
|
|
371
367
|
const held = body;
|
|
372
368
|
if (!Array.isArray(held.revisions))
|
|
373
|
-
return
|
|
369
|
+
return unusable();
|
|
374
370
|
const entries = [];
|
|
375
371
|
for (const entry of held.revisions) {
|
|
376
372
|
if (typeof entry !== 'object' || entry === null)
|
|
377
|
-
return
|
|
373
|
+
return unusable();
|
|
378
374
|
entries.push(entry);
|
|
379
375
|
}
|
|
380
376
|
if (request.revision !== undefined) {
|
|
381
377
|
const named = entries[0];
|
|
382
378
|
if (named === undefined)
|
|
383
379
|
return { kind: 'no-history' };
|
|
384
|
-
if (named.unavailable === true) {
|
|
385
|
-
return {
|
|
386
|
-
kind: 'scoped-refusal',
|
|
387
|
-
locator,
|
|
388
|
-
scope: 'operation',
|
|
389
|
-
code: 'retained_history_unavailable',
|
|
390
|
-
fields: { path: request.path, revision: request.revision },
|
|
391
|
-
retryable: false,
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
380
|
if (typeof named.media_type === 'string')
|
|
395
381
|
return { kind: 'no-history' };
|
|
396
382
|
if (typeof named.content !== 'string')
|
|
397
|
-
return
|
|
383
|
+
return unusable();
|
|
398
384
|
return { kind: 'revision', content: named.content };
|
|
399
385
|
}
|
|
400
386
|
if (entries.length === 0)
|
|
@@ -405,11 +391,11 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
405
391
|
if (typeof entry.revision !== 'string' ||
|
|
406
392
|
author === null ||
|
|
407
393
|
typeof entry.created_at !== 'string') {
|
|
408
|
-
return
|
|
394
|
+
return unusable();
|
|
409
395
|
}
|
|
410
396
|
const binaryFile = binaryFileOf(entry);
|
|
411
397
|
if (binaryFile === null)
|
|
412
|
-
return
|
|
398
|
+
return unusable();
|
|
413
399
|
revisions.push({
|
|
414
400
|
revision: entry.revision,
|
|
415
401
|
author,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime-adapter",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-cfcea2fad4cce",
|
|
4
4
|
"description": "Agents House Adapter for the MD Runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"LICENSE"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@agentshouse/mdruntime": "0.1.0-
|
|
27
|
+
"@agentshouse/mdruntime": "0.1.0-c23131153db9f"
|
|
28
28
|
},
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
package/dist/part.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export type RoomFrame = {
|
|
2
|
-
readonly kind: 'frame';
|
|
3
|
-
readonly payload: Uint8Array<ArrayBuffer>;
|
|
4
|
-
readonly bytes: number;
|
|
5
|
-
} | {
|
|
6
|
-
readonly kind: 'ended';
|
|
7
|
-
} | {
|
|
8
|
-
readonly kind: 'broken';
|
|
9
|
-
};
|
|
10
|
-
export type RoomFrames = () => Promise<RoomFrame>;
|
|
11
|
-
export declare function checkedPayload(frame: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer> | null>;
|
|
12
|
-
export declare function roomFrames(room: ReadableStream<Uint8Array>, arrived?: (bytes: number) => void, signal?: AbortSignal): RoomFrames;
|
|
13
|
-
export declare function gunzipped(payload: Uint8Array<ArrayBuffer>): ReadableStream<string>;
|
|
14
|
-
//# sourceMappingURL=part.d.ts.map
|
package/dist/part.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"part.d.ts","sourceRoot":"","sources":["../src/part.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,SAAS,GACjB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC7F;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEhC,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,CAAC;AAQlD,wBAAsB,cAAc,CAClC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,GAC7B,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CASzC;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,EACjC,MAAM,CAAC,EAAE,WAAW,GACnB,UAAU,CAwDZ;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAKlF"}
|
package/dist/part.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
const PART_MAGIC = 0x48505431;
|
|
2
|
-
const PART_HEAD_BYTES = 8;
|
|
3
|
-
const PART_DIGEST_BYTES = 32;
|
|
4
|
-
function hex(bytes) {
|
|
5
|
-
let text = '';
|
|
6
|
-
for (const byte of bytes)
|
|
7
|
-
text += byte.toString(16).padStart(2, '0');
|
|
8
|
-
return text;
|
|
9
|
-
}
|
|
10
|
-
export async function checkedPayload(frame) {
|
|
11
|
-
if (frame.length < PART_HEAD_BYTES + PART_DIGEST_BYTES)
|
|
12
|
-
return null;
|
|
13
|
-
const view = new DataView(frame.buffer, frame.byteOffset, frame.byteLength);
|
|
14
|
-
if (view.getUint32(0) !== PART_MAGIC)
|
|
15
|
-
return null;
|
|
16
|
-
const length = view.getUint32(4);
|
|
17
|
-
if (PART_HEAD_BYTES + length + PART_DIGEST_BYTES !== frame.length)
|
|
18
|
-
return null;
|
|
19
|
-
const payload = frame.subarray(PART_HEAD_BYTES, PART_HEAD_BYTES + length);
|
|
20
|
-
const digest = hex(new Uint8Array(await crypto.subtle.digest('SHA-256', payload)));
|
|
21
|
-
return hex(frame.subarray(PART_HEAD_BYTES + length)) === digest ? payload : null;
|
|
22
|
-
}
|
|
23
|
-
export function roomFrames(room, arrived, signal) {
|
|
24
|
-
const reader = room.getReader();
|
|
25
|
-
signal?.addEventListener('abort', () => void reader.cancel().catch(() => { }), { once: true });
|
|
26
|
-
const chunks = [];
|
|
27
|
-
let held = 0;
|
|
28
|
-
let received = 0;
|
|
29
|
-
let ended = false;
|
|
30
|
-
async function filled(bytes) {
|
|
31
|
-
while (held < bytes && !ended) {
|
|
32
|
-
const read = await reader.read();
|
|
33
|
-
if (read.done) {
|
|
34
|
-
ended = true;
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
chunks.push(read.value);
|
|
38
|
-
held += read.value.byteLength;
|
|
39
|
-
received += read.value.byteLength;
|
|
40
|
-
arrived?.(received);
|
|
41
|
-
}
|
|
42
|
-
return held >= bytes;
|
|
43
|
-
}
|
|
44
|
-
function taken(bytes) {
|
|
45
|
-
const out = new Uint8Array(bytes);
|
|
46
|
-
let at = 0;
|
|
47
|
-
while (at < bytes) {
|
|
48
|
-
const chunk = chunks[0];
|
|
49
|
-
const used = Math.min(chunk.byteLength, bytes - at);
|
|
50
|
-
out.set(chunk.subarray(0, used), at);
|
|
51
|
-
at += used;
|
|
52
|
-
if (used === chunk.byteLength)
|
|
53
|
-
chunks.shift();
|
|
54
|
-
else
|
|
55
|
-
chunks[0] = chunk.subarray(used);
|
|
56
|
-
}
|
|
57
|
-
held -= bytes;
|
|
58
|
-
return out;
|
|
59
|
-
}
|
|
60
|
-
return async () => {
|
|
61
|
-
try {
|
|
62
|
-
if (!(await filled(PART_HEAD_BYTES)))
|
|
63
|
-
return held === 0 ? { kind: 'ended' } : { kind: 'broken' };
|
|
64
|
-
const head = taken(PART_HEAD_BYTES);
|
|
65
|
-
const view = new DataView(head.buffer);
|
|
66
|
-
if (view.getUint32(0) !== PART_MAGIC)
|
|
67
|
-
return { kind: 'broken' };
|
|
68
|
-
const length = view.getUint32(4);
|
|
69
|
-
const rest = length + PART_DIGEST_BYTES;
|
|
70
|
-
if (!(await filled(rest)))
|
|
71
|
-
return { kind: 'broken' };
|
|
72
|
-
const frame = new Uint8Array(PART_HEAD_BYTES + rest);
|
|
73
|
-
frame.set(head, 0);
|
|
74
|
-
frame.set(taken(rest), PART_HEAD_BYTES);
|
|
75
|
-
const payload = await checkedPayload(frame);
|
|
76
|
-
return payload === null
|
|
77
|
-
? { kind: 'broken' }
|
|
78
|
-
: { kind: 'frame', payload, bytes: frame.byteLength };
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
return { kind: 'broken' };
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
export function gunzipped(payload) {
|
|
86
|
-
return new Blob([payload])
|
|
87
|
-
.stream()
|
|
88
|
-
.pipeThrough(new DecompressionStream('gzip'))
|
|
89
|
-
.pipeThrough(new TextDecoderStream());
|
|
90
|
-
}
|
package/dist/room-stream.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { BootstrapResult, RoomModels } from '@agentshouse/mdruntime';
|
|
2
|
-
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import { type HouseScope } from './read.js';
|
|
4
|
-
import type { HouseMode } from './transport.js';
|
|
5
|
-
export type StreamedPart = {
|
|
6
|
-
readonly scope: HouseScope;
|
|
7
|
-
readonly first: boolean;
|
|
8
|
-
readonly ended: boolean;
|
|
9
|
-
readonly models: RoomModels | undefined;
|
|
10
|
-
readonly pageToken: string | undefined;
|
|
11
|
-
readonly bytes: number;
|
|
12
|
-
};
|
|
13
|
-
export declare function roomStreams(mode: HouseMode): {
|
|
14
|
-
head: (entry: TrackedAuthority, room: ReadableStream<Uint8Array>, arriving: ((bytes: number) => void) | undefined, signal: AbortSignal | undefined) => Promise<BootstrapResult>;
|
|
15
|
-
part: (entry: TrackedAuthority, token: string) => Promise<StreamedPart | Exclude<BootstrapResult, {
|
|
16
|
-
kind: 'bootstrap';
|
|
17
|
-
}>>;
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=room-stream.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"room-stream.d.ts","sourceRoot":"","sources":["../src/room-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,OAAO,EAAuD,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACjG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAYhD,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS;kBAKhC,gBAAgB,QACjB,cAAc,CAAC,UAAU,CAAC,YACtB,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,UACvC,WAAW,GAAG,SAAS,KAC9B,OAAO,CAAC,eAAe,CAAC;kBAelB,gBAAgB,SAChB,MAAM,KACZ,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,eAAe,EAAE;QAAE,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC,CAAC;EAkC3E"}
|
package/dist/room-stream.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { manifestedModels, partModels } from './model.js';
|
|
2
|
-
import { roomFrames } from './part.js';
|
|
3
|
-
import { housePart, manifested, roomHead } from './read.js';
|
|
4
|
-
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
5
|
-
export function roomStreams(mode) {
|
|
6
|
-
const open = new Map();
|
|
7
|
-
let opened = 0;
|
|
8
|
-
async function head(entry, room, arriving, signal) {
|
|
9
|
-
const frames = roomFrames(room, arriving, signal);
|
|
10
|
-
const first = await frames();
|
|
11
|
-
if (first.kind !== 'frame')
|
|
12
|
-
return UNCERTAIN;
|
|
13
|
-
const held = await roomHead(first.payload, mode);
|
|
14
|
-
if (held === null || held.anchor !== entry.authority)
|
|
15
|
-
return UNCERTAIN;
|
|
16
|
-
const { models, seen } = await manifestedModels(held, entry);
|
|
17
|
-
opened += 1;
|
|
18
|
-
const id = String(opened);
|
|
19
|
-
open.set(id, { entry, head: held, frames, next: 1, seen });
|
|
20
|
-
signal?.addEventListener('abort', () => open.delete(id), { once: true });
|
|
21
|
-
return { ...manifested(held, `${id}:1`, models), bytes: first.bytes };
|
|
22
|
-
}
|
|
23
|
-
async function part(entry, token) {
|
|
24
|
-
const [id = '', at = ''] = token.split(':');
|
|
25
|
-
const room = open.get(id);
|
|
26
|
-
if (room === undefined || room.entry.locator !== entry.locator || String(room.next) !== at)
|
|
27
|
-
return UNCERTAIN;
|
|
28
|
-
const frame = await room.frames();
|
|
29
|
-
if (frame.kind !== 'frame') {
|
|
30
|
-
open.delete(id);
|
|
31
|
-
return UNCERTAIN;
|
|
32
|
-
}
|
|
33
|
-
const read = await housePart(room.head, frame.payload, mode);
|
|
34
|
-
if ('kind' in read) {
|
|
35
|
-
open.delete(id);
|
|
36
|
-
return read;
|
|
37
|
-
}
|
|
38
|
-
const { scope, ended } = read;
|
|
39
|
-
const first = room.next === 1;
|
|
40
|
-
room.next += 1;
|
|
41
|
-
room.seen = [
|
|
42
|
-
...room.seen,
|
|
43
|
-
...(scope.files.some((file) => file.path === entry.schema) ? [entry.schema] : []),
|
|
44
|
-
];
|
|
45
|
-
if (ended)
|
|
46
|
-
open.delete(id);
|
|
47
|
-
return {
|
|
48
|
-
scope,
|
|
49
|
-
first,
|
|
50
|
-
ended,
|
|
51
|
-
models: await partModels(scope, entry, new Set(room.seen), ended),
|
|
52
|
-
pageToken: ended ? undefined : `${id}:${room.next}`,
|
|
53
|
-
bytes: frame.bytes,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
return { head, part };
|
|
57
|
-
}
|