@agentshouse/mdruntime 0.1.0-c49444f2a8fc6 → 0.1.0-c4c5934c45f21
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 +8 -8
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +308 -0
- package/dist/act-lanes.d.ts +33 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +177 -0
- package/dist/actions.d.ts +20 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +251 -0
- package/dist/adapter.d.ts +31 -44
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +6 -18
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +4 -2
- package/dist/chat-types.d.ts +5 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +13 -0
- package/dist/client.d.ts +19 -13
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +30 -14
- package/dist/collection.d.ts +22 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +12 -2
- package/dist/compile.d.ts +5 -0
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +200 -75
- package/dist/connection.d.ts +5 -143
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +104 -5308
- package/dist/conversation-live.d.ts +136 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +249 -0
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +7 -1
- package/dist/conversation.d.ts +43 -44
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +906 -1024
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +148 -0
- package/dist/durability.d.ts +9 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/expectation.d.ts +4 -2
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +33 -11
- package/dist/failure.d.ts +1 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/holdings.d.ts +29 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +95 -0
- package/dist/host.d.ts +18 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +45 -12
- package/dist/index.d.ts +22 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/dist/install.d.ts +54 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +538 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +272 -0
- package/dist/listing.d.ts +48 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +139 -0
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +3 -3
- package/dist/locks.d.ts +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +33 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +50 -0
- package/dist/media.d.ts +1 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +4 -4
- package/dist/memory.d.ts +4 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +38 -20
- package/dist/messages.d.ts +1 -4
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +14 -32
- package/dist/model.d.ts +0 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -5
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +156 -0
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +12 -17
- package/dist/opened.d.ts +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +5 -5
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +59 -0
- package/dist/outcome.d.ts +4 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +3 -0
- package/dist/overlay.d.ts +2 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +32 -21
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +3 -51
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +14 -111
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +22 -0
- package/dist/preparation.d.ts +20 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +233 -0
- package/dist/presence.d.ts +52 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +220 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +270 -0
- package/dist/query.d.ts +10 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +2 -0
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +5 -1
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +455 -0
- package/dist/reach.d.ts +3 -1
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +38 -8
- package/dist/react.d.ts +18 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +15 -1
- package/dist/readiness.d.ts +0 -1
- package/dist/readiness.d.ts.map +1 -1
- package/dist/reads.d.ts +37 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +174 -0
- package/dist/refresh.js +2 -2
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +57 -0
- package/dist/replica.d.ts +5 -13
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +15 -16
- package/dist/room-draft.d.ts +4 -6
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +36 -52
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +217 -0
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +3 -4
- package/dist/runtime.d.ts +34 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +41 -86
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +232 -112
- package/dist/saves.d.ts +32 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +413 -0
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/shared.d.ts +1 -6
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -95
- package/dist/shown.d.ts +32 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +290 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/lanes.d.ts +20 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +77 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket/session.d.ts +38 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +23 -0
- package/dist/socket.d.ts +67 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +170 -0
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +5 -4
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +34 -0
- package/dist/store/readiness.d.ts +10 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +52 -0
- package/dist/store/records.d.ts +212 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +430 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- package/dist/store/space.d.ts +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +112 -204
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +158 -394
- package/dist/stored.d.ts +1 -1
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +28 -14
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +223 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +521 -0
- package/dist/tables.d.ts +32 -8
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +43 -12
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +2 -2
- package/dist/wire.d.ts +48 -5
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +16 -3
- package/package.json +3 -2
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/job.d.ts +0 -33
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -54
package/dist/sync.js
ADDED
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import { resendCalls, resendLater } from './actions.js';
|
|
2
|
+
import { catchUpConversations, reconcileConversations, resendConversations, } from './conversation.js';
|
|
3
|
+
import { declared, sameDeclaration } from './declaration.js';
|
|
4
|
+
import { applyDiscovery, discoverRooms, malformed, signIn } from './discovery.js';
|
|
5
|
+
import { behind, caughtUpTo, publish, pullBootstrap, pullRefresh, reachedBy, replaced, standingAt, } from './install.js';
|
|
6
|
+
import { heldRooms, name } from './listing.js';
|
|
7
|
+
import { retainModel, revoked, scoped } from './models.js';
|
|
8
|
+
import { refuse } from './refusal.js';
|
|
9
|
+
import { emitRooms, moveTo, rest, roomUnreadable, submissionDue, transferring, AUTHORITY_TOPIC, } from './shown.js';
|
|
10
|
+
import { unconfirmed } from './transfer.js';
|
|
11
|
+
export const OPENING_LANE = 'opening';
|
|
12
|
+
async function advance(runtime, room, local, authorized, running, unheld) {
|
|
13
|
+
const { store, socket, presence } = runtime;
|
|
14
|
+
const live = () => running() && !store.space.full();
|
|
15
|
+
if (!live())
|
|
16
|
+
return unconfirmed;
|
|
17
|
+
const held = unheld === undefined ? await store.record(room.locator) : undefined;
|
|
18
|
+
if (socket.streamed && (held !== undefined || !store.installs.of(room.locator).beyondHorizon)) {
|
|
19
|
+
presence.stood(room.locator, false);
|
|
20
|
+
await name(runtime, room.locator);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const refresh = socket.reads.refresh;
|
|
24
|
+
if (held !== undefined && refresh !== undefined) {
|
|
25
|
+
const refreshed = await store.ahead((hold) => refreshedRoom(runtime, room, local, authorized, held, live, hold, refresh));
|
|
26
|
+
if (refreshed === 'behind')
|
|
27
|
+
return advance(runtime, room, local, authorized, live);
|
|
28
|
+
if (refreshed !== 'beyond-horizon')
|
|
29
|
+
return refreshed;
|
|
30
|
+
if (presence.standing(room.locator).reloadDue)
|
|
31
|
+
return unconfirmed;
|
|
32
|
+
replaced(store, [room.locator]);
|
|
33
|
+
}
|
|
34
|
+
const prior = held === undefined ? undefined : await store.record(room.locator);
|
|
35
|
+
const from = standingAt(store, room.locator, prior);
|
|
36
|
+
const bootstrapped = await pullBootstrap(runtime, authorized, room, local, live, prior, socket.reads, unheld);
|
|
37
|
+
if (bootstrapped.kind !== 'staged')
|
|
38
|
+
return live() ? bootstrapped : unconfirmed;
|
|
39
|
+
const landing = { kind: 'bootstrapped', refreshed: bootstrapped.refreshed, from };
|
|
40
|
+
if (await publish(runtime, local, room, bootstrapped.record, landing, live)) {
|
|
41
|
+
return live() ? null : unconfirmed;
|
|
42
|
+
}
|
|
43
|
+
return (await reachedBy(runtime, room.locator, bootstrapped.record.roomVersion))
|
|
44
|
+
? null
|
|
45
|
+
: advance(runtime, room, local, authorized, live);
|
|
46
|
+
}
|
|
47
|
+
async function refreshedRoom(runtime, room, local, authorized, held, live, hold, refresh) {
|
|
48
|
+
const { store, socket, presence } = runtime;
|
|
49
|
+
const refreshed = await pullRefresh(runtime, authorized, held, live, hold, refresh);
|
|
50
|
+
if (!live())
|
|
51
|
+
return unconfirmed;
|
|
52
|
+
if (refreshed.kind === 'still-current') {
|
|
53
|
+
presence.stood(room.locator, false);
|
|
54
|
+
if (presence.readable(room.locator))
|
|
55
|
+
emitRooms(runtime);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if (refreshed.kind === 'advanced') {
|
|
59
|
+
const landing = {
|
|
60
|
+
kind: 'refreshed',
|
|
61
|
+
from: refreshed.from,
|
|
62
|
+
remodelled: refreshed.remodelled,
|
|
63
|
+
};
|
|
64
|
+
if (!(await publish(runtime, local, room, refreshed.record, landing, live))) {
|
|
65
|
+
const now = (await store.record(room.locator))?.roomVersion;
|
|
66
|
+
const reached = now !== undefined && socket.reads.reached(room.locator, now, refreshed.record.roomVersion);
|
|
67
|
+
return reached ? null : 'behind';
|
|
68
|
+
}
|
|
69
|
+
await retainModel(runtime, room.locator, declared(room), null);
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return refreshed.kind === 'beyond-horizon' ? 'beyond-horizon' : refreshed;
|
|
73
|
+
}
|
|
74
|
+
export function advanced(runtime, room, local, authorized) {
|
|
75
|
+
return runtime.socket.lanes.inRoom(room.locator, (live) => advance(runtime, room, local, authorized, live));
|
|
76
|
+
}
|
|
77
|
+
export async function withhold(runtime, withheld, room, local, progress) {
|
|
78
|
+
const { presence, journal } = runtime;
|
|
79
|
+
if (withheld.kind === 'unconfirmed' || presence.lost(room.locator))
|
|
80
|
+
return;
|
|
81
|
+
if (withheld.kind === 'not-ready') {
|
|
82
|
+
progress.complete = false;
|
|
83
|
+
askAgain(runtime, room.locator);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (withheld.kind === 'transport-uncertainty' || withheld.kind === 'retryable-refusal') {
|
|
87
|
+
const reset = withheld.kind === 'retryable-refusal' ? withheld.reset : undefined;
|
|
88
|
+
presence.stood(room.locator, true, { reset });
|
|
89
|
+
repairLater(runtime, room.locator, reset === undefined ? { again: true } : { at: Date.parse(reset) });
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
presence.stood(room.locator, true, null);
|
|
93
|
+
if (withheld.kind === 'scoped-refusal') {
|
|
94
|
+
await scoped(runtime, withheld, room.locator, declared(room));
|
|
95
|
+
}
|
|
96
|
+
else if (withheld.kind === 'transport-uncertainty') {
|
|
97
|
+
progress.reachable = false;
|
|
98
|
+
}
|
|
99
|
+
else if (withheld.kind === 'retryable-refusal') {
|
|
100
|
+
journal.record(`refusal ${withheld.kind} ${withheld.code}`);
|
|
101
|
+
}
|
|
102
|
+
else if (withheld.kind === 'room-not-readable') {
|
|
103
|
+
roomUnreadable(runtime, room.locator);
|
|
104
|
+
}
|
|
105
|
+
else if (withheld.kind === 'revoked-authorization') {
|
|
106
|
+
await refuse(runtime, 'revoked-authorization');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function askAgain(runtime, locator) {
|
|
110
|
+
const { store, socket, presence } = runtime;
|
|
111
|
+
presence.askAgain(locator, () => {
|
|
112
|
+
const room = presence.room(locator);
|
|
113
|
+
if (socket.closed() ||
|
|
114
|
+
socket.stopping() ||
|
|
115
|
+
(socket.streamed && !socket.isOpen()) ||
|
|
116
|
+
room === undefined)
|
|
117
|
+
return;
|
|
118
|
+
const progress = { complete: true, reachable: true };
|
|
119
|
+
void store
|
|
120
|
+
.open()
|
|
121
|
+
.then((local) => socket.lanes.roomTask(locator, (live) => loadRoom(runtime, room, local, progress, live)))
|
|
122
|
+
.then(() => rest(runtime, progress), () => undefined);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async function prepareRoom(runtime, room, progress, prior) {
|
|
126
|
+
const { socket, journal } = runtime;
|
|
127
|
+
const { session } = socket;
|
|
128
|
+
if (socket.closed() || session.now().authorization === undefined) {
|
|
129
|
+
progress.complete = false;
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (prior !== undefined && prior.declaration.replica.selection !== room.replica.selection) {
|
|
133
|
+
emitRooms(runtime);
|
|
134
|
+
journal.record(`selection changed ${room.locator}`);
|
|
135
|
+
progress.complete = false;
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
const declaration = declared(room);
|
|
139
|
+
if (prior !== undefined && !sameDeclaration(prior.declaration, declaration)) {
|
|
140
|
+
await retainModel(runtime, room.locator, declaration, null);
|
|
141
|
+
}
|
|
142
|
+
const { paused, authorization } = session.now();
|
|
143
|
+
if (paused || authorization === undefined)
|
|
144
|
+
return false;
|
|
145
|
+
return room.replica.admission === 'admitted';
|
|
146
|
+
}
|
|
147
|
+
async function synchronize(runtime, listed, local, progress, attempt, live) {
|
|
148
|
+
const { store, socket } = runtime;
|
|
149
|
+
const heldNow = await store.rooms(listed.map(({ locator }) => locator));
|
|
150
|
+
const prepared = await Promise.allSettled(listed.map((room) => prepareRoom(runtime, room, progress, heldNow.get(room.locator)?.record)));
|
|
151
|
+
if (!live())
|
|
152
|
+
return;
|
|
153
|
+
const ready = listed.filter((_, index) => {
|
|
154
|
+
const outcome = prepared[index];
|
|
155
|
+
return outcome.status === 'fulfilled' && outcome.value;
|
|
156
|
+
});
|
|
157
|
+
if (attempt === 'opened') {
|
|
158
|
+
const held = await heldRooms(runtime, ready);
|
|
159
|
+
if (!live())
|
|
160
|
+
return;
|
|
161
|
+
socket.hand(held);
|
|
162
|
+
}
|
|
163
|
+
const kept = attempt === 'authorized'
|
|
164
|
+
? new Set((await store.rooms(ready.map(({ locator }) => locator))).keys())
|
|
165
|
+
: new Set();
|
|
166
|
+
for (const room of ready) {
|
|
167
|
+
if (attempt === 'opened' || kept.has(room.locator)) {
|
|
168
|
+
if (attempt === 'authorized')
|
|
169
|
+
await name(runtime, room.locator);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
void socket.lanes
|
|
173
|
+
.roomTask(room.locator, (live) => loadRoom(runtime, room, local, progress, live))
|
|
174
|
+
.then(() => rest(runtime, progress));
|
|
175
|
+
}
|
|
176
|
+
const failed = prepared.find((room) => room.status === 'rejected');
|
|
177
|
+
if (failed !== undefined)
|
|
178
|
+
throw failed.reason;
|
|
179
|
+
}
|
|
180
|
+
async function caughtUp(runtime, room, local, progress, live) {
|
|
181
|
+
const { socket } = runtime;
|
|
182
|
+
const { authorization } = socket.session.now();
|
|
183
|
+
if (socket.streamed || authorization === undefined)
|
|
184
|
+
return;
|
|
185
|
+
if (!live() || !(await behind(runtime, room)))
|
|
186
|
+
return;
|
|
187
|
+
const withheld = await advance(runtime, room, local, authorization, live);
|
|
188
|
+
if (withheld !== null)
|
|
189
|
+
await withhold(runtime, withheld, room, local, progress);
|
|
190
|
+
}
|
|
191
|
+
export async function loadRoom(runtime, room, local, progress, live, unheld) {
|
|
192
|
+
const { store, socket } = runtime;
|
|
193
|
+
const { authorization } = socket.session.now();
|
|
194
|
+
if (!live() || authorization === undefined)
|
|
195
|
+
return;
|
|
196
|
+
const prior = unheld === undefined ? await store.record(room.locator) : undefined;
|
|
197
|
+
if (prior !== undefined) {
|
|
198
|
+
if (!(await prepareRoom(runtime, room, progress, prior)))
|
|
199
|
+
return;
|
|
200
|
+
if (revoked(prior.model)) {
|
|
201
|
+
await reload(runtime, room, local, progress, live);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const withheld = await advance(runtime, room, local, authorization, live, unheld);
|
|
206
|
+
if (withheld !== null) {
|
|
207
|
+
await withhold(runtime, withheld, room, local, progress);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
await caughtUp(runtime, room, local, progress, live);
|
|
211
|
+
}
|
|
212
|
+
export async function reload(runtime, room, local, progress, live) {
|
|
213
|
+
const { store, socket, presence } = runtime;
|
|
214
|
+
try {
|
|
215
|
+
if (live())
|
|
216
|
+
presence.reload(room.locator, false);
|
|
217
|
+
const { authorization } = socket.session.now();
|
|
218
|
+
if (!live() || authorization === undefined)
|
|
219
|
+
return;
|
|
220
|
+
const prior = await store.record(room.locator);
|
|
221
|
+
const from = standingAt(store, room.locator, prior);
|
|
222
|
+
const bootstrapped = await pullBootstrap(runtime, authorization, room, local, live, prior);
|
|
223
|
+
if (bootstrapped.kind !== 'staged') {
|
|
224
|
+
if (live())
|
|
225
|
+
await withhold(runtime, bootstrapped, room, local, progress);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
await publish(runtime, local, room, bootstrapped.record, { kind: 'bootstrapped', refreshed: bootstrapped.refreshed, from }, live);
|
|
229
|
+
await caughtUp(runtime, room, local, progress, live);
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
caughtUpTo(runtime, room.locator);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function repairLater(runtime, locator, when) {
|
|
236
|
+
const { socket, presence, recovery } = runtime;
|
|
237
|
+
if (!socket.isOpen() || presence.standing(locator).repairing)
|
|
238
|
+
return;
|
|
239
|
+
void recovery.attempt(`repair ${locator}`, (signal) => repairPass(runtime, locator, signal), when);
|
|
240
|
+
}
|
|
241
|
+
async function repairPass(runtime, locator, signal) {
|
|
242
|
+
const { store, socket, presence } = runtime;
|
|
243
|
+
const room = presence.room(locator);
|
|
244
|
+
if (!socket.isOpen() ||
|
|
245
|
+
!socket.continuing() ||
|
|
246
|
+
socket.stopping() ||
|
|
247
|
+
!presence.standing(locator).stale)
|
|
248
|
+
return 'done';
|
|
249
|
+
if (room === undefined || room.replica.admission !== 'admitted')
|
|
250
|
+
return 'done';
|
|
251
|
+
const progress = { complete: true, reachable: true };
|
|
252
|
+
presence.repairing(locator, true);
|
|
253
|
+
try {
|
|
254
|
+
const local = await store.open();
|
|
255
|
+
await socket.lanes.roomTask(locator, async (live) => {
|
|
256
|
+
const { authorization } = socket.session.now();
|
|
257
|
+
if (!live() || authorization === undefined)
|
|
258
|
+
return;
|
|
259
|
+
const withheld = await advance(runtime, room, local, authorization, live);
|
|
260
|
+
if (withheld !== null && live())
|
|
261
|
+
await withhold(runtime, withheld, room, local, progress);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
presence.stood(locator, true);
|
|
266
|
+
progress.reachable = false;
|
|
267
|
+
}
|
|
268
|
+
finally {
|
|
269
|
+
presence.repairing(locator, false);
|
|
270
|
+
}
|
|
271
|
+
if (signal.aborted)
|
|
272
|
+
return 'done';
|
|
273
|
+
await rest(runtime, progress);
|
|
274
|
+
if (!presence.standing(locator).stale) {
|
|
275
|
+
await submissionDue(runtime, [locator]);
|
|
276
|
+
return 'done';
|
|
277
|
+
}
|
|
278
|
+
const { repairable } = presence.standing(locator);
|
|
279
|
+
if (repairable === null)
|
|
280
|
+
return 'done';
|
|
281
|
+
return repairable.reset === undefined ? 'again' : { at: Date.parse(repairable.reset) };
|
|
282
|
+
}
|
|
283
|
+
export async function finishOpening(runtime, progress, live) {
|
|
284
|
+
const { socket, presence, conversations, recovery } = runtime;
|
|
285
|
+
try {
|
|
286
|
+
if (!live()) {
|
|
287
|
+
progress.complete = false;
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
await submissionDue(runtime);
|
|
291
|
+
for (const locator of presence.repairsOwed())
|
|
292
|
+
repairLater(runtime, locator, {});
|
|
293
|
+
await reconcileConversations(conversations);
|
|
294
|
+
const reading = { complete: true, reachable: true };
|
|
295
|
+
await catchUpConversations(conversations, reading);
|
|
296
|
+
if (progress.reachable && reading.reachable)
|
|
297
|
+
await resendConversations(conversations, reading);
|
|
298
|
+
if (progress.reachable) {
|
|
299
|
+
void recovery.attempt('calls', (signal) => resendCalls(runtime, signal));
|
|
300
|
+
}
|
|
301
|
+
if (!reading.reachable) {
|
|
302
|
+
progress.reachable = false;
|
|
303
|
+
resendLater(runtime);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
catch {
|
|
307
|
+
progress.complete = false;
|
|
308
|
+
}
|
|
309
|
+
finally {
|
|
310
|
+
if (live()) {
|
|
311
|
+
socket.session.set({ complete: progress.complete });
|
|
312
|
+
await rest(runtime, progress, live);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
export function sync(runtime, attempt, found) {
|
|
317
|
+
const { store, socket } = runtime;
|
|
318
|
+
const { session } = socket;
|
|
319
|
+
return socket.lanes.task(OPENING_LANE, async (live) => {
|
|
320
|
+
if (!live()) {
|
|
321
|
+
socket.readyFromStore();
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const progress = { complete: true, reachable: true };
|
|
325
|
+
session.set({
|
|
326
|
+
underway: attempt === 'opened' ? progress : null,
|
|
327
|
+
...(attempt === 'opened' ? { streamed: progress } : {}),
|
|
328
|
+
complete: false,
|
|
329
|
+
recorded: false,
|
|
330
|
+
});
|
|
331
|
+
moveTo(runtime, transferring(runtime));
|
|
332
|
+
try {
|
|
333
|
+
const local = await store.open();
|
|
334
|
+
if (!live())
|
|
335
|
+
return;
|
|
336
|
+
await socket.authorize();
|
|
337
|
+
if (!live())
|
|
338
|
+
return;
|
|
339
|
+
const listed = await discoverRooms(runtime, local, progress, live, found);
|
|
340
|
+
if (listed !== null)
|
|
341
|
+
await synchronize(runtime, listed, local, progress, attempt, live);
|
|
342
|
+
}
|
|
343
|
+
catch {
|
|
344
|
+
progress.complete = false;
|
|
345
|
+
if (attempt === 'opened' && !socket.isHanded())
|
|
346
|
+
progress.reachable = false;
|
|
347
|
+
}
|
|
348
|
+
finally {
|
|
349
|
+
socket.notifyReady();
|
|
350
|
+
}
|
|
351
|
+
if (!live())
|
|
352
|
+
return;
|
|
353
|
+
if (attempt !== 'opened') {
|
|
354
|
+
await finishOpening(runtime, progress, live);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (socket.isHanded() || socket.closed() || progress.reachable)
|
|
358
|
+
return;
|
|
359
|
+
session.set({ underway: null });
|
|
360
|
+
await rest(runtime, progress, live);
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
export function resynchronize(runtime) {
|
|
364
|
+
const { store, socket, presence } = runtime;
|
|
365
|
+
return socket.lanes.task(OPENING_LANE, async (live) => {
|
|
366
|
+
if (!live() || !socket.isAnnounced())
|
|
367
|
+
return;
|
|
368
|
+
const progress = { complete: true, reachable: true };
|
|
369
|
+
moveTo(runtime, transferring(runtime));
|
|
370
|
+
try {
|
|
371
|
+
const local = await store.open();
|
|
372
|
+
if (!live())
|
|
373
|
+
return;
|
|
374
|
+
await synchronize(runtime, presence.rooms(), local, progress, 'unstreamed', live);
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
progress.complete = false;
|
|
378
|
+
}
|
|
379
|
+
if (live())
|
|
380
|
+
await finishOpening(runtime, progress, live);
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
export function countAuthorityChange({ store, socket, lastAnswers }) {
|
|
384
|
+
const authorityChanges = socket.session.now().authorityChanges + 1;
|
|
385
|
+
socket.session.set({ authorityChanges });
|
|
386
|
+
store.tell(AUTHORITY_TOPIC, authorityChanges);
|
|
387
|
+
lastAnswers.again();
|
|
388
|
+
}
|
|
389
|
+
export function changeAuthority(runtime, change) {
|
|
390
|
+
const { store, socket, journal } = runtime;
|
|
391
|
+
const { session } = socket;
|
|
392
|
+
return socket.lanes.task(OPENING_LANE, async (live) => {
|
|
393
|
+
if (!live() || !socket.isAnnounced())
|
|
394
|
+
return;
|
|
395
|
+
countAuthorityChange(runtime);
|
|
396
|
+
const progress = { complete: true, reachable: true };
|
|
397
|
+
moveTo(runtime, transferring(runtime));
|
|
398
|
+
try {
|
|
399
|
+
const local = await store.open();
|
|
400
|
+
if (!live())
|
|
401
|
+
return;
|
|
402
|
+
const invalid = malformed(change.rooms);
|
|
403
|
+
if (invalid !== null) {
|
|
404
|
+
journal.record(invalid);
|
|
405
|
+
await refuse(runtime, 'missing-required-guarantee');
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (change.member !== undefined)
|
|
409
|
+
await signIn(runtime, local, change.member);
|
|
410
|
+
const discoveries = session.now().discoveries + 1;
|
|
411
|
+
session.set({ discoveries });
|
|
412
|
+
const listed = await applyDiscovery(runtime, change.rooms, discoveries, change.left);
|
|
413
|
+
await synchronize(runtime, listed, local, progress, 'authorized', live);
|
|
414
|
+
}
|
|
415
|
+
catch {
|
|
416
|
+
progress.complete = false;
|
|
417
|
+
}
|
|
418
|
+
if (!live())
|
|
419
|
+
return;
|
|
420
|
+
if (!progress.complete)
|
|
421
|
+
session.set({ complete: false });
|
|
422
|
+
await rest(runtime, progress, live);
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
async function installCarried(runtime, room, local, change, live, progress) {
|
|
426
|
+
const { store, socket } = runtime;
|
|
427
|
+
const { authorization, underway } = socket.session.now();
|
|
428
|
+
if (authorization === undefined)
|
|
429
|
+
return;
|
|
430
|
+
if (underway === null)
|
|
431
|
+
moveTo(runtime, transferring(runtime));
|
|
432
|
+
const prior = await store.record(room.locator);
|
|
433
|
+
const from = standingAt(store, room.locator, prior);
|
|
434
|
+
const page = await change.read();
|
|
435
|
+
const carried = {
|
|
436
|
+
bootstrap: () => Promise.resolve({
|
|
437
|
+
kind: 'bootstrap',
|
|
438
|
+
roomVersion: page.roomVersion,
|
|
439
|
+
...(page.models === undefined ? {} : { models: page.models }),
|
|
440
|
+
documents: page.documents,
|
|
441
|
+
facts: page.facts,
|
|
442
|
+
revisions: page.revisions,
|
|
443
|
+
...(page.fileIds === undefined ? {} : { fileIds: page.fileIds }),
|
|
444
|
+
...(page.created === undefined ? {} : { created: page.created }),
|
|
445
|
+
changes: page.changes,
|
|
446
|
+
binaryFiles: page.binaryFiles,
|
|
447
|
+
...(page.folders === undefined ? {} : { folders: page.folders }),
|
|
448
|
+
}),
|
|
449
|
+
reached: socket.reads.reached,
|
|
450
|
+
};
|
|
451
|
+
const bootstrapped = await pullBootstrap(runtime, authorization, room, local, live, prior, carried);
|
|
452
|
+
if (bootstrapped.kind !== 'staged') {
|
|
453
|
+
if (live())
|
|
454
|
+
await withhold(runtime, bootstrapped, room, local, progress);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
await publish(runtime, local, room, bootstrapped.record, { kind: 'bootstrapped', refreshed: bootstrapped.refreshed, from }, live);
|
|
458
|
+
}
|
|
459
|
+
export function applyRoom(runtime, change) {
|
|
460
|
+
const { store, socket, presence } = runtime;
|
|
461
|
+
const { session } = socket;
|
|
462
|
+
const { locator } = change;
|
|
463
|
+
if (socket.stopping())
|
|
464
|
+
return Promise.resolve();
|
|
465
|
+
return socket.lanes
|
|
466
|
+
.inRoom(locator, async (live) => {
|
|
467
|
+
await socket.answered(locator);
|
|
468
|
+
const progress = session.now().underway ?? { complete: true, reachable: true };
|
|
469
|
+
try {
|
|
470
|
+
const local = await store.open();
|
|
471
|
+
for (;;) {
|
|
472
|
+
if (!live())
|
|
473
|
+
return null;
|
|
474
|
+
const room = presence.room(locator);
|
|
475
|
+
if (room === undefined || room.replica.admission !== 'admitted')
|
|
476
|
+
return null;
|
|
477
|
+
const held = await store.record(locator);
|
|
478
|
+
if (held === undefined) {
|
|
479
|
+
if (change.from !== null)
|
|
480
|
+
return null;
|
|
481
|
+
await installCarried(runtime, room, local, change, live, progress);
|
|
482
|
+
return progress;
|
|
483
|
+
}
|
|
484
|
+
if (held.declaration.replica.selection !== room.replica.selection)
|
|
485
|
+
return null;
|
|
486
|
+
const at = held.roomVersion;
|
|
487
|
+
if (socket.reads.reached(locator, at, change.roomVersion))
|
|
488
|
+
return progress;
|
|
489
|
+
if (change.from === null || !socket.reads.reached(locator, at, change.from)) {
|
|
490
|
+
await name(runtime, locator);
|
|
491
|
+
return progress;
|
|
492
|
+
}
|
|
493
|
+
if (session.now().underway === null)
|
|
494
|
+
moveTo(runtime, transferring(runtime));
|
|
495
|
+
const writing = () => live() && !store.space.full();
|
|
496
|
+
const refreshed = await store.ahead((hold) => pullRefresh(runtime, session.now().authorization ?? {}, held, writing, hold, () => change.read()));
|
|
497
|
+
if (refreshed.kind !== 'advanced')
|
|
498
|
+
return progress;
|
|
499
|
+
const landing = {
|
|
500
|
+
kind: 'refreshed',
|
|
501
|
+
from: refreshed.from,
|
|
502
|
+
remodelled: refreshed.remodelled,
|
|
503
|
+
};
|
|
504
|
+
if (await publish(runtime, local, room, refreshed.record, landing, writing)) {
|
|
505
|
+
presence.stood(locator, false);
|
|
506
|
+
const declaration = declared(room);
|
|
507
|
+
if (!sameDeclaration(held.declaration, declaration))
|
|
508
|
+
await retainModel(runtime, locator, declaration, null);
|
|
509
|
+
return progress;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
catch {
|
|
514
|
+
if (!presence.standing(locator).stale)
|
|
515
|
+
void name(runtime, locator);
|
|
516
|
+
presence.stood(locator, true);
|
|
517
|
+
return progress;
|
|
518
|
+
}
|
|
519
|
+
})
|
|
520
|
+
.then((progress) => rest(runtime, progress), () => undefined);
|
|
521
|
+
}
|
package/dist/tables.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { type QueryAnswer, type QueryRoom } from './compile.js';
|
|
2
2
|
import type { Composed } from './collection.js';
|
|
3
3
|
import type { UnsentWork } from './durability.js';
|
|
4
|
-
import type { JobMarker } from './job.js';
|
|
5
4
|
import { type ConversationWrite, type HeldConversation, type HeldRow, type MessageWindow } from './messages.js';
|
|
6
|
-
import type { Plan } from './query.js';
|
|
5
|
+
import type { GroupTotal, Plan } from './query.js';
|
|
6
|
+
import { type ReadAt } from './reads.js';
|
|
7
|
+
import { type ConversationTally, type RoomTally } from './tallies.js';
|
|
7
8
|
import { type Committed, type Covering, type HeldEntry, type HeldLocators, type HeldRoomRow, type HeldRoomWork, type ReplicaOpened, type Referrer, type Resumed, type RoomCommit, type StoredEntry, type TypedEntry, type View } from './stored.js';
|
|
8
9
|
export type { Committed, Covering, HeldEntry, HeldLocators, HeldRoomRow, HeldRoomWork, OverlayEntry, ReplicaOpened, Referrer, Resumed, RoomCommit, StoredEntry, TypedEntry, View, } from './stored.js';
|
|
9
10
|
export type { QueryAnswer, QueryRoom } from './compile.js';
|
|
10
11
|
export type { ConversationWrite, HeldConversation, HeldRow, MessageWindow } from './messages.js';
|
|
12
|
+
export type { ConversationTally, RoomTally } from './tallies.js';
|
|
11
13
|
export type Value = string | number | bigint | Uint8Array | null;
|
|
12
14
|
export type Row = Readonly<Record<string, Value>>;
|
|
13
15
|
export interface Connection {
|
|
@@ -50,7 +52,7 @@ export interface SqliteDatabase {
|
|
|
50
52
|
export declare function sqliteConnection(engine: SqliteEngine, database: SqliteDatabase): Connection;
|
|
51
53
|
export declare const FILE_PART_BYTES = 1048576;
|
|
52
54
|
export declare const RUNTIME_TABLES: readonly string[];
|
|
53
|
-
export type AuthoredFact = 'holder' | '
|
|
55
|
+
export type AuthoredFact = 'holder' | 'generation';
|
|
54
56
|
export type StoredFile = {
|
|
55
57
|
readonly key: string;
|
|
56
58
|
readonly blob: Blob;
|
|
@@ -113,6 +115,13 @@ export type OpenedFile = {
|
|
|
113
115
|
readonly byteLength: number;
|
|
114
116
|
readonly mediaType: string;
|
|
115
117
|
};
|
|
118
|
+
export type OpenedRoom = GroupTotal & {
|
|
119
|
+
readonly room: string;
|
|
120
|
+
};
|
|
121
|
+
export type OpenedHeld = {
|
|
122
|
+
readonly rooms: readonly OpenedRoom[];
|
|
123
|
+
readonly cleanable: number;
|
|
124
|
+
};
|
|
116
125
|
type Asked<A, R> = {
|
|
117
126
|
readonly asked: A;
|
|
118
127
|
readonly answer: R;
|
|
@@ -217,6 +226,11 @@ export interface RuntimeRequests {
|
|
|
217
226
|
readonly rooms: readonly QueryRoom[];
|
|
218
227
|
readonly budget: number | null;
|
|
219
228
|
}, QueryAnswer>;
|
|
229
|
+
readonly 'replica.tallies': Asked<{
|
|
230
|
+
readonly totals: Plan;
|
|
231
|
+
readonly rooms: readonly QueryRoom[];
|
|
232
|
+
readonly since: string;
|
|
233
|
+
}, readonly RoomTally[]>;
|
|
220
234
|
readonly 'replica.entries': Asked<{
|
|
221
235
|
readonly key: number;
|
|
222
236
|
readonly view: View;
|
|
@@ -234,7 +248,6 @@ export interface RuntimeRequests {
|
|
|
234
248
|
}, readonly Referrer[]>;
|
|
235
249
|
readonly 'replica.folders': Asked<{
|
|
236
250
|
readonly key: number;
|
|
237
|
-
readonly view: View;
|
|
238
251
|
readonly paths: readonly string[];
|
|
239
252
|
}, readonly string[]>;
|
|
240
253
|
readonly 'replica.typedWithin': Asked<{
|
|
@@ -337,6 +350,7 @@ export interface RuntimeRequests {
|
|
|
337
350
|
readonly key: string;
|
|
338
351
|
}, null>;
|
|
339
352
|
readonly 'opened.clean': Asked<Nothing, number>;
|
|
353
|
+
readonly 'opened.held': Asked<Nothing, OpenedHeld>;
|
|
340
354
|
readonly 'file.part': Asked<{
|
|
341
355
|
readonly key: string;
|
|
342
356
|
readonly part: number;
|
|
@@ -362,13 +376,21 @@ export interface RuntimeRequests {
|
|
|
362
376
|
readonly 'conversation.rows': Asked<{
|
|
363
377
|
readonly conversations: readonly string[];
|
|
364
378
|
}, readonly HeldRow[]>;
|
|
365
|
-
readonly 'conversation.
|
|
366
|
-
readonly
|
|
367
|
-
|
|
379
|
+
readonly 'conversation.tallies': Asked<{
|
|
380
|
+
readonly conversations: readonly string[] | null;
|
|
381
|
+
readonly since: string;
|
|
382
|
+
}, readonly ConversationTally[]>;
|
|
368
383
|
readonly 'conversation.drop': Asked<{
|
|
369
384
|
readonly conversations: readonly string[];
|
|
370
385
|
}, null>;
|
|
371
386
|
readonly 'space.probe': Asked<Nothing, null>;
|
|
387
|
+
readonly 'read.stored': Asked<ReadAt, string | null>;
|
|
388
|
+
readonly 'read.keep': Asked<ReadAt & {
|
|
389
|
+
readonly answer: string;
|
|
390
|
+
}, null>;
|
|
391
|
+
readonly 'read.builds': Asked<{
|
|
392
|
+
readonly build: string;
|
|
393
|
+
}, null>;
|
|
372
394
|
}
|
|
373
395
|
export type RuntimeKind = keyof RuntimeRequests;
|
|
374
396
|
export type RuntimeRequest<K extends RuntimeKind = RuntimeKind> = {
|
|
@@ -383,6 +405,8 @@ export interface RuntimeDatabase {
|
|
|
383
405
|
export declare function isRuntime(request: {
|
|
384
406
|
readonly kind: string;
|
|
385
407
|
}): request is RuntimeRequest;
|
|
386
|
-
export declare function readsRuntime(request:
|
|
408
|
+
export declare function readsRuntime(request: {
|
|
409
|
+
readonly kind: string;
|
|
410
|
+
}): boolean;
|
|
387
411
|
export declare function answerRuntime(connection: Connection, request: RuntimeRequest, spool: FileSpool): unknown;
|
|
388
412
|
//# sourceMappingURL=tables.d.ts.map
|