@agentshouse/mdruntime 0.1.0-ce531b51ff088 → 0.1.0-ceb97106cc2fd
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/AGENTS.md +273 -175
- package/README.md +21 -11
- package/dist/acquisition.d.ts +14 -0
- package/dist/acquisition.d.ts.map +1 -0
- package/dist/acquisition.js +24 -0
- package/dist/adapter.d.ts +129 -41
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -9
- package/dist/attached-model.d.ts +11 -0
- package/dist/attached-model.d.ts.map +1 -0
- package/dist/attached-model.js +47 -0
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +70 -0
- package/dist/binary.d.ts +23 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +20 -6
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +114 -37
- package/dist/change-set.d.ts +2 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +49 -16
- package/dist/change.d.ts +15 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +26 -1
- package/dist/chat/acts.d.ts +33 -0
- package/dist/chat/acts.d.ts.map +1 -0
- package/dist/chat/acts.js +36 -0
- package/dist/chat/context.d.ts +3 -0
- package/dist/chat/context.d.ts.map +1 -0
- package/dist/chat/context.js +10 -0
- package/dist/chat/input.d.ts +9 -0
- package/dist/chat/input.d.ts.map +1 -0
- package/dist/chat/input.js +99 -0
- package/dist/chat/kit.d.ts +61 -0
- package/dist/chat/kit.d.ts.map +1 -0
- package/dist/chat/kit.js +123 -0
- package/dist/chat/lasting.d.ts +6 -0
- package/dist/chat/lasting.d.ts.map +1 -0
- package/dist/chat/lasting.js +19 -0
- package/dist/chat/list.d.ts +27 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +63 -0
- package/dist/chat/markdown.d.ts +20 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +188 -0
- package/dist/chat/message.d.ts +6 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +192 -0
- package/dist/chat/messages.d.ts +22 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +155 -0
- package/dist/chat/name.d.ts +6 -0
- package/dist/chat/name.d.ts.map +1 -0
- package/dist/chat/name.js +37 -0
- package/dist/chat/opened.d.ts +11 -0
- package/dist/chat/opened.d.ts.map +1 -0
- package/dist/chat/opened.js +17 -0
- package/dist/chat/overlay.d.ts +31 -0
- package/dist/chat/overlay.d.ts.map +1 -0
- package/dist/chat/overlay.js +97 -0
- package/dist/chat/parts.d.ts +57 -0
- package/dist/chat/parts.d.ts.map +1 -0
- package/dist/chat/parts.js +119 -0
- package/dist/chat/process.d.ts +20 -0
- package/dist/chat/process.d.ts.map +1 -0
- package/dist/chat/process.js +32 -0
- package/dist/chat/provider.d.ts +63 -0
- package/dist/chat/provider.d.ts.map +1 -0
- package/dist/chat/provider.js +629 -0
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +80 -0
- package/dist/chat/questions.d.ts +31 -0
- package/dist/chat/questions.d.ts.map +1 -0
- package/dist/chat/questions.js +111 -0
- package/dist/chat/read.d.ts +5 -0
- package/dist/chat/read.d.ts.map +1 -0
- package/dist/chat/read.js +13 -0
- package/dist/chat/ready.d.ts +34 -0
- package/dist/chat/ready.d.ts.map +1 -0
- package/dist/chat/ready.js +91 -0
- package/dist/chat/style.d.ts +4 -0
- package/dist/chat/style.d.ts.map +1 -0
- package/dist/chat/style.js +302 -0
- package/dist/chat.d.ts +14 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +8 -0
- package/dist/client.d.ts +28 -14
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +71 -26
- package/dist/collection.d.ts +21 -12
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +271 -23
- package/dist/connection.d.ts +50 -23
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +2074 -735
- package/dist/conversation.d.ts +41 -14
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +546 -214
- package/dist/durability.d.ts +7 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +17 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +156 -0
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/fence.d.ts +6 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +10 -0
- package/dist/host.d.ts +24 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +126 -45
- package/dist/identity.d.ts +5 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +19 -1
- package/dist/index.d.ts +16 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/memory.d.ts +17 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +159 -46
- package/dist/model.d.ts +17 -14
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +16 -4
- package/dist/observation.d.ts +6 -1
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +38 -17
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/outcome.d.ts +32 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +42 -1
- package/dist/overlay.d.ts +16 -3
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +118 -77
- package/dist/paths.d.ts +0 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +0 -16
- package/dist/query.d.ts +46 -6
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +85 -37
- package/dist/reach.d.ts +45 -0
- package/dist/reach.d.ts.map +1 -0
- package/dist/reach.js +306 -0
- package/dist/react.d.ts +44 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +66 -0
- package/dist/read-side.d.ts +16 -5
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +408 -137
- package/dist/readiness.d.ts +53 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +33 -0
- package/dist/recovery.d.ts +25 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +197 -0
- package/dist/refresh.d.ts +12 -1
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +51 -36
- package/dist/replica.d.ts +10 -7
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +129 -73
- package/dist/room-draft.d.ts +41 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +139 -28
- package/dist/rows.d.ts +11 -14
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +87 -50
- package/dist/save.d.ts +32 -3
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +465 -92
- package/dist/search.d.ts +37 -8
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +116 -45
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +61 -0
- package/dist/shared.d.ts +11 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +368 -0
- package/dist/status.d.ts +6 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +76 -19
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +539 -200
- package/dist/turn.d.ts +7 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +45 -0
- package/dist/wire.d.ts +162 -19
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +82 -61
- package/package.json +31 -7
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
package/dist/memory.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { ROOM_CONTRACT_VERSION, } from './adapter.js';
|
|
2
|
-
import { MD_MODEL } from './collection.js';
|
|
3
1
|
import { sameChange } from './overlay.js';
|
|
4
2
|
const FIXTURE_RETENTION = {
|
|
5
3
|
history: { kind: 'duration', seconds: 1 },
|
|
6
|
-
outcome:
|
|
4
|
+
outcome: 604_800,
|
|
7
5
|
refreshHorizon: 1,
|
|
8
6
|
};
|
|
9
7
|
function declaredRetention(value) {
|
|
@@ -15,6 +13,19 @@ function declaredRetention(value) {
|
|
|
15
13
|
}
|
|
16
14
|
throw new Error('history retention duration must be a finite positive number of seconds');
|
|
17
15
|
}
|
|
16
|
+
const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
|
|
17
|
+
function modelsOf(room) {
|
|
18
|
+
return {
|
|
19
|
+
collection: room.model ?? MODEL_ABSENT,
|
|
20
|
+
...(room.typedSelection === undefined
|
|
21
|
+
? {}
|
|
22
|
+
: { selection: room.selectionModel ?? MODEL_ABSENT }),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function changedModels(room, from) {
|
|
26
|
+
const now = modelsOf(room);
|
|
27
|
+
return JSON.stringify(now) === JSON.stringify(modelsOf(from)) ? undefined : now;
|
|
28
|
+
}
|
|
18
29
|
function named(source, paths) {
|
|
19
30
|
const taken = {};
|
|
20
31
|
for (const path of paths) {
|
|
@@ -31,8 +42,6 @@ async function resolveScript(answer, fallback, request) {
|
|
|
31
42
|
}
|
|
32
43
|
export function createMemoryAdapter(options = {}) {
|
|
33
44
|
let rooms = options.rooms === undefined ? [] : [...options.rooms];
|
|
34
|
-
const mdModel = options.mdModel ?? MD_MODEL;
|
|
35
|
-
const supportedVersions = options.supportedVersions ?? [ROOM_CONTRACT_VERSION];
|
|
36
45
|
const capabilities = options.capabilities ?? [];
|
|
37
46
|
const providerLimits = options.providerLimits ?? [];
|
|
38
47
|
const retention = declaredRetention(options.retention);
|
|
@@ -46,8 +55,11 @@ export function createMemoryAdapter(options = {}) {
|
|
|
46
55
|
const scripted = new Map();
|
|
47
56
|
const unsealed = new Map();
|
|
48
57
|
const sealed = new Set();
|
|
58
|
+
const sentTurns = new Map();
|
|
49
59
|
const historyPageSize = options.historyPageSize;
|
|
50
|
-
let
|
|
60
|
+
let held = [];
|
|
61
|
+
let heldDemand = null;
|
|
62
|
+
let expiring = [];
|
|
51
63
|
let replicated = [];
|
|
52
64
|
let issued = 0;
|
|
53
65
|
function scriptConversations(entries) {
|
|
@@ -89,37 +101,43 @@ export function createMemoryAdapter(options = {}) {
|
|
|
89
101
|
return {
|
|
90
102
|
name: room.name,
|
|
91
103
|
locator: room.locator,
|
|
104
|
+
handle: room.handle,
|
|
92
105
|
roomVersion: room.roomVersion,
|
|
93
106
|
operations: room.operations,
|
|
94
107
|
replica: room.replica,
|
|
95
|
-
attachedModel: room.attachedModel,
|
|
96
108
|
...(room.typedSelection === undefined ? {} : { typedSelection: room.typedSelection }),
|
|
97
109
|
providerOwnedPaths: room.providerOwnedPaths,
|
|
98
110
|
};
|
|
99
111
|
}
|
|
100
|
-
function page(room,
|
|
112
|
+
function page(room, after) {
|
|
101
113
|
const paths = Object.keys(room.documents ?? {}).sort();
|
|
114
|
+
const opening = after === undefined;
|
|
115
|
+
const from = opening ? 0 : paths.filter((path) => path <= after).length;
|
|
102
116
|
const size = pageSize ?? paths.length;
|
|
103
117
|
const taken = paths.slice(from, from + size);
|
|
104
118
|
const next = from + taken.length;
|
|
105
|
-
const targets =
|
|
119
|
+
const targets = opening ? Object.keys(room.binaryFiles ?? {}) : [];
|
|
106
120
|
return {
|
|
107
121
|
kind: 'bootstrap',
|
|
108
122
|
roomVersion: room.roomVersion,
|
|
123
|
+
...(opening ? { models: modelsOf(room) } : {}),
|
|
109
124
|
documents: named(room.documents ?? {}, taken),
|
|
110
|
-
revisions: named(room.revisions ?? {}, taken),
|
|
125
|
+
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
126
|
+
...(room.fileIds === undefined
|
|
127
|
+
? {}
|
|
128
|
+
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
111
129
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
112
|
-
|
|
113
|
-
...(
|
|
114
|
-
...(next < paths.length ? { pageToken: String(next) } : {}),
|
|
130
|
+
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
131
|
+
...(next < paths.length ? { pageToken: taken.at(-1) } : {}),
|
|
115
132
|
};
|
|
116
133
|
}
|
|
117
134
|
function advancement(room, from, at) {
|
|
118
135
|
const current = room.documents ?? {};
|
|
119
136
|
const previous = from.documents ?? {};
|
|
120
|
-
const currentTargets = new Set(room.
|
|
121
|
-
const previousTargets = new Set(from.
|
|
137
|
+
const currentTargets = new Set(Object.keys(room.binaryFiles ?? {}));
|
|
138
|
+
const previousTargets = new Set(Object.keys(from.binaryFiles ?? {}));
|
|
122
139
|
const headMoved = (path) => room.revisions?.[path] !== from.revisions?.[path] ||
|
|
140
|
+
room.fileIds?.[path] !== from.fileIds?.[path] ||
|
|
123
141
|
!sameChange(room.changes?.[path], from.changes?.[path]);
|
|
124
142
|
const changed = Object.keys(current)
|
|
125
143
|
.filter((path) => current[path] !== previous[path] || headMoved(path))
|
|
@@ -134,22 +152,24 @@ export function createMemoryAdapter(options = {}) {
|
|
|
134
152
|
const targets = opening
|
|
135
153
|
? [...currentTargets].filter((target) => !previousTargets.has(target) || headMoved(target))
|
|
136
154
|
: [];
|
|
137
|
-
const
|
|
138
|
-
const declared = opening && JSON.stringify(attachments) !== JSON.stringify(from.attachments ?? []);
|
|
155
|
+
const models = opening ? changedModels(room, from) : undefined;
|
|
139
156
|
return {
|
|
140
157
|
kind: 'net-advancement',
|
|
141
158
|
roomVersion: room.roomVersion,
|
|
159
|
+
...(models === undefined ? {} : { models }),
|
|
142
160
|
documents: named(current, taken),
|
|
143
|
-
revisions: named(room.revisions ?? {}, taken),
|
|
161
|
+
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
162
|
+
...(room.fileIds === undefined
|
|
163
|
+
? {}
|
|
164
|
+
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
144
165
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
145
|
-
|
|
166
|
+
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
146
167
|
removals: opening
|
|
147
168
|
? [
|
|
148
169
|
...Object.keys(previous).filter((path) => !(path in current) && !currentTargets.has(path)),
|
|
149
170
|
...[...previousTargets].filter((target) => !currentTargets.has(target) && !(target in current)),
|
|
150
171
|
].sort()
|
|
151
172
|
: [],
|
|
152
|
-
...(declared ? { attachments } : {}),
|
|
153
173
|
...(pageToken === undefined ? {} : { pageToken }),
|
|
154
174
|
};
|
|
155
175
|
}
|
|
@@ -170,7 +190,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
170
190
|
function historiesOf(input) {
|
|
171
191
|
const asked = input?.conversations;
|
|
172
192
|
if (!Array.isArray(asked))
|
|
173
|
-
return { kind: 'rejected', code: 'invalid_request', fields: {} };
|
|
193
|
+
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
174
194
|
const histories = [];
|
|
175
195
|
for (const entry of asked) {
|
|
176
196
|
const conversation = typeof entry.conversation === 'string' ? scripted.get(entry.conversation) : undefined;
|
|
@@ -198,21 +218,32 @@ export function createMemoryAdapter(options = {}) {
|
|
|
198
218
|
const named = typeof input.conversation === 'string' ? input.conversation : '';
|
|
199
219
|
const conversation = scripted.get(named);
|
|
200
220
|
if (conversation === undefined) {
|
|
201
|
-
return {
|
|
221
|
+
return {
|
|
222
|
+
kind: 'rejected',
|
|
223
|
+
code: 'unknown-conversation',
|
|
224
|
+
fields: { conversation: named },
|
|
225
|
+
retryable: false,
|
|
226
|
+
};
|
|
202
227
|
}
|
|
203
228
|
const outcome = conversation.outcomes?.[name];
|
|
204
229
|
if (outcome !== undefined)
|
|
205
230
|
return outcome;
|
|
206
231
|
if (name === 'conversation.send') {
|
|
232
|
+
const operation = typeof input.operation_id === 'string' ? input.operation_id : null;
|
|
233
|
+
const answered = operation === null ? undefined : sentTurns.get(operation);
|
|
234
|
+
if (answered !== undefined)
|
|
235
|
+
return { kind: 'action', result: { turn: answered } };
|
|
207
236
|
issued += 1;
|
|
208
237
|
const turn = `turn-${issued}`;
|
|
209
238
|
unsealed.set(turn, named);
|
|
239
|
+
if (operation !== null)
|
|
240
|
+
sentTurns.set(operation, turn);
|
|
210
241
|
return { kind: 'action', result: { turn } };
|
|
211
242
|
}
|
|
212
243
|
if (name === 'conversation.cancel') {
|
|
213
244
|
const turn = typeof input.turn === 'string' ? input.turn : '';
|
|
214
245
|
if (sealed.has(turn) || !unsealed.has(turn)) {
|
|
215
|
-
return { kind: 'rejected', code: 'turn-sealed', fields: { turn } };
|
|
246
|
+
return { kind: 'rejected', code: 'turn-sealed', fields: { turn }, retryable: false };
|
|
216
247
|
}
|
|
217
248
|
unsealed.delete(turn);
|
|
218
249
|
return { kind: 'action', result: { turn, cancelled: true } };
|
|
@@ -221,18 +252,23 @@ export function createMemoryAdapter(options = {}) {
|
|
|
221
252
|
scripted.delete(named);
|
|
222
253
|
return { kind: 'action', result: { conversation: named } };
|
|
223
254
|
}
|
|
255
|
+
function announceList() {
|
|
256
|
+
const entries = [...scripted.values()].flatMap(({ conversation, listed }) => listed === undefined ? [] : [{ conversation, ...listed }]);
|
|
257
|
+
for (const listener of listeners)
|
|
258
|
+
listener({ kind: 'list', entries });
|
|
259
|
+
}
|
|
224
260
|
function discovery() {
|
|
225
261
|
return {
|
|
226
262
|
kind: 'discovery',
|
|
227
|
-
supportedVersions,
|
|
228
|
-
mdModel,
|
|
229
263
|
rooms: rooms.map(declared),
|
|
230
264
|
capabilities,
|
|
231
265
|
providerLimits,
|
|
232
266
|
retention,
|
|
267
|
+
...(options.member === undefined ? {} : { member: options.member }),
|
|
233
268
|
};
|
|
234
269
|
}
|
|
235
270
|
return {
|
|
271
|
+
...(options.exhaustiveDiscovery === undefined ? {} : { exhaustiveDiscovery: true }),
|
|
236
272
|
setRooms(next) {
|
|
237
273
|
rooms = [...next];
|
|
238
274
|
retain(rooms);
|
|
@@ -240,9 +276,21 @@ export function createMemoryAdapter(options = {}) {
|
|
|
240
276
|
setConversations(next) {
|
|
241
277
|
scriptConversations(next);
|
|
242
278
|
},
|
|
243
|
-
|
|
279
|
+
open() {
|
|
280
|
+
announceList();
|
|
281
|
+
for (const observer of observers)
|
|
282
|
+
observer({ kind: 'opened' });
|
|
283
|
+
},
|
|
284
|
+
close(revoked = false) {
|
|
244
285
|
for (const observer of observers)
|
|
245
|
-
observer(
|
|
286
|
+
observer({ kind: 'closed', revoked });
|
|
287
|
+
},
|
|
288
|
+
expire(locators) {
|
|
289
|
+
expiring = [...locators];
|
|
290
|
+
},
|
|
291
|
+
notifyRoomVersion({ locator, roomVersion }) {
|
|
292
|
+
for (const observer of observers)
|
|
293
|
+
observer({ kind: 'room-version', locator, roomVersion });
|
|
246
294
|
},
|
|
247
295
|
notifyConversation(event) {
|
|
248
296
|
if (event.kind === 'accepted-message') {
|
|
@@ -256,8 +304,11 @@ export function createMemoryAdapter(options = {}) {
|
|
|
256
304
|
for (const observer of modeObservers)
|
|
257
305
|
observer(mode);
|
|
258
306
|
},
|
|
259
|
-
|
|
260
|
-
return
|
|
307
|
+
heldRooms() {
|
|
308
|
+
return held;
|
|
309
|
+
},
|
|
310
|
+
heldDemand() {
|
|
311
|
+
return heldDemand;
|
|
261
312
|
},
|
|
262
313
|
replicatedConversations() {
|
|
263
314
|
return replicated;
|
|
@@ -281,12 +332,47 @@ export function createMemoryAdapter(options = {}) {
|
|
|
281
332
|
};
|
|
282
333
|
},
|
|
283
334
|
},
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
335
|
+
roomStream: {
|
|
336
|
+
hold(asked, demand) {
|
|
337
|
+
held = asked.map((room) => room.locator);
|
|
338
|
+
heldDemand = demand;
|
|
339
|
+
const expired = expiring.filter((locator) => held.includes(locator));
|
|
340
|
+
expiring = [];
|
|
341
|
+
const moved = asked.flatMap((room) => {
|
|
342
|
+
const current = rooms.find((entry) => entry.locator === room.locator);
|
|
343
|
+
return current === undefined ||
|
|
344
|
+
expired.includes(room.locator) ||
|
|
345
|
+
current.roomVersion === room.roomVersion
|
|
346
|
+
? []
|
|
347
|
+
: [{ locator: room.locator, roomVersion: current.roomVersion }];
|
|
348
|
+
});
|
|
349
|
+
queueMicrotask(() => {
|
|
350
|
+
for (const observer of observers) {
|
|
351
|
+
for (const room of moved)
|
|
352
|
+
observer({ kind: 'room-version', ...room });
|
|
353
|
+
observer({ kind: 'opening', expired });
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
},
|
|
357
|
+
reopen() {
|
|
358
|
+
queueMicrotask(() => {
|
|
359
|
+
for (const observer of observers)
|
|
360
|
+
observer({ kind: 'closed', revoked: false });
|
|
361
|
+
});
|
|
287
362
|
},
|
|
363
|
+
published() { },
|
|
288
364
|
observe(notify) {
|
|
289
365
|
observers.add(notify);
|
|
366
|
+
queueMicrotask(() => {
|
|
367
|
+
if (!observers.has(notify))
|
|
368
|
+
return;
|
|
369
|
+
if (options.unopened === true) {
|
|
370
|
+
notify({ kind: 'closed', revoked: false });
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
announceList();
|
|
374
|
+
notify({ kind: 'opened' });
|
|
375
|
+
});
|
|
290
376
|
return () => {
|
|
291
377
|
observers.delete(notify);
|
|
292
378
|
};
|
|
@@ -298,13 +384,6 @@ export function createMemoryAdapter(options = {}) {
|
|
|
298
384
|
else
|
|
299
385
|
scripts[operation] = answer;
|
|
300
386
|
},
|
|
301
|
-
async model(_authorization, request) {
|
|
302
|
-
return resolveScript(scripts.model, () => {
|
|
303
|
-
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
304
|
-
const answer = request.attached === 'collection' ? room?.model : room?.selectionModel;
|
|
305
|
-
return answer ?? { kind: 'model-unavailable', reason: 'not-readable' };
|
|
306
|
-
}, request);
|
|
307
|
-
},
|
|
308
387
|
async authorize() {
|
|
309
388
|
return resolveScript(scripts.authorize, () => ({}), undefined);
|
|
310
389
|
},
|
|
@@ -317,13 +396,21 @@ export function createMemoryAdapter(options = {}) {
|
|
|
317
396
|
});
|
|
318
397
|
},
|
|
319
398
|
reached,
|
|
399
|
+
follows(locator, roomVersion, next) {
|
|
400
|
+
const scripted = scripts.follows;
|
|
401
|
+
if (typeof scripted === 'boolean')
|
|
402
|
+
return scripted;
|
|
403
|
+
if (scripted !== undefined)
|
|
404
|
+
return scripted(locator, roomVersion, next);
|
|
405
|
+
return true;
|
|
406
|
+
},
|
|
320
407
|
async bootstrap(_authorization, request) {
|
|
321
408
|
return resolveScript(scripts.bootstrap, () => {
|
|
322
409
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
323
410
|
if (room === undefined) {
|
|
324
411
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
325
412
|
}
|
|
326
|
-
return page(room, request.pageToken
|
|
413
|
+
return page(room, request.pageToken);
|
|
327
414
|
}, request).then((answer) => note(request.locator, answer));
|
|
328
415
|
},
|
|
329
416
|
async refresh(_authorization, request) {
|
|
@@ -341,10 +428,6 @@ export function createMemoryAdapter(options = {}) {
|
|
|
341
428
|
}
|
|
342
429
|
return advancement(continuation.room, continuation.from, continuation.at);
|
|
343
430
|
}
|
|
344
|
-
if (request.minPosition !== undefined &&
|
|
345
|
-
!reached(room.locator, room.roomVersion, request.minPosition)) {
|
|
346
|
-
return { kind: 'retryable-refusal', code: 'replica_behind', fields: {} };
|
|
347
|
-
}
|
|
348
431
|
if (request.fromRoomVersion === room.roomVersion) {
|
|
349
432
|
return { kind: 'still-current' };
|
|
350
433
|
}
|
|
@@ -360,7 +443,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
360
443
|
if (room === undefined) {
|
|
361
444
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
362
445
|
}
|
|
363
|
-
return {
|
|
446
|
+
return {
|
|
447
|
+
kind: 'rejected',
|
|
448
|
+
code: 'unscripted-mutation',
|
|
449
|
+
fields: {},
|
|
450
|
+
retryable: false,
|
|
451
|
+
affected: {},
|
|
452
|
+
};
|
|
364
453
|
}, request).then((answer) => note(request.locator, answer));
|
|
365
454
|
},
|
|
366
455
|
async history(_authorization, request) {
|
|
@@ -375,11 +464,35 @@ export function createMemoryAdapter(options = {}) {
|
|
|
375
464
|
};
|
|
376
465
|
}, request);
|
|
377
466
|
},
|
|
467
|
+
async binary(_authorization, request) {
|
|
468
|
+
return resolveScript(scripts.binary, () => {
|
|
469
|
+
if (request.kind === 'reference') {
|
|
470
|
+
return { kind: 'rejected', code: 'unscripted-binary', fields: {}, retryable: false };
|
|
471
|
+
}
|
|
472
|
+
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
473
|
+
if (room === undefined)
|
|
474
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
475
|
+
const blob = room.blobs?.[request.path];
|
|
476
|
+
return blob === undefined
|
|
477
|
+
? { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false }
|
|
478
|
+
: { kind: 'binary', blob };
|
|
479
|
+
}, request);
|
|
480
|
+
},
|
|
481
|
+
referrerScope(referrer) {
|
|
482
|
+
if (typeof referrer !== 'object' || referrer === null)
|
|
483
|
+
return null;
|
|
484
|
+
const { room, path, message } = referrer;
|
|
485
|
+
if (typeof message === 'string')
|
|
486
|
+
return { kind: 'conversations' };
|
|
487
|
+
if (typeof room !== 'string')
|
|
488
|
+
return null;
|
|
489
|
+
return { kind: 'room', locator: room, ...(typeof path === 'string' ? { path } : {}) };
|
|
490
|
+
},
|
|
378
491
|
async action(_authorization, request) {
|
|
379
492
|
return resolveScript(scripts.action, () => {
|
|
380
493
|
if (request.name.startsWith('conversation.'))
|
|
381
494
|
return conversationAction(request);
|
|
382
|
-
return { kind: 'rejected', code: 'unscripted-action', fields: {} };
|
|
495
|
+
return { kind: 'rejected', code: 'unscripted-action', fields: {}, retryable: false };
|
|
383
496
|
}, request).then((answer) => {
|
|
384
497
|
if (answer.kind === 'action' && answer.at !== undefined)
|
|
385
498
|
note(answer.at.locator, answer.at);
|
package/dist/model.d.ts
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
import type { Definition,
|
|
1
|
+
import type { Definition, ValueFacts, VerifiedModel } from '@agentshouse/mdmodel';
|
|
2
|
+
import type { Open } from './open.js';
|
|
2
3
|
export type ModelIdentity = {
|
|
3
4
|
identity: string;
|
|
4
5
|
version: string;
|
|
5
6
|
};
|
|
6
7
|
export type ModelSnapshot = ModelIdentity & {
|
|
7
8
|
schema: string | null;
|
|
9
|
+
revision: string | null;
|
|
8
10
|
};
|
|
9
|
-
export type ModelUnavailableReason = 'not-readable' | 'revoked' | 'not-acquired' | '
|
|
11
|
+
export type ModelUnavailableReason = Open<'not-readable' | 'revoked' | 'not-acquired' | 'invalid'>;
|
|
10
12
|
export type ModelResult = {
|
|
11
13
|
kind: 'model';
|
|
12
14
|
snapshot: ModelSnapshot;
|
|
13
15
|
} | {
|
|
14
16
|
kind: 'model-unavailable';
|
|
15
17
|
reason: ModelUnavailableReason;
|
|
16
|
-
} | {
|
|
17
|
-
kind: 'transport-uncertainty';
|
|
18
|
-
} | {
|
|
19
|
-
kind: 'revoked-authorization';
|
|
20
|
-
};
|
|
21
|
-
export type MdType = {
|
|
22
|
-
name: string;
|
|
23
|
-
fields: Readonly<Record<string, FieldSpec>>;
|
|
24
|
-
sections: Readonly<Record<string, SectionSpec>>;
|
|
25
18
|
};
|
|
19
|
+
export type MdType = Definition;
|
|
26
20
|
export type ModelState = {
|
|
27
21
|
status: 'unavailable';
|
|
28
22
|
reason: ModelUnavailableReason;
|
|
23
|
+
schema?: string | null;
|
|
24
|
+
revision?: string | null;
|
|
29
25
|
} | {
|
|
30
26
|
status: 'current' | 'cached';
|
|
31
27
|
snapshot: ModelSnapshot;
|
|
@@ -33,23 +29,30 @@ export type ModelState = {
|
|
|
33
29
|
types: VerifiedModel['types'];
|
|
34
30
|
};
|
|
35
31
|
export type TypesResult = {
|
|
36
|
-
status: 'unavailable'
|
|
32
|
+
status: Open<'unavailable'>;
|
|
37
33
|
reason: ModelUnavailableReason;
|
|
34
|
+
types: null;
|
|
35
|
+
schema?: string | null;
|
|
36
|
+
revision?: string | null;
|
|
38
37
|
} | {
|
|
39
|
-
status: 'current' | 'cached'
|
|
38
|
+
status: Open<'current' | 'cached'>;
|
|
40
39
|
identity: string;
|
|
41
40
|
version: string;
|
|
42
41
|
verifiedWith: ModelIdentity;
|
|
43
42
|
types: readonly MdType[];
|
|
43
|
+
schema: string | null;
|
|
44
|
+
revision: string | null;
|
|
44
45
|
};
|
|
45
46
|
export type ValidationReceipt = {
|
|
46
47
|
identity: string;
|
|
47
48
|
version: string;
|
|
48
|
-
source: 'current' | 'cached'
|
|
49
|
+
source: Open<'current' | 'cached'>;
|
|
49
50
|
};
|
|
50
51
|
export declare const NO_MODEL: ModelState;
|
|
51
52
|
export declare function definitionOf(state: ModelState, type: string | undefined): Definition | undefined;
|
|
52
53
|
export declare function modelTypes(state: ModelState): TypesResult;
|
|
53
54
|
export declare function cached(state: ModelState): ModelState;
|
|
54
55
|
export declare function sameModel(left: ModelIdentity, right: ModelIdentity): boolean;
|
|
56
|
+
export declare function sameTyping(left: ModelState, right: ModelState): boolean;
|
|
57
|
+
export declare function referenceField(facts: ValueFacts | undefined): boolean;
|
|
55
58
|
//# sourceMappingURL=model.d.ts.map
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAC/F,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,cAAc,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,CAAC,CAAC;AACnG,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,aAAa,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC;AAChC,MAAM,MAAM,UAAU,GAClB;IACE,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,sBAAsB,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,GACD;IACE,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,QAAQ,EAAE,aAAa,CAAC;IACxB,YAAY,EAAE,aAAa,CAAC;IAC5B,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CAC/B,CAAC;AACN,MAAM,MAAM,WAAW,GACnB;IACE,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC5B,MAAM,EAAE,sBAAsB,CAAC;IAC/B,KAAK,EAAE,IAAI,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,GACD;IACE,MAAM,EAAE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,aAAa,CAAC;IAC5B,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AACN,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,CAAC;CACpC,CAAC;AACF,eAAO,MAAM,QAAQ,EAAE,UAA8D,CAAC;AACtF,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAGhG;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAgBzD;AACD,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAEpD;AACD,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAE5E;AACD,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CASvE;AACD,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAErE"}
|
package/dist/model.js
CHANGED
|
@@ -6,15 +6,15 @@ export function definitionOf(state, type) {
|
|
|
6
6
|
}
|
|
7
7
|
export function modelTypes(state) {
|
|
8
8
|
return state.status === 'unavailable'
|
|
9
|
-
? { ...state }
|
|
9
|
+
? { ...state, types: null }
|
|
10
10
|
: {
|
|
11
11
|
status: state.status,
|
|
12
12
|
identity: state.snapshot.identity,
|
|
13
13
|
version: state.snapshot.version,
|
|
14
14
|
verifiedWith: { ...state.verifiedWith },
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
schema: state.snapshot.schema,
|
|
16
|
+
revision: state.snapshot.revision,
|
|
17
|
+
types: structuredClone(Object.values(state.types).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0)),
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
export function cached(state) {
|
|
@@ -23,3 +23,15 @@ export function cached(state) {
|
|
|
23
23
|
export function sameModel(left, right) {
|
|
24
24
|
return left.identity === right.identity && left.version === right.version;
|
|
25
25
|
}
|
|
26
|
+
export function sameTyping(left, right) {
|
|
27
|
+
if (left === right)
|
|
28
|
+
return true;
|
|
29
|
+
if (left.status === 'unavailable' || right.status === 'unavailable') {
|
|
30
|
+
return left.status === right.status;
|
|
31
|
+
}
|
|
32
|
+
return (left.snapshot.schema === right.snapshot.schema &&
|
|
33
|
+
sameModel(left.verifiedWith, right.verifiedWith));
|
|
34
|
+
}
|
|
35
|
+
export function referenceField(facts) {
|
|
36
|
+
return facts?.reference !== undefined || facts?.items?.reference !== undefined;
|
|
37
|
+
}
|
package/dist/observation.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { QueryDocument, QueryGroup, QueryResult } from './query.js';
|
|
1
|
+
import type { QueryCoverage, QueryDocument, QueryGroup, QueryResult } from './query.js';
|
|
2
2
|
export type Observation<T> = {
|
|
3
3
|
current(): T;
|
|
4
4
|
subscribe(listener: (value: T) => void): () => void;
|
|
@@ -13,13 +13,18 @@ export type QueryChange = {
|
|
|
13
13
|
changed: readonly (readonly [RowKey, QueryDocument | QueryGroup])[];
|
|
14
14
|
removed: readonly RowKey[];
|
|
15
15
|
order: readonly RowKey[] | null;
|
|
16
|
+
coverage?: QueryCoverage;
|
|
16
17
|
};
|
|
18
|
+
export type QueryMessage = KeyedResult | QueryChange;
|
|
17
19
|
export type Observed = {
|
|
18
20
|
observation: Observation<unknown>;
|
|
19
21
|
receive(message: unknown): void;
|
|
20
22
|
end(): void;
|
|
21
23
|
};
|
|
22
24
|
export declare function rowsOf(result: QueryResult): readonly (QueryDocument | QueryGroup)[];
|
|
25
|
+
export declare function whole(message: QueryMessage): message is KeyedResult;
|
|
26
|
+
export declare function applied(keyed: KeyedResult, message: QueryMessage): KeyedResult;
|
|
23
27
|
export declare function observed(first: unknown, stop: () => void, keyed: boolean): Observed;
|
|
24
28
|
export declare function opened(watch: (deliver: (message: unknown) => void) => () => void, keyed: boolean): Promise<Observation<unknown>>;
|
|
29
|
+
export declare function observing<Topic extends string>(watch: (topic: Topic, input: readonly unknown[], deliver: (message: unknown) => void) => () => void): (topic: Topic, ...input: unknown[]) => Promise<Observation<unknown>>;
|
|
25
30
|
//# sourceMappingURL=observation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../src/observation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAExF,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,OAAO,IAAI,CAAC,CAAC;IACb,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACpD,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAErC,MAAM,MAAM,WAAW,GAAG;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAE3E,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC;IACpE,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,WAAW,CAAC;AAErD,MAAM,MAAM,QAAQ,GAAG;IACrB,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,GAAG,IAAI,IAAI,CAAC;CACb,CAAC;AAEF,wBAAgB,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC,aAAa,GAAG,UAAU,CAAC,EAAE,CAGnF;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,IAAI,WAAW,CAEnE;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,GAAG,WAAW,CAkB9E;AAiBD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,QAAQ,CAkCnF;AAED,wBAAgB,MAAM,CACpB,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAAK,MAAM,IAAI,EAC1D,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAiB/B;AAED,wBAAgB,SAAS,CAAC,KAAK,SAAS,MAAM,EAC5C,KAAK,EAAE,CACL,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAChC,MAAM,IAAI,WAEA,KAAK,YAAY,OAAO,EAAE,KAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAQ1E"}
|
package/dist/observation.js
CHANGED
|
@@ -1,32 +1,48 @@
|
|
|
1
1
|
export function rowsOf(result) {
|
|
2
|
-
|
|
2
|
+
if ('groups' in result)
|
|
3
|
+
return result.groups;
|
|
4
|
+
return 'documents' in result ? result.documents : [];
|
|
5
|
+
}
|
|
6
|
+
export function whole(message) {
|
|
7
|
+
return 'result' in message;
|
|
8
|
+
}
|
|
9
|
+
export function applied(keyed, message) {
|
|
10
|
+
if (whole(message))
|
|
11
|
+
return message;
|
|
12
|
+
const result = keyed.result;
|
|
13
|
+
if ('pending' in result)
|
|
14
|
+
return keyed;
|
|
15
|
+
const rows = rowsOf(result);
|
|
16
|
+
const byKey = new Map(keyed.keys.map((key, index) => [key, rows[index]]));
|
|
17
|
+
for (const key of message.removed)
|
|
18
|
+
byKey.delete(key);
|
|
19
|
+
for (const [key, row] of message.changed)
|
|
20
|
+
byKey.set(key, row);
|
|
21
|
+
const keys = message.order ?? keyed.keys.filter((key) => byKey.has(key));
|
|
22
|
+
const next = keys.map((key) => byKey.get(key));
|
|
23
|
+
const coverage = message.coverage ?? result.coverage;
|
|
24
|
+
return {
|
|
25
|
+
result: 'groups' in result
|
|
26
|
+
? { groups: next, coverage }
|
|
27
|
+
: { documents: next, coverage },
|
|
28
|
+
keys,
|
|
29
|
+
};
|
|
3
30
|
}
|
|
4
31
|
function keyedResult(first) {
|
|
5
|
-
|
|
6
|
-
const rows = rowsOf(first.result);
|
|
7
|
-
const byKey = new Map(first.keys.map((key, index) => [key, rows[index]]));
|
|
8
|
-
let keys = first.keys;
|
|
32
|
+
let keyed = first;
|
|
9
33
|
return {
|
|
10
34
|
value: first.result,
|
|
11
35
|
next(message) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
byKey.delete(key);
|
|
15
|
-
for (const [key, row] of change.changed)
|
|
16
|
-
byKey.set(key, row);
|
|
17
|
-
keys = change.order ?? keys.filter((key) => byKey.has(key));
|
|
18
|
-
const next = keys.map((key) => byKey.get(key));
|
|
19
|
-
return grouped
|
|
20
|
-
? { groups: next }
|
|
21
|
-
: { documents: next };
|
|
36
|
+
keyed = applied(keyed, message);
|
|
37
|
+
return keyed.result;
|
|
22
38
|
},
|
|
23
39
|
};
|
|
24
40
|
}
|
|
25
|
-
function
|
|
41
|
+
function replaced(first) {
|
|
26
42
|
return { value: first, next: (message) => message };
|
|
27
43
|
}
|
|
28
44
|
export function observed(first, stop, keyed) {
|
|
29
|
-
const reducer = keyed ? keyedResult(first) :
|
|
45
|
+
const reducer = keyed ? keyedResult(first) : replaced(first);
|
|
30
46
|
let value = reducer.value;
|
|
31
47
|
let open = true;
|
|
32
48
|
const listeners = new Set();
|
|
@@ -83,3 +99,8 @@ export function opened(watch, keyed) {
|
|
|
83
99
|
}
|
|
84
100
|
});
|
|
85
101
|
}
|
|
102
|
+
export function observing(watch) {
|
|
103
|
+
return (topic, ...input) => opened((deliver) => watch(topic, input, (message) => {
|
|
104
|
+
deliver(structuredClone(message));
|
|
105
|
+
}), topic === 'query');
|
|
106
|
+
}
|
package/dist/open.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open.d.ts","sourceRoot":"","sources":["../src/open.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,CAAC,KAAK,SAAS,MAAM,IAAI,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC"}
|
package/dist/open.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|