@agentshouse/mdruntime 0.1.0-cf281e8224a5d → 0.1.0-cf4cf1851ebaa
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 +0 -3
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +72 -158
- 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 +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +142 -72
- package/dist/adapter.d.ts +120 -58
- 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 +0 -5
- 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 +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 +4 -0
- 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 +0 -2
- package/dist/client.d.ts +16 -20
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +41 -56
- package/dist/collection.d.ts +26 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +28 -10
- 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 +2 -0
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +17 -5
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +35 -26
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +28 -12
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +25 -12
- 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 +37 -12
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +325 -234
- 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 +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +47 -47
- 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 +14 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +45 -16
- 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 +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +8 -0
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +4 -2
- 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 +23 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +84 -19
- package/dist/house-query.d.ts +15 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +43 -0
- package/dist/index.d.ts +20 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -7
- package/dist/install.d.ts +10 -6
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +92 -109
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +75 -53
- package/dist/listing.d.ts +29 -22
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +71 -79
- package/dist/live.d.ts +5 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +74 -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 +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +12 -39
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +11 -23
- package/dist/media.d.ts +18 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +114 -24
- package/dist/memory.d.ts +9 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +93 -32
- package/dist/messages.d.ts +12 -6
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +29 -27
- 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 +4 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -5
- package/dist/models.d.ts +4 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +97 -139
- 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 +1 -1
- 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 +13 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +32 -2
- package/dist/overlay.d.ts +6 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +37 -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 +5 -59
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +32 -122
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +210 -92
- 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 +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +85 -70
- 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 +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +480 -0
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +177 -33
- package/dist/react.d.ts +11 -5
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +28 -5
- package/dist/readiness.d.ts +20 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +17 -10
- package/dist/reads.d.ts +4 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +11 -4
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/refresh.js +2 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +5 -5
- package/dist/replica.d.ts +5 -11
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +14 -16
- 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 +30 -5
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +270 -63
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +8 -5
- 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 +2 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +9 -10
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runtime.d.ts +11 -19
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +42 -90
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +326 -223
- package/dist/saves.d.ts +4 -40
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +142 -710
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +4 -4
- package/dist/shown.d.ts +9 -5
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +94 -60
- 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 +4 -6
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +4 -14
- package/dist/source.d.ts +5 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +13 -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 +21 -6
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +59 -22
- 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 +25 -15
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +50 -18
- package/dist/stored.d.ts +32 -14
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +187 -51
- package/dist/surface.d.ts +12 -6
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +66 -34
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +126 -101
- package/dist/tables.d.ts +16 -56
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +86 -327
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +1 -2
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +4 -10
- package/dist/wire.d.ts +66 -7
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +25 -9
- package/package.json +3 -2
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/job.d.ts +0 -33
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -54
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/socket/rooms.d.ts +0 -44
- package/dist/socket/rooms.d.ts.map +0 -1
- package/dist/socket/rooms.js +0 -90
- package/dist/store/fences.d.ts +0 -16
- package/dist/store/fences.d.ts.map +0 -1
- package/dist/store/fences.js +0 -26
package/dist/models.js
CHANGED
|
@@ -1,195 +1,153 @@
|
|
|
1
|
+
import { equalValue } from '@agentshouse/mdmodel';
|
|
1
2
|
import { changeSet } from './change-set.js';
|
|
2
3
|
import { composedOf } from './collection.js';
|
|
3
|
-
import {
|
|
4
|
+
import { declared, sameDeclaration } from './declaration.js';
|
|
5
|
+
import { uncaught } from './failure.js';
|
|
6
|
+
import { declarationOf, listedLocators } from './listing.js';
|
|
4
7
|
import { loseRooms } from './lost.js';
|
|
5
8
|
import { NO_MODEL } from './model.js';
|
|
9
|
+
import { settle } from './queue.js';
|
|
6
10
|
import { storedRecord } from './replica.js';
|
|
7
|
-
import { overlayDiff, preparedAfter, replayed, sliceAt } from './saves.js';
|
|
8
11
|
import { emitRooms } from './shown.js';
|
|
9
|
-
|
|
10
|
-
return
|
|
11
|
-
(JSON.stringify(held.operations) === JSON.stringify(room.operations) &&
|
|
12
|
-
JSON.stringify(held.replica) === JSON.stringify(room.replica) &&
|
|
13
|
-
JSON.stringify(held.providerOwnedPaths) === JSON.stringify(room.providerOwnedPaths) &&
|
|
14
|
-
JSON.stringify(held.authoredPaths) === JSON.stringify(room.authoredPaths) &&
|
|
15
|
-
JSON.stringify(held.typedSelection) === JSON.stringify(room.typedSelection ?? null)));
|
|
12
|
+
function declaredAsHeld(held, declaration) {
|
|
13
|
+
return held === undefined || sameDeclaration(held.declaration, declaration);
|
|
16
14
|
}
|
|
17
15
|
export function revoked(model) {
|
|
18
16
|
return model?.status === 'unavailable' && model.reason === 'revoked';
|
|
19
17
|
}
|
|
20
|
-
function unheldModelOf({
|
|
21
|
-
return
|
|
18
|
+
function unheldModelOf({ presence }, locator) {
|
|
19
|
+
return presence.unheldModel(locator) ?? NO_MODEL;
|
|
22
20
|
}
|
|
23
|
-
|
|
21
|
+
async function modelNow(runtime, locator) {
|
|
22
|
+
return (await runtime.store.record(locator))?.model ?? unheldModelOf(runtime, locator);
|
|
23
|
+
}
|
|
24
|
+
function restands(held, model, declaration) {
|
|
25
|
+
return (JSON.stringify(held.model) !== JSON.stringify(model) ||
|
|
26
|
+
!equalValue(held.declaration.typedSelection, declaration.typedSelection));
|
|
27
|
+
}
|
|
28
|
+
function recordAlone(store, record) {
|
|
29
|
+
return {
|
|
30
|
+
locator: record.locator,
|
|
31
|
+
key: record.key,
|
|
32
|
+
record: storedRecord(record),
|
|
33
|
+
composed: composedOf(store.composed(record)),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function unheld(runtime, locator, model) {
|
|
37
|
+
runtime.presence.modelled(locator, model);
|
|
38
|
+
emitRooms(runtime, [locator]);
|
|
39
|
+
}
|
|
40
|
+
function recorded(runtime, locator, declaration, model) {
|
|
24
41
|
const { store, socket } = runtime;
|
|
25
|
-
|
|
26
|
-
if (held === undefined || (held.name === room.name && held.handle === room.handle))
|
|
27
|
-
return;
|
|
28
|
-
await store.exclusive(async () => {
|
|
42
|
+
return store.exclusive(async () => {
|
|
29
43
|
if (!socket.continuing())
|
|
30
44
|
return;
|
|
31
|
-
const current = await store.record(
|
|
32
|
-
if (current === undefined)
|
|
45
|
+
const current = await store.record(locator);
|
|
46
|
+
if (current === undefined) {
|
|
47
|
+
unheld(runtime, locator, model);
|
|
33
48
|
return;
|
|
34
|
-
|
|
35
|
-
await
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
composed: composedOf(store.composed(record)),
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
});
|
|
45
|
-
emitRooms(runtime);
|
|
49
|
+
}
|
|
50
|
+
const answer = await (await store.open()).commit({ rooms: [recordAlone(store, { ...current, declaration, model })] });
|
|
51
|
+
void store.changed(changeSet(locator, {
|
|
52
|
+
documents: answer.changed[locator] ?? [],
|
|
53
|
+
room: true,
|
|
54
|
+
unindexed: answer.indexed[locator] === false,
|
|
55
|
+
}));
|
|
46
56
|
});
|
|
47
57
|
}
|
|
48
|
-
async function
|
|
49
|
-
return (await runtime.store.record(locator))?.model ?? unheldModelOf(runtime, locator);
|
|
50
|
-
}
|
|
51
|
-
export async function retainModel(runtime, local, room, given) {
|
|
58
|
+
export async function retainModel(runtime, locator, declaration, given, refused) {
|
|
52
59
|
const { store, socket } = runtime;
|
|
53
|
-
const held = await store.record(
|
|
54
|
-
const previous = held?.model ?? unheldModelOf(runtime,
|
|
60
|
+
const held = await store.record(locator);
|
|
61
|
+
const previous = held?.model ?? unheldModelOf(runtime, locator);
|
|
55
62
|
const next = given ?? previous;
|
|
56
|
-
if (JSON.stringify(previous) === JSON.stringify(next) && declaredAsHeld(held,
|
|
63
|
+
if (JSON.stringify(previous) === JSON.stringify(next) && declaredAsHeld(held, declaration))
|
|
64
|
+
return;
|
|
65
|
+
if (held !== undefined && !restands(held, next, declaration)) {
|
|
66
|
+
await recorded(runtime, locator, declaration, next);
|
|
57
67
|
return;
|
|
58
|
-
|
|
68
|
+
}
|
|
69
|
+
await settle(runtime, [locator], async (works) => {
|
|
59
70
|
if (!socket.continuing())
|
|
60
|
-
return;
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const record = {
|
|
66
|
-
...current.record,
|
|
67
|
-
name: room.name,
|
|
68
|
-
handle: room.handle,
|
|
69
|
-
operations: room.operations,
|
|
70
|
-
replica: room.replica,
|
|
71
|
-
providerOwnedPaths: room.providerOwnedPaths,
|
|
72
|
-
authoredPaths: room.authoredPaths,
|
|
73
|
-
typedSelection: room.typedSelection ?? null,
|
|
74
|
-
model: next,
|
|
75
|
-
};
|
|
76
|
-
const confirmedLayer = await sliceAt(store, record, 'confirmed', current.queue, current.overlaid);
|
|
77
|
-
const replayedLayer = await replayed(store, record, confirmedLayer, current.queue);
|
|
78
|
-
const diff = await overlayDiff(record, current, replayedLayer.visible, replayedLayer.touched);
|
|
79
|
-
const answer = await local.commit({
|
|
80
|
-
rooms: [
|
|
81
|
-
{
|
|
82
|
-
locator: room.locator,
|
|
83
|
-
key: record.key,
|
|
84
|
-
record: storedRecord(record),
|
|
85
|
-
roots: record.typedSelection?.roots ?? [],
|
|
86
|
-
composed: composedOf(store.composed(record)),
|
|
87
|
-
overlay: diff.overlay,
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
});
|
|
91
|
-
preparedAfter(runtime, room.locator, answer);
|
|
92
|
-
changed = changeSet(room.locator, {
|
|
93
|
-
documents: answer.changed[room.locator] ?? [],
|
|
94
|
-
room: true,
|
|
95
|
-
});
|
|
71
|
+
return [];
|
|
72
|
+
const current = works.get(locator)?.replica;
|
|
73
|
+
if (current === undefined) {
|
|
74
|
+
unheld(runtime, locator, next);
|
|
75
|
+
return [];
|
|
96
76
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
77
|
+
return [
|
|
78
|
+
{
|
|
79
|
+
locator,
|
|
80
|
+
record: { ...current.record, declaration, model: next },
|
|
81
|
+
...(refused === undefined ? {} : { refused }),
|
|
82
|
+
},
|
|
83
|
+
];
|
|
104
84
|
});
|
|
105
85
|
}
|
|
106
|
-
export async function scoped(runtime, result,
|
|
107
|
-
const { socket,
|
|
86
|
+
export async function scoped(runtime, result, locator, declaration) {
|
|
87
|
+
const { socket, presence } = runtime;
|
|
108
88
|
if (result.scope === 'content' && !result.retryable) {
|
|
109
|
-
|
|
110
|
-
await loseRooms(runtime, [room.locator]);
|
|
89
|
+
await loseRooms(runtime, [locator]);
|
|
111
90
|
return;
|
|
112
91
|
}
|
|
113
|
-
|
|
114
|
-
refusal: { code: result.code, fields: result.fields, retryable: result.retryable },
|
|
115
|
-
});
|
|
116
|
-
let scopedAway = room;
|
|
92
|
+
presence.refused(locator, result);
|
|
117
93
|
if (result.scope === 'model')
|
|
118
|
-
await retainModel(runtime,
|
|
119
|
-
status: 'unavailable',
|
|
120
|
-
reason: 'not-readable',
|
|
121
|
-
});
|
|
122
|
-
else if (result.scope !== 'operation') {
|
|
123
|
-
socket.rooms.stand(room.locator, { unreadable: true });
|
|
124
|
-
scopedAway = { ...room, replica: { ...room.replica, admission: 'unavailable' } };
|
|
125
|
-
await retainModel(runtime, local, scopedAway, null);
|
|
126
|
-
}
|
|
94
|
+
await retainModel(runtime, locator, declaration, { status: 'unavailable', reason: 'not-readable' }, true);
|
|
127
95
|
if (!socket.continuing())
|
|
128
96
|
return;
|
|
129
|
-
|
|
130
|
-
emitRooms(runtime);
|
|
131
|
-
journal.record(`scoped refusal ${room.locator} ${result.scope} ${result.code}`);
|
|
97
|
+
emitRooms(runtime, [locator]);
|
|
132
98
|
}
|
|
133
99
|
export async function settleModels(runtime, held, status, local) {
|
|
134
|
-
const { store, socket,
|
|
100
|
+
const { store, socket, presence } = runtime;
|
|
135
101
|
const owed = (model) => model.status !== 'unavailable' && model.status !== status;
|
|
136
102
|
const declaredAnew = await store.exclusive(async () => {
|
|
137
103
|
if (!socket.continuing())
|
|
138
104
|
return [];
|
|
139
|
-
const stored = await store.rooms(held.
|
|
140
|
-
const unchanged = held.filter((
|
|
141
|
-
const record = stored.get(
|
|
142
|
-
return (owed(record?.model ?? unheldModelOf(runtime,
|
|
105
|
+
const stored = await store.rooms([...held.keys()]);
|
|
106
|
+
const unchanged = [...held].filter(([locator, declaration]) => {
|
|
107
|
+
const record = stored.get(locator)?.record;
|
|
108
|
+
return (owed(record?.model ?? unheldModelOf(runtime, locator)) &&
|
|
109
|
+
declaredAsHeld(record, declaration));
|
|
143
110
|
});
|
|
144
|
-
const records = unchanged.flatMap((
|
|
145
|
-
const record = stored.get(
|
|
111
|
+
const records = unchanged.flatMap(([locator]) => {
|
|
112
|
+
const record = stored.get(locator)?.record;
|
|
146
113
|
return record === undefined
|
|
147
114
|
? []
|
|
148
115
|
: [{ ...record, model: { ...record.model, status } }];
|
|
149
116
|
});
|
|
150
117
|
if (records.length > 0) {
|
|
151
118
|
try {
|
|
152
|
-
await local.commit({
|
|
153
|
-
rooms: records.map((record) => ({
|
|
154
|
-
locator: record.locator,
|
|
155
|
-
key: record.key,
|
|
156
|
-
record: storedRecord(record),
|
|
157
|
-
composed: composedOf(store.composed(record)),
|
|
158
|
-
})),
|
|
159
|
-
});
|
|
119
|
+
await local.commit({ rooms: records.map((record) => recordAlone(store, record)) });
|
|
160
120
|
}
|
|
161
|
-
catch {
|
|
162
|
-
|
|
121
|
+
catch (error) {
|
|
122
|
+
uncaught(error);
|
|
163
123
|
}
|
|
164
124
|
}
|
|
165
|
-
for (const
|
|
166
|
-
const
|
|
167
|
-
if (!stored.has(
|
|
168
|
-
|
|
169
|
-
unheldModel: { ...unheldModel, status },
|
|
170
|
-
});
|
|
125
|
+
for (const [locator] of unchanged) {
|
|
126
|
+
const unheldModel = presence.unheldModel(locator);
|
|
127
|
+
if (!stored.has(locator) && unheldModel !== null) {
|
|
128
|
+
presence.modelled(locator, { ...unheldModel, status });
|
|
171
129
|
}
|
|
172
|
-
list(runtime, room, admitted(runtime, room));
|
|
173
130
|
}
|
|
174
131
|
if (unchanged.length > 0)
|
|
175
|
-
emitRooms(runtime);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
|
132
|
+
emitRooms(runtime, unchanged.map(([locator]) => locator));
|
|
133
|
+
const kept = new Set(unchanged.map(([locator]) => locator));
|
|
134
|
+
return [...held].filter(([locator]) => !kept.has(locator) &&
|
|
135
|
+
owed(stored.get(locator)?.record.model ?? unheldModelOf(runtime, locator)));
|
|
180
136
|
});
|
|
181
|
-
for (const
|
|
182
|
-
const model = await modelNow(runtime,
|
|
137
|
+
for (const [locator, declaration] of declaredAnew) {
|
|
138
|
+
const model = await modelNow(runtime, locator);
|
|
183
139
|
if (owed(model))
|
|
184
|
-
await retainModel(runtime,
|
|
140
|
+
await retainModel(runtime, locator, declaration, { ...model, status });
|
|
185
141
|
}
|
|
186
142
|
}
|
|
187
143
|
export async function cachedModels(runtime, local) {
|
|
188
|
-
const { store,
|
|
144
|
+
const { store, presence } = runtime;
|
|
189
145
|
const held = await store.rooms();
|
|
190
|
-
await settleModels(runtime, listedLocators(runtime, held).flatMap((locator) => {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
146
|
+
await settleModels(runtime, new Map(listedLocators(runtime, held).flatMap((locator) => {
|
|
147
|
+
const discovered = presence.room(locator);
|
|
148
|
+
const declaration = discovered === undefined
|
|
149
|
+
? declarationOf(runtime, locator, held.get(locator))?.room
|
|
150
|
+
: declared(discovered);
|
|
151
|
+
return declaration === undefined ? [] : [[locator, declaration]];
|
|
152
|
+
})), 'cached', local);
|
|
195
153
|
}
|
package/dist/observation.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { QueryCoverage, QueryDocument, QueryGroup, QueryResult } from './query.js';
|
|
1
|
+
import type { PendingRoom, QueryCoverage, QueryDocument, QueryGroup, QueryResult } from './query.js';
|
|
2
|
+
import type { ReadinessShown, RoomCoverage } from './readiness.js';
|
|
3
|
+
import type { AppRoom, ListedRooms } from './listing.js';
|
|
2
4
|
export type Observation<T> = {
|
|
3
5
|
current(): T;
|
|
4
6
|
subscribe(listener: (value: T) => void): () => void;
|
|
@@ -9,15 +11,24 @@ export type KeyedResult = {
|
|
|
9
11
|
result: QueryResult;
|
|
10
12
|
keys: readonly RowKey[];
|
|
11
13
|
};
|
|
12
|
-
export type
|
|
13
|
-
changed: readonly (readonly [
|
|
14
|
-
removed: readonly
|
|
15
|
-
order: readonly
|
|
14
|
+
export type KeyedChange<K, T> = {
|
|
15
|
+
readonly changed: readonly (readonly [K, T])[];
|
|
16
|
+
readonly removed: readonly K[];
|
|
17
|
+
readonly order: readonly K[] | null;
|
|
18
|
+
};
|
|
19
|
+
export type QueryChange = KeyedChange<RowKey, QueryDocument | QueryGroup> & {
|
|
16
20
|
coverage?: QueryCoverage;
|
|
17
21
|
next?: string | null;
|
|
18
22
|
total?: number;
|
|
19
23
|
};
|
|
20
|
-
export type
|
|
24
|
+
export type ReadinessChange = {
|
|
25
|
+
readonly shown: ReadinessShown;
|
|
26
|
+
readonly rooms: KeyedChange<string, RoomCoverage>;
|
|
27
|
+
};
|
|
28
|
+
export type PendingChange = {
|
|
29
|
+
readonly pending: KeyedChange<string, PendingRoom>;
|
|
30
|
+
};
|
|
31
|
+
export type QueryMessage = KeyedResult | QueryChange | PendingChange;
|
|
21
32
|
export type Observed = {
|
|
22
33
|
observation: Observation<unknown>;
|
|
23
34
|
receive(message: unknown): void;
|
|
@@ -25,15 +36,21 @@ export type Observed = {
|
|
|
25
36
|
};
|
|
26
37
|
export declare function rowsOf(result: QueryResult): readonly (QueryDocument | QueryGroup)[];
|
|
27
38
|
export declare function whole(message: QueryMessage): message is KeyedResult;
|
|
28
|
-
export declare function
|
|
29
|
-
export declare function
|
|
30
|
-
export declare function
|
|
39
|
+
export declare function pendingChange(message: QueryMessage): message is PendingChange;
|
|
40
|
+
export declare function unchanged(change: KeyedChange<unknown, unknown>): boolean;
|
|
41
|
+
export declare function keyedChange<K, H, T>(held: ReadonlyMap<K, H>, keys: readonly K[], rows: readonly T[], same: (was: H, now: T) => boolean): KeyedChange<K, T>;
|
|
42
|
+
export declare function keyedAt<K, H, T>(held: ReadonlyMap<K, H>, at: ReadonlyMap<K, T | null>, same: (was: H, now: T) => boolean): KeyedChange<K, T> | null;
|
|
43
|
+
export declare function keyedInto<K, T>(held: Map<K, T>, change: KeyedChange<K, T>): void;
|
|
44
|
+
export declare function samePending(was: PendingRoom, now: PendingRoom): boolean;
|
|
45
|
+
export declare function appRooms({ rooms, models }: ListedRooms): readonly AppRoom[];
|
|
46
|
+
export declare function replaces(topic: string, message: unknown): boolean;
|
|
47
|
+
export declare function observed(first: unknown, stop: () => void, topic: string): Observed;
|
|
48
|
+
export declare function opened(watch: (deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void, topic: string): Promise<Observation<unknown>>;
|
|
31
49
|
export declare function observing<Topic extends string>(watch: (topic: Topic, input: readonly unknown[], deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void): (topic: Topic, ...input: unknown[]) => Promise<Observation<unknown>>;
|
|
32
50
|
export type Digest = {
|
|
33
|
-
readonly pending: string
|
|
51
|
+
readonly pending: Map<string, PendingRoom>;
|
|
34
52
|
} | {
|
|
35
|
-
readonly
|
|
36
|
-
readonly rows: ReadonlyMap<RowKey, number>;
|
|
53
|
+
readonly rows: Map<RowKey, number>;
|
|
37
54
|
readonly coverage: string;
|
|
38
55
|
readonly next: string | undefined;
|
|
39
56
|
readonly total: number | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,aAAa,EACb,UAAU,EACV,WAAW,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAa,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,KAAK,EAAE,OAAO,EAA4B,WAAW,EAAe,MAAM,cAAc,CAAC;AAGhG,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,OAAO,IAAI,CAAC,CAAC;IACb,SAA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