@agentshouse/mdruntime 0.1.0-c01d4615bfe46 → 0.1.0-c024a9c474f5e
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 +14 -13
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +32 -3
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +58 -19
- package/dist/adapter.d.ts +183 -21
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -2
- 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 +345 -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.js +2 -2
- package/dist/client.d.ts +23 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +25 -54
- 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 +2 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +73 -42
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +16 -6
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +8 -5
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +5 -3
- package/dist/conversation-row.d.ts +23 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +37 -8
- package/dist/conversation.d.ts +20 -9
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +102 -68
- 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 -5
- 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 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +3 -0
- package/dist/entry.d.ts +26 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +126 -36
- 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 +1 -1
- package/dist/holdings.d.ts.map +1 -1
- package/dist/holdings.js +5 -3
- package/dist/host.d.ts +6 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +70 -29
- 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 +20 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/install.d.ts +8 -2
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +40 -33
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +42 -25
- package/dist/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +13 -0
- 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 -2
- package/dist/lost.js +1 -1
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +177 -27
- package/dist/memory.d.ts +4 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +50 -16
- package/dist/messages.d.ts +12 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +28 -6
- 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 +3 -3
- 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 +26 -10
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +200 -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 +20 -2
- package/dist/outcome.d.ts +27 -14
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +14 -5
- package/dist/overlay.d.ts +20 -9
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +110 -41
- package/dist/parts.d.ts +4 -1
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -7
- 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 +195 -78
- 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 +115 -67
- package/dist/query.d.ts +2 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +1 -0
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -1
- package/dist/queue.d.ts +1 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +55 -23
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +140 -25
- package/dist/react.d.ts +11 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +22 -3
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +2 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +21 -13
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +2 -1
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +4 -4
- 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 +29 -4
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +237 -16
- 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 -3
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +25 -11
- 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 +7 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +1 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +31 -96
- package/dist/saves.d.ts +7 -5
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +108 -54
- 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 +4 -2
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +73 -48
- 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 -1
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +14 -2
- package/dist/source.d.ts +42 -0
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +76 -9
- 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 +24 -5
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +59 -24
- 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 +40 -16
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +210 -52
- package/dist/surface.d.ts +18 -7
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +52 -16
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +47 -25
- package/dist/tables.d.ts +34 -49
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +84 -325
- package/dist/tallies.js +2 -2
- 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 +29 -14
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +18 -13
- package/package.json +4 -4
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
package/dist/client.js
CHANGED
|
@@ -1,27 +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 {
|
|
5
|
+
import { attachmentBlob, } from './outcome.js';
|
|
6
6
|
import { AUTHORIZATION_ENDED, PORT_CLOSED, wireAnswer, } from './wire.js';
|
|
7
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.
|
|
8
8
|
const SETTLED_FRAMES = 2;
|
|
9
|
-
// 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.
|
|
10
|
-
const HANDED_COPY_MS = 60_000;
|
|
11
|
-
const PAGE = /\.html?$/iu;
|
|
12
|
-
const STARTED = { kind: 'started' };
|
|
13
|
-
const BLOCKED = {
|
|
14
|
-
kind: 'blocked',
|
|
15
|
-
code: 'popup-blocked',
|
|
16
|
-
fields: {},
|
|
17
|
-
retryable: true,
|
|
18
|
-
};
|
|
19
|
-
function handed(url, name) {
|
|
20
|
-
const anchor = document.createElement('a');
|
|
21
|
-
anchor.href = url;
|
|
22
|
-
anchor.download = name;
|
|
23
|
-
anchor.click();
|
|
24
|
-
}
|
|
25
9
|
function refused(refusal) {
|
|
26
10
|
return runtimeError(refusal.code);
|
|
27
11
|
}
|
|
@@ -91,7 +75,7 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
91
75
|
}
|
|
92
76
|
if (message.kind === 'ended') {
|
|
93
77
|
for (const { topic, handle } of observations.values()) {
|
|
94
|
-
if (topic === 'member')
|
|
78
|
+
if (topic === 'member' || topic === 'time-zone')
|
|
95
79
|
handle.receive(null);
|
|
96
80
|
}
|
|
97
81
|
end(runtimeError('authorization-ended', AUTHORIZATION_ENDED));
|
|
@@ -161,12 +145,12 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
161
145
|
let received = 0;
|
|
162
146
|
const stream = new ReadableStream({
|
|
163
147
|
async pull(controller) {
|
|
164
|
-
const bytes = await ask('
|
|
148
|
+
const bytes = await ask('attachment.part', [file, part]);
|
|
165
149
|
if (bytes === null) {
|
|
166
150
|
if (received === byteLength)
|
|
167
151
|
controller.close();
|
|
168
152
|
else
|
|
169
|
-
controller.error(runtimeError('
|
|
153
|
+
controller.error(runtimeError('attachment-absent', 'The file ended early'));
|
|
170
154
|
return;
|
|
171
155
|
}
|
|
172
156
|
part += 1;
|
|
@@ -177,30 +161,13 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
177
161
|
return { kind: 'binary', stream, byteLength, mediaType };
|
|
178
162
|
}
|
|
179
163
|
async function download(room, path, revision) {
|
|
180
|
-
const
|
|
181
|
-
const linked = await ask('binaryFile.link', [room, path, revision]);
|
|
182
|
-
if (linked.kind === 'link' && PAGE.test(linked.name)) {
|
|
183
|
-
const away = tab ?? globalThis.open('', '_blank');
|
|
184
|
-
if (away === null)
|
|
185
|
-
return BLOCKED;
|
|
186
|
-
away.location.replace(linked.url);
|
|
187
|
-
return STARTED;
|
|
188
|
-
}
|
|
189
|
-
tab?.close();
|
|
190
|
-
if (linked.kind === 'link') {
|
|
191
|
-
handed(linked.url, linked.name);
|
|
192
|
-
return STARTED;
|
|
193
|
-
}
|
|
164
|
+
const linked = await handedLink(path, () => ask('attachment.link', [room, path, revision]));
|
|
194
165
|
if (linked.kind !== 'absent')
|
|
195
166
|
return linked;
|
|
196
|
-
const read = streamed(await ask('
|
|
167
|
+
const read = streamed(await ask('attachment.read', [room, path, revision]));
|
|
197
168
|
if (read.kind !== 'binary')
|
|
198
169
|
return read;
|
|
199
|
-
|
|
200
|
-
const url = URL.createObjectURL(copy);
|
|
201
|
-
handed(url, path.slice(path.lastIndexOf('/') + 1));
|
|
202
|
-
setTimeout(() => URL.revokeObjectURL(url), HANDED_COPY_MS);
|
|
203
|
-
return STARTED;
|
|
170
|
+
return handedCopy(await attachmentBlob(read), path.slice(path.lastIndexOf('/') + 1));
|
|
204
171
|
}
|
|
205
172
|
function settled() {
|
|
206
173
|
if (settling !== null)
|
|
@@ -231,12 +198,12 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
231
198
|
});
|
|
232
199
|
return settling;
|
|
233
200
|
}
|
|
234
|
-
|
|
235
|
-
return shownBy(show, {
|
|
201
|
+
return {
|
|
236
202
|
buildFile,
|
|
237
|
-
rooms: () => ask('rooms', []),
|
|
203
|
+
rooms: () => ask('rooms', []).then(appRooms),
|
|
238
204
|
query: ((query) => ask('query', [query])),
|
|
239
205
|
search: (request) => ask('search', [request]),
|
|
206
|
+
queryHouse: (query, options) => ask('queryHouse', options === undefined ? [query] : [query, options]),
|
|
240
207
|
types: (locator) => ask('types', [locator]),
|
|
241
208
|
roomDraft: {
|
|
242
209
|
list: () => ask('roomDraft.list', []),
|
|
@@ -263,13 +230,13 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
263
230
|
takeOut: (conversation, message, operation) => ask('conversation.takeOut', [conversation, message, operation]),
|
|
264
231
|
decide: (request, decision, operation) => ask('conversation.decide', [request, decision, operation]),
|
|
265
232
|
rename: (conversation, name, operation) => ask('conversation.rename', [conversation, name, operation]),
|
|
266
|
-
|
|
233
|
+
set: (conversation, settings, operation) => ask('conversation.set', [conversation, settings, operation]),
|
|
267
234
|
retry: (conversation, message, operation) => ask('conversation.retry', [conversation, message, operation]),
|
|
268
|
-
pins: () => ask('conversation.pins', []),
|
|
269
235
|
pin: (figures) => ask('conversation.pin', [figures]),
|
|
270
|
-
openedTurns: () => ask('conversation.openedTurns', []),
|
|
271
236
|
openTurn: (conversation, turn) => ask('conversation.openTurn', [conversation, turn]),
|
|
272
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]] : []))),
|
|
@@ -282,9 +249,10 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
282
249
|
},
|
|
283
250
|
history: (locator, path, query) => ask('history', [locator, path, query]),
|
|
284
251
|
resolve: (room, path, destination) => ask('resolve', [room, path, destination]),
|
|
285
|
-
|
|
286
|
-
read: (room, path, revision) => ask('
|
|
287
|
-
|
|
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]),
|
|
288
256
|
download,
|
|
289
257
|
},
|
|
290
258
|
call: (name, input) => ask('call', [name, input]),
|
|
@@ -294,12 +262,13 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
294
262
|
retry: () => ask('retry', []),
|
|
295
263
|
cleanUp: () => ask('cleanUp', []),
|
|
296
264
|
unsent: () => ask('unsent', []),
|
|
265
|
+
sent: () => ask('sent', []),
|
|
297
266
|
reset: () => ask('reset', []),
|
|
298
267
|
readAgain: () => ask('readAgain', []),
|
|
299
268
|
observe: ((topic, ...input) => watch(topic, input)),
|
|
300
269
|
reauthorize: () => ask('reauthorize', []),
|
|
301
270
|
settled,
|
|
302
|
-
}
|
|
271
|
+
};
|
|
303
272
|
}
|
|
304
273
|
const turns = new WeakMap();
|
|
305
274
|
export function inTurn(client, work) {
|
|
@@ -309,5 +278,7 @@ export function inTurn(client, work) {
|
|
|
309
278
|
}
|
|
310
279
|
export { chainedWindows } from './chain.js';
|
|
311
280
|
export { roomDraftRevision } from './identity.js';
|
|
312
|
-
export {
|
|
313
|
-
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
|
@@ -13,6 +13,7 @@ export declare function within(alias: string, path: string): Fragment;
|
|
|
13
13
|
export type QueryAnswer = QueryRows & {
|
|
14
14
|
readonly more?: string;
|
|
15
15
|
};
|
|
16
|
-
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;
|
|
17
18
|
export {};
|
|
18
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,EAQJ,MAAM,sBAAsB,CAAC;AAG9B,OAAO,
|
|
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,21 +1,24 @@
|
|
|
1
1
|
import { ARRAY_INDEX, bodied, byCodePoint, compared, cursorOf, heldKind, parse, pointerSegments, sql, } from '@agentshouse/mdmodel';
|
|
2
|
-
import {
|
|
3
|
-
import { definitionsAt } from './collection.js';
|
|
2
|
+
import { attachmentRecord } from './attachment.js';
|
|
3
|
+
import { definitionsAt, UNTYPED } from './collection.js';
|
|
4
4
|
import { documentKey, pathOfKey, roomOfKey } from './rows.js';
|
|
5
|
+
import { ROOM_HANDLE } from './stored.js';
|
|
5
6
|
import { FROM_START, MAXIMUM_WINDOW } from './windows.js';
|
|
6
|
-
const UNTYPED = 'any';
|
|
7
7
|
const { all, any, exists, fragment, grouped, joined, listed } = sql;
|
|
8
|
-
export const VISIBLE = (alias) => `${alias}.visible = 1 AND ${alias}.present = 1
|
|
8
|
+
export const VISIBLE = (alias) => `${alias}.visible = 1 AND ${alias}.present = 1`;
|
|
9
9
|
function located(alias) {
|
|
10
10
|
return fragment(`(SELECT k.locator FROM replica_keys k WHERE k.key = ${alias}.key)`);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
return fragment(`(${
|
|
14
|
-
|
|
15
|
-
`${
|
|
16
|
-
`${
|
|
12
|
+
function inside(path, folder) {
|
|
13
|
+
return fragment(`(${path} = ? OR (${path} >= ? AND ${path} < ?))`, [
|
|
14
|
+
folder,
|
|
15
|
+
`${folder}/`,
|
|
16
|
+
`${folder}0`,
|
|
17
17
|
]);
|
|
18
18
|
}
|
|
19
|
+
export function within(alias, path) {
|
|
20
|
+
return inside(`${alias}.path`, path);
|
|
21
|
+
}
|
|
19
22
|
function ancestors(area) {
|
|
20
23
|
const depth = area.path.split('/').length;
|
|
21
24
|
return area.open.flatMap((open) => {
|
|
@@ -23,18 +26,18 @@ function ancestors(area) {
|
|
|
23
26
|
return segments.slice(depth - 1, -1).map((_, at) => segments.slice(0, depth + at).join('/'));
|
|
24
27
|
});
|
|
25
28
|
}
|
|
26
|
-
function fenced(
|
|
29
|
+
function fenced(key, path, held, area, folders) {
|
|
27
30
|
const opened = any([
|
|
28
|
-
...area.open.map((open) =>
|
|
29
|
-
...(folders ? ancestors(area).map((
|
|
31
|
+
...area.open.map((open) => inside(path, open)),
|
|
32
|
+
...(folders ? ancestors(area).map((ancestor) => fragment(`${path} = ?`, [ancestor])) : []),
|
|
30
33
|
]);
|
|
31
34
|
return all([
|
|
32
|
-
fragment(`${
|
|
33
|
-
|
|
35
|
+
fragment(`${key} = ?`, [held]),
|
|
36
|
+
inside(path, area.path),
|
|
34
37
|
fragment(`NOT ${grouped(opened).sql}`, opened.bind),
|
|
35
38
|
]);
|
|
36
39
|
}
|
|
37
|
-
function reached(bound,
|
|
40
|
+
function reached(bound, key, path) {
|
|
38
41
|
const reach = bound.reach;
|
|
39
42
|
if (reach === null)
|
|
40
43
|
return fragment('1');
|
|
@@ -47,49 +50,65 @@ function reached(bound, alias) {
|
|
|
47
50
|
return key === undefined ? [] : [[key, pathOfKey(held)]];
|
|
48
51
|
});
|
|
49
52
|
const outside = any(reach.areas.flatMap((area) => {
|
|
50
|
-
const
|
|
51
|
-
return
|
|
53
|
+
const held = bound.keys.get(area.room);
|
|
54
|
+
return held === undefined ? [] : [fenced(key, path, held, area, false)];
|
|
52
55
|
}));
|
|
53
56
|
return all([
|
|
54
57
|
any([
|
|
55
|
-
...(rooms.length === 0 ? [] : [fragment(`${
|
|
58
|
+
...(rooms.length === 0 ? [] : [fragment(`${key} IN ${listed(rooms).sql}`, rooms)]),
|
|
56
59
|
...(documents.length === 0
|
|
57
60
|
? []
|
|
58
61
|
: [
|
|
59
|
-
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)]),
|
|
60
63
|
]),
|
|
61
64
|
]),
|
|
62
65
|
...(reach.areas.length === 0 ? [] : [fragment(`NOT ${grouped(outside).sql}`, outside.bind)]),
|
|
63
66
|
]);
|
|
64
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
|
+
}
|
|
65
88
|
function related(bound, plan) {
|
|
66
89
|
const parts = [];
|
|
67
|
-
if (plan.hop !== null)
|
|
68
|
-
parts.push(
|
|
69
|
-
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`),
|
|
70
|
-
grouped(sql.placed('l', plan.hop.field, 'link')),
|
|
71
|
-
fragment('AND'),
|
|
72
|
-
grouped(all([sql.scoped('m', plan.hop), reached(bound, 'm')])),
|
|
73
|
-
], ' ')));
|
|
74
|
-
}
|
|
90
|
+
if (plan.hop !== null)
|
|
91
|
+
parts.push(sql.hopped('d', plan.hop, followed(bound)));
|
|
75
92
|
if (plan.backlinks !== null) {
|
|
76
93
|
const field = plan.backlinks.field;
|
|
77
94
|
parts.push(exists(joined([
|
|
78
|
-
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`),
|
|
79
96
|
...(field === null ? [] : [grouped(sql.placed('l', field, 'link')), fragment('AND')]),
|
|
80
|
-
grouped(all([sql.scoped('s', plan.backlinks), reached(bound, 's')])),
|
|
97
|
+
grouped(all([sql.scoped('s', plan.backlinks), reached(bound, 's.key', 's.path')])),
|
|
81
98
|
], ' ')));
|
|
82
99
|
}
|
|
83
100
|
return parts;
|
|
84
101
|
}
|
|
85
|
-
function
|
|
102
|
+
function tested(bound, plan) {
|
|
86
103
|
const keys = bound.rooms.map(({ key }) => key);
|
|
87
|
-
return
|
|
104
|
+
return [
|
|
88
105
|
fragment(`d.key IN ${listed(keys).sql} AND ${VISIBLE('d')}`, keys),
|
|
89
|
-
reached(bound, 'd'),
|
|
106
|
+
reached(bound, 'd.key', 'd.path'),
|
|
90
107
|
sql.tests('d', plan),
|
|
91
|
-
|
|
92
|
-
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
function filtered(bound, plan) {
|
|
111
|
+
return all([...tested(bound, plan), ...related(bound, plan)]);
|
|
93
112
|
}
|
|
94
113
|
function orderingOf(options) {
|
|
95
114
|
const stringSort = options.stringSort ?? 'locale';
|
|
@@ -335,7 +354,7 @@ function documentOf(shape, queried, row, linked) {
|
|
|
335
354
|
...(binary === null
|
|
336
355
|
? {}
|
|
337
356
|
: {
|
|
338
|
-
|
|
357
|
+
attachment: attachmentRecord(path, binary, revision ?? undefined),
|
|
339
358
|
}),
|
|
340
359
|
...(shape.markdown && content !== null ? { markdown: content } : {}),
|
|
341
360
|
...(shape.change ? { change: changeOf(row) } : {}),
|
|
@@ -389,10 +408,10 @@ function backlinksOf(connection, bound, rows) {
|
|
|
389
408
|
held.push(row.path);
|
|
390
409
|
byKey.set(key, held);
|
|
391
410
|
}
|
|
392
|
-
const reach = reached(bound, 's');
|
|
411
|
+
const reach = reached(bound, 's.key', 's.path');
|
|
393
412
|
for (const [key, targets] of byKey) {
|
|
394
413
|
const room = bound.rooms.find((one) => one.key === key).locator;
|
|
395
|
-
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]);
|
|
396
415
|
for (const row of found) {
|
|
397
416
|
const at = documentKey(room, row.target);
|
|
398
417
|
const held = linked.get(at) ?? [];
|
|
@@ -507,7 +526,7 @@ function storedFolders(bound, plan, subfolder) {
|
|
|
507
526
|
const key = bound.keys.get(area.room);
|
|
508
527
|
if (key === undefined)
|
|
509
528
|
return [];
|
|
510
|
-
const fence = fenced('f', key, area, true);
|
|
529
|
+
const fence = fenced('f.key', 'f.path', key, area, true);
|
|
511
530
|
return [fragment(`NOT ${grouped(fence).sql}`, fence.bind)];
|
|
512
531
|
});
|
|
513
532
|
const under = prefix === ''
|
|
@@ -703,16 +722,28 @@ function groups(connection, bound, plan, shape) {
|
|
|
703
722
|
...(total === undefined ? {} : { total }),
|
|
704
723
|
};
|
|
705
724
|
}
|
|
706
|
-
function boundOf(connection, plan, rooms) {
|
|
725
|
+
function boundOf(connection, plan, rooms, follows) {
|
|
707
726
|
return {
|
|
708
727
|
rooms: [...rooms].sort((left, right) => left.locator < right.locator ? -1 : left.locator > right.locator ? 1 : 0),
|
|
709
|
-
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)),
|
|
710
730
|
reach: plan.reach,
|
|
711
731
|
collate: collating(connection),
|
|
712
732
|
};
|
|
713
733
|
}
|
|
714
|
-
export function
|
|
715
|
-
|
|
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);
|
|
716
747
|
if (rooms.length === 0) {
|
|
717
748
|
return plan.shape.kind === 'groups'
|
|
718
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,EAAsC,MAAM,cAAc,CAAC;AAI/F,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;AAOrE,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,CA6GzE"}
|
package/dist/connection.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { notReadyWaitMs } from '@agentshouse/mdmodel';
|
|
1
2
|
import { submitLater } from './acceptance.js';
|
|
2
3
|
import { invokeAction, called, readConversationHistory, resendLater } from './actions.js';
|
|
3
4
|
import { builtInModel, NO_ROOM_TYPES } from './attached-model.js';
|
|
@@ -19,6 +20,10 @@ import { publishChangeSet, show } from './shown.js';
|
|
|
19
20
|
import { createSocket } from './socket.js';
|
|
20
21
|
import { createStore } from './store.js';
|
|
21
22
|
import { composedRuntime } from './surface.js';
|
|
23
|
+
import { adopt, discover } from './sync.js';
|
|
24
|
+
function writable(room) {
|
|
25
|
+
return room !== undefined && room.operations.write.length > 0;
|
|
26
|
+
}
|
|
22
27
|
const ROOM_ATTEMPTS = 16;
|
|
23
28
|
export function composeRuntime(options) {
|
|
24
29
|
const { adapter, shell } = options;
|
|
@@ -27,7 +32,7 @@ export function composeRuntime(options) {
|
|
|
27
32
|
const typedPaths = adapter.typedPaths ?? [];
|
|
28
33
|
const retries = createRetries(shell);
|
|
29
34
|
const socket = createSocket(adapter, retries, options.authorization);
|
|
30
|
-
const presence = createPresence();
|
|
35
|
+
const presence = createPresence(notReadyWaitMs);
|
|
31
36
|
const store = createStore({
|
|
32
37
|
retries,
|
|
33
38
|
database: {
|
|
@@ -47,6 +52,7 @@ export function composeRuntime(options) {
|
|
|
47
52
|
typedPaths,
|
|
48
53
|
persistence: shell.persistence,
|
|
49
54
|
lost: presence.lost,
|
|
55
|
+
losing: presence.losing,
|
|
50
56
|
opening: (local) => open(runtime, local),
|
|
51
57
|
unpublished: uncaught,
|
|
52
58
|
changed(set) {
|
|
@@ -56,7 +62,7 @@ export function composeRuntime(options) {
|
|
|
56
62
|
submitLater(runtime, locator);
|
|
57
63
|
return publishChangeSet(runtime, set);
|
|
58
64
|
},
|
|
59
|
-
deliverReadiness: (owed) => deliverOwedReadiness(runtime, owed),
|
|
65
|
+
deliverReadiness: (owed, rooms) => deliverOwedReadiness(runtime, owed, rooms),
|
|
60
66
|
spaceFreed: () => spaceFreed(runtime),
|
|
61
67
|
});
|
|
62
68
|
const recovery = (options.recovery ?? createRecovery()).scope(ROOM_ATTEMPTS);
|
|
@@ -67,12 +73,14 @@ export function composeRuntime(options) {
|
|
|
67
73
|
recovery,
|
|
68
74
|
retries,
|
|
69
75
|
shell,
|
|
70
|
-
|
|
76
|
+
savesLocally: (locator) => adapter.localSaves === true && !writable(presence.room(locator)),
|
|
71
77
|
roomTypes,
|
|
72
78
|
builtIn,
|
|
73
79
|
typedPaths,
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
renamedActions: adapter.renamedActions ?? new Map(),
|
|
81
|
+
rewrittenInputs: adapter.rewrittenInputs ?? new Map(),
|
|
82
|
+
keptInput: adapter.keptInput ?? ((input) => input),
|
|
83
|
+
writeRule: (declaration) => writeRule(declaration, adapter.pathRule ?? (() => true), adapter.localSaves === true && !writable(declaration)),
|
|
76
84
|
build: options.build ?? '',
|
|
77
85
|
conversations: createLiveConversations({
|
|
78
86
|
call: (name, input, attempt) => invokeAction(runtime, name, input, { attempt }),
|
|
@@ -115,7 +123,9 @@ export function composeRuntime(options) {
|
|
|
115
123
|
full: store.space.full,
|
|
116
124
|
filled: () => filled(runtime),
|
|
117
125
|
}),
|
|
126
|
+
discover: () => discover(runtime),
|
|
127
|
+
adopt: (unstored) => adopt(runtime, unstored),
|
|
118
128
|
};
|
|
119
|
-
start(runtime, options.signal);
|
|
129
|
+
start(runtime, options.signal, options.storeOnNeed === true);
|
|
120
130
|
return composedRuntime(runtime);
|
|
121
131
|
}
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKpD"}
|
package/dist/context.js
CHANGED