@agentshouse/mdruntime 0.1.0-cb1f56e16291b → 0.1.0-cb3bb3b233fa1
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 +21 -19
- package/dist/acceptance.d.ts +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +299 -0
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +26 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +302 -0
- package/dist/adapter.d.ts +113 -81
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +3 -11
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +20 -60
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/bootstrap.d.ts +9 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +204 -85
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- 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 +5 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +7 -2
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +11 -0
- package/dist/client.d.ts +30 -22
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +39 -20
- package/dist/collection.d.ts +26 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +19 -2
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +9 -7
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +252 -318
- package/dist/connection.d.ts +5 -141
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +111 -5282
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +150 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +259 -0
- package/dist/conversation-row.d.ts +40 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +66 -0
- package/dist/conversation.d.ts +62 -43
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +987 -902
- 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 +150 -0
- package/dist/durability.d.ts +19 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +4 -0
- package/dist/entry.d.ts +2 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +18 -9
- package/dist/expectation.d.ts +26 -13
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +72 -19
- package/dist/failure.d.ts +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +6 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +199 -0
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- 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 +20 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +72 -28
- package/dist/identity.d.ts +0 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -3
- package/dist/index.d.ts +32 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -5
- package/dist/install.d.ts +60 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +537 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +282 -0
- package/dist/listing.d.ts +52 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +152 -0
- package/dist/live.d.ts +8 -6
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +110 -31
- package/dist/loaded.d.ts +5 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +40 -0
- package/dist/locks.d.ts +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +32 -0
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +49 -0
- package/dist/media.d.ts +6 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +68 -17
- package/dist/memory.d.ts +11 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +132 -33
- package/dist/messages.d.ts +33 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +98 -27
- package/dist/model.d.ts +2 -10
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -14
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +153 -0
- package/dist/observation.d.ts +27 -12
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +184 -85
- 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 +53 -0
- package/dist/outcome.d.ts +17 -2
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +35 -2
- package/dist/overlay.d.ts +7 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +48 -24
- 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 +4 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +13 -0
- 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 +41 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +314 -0
- package/dist/presence.d.ts +58 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +231 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +308 -0
- package/dist/query.d.ts +13 -213
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -524
- package/dist/questions.d.ts +30 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +116 -0
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +480 -0
- package/dist/reach.d.ts +10 -10
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +235 -120
- package/dist/react.d.ts +17 -3
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +9 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +3 -5
- package/dist/reads.d.ts +39 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +178 -0
- package/dist/recovery.d.ts +3 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +38 -8
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +10 -22
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +55 -0
- package/dist/replica.d.ts +11 -16
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +66 -35
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +32 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +273 -66
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +220 -0
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +45 -0
- package/dist/rows.d.ts +16 -23
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +49 -191
- 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 +42 -86
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +332 -228
- package/dist/saves.d.ts +34 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +437 -0
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +1 -1
- 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 +33 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +309 -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 +28 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +103 -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 +164 -0
- package/dist/source.d.ts +59 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +93 -0
- package/dist/status.d.ts +0 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -6
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +40 -0
- package/dist/store/readiness.d.ts +11 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +68 -0
- package/dist/store/records.d.ts +223 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +465 -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/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -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 +115 -152
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +171 -395
- package/dist/stored.d.ts +72 -67
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +317 -166
- package/dist/surface.d.ts +90 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +225 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +536 -0
- package/dist/tables.d.ts +112 -89
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +197 -283
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +128 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +9 -12
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +68 -7
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +23 -4
- 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/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/job.d.ts +0 -14
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -28
- package/dist/log.d.ts +0 -5
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/phrase.d.ts +0 -3
- package/dist/phrase.d.ts.map +0 -1
- package/dist/phrase.js +0 -8
package/dist/install.js
ADDED
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
import { attachedModel } from './attached-model.js';
|
|
2
|
+
import { bootstrapRoom } from './bootstrap.js';
|
|
3
|
+
import { refusedForSpace } from './durability.js';
|
|
4
|
+
import { uncaught } from './failure.js';
|
|
5
|
+
import { name } from './listing.js';
|
|
6
|
+
import { NO_MODEL } from './model.js';
|
|
7
|
+
import { settle } from './queue.js';
|
|
8
|
+
import { advancement } from './refresh.js';
|
|
9
|
+
import { recoverReads } from './shown.js';
|
|
10
|
+
import { unconfirmed } from './transfer.js';
|
|
11
|
+
import { ROW_WEIGHT, yielded } from './turn.js';
|
|
12
|
+
// Bytes still arriving are reported at most this often, so readiness is not rebuilt for every chunk the network hands over while a slow link still moves the figure.
|
|
13
|
+
const ARRIVAL_REPORT_MS = 250;
|
|
14
|
+
const NOTHING_HELD = { bytes: 0 };
|
|
15
|
+
export const ERASE_BATCH = 512;
|
|
16
|
+
function transferGone(held) {
|
|
17
|
+
return {
|
|
18
|
+
...held,
|
|
19
|
+
transfer: null,
|
|
20
|
+
arrived: null,
|
|
21
|
+
streaming: false,
|
|
22
|
+
underived: 0,
|
|
23
|
+
unindexed: [],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function amountOf(held, kept) {
|
|
27
|
+
if (held.transfer !== null) {
|
|
28
|
+
const owed = held.unindexed.reduce((sum, part) => sum + part.bytes, 0);
|
|
29
|
+
return {
|
|
30
|
+
done: held.transfer.done.bytes - Math.ceil(owed),
|
|
31
|
+
total: Math.max(held.arrived ?? 0, held.transfer.done.bytes),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return { done: kept, total: held.arrived ?? kept };
|
|
35
|
+
}
|
|
36
|
+
function setBack(held) {
|
|
37
|
+
const now = amountOf(held, NOTHING_HELD.bytes);
|
|
38
|
+
const earlier = held.startedOver;
|
|
39
|
+
return {
|
|
40
|
+
...held,
|
|
41
|
+
startedOver: {
|
|
42
|
+
done: Math.max(now.done, earlier?.done ?? 0),
|
|
43
|
+
total: Math.max(now.total, earlier?.total ?? 0),
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function owedIndexes(held, bytes, text) {
|
|
48
|
+
if (bytes <= 0 || text <= 0)
|
|
49
|
+
return held;
|
|
50
|
+
return { ...held, unindexed: [...held.unindexed, { bytes, text }] };
|
|
51
|
+
}
|
|
52
|
+
function built(held, done, text) {
|
|
53
|
+
const owed = [...held.unindexed];
|
|
54
|
+
let left = text;
|
|
55
|
+
while (!done && left > 0 && owed.length > 0) {
|
|
56
|
+
const [first] = owed;
|
|
57
|
+
if (left >= first.text) {
|
|
58
|
+
left -= first.text;
|
|
59
|
+
owed.shift();
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
owed[0] = {
|
|
63
|
+
bytes: (first.bytes * (first.text - left)) / first.text,
|
|
64
|
+
text: first.text - left,
|
|
65
|
+
};
|
|
66
|
+
left = 0;
|
|
67
|
+
}
|
|
68
|
+
return { ...held, unindexed: done ? [] : owed };
|
|
69
|
+
}
|
|
70
|
+
function batchEnd(entries, from, bytes) {
|
|
71
|
+
let end = from;
|
|
72
|
+
let spent = 0;
|
|
73
|
+
while (end < entries.length) {
|
|
74
|
+
const size = (entries[end].content?.length ?? 0) + ROW_WEIGHT;
|
|
75
|
+
if (spent + size > bytes && end > from)
|
|
76
|
+
break;
|
|
77
|
+
spent += size;
|
|
78
|
+
end += 1;
|
|
79
|
+
}
|
|
80
|
+
return end;
|
|
81
|
+
}
|
|
82
|
+
const UNSHARED = {
|
|
83
|
+
installing: false,
|
|
84
|
+
downloading: false,
|
|
85
|
+
bytes: { done: 0, total: 0 },
|
|
86
|
+
};
|
|
87
|
+
export function installShare(store, { room, state }, held) {
|
|
88
|
+
if (state === 'unadmitted')
|
|
89
|
+
return UNSHARED;
|
|
90
|
+
const install = store.installs.of(room);
|
|
91
|
+
const underway = state === 'acquiring' || (install.installing && state !== 'complete');
|
|
92
|
+
const kept = underway ? NOTHING_HELD.bytes : (held.get(room)?.bytes ?? NOTHING_HELD.bytes);
|
|
93
|
+
const now = amountOf(install, kept);
|
|
94
|
+
const earlier = underway ? install.startedOver : null;
|
|
95
|
+
return {
|
|
96
|
+
installing: underway,
|
|
97
|
+
downloading: underway && (install.streaming || install.arrived === null),
|
|
98
|
+
bytes: {
|
|
99
|
+
done: Math.max(now.done, earlier?.done ?? 0),
|
|
100
|
+
total: Math.max(now.total, earlier?.total ?? 0),
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function installationOf(installing, downloading, bytes) {
|
|
105
|
+
const step = installing === 0
|
|
106
|
+
? null
|
|
107
|
+
: downloading > 0
|
|
108
|
+
? 'downloading'
|
|
109
|
+
: bytes.done < bytes.total
|
|
110
|
+
? 'writing'
|
|
111
|
+
: 'replaying';
|
|
112
|
+
return { step, bytes };
|
|
113
|
+
}
|
|
114
|
+
export function roomInFlight(store, locator) {
|
|
115
|
+
const { catching, transfer } = store.installs.of(locator);
|
|
116
|
+
return catching || transfer !== null;
|
|
117
|
+
}
|
|
118
|
+
function installing(runtime, locator) {
|
|
119
|
+
runtime.store.installs.change(locator, (held) => ({ ...held, installing: true }));
|
|
120
|
+
runtime.store.readiness.queue([locator]);
|
|
121
|
+
}
|
|
122
|
+
function installed(runtime, locator) {
|
|
123
|
+
if (!runtime.store.installs.of(locator).installing)
|
|
124
|
+
return;
|
|
125
|
+
runtime.store.installs.change(locator, (held) => ({ ...held, installing: false }));
|
|
126
|
+
runtime.store.readiness.queue([locator]);
|
|
127
|
+
}
|
|
128
|
+
export function sweep({ store, socket }) {
|
|
129
|
+
if (store.device.now().sweeping || socket.closed())
|
|
130
|
+
return;
|
|
131
|
+
store.device.set({ sweeping: true });
|
|
132
|
+
void (async () => {
|
|
133
|
+
try {
|
|
134
|
+
while (!socket.closed() && (await store.durably((local) => local.erase(null, ERASE_BATCH)))) {
|
|
135
|
+
await yielded();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
uncaught(error);
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
store.device.set({ sweeping: false });
|
|
143
|
+
}
|
|
144
|
+
})();
|
|
145
|
+
}
|
|
146
|
+
export function caughtUpTo(runtime, locator) {
|
|
147
|
+
if (!runtime.store.installs.of(locator).catching)
|
|
148
|
+
return;
|
|
149
|
+
runtime.store.installs.change(locator, (held) => ({ ...held, catching: false }));
|
|
150
|
+
recoverReads(runtime, [locator]);
|
|
151
|
+
}
|
|
152
|
+
export function catching(store, locator) {
|
|
153
|
+
store.installs.change(locator, (held) => ({ ...held, catching: true }));
|
|
154
|
+
}
|
|
155
|
+
export function standingAt(store, locator, held) {
|
|
156
|
+
return { key: held?.key ?? null, confirmed: store.installs.of(locator).confirmations };
|
|
157
|
+
}
|
|
158
|
+
function standsAt(store, locator, held, from) {
|
|
159
|
+
const now = standingAt(store, locator, held);
|
|
160
|
+
return now.key === from.key && now.confirmed === from.confirmed;
|
|
161
|
+
}
|
|
162
|
+
function shownAt({ store, socket }, locator, held) {
|
|
163
|
+
const raised = store.installs.of(locator).highest ?? undefined;
|
|
164
|
+
if (held === undefined || raised === undefined)
|
|
165
|
+
return held ?? raised;
|
|
166
|
+
return socket.reads.reached(locator, held, raised) ? held : raised;
|
|
167
|
+
}
|
|
168
|
+
export function showing(system, locator, roomVersion, held) {
|
|
169
|
+
const at = shownAt(system, locator, held);
|
|
170
|
+
if (at === undefined || !system.socket.reads.reached(locator, at, roomVersion)) {
|
|
171
|
+
system.store.installs.change(locator, (room) => ({ ...room, highest: roomVersion }));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
export function olderThan(system, locator, roomVersion, held) {
|
|
175
|
+
const { store, socket } = system;
|
|
176
|
+
if (store.installs.of(locator).beyondHorizon)
|
|
177
|
+
return false;
|
|
178
|
+
const at = shownAt(system, locator, held);
|
|
179
|
+
return (at !== undefined &&
|
|
180
|
+
socket.reads.reached(locator, at, roomVersion) &&
|
|
181
|
+
!socket.reads.reached(locator, roomVersion, at));
|
|
182
|
+
}
|
|
183
|
+
async function older(runtime, locator, roomVersion) {
|
|
184
|
+
const { store } = runtime;
|
|
185
|
+
if (store.installs.of(locator).beyondHorizon)
|
|
186
|
+
return false;
|
|
187
|
+
return olderThan(runtime, locator, roomVersion, (await store.record(locator))?.roomVersion);
|
|
188
|
+
}
|
|
189
|
+
export function replaced(store, locators) {
|
|
190
|
+
for (const locator of locators) {
|
|
191
|
+
store.installs.change(locator, (held) => ({ ...held, highest: null, beyondHorizon: true }));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
export async function reachedBy({ store, socket }, locator, roomVersion) {
|
|
195
|
+
const held = await store.record(locator);
|
|
196
|
+
return held !== undefined && socket.reads.reached(locator, held.roomVersion, roomVersion);
|
|
197
|
+
}
|
|
198
|
+
export async function behind({ store, socket }, room) {
|
|
199
|
+
const held = (await store.record(room.locator))?.roomVersion;
|
|
200
|
+
return held !== undefined && !socket.reads.reached(room.locator, held, room.roomVersion);
|
|
201
|
+
}
|
|
202
|
+
export async function writtenAfter({ store, socket }, locator, roomVersion, path) {
|
|
203
|
+
const held = await store.record(locator);
|
|
204
|
+
if (held === undefined)
|
|
205
|
+
return false;
|
|
206
|
+
const [entry] = await (await store.open()).entries(held.key, 'confirmed', [path]);
|
|
207
|
+
const written = entry?.written ?? undefined;
|
|
208
|
+
return (written !== undefined &&
|
|
209
|
+
socket.reads.reached(locator, written, roomVersion) &&
|
|
210
|
+
!socket.reads.reached(locator, roomVersion, written));
|
|
211
|
+
}
|
|
212
|
+
async function writtenLater(runtime, local, locator, key, paths, roomVersion, heldAt) {
|
|
213
|
+
if (paths.length === 0)
|
|
214
|
+
return new Set();
|
|
215
|
+
const { reached } = runtime.socket.reads;
|
|
216
|
+
const behindShown = heldAt === undefined
|
|
217
|
+
? await older(runtime, locator, roomVersion)
|
|
218
|
+
: olderThan(runtime, locator, roomVersion, heldAt);
|
|
219
|
+
if (!behindShown)
|
|
220
|
+
return new Set();
|
|
221
|
+
const entries = await local.entries(key, 'confirmed', paths);
|
|
222
|
+
return new Set(entries.flatMap(({ path, written }) => written !== null &&
|
|
223
|
+
reached(locator, written, roomVersion) &&
|
|
224
|
+
!reached(locator, roomVersion, written)
|
|
225
|
+
? [path]
|
|
226
|
+
: []));
|
|
227
|
+
}
|
|
228
|
+
function remodel(runtime, answers, held) {
|
|
229
|
+
const answer = answers?.collection;
|
|
230
|
+
if (answer === undefined)
|
|
231
|
+
return held;
|
|
232
|
+
return { collection: attachedModel(answer, runtime.roomTypes) };
|
|
233
|
+
}
|
|
234
|
+
function refreshingOf(runtime, local, locator, key, composition, liveness, replaying = false, heldAt) {
|
|
235
|
+
const { store } = runtime;
|
|
236
|
+
const write = replaying ? store.finishingWrite : store.exclusive;
|
|
237
|
+
return {
|
|
238
|
+
turn() {
|
|
239
|
+
if (replaying)
|
|
240
|
+
installing(runtime, locator);
|
|
241
|
+
},
|
|
242
|
+
prior: async (paths) => new Map((await local.entries(key, 'refreshed', paths)).map((entry) => [entry.path, entry])),
|
|
243
|
+
later: (paths, roomVersion) => writtenLater(runtime, local, locator, key, paths, roomVersion, heldAt),
|
|
244
|
+
async stage(page) {
|
|
245
|
+
for (let written = 0;;) {
|
|
246
|
+
const end = batchEnd(page.entries, written, store.stageBytes());
|
|
247
|
+
const last = end === page.entries.length;
|
|
248
|
+
const entries = page.entries.slice(written, end);
|
|
249
|
+
const staged = await write(async () => {
|
|
250
|
+
if (!liveness())
|
|
251
|
+
return false;
|
|
252
|
+
await store.refreshPage(local, key, composition, last
|
|
253
|
+
? { ...page, entries }
|
|
254
|
+
: { entries, removals: [], folders: [], folderRemovals: [] });
|
|
255
|
+
return true;
|
|
256
|
+
});
|
|
257
|
+
if (!staged)
|
|
258
|
+
return false;
|
|
259
|
+
if (last)
|
|
260
|
+
return true;
|
|
261
|
+
written = end;
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
export async function pullRefresh(runtime, authorized, record, liveness, hold, refresh) {
|
|
267
|
+
if (!liveness())
|
|
268
|
+
return unconfirmed;
|
|
269
|
+
const { store } = runtime;
|
|
270
|
+
const from = standingAt(store, record.locator, record);
|
|
271
|
+
const local = await store.open();
|
|
272
|
+
try {
|
|
273
|
+
await store.exclusive(() => local.unrefresh(record.key));
|
|
274
|
+
const result = await advancement(async (authorization, request) => {
|
|
275
|
+
hold.release();
|
|
276
|
+
try {
|
|
277
|
+
return await refresh(authorization, request);
|
|
278
|
+
}
|
|
279
|
+
finally {
|
|
280
|
+
hold.take();
|
|
281
|
+
}
|
|
282
|
+
}, authorized, record, (models, kept) => (liveness() ? remodel(runtime, models, kept) : kept), liveness, refreshingOf(runtime, local, record.locator, record.key, store.composed(record), liveness, false, record.roomVersion));
|
|
283
|
+
if (result.kind !== 'advanced')
|
|
284
|
+
return result;
|
|
285
|
+
return {
|
|
286
|
+
kind: 'advanced',
|
|
287
|
+
record: result.record,
|
|
288
|
+
from,
|
|
289
|
+
remodelled: result.record.model !== record.model,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
if (refusedForSpace(error))
|
|
294
|
+
return unconfirmed;
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async function abandoned(runtime, local, locator) {
|
|
299
|
+
await local.abandon(locator);
|
|
300
|
+
runtime.store.installs.change(locator, (held) => transferGone(setBack(held)));
|
|
301
|
+
recoverReads(runtime, [locator]);
|
|
302
|
+
runtime.store.readiness.queue([locator]);
|
|
303
|
+
sweep(runtime);
|
|
304
|
+
}
|
|
305
|
+
function staging(runtime, local, liveness, unheld) {
|
|
306
|
+
const { store, socket } = runtime;
|
|
307
|
+
const derived = async (locator, key, composition) => {
|
|
308
|
+
store.installs.change(locator, (held) => ({ ...held, underived: 0 }));
|
|
309
|
+
for (;;) {
|
|
310
|
+
if (!liveness())
|
|
311
|
+
return false;
|
|
312
|
+
const done = await store.finishingWrite(async () => liveness() ? store.rederive(local, key, composition) : null);
|
|
313
|
+
if (done === null)
|
|
314
|
+
return false;
|
|
315
|
+
store.installs.change(locator, (held) => built(held, done.done, done.text));
|
|
316
|
+
runtime.store.readiness.queue([locator]);
|
|
317
|
+
if (done.done)
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
return {
|
|
322
|
+
held: (locator) => store.installs.of(locator).transfer,
|
|
323
|
+
async turn(locator, step) {
|
|
324
|
+
installing(runtime, locator);
|
|
325
|
+
return step === 'downloading' ? socket.heldStream() : () => { };
|
|
326
|
+
},
|
|
327
|
+
unqueued: socket.unqueued,
|
|
328
|
+
queued: socket.queued,
|
|
329
|
+
arriving(locator) {
|
|
330
|
+
let ended = false;
|
|
331
|
+
return {
|
|
332
|
+
at(bytes) {
|
|
333
|
+
if (ended)
|
|
334
|
+
return;
|
|
335
|
+
store.installs.change(locator, (held) => ({
|
|
336
|
+
...held,
|
|
337
|
+
arrived: bytes,
|
|
338
|
+
streaming: true,
|
|
339
|
+
}));
|
|
340
|
+
const due = store.installs.arrivalsDue(locator, performance.now(), ARRIVAL_REPORT_MS);
|
|
341
|
+
if (due.length > 0)
|
|
342
|
+
runtime.store.readiness.queue(due);
|
|
343
|
+
},
|
|
344
|
+
end() {
|
|
345
|
+
if (ended)
|
|
346
|
+
return;
|
|
347
|
+
ended = true;
|
|
348
|
+
if (!store.installs.of(locator).streaming)
|
|
349
|
+
return;
|
|
350
|
+
store.installs.change(locator, (held) => ({ ...held, streaming: false }));
|
|
351
|
+
runtime.store.readiness.queue([locator]);
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
},
|
|
355
|
+
streamed: socket.streamed,
|
|
356
|
+
async stage(record, page, composition) {
|
|
357
|
+
const { locator } = record;
|
|
358
|
+
installing(runtime, locator);
|
|
359
|
+
if (!liveness())
|
|
360
|
+
return null;
|
|
361
|
+
const key = await store.startingWrite(async () => {
|
|
362
|
+
if (!liveness())
|
|
363
|
+
return null;
|
|
364
|
+
return local.stage(record, composition, page);
|
|
365
|
+
});
|
|
366
|
+
if (key === null || !liveness())
|
|
367
|
+
return null;
|
|
368
|
+
const before = store.installs.of(locator);
|
|
369
|
+
const prior = before.transfer?.done.bytes ?? 0;
|
|
370
|
+
const held = { ...record, key };
|
|
371
|
+
const text = page.entries.reduce((sum, entry) => sum + (entry.content?.length ?? 0), 0);
|
|
372
|
+
const owed = text + before.underived;
|
|
373
|
+
store.installs.change(locator, (room) => ({
|
|
374
|
+
...owedIndexes(room, record.done.bytes - prior, text),
|
|
375
|
+
transfer: held,
|
|
376
|
+
underived: owed,
|
|
377
|
+
}));
|
|
378
|
+
installing(runtime, locator);
|
|
379
|
+
recoverReads(runtime, [locator]);
|
|
380
|
+
if (owed < store.deriveBytes())
|
|
381
|
+
return held;
|
|
382
|
+
return (await derived(locator, key, composition)) ? held : null;
|
|
383
|
+
},
|
|
384
|
+
async resume(record, parts, composition) {
|
|
385
|
+
const { locator } = record;
|
|
386
|
+
installing(runtime, locator);
|
|
387
|
+
if (!liveness())
|
|
388
|
+
return null;
|
|
389
|
+
const prior = unheld === undefined ? await store.record(locator) : undefined;
|
|
390
|
+
const published = prior !== undefined && prior.declaration.replica.selection === record.selection
|
|
391
|
+
? prior.key
|
|
392
|
+
: null;
|
|
393
|
+
const kept = unheld?.staged ?? (await local.held()).staged.has(locator);
|
|
394
|
+
if (published === null && !kept)
|
|
395
|
+
return { record: null, staged: new Set() };
|
|
396
|
+
const resumed = await store.startingWrite(async () => {
|
|
397
|
+
if (!liveness())
|
|
398
|
+
return null;
|
|
399
|
+
return local.resume(record, composition, parts.map((part) => part.id), published);
|
|
400
|
+
});
|
|
401
|
+
if (resumed === null || !liveness())
|
|
402
|
+
return null;
|
|
403
|
+
const parted = new Set(resumed.staged);
|
|
404
|
+
if (resumed.key === null)
|
|
405
|
+
return { record: null, staged: parted };
|
|
406
|
+
const bytes = parts.reduce((sum, part) => sum + (parted.has(part.id) ? part.bytes : 0), 0);
|
|
407
|
+
const held = {
|
|
408
|
+
...record,
|
|
409
|
+
transfer: resumed.transfer,
|
|
410
|
+
key: resumed.key,
|
|
411
|
+
done: { bytes },
|
|
412
|
+
};
|
|
413
|
+
store.installs.change(locator, (room) => ({ ...room, transfer: held }));
|
|
414
|
+
recoverReads(runtime, [locator]);
|
|
415
|
+
store.readiness.queue([locator]);
|
|
416
|
+
return { record: held, staged: parted };
|
|
417
|
+
},
|
|
418
|
+
derive: derived,
|
|
419
|
+
async refreshing(locator, key, composition) {
|
|
420
|
+
await store.exclusive(() => local.unrefresh(key));
|
|
421
|
+
return refreshingOf(runtime, local, locator, key, composition, liveness, true);
|
|
422
|
+
},
|
|
423
|
+
abandon: (locator) => store.exclusive(async () => {
|
|
424
|
+
if (liveness())
|
|
425
|
+
await abandoned(runtime, local, locator);
|
|
426
|
+
}),
|
|
427
|
+
setAside: async (locator) => {
|
|
428
|
+
if (!liveness())
|
|
429
|
+
return;
|
|
430
|
+
store.installs.change(locator, (held) => transferGone(setBack(held)));
|
|
431
|
+
recoverReads(runtime, [locator]);
|
|
432
|
+
store.readiness.queue([locator]);
|
|
433
|
+
},
|
|
434
|
+
release: (key) => store.exclusive(async () => {
|
|
435
|
+
await local.release(key);
|
|
436
|
+
sweep(runtime);
|
|
437
|
+
}),
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
export async function pullBootstrap(runtime, authorized, room, local, liveness, prior, from = runtime.socket.reads, unheld) {
|
|
441
|
+
if (!liveness())
|
|
442
|
+
return unconfirmed;
|
|
443
|
+
const { store } = runtime;
|
|
444
|
+
if (prior !== undefined) {
|
|
445
|
+
catching(store, room.locator);
|
|
446
|
+
recoverReads(runtime, [room.locator]);
|
|
447
|
+
}
|
|
448
|
+
try {
|
|
449
|
+
const result = await bootstrapRoom(from, authorized, room, {
|
|
450
|
+
collection: prior?.model ?? runtime.presence.unheldModel(room.locator) ?? NO_MODEL,
|
|
451
|
+
}, runtime.builtIn, runtime.typedPaths, (models, held) => (liveness() ? remodel(runtime, models, held) : held), liveness, staging(runtime, local, liveness, unheld));
|
|
452
|
+
if (result.kind === 'staged' &&
|
|
453
|
+
(await older(runtime, room.locator, result.record.roomVersion))) {
|
|
454
|
+
caughtUpTo(runtime, room.locator);
|
|
455
|
+
installed(runtime, room.locator);
|
|
456
|
+
await abandoned(runtime, local, room.locator);
|
|
457
|
+
return { kind: 'transport-uncertainty' };
|
|
458
|
+
}
|
|
459
|
+
if (result.kind !== 'staged') {
|
|
460
|
+
caughtUpTo(runtime, room.locator);
|
|
461
|
+
installed(runtime, room.locator);
|
|
462
|
+
}
|
|
463
|
+
return result;
|
|
464
|
+
}
|
|
465
|
+
catch (error) {
|
|
466
|
+
caughtUpTo(runtime, room.locator);
|
|
467
|
+
installed(runtime, room.locator);
|
|
468
|
+
if (refusedForSpace(error))
|
|
469
|
+
return unconfirmed;
|
|
470
|
+
throw error;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
export function publish(runtime, local, room, reached, landing, live) {
|
|
474
|
+
const { store } = runtime;
|
|
475
|
+
let published = true;
|
|
476
|
+
const landed = settle(runtime, [room.locator], async (held) => {
|
|
477
|
+
if (!live()) {
|
|
478
|
+
caughtUpTo(runtime, room.locator);
|
|
479
|
+
return [];
|
|
480
|
+
}
|
|
481
|
+
const prior = held.get(room.locator)?.replica;
|
|
482
|
+
if (!standsAt(store, room.locator, prior?.record, landing.from)) {
|
|
483
|
+
published = false;
|
|
484
|
+
if (landing.kind === 'refreshed') {
|
|
485
|
+
await local.unrefresh(reached.key);
|
|
486
|
+
return [];
|
|
487
|
+
}
|
|
488
|
+
caughtUpTo(runtime, room.locator);
|
|
489
|
+
await abandoned(runtime, local, room.locator);
|
|
490
|
+
return [];
|
|
491
|
+
}
|
|
492
|
+
const record = landing.kind === 'refreshed' && prior !== undefined
|
|
493
|
+
? {
|
|
494
|
+
...prior.record,
|
|
495
|
+
roomVersion: reached.roomVersion,
|
|
496
|
+
...(landing.remodelled ? { model: reached.model } : {}),
|
|
497
|
+
}
|
|
498
|
+
: reached;
|
|
499
|
+
return [
|
|
500
|
+
{
|
|
501
|
+
locator: room.locator,
|
|
502
|
+
record,
|
|
503
|
+
installed: landing.kind === 'refreshed'
|
|
504
|
+
? { refreshed: true }
|
|
505
|
+
: {
|
|
506
|
+
published: { from: prior?.record.key ?? null },
|
|
507
|
+
...(landing.refreshed ? { refreshed: true } : {}),
|
|
508
|
+
},
|
|
509
|
+
after() {
|
|
510
|
+
runtime.presence.installed(room.locator, landing.kind === 'bootstrapped');
|
|
511
|
+
runtime.retries.succeeded('download', room.locator);
|
|
512
|
+
store.prepareAgain(room.locator);
|
|
513
|
+
if (landing.kind === 'bootstrapped') {
|
|
514
|
+
store.installs.change(room.locator, (held) => ({
|
|
515
|
+
...transferGone(held),
|
|
516
|
+
highest: null,
|
|
517
|
+
beyondHorizon: false,
|
|
518
|
+
startedOver: null,
|
|
519
|
+
catching: false,
|
|
520
|
+
}));
|
|
521
|
+
if (prior !== undefined && prior.record.key !== record.key)
|
|
522
|
+
sweep(runtime);
|
|
523
|
+
void name(runtime, room.locator);
|
|
524
|
+
}
|
|
525
|
+
},
|
|
526
|
+
},
|
|
527
|
+
];
|
|
528
|
+
}).then(() => published, (error) => {
|
|
529
|
+
if (!refusedForSpace(error))
|
|
530
|
+
throw error;
|
|
531
|
+
caughtUpTo(runtime, room.locator);
|
|
532
|
+
return published;
|
|
533
|
+
});
|
|
534
|
+
return landing.kind === 'refreshed'
|
|
535
|
+
? landed
|
|
536
|
+
: landed.finally(() => installed(runtime, room.locator));
|
|
537
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Runtime } from './runtime.js';
|
|
2
|
+
export declare function scheduleCurrency(runtime: Runtime): void;
|
|
3
|
+
export declare function spaceFreed(runtime: Runtime): void;
|
|
4
|
+
export declare function close({ store, socket, presence, conversations, recovery, liveQueries, figures, }: Runtime): void;
|
|
5
|
+
export declare function stop(runtime: Runtime): Promise<void>;
|
|
6
|
+
export declare function start(runtime: Runtime, signal: AbortSignal | undefined): void;
|
|
7
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAoO5C,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,QAOhD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,QAQ1C;AAED,wBAAgB,KAAK,CAAC,EACpB,KAAK,EACL,MAAM,EACN,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,WAAW,EACX,OAAO,GACR,EAAE,OAAO,QAST;AAED,wBAAsB,IAAI,CAAC,OAAO,EAAE,OAAO,iBAS1C;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,SAAS,QA2CtE"}
|