@agentshouse/mdruntime 0.1.0-c806ecaf4afed → 0.1.0-c809974611fbc
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.map +1 -1
- package/dist/acceptance.js +45 -25
- package/dist/act-lanes.d.ts +11 -14
- package/dist/act-lanes.d.ts.map +1 -1
- package/dist/act-lanes.js +53 -5
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +161 -71
- package/dist/adapter.d.ts +165 -29
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +0 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -7
- package/dist/{binary.d.ts → attachment.d.ts} +8 -4
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +15 -0
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +347 -0
- package/dist/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- package/dist/change.d.ts +6 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +3 -0
- package/dist/chat-types.d.ts +0 -2
- package/dist/chat-types.d.ts.map +1 -1
- package/dist/chat-types.js +2 -4
- package/dist/client.d.ts +27 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +29 -57
- package/dist/collection.d.ts +6 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +23 -9
- 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 +4 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +88 -44
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +23 -16
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +23 -10
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +18 -8
- package/dist/conversation-row.d.ts +8 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +20 -7
- package/dist/conversation.d.ts +31 -12
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +264 -190
- package/dist/declaration.js +3 -3
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +36 -9
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +5 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +25 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +111 -34
- package/dist/expectation.d.ts +25 -14
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +51 -20
- package/dist/failure.d.ts +2 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +6 -1
- package/dist/figures.d.ts +1 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +6 -4
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- package/dist/host.d.ts +7 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +78 -32
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +102 -0
- package/dist/identity.d.ts +1 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -1
- package/dist/index.d.ts +24 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -7
- package/dist/install.d.ts +10 -4
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +45 -46
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +52 -32
- package/dist/listing.d.ts +24 -12
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +50 -21
- package/dist/live.d.ts +19 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +94 -36
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +4 -3
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +2 -3
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +181 -34
- package/dist/memory.d.ts +7 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +66 -22
- package/dist/messages.d.ts +17 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +29 -10
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +10 -7
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +5 -8
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +29 -12
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +206 -69
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opened.d.ts +5 -5
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +2 -2
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +22 -10
- package/dist/outcome.d.ts +33 -13
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +36 -6
- package/dist/overlay.d.ts +21 -7
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +112 -39
- package/dist/parts.d.ts +4 -9
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -15
- package/dist/paths.d.ts +1 -1
- package/dist/paths.js +1 -1
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +198 -87
- package/dist/presence.d.ts +8 -2
- package/dist/presence.d.ts.map +1 -1
- package/dist/presence.js +24 -13
- package/dist/queries.d.ts +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +133 -73
- package/dist/query.d.ts +2 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +1 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -8
- package/dist/queue.d.ts +2 -2
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +73 -48
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +180 -39
- package/dist/react.d.ts +16 -11
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +22 -4
- package/dist/readiness.d.ts +23 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +4 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +22 -7
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/reference-forms.d.ts +4 -0
- package/dist/reference-forms.d.ts.map +1 -0
- package/dist/reference-forms.js +74 -0
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +4 -4
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +1 -3
- package/dist/replica.d.ts +3 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +5 -5
- 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 +31 -6
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +262 -36
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +12 -7
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +47 -0
- package/dist/rows.d.ts +11 -2
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +24 -10
- package/dist/run-tables.d.ts +25 -0
- package/dist/run-tables.d.ts.map +1 -0
- package/dist/run-tables.js +94 -0
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runs.d.ts +27 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +90 -0
- package/dist/runtime.d.ts +7 -4
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +105 -124
- package/dist/saves.d.ts +7 -5
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +107 -57
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +2 -2
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shown.d.ts +5 -2
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +79 -43
- package/dist/socket/lanes.d.ts +12 -4
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +34 -8
- package/dist/socket/session.d.ts +4 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +7 -4
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +11 -9
- package/dist/source.d.ts +7 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +15 -2
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +30 -8
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +70 -26
- 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.d.ts +17 -10
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +18 -6
- package/dist/stored.d.ts +41 -16
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +215 -57
- package/dist/surface.d.ts +20 -8
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +62 -27
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +76 -40
- package/dist/tables.d.ts +41 -52
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +110 -326
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +3 -4
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +50 -10
- package/dist/wire.d.ts +40 -16
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +22 -14
- package/package.json +4 -4
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
package/dist/saves.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isImageType, parse } from '@agentshouse/mdmodel';
|
|
2
|
+
import { attachmentRecord } from './attachment.js';
|
|
3
|
+
import { changeSet } from './change-set.js';
|
|
3
4
|
import { queuedFile } from './change.js';
|
|
4
|
-
import { available } from './collection.js';
|
|
5
|
+
import { available, definitionsAt, typeAt } from './collection.js';
|
|
5
6
|
import { runtimeError } from './failure.js';
|
|
6
7
|
import { attachedFile } from './file.js';
|
|
8
|
+
import { roomDraftRevision } from './identity.js';
|
|
7
9
|
import { compositionFor } from './listing.js';
|
|
8
10
|
import { scoped } from './models.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
+
import { absentAttachment, attachAnswer, attachmentAnswer, attachmentLinkAnswer, failure, linkedAnswer, OFFLINE, UNCERTAIN, } from './outcome.js';
|
|
12
|
+
import { sameAttachment } from './overlay.js';
|
|
11
13
|
import { ancestors } from './paths.js';
|
|
12
14
|
import { connectionNow } from './preparation.js';
|
|
13
15
|
import { append, sliceAt, withdrawable } from './queue.js';
|
|
14
16
|
import { entryAt, replaying, slicing, } from './replica.js';
|
|
15
|
-
import {
|
|
17
|
+
import { attachmentBase, changesOf, held, heldFile, joinedOver, moveTarget, readSavedParts, } from './room-draft.js';
|
|
16
18
|
import { refuse } from './refusal.js';
|
|
17
19
|
import { visibleOf } from './room-drafts.js';
|
|
18
20
|
import { destination, planSave, } from './save.js';
|
|
@@ -43,9 +45,24 @@ export function saveRoomDrafts(runtime, locator, named, writtenBy) {
|
|
|
43
45
|
if (!saved.some((draft) => draft.path === path))
|
|
44
46
|
saved.push({ path, parts: record.parts });
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
const result = await loaded(runtime, locator, replica, saved, new Set(saved.map(({ path }) => path)), [], writtenBy);
|
|
49
|
+
if (result.outcome !== 'refused' || result.code !== 'changed-underneath')
|
|
50
|
+
return result;
|
|
51
|
+
return joinedUnderneath(runtime, locator, saved.map(({ path }) => drafts.get(path)), result);
|
|
47
52
|
});
|
|
48
53
|
}
|
|
54
|
+
async function joinedUnderneath({ store }, locator, records, refused) {
|
|
55
|
+
const visible = (await visibleOf(store, locator, records.map(({ path }) => path)));
|
|
56
|
+
const joined = records.flatMap((record) => {
|
|
57
|
+
const join = joinedOver(record.parts, record.marks, record.path, visible);
|
|
58
|
+
return join === null ? [] : [{ ...record, ...join, revision: roomDraftRevision() }];
|
|
59
|
+
});
|
|
60
|
+
if (joined.length === 0)
|
|
61
|
+
return refused;
|
|
62
|
+
await (await store.open()).commit({ rooms: [], writes: [{ locator, roomDrafts: joined }] });
|
|
63
|
+
await store.changed(changeSet(locator, { drafts: joined.map(({ path }) => path) }));
|
|
64
|
+
return refused;
|
|
65
|
+
}
|
|
49
66
|
export function saveParts(runtime, locator, named, writtenBy) {
|
|
50
67
|
const { store } = runtime;
|
|
51
68
|
return store.exclusive(async () => {
|
|
@@ -60,7 +77,7 @@ export function saveParts(runtime, locator, named, writtenBy) {
|
|
|
60
77
|
for (const { path, parts } of read) {
|
|
61
78
|
const file = parts.file === undefined
|
|
62
79
|
? undefined
|
|
63
|
-
: await heldFile(parts.file.blob, parts.file.base === undefined ?
|
|
80
|
+
: await heldFile(parts.file.blob, parts.file.base === undefined ? attachmentBase(visible, path) : parts.file.base);
|
|
64
81
|
if (parts.file !== undefined && file !== undefined) {
|
|
65
82
|
files.push({ key: file.localId, blob: parts.file.blob });
|
|
66
83
|
}
|
|
@@ -142,7 +159,7 @@ async function loaded(runtime, locator, replica, saved, consumed, files, written
|
|
|
142
159
|
}
|
|
143
160
|
function textDiffers(left, right) {
|
|
144
161
|
return ((left?.content ?? undefined) !== (right?.content ?? undefined) ||
|
|
145
|
-
!
|
|
162
|
+
!sameAttachment(left?.binary ?? undefined, right?.binary ?? undefined));
|
|
146
163
|
}
|
|
147
164
|
function textOf(entry) {
|
|
148
165
|
if (entry === null)
|
|
@@ -159,13 +176,16 @@ function lookupOf(local, key, view) {
|
|
|
159
176
|
]));
|
|
160
177
|
};
|
|
161
178
|
}
|
|
162
|
-
function declaredOf(entry) {
|
|
179
|
+
function declaredOf(composition, path, entry) {
|
|
163
180
|
if (entry.binary !== null)
|
|
164
181
|
return { type: undefined, binary: true };
|
|
165
|
-
const
|
|
166
|
-
return {
|
|
182
|
+
const content = entry.content ?? '';
|
|
183
|
+
return {
|
|
184
|
+
type: typeAt(composition, path, parse(content, path, definitionsAt(composition, path))),
|
|
185
|
+
binary: false,
|
|
186
|
+
};
|
|
167
187
|
}
|
|
168
|
-
function overriddenLookup(lookup, overrides) {
|
|
188
|
+
function overriddenLookup(composition, lookup, overrides) {
|
|
169
189
|
return async (paths) => {
|
|
170
190
|
const known = new Map(await lookup(paths.filter((path) => !overrides.has(path))));
|
|
171
191
|
for (const path of paths) {
|
|
@@ -175,7 +195,7 @@ function overriddenLookup(lookup, overrides) {
|
|
|
175
195
|
if (entry === null)
|
|
176
196
|
known.delete(path);
|
|
177
197
|
else
|
|
178
|
-
known.set(path, declaredOf(entry));
|
|
198
|
+
known.set(path, declaredOf(composition, path, entry));
|
|
179
199
|
}
|
|
180
200
|
return known;
|
|
181
201
|
};
|
|
@@ -196,10 +216,12 @@ function validatorOf(runtime, record, confirmedLayer) {
|
|
|
196
216
|
if (textOf(was) !== textOf(now))
|
|
197
217
|
changes.push({ path, was: textOf(was), now: textOf(now) });
|
|
198
218
|
}
|
|
199
|
-
|
|
200
|
-
|
|
219
|
+
const composition = compositionFor(runtime, record);
|
|
220
|
+
return validatedNeighbourhood(changes, composition, {
|
|
221
|
+
lookup: overriddenLookup(composition, lookupOf(local, record.key, 'confirmed'), overrides),
|
|
201
222
|
texts: textsOf(local, record.key, 'confirmed'),
|
|
202
223
|
referrers: referrersOf(local, record.key, 'confirmed'),
|
|
224
|
+
holders: (sought) => local.holders(record.key, 'confirmed', sought),
|
|
203
225
|
});
|
|
204
226
|
};
|
|
205
227
|
}
|
|
@@ -229,8 +251,8 @@ export function batchFile(store, batch) {
|
|
|
229
251
|
return (await store.open()).file(localId, change?.kind === 'binary' ? change.mediaType : '');
|
|
230
252
|
};
|
|
231
253
|
}
|
|
232
|
-
async function
|
|
233
|
-
const { store, socket, presence
|
|
254
|
+
async function transferAttachment(runtime, request, transfer, answer) {
|
|
255
|
+
const { store, socket, presence } = runtime;
|
|
234
256
|
const { session } = socket;
|
|
235
257
|
if (socket.closed() || session.now().refusal !== null)
|
|
236
258
|
return UNCERTAIN;
|
|
@@ -247,12 +269,10 @@ async function transferBinary(runtime, request, transfer, answer) {
|
|
|
247
269
|
if (closed || authorization === undefined || refusal !== null)
|
|
248
270
|
return UNCERTAIN;
|
|
249
271
|
const since = presence.losses();
|
|
250
|
-
journal.record(`transfer binary ${request.locator} ${request.path}`);
|
|
251
272
|
try {
|
|
252
273
|
const result = await transfer(authorization);
|
|
253
274
|
const settled = result;
|
|
254
|
-
|
|
255
|
-
if (presence.lostSince(request.locator, since))
|
|
275
|
+
if (request.locator !== null && presence.lostSince(request.locator, since))
|
|
256
276
|
return failure({ kind: 'room-not-readable', locator: request.locator });
|
|
257
277
|
if (settled.kind === 'scoped-refusal') {
|
|
258
278
|
const room = await store.record(settled.locator);
|
|
@@ -264,23 +284,22 @@ async function transferBinary(runtime, request, transfer, answer) {
|
|
|
264
284
|
return answer(result);
|
|
265
285
|
}
|
|
266
286
|
catch {
|
|
267
|
-
journal.record('outcome binary transport-uncertainty');
|
|
268
287
|
return UNCERTAIN;
|
|
269
288
|
}
|
|
270
289
|
}
|
|
271
|
-
function
|
|
290
|
+
function fetchAttachment(runtime, request, name) {
|
|
272
291
|
const { store, socket } = runtime;
|
|
273
|
-
return
|
|
292
|
+
return transferAttachment(runtime, request, (authorization) => store.opened.fetch(name, () => socket.binary(authorization, request)), attachmentAnswer);
|
|
274
293
|
}
|
|
275
|
-
async function
|
|
294
|
+
async function readAttachment(runtime, request, name) {
|
|
276
295
|
if (runtime.socket.closed())
|
|
277
296
|
return UNCERTAIN;
|
|
278
297
|
const held = await runtime.store.opened.find(name);
|
|
279
298
|
if (held !== null)
|
|
280
299
|
return held;
|
|
281
|
-
return
|
|
300
|
+
return fetchAttachment(runtime, request, name);
|
|
282
301
|
}
|
|
283
|
-
async function
|
|
302
|
+
async function attachmentPath(store, locator, path, revision) {
|
|
284
303
|
if (revision !== undefined)
|
|
285
304
|
return { kind: 'path', locator, path, revision };
|
|
286
305
|
const replica = await store.replica(locator);
|
|
@@ -293,7 +312,7 @@ async function binaryPath(store, locator, path, revision) {
|
|
|
293
312
|
return null;
|
|
294
313
|
if (held.binary.state === 'pending')
|
|
295
314
|
return { kind: 'pending', localId: held.binary.localId };
|
|
296
|
-
const record =
|
|
315
|
+
const record = attachmentRecord(path, held.binary, held.revision ?? undefined);
|
|
297
316
|
if (record.state !== 'accepted')
|
|
298
317
|
return null;
|
|
299
318
|
const queued = replica.queue.flatMap((batch) => batch.changes);
|
|
@@ -321,17 +340,17 @@ async function binaryPath(store, locator, path, revision) {
|
|
|
321
340
|
revision: record.revision,
|
|
322
341
|
};
|
|
323
342
|
}
|
|
324
|
-
async function
|
|
343
|
+
async function askedAttachment({ store, socket }, locator, path, revision) {
|
|
325
344
|
await socket.ready;
|
|
326
345
|
const drafted = (await store.draft(locator, path))?.parts.file;
|
|
327
346
|
return drafted !== undefined && drafted.localId === revision
|
|
328
347
|
? { kind: 'pending', localId: revision }
|
|
329
|
-
:
|
|
348
|
+
: attachmentPath(store, locator, path, revision);
|
|
330
349
|
}
|
|
331
|
-
async function
|
|
350
|
+
async function pendingAttachment(store, locator, path, localId) {
|
|
332
351
|
const facts = await queuedFacts(store, locator, path, localId);
|
|
333
352
|
return facts === null
|
|
334
|
-
?
|
|
353
|
+
? absentAttachment(path)
|
|
335
354
|
: {
|
|
336
355
|
kind: 'binary',
|
|
337
356
|
file: localId,
|
|
@@ -339,13 +358,13 @@ async function pendingBinary(store, locator, path, localId) {
|
|
|
339
358
|
mediaType: facts.mediaType,
|
|
340
359
|
};
|
|
341
360
|
}
|
|
342
|
-
async function
|
|
343
|
-
const asked = await
|
|
361
|
+
async function readAttachmentPath(runtime, locator, path, revision) {
|
|
362
|
+
const asked = await askedAttachment(runtime, locator, path, revision);
|
|
344
363
|
if (asked === null)
|
|
345
|
-
return
|
|
364
|
+
return absentAttachment(path);
|
|
346
365
|
if (asked.kind === 'pending')
|
|
347
|
-
return
|
|
348
|
-
return
|
|
366
|
+
return pendingAttachment(runtime.store, locator, path, asked.localId);
|
|
367
|
+
return readAttachment(runtime, asked, { locator, path: asked.path, revision: asked.revision });
|
|
349
368
|
}
|
|
350
369
|
async function heldMediaType(store, locator, path) {
|
|
351
370
|
const replica = await store.record(locator);
|
|
@@ -353,23 +372,42 @@ async function heldMediaType(store, locator, path) {
|
|
|
353
372
|
return held === undefined ? store.attached.of(locator, path)?.mediaType : held.binary?.mediaType;
|
|
354
373
|
}
|
|
355
374
|
function linkOf(runtime, asked, held) {
|
|
356
|
-
return
|
|
375
|
+
return transferAttachment(runtime, asked, (authorization) => runtime.socket.link(authorization, asked), (result) => attachmentLinkAnswer(result, held));
|
|
357
376
|
}
|
|
358
|
-
async function
|
|
377
|
+
async function linkAttachmentPath(runtime, locator, path, revision) {
|
|
359
378
|
const { store, socket } = runtime;
|
|
360
379
|
await socket.ready;
|
|
361
|
-
const asked = await
|
|
380
|
+
const asked = await attachmentPath(store, locator, path, revision);
|
|
362
381
|
if (asked === null || asked.kind === 'pending')
|
|
363
|
-
return
|
|
382
|
+
return absentAttachment(path);
|
|
364
383
|
return linkOf(runtime, asked, revision === undefined ? await heldMediaType(store, locator, path) : undefined);
|
|
365
384
|
}
|
|
366
|
-
|
|
385
|
+
function shownImage(runtime, asked, name) {
|
|
386
|
+
const { store, socket } = runtime;
|
|
387
|
+
return new Promise((answer) => {
|
|
388
|
+
void transferAttachment(runtime, asked, (authorization) => store.opened.fetch(name, async () => {
|
|
389
|
+
const read = await socket.binary(authorization, asked);
|
|
390
|
+
const copies = read.kind === 'binary' ? (read.copies ?? []) : [];
|
|
391
|
+
if (read.kind === 'binary' && read.url !== undefined && copies.length > 0) {
|
|
392
|
+
answer({
|
|
393
|
+
kind: 'link',
|
|
394
|
+
url: read.url,
|
|
395
|
+
name: asked.path.slice(asked.path.lastIndexOf('/') + 1),
|
|
396
|
+
mediaType: read.mediaType,
|
|
397
|
+
copies,
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
return read;
|
|
401
|
+
}), attachmentAnswer).then(answer);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
async function showAttachmentPath(runtime, locator, path, revision) {
|
|
367
405
|
const { store } = runtime;
|
|
368
|
-
const asked = await
|
|
406
|
+
const asked = await askedAttachment(runtime, locator, path, revision);
|
|
369
407
|
if (asked === null)
|
|
370
|
-
return
|
|
408
|
+
return absentAttachment(path);
|
|
371
409
|
if (asked.kind === 'pending')
|
|
372
|
-
return
|
|
410
|
+
return pendingAttachment(store, locator, path, asked.localId);
|
|
373
411
|
if (runtime.socket.closed())
|
|
374
412
|
return UNCERTAIN;
|
|
375
413
|
const name = { locator, path: asked.path, revision: asked.revision };
|
|
@@ -377,11 +415,12 @@ async function showBinaryPath(runtime, locator, path, revision) {
|
|
|
377
415
|
if (kept !== null)
|
|
378
416
|
return kept;
|
|
379
417
|
const mediaType = await heldMediaType(store, locator, path);
|
|
380
|
-
if (mediaType
|
|
381
|
-
return
|
|
382
|
-
|
|
418
|
+
if (mediaType !== undefined && isImageType(mediaType))
|
|
419
|
+
return shownImage(runtime, asked, name);
|
|
420
|
+
const linked = await linkOf(runtime, asked, revision === undefined ? mediaType : undefined);
|
|
421
|
+
return linked.kind === 'link' ? { ...linked, copies: [] } : linked;
|
|
383
422
|
}
|
|
384
|
-
async function
|
|
423
|
+
async function attachFile(runtime, locator, file, answer) {
|
|
385
424
|
const { store, socket } = runtime;
|
|
386
425
|
await socket.ready;
|
|
387
426
|
await socket.firstDiscovery;
|
|
@@ -391,23 +430,34 @@ async function attachBinary(runtime, locator, file) {
|
|
|
391
430
|
socket.session.now().refusal !== null)
|
|
392
431
|
return OFFLINE;
|
|
393
432
|
const request = await attachedFile(locator, file);
|
|
394
|
-
return
|
|
433
|
+
return transferAttachment(runtime, { locator }, async (held) => {
|
|
395
434
|
const result = await socket.attach(held, request);
|
|
396
|
-
if (result.kind === 'attached') {
|
|
435
|
+
if (result.kind === 'attached' && locator !== null) {
|
|
397
436
|
store.attached.hold(locator, result.path, {
|
|
398
437
|
revision: result.revision,
|
|
399
438
|
mediaType: request.mediaType,
|
|
400
439
|
});
|
|
401
440
|
}
|
|
402
441
|
return result;
|
|
403
|
-
},
|
|
442
|
+
}, answer);
|
|
443
|
+
}
|
|
444
|
+
async function keyedAttachment(runtime, link) {
|
|
445
|
+
await runtime.socket.ready;
|
|
446
|
+
const asked = { kind: 'key', link };
|
|
447
|
+
return transferAttachment(runtime, { locator: null }, (authorization) => runtime.socket.link(authorization, asked), (result) => attachmentLinkAnswer(result));
|
|
448
|
+
}
|
|
449
|
+
export function conversationFiles(runtime) {
|
|
450
|
+
return {
|
|
451
|
+
attach: (file) => attachFile(runtime, null, file, linkedAnswer),
|
|
452
|
+
attachment: (link) => keyedAttachment(runtime, link),
|
|
453
|
+
};
|
|
404
454
|
}
|
|
405
|
-
export function
|
|
455
|
+
export function attachmentSurface(runtime) {
|
|
406
456
|
return {
|
|
407
457
|
part: runtime.store.part,
|
|
408
|
-
read: (room, path, revision) =>
|
|
409
|
-
link: (room, path, revision) =>
|
|
410
|
-
show: (room, path, revision) =>
|
|
411
|
-
attach: (room, file) =>
|
|
458
|
+
read: (room, path, revision) => readAttachmentPath(runtime, room, path, revision),
|
|
459
|
+
link: (room, path, revision) => linkAttachmentPath(runtime, room, path, revision),
|
|
460
|
+
show: (room, path, revision) => showAttachmentPath(runtime, room, path, revision),
|
|
461
|
+
attach: (room, file) => attachFile(runtime, room, file, attachAnswer),
|
|
412
462
|
};
|
|
413
463
|
}
|
package/dist/seed.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,
|
|
1
|
+
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAwB,KAAK,WAAW,EAAqB,MAAM,kBAAkB,CAAC;AAC7F,OAAO,KAAK,EAAE,IAAI,EAA4C,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9C,QAAQ,CAAC,OAAO,EAAE,SAAS;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;KAAE,EAAE,CAAC;CACpF,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC;AAEjG,KAAK,WAAW,GAAG,CACjB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,KAAK,KAAK,EACjD,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAChC,MAAM,IAAI,CAAC;AA0ChB,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAe5D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAmBtD;AA+BD,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAOxF;AAYD,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAMlE;AAED,wBAAgB,WAAW,CACzB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,WAAW,GACjB,MAAM,IAAI,CA4BZ"}
|
package/dist/seed.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { queryKey } from '@agentshouse/mdmodel';
|
|
2
|
-
import { whole } from './observation.js';
|
|
2
|
+
import { pendingChange, whole } from './observation.js';
|
|
3
3
|
import { documentKey } from './rows.js';
|
|
4
4
|
const seedTopic = (key) => `seed\u0000${key}`;
|
|
5
5
|
function plain(value) {
|
|
@@ -130,7 +130,7 @@ export function watchSeeded(runtime, plan, deliver, watch) {
|
|
|
130
130
|
const watcher = store.watch(seedTopic(plan.key), shown);
|
|
131
131
|
const stop = watch((cover, held) => seedBehind(runtime, plan, cover, held), (message) => {
|
|
132
132
|
const answered = message;
|
|
133
|
-
pending = whole(answered)
|
|
133
|
+
pending = whole(answered) ? 'pending' in answered.result : pendingChange(answered);
|
|
134
134
|
if (pending && store.seeds.of(plan.key) !== undefined) {
|
|
135
135
|
shown();
|
|
136
136
|
return;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../src/selector.ts"],"names":[],"mappings":"AAaA,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,OAAO,GACtC,OAAO,CAET;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,OAAO,EAAE,CAOnF"}
|
package/dist/selector.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function rewrittenAt(value, members, rewrite) {
|
|
2
|
+
if (Array.isArray(value))
|
|
3
|
+
return value.map((one) => rewrittenAt(one, members, rewrite));
|
|
4
|
+
const [member, ...rest] = members;
|
|
5
|
+
if (member === undefined)
|
|
6
|
+
return rewrite(value);
|
|
7
|
+
if (value === null || typeof value !== 'object' || !Object.hasOwn(value, member))
|
|
8
|
+
return value;
|
|
9
|
+
const held = value;
|
|
10
|
+
return { ...held, [member]: rewrittenAt(held[member], rest, rewrite) };
|
|
11
|
+
}
|
|
12
|
+
export function selectorRewritten(value, selector, rewrite) {
|
|
13
|
+
return rewrittenAt(value, selector.split('.'), rewrite);
|
|
14
|
+
}
|
|
15
|
+
export function selectorValues(value, selector) {
|
|
16
|
+
const selected = [];
|
|
17
|
+
selectorRewritten(value, selector, (one) => {
|
|
18
|
+
selected.push(one);
|
|
19
|
+
return one;
|
|
20
|
+
});
|
|
21
|
+
return selected;
|
|
22
|
+
}
|
package/dist/shown.d.ts
CHANGED
|
@@ -10,15 +10,18 @@ export declare const REFUSAL_TOPIC = "connection-refusal";
|
|
|
10
10
|
export declare const STORAGE_LOSS_TOPIC = "storage-loss";
|
|
11
11
|
export declare const SERVICE_MODE_TOPIC = "service-mode";
|
|
12
12
|
export declare const MEMBER_TOPIC = "member";
|
|
13
|
+
export declare const TIME_ZONE_TOPIC = "time-zone";
|
|
13
14
|
export declare const AUTHORITY_TOPIC = "authority-changes";
|
|
14
15
|
export declare const LOCKS_TOPIC = "locks";
|
|
15
16
|
export declare const queueTopic: (locator: string) => string;
|
|
16
|
-
export declare function recoverReads({ liveQueries, figures }: Runtime): void;
|
|
17
|
+
export declare function recoverReads({ liveQueries, figures }: Runtime, locators?: readonly string[]): void;
|
|
17
18
|
export declare function emitRooms(runtime: Runtime, changed?: readonly string[]): Promise<void>;
|
|
18
19
|
export declare function emitKnownRooms(runtime: Runtime): void;
|
|
19
20
|
export declare function emitRefusal(runtime: Runtime): void;
|
|
20
|
-
export declare function
|
|
21
|
+
export declare function storageLossNow({ store }: Runtime): string | null;
|
|
22
|
+
export declare function emitStorageLoss(runtime: Runtime): void;
|
|
21
23
|
export declare function emitMember({ store }: Runtime, member: Member | null): void;
|
|
24
|
+
export declare function emitTimeZone({ store }: Runtime, zone: string | null): void;
|
|
22
25
|
export declare function show(runtime: Runtime): Promise<void>;
|
|
23
26
|
export declare function moveTo(runtime: Runtime, next: Moving): Promise<void>;
|
|
24
27
|
export declare function statusShown(runtime: Runtime): Promise<void>;
|
package/dist/shown.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shown.d.ts","sourceRoot":"","sources":["../src/shown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"shown.d.ts","sourceRoot":"","sources":["../src/shown.ts"],"names":[],"mappings":"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"}
|
package/dist/shown.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { changeSet, mergeChangeSets } from './change-set.js';
|
|
2
2
|
import { conversationsChanged, conversationsLearned } from './conversation.js';
|
|
3
|
-
import {
|
|
3
|
+
import { lossStated } from './durability.js';
|
|
4
|
+
import { listedEntries, listingNow, shownChange, shownRooms } from './listing.js';
|
|
4
5
|
import { emitPresentation, publishRoomDrafts } from './room-drafts.js';
|
|
5
6
|
import { same } from './status.js';
|
|
6
7
|
export const ROOMS_TOPIC = 'rooms';
|
|
@@ -9,11 +10,20 @@ export const REFUSAL_TOPIC = 'connection-refusal';
|
|
|
9
10
|
export const STORAGE_LOSS_TOPIC = 'storage-loss';
|
|
10
11
|
export const SERVICE_MODE_TOPIC = 'service-mode';
|
|
11
12
|
export const MEMBER_TOPIC = 'member';
|
|
13
|
+
export const TIME_ZONE_TOPIC = 'time-zone';
|
|
12
14
|
export const AUTHORITY_TOPIC = 'authority-changes';
|
|
13
15
|
export const LOCKS_TOPIC = 'locks';
|
|
14
16
|
export const queueTopic = (locator) => `queue\u0000${locator}`;
|
|
15
|
-
async function attended({ store, localSaves }) {
|
|
16
|
-
const held =
|
|
17
|
+
async function attended({ store, socket, localSaves }) {
|
|
18
|
+
const held = store.needed()
|
|
19
|
+
? await store.status()
|
|
20
|
+
: {
|
|
21
|
+
queued: [],
|
|
22
|
+
lastCompleted: socket.session.now().lastCompleted,
|
|
23
|
+
unsent: [],
|
|
24
|
+
resets: [],
|
|
25
|
+
returned: [],
|
|
26
|
+
};
|
|
17
27
|
const attentionRequired = held.returned.flatMap((record) => record.returned === null
|
|
18
28
|
? []
|
|
19
29
|
: [{ room: record.locator, path: record.path, returned: structuredClone(record.returned) }]);
|
|
@@ -41,15 +51,15 @@ async function attended({ store, localSaves }) {
|
|
|
41
51
|
};
|
|
42
52
|
}
|
|
43
53
|
async function queuedWork({ store, localSaves }) {
|
|
44
|
-
return !localSaves && (await store.queued()).length > 0;
|
|
54
|
+
return !localSaves && store.needed() && (await store.queued()).length > 0;
|
|
45
55
|
}
|
|
46
|
-
export function recoverReads({ liveQueries, figures }) {
|
|
47
|
-
liveQueries.recover();
|
|
56
|
+
export function recoverReads({ liveQueries, figures }, locators) {
|
|
57
|
+
liveQueries.recover(locators);
|
|
48
58
|
figures.recover();
|
|
49
59
|
}
|
|
50
60
|
export function emitRooms(runtime, changed) {
|
|
51
|
-
recoverReads(runtime);
|
|
52
|
-
runtime.store.readiness.queue();
|
|
61
|
+
recoverReads(runtime, changed);
|
|
62
|
+
runtime.store.readiness.queue(changed);
|
|
53
63
|
return changed === undefined
|
|
54
64
|
? publishRooms(runtime, 'all')
|
|
55
65
|
: publishRooms(runtime, 'changed', changed);
|
|
@@ -74,51 +84,58 @@ function roomsOwedWith(held, mode, touched) {
|
|
|
74
84
|
}
|
|
75
85
|
return held;
|
|
76
86
|
}
|
|
87
|
+
async function patchedRooms(runtime, owed) {
|
|
88
|
+
const { store } = runtime;
|
|
89
|
+
const touched = [...new Set([...owed.changed, ...owed.counted])];
|
|
90
|
+
const entries = await listedEntries(runtime, touched);
|
|
91
|
+
const shown = store.roomsShown.now();
|
|
92
|
+
if (entries === null || shown === null)
|
|
93
|
+
return false;
|
|
94
|
+
if (runtime.socket.closed())
|
|
95
|
+
return true;
|
|
96
|
+
const moved = entries.filter(({ locator, documents }) => owed.changed.has(locator) || shown.get(locator)?.documents !== documents);
|
|
97
|
+
const counted = moved.flatMap(({ locator }) => (owed.changed.has(locator) ? [] : [locator]));
|
|
98
|
+
if (counted.length > 0) {
|
|
99
|
+
recoverReads(runtime, counted);
|
|
100
|
+
store.readiness.queue(counted);
|
|
101
|
+
}
|
|
102
|
+
store.roomsShown.patch(moved);
|
|
103
|
+
if (moved.length === 0)
|
|
104
|
+
return true;
|
|
105
|
+
const change = shownChange(runtime, moved);
|
|
106
|
+
for (const watcher of store.watching(ROOMS_TOPIC, 'ready'))
|
|
107
|
+
watcher.answer(change);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
77
110
|
async function deliverRooms(runtime, owed) {
|
|
78
111
|
const { store, socket } = runtime;
|
|
79
112
|
const waiting = () => store.watching(ROOMS_TOPIC, 'waiting');
|
|
80
113
|
if (socket.closed() || store.watching(ROOMS_TOPIC).length === 0)
|
|
81
114
|
return;
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (
|
|
115
|
+
const touched = owed.changed.size > 0 || owed.counted.size > 0;
|
|
116
|
+
if (!owed.all && touched && waiting().length === 0 && (await patchedRooms(runtime, owed)))
|
|
117
|
+
return;
|
|
118
|
+
if (touched)
|
|
86
119
|
owed.all = true;
|
|
87
|
-
|
|
88
|
-
const held = await store.covering();
|
|
89
|
-
const { roomsShown } = store.device.now();
|
|
90
|
-
owed.all = [...owed.counted].some((locator) => held.rooms.has(locator) &&
|
|
91
|
-
roomsShown?.get(locator)?.documents !== held.rooms.get(locator).documents);
|
|
92
|
-
if (owed.all) {
|
|
93
|
-
recoverReads(runtime);
|
|
94
|
-
store.readiness.queue();
|
|
95
|
-
}
|
|
96
|
-
else if (waiting().length === 0)
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const listing = patched ?? (await listingNow(runtime));
|
|
120
|
+
const listing = await listingNow(runtime);
|
|
100
121
|
if (socket.closed())
|
|
101
122
|
return;
|
|
102
123
|
const { roomsListed, refusal, moving } = socket.session.now();
|
|
103
124
|
const joining = waiting().length > 0 &&
|
|
104
125
|
(roomsListed || listing.size > 0 || refusal !== null || moving.providerUnreachable);
|
|
105
|
-
if (!owed.all &&
|
|
126
|
+
if (!owed.all && !joining)
|
|
106
127
|
return;
|
|
107
128
|
const value = shownRooms(runtime, listing);
|
|
108
|
-
const
|
|
129
|
+
const shown = store.roomsShown.now();
|
|
109
130
|
const moved = owed.all ||
|
|
110
|
-
|
|
111
|
-
(roomsShown !== null &&
|
|
112
|
-
JSON.stringify(shownRooms(runtime, roomsShown)) !== JSON.stringify(value));
|
|
131
|
+
(shown !== null && JSON.stringify(shownRooms(runtime, shown)) !== JSON.stringify(value));
|
|
113
132
|
if (moved)
|
|
114
133
|
for (const watcher of store.watching(ROOMS_TOPIC, 'ready'))
|
|
115
134
|
watcher.answer(value);
|
|
116
135
|
if (joining)
|
|
117
136
|
for (const watcher of waiting())
|
|
118
137
|
watcher.answer(value);
|
|
119
|
-
store.
|
|
120
|
-
roomsShown: store.watching(ROOMS_TOPIC, 'ready').length === 0 ? null : listing,
|
|
121
|
-
});
|
|
138
|
+
store.roomsShown.show(store.watching(ROOMS_TOPIC, 'ready').length === 0 ? null : listing);
|
|
122
139
|
}
|
|
123
140
|
function publishRooms(runtime, mode, touched = []) {
|
|
124
141
|
if (runtime.socket.closed())
|
|
@@ -127,17 +144,24 @@ function publishRooms(runtime, mode, touched = []) {
|
|
|
127
144
|
}
|
|
128
145
|
export function emitRefusal(runtime) {
|
|
129
146
|
const { store, socket } = runtime;
|
|
130
|
-
store.readiness.queue();
|
|
147
|
+
store.readiness.queue([]);
|
|
131
148
|
store.tell(REFUSAL_TOPIC, socket.session.now().refusal);
|
|
132
149
|
emitKnownRooms(runtime);
|
|
133
150
|
}
|
|
134
|
-
export function
|
|
135
|
-
store.
|
|
136
|
-
|
|
151
|
+
export function storageLossNow({ store }) {
|
|
152
|
+
const { persistence, storageLoss } = store.device.now();
|
|
153
|
+
return lossStated(persistence, storageLoss);
|
|
154
|
+
}
|
|
155
|
+
export function emitStorageLoss(runtime) {
|
|
156
|
+
runtime.store.readiness.queue([]);
|
|
157
|
+
runtime.store.tell(STORAGE_LOSS_TOPIC, storageLossNow(runtime));
|
|
137
158
|
}
|
|
138
159
|
export function emitMember({ store }, member) {
|
|
139
160
|
store.tell(MEMBER_TOPIC, member);
|
|
140
161
|
}
|
|
162
|
+
export function emitTimeZone({ store }, zone) {
|
|
163
|
+
store.tell(TIME_ZONE_TOPIC, zone);
|
|
164
|
+
}
|
|
141
165
|
async function deliverStatus(runtime, owed) {
|
|
142
166
|
const { store, socket } = runtime;
|
|
143
167
|
const held = await attended(runtime);
|
|
@@ -159,13 +183,16 @@ async function deliverStatus(runtime, owed) {
|
|
|
159
183
|
store.tell(STATUS_TOPIC, next);
|
|
160
184
|
}
|
|
161
185
|
}
|
|
186
|
+
function conversationsCurrent({ conversations }) {
|
|
187
|
+
return conversations.listed() && conversations.current();
|
|
188
|
+
}
|
|
162
189
|
export function show(runtime) {
|
|
163
|
-
const { store, socket
|
|
190
|
+
const { store, socket } = runtime;
|
|
164
191
|
if (socket.closed())
|
|
165
192
|
return Promise.resolve();
|
|
166
|
-
store.readiness.queue();
|
|
193
|
+
store.readiness.queue([]);
|
|
167
194
|
emitKnownRooms(runtime);
|
|
168
|
-
const moved = { moving: socket.session.now().moving, current:
|
|
195
|
+
const moved = { moving: socket.session.now().moving, current: conversationsCurrent(runtime) };
|
|
169
196
|
return store.owing(STATUS_TOPIC, (held) => {
|
|
170
197
|
if (held === undefined)
|
|
171
198
|
return [moved];
|
|
@@ -247,6 +274,8 @@ export function publishChangeSet(runtime, set) {
|
|
|
247
274
|
}
|
|
248
275
|
export async function submissionDue(runtime, locators) {
|
|
249
276
|
const { store } = runtime;
|
|
277
|
+
if (!store.needed())
|
|
278
|
+
return;
|
|
250
279
|
const due = (await store.queued()).filter((locator) => locators === undefined || locators.includes(locator));
|
|
251
280
|
if (due.length === 0)
|
|
252
281
|
return;
|
|
@@ -254,14 +283,18 @@ export async function submissionDue(runtime, locators) {
|
|
|
254
283
|
}
|
|
255
284
|
export function roomUnreadable(runtime, locator) {
|
|
256
285
|
runtime.presence.refused(locator, null);
|
|
257
|
-
emitRooms(runtime);
|
|
286
|
+
emitRooms(runtime, [locator]);
|
|
258
287
|
}
|
|
259
288
|
export async function rest(runtime, progress, live = () => !runtime.socket.closed()) {
|
|
260
289
|
const { store, socket, presence } = runtime;
|
|
261
290
|
const { session, lanes } = socket;
|
|
262
291
|
if (!live())
|
|
263
292
|
return;
|
|
264
|
-
const settled = () => session.now().complete &&
|
|
293
|
+
const settled = () => session.now().complete &&
|
|
294
|
+
lanes.roomWork() === 0 &&
|
|
295
|
+
!socket.naming() &&
|
|
296
|
+
presence.settled() &&
|
|
297
|
+
conversationsCurrent(runtime);
|
|
265
298
|
let synced = settled();
|
|
266
299
|
if (synced && !session.now().recorded) {
|
|
267
300
|
const queued = await queuedWork(runtime).catch(() => true);
|
|
@@ -272,7 +305,10 @@ export async function rest(runtime, progress, live = () => !runtime.socket.close
|
|
|
272
305
|
if (synced && !session.now().recorded) {
|
|
273
306
|
const completedAt = new Date().toISOString();
|
|
274
307
|
try {
|
|
275
|
-
|
|
308
|
+
if (store.needed())
|
|
309
|
+
await (await store.open()).fact('lastCompleted', completedAt);
|
|
310
|
+
else
|
|
311
|
+
session.set({ lastCompleted: completedAt });
|
|
276
312
|
if (!live())
|
|
277
313
|
return;
|
|
278
314
|
session.set({ recorded: true });
|