@agentshouse/mdruntime 0.1.0-cd71aba4d0215 → 0.1.0-cd8d184c6fbe0
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 +32 -22
- 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 +1 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +135 -55
- package/dist/adapter.d.ts +168 -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 +15 -14
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +21 -9
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +19 -8
- package/dist/conversation-row.d.ts +20 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +30 -7
- package/dist/conversation.d.ts +30 -12
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +273 -193
- 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 +30 -8
- 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 +2 -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.map +1 -1
- package/dist/failure.js +3 -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 +77 -31
- 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 +23 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -7
- package/dist/install.d.ts +9 -3
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +44 -46
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +42 -29
- 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 +21 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +43 -13
- 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 +30 -13
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +21 -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 +1 -1
- 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 +1 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +17 -6
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +2 -1
- 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/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 +98 -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 +92 -0
- package/dist/runtime.d.ts +5 -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 +10 -3
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +29 -6
- 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 +6 -4
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +10 -9
- package/dist/source.d.ts +18 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +36 -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 +15 -10
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +12 -5
- 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 +52 -35
- 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/client.js
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { handedCopy, handedLink } from './download.js';
|
|
2
2
|
import { pageMetadataBlock } from './page-metadata.js';
|
|
3
|
-
import { observed } from './observation.js';
|
|
3
|
+
import { appRooms, observed } from './observation.js';
|
|
4
4
|
import { runtimeError } from './failure.js';
|
|
5
|
+
import { attachmentBlob, } from './outcome.js';
|
|
5
6
|
import { AUTHORIZATION_ENDED, PORT_CLOSED, wireAnswer, } from './wire.js';
|
|
6
7
|
// React renders an arrived value in a later task and opens what that render observes as it commits, so this many frames opening nothing mean the page drew what it observes.
|
|
7
8
|
const SETTLED_FRAMES = 2;
|
|
8
|
-
// A browser reads a download's address only after the click that hands it returns, so a copy's address is released a minute later.
|
|
9
|
-
const HANDED_COPY_MS = 60_000;
|
|
10
|
-
const PAGE = /\.html?$/iu;
|
|
11
|
-
const STARTED = { kind: 'started' };
|
|
12
|
-
const BLOCKED = {
|
|
13
|
-
kind: 'blocked',
|
|
14
|
-
code: 'popup-blocked',
|
|
15
|
-
fields: {},
|
|
16
|
-
retryable: true,
|
|
17
|
-
};
|
|
18
|
-
function handed(url, name) {
|
|
19
|
-
const anchor = document.createElement('a');
|
|
20
|
-
anchor.href = url;
|
|
21
|
-
anchor.download = name;
|
|
22
|
-
anchor.click();
|
|
23
|
-
}
|
|
24
9
|
function refused(refusal) {
|
|
25
10
|
return runtimeError(refusal.code);
|
|
26
11
|
}
|
|
@@ -42,7 +27,7 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
42
27
|
observations.delete(id);
|
|
43
28
|
if (refusal === null)
|
|
44
29
|
send({ kind: 'stop', id });
|
|
45
|
-
}, topic
|
|
30
|
+
}, topic);
|
|
46
31
|
observations.set(id, { topic, input, handle });
|
|
47
32
|
return handle.observation;
|
|
48
33
|
}
|
|
@@ -90,7 +75,7 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
90
75
|
}
|
|
91
76
|
if (message.kind === 'ended') {
|
|
92
77
|
for (const { topic, handle } of observations.values()) {
|
|
93
|
-
if (topic === 'member')
|
|
78
|
+
if (topic === 'member' || topic === 'time-zone')
|
|
94
79
|
handle.receive(null);
|
|
95
80
|
}
|
|
96
81
|
end(runtimeError('authorization-ended', AUTHORIZATION_ENDED));
|
|
@@ -160,12 +145,12 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
160
145
|
let received = 0;
|
|
161
146
|
const stream = new ReadableStream({
|
|
162
147
|
async pull(controller) {
|
|
163
|
-
const bytes = await ask('
|
|
148
|
+
const bytes = await ask('attachment.part', [file, part]);
|
|
164
149
|
if (bytes === null) {
|
|
165
150
|
if (received === byteLength)
|
|
166
151
|
controller.close();
|
|
167
152
|
else
|
|
168
|
-
controller.error(runtimeError('
|
|
153
|
+
controller.error(runtimeError('attachment-absent', 'The file ended early'));
|
|
169
154
|
return;
|
|
170
155
|
}
|
|
171
156
|
part += 1;
|
|
@@ -176,32 +161,13 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
176
161
|
return { kind: 'binary', stream, byteLength, mediaType };
|
|
177
162
|
}
|
|
178
163
|
async function download(room, path, revision) {
|
|
179
|
-
const
|
|
180
|
-
const linked = await ask('binaryFile.link', [room, path, revision]);
|
|
181
|
-
if (linked.kind === 'link' && PAGE.test(linked.name)) {
|
|
182
|
-
const away = tab ?? globalThis.open('', '_blank');
|
|
183
|
-
if (away === null)
|
|
184
|
-
return BLOCKED;
|
|
185
|
-
away.location.replace(linked.url);
|
|
186
|
-
return STARTED;
|
|
187
|
-
}
|
|
188
|
-
tab?.close();
|
|
189
|
-
if (linked.kind === 'link') {
|
|
190
|
-
handed(linked.url, linked.name);
|
|
191
|
-
return STARTED;
|
|
192
|
-
}
|
|
164
|
+
const linked = await handedLink(path, () => ask('attachment.link', [room, path, revision]));
|
|
193
165
|
if (linked.kind !== 'absent')
|
|
194
166
|
return linked;
|
|
195
|
-
const read = streamed(await ask('
|
|
167
|
+
const read = streamed(await ask('attachment.read', [room, path, revision]));
|
|
196
168
|
if (read.kind !== 'binary')
|
|
197
169
|
return read;
|
|
198
|
-
|
|
199
|
-
headers: { 'content-type': read.mediaType },
|
|
200
|
-
}).blob();
|
|
201
|
-
const url = URL.createObjectURL(copy);
|
|
202
|
-
handed(url, path.slice(path.lastIndexOf('/') + 1));
|
|
203
|
-
setTimeout(() => URL.revokeObjectURL(url), HANDED_COPY_MS);
|
|
204
|
-
return STARTED;
|
|
170
|
+
return handedCopy(await attachmentBlob(read), path.slice(path.lastIndexOf('/') + 1));
|
|
205
171
|
}
|
|
206
172
|
function settled() {
|
|
207
173
|
if (settling !== null)
|
|
@@ -232,12 +198,12 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
232
198
|
});
|
|
233
199
|
return settling;
|
|
234
200
|
}
|
|
235
|
-
|
|
236
|
-
return shownBy(show, {
|
|
201
|
+
return {
|
|
237
202
|
buildFile,
|
|
238
|
-
rooms: () => ask('rooms', []),
|
|
203
|
+
rooms: () => ask('rooms', []).then(appRooms),
|
|
239
204
|
query: ((query) => ask('query', [query])),
|
|
240
205
|
search: (request) => ask('search', [request]),
|
|
206
|
+
queryHouse: (query, options) => ask('queryHouse', options === undefined ? [query] : [query, options]),
|
|
241
207
|
types: (locator) => ask('types', [locator]),
|
|
242
208
|
roomDraft: {
|
|
243
209
|
list: () => ask('roomDraft.list', []),
|
|
@@ -264,12 +230,13 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
264
230
|
takeOut: (conversation, message, operation) => ask('conversation.takeOut', [conversation, message, operation]),
|
|
265
231
|
decide: (request, decision, operation) => ask('conversation.decide', [request, decision, operation]),
|
|
266
232
|
rename: (conversation, name, operation) => ask('conversation.rename', [conversation, name, operation]),
|
|
267
|
-
|
|
233
|
+
set: (conversation, settings, operation) => ask('conversation.set', [conversation, settings, operation]),
|
|
268
234
|
retry: (conversation, message, operation) => ask('conversation.retry', [conversation, message, operation]),
|
|
269
|
-
pins: () => ask('conversation.pins', []),
|
|
270
235
|
pin: (figures) => ask('conversation.pin', [figures]),
|
|
271
|
-
openedTurns: () => ask('conversation.openedTurns', []),
|
|
272
236
|
openTurn: (conversation, turn) => ask('conversation.openTurn', [conversation, turn]),
|
|
237
|
+
dismissSuggestion: (conversation, suggestion) => ask('conversation.dismissSuggestion', [conversation, suggestion]),
|
|
238
|
+
attach: (file) => ask('conversation.attach', [file]),
|
|
239
|
+
attachment: (link) => ask('conversation.attachment', [link]),
|
|
273
240
|
pageMetadata: async (app, address) => pageMetadataBlock(app, address, [...observations]
|
|
274
241
|
.sort(([left], [right]) => left - right)
|
|
275
242
|
.flatMap(([, { topic, input }]) => (topic === 'query' ? [input[0]] : []))),
|
|
@@ -277,28 +244,31 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
277
244
|
chatDraft: {
|
|
278
245
|
write: (conversation, draft, revision) => ask('chatDraft.write', [conversation, draft, revision]),
|
|
279
246
|
prepend: (conversation, draft) => ask('chatDraft.prepend', [conversation, draft]),
|
|
247
|
+
append: (conversation, draft) => ask('chatDraft.append', [conversation, draft]),
|
|
280
248
|
discard: (conversation) => ask('chatDraft.discard', [conversation]),
|
|
281
249
|
},
|
|
282
250
|
history: (locator, path, query) => ask('history', [locator, path, query]),
|
|
283
251
|
resolve: (room, path, destination) => ask('resolve', [room, path, destination]),
|
|
284
|
-
|
|
285
|
-
read: (room, path, revision) => ask('
|
|
286
|
-
|
|
252
|
+
attachment: {
|
|
253
|
+
read: (room, path, revision) => ask('attachment.read', [room, path, revision]).then((read) => streamed(read)),
|
|
254
|
+
show: (room, path, revision) => ask('attachment.show', [room, path, revision]).then((shown) => streamed(shown)),
|
|
255
|
+
attach: (room, file) => ask('attachment.attach', [room, file]),
|
|
287
256
|
download,
|
|
288
257
|
},
|
|
289
258
|
call: (name, input) => ask('call', [name, input]),
|
|
259
|
+
answered: (operation) => ask('answered', [operation]),
|
|
290
260
|
reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
|
|
291
|
-
log: () => ask('log', []),
|
|
292
261
|
persistence: () => ask('persistence', []),
|
|
293
262
|
retry: () => ask('retry', []),
|
|
294
263
|
cleanUp: () => ask('cleanUp', []),
|
|
295
264
|
unsent: () => ask('unsent', []),
|
|
265
|
+
sent: () => ask('sent', []),
|
|
296
266
|
reset: () => ask('reset', []),
|
|
297
267
|
readAgain: () => ask('readAgain', []),
|
|
298
268
|
observe: ((topic, ...input) => watch(topic, input)),
|
|
299
269
|
reauthorize: () => ask('reauthorize', []),
|
|
300
270
|
settled,
|
|
301
|
-
}
|
|
271
|
+
};
|
|
302
272
|
}
|
|
303
273
|
const turns = new WeakMap();
|
|
304
274
|
export function inTurn(client, work) {
|
|
@@ -308,5 +278,7 @@ export function inTurn(client, work) {
|
|
|
308
278
|
}
|
|
309
279
|
export { chainedWindows } from './chain.js';
|
|
310
280
|
export { roomDraftRevision } from './identity.js';
|
|
311
|
-
export {
|
|
312
|
-
export {
|
|
281
|
+
export { atAddress, importedFile } from './loaded.js';
|
|
282
|
+
export { defineRoomMedia, ROOM_MEDIA, viewFile } from './media.js';
|
|
283
|
+
export { shownModal } from './modal.js';
|
|
284
|
+
export { unanswered, undelivered } from './wire.js';
|
package/dist/collection.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DefinitionOf, type Document, type TypedPath } from '@agentshouse/mdmodel';
|
|
1
|
+
import { type DefinitionOf, type Document, type ParseResult, type TypedPath, type VerifiedModel } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { ModelState, TypesResult } from './model.js';
|
|
3
3
|
import type { AppTypedSelection } from './listing.js';
|
|
4
4
|
import type { MdModelIdentity } from './adapter.js';
|
|
@@ -20,6 +20,7 @@ export type Composed = {
|
|
|
20
20
|
readonly composition: Composition;
|
|
21
21
|
readonly fingerprint: string;
|
|
22
22
|
};
|
|
23
|
+
export declare function typesPrint(types: VerifiedModel['types']): string;
|
|
23
24
|
export declare function composedOf(composition: Composition): Composed;
|
|
24
25
|
type Selecting<M> = {
|
|
25
26
|
readonly model: M;
|
|
@@ -42,6 +43,10 @@ export declare function definitionsIn(room: {
|
|
|
42
43
|
export declare function collectionOf(text: Readonly<Record<string, string>>, composition: Composition): Collection;
|
|
43
44
|
export declare function documentsOf(collection: Collection): Generator<number, Iterable<readonly [string, Document]>, void>;
|
|
44
45
|
export declare function validRoot(root: unknown): root is string;
|
|
46
|
+
export declare const UNTYPED = "any";
|
|
47
|
+
export declare function textType(read: ParseResult): string | undefined;
|
|
48
|
+
export declare function typeAt(composition: Composition, path: string, read: ParseResult): string | undefined;
|
|
49
|
+
export declare function typedText(read: ParseResult): boolean;
|
|
45
50
|
export declare function available(composition: Composition): boolean;
|
|
46
51
|
export {};
|
|
47
52
|
//# sourceMappingURL=collection.d.ts.map
|
package/dist/collection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"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"}
|
package/dist/collection.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import { definitionAt, parse, VERSION, } from '@agentshouse/mdmodel';
|
|
1
|
+
import { definitionAt, folderType, parse, VERSION, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { beneath, normalize } from './paths.js';
|
|
3
3
|
import { hashed } from './observation.js';
|
|
4
4
|
import { sortedKeys } from './shared.js';
|
|
5
5
|
export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
|
|
6
6
|
const typesPrinted = new WeakMap();
|
|
7
|
-
function typesPrint(
|
|
8
|
-
|
|
9
|
-
return '';
|
|
10
|
-
let print = typesPrinted.get(model.types);
|
|
7
|
+
export function typesPrint(types) {
|
|
8
|
+
let print = typesPrinted.get(types);
|
|
11
9
|
if (print === undefined) {
|
|
12
|
-
print = hashed(JSON.stringify(
|
|
13
|
-
typesPrinted.set(
|
|
10
|
+
print = hashed(JSON.stringify(types)).toString(36);
|
|
11
|
+
typesPrinted.set(types, print);
|
|
14
12
|
}
|
|
15
13
|
return print;
|
|
16
14
|
}
|
|
15
|
+
function modelPrint(model) {
|
|
16
|
+
return model.status === 'unavailable' ? '' : typesPrint(model.types);
|
|
17
|
+
}
|
|
17
18
|
export function composedOf(composition) {
|
|
18
19
|
const { model, selection } = composition;
|
|
19
20
|
return {
|
|
20
21
|
composition,
|
|
21
22
|
fingerprint: JSON.stringify([
|
|
22
|
-
|
|
23
|
-
selection === null ? null : [selection.roots,
|
|
23
|
+
modelPrint(model),
|
|
24
|
+
selection === null ? null : [selection.roots, modelPrint(selection.model)],
|
|
24
25
|
]),
|
|
25
26
|
};
|
|
26
27
|
}
|
|
@@ -73,6 +74,19 @@ export function* documentsOf(collection) {
|
|
|
73
74
|
export function validRoot(root) {
|
|
74
75
|
return typeof root === 'string' && normalize(root) === root;
|
|
75
76
|
}
|
|
77
|
+
export const UNTYPED = 'any';
|
|
78
|
+
export function textType(read) {
|
|
79
|
+
return read.ok ? (read.document.type ?? UNTYPED) : undefined;
|
|
80
|
+
}
|
|
81
|
+
export function typeAt(composition, path, read) {
|
|
82
|
+
if (!read.ok || read.document.type !== undefined)
|
|
83
|
+
return textType(read);
|
|
84
|
+
const model = governing(composition, path);
|
|
85
|
+
return (model.status === 'unavailable' ? undefined : folderType(model, path)) ?? UNTYPED;
|
|
86
|
+
}
|
|
87
|
+
export function typedText(read) {
|
|
88
|
+
return (textType(read) ?? UNTYPED) !== UNTYPED;
|
|
89
|
+
}
|
|
76
90
|
export function available(composition) {
|
|
77
91
|
return composition.model.status !== 'unavailable';
|
|
78
92
|
}
|
package/dist/column.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Row, Value } from './tables.js';
|
|
2
|
+
export declare function text(value: Value | undefined): string;
|
|
3
|
+
export declare function texts(rows: readonly Row[], column: string): string[];
|
|
4
|
+
export declare function count(value: Value | undefined): number;
|
|
5
|
+
//# sourceMappingURL=column.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column.d.ts","sourceRoot":"","sources":["../src/column.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE9C,wBAAgB,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAErD;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAEpE;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAEtD"}
|
package/dist/column.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function text(value) {
|
|
2
|
+
return typeof value === 'string' ? value : String(value);
|
|
3
|
+
}
|
|
4
|
+
export function texts(rows, column) {
|
|
5
|
+
return rows.map((row) => text(row[column]));
|
|
6
|
+
}
|
|
7
|
+
export function count(value) {
|
|
8
|
+
return typeof value === 'bigint' ? Number(value) : typeof value === 'number' ? value : 0;
|
|
9
|
+
}
|
package/dist/compile.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { sql } from '@agentshouse/mdmodel';
|
|
2
|
+
import { type Composition } from './collection.js';
|
|
2
3
|
import type { Plan, QueryRows } from './query.js';
|
|
3
4
|
import type { Connection } from './tables.js';
|
|
4
5
|
export type QueryRoom = {
|
|
5
6
|
readonly locator: string;
|
|
6
7
|
readonly key: number;
|
|
8
|
+
readonly composition?: Composition;
|
|
7
9
|
};
|
|
8
10
|
type Fragment = sql.Fragment;
|
|
9
11
|
export declare const VISIBLE: (alias: string) => string;
|
|
@@ -11,6 +13,7 @@ export declare function within(alias: string, path: string): Fragment;
|
|
|
11
13
|
export type QueryAnswer = QueryRows & {
|
|
12
14
|
readonly more?: string;
|
|
13
15
|
};
|
|
14
|
-
export declare function
|
|
16
|
+
export declare function namedHandles(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], handles: readonly string[]): readonly string[];
|
|
17
|
+
export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null, follows?: readonly QueryRoom[]): QueryAnswer;
|
|
15
18
|
export {};
|
|
16
19
|
//# sourceMappingURL=compile.d.ts.map
|
package/dist/compile.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,GAAG,
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,GAAG,EAQJ,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE3E,OAAO,KAAK,EAAE,IAAI,EAAuC,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvF,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAG1D,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;CACpC,CAAC;AAEF,KAAK,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AAI7B,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,MAAyD,CAAC;AAsBlG,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAE5D;AAufD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAkajE,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,MAAM,EAAE,CAenB;AAED,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,OAAO,GAAE,SAAS,SAAS,EAAO,GACjC,WAAW,CAUb"}
|
package/dist/compile.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { ARRAY_INDEX, bodied, byCodePoint, compared, cursorOf, heldKind, parse, pointerSegments, sql, } from '@agentshouse/mdmodel';
|
|
2
|
-
import {
|
|
2
|
+
import { attachmentRecord } from './attachment.js';
|
|
3
|
+
import { definitionsAt, UNTYPED } from './collection.js';
|
|
3
4
|
import { documentKey, pathOfKey, roomOfKey } from './rows.js';
|
|
5
|
+
import { ROOM_HANDLE } from './stored.js';
|
|
4
6
|
import { FROM_START, MAXIMUM_WINDOW } from './windows.js';
|
|
5
7
|
const { all, any, exists, fragment, grouped, joined, listed } = sql;
|
|
6
|
-
export const VISIBLE = (alias) => `${alias}.visible = 1 AND ${alias}.present = 1
|
|
8
|
+
export const VISIBLE = (alias) => `${alias}.visible = 1 AND ${alias}.present = 1`;
|
|
7
9
|
function located(alias) {
|
|
8
10
|
return fragment(`(SELECT k.locator FROM replica_keys k WHERE k.key = ${alias}.key)`);
|
|
9
11
|
}
|
|
10
|
-
|
|
11
|
-
return fragment(`(${
|
|
12
|
-
|
|
13
|
-
`${
|
|
14
|
-
`${
|
|
12
|
+
function inside(path, folder) {
|
|
13
|
+
return fragment(`(${path} = ? OR (${path} >= ? AND ${path} < ?))`, [
|
|
14
|
+
folder,
|
|
15
|
+
`${folder}/`,
|
|
16
|
+
`${folder}0`,
|
|
15
17
|
]);
|
|
16
18
|
}
|
|
19
|
+
export function within(alias, path) {
|
|
20
|
+
return inside(`${alias}.path`, path);
|
|
21
|
+
}
|
|
17
22
|
function ancestors(area) {
|
|
18
23
|
const depth = area.path.split('/').length;
|
|
19
24
|
return area.open.flatMap((open) => {
|
|
@@ -21,18 +26,18 @@ function ancestors(area) {
|
|
|
21
26
|
return segments.slice(depth - 1, -1).map((_, at) => segments.slice(0, depth + at).join('/'));
|
|
22
27
|
});
|
|
23
28
|
}
|
|
24
|
-
function fenced(
|
|
29
|
+
function fenced(key, path, held, area, folders) {
|
|
25
30
|
const opened = any([
|
|
26
|
-
...area.open.map((open) =>
|
|
27
|
-
...(folders ? ancestors(area).map((
|
|
31
|
+
...area.open.map((open) => inside(path, open)),
|
|
32
|
+
...(folders ? ancestors(area).map((ancestor) => fragment(`${path} = ?`, [ancestor])) : []),
|
|
28
33
|
]);
|
|
29
34
|
return all([
|
|
30
|
-
fragment(`${
|
|
31
|
-
|
|
35
|
+
fragment(`${key} = ?`, [held]),
|
|
36
|
+
inside(path, area.path),
|
|
32
37
|
fragment(`NOT ${grouped(opened).sql}`, opened.bind),
|
|
33
38
|
]);
|
|
34
39
|
}
|
|
35
|
-
function reached(bound,
|
|
40
|
+
function reached(bound, key, path) {
|
|
36
41
|
const reach = bound.reach;
|
|
37
42
|
if (reach === null)
|
|
38
43
|
return fragment('1');
|
|
@@ -45,49 +50,65 @@ function reached(bound, alias) {
|
|
|
45
50
|
return key === undefined ? [] : [[key, pathOfKey(held)]];
|
|
46
51
|
});
|
|
47
52
|
const outside = any(reach.areas.flatMap((area) => {
|
|
48
|
-
const
|
|
49
|
-
return
|
|
53
|
+
const held = bound.keys.get(area.room);
|
|
54
|
+
return held === undefined ? [] : [fenced(key, path, held, area, false)];
|
|
50
55
|
}));
|
|
51
56
|
return all([
|
|
52
57
|
any([
|
|
53
|
-
...(rooms.length === 0 ? [] : [fragment(`${
|
|
58
|
+
...(rooms.length === 0 ? [] : [fragment(`${key} IN ${listed(rooms).sql}`, rooms)]),
|
|
54
59
|
...(documents.length === 0
|
|
55
60
|
? []
|
|
56
61
|
: [
|
|
57
|
-
fragment(`EXISTS (SELECT 1 FROM json_each(?) j WHERE j.value ->> 0 = ${
|
|
62
|
+
fragment(`EXISTS (SELECT 1 FROM json_each(?) j WHERE j.value ->> 0 = ${key} AND j.value ->> 1 = ${path})`, [JSON.stringify(documents)]),
|
|
58
63
|
]),
|
|
59
64
|
]),
|
|
60
65
|
...(reach.areas.length === 0 ? [] : [fragment(`NOT ${grouped(outside).sql}`, outside.bind)]),
|
|
61
66
|
]);
|
|
62
67
|
}
|
|
68
|
+
function handled(bound, link) {
|
|
69
|
+
return fragment(`FROM replica_rooms h WHERE ${ROOM_HANDLE('h')} = ${link}.handle AND h.key IN (SELECT value FROM json_each(?))`, [bound.follows]);
|
|
70
|
+
}
|
|
71
|
+
function followed(bound) {
|
|
72
|
+
return {
|
|
73
|
+
targets: (link, document) => {
|
|
74
|
+
const room = handled(bound, link);
|
|
75
|
+
return joined([
|
|
76
|
+
fragment(`replica_entries ${document} ON ${document}.key = CASE WHEN ${link}.handle IS NULL THEN d.key ELSE (SELECT h.key ${room.sql}) END AND ${document}.path = ${link}.target AND ${VISIBLE(document)} AND`, room.bind),
|
|
77
|
+
grouped(reached(bound, `${document}.key`, `${document}.path`)),
|
|
78
|
+
], ' ');
|
|
79
|
+
},
|
|
80
|
+
unfollowed: (link) => {
|
|
81
|
+
const own = reached(bound, 'd.key', `${link}.target`);
|
|
82
|
+
const room = handled(bound, link);
|
|
83
|
+
const other = reached(bound, 'h.key', `${link}.target`);
|
|
84
|
+
return fragment(`NOT ((${link}.handle IS NULL AND ${own.sql}) OR EXISTS (SELECT 1 ${room.sql} AND ${other.sql}))`, [...own.bind, ...room.bind, ...other.bind]);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
63
88
|
function related(bound, plan) {
|
|
64
89
|
const parts = [];
|
|
65
|
-
if (plan.hop !== null)
|
|
66
|
-
parts.push(
|
|
67
|
-
fragment(`SELECT 1 FROM replica_links l JOIN replica_entries m ON m.key = d.key AND m.path = l.target AND ${VISIBLE('m')} WHERE l.doc = d.id AND l.kind = 'field' AND`),
|
|
68
|
-
grouped(sql.placed('l', plan.hop.field, 'link')),
|
|
69
|
-
fragment('AND'),
|
|
70
|
-
grouped(all([sql.scoped('m', plan.hop), reached(bound, 'm')])),
|
|
71
|
-
], ' ')));
|
|
72
|
-
}
|
|
90
|
+
if (plan.hop !== null)
|
|
91
|
+
parts.push(sql.hopped('d', plan.hop, followed(bound)));
|
|
73
92
|
if (plan.backlinks !== null) {
|
|
74
93
|
const field = plan.backlinks.field;
|
|
75
94
|
parts.push(exists(joined([
|
|
76
|
-
fragment(`SELECT 1 FROM replica_links l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE l.key = d.key AND l.target = d.path AND l.kind = 'field' AND`),
|
|
95
|
+
fragment(`SELECT 1 FROM replica_links l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE l.key = d.key AND l.handle IS NULL AND l.target = d.path AND l.kind = 'field' AND`),
|
|
77
96
|
...(field === null ? [] : [grouped(sql.placed('l', field, 'link')), fragment('AND')]),
|
|
78
|
-
grouped(all([sql.scoped('s', plan.backlinks), reached(bound, 's')])),
|
|
97
|
+
grouped(all([sql.scoped('s', plan.backlinks), reached(bound, 's.key', 's.path')])),
|
|
79
98
|
], ' ')));
|
|
80
99
|
}
|
|
81
100
|
return parts;
|
|
82
101
|
}
|
|
83
|
-
function
|
|
102
|
+
function tested(bound, plan) {
|
|
84
103
|
const keys = bound.rooms.map(({ key }) => key);
|
|
85
|
-
return
|
|
104
|
+
return [
|
|
86
105
|
fragment(`d.key IN ${listed(keys).sql} AND ${VISIBLE('d')}`, keys),
|
|
87
|
-
reached(bound, 'd'),
|
|
106
|
+
reached(bound, 'd.key', 'd.path'),
|
|
88
107
|
sql.tests('d', plan),
|
|
89
|
-
|
|
90
|
-
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
function filtered(bound, plan) {
|
|
111
|
+
return all([...tested(bound, plan), ...related(bound, plan)]);
|
|
91
112
|
}
|
|
92
113
|
function orderingOf(options) {
|
|
93
114
|
const stringSort = options.stringSort ?? 'locale';
|
|
@@ -310,7 +331,16 @@ function sectionsOf(sections, names) {
|
|
|
310
331
|
return sections;
|
|
311
332
|
return Object.fromEntries(names.flatMap((name) => (Object.hasOwn(sections, name) ? [[name, sections[name]]] : [])));
|
|
312
333
|
}
|
|
313
|
-
function
|
|
334
|
+
function freeParts(room, path, type, content) {
|
|
335
|
+
const definitions = room.composition === undefined ? undefined : definitionsAt(room.composition, path);
|
|
336
|
+
const definition = definitions?.(type === UNTYPED ? undefined : type);
|
|
337
|
+
if (definition === undefined && type !== UNTYPED)
|
|
338
|
+
return null;
|
|
339
|
+
const read = parse(content, path, definition);
|
|
340
|
+
return read.ok ? read.document : null;
|
|
341
|
+
}
|
|
342
|
+
function documentOf(shape, queried, row, linked) {
|
|
343
|
+
const room = queried.locator;
|
|
314
344
|
const path = row.path;
|
|
315
345
|
const type = row.type;
|
|
316
346
|
const fileId = row.file_id;
|
|
@@ -324,7 +354,7 @@ function documentOf(shape, room, row, linked) {
|
|
|
324
354
|
...(binary === null
|
|
325
355
|
? {}
|
|
326
356
|
: {
|
|
327
|
-
|
|
357
|
+
attachment: attachmentRecord(path, binary, revision ?? undefined),
|
|
328
358
|
}),
|
|
329
359
|
...(shape.markdown && content !== null ? { markdown: content } : {}),
|
|
330
360
|
...(shape.change ? { change: changeOf(row) } : {}),
|
|
@@ -333,8 +363,9 @@ function documentOf(shape, room, row, linked) {
|
|
|
333
363
|
...heldFacts(shape, row),
|
|
334
364
|
};
|
|
335
365
|
}
|
|
336
|
-
const
|
|
337
|
-
|
|
366
|
+
const body = shape.sections !== null || shape.preamble
|
|
367
|
+
? freeParts(queried, path, type, row.content)
|
|
368
|
+
: null;
|
|
338
369
|
const fields = JSON.parse(row.fields ?? '{}');
|
|
339
370
|
return {
|
|
340
371
|
room,
|
|
@@ -377,10 +408,10 @@ function backlinksOf(connection, bound, rows) {
|
|
|
377
408
|
held.push(row.path);
|
|
378
409
|
byKey.set(key, held);
|
|
379
410
|
}
|
|
380
|
-
const reach = reached(bound, 's');
|
|
411
|
+
const reach = reached(bound, 's.key', 's.path');
|
|
381
412
|
for (const [key, targets] of byKey) {
|
|
382
413
|
const room = bound.rooms.find((one) => one.key === key).locator;
|
|
383
|
-
const found = connection.rows(`SELECT target, path, type, field FROM (SELECT l.target, s.path, s.type, l.field, ROW_NUMBER() OVER (PARTITION BY l.target ORDER BY s.path, l.field) AS rank FROM (SELECT DISTINCT doc, target, field FROM replica_links WHERE key = ? AND kind = 'field' AND target IN (SELECT value FROM json_each(?))) l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE ${reach.sql}) WHERE rank <= ? ORDER BY target, path, field`, [key, JSON.stringify(targets), ...reach.bind, MAXIMUM_WINDOW]);
|
|
414
|
+
const found = connection.rows(`SELECT target, path, type, field FROM (SELECT l.target, s.path, s.type, l.field, ROW_NUMBER() OVER (PARTITION BY l.target ORDER BY s.path, l.field) AS rank FROM (SELECT DISTINCT doc, target, field FROM replica_links WHERE key = ? AND kind = 'field' AND handle IS NULL AND target IN (SELECT value FROM json_each(?))) l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE ${reach.sql}) WHERE rank <= ? ORDER BY target, path, field`, [key, JSON.stringify(targets), ...reach.bind, MAXIMUM_WINDOW]);
|
|
384
415
|
for (const row of found) {
|
|
385
416
|
const at = documentKey(room, row.target);
|
|
386
417
|
const held = linked.get(at) ?? [];
|
|
@@ -428,8 +459,9 @@ function documents(connection, bound, plan, shape, budget) {
|
|
|
428
459
|
const kept = bodied(shape) ? withContent(connection, windowed, budget) : windowed;
|
|
429
460
|
const cut = kept.length;
|
|
430
461
|
const roomOf = new Map(bound.rooms.map(({ key, locator }) => [key, locator]));
|
|
462
|
+
const queried = new Map(bound.rooms.map((one) => [one.key, one]));
|
|
431
463
|
const linked = shape.backlinks ? backlinksOf(connection, bound, kept) : new Map();
|
|
432
|
-
const found = kept.map((row) => documentOf(shape,
|
|
464
|
+
const found = kept.map((row) => documentOf(shape, queried.get(Number(row.key)), row, linked));
|
|
433
465
|
const last = kept.at(-1);
|
|
434
466
|
const cursorAt = (row) => cursorOf([
|
|
435
467
|
...shape.orderBy.map(({ key }, index) => decodedKey(key, row, index)),
|
|
@@ -494,7 +526,7 @@ function storedFolders(bound, plan, subfolder) {
|
|
|
494
526
|
const key = bound.keys.get(area.room);
|
|
495
527
|
if (key === undefined)
|
|
496
528
|
return [];
|
|
497
|
-
const fence = fenced('f', key, area, true);
|
|
529
|
+
const fence = fenced('f.key', 'f.path', key, area, true);
|
|
498
530
|
return [fragment(`NOT ${grouped(fence).sql}`, fence.bind)];
|
|
499
531
|
});
|
|
500
532
|
const under = prefix === ''
|
|
@@ -690,16 +722,28 @@ function groups(connection, bound, plan, shape) {
|
|
|
690
722
|
...(total === undefined ? {} : { total }),
|
|
691
723
|
};
|
|
692
724
|
}
|
|
693
|
-
function boundOf(connection, plan, rooms) {
|
|
725
|
+
function boundOf(connection, plan, rooms, follows) {
|
|
694
726
|
return {
|
|
695
727
|
rooms: [...rooms].sort((left, right) => left.locator < right.locator ? -1 : left.locator > right.locator ? 1 : 0),
|
|
696
|
-
keys: new Map(rooms.map(({ locator, key }) => [locator, key])),
|
|
728
|
+
keys: new Map([...rooms, ...follows].map(({ locator, key }) => [locator, key])),
|
|
729
|
+
follows: JSON.stringify(follows.map(({ key }) => key)),
|
|
697
730
|
reach: plan.reach,
|
|
698
731
|
collate: collating(connection),
|
|
699
732
|
};
|
|
700
733
|
}
|
|
701
|
-
export function
|
|
702
|
-
|
|
734
|
+
export function namedHandles(connection, plan, rooms, handles) {
|
|
735
|
+
if (plan.hop === null)
|
|
736
|
+
return [];
|
|
737
|
+
const statement = joined([
|
|
738
|
+
fragment("SELECT DISTINCT l.handle FROM replica_entries d JOIN replica_links l ON l.doc = d.id AND l.kind = 'field' AND l.handle IN (SELECT value FROM json_each(?)) AND ", [JSON.stringify(handles)]),
|
|
739
|
+
grouped(sql.placed('l', plan.hop.field, 'link')),
|
|
740
|
+
fragment(' WHERE '),
|
|
741
|
+
all(tested(boundOf(connection, plan, rooms, []), plan)),
|
|
742
|
+
], '');
|
|
743
|
+
return connection.rows(statement.sql, statement.bind).map((row) => row.handle);
|
|
744
|
+
}
|
|
745
|
+
export function answerQuery(connection, plan, rooms, budget = null, follows = []) {
|
|
746
|
+
const bound = boundOf(connection, plan, rooms, follows);
|
|
703
747
|
if (rooms.length === 0) {
|
|
704
748
|
return plan.shape.kind === 'groups'
|
|
705
749
|
? { groups: [], ...(plan.total ? { total: 0 } : {}) }
|
package/dist/connection.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ export type MdRuntimeOptions = {
|
|
|
10
10
|
authorization?: Authorization;
|
|
11
11
|
signal?: AbortSignal;
|
|
12
12
|
recovery?: Recovery;
|
|
13
|
-
usableWhenHeld?: readonly string[];
|
|
14
13
|
build?: string;
|
|
14
|
+
storeOnNeed?: boolean;
|
|
15
15
|
};
|
|
16
16
|
export declare function composeRuntime(options: MdRuntimeOptions): ComposedRuntime;
|
|
17
17
|
//# sourceMappingURL=connection.d.ts.map
|
package/dist/connection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAI/E,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAUrE,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAK9D,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAGrE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,YAAY,CAAC;IACpB,QAAQ,EAAE,eAAe,CAAC;IAC1B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAIF,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CAwGzE"}
|