@agentshouse/mdruntime 0.1.0-c99e5271060cd → 0.1.0-c99ee6ff87175
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 +22 -9
- package/dist/adapter.d.ts +173 -49
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +5 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +38 -4
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +70 -0
- package/dist/binary.d.ts +18 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +27 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +184 -84
- package/dist/chain.d.ts +11 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +9 -14
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -62
- package/dist/change.d.ts +41 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +34 -0
- package/dist/client.d.ts +34 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +104 -8
- package/dist/collection.d.ts +10 -7
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +38 -79
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +789 -0
- package/dist/connection.d.ts +50 -17
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +3990 -922
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation.d.ts +49 -19
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +729 -240
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/durability.d.ts +4 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +20 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +152 -0
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/fence.d.ts +6 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +10 -0
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- package/dist/host.d.ts +11 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +125 -18
- package/dist/identity.d.ts +3 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +9 -0
- package/dist/index.d.ts +21 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/job.d.ts +14 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +28 -0
- package/dist/live.d.ts +23 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +127 -0
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +18 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +231 -91
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +89 -0
- package/dist/model.d.ts +9 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +8 -2
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +22 -4
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +120 -14
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/outcome.d.ts +52 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +46 -0
- package/dist/overlay.d.ts +15 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +129 -177
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -0
- package/dist/phrase.d.ts +3 -0
- package/dist/phrase.d.ts.map +1 -0
- package/dist/phrase.js +8 -0
- package/dist/query.d.ts +72 -4
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +67 -7
- package/dist/reach.d.ts +18 -4
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +225 -62
- package/dist/react.d.ts +11 -7
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +7 -17
- package/dist/readiness.d.ts +50 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +27 -0
- package/dist/recovery.d.ts +26 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +224 -0
- package/dist/refresh.d.ts +17 -14
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +155 -56
- package/dist/replica.d.ts +58 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +310 -159
- package/dist/room-draft.d.ts +53 -5
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +265 -60
- package/dist/rows.d.ts +38 -35
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +178 -102
- package/dist/save.d.ts +70 -3
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +805 -147
- package/dist/search.d.ts +15 -55
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -121
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +75 -0
- package/dist/shared.d.ts +15 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +421 -0
- package/dist/status.d.ts +5 -1
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -9
- package/dist/store.d.ts +116 -80
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +355 -461
- package/dist/stored.d.ts +162 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +549 -0
- package/dist/tables.d.ts +353 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +585 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/turn.d.ts +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +75 -0
- package/dist/validation.d.ts +29 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +101 -0
- package/dist/windows.d.ts +22 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +89 -0
- package/dist/wire.d.ts +166 -30
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +57 -29
- package/package.json +26 -15
- package/AGENTS.md +0 -269
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
- package/dist/read-side.d.ts +0 -18
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -433
package/dist/attempt.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { changeBatchIdentity } from './identity.js';
|
|
2
|
+
export function identities(mint = () => changeBatchIdentity()) {
|
|
3
|
+
const kept = new Map();
|
|
4
|
+
let used = new Map();
|
|
5
|
+
return {
|
|
6
|
+
of(intent) {
|
|
7
|
+
const one = used.get(intent) ?? kept.get(intent) ?? mint();
|
|
8
|
+
used.set(intent, one);
|
|
9
|
+
return one;
|
|
10
|
+
},
|
|
11
|
+
settle(answered) {
|
|
12
|
+
if (answered !== 'offline') {
|
|
13
|
+
for (const [intent, one] of used) {
|
|
14
|
+
if (answered === 'unanswered')
|
|
15
|
+
kept.set(intent, one);
|
|
16
|
+
else
|
|
17
|
+
kept.delete(intent);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
used = new Map();
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const blobs = new WeakMap();
|
|
25
|
+
export function intentOf(name, about) {
|
|
26
|
+
const carried = [];
|
|
27
|
+
const json = JSON.stringify(about, (_key, value) => {
|
|
28
|
+
if (!(value instanceof Blob))
|
|
29
|
+
return value;
|
|
30
|
+
let identity = blobs.get(value);
|
|
31
|
+
if (identity === undefined) {
|
|
32
|
+
identity = changeBatchIdentity();
|
|
33
|
+
blobs.set(value, identity);
|
|
34
|
+
}
|
|
35
|
+
carried.push(identity);
|
|
36
|
+
return null;
|
|
37
|
+
});
|
|
38
|
+
return `${name}\u0000${json}\u0000${carried.join(',')}`;
|
|
39
|
+
}
|
|
40
|
+
export function attempts(mint) {
|
|
41
|
+
const numbers = identities(mint);
|
|
42
|
+
const waiting = new Map();
|
|
43
|
+
return {
|
|
44
|
+
begin(act) {
|
|
45
|
+
const intents = [];
|
|
46
|
+
return {
|
|
47
|
+
identity(intent) {
|
|
48
|
+
intents.push(intent);
|
|
49
|
+
return numbers.of(intent);
|
|
50
|
+
},
|
|
51
|
+
settle(answered, drop) {
|
|
52
|
+
numbers.settle(answered);
|
|
53
|
+
if (answered === 'refused' || answered === 'offline')
|
|
54
|
+
drop(act);
|
|
55
|
+
if (answered === 'offline')
|
|
56
|
+
return;
|
|
57
|
+
for (const intent of intents) {
|
|
58
|
+
const earlier = waiting.get(intent);
|
|
59
|
+
if (earlier !== undefined && earlier !== act)
|
|
60
|
+
drop(earlier);
|
|
61
|
+
if (answered === 'unanswered')
|
|
62
|
+
waiting.set(intent, act);
|
|
63
|
+
else
|
|
64
|
+
waiting.delete(intent);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
package/dist/binary.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HeldBinary } from './overlay.js';
|
|
2
|
+
export type BinaryFileRecord = {
|
|
3
|
+
readonly state: 'accepted';
|
|
4
|
+
readonly revision: string;
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly byteLength: number;
|
|
7
|
+
readonly mediaType: string;
|
|
8
|
+
readonly sha256: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly state: 'pending';
|
|
11
|
+
readonly localId: string;
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly byteLength: number;
|
|
14
|
+
readonly mediaType: string;
|
|
15
|
+
readonly sha256: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function binaryRecord(path: string, held: HeldBinary, revision: string | undefined): BinaryFileRecord;
|
|
18
|
+
//# sourceMappingURL=binary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../src/binary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,MAAM,gBAAgB,GACxB;IACE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GACD;IACE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEN,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,gBAAgB,CAKlB"}
|
package/dist/binary.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function binaryRecord(path, held, revision) {
|
|
2
|
+
const facts = { byteLength: held.byteLength, mediaType: held.mediaType, sha256: held.sha256 };
|
|
3
|
+
if (held.state === 'pending')
|
|
4
|
+
return { state: 'pending', localId: held.localId, path, ...facts };
|
|
5
|
+
if (revision === undefined)
|
|
6
|
+
throw new Error(`the accepted binary file ${path} has no revision`);
|
|
7
|
+
return { state: 'accepted', revision, path, ...facts };
|
|
8
|
+
}
|
package/dist/bootstrap.d.ts
CHANGED
|
@@ -1,24 +1,40 @@
|
|
|
1
1
|
import type { ModelState } from './model.js';
|
|
2
|
-
import type { Adapter, AdapterFailure, Authorization, DiscoveredRoom, RetryableRefusal, RoomModels } from './adapter.js';
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import { type
|
|
2
|
+
import type { Adapter, AdapterFailure, Authorization, DiscoveredRoom, HeldContent, RetryableRefusal, RoomModels } from './adapter.js';
|
|
3
|
+
import type { Composition } from './collection.js';
|
|
4
|
+
import type { InstallationStep } from './readiness.js';
|
|
5
|
+
import { type Refreshing } from './refresh.js';
|
|
6
|
+
import type { ReplicaRecord } from './replica.js';
|
|
7
|
+
import type { StagedPage, TransferRecord } from './store.js';
|
|
8
|
+
import { type Unconfirmed } from './transfer.js';
|
|
6
9
|
export type Bootstrapped = {
|
|
7
10
|
kind: 'staged';
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
record: ReplicaRecord;
|
|
12
|
+
refreshed: boolean;
|
|
10
13
|
};
|
|
11
|
-
export type BootstrapOutcome = Bootstrapped |
|
|
14
|
+
export type BootstrapOutcome = Bootstrapped | Unconfirmed | RetryableRefusal | AdapterFailure;
|
|
12
15
|
export type HeldModels = {
|
|
13
16
|
collection: ModelState;
|
|
14
|
-
selection: ModelState;
|
|
15
17
|
};
|
|
16
18
|
export type Remodel = (models: RoomModels | undefined, held: HeldModels) => HeldModels;
|
|
19
|
+
export type Reads = Pick<Adapter, 'bootstrap' | 'refresh' | 'reached'>;
|
|
20
|
+
export type Arriving = {
|
|
21
|
+
at(bytes: number): void;
|
|
22
|
+
end(): void;
|
|
23
|
+
};
|
|
17
24
|
export type Staging = {
|
|
18
25
|
held(locator: string): TransferRecord | null;
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
turn(locator: string, step: InstallationStep): Promise<() => void>;
|
|
27
|
+
unqueued(): Promise<void>;
|
|
28
|
+
queued(text: number): () => void;
|
|
29
|
+
arriving(locator: string): Arriving;
|
|
30
|
+
readonly streamed: boolean;
|
|
31
|
+
stage(record: TransferRecord, page: StagedPage, composition: Composition): Promise<TransferRecord | null>;
|
|
32
|
+
derive(locator: string, key: number, composition: Composition): Promise<boolean>;
|
|
33
|
+
refreshing(locator: string, key: number, composition: Composition): Promise<Refreshing>;
|
|
21
34
|
abandon(locator: string): Promise<void>;
|
|
35
|
+
setAside(locator: string): Promise<void>;
|
|
36
|
+
release(key: number): Promise<void>;
|
|
37
|
+
content(key: number): HeldContent;
|
|
22
38
|
};
|
|
23
|
-
export declare function bootstrapRoom(adapter:
|
|
39
|
+
export declare function bootstrapRoom(adapter: Reads, authorization: Authorization, room: DiscoveredRoom, held: HeldModels, builtIn: ModelState, remodel: Remodel, continuing: () => boolean, staging: Staging, reuse: HeldContent | null): Promise<BootstrapOutcome>;
|
|
24
40
|
//# sourceMappingURL=bootstrap.d.ts.map
|
package/dist/bootstrap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,aAAa,
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"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"}
|
package/dist/bootstrap.js
CHANGED
|
@@ -1,110 +1,210 @@
|
|
|
1
|
-
import { declaredAttachments } from './attachment.js';
|
|
2
1
|
import { transferIdentity } from './identity.js';
|
|
3
|
-
import { advancement } from './refresh.js';
|
|
4
|
-
import {
|
|
2
|
+
import { advancement, pageEntries } from './refresh.js';
|
|
3
|
+
import { entriesIn } from './shared.js';
|
|
5
4
|
import { unconfirmed } from './transfer.js';
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const NOTHING_PRIOR = () => Promise.resolve(new Map());
|
|
6
|
+
function textOf(page) {
|
|
7
|
+
let text = 0;
|
|
8
|
+
for (const [, content] of entriesIn(page.documents))
|
|
9
|
+
text += content.length;
|
|
10
|
+
return text;
|
|
11
|
+
}
|
|
12
|
+
async function pageOf(page) {
|
|
13
|
+
return {
|
|
14
|
+
entries: await pageEntries(page, [], page.roomVersion, NOTHING_PRIOR),
|
|
15
|
+
folders: page.folders ?? [],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function heldTogether(first, second) {
|
|
19
|
+
if (first === null)
|
|
20
|
+
return second;
|
|
21
|
+
return {
|
|
22
|
+
async files(after, limit) {
|
|
23
|
+
const [left, right] = await Promise.all([
|
|
24
|
+
first.files(after, limit),
|
|
25
|
+
second.files(after, limit),
|
|
26
|
+
]);
|
|
27
|
+
const merged = new Map([...left, ...right].map((file) => [file.path, file]));
|
|
28
|
+
return [...merged.values()]
|
|
29
|
+
.sort((one, other) => (one.path < other.path ? -1 : one.path > other.path ? 1 : 0))
|
|
30
|
+
.slice(0, limit);
|
|
31
|
+
},
|
|
32
|
+
async contents(paths) {
|
|
33
|
+
const [left, right] = await Promise.all([first.contents(paths), second.contents(paths)]);
|
|
34
|
+
return new Map([...left, ...right]);
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const NO_CONTENT = {
|
|
39
|
+
files: () => Promise.resolve([]),
|
|
40
|
+
contents: () => Promise.resolve(new Map()),
|
|
41
|
+
};
|
|
42
|
+
export async function bootstrapRoom(adapter, authorization, room, held, builtIn, remodel, continuing, staging, reuse) {
|
|
43
|
+
if (staging.held(room.locator) !== null)
|
|
44
|
+
await staging.abandon(room.locator);
|
|
45
|
+
const begun = (pool) => started(adapter, authorization, room, held, builtIn, remodel, continuing, staging, pool);
|
|
46
|
+
const first = await begun(reuse);
|
|
47
|
+
if (first.kind !== 'expired')
|
|
48
|
+
return first;
|
|
49
|
+
await staging.setAside(room.locator);
|
|
50
|
+
try {
|
|
51
|
+
const replacement = await begun(heldTogether(reuse, first.held));
|
|
52
|
+
if (replacement.kind !== 'expired')
|
|
53
|
+
return replacement;
|
|
54
|
+
await staging.abandon(room.locator);
|
|
55
|
+
return unconfirmed;
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
if (first.key !== null)
|
|
59
|
+
await staging.release(first.key);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function dropped(ahead) {
|
|
63
|
+
void ahead?.fetched.then(({ next, written }) => {
|
|
64
|
+
written();
|
|
65
|
+
dropped(next);
|
|
66
|
+
}, () => { });
|
|
67
|
+
}
|
|
68
|
+
function compositionFor(room, models, builtIn) {
|
|
12
69
|
return {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
binaryTargets: page.binaryTargets,
|
|
70
|
+
model: models.collection,
|
|
71
|
+
selection: room.typedSelection === undefined
|
|
72
|
+
? null
|
|
73
|
+
: { roots: room.typedSelection.roots, model: builtIn },
|
|
18
74
|
};
|
|
19
75
|
}
|
|
20
|
-
async function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
76
|
+
async function started(adapter, authorization, room, held, builtIn, remodel, continuing, staging, pool) {
|
|
77
|
+
let outcome;
|
|
78
|
+
try {
|
|
79
|
+
outcome = await bundle(adapter, authorization, room, held, builtIn, remodel, continuing, staging, pool);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
await staging.abandon(room.locator).catch(() => { });
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
if (outcome.kind !== 'staged' && outcome.kind !== 'expired') {
|
|
86
|
+
await staging.abandon(room.locator);
|
|
26
87
|
}
|
|
27
|
-
|
|
28
|
-
return null;
|
|
88
|
+
return outcome;
|
|
29
89
|
}
|
|
30
|
-
|
|
90
|
+
async function bundle(adapter, authorization, room, held, builtIn, remodel, continuing, staging, pool) {
|
|
31
91
|
const locator = room.locator;
|
|
32
92
|
const selection = room.replica.selection;
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
93
|
+
const ending = new AbortController();
|
|
94
|
+
const arriving = staging.arriving(locator);
|
|
95
|
+
const downloaded = await staging.turn(locator, 'downloading');
|
|
96
|
+
const asking = (token) => adapter.bootstrap(authorization, {
|
|
97
|
+
locator,
|
|
98
|
+
selection,
|
|
99
|
+
signal: ending.signal,
|
|
100
|
+
...(token === null
|
|
101
|
+
? { arriving: (bytes) => arriving.at(bytes) }
|
|
102
|
+
: { pageToken: token }),
|
|
103
|
+
...(pool === null ? {} : { held: pool }),
|
|
104
|
+
});
|
|
105
|
+
const fetching = (token) => {
|
|
106
|
+
const fetched = (async () => {
|
|
107
|
+
await staging.unqueued();
|
|
108
|
+
const page = continuing() ? await asking(token) : unconfirmed;
|
|
109
|
+
if (page.kind !== 'bootstrap')
|
|
110
|
+
return { page, next: null, written: () => { } };
|
|
111
|
+
const written = staging.queued(textOf(page));
|
|
112
|
+
const later = page.pageToken;
|
|
113
|
+
if (later === undefined) {
|
|
114
|
+
downloaded();
|
|
115
|
+
arriving.end();
|
|
116
|
+
}
|
|
117
|
+
return { page, written, next: later === undefined || !continuing() ? null : fetching(later) };
|
|
118
|
+
})();
|
|
119
|
+
fetched.catch(() => { });
|
|
120
|
+
return { fetched };
|
|
121
|
+
};
|
|
122
|
+
let transfer = null;
|
|
123
|
+
let ahead = fetching(null);
|
|
124
|
+
try {
|
|
125
|
+
while (ahead !== null) {
|
|
126
|
+
if (!continuing())
|
|
127
|
+
return unconfirmed;
|
|
128
|
+
const fetched = await ahead.fetched;
|
|
129
|
+
ahead = fetched.next;
|
|
130
|
+
try {
|
|
131
|
+
if (!continuing())
|
|
132
|
+
return unconfirmed;
|
|
133
|
+
const page = fetched.page;
|
|
134
|
+
if (page.kind === 'beyond-horizon') {
|
|
135
|
+
const key = transfer?.key ?? null;
|
|
136
|
+
return { kind: 'expired', held: key === null ? NO_CONTENT : staging.content(key), key };
|
|
137
|
+
}
|
|
138
|
+
if (page.kind !== 'bootstrap')
|
|
139
|
+
return page;
|
|
140
|
+
const models = remodel(page.models, transfer?.models ?? held);
|
|
141
|
+
const staged = await staging.stage({
|
|
142
|
+
locator,
|
|
143
|
+
transfer: transfer?.transfer ?? transferIdentity(),
|
|
144
|
+
selection,
|
|
145
|
+
from: transfer !== null && adapter.reached(locator, page.roomVersion, transfer.from)
|
|
146
|
+
? transfer.from
|
|
147
|
+
: page.roomVersion,
|
|
148
|
+
last: transfer !== null && !adapter.reached(locator, page.roomVersion, transfer.last)
|
|
149
|
+
? transfer.last
|
|
150
|
+
: page.roomVersion,
|
|
151
|
+
done: { bytes: (transfer?.done.bytes ?? 0) + (page.bytes ?? 0) },
|
|
152
|
+
models,
|
|
153
|
+
key: transfer?.key ?? null,
|
|
154
|
+
}, await pageOf(page), compositionFor(room, models, builtIn));
|
|
155
|
+
if (staged === null)
|
|
156
|
+
return unconfirmed;
|
|
157
|
+
transfer = staged;
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
fetched.written();
|
|
161
|
+
}
|
|
52
162
|
}
|
|
53
|
-
transfer = {
|
|
54
|
-
locator,
|
|
55
|
-
transfer: transfer?.transfer ?? transferIdentity(),
|
|
56
|
-
selection,
|
|
57
|
-
from: transfer?.from ?? page.roomVersion,
|
|
58
|
-
last: page.roomVersion,
|
|
59
|
-
pageToken: page.pageToken ?? null,
|
|
60
|
-
models: remodel(page.models, transfer?.models ?? held),
|
|
61
|
-
attachments: [...(transfer?.attachments ?? []), page.attachments ?? []],
|
|
62
|
-
};
|
|
63
|
-
const staged = pageLayer(page);
|
|
64
|
-
if (!(await staging.stage(transfer, staged)))
|
|
65
|
-
return unconfirmed;
|
|
66
|
-
Object.assign(documents, staged.documents);
|
|
67
|
-
Object.assign(revisions, staged.revisions);
|
|
68
|
-
Object.assign(changes, staged.changes);
|
|
69
|
-
Object.assign(written, staged.written);
|
|
70
|
-
for (const target of staged.binaryTargets)
|
|
71
|
-
binaryTargets.add(target);
|
|
72
163
|
}
|
|
164
|
+
finally {
|
|
165
|
+
ending.abort();
|
|
166
|
+
downloaded();
|
|
167
|
+
arriving.end();
|
|
168
|
+
dropped(ahead);
|
|
169
|
+
}
|
|
170
|
+
if (transfer === null)
|
|
171
|
+
return unconfirmed;
|
|
172
|
+
const installed = transfer;
|
|
173
|
+
const composition = compositionFor(room, installed.models, builtIn);
|
|
174
|
+
if (!(await staging.derive(locator, installed.key, composition)))
|
|
175
|
+
return unconfirmed;
|
|
176
|
+
await staging.turn(locator, 'replaying');
|
|
177
|
+
if (!continuing())
|
|
178
|
+
return unconfirmed;
|
|
73
179
|
const record = {
|
|
74
180
|
locator,
|
|
75
181
|
name: room.name,
|
|
76
182
|
handle: room.handle,
|
|
77
183
|
operations: room.operations,
|
|
78
184
|
replica: room.replica,
|
|
79
|
-
model:
|
|
185
|
+
model: installed.models.collection,
|
|
80
186
|
typedSelection: room.typedSelection ?? null,
|
|
81
|
-
selectionModel: transfer.models.selection,
|
|
82
187
|
providerOwnedPaths: room.providerOwnedPaths,
|
|
83
|
-
roomVersion:
|
|
84
|
-
transfer:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
revisions,
|
|
88
|
-
changes,
|
|
89
|
-
written,
|
|
90
|
-
attachments: declaredAttachments(transfer.attachments),
|
|
188
|
+
roomVersion: installed.from,
|
|
189
|
+
transfer: installed.transfer,
|
|
190
|
+
inventory: installed.done,
|
|
191
|
+
key: installed.key,
|
|
91
192
|
};
|
|
92
|
-
const
|
|
193
|
+
const last = installed.last;
|
|
194
|
+
const refresh = adapter.refresh;
|
|
195
|
+
const reconciled = last === installed.from &&
|
|
196
|
+
(staging.streamed || adapter.reached(locator, last, room.roomVersion))
|
|
93
197
|
? { kind: 'still-current' }
|
|
94
|
-
:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return read;
|
|
100
|
-
}
|
|
101
|
-
return { kind: 'staged', confirmed: read.confirmed, stored: record };
|
|
198
|
+
: refresh === undefined
|
|
199
|
+
? unconfirmed
|
|
200
|
+
: await advancement(refresh, authorization, record, remodel, continuing, await staging.refreshing(locator, record.key, composition));
|
|
201
|
+
if (reconciled.kind === 'advanced') {
|
|
202
|
+
return { kind: 'staged', record: reconciled.record, refreshed: true };
|
|
102
203
|
}
|
|
204
|
+
if (reconciled.kind === 'still-current')
|
|
205
|
+
return { kind: 'staged', record, refreshed: false };
|
|
103
206
|
if (reconciled.kind === 'beyond-horizon') {
|
|
104
|
-
|
|
105
|
-
return unconfirmed;
|
|
207
|
+
return { kind: 'expired', held: staging.content(record.key), key: record.key };
|
|
106
208
|
}
|
|
107
|
-
if (!RESUMABLE.has(reconciled.kind))
|
|
108
|
-
await staging.abandon(locator);
|
|
109
209
|
return reconciled;
|
|
110
210
|
}
|
package/dist/chain.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MdRuntimeClient } from './client.js';
|
|
2
|
+
import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult, PendingResult } from './query.js';
|
|
3
|
+
type Rows = DocumentResult | GroupResult;
|
|
4
|
+
export type WindowAnswer = Rows | PendingResult;
|
|
5
|
+
export type WindowChain = {
|
|
6
|
+
want(count: number): void;
|
|
7
|
+
close(): void;
|
|
8
|
+
};
|
|
9
|
+
export declare function chainedWindows(runtime: MdRuntimeClient, query: DocumentQuery | GroupQuery, count: number, publish: (answers: readonly (WindowAnswer | null)[], settled: boolean) => void): WindowChain;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,UAAU,EACV,WAAW,EACX,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,KAAK,IAAI,GAAG,cAAc,GAAG,WAAW,CAAC;AAEzC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,aAAa,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAaF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,aAAa,GAAG,UAAU,EACjC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GAC7E,WAAW,CAkEb"}
|
package/dist/chain.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function answered(answer) {
|
|
2
|
+
return answer !== null && !('pending' in answer);
|
|
3
|
+
}
|
|
4
|
+
export function chainedWindows(runtime, query, count, publish) {
|
|
5
|
+
let links = [];
|
|
6
|
+
let wanted = count;
|
|
7
|
+
let closed = false;
|
|
8
|
+
const observe = runtime.observe;
|
|
9
|
+
const open = (after, shown) => {
|
|
10
|
+
const link = { after, observation: null, value: shown, fresh: false };
|
|
11
|
+
void observe('query', after === undefined ? query : { ...query, after }).then((observation) => {
|
|
12
|
+
if (closed || !links.includes(link)) {
|
|
13
|
+
observation.close();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
link.observation = observation;
|
|
17
|
+
const take = (value) => {
|
|
18
|
+
link.value = value;
|
|
19
|
+
link.fresh = true;
|
|
20
|
+
settle();
|
|
21
|
+
};
|
|
22
|
+
observation.subscribe(take);
|
|
23
|
+
take(observation.current());
|
|
24
|
+
}, () => { });
|
|
25
|
+
return link;
|
|
26
|
+
};
|
|
27
|
+
const settle = () => {
|
|
28
|
+
if (closed)
|
|
29
|
+
return;
|
|
30
|
+
const next = [];
|
|
31
|
+
for (let at = 0; at < wanted; at += 1) {
|
|
32
|
+
const before = next[at - 1];
|
|
33
|
+
if (before !== undefined && !before.fresh) {
|
|
34
|
+
next.push(...links.slice(at, wanted));
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
if (before !== undefined && (!answered(before.value) || before.value.next === undefined)) {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
const after = before === undefined ? undefined : before.value.next;
|
|
41
|
+
const held = links[at];
|
|
42
|
+
next.push(held !== undefined && held.after === after ? held : open(after, held?.value ?? null));
|
|
43
|
+
}
|
|
44
|
+
for (const link of links)
|
|
45
|
+
if (!next.includes(link))
|
|
46
|
+
link.observation?.close();
|
|
47
|
+
links = next;
|
|
48
|
+
publish(links.map((link) => link.value), links.every((link) => link.fresh));
|
|
49
|
+
};
|
|
50
|
+
settle();
|
|
51
|
+
return {
|
|
52
|
+
want(count) {
|
|
53
|
+
if (count === wanted)
|
|
54
|
+
return;
|
|
55
|
+
wanted = count;
|
|
56
|
+
settle();
|
|
57
|
+
},
|
|
58
|
+
close() {
|
|
59
|
+
closed = true;
|
|
60
|
+
for (const link of links)
|
|
61
|
+
link.observation?.close();
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
package/dist/change-set.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import { type Replica } from './replica.js';
|
|
2
|
-
import { type Row } from './rows.js';
|
|
3
1
|
export type DocumentChange = {
|
|
4
|
-
locator: string;
|
|
5
|
-
path: string;
|
|
6
|
-
before: readonly Row[];
|
|
7
|
-
after: readonly Row[];
|
|
8
|
-
};
|
|
9
|
-
export type MessageChange = {
|
|
10
|
-
conversation: string;
|
|
11
|
-
identity: string;
|
|
2
|
+
readonly locator: string;
|
|
3
|
+
readonly path: string | null;
|
|
12
4
|
};
|
|
13
5
|
export type ChangeSet = {
|
|
14
6
|
documents: readonly DocumentChange[];
|
|
@@ -19,15 +11,18 @@ export type ChangeSet = {
|
|
|
19
11
|
rooms: readonly string[];
|
|
20
12
|
queues: readonly string[];
|
|
21
13
|
presentations: readonly string[];
|
|
22
|
-
messages: readonly MessageChange[];
|
|
23
14
|
conversations: readonly string[];
|
|
24
15
|
};
|
|
25
|
-
|
|
16
|
+
type Changed = {
|
|
17
|
+
documents?: readonly string[] | null;
|
|
26
18
|
drafts?: readonly string[];
|
|
27
19
|
room?: boolean;
|
|
28
20
|
queue?: boolean;
|
|
29
21
|
presentation?: string;
|
|
30
|
-
}
|
|
31
|
-
export declare function
|
|
22
|
+
};
|
|
23
|
+
export declare function changeSet(locator: string, changed?: Changed): ChangeSet;
|
|
24
|
+
export declare function conversationChangeSet(conversations: readonly string[]): ChangeSet;
|
|
32
25
|
export declare function mergeChangeSets(sets: readonly ChangeSet[]): ChangeSet;
|
|
26
|
+
export declare function touches(set: ChangeSet, locator: string, path: string): boolean;
|
|
27
|
+
export {};
|
|
33
28
|
//# sourceMappingURL=change-set.d.ts.map
|
package/dist/change-set.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"change-set.d.ts","sourceRoot":"","sources":["../src/change-set.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"change-set.d.ts","sourceRoot":"","sources":["../src/change-set.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAExF,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,SAAS,cAAc,EAAE,CAAC;IACrC,MAAM,EAAE,SAAS;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACrD,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IACrC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,OAAY,GAAG,SAAS,CAe3E;AAED,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CASjF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CASrE;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAI9E"}
|