@agentshouse/mdruntime 0.1.0-cf04ede9fb796 → 0.1.0-cf08ada271a7f
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 +0 -3
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +51 -131
- package/dist/actions.js +2 -2
- package/dist/adapter.d.ts +16 -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 -19
- 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/client.d.ts +3 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +6 -4
- 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.map +1 -1
- package/dist/compile.js +15 -21
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +13 -13
- package/dist/conversation-live.d.ts +3 -4
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +2 -3
- package/dist/conversation.d.ts +4 -6
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +43 -71
- 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.map +1 -1
- package/dist/discovery.js +5 -3
- 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/host.d.ts +17 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +16 -4
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/install.d.ts +0 -1
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +46 -59
- package/dist/job.d.ts +1 -29
- package/dist/job.d.ts.map +1 -1
- package/dist/job.js +2 -49
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +9 -6
- package/dist/listing.d.ts +4 -4
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +15 -22
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +3 -3
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +2 -1
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +3 -3
- package/dist/media.d.ts +1 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +3 -3
- package/dist/memory.d.ts +4 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +8 -6
- package/dist/messages.d.ts +0 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +9 -29
- 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 +4 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +101 -126
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +12 -17
- package/dist/opened.js +3 -3
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +6 -4
- package/dist/overlay.d.ts +2 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +32 -21
- package/dist/parts.d.ts +3 -52
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +15 -120
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +12 -5
- package/dist/queries.js +1 -1
- package/dist/query.d.ts +0 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.js +1 -1
- package/dist/queue.d.ts +39 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +455 -0
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +5 -4
- package/dist/react.d.ts +4 -0
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +10 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +4 -1
- package/dist/refresh.js +2 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +3 -2
- package/dist/replica.d.ts +5 -11
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +13 -15
- 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.map +1 -1
- package/dist/room-drafts.js +17 -16
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +3 -4
- package/dist/runtime.d.ts +5 -16
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +41 -90
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +233 -116
- package/dist/saves.d.ts +2 -40
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +102 -697
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +0 -1
- package/dist/shared.d.ts +0 -5
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +4 -90
- package/dist/shown.d.ts +2 -1
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +15 -11
- package/dist/socket/rooms.d.ts +1 -4
- package/dist/socket/rooms.d.ts.map +1 -1
- package/dist/socket/session.d.ts +0 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket.d.ts +0 -1
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +2 -2
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +5 -4
- package/dist/store/records.d.ts +1 -3
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +2 -5
- package/dist/store/space.d.ts +1 -1
- package/dist/store/space.d.ts.map +1 -1
- package/dist/store/space.js +0 -2
- package/dist/store/watchers.js +1 -2
- package/dist/store.d.ts +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +1 -1
- package/dist/stored.d.ts +1 -1
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +6 -6
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +4 -3
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +25 -27
- package/dist/tables.d.ts +0 -5
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +8 -11
- package/dist/tallies.js +5 -5
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +2 -2
- package/dist/wire.d.ts +4 -4
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +3 -3
- package/package.json +3 -2
package/dist/queue.js
ADDED
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import { changeSet, mergeChangeSets } from './change-set.js';
|
|
2
|
+
import { leaving as leavingIn, partnerOf } from './change.js';
|
|
3
|
+
import { composedOf, definitionsAt } from './collection.js';
|
|
4
|
+
import { runtimeError } from './failure.js';
|
|
5
|
+
import { roomDraftRevision } from './identity.js';
|
|
6
|
+
import { landed, movedBy, overlayOf, replaying, slicing, slicingWith, standing, storedRecord, touchedBy, } from './replica.js';
|
|
7
|
+
import { returnedBy, returnedInto } from './room-draft.js';
|
|
8
|
+
import { documentKey } from './rows.js';
|
|
9
|
+
import { stepped } from './turn.js';
|
|
10
|
+
export function withdrawable(states) {
|
|
11
|
+
return (batch) => {
|
|
12
|
+
const state = states.get(batch.id);
|
|
13
|
+
return state !== undefined && state.submission.state !== 'submitted' && !state.lost;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export async function sliceAt(store, record, view, queue, extra = [], moved = []) {
|
|
17
|
+
const local = await store.open();
|
|
18
|
+
const needed = new Set([...touchedBy(queue), ...extra]);
|
|
19
|
+
const movedPaths = [...new Set([...movedBy(queue, record.locator), ...moved])];
|
|
20
|
+
if (movedPaths.length > 0) {
|
|
21
|
+
for (const { path } of await local.referrers(record.key, view, movedPaths)) {
|
|
22
|
+
needed.add(path);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const paths = [...needed];
|
|
26
|
+
return stepped(slicing(await local.entries(record.key, view, paths), paths));
|
|
27
|
+
}
|
|
28
|
+
async function landedWhole(store, record, batch, confirmedLayer, current) {
|
|
29
|
+
if (!landed(batch, confirmedLayer, store.composed(record), current))
|
|
30
|
+
return false;
|
|
31
|
+
const partner = partnerOf(batch, record.locator);
|
|
32
|
+
if (partner === null)
|
|
33
|
+
return true;
|
|
34
|
+
const other = await store.replica(partner);
|
|
35
|
+
const half = other?.queue.find((one) => one.id === batch.id);
|
|
36
|
+
if (other === undefined || half === undefined)
|
|
37
|
+
return false;
|
|
38
|
+
return landed(half, await sliceAt(store, other.record, 'confirmed', [half]), store.composed(other.record));
|
|
39
|
+
}
|
|
40
|
+
async function returnedDrafts(store, locator, work, leaving, composition) {
|
|
41
|
+
const written = new Map();
|
|
42
|
+
for (const { batch, returned } of leaving) {
|
|
43
|
+
if (returned === null || batch.between?.destination.room === locator)
|
|
44
|
+
continue;
|
|
45
|
+
for (const saved of work.states.get(batch.id)?.drafts ?? []) {
|
|
46
|
+
const existing = written.get(saved.path) ?? (await store.draft(locator, saved.path));
|
|
47
|
+
written.set(saved.path, {
|
|
48
|
+
locator,
|
|
49
|
+
path: saved.path,
|
|
50
|
+
revision: roomDraftRevision(),
|
|
51
|
+
parts: returnedInto(existing?.parts, saved.parts, composition === undefined ? undefined : definitionsAt(composition, saved.path)),
|
|
52
|
+
returned,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return written;
|
|
57
|
+
}
|
|
58
|
+
async function carriedBack(store, locator, unlanded, written) {
|
|
59
|
+
const back = new Map();
|
|
60
|
+
const taken = [];
|
|
61
|
+
for (const batch of unlanded) {
|
|
62
|
+
const between = batch.between;
|
|
63
|
+
if (between === undefined)
|
|
64
|
+
continue;
|
|
65
|
+
const source = between.source.room;
|
|
66
|
+
const destination = between.destination.room;
|
|
67
|
+
const local = await store.open();
|
|
68
|
+
const arrived = (await local.pending(destination, batch.id)).state?.drafts ?? [];
|
|
69
|
+
for (const { path: to } of arrived) {
|
|
70
|
+
const record = await store.draft(destination, to);
|
|
71
|
+
const path = between.moves.find((move) => move.to === to)?.path;
|
|
72
|
+
if (record === undefined || path === undefined)
|
|
73
|
+
continue;
|
|
74
|
+
const [into, key] = source === locator ? [written, path] : [back, documentKey(source, path)];
|
|
75
|
+
const existing = into.get(key) ?? (await store.draft(source, path));
|
|
76
|
+
const held = await store.record(source);
|
|
77
|
+
taken.push({ locator: destination, path: to });
|
|
78
|
+
into.set(key, {
|
|
79
|
+
locator: source,
|
|
80
|
+
path,
|
|
81
|
+
revision: roomDraftRevision(),
|
|
82
|
+
parts: returnedInto(existing?.parts, record.parts, held === undefined ? undefined : definitionsAt(store.composed(held), path)),
|
|
83
|
+
returned: existing?.returned ?? null,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const records = [...back.values()];
|
|
88
|
+
const elsewhere = taken.filter((one) => one.locator !== locator);
|
|
89
|
+
const rooms = new Set([...records, ...elsewhere].map((one) => one.locator));
|
|
90
|
+
return {
|
|
91
|
+
taken: taken.filter((one) => one.locator === locator).map(({ path }) => path),
|
|
92
|
+
writes: [...rooms].map((room) => ({
|
|
93
|
+
locator: room,
|
|
94
|
+
roomDrafts: records.filter((record) => record.locator === room),
|
|
95
|
+
consumedRoomDrafts: elsewhere.filter((one) => one.locator === room).map(({ path }) => path),
|
|
96
|
+
})),
|
|
97
|
+
changes: [...rooms].map((room) => changeSet(room, {
|
|
98
|
+
drafts: [...records, ...elsewhere]
|
|
99
|
+
.filter((one) => one.locator === room)
|
|
100
|
+
.map(({ path }) => path),
|
|
101
|
+
})),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function confirmedAgain(store, locator) {
|
|
105
|
+
store.installs.change(locator, (held) => ({
|
|
106
|
+
...held,
|
|
107
|
+
confirmations: held.confirmations + 1,
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
function replayed(store, record, confirmedLayer, queue) {
|
|
111
|
+
return stepped(replaying(confirmedLayer, queue, record.locator, store.composed(record)));
|
|
112
|
+
}
|
|
113
|
+
async function overlayDiff(record, before, visible, touched) {
|
|
114
|
+
const kept = before !== undefined && before.record.key === record.key ? before.overlaid : new Set();
|
|
115
|
+
return {
|
|
116
|
+
overlay: {
|
|
117
|
+
set: await stepped(overlayOf(visible, touched)),
|
|
118
|
+
cleared: [...kept].filter((path) => !touched.has(path)),
|
|
119
|
+
},
|
|
120
|
+
touched,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function unsent(state, batch, locator) {
|
|
124
|
+
if (state === undefined)
|
|
125
|
+
return false;
|
|
126
|
+
return !leavingIn(batch, locator) || withdrawable(new Map([[batch.id, state]]))(batch);
|
|
127
|
+
}
|
|
128
|
+
async function together(runtime, local, settlements) {
|
|
129
|
+
const settled = new Set(settlements.map(({ locator }) => locator));
|
|
130
|
+
const all = [...settlements];
|
|
131
|
+
for (let wave = settlements; wave.length > 0;) {
|
|
132
|
+
const partnered = new Map();
|
|
133
|
+
for (const { locator, left } of wave) {
|
|
134
|
+
for (const batch of left) {
|
|
135
|
+
const partner = partnerOf(batch, locator);
|
|
136
|
+
if (partner === null ||
|
|
137
|
+
settled.has(partner) ||
|
|
138
|
+
!unsent((await local.pending(partner, batch.id)).state, batch, partner)) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
partnered.set(partner, [...(partnered.get(partner) ?? []), batch]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const partners = [];
|
|
145
|
+
for (const [partner, batches] of partnered) {
|
|
146
|
+
settled.add(partner);
|
|
147
|
+
partners.push(await unpairing(runtime, local, partner, batches));
|
|
148
|
+
}
|
|
149
|
+
all.push(...partners);
|
|
150
|
+
wave = partners;
|
|
151
|
+
}
|
|
152
|
+
const answer = await local.commit({
|
|
153
|
+
rooms: all.flatMap(({ commit }) => commit.rooms),
|
|
154
|
+
writes: all.flatMap(({ commit }) => commit.writes),
|
|
155
|
+
});
|
|
156
|
+
return mergeChangeSets(all.map((one) => one.apply(answer)));
|
|
157
|
+
}
|
|
158
|
+
async function settlement(runtime, local, locator, work, record, queue, settling = {}) {
|
|
159
|
+
const { store, journal, localSaves } = runtime;
|
|
160
|
+
const before = work.replica;
|
|
161
|
+
const view = settling.view ?? 'confirmed';
|
|
162
|
+
const previousQueue = work.queue;
|
|
163
|
+
const overrides = settling.changes;
|
|
164
|
+
const read = await sliceAt(store, record, view, queue, [
|
|
165
|
+
...(before !== undefined && before.record.key === record.key ? before.overlaid : []),
|
|
166
|
+
...(overrides?.set.map(({ path }) => path) ?? []),
|
|
167
|
+
...(overrides?.removed ?? []),
|
|
168
|
+
]);
|
|
169
|
+
const confirmedLayer = overrides === undefined
|
|
170
|
+
? read
|
|
171
|
+
: await stepped(slicingWith(read, overrides.set, overrides.removed));
|
|
172
|
+
const composition = store.composed(record);
|
|
173
|
+
const shown = queue.filter((batch) => {
|
|
174
|
+
const held = store.landed.of(locator, batch.id);
|
|
175
|
+
return (held !== undefined &&
|
|
176
|
+
Object.entries(held).some(([path, revision]) => confirmedLayer.revisions[path] !== revision));
|
|
177
|
+
});
|
|
178
|
+
const unshown = queue.filter((batch) => !shown.includes(batch));
|
|
179
|
+
const { withdrawn, kept } = await stepped(standing(confirmedLayer, unshown, withdrawable(work.states), localSaves, locator, composition));
|
|
180
|
+
const founded = kept.filter((batch) => !unshown.includes(batch));
|
|
181
|
+
const queueChanged = kept.length !== previousQueue.length || founded.length > 0;
|
|
182
|
+
const unqueued = shown.map((batch) => ({ batch, landed: true }));
|
|
183
|
+
for (const batch of withdrawn) {
|
|
184
|
+
unqueued.push({ batch, landed: await landedWhole(store, record, batch, confirmedLayer) });
|
|
185
|
+
}
|
|
186
|
+
const returning = [
|
|
187
|
+
...[...unqueued].reverse().map(({ batch, landed: held }) => ({
|
|
188
|
+
batch,
|
|
189
|
+
returned: localSaves || held ? null : returnedBy(),
|
|
190
|
+
})),
|
|
191
|
+
...(settling.leaving ?? []),
|
|
192
|
+
];
|
|
193
|
+
const written = await returnedDrafts(store, locator, work, returning, composition);
|
|
194
|
+
const carried = await carriedBack(store, locator, [
|
|
195
|
+
...[...unqueued].reverse().flatMap(({ batch, landed: held }) => (held ? [] : [batch])),
|
|
196
|
+
...(settling.leaving ?? []).flatMap(({ batch, returned }) => returned === null ? [] : [batch]),
|
|
197
|
+
], written);
|
|
198
|
+
const replayedLayer = await replayed(store, record, confirmedLayer, kept);
|
|
199
|
+
const { overlay } = await overlayDiff(record, before, replayedLayer.visible, replayedLayer.touched);
|
|
200
|
+
const commit = {
|
|
201
|
+
rooms: [
|
|
202
|
+
{
|
|
203
|
+
locator,
|
|
204
|
+
key: record.key,
|
|
205
|
+
record: storedRecord(record),
|
|
206
|
+
roots: record.declaration.typedSelection?.roots ?? [],
|
|
207
|
+
composed: composedOf(composition),
|
|
208
|
+
...settling.commit,
|
|
209
|
+
...(overrides === undefined
|
|
210
|
+
? {}
|
|
211
|
+
: { confirmed: { set: overrides.set, removed: overrides.removed } }),
|
|
212
|
+
overlay,
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
writes: [
|
|
216
|
+
{
|
|
217
|
+
locator,
|
|
218
|
+
queue: kept,
|
|
219
|
+
stored: previousQueue,
|
|
220
|
+
founded,
|
|
221
|
+
roomDrafts: [...written.values()],
|
|
222
|
+
consumedRoomDrafts: carried.taken,
|
|
223
|
+
},
|
|
224
|
+
...carried.writes,
|
|
225
|
+
],
|
|
226
|
+
};
|
|
227
|
+
const staying = new Set(kept.map((batch) => batch.id));
|
|
228
|
+
return {
|
|
229
|
+
locator,
|
|
230
|
+
left: previousQueue.filter((batch) => !staying.has(batch.id)),
|
|
231
|
+
commit,
|
|
232
|
+
apply: (answer) => {
|
|
233
|
+
for (const batch of previousQueue) {
|
|
234
|
+
if (!staying.has(batch.id))
|
|
235
|
+
store.landed.drop(locator, batch.id);
|
|
236
|
+
}
|
|
237
|
+
const drafts = [...written.keys(), ...carried.taken];
|
|
238
|
+
for (const { batch, landed: held } of unqueued) {
|
|
239
|
+
const outcome = localSaves ? 'dropped' : held ? 'landed' : 'withdrawn';
|
|
240
|
+
journal.record(`outcome ${locator} ${batch.id} ${outcome}`);
|
|
241
|
+
}
|
|
242
|
+
const changed = answer.changed[locator];
|
|
243
|
+
if (settling.commit?.published !== undefined ||
|
|
244
|
+
settling.commit?.refreshed === true ||
|
|
245
|
+
overrides !== undefined) {
|
|
246
|
+
confirmedAgain(store, locator);
|
|
247
|
+
}
|
|
248
|
+
return mergeChangeSets([
|
|
249
|
+
changeSet(locator, {
|
|
250
|
+
documents: changed === undefined ? [] : changed,
|
|
251
|
+
room: settling.room,
|
|
252
|
+
queue: queueChanged,
|
|
253
|
+
drafts,
|
|
254
|
+
unindexed: answer.indexed[locator] === false,
|
|
255
|
+
due: kept.length > 0 && settling.refused !== true,
|
|
256
|
+
}),
|
|
257
|
+
...carried.changes,
|
|
258
|
+
]);
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
async function unpairing(runtime, local, locator, batches) {
|
|
263
|
+
const { store, journal, localSaves } = runtime;
|
|
264
|
+
const ids = new Set(batches.map(({ id }) => id));
|
|
265
|
+
const leaving = batches.map((batch) => ({
|
|
266
|
+
batch,
|
|
267
|
+
returned: !localSaves && leavingIn(batch, locator) ? returnedBy() : null,
|
|
268
|
+
}));
|
|
269
|
+
const outcome = localSaves ? 'dropped' : 'unpaired';
|
|
270
|
+
const work = await store.work(locator);
|
|
271
|
+
const current = work.replica;
|
|
272
|
+
if (current !== undefined) {
|
|
273
|
+
const settled = await settlement(runtime, local, locator, work, current.record, current.queue.filter((one) => !ids.has(one.id)), { leaving });
|
|
274
|
+
return {
|
|
275
|
+
...settled,
|
|
276
|
+
apply(answer) {
|
|
277
|
+
for (const batch of batches)
|
|
278
|
+
journal.record(`outcome ${locator} ${batch.id} ${outcome}`);
|
|
279
|
+
return settled.apply(answer);
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
const queue = work.queue.filter((one) => !ids.has(one.id));
|
|
284
|
+
const written = await returnedDrafts(store, locator, work, leaving, undefined);
|
|
285
|
+
const carried = await carriedBack(store, locator, leaving.flatMap(({ batch, returned }) => (returned === null ? [] : [batch])), written);
|
|
286
|
+
return {
|
|
287
|
+
locator,
|
|
288
|
+
left: batches,
|
|
289
|
+
commit: {
|
|
290
|
+
rooms: [],
|
|
291
|
+
writes: [
|
|
292
|
+
{
|
|
293
|
+
locator,
|
|
294
|
+
queue,
|
|
295
|
+
stored: work.queue,
|
|
296
|
+
roomDrafts: [...written.values()],
|
|
297
|
+
consumedRoomDrafts: carried.taken,
|
|
298
|
+
},
|
|
299
|
+
...carried.writes,
|
|
300
|
+
],
|
|
301
|
+
},
|
|
302
|
+
apply() {
|
|
303
|
+
for (const batch of batches)
|
|
304
|
+
journal.record(`outcome ${locator} ${batch.id} ${outcome}`);
|
|
305
|
+
return mergeChangeSets([
|
|
306
|
+
changeSet(locator, {
|
|
307
|
+
queue: true,
|
|
308
|
+
drafts: [...written.keys(), ...carried.taken],
|
|
309
|
+
due: queue.length > 0,
|
|
310
|
+
}),
|
|
311
|
+
...carried.changes,
|
|
312
|
+
]);
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
async function orphaned(local) {
|
|
317
|
+
const { queued, moving } = await local.moving();
|
|
318
|
+
const halves = new Map();
|
|
319
|
+
for (const { locator, batch, state } of moving) {
|
|
320
|
+
const partner = partnerOf(batch, locator);
|
|
321
|
+
if (partner === null || queued.get(partner)?.includes(batch.id) === true)
|
|
322
|
+
continue;
|
|
323
|
+
if (unsent(state, batch, locator))
|
|
324
|
+
halves.set(locator, [...(halves.get(locator) ?? []), batch]);
|
|
325
|
+
}
|
|
326
|
+
return halves;
|
|
327
|
+
}
|
|
328
|
+
async function sweep(runtime, local) {
|
|
329
|
+
if (!runtime.socket.continuing())
|
|
330
|
+
return;
|
|
331
|
+
const halves = await orphaned(local);
|
|
332
|
+
if (halves.size === 0)
|
|
333
|
+
return;
|
|
334
|
+
const settlements = [];
|
|
335
|
+
for (const [locator, batches] of halves) {
|
|
336
|
+
settlements.push(await unpairing(runtime, local, locator, batches));
|
|
337
|
+
}
|
|
338
|
+
void runtime.store.changed(await together(runtime, local, settlements));
|
|
339
|
+
}
|
|
340
|
+
async function settled(runtime, local, settlements, steps) {
|
|
341
|
+
const set = await together(runtime, local, settlements);
|
|
342
|
+
for (const step of steps)
|
|
343
|
+
step();
|
|
344
|
+
void runtime.store.changed(set);
|
|
345
|
+
await sweep(runtime, local);
|
|
346
|
+
}
|
|
347
|
+
export function settle(runtime, locators, decide) {
|
|
348
|
+
const { store } = runtime;
|
|
349
|
+
return store.exclusive(async () => {
|
|
350
|
+
const local = await store.open();
|
|
351
|
+
const held = new Map();
|
|
352
|
+
for (const locator of locators)
|
|
353
|
+
held.set(locator, await store.work(locator));
|
|
354
|
+
const decided = await decide(held);
|
|
355
|
+
if (decided.length === 0)
|
|
356
|
+
return;
|
|
357
|
+
const settlements = [];
|
|
358
|
+
for (const { locator, record, accepted, adopted, installed, refused } of decided) {
|
|
359
|
+
const work = held.get(locator) ?? (await store.work(locator));
|
|
360
|
+
settlements.push(await settlement(runtime, local, locator, work, record, work.queue.filter((batch) => batch.id !== accepted), {
|
|
361
|
+
room: true,
|
|
362
|
+
view: installed?.refreshed === true ? 'refreshed' : 'confirmed',
|
|
363
|
+
...(installed === undefined ? {} : { commit: installed }),
|
|
364
|
+
...(adopted === undefined ? {} : { changes: adopted }),
|
|
365
|
+
...(refused === undefined ? {} : { refused }),
|
|
366
|
+
}));
|
|
367
|
+
}
|
|
368
|
+
await settled(runtime, local, settlements, decided.flatMap(({ after }) => (after === undefined ? [] : [after])));
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
export function answered(runtime, locator, head, answer) {
|
|
372
|
+
const { store, socket } = runtime;
|
|
373
|
+
return store.exclusive(async () => {
|
|
374
|
+
if (!socket.continuing())
|
|
375
|
+
return;
|
|
376
|
+
const local = await store.open();
|
|
377
|
+
const work = await store.work(locator);
|
|
378
|
+
const current = work.replica;
|
|
379
|
+
if (current === undefined || !current.queue.some((batch) => batch.id === head.id))
|
|
380
|
+
return;
|
|
381
|
+
const confirmedLayer = await sliceAt(store, current.record, 'confirmed', [head]);
|
|
382
|
+
const held = answer.kind === 'conflicted' &&
|
|
383
|
+
(await landedWhole(store, current.record, head, confirmedLayer, answer.affected));
|
|
384
|
+
if (held &&
|
|
385
|
+
partnerOf(head, locator) === null &&
|
|
386
|
+
!landed(head, confirmedLayer, store.composed(current.record))) {
|
|
387
|
+
store.landed.hold(locator, head.id, Object.fromEntries([...touchedBy([head])].map((path) => [path, confirmedLayer.revisions[path]])));
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
const returned = {
|
|
391
|
+
kind: answer.kind,
|
|
392
|
+
code: answer.code,
|
|
393
|
+
fields: answer.fields,
|
|
394
|
+
retryable: answer.retryable,
|
|
395
|
+
};
|
|
396
|
+
await settled(runtime, local, [
|
|
397
|
+
await settlement(runtime, local, locator, work, current.record, current.queue.filter((batch) => batch.id !== head.id), { leaving: [{ batch: head, returned: held ? null : returned }] }),
|
|
398
|
+
], []);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
export function unpair(runtime) {
|
|
402
|
+
return runtime.store.durably((local) => sweep(runtime, local));
|
|
403
|
+
}
|
|
404
|
+
export async function append(runtime, appending) {
|
|
405
|
+
const { plan, files, held, after } = appending;
|
|
406
|
+
if (plan.kind === 'refused')
|
|
407
|
+
return { outcome: 'refused', ...plan.refusal };
|
|
408
|
+
const { store } = runtime;
|
|
409
|
+
const local = await store.open();
|
|
410
|
+
const rooms = [];
|
|
411
|
+
const writes = [];
|
|
412
|
+
for (const { locator, queue, saved, consumed, carried } of plan.rooms) {
|
|
413
|
+
const { replica, confirmed } = held.get(locator);
|
|
414
|
+
const { record } = replica;
|
|
415
|
+
const replayedLayer = await replayed(store, record, confirmed, queue);
|
|
416
|
+
const { overlay } = await overlayDiff(record, replica, replayedLayer.visible, replayedLayer.touched);
|
|
417
|
+
rooms.push({
|
|
418
|
+
locator,
|
|
419
|
+
key: record.key,
|
|
420
|
+
roots: record.declaration.typedSelection?.roots ?? [],
|
|
421
|
+
composed: composedOf(store.composed(record)),
|
|
422
|
+
overlay,
|
|
423
|
+
});
|
|
424
|
+
writes.push({
|
|
425
|
+
locator,
|
|
426
|
+
queue,
|
|
427
|
+
stored: replica.queue,
|
|
428
|
+
saved,
|
|
429
|
+
consumedRoomDrafts: consumed,
|
|
430
|
+
roomDrafts: carried,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
let answer;
|
|
434
|
+
try {
|
|
435
|
+
answer = await local.commit({ rooms, writes, files, whole: true });
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
return { outcome: 'refused', code: 'durable-write', retryable: true };
|
|
439
|
+
}
|
|
440
|
+
const lost = answer.fenced ?? plan.rooms.find(({ locator }) => store.fences.has(locator))?.locator;
|
|
441
|
+
if (lost !== undefined)
|
|
442
|
+
throw runtimeError('unknown-room', `Unknown Room ${lost}`);
|
|
443
|
+
const [saving] = plan.rooms;
|
|
444
|
+
await Promise.all([
|
|
445
|
+
store.changed(mergeChangeSets(plan.rooms.map(({ locator, consumed, carried }) => changeSet(locator, {
|
|
446
|
+
documents: answer.changed[locator] ?? [],
|
|
447
|
+
queue: true,
|
|
448
|
+
drafts: [...consumed, ...carried.map(({ path }) => path)],
|
|
449
|
+
unindexed: answer.indexed[locator] === false,
|
|
450
|
+
due: locator === saving?.locator,
|
|
451
|
+
})))),
|
|
452
|
+
after?.(),
|
|
453
|
+
]);
|
|
454
|
+
return { outcome: 'saved', identifier: plan.identifier };
|
|
455
|
+
}
|
package/dist/reach.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reach.d.ts","sourceRoot":"","sources":["../src/reach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK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AAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC3C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IAC1F,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;CACrD,CAAC;AAsCF,wBAAgB,KAAK,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAMpE;AAMD,wBAAgB,OAAO,CACrB,KAAK,EAAE,SAAS,GAAG,IAAI,EACvB,IAAI,EAAE;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,cAAc,EAAE;QAAE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,GAAG,IAAI,CAAA;CAAE,GAC/F;IAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAS/D;AAeD,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAcnE;AA2GD,wBAAgB,QAAQ,CACtB,OAAO,EAAE,SAAS,EAClB,KAAK,EAAE,SAAS,GAAG,IAAI,EACvB,IAAI,EAAE,aAAa,GAClB,YAAY,CA8Xd"}
|
package/dist/reach.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { selected } from './collection.js';
|
|
1
2
|
import { unheldView } from './conversation.js';
|
|
2
3
|
import { modelTypes, NO_MODEL } from './model.js';
|
|
3
4
|
import { changeOf, digestApplied, digestOf, observing, } from './observation.js';
|
|
4
|
-
import { runtimeError } from './failure.js';
|
|
5
|
+
import { runtimeError, uncaught } from './failure.js';
|
|
5
6
|
import { failure, lockedRoom, ROOM_LOCKED, undeclared, UNREADABLE, } from './outcome.js';
|
|
6
7
|
import { beneath } from './paths.js';
|
|
7
8
|
import { moveTarget, readParts, staleWrite, } from './room-draft.js';
|
|
@@ -45,11 +46,11 @@ export function governs(reach, room) {
|
|
|
45
46
|
if (wholly(reach, room.locator)) {
|
|
46
47
|
return { collection: true, selection: room.typedSelection !== null };
|
|
47
48
|
}
|
|
48
|
-
const
|
|
49
|
+
const within = (path) => selected({ selection: room.typedSelection }, path);
|
|
49
50
|
const paths = reach.documents
|
|
50
51
|
.filter((document) => document.room === room.locator)
|
|
51
52
|
.map(({ path }) => path);
|
|
52
|
-
return { collection: paths.some((path) => !
|
|
53
|
+
return { collection: paths.some((path) => !within(path)), selection: paths.some(within) };
|
|
53
54
|
}
|
|
54
55
|
function covers(reach, room, path) {
|
|
55
56
|
return (reach === null ||
|
|
@@ -190,7 +191,7 @@ export function narrowed(runtime, given, port) {
|
|
|
190
191
|
shown = shown.then(() => making.then((value) => {
|
|
191
192
|
if (open)
|
|
192
193
|
deliver(value);
|
|
193
|
-
},
|
|
194
|
+
}, uncaught), uncaught);
|
|
194
195
|
},
|
|
195
196
|
stop() {
|
|
196
197
|
open = false;
|
package/dist/react.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { ConversationAgent, ConversationEntry, ConversationOptions, Convers
|
|
|
8
8
|
import { type RuntimeError } from './failure.js';
|
|
9
9
|
import type { FiguresResult } from './figures.js';
|
|
10
10
|
import type { Holdings } from './holdings.js';
|
|
11
|
+
import type { Expecting } from './expectation.js';
|
|
11
12
|
import type { QueueEntry } from './outcome.js';
|
|
12
13
|
import type { DocumentResult, GroupResult, PendingResult } from './query.js';
|
|
13
14
|
import type { Readiness } from './readiness.js';
|
|
@@ -39,6 +40,9 @@ export declare function useObserve(client: Client, topic: 'conversations'): Obse
|
|
|
39
40
|
export declare function useObserve(client: Client, topic: 'agents'): Observed<readonly ConversationAgent[]>;
|
|
40
41
|
export declare function useObserve(client: Client, topic: 'figures'): Observed<FiguresResult>;
|
|
41
42
|
export declare function useObserve(client: Client, topic: 'holdings'): Observed<Holdings>;
|
|
43
|
+
export declare function useReading<E extends {
|
|
44
|
+
readonly key: string;
|
|
45
|
+
}>(store: Pick<Expecting<E>, 'reads' | 'heard' | 'left'>, asks: (one: E) => boolean, shown: ((one: E) => boolean) | null): void;
|
|
42
46
|
export type Saving = {
|
|
43
47
|
readonly busy: boolean;
|
|
44
48
|
readonly outcome: SaveResult | null;
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAU,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK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G,IAAI,GAClC,IAAI,CAON;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IACtC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACpF,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,cAAc,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACvF,CAAC;AAMF,wBAAgB,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CA8BvD"}
|
package/dist/react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
1
|
+
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
|
|
2
2
|
import { failed } from './failure.js';
|
|
3
3
|
const LOADING = { state: 'loading' };
|
|
4
4
|
export function useObserve(client, topic, ...input) {
|
|
@@ -32,6 +32,15 @@ export function useObserve(client, topic, ...input) {
|
|
|
32
32
|
}, [client, key]);
|
|
33
33
|
return held !== null && held.client === client && held.key === key ? held.observed : LOADING;
|
|
34
34
|
}
|
|
35
|
+
export function useReading(store, asks, shown) {
|
|
36
|
+
const reader = useId();
|
|
37
|
+
useLayoutEffect(() => store.reads(reader, asks), [store, reader, asks]);
|
|
38
|
+
useLayoutEffect(() => () => store.left(reader), [store, reader]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (shown !== null)
|
|
41
|
+
store.heard(reader, shown);
|
|
42
|
+
}, [store, reader, shown]);
|
|
43
|
+
}
|
|
35
44
|
const IDLE = { busy: false, outcome: null, failure: null };
|
|
36
45
|
export function useSave(client) {
|
|
37
46
|
const [state, setState] = useState(IDLE);
|
package/dist/reads.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reads.d.ts","sourceRoot":"","sources":["../src/reads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reads.d.ts","sourceRoot":"","sources":["../src/reads.ts"],"names":[],"mappings":"AAEA,OAAO,EAA6B,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE/D,eAAO,MAAM,WAAW,EAAE,SAAS,MAAM,EAExC,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACvF,KAAK,IAAI,IAAI,CAAC;IACd,QAAQ,IAAI,IAAI,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACxD,MAAM,IAAI,OAAO,CAAC;IAClB,SAAS,IAAI,OAAO,CAAC;IACrB,MAAM,IAAI,OAAO,CAAC;IAClB,IAAI,IAAI,OAAO,CAAC;IAChB,MAAM,IAAI,IAAI,CAAC;CAChB,CAAC;AAeF,wBAAgB,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMhG;AAED,wBAAgB,QAAQ,CACtB,UAAU,EAAE,UAAU,EACtB,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,MAAM,EAC9B,MAAM,EAAE,MAAM,GACb,IAAI,CAMN;AAED,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAGvF;AAMD,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAoJpE"}
|
package/dist/reads.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { refusedForSpace } from './durability.js';
|
|
2
|
+
import { uncaught } from './failure.js';
|
|
2
3
|
import { answeredResult, UNCERTAIN } from './outcome.js';
|
|
3
4
|
export const READ_TABLES = [
|
|
4
5
|
'CREATE TABLE read_answers (name TEXT NOT NULL, input TEXT NOT NULL, build TEXT NOT NULL, answer TEXT NOT NULL, PRIMARY KEY (name, input)) WITHOUT ROWID',
|
|
@@ -37,6 +38,8 @@ export function readAnswers(options) {
|
|
|
37
38
|
await database.ask({ kind: 'read.keep', ...read.at, answer }).catch((error) => {
|
|
38
39
|
if (refusedForSpace(error))
|
|
39
40
|
options.filled();
|
|
41
|
+
else
|
|
42
|
+
uncaught(error);
|
|
40
43
|
});
|
|
41
44
|
}
|
|
42
45
|
async function asked(read, led) {
|
|
@@ -121,7 +124,7 @@ export function readAnswers(options) {
|
|
|
121
124
|
return;
|
|
122
125
|
read.text = text;
|
|
123
126
|
read.shown = { ...read.shown, answer: JSON.parse(text) };
|
|
124
|
-
},
|
|
127
|
+
}, uncaught);
|
|
125
128
|
}
|
|
126
129
|
reads.set(key, read);
|
|
127
130
|
return read;
|
package/dist/refresh.js
CHANGED
|
@@ -129,7 +129,7 @@ export async function advancement(refresh, authorization, held, remodel, continu
|
|
|
129
129
|
return unconfirmed;
|
|
130
130
|
const first = await refresh(authorization, {
|
|
131
131
|
locator,
|
|
132
|
-
selection: held.replica.selection,
|
|
132
|
+
selection: held.declaration.replica.selection,
|
|
133
133
|
fromRoomVersion,
|
|
134
134
|
});
|
|
135
135
|
if (first.kind !== 'net-advancement')
|
|
@@ -154,7 +154,7 @@ export async function advancement(refresh, authorization, held, remodel, continu
|
|
|
154
154
|
return unconfirmed;
|
|
155
155
|
const page = await refresh(authorization, {
|
|
156
156
|
locator,
|
|
157
|
-
selection: held.replica.selection,
|
|
157
|
+
selection: held.declaration.replica.selection,
|
|
158
158
|
fromRoomVersion,
|
|
159
159
|
pageToken,
|
|
160
160
|
});
|
package/dist/refusal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAQpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,wBAAsB,MAAM,CAC1B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,aAAa,EACrB,QAAQ,GAAE,eAAe,GAAG,IAAW,iBAmDxC"}
|
package/dist/refusal.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { changeSet, mergeChangeSets } from './change-set.js';
|
|
2
2
|
import { composedOf } from './collection.js';
|
|
3
|
+
import { uncaught } from './failure.js';
|
|
3
4
|
import { listedLocators } from './listing.js';
|
|
4
5
|
import { prepare } from './preparation.js';
|
|
5
6
|
import { storedRecord } from './replica.js';
|
|
@@ -28,8 +29,9 @@ export async function refuse(runtime, reason, provider = null) {
|
|
|
28
29
|
}),
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
|
-
catch {
|
|
32
|
+
catch (error) {
|
|
32
33
|
journal.record('model revocation persistence failed');
|
|
34
|
+
uncaught(error);
|
|
33
35
|
}
|
|
34
36
|
const listedNow = listedLocators(runtime, held);
|
|
35
37
|
for (const locator of listedNow) {
|
|
@@ -45,7 +47,6 @@ export async function refuse(runtime, reason, provider = null) {
|
|
|
45
47
|
socket.session.set({
|
|
46
48
|
refusal: {
|
|
47
49
|
code: reason,
|
|
48
|
-
retryable: false,
|
|
49
50
|
reauthorizationOffered: reason === 'revoked-authorization',
|
|
50
51
|
refusal: provider,
|
|
51
52
|
},
|