@agentshouse/mdruntime 0.1.0-cb8a03985803b → 0.1.0-cb9a984171ffb
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.js +1 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +26 -6
- package/dist/adapter.d.ts +113 -21
- 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/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +347 -0
- package/dist/binary.d.ts +6 -2
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +10 -3
- 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 +17 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +24 -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 +72 -41
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +11 -6
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +18 -9
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +17 -8
- package/dist/conversation-row.d.ts +8 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +20 -7
- package/dist/conversation.d.ts +16 -11
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +183 -139
- package/dist/declaration.js +1 -1
- 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 +1 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +3 -0
- package/dist/entry.d.ts +14 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +45 -16
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +4 -2
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- package/dist/host.d.ts +6 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +68 -27
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +67 -0
- package/dist/index.d.ts +13 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- 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 +38 -25
- 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 +167 -33
- package/dist/memory.d.ts +7 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +60 -20
- package/dist/messages.d.ts +8 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +14 -3
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +4 -2
- 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/opening.d.ts.map +1 -1
- package/dist/opening.js +18 -2
- package/dist/outcome.d.ts +21 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +18 -3
- package/dist/overlay.d.ts +4 -4
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +3 -5
- package/dist/parts.d.ts +3 -1
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -7
- 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 +114 -66
- package/dist/query.d.ts +2 -2
- 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.map +1 -1
- package/dist/queue.js +51 -21
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +122 -23
- package/dist/react.d.ts +6 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +19 -3
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +17 -10
- package/dist/reads.d.ts +1 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +2 -2
- 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/replica.d.ts.map +1 -1
- package/dist/replica.js +4 -4
- package/dist/room-draft.d.ts +28 -3
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +235 -14
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +11 -6
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +45 -0
- package/dist/rows.d.ts +11 -2
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +24 -10
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runtime.d.ts +4 -2
- 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 +17 -86
- package/dist/saves.d.ts +4 -2
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +75 -22
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +2 -2
- package/dist/shown.d.ts +3 -1
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +72 -41
- 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 +1 -0
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +1 -0
- package/dist/source.d.ts +7 -0
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +15 -2
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +18 -3
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +57 -21
- 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 +14 -9
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +12 -5
- package/dist/stored.d.ts +38 -14
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +210 -52
- package/dist/surface.d.ts +13 -7
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +52 -17
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +49 -27
- package/dist/tables.d.ts +22 -49
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +70 -325
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +1 -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 +28 -13
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +17 -12
- package/package.json +3 -3
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 { blobOf, } 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
|
}
|
|
@@ -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 blobOf(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', []),
|
|
@@ -266,11 +232,11 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
266
232
|
rename: (conversation, name, operation) => ask('conversation.rename', [conversation, name, operation]),
|
|
267
233
|
option: (conversation, option, value, operation) => ask('conversation.option', [conversation, option, value, 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]),
|
|
273
237
|
dismissSuggestion: (conversation, suggestion) => ask('conversation.dismissSuggestion', [conversation, suggestion]),
|
|
238
|
+
attach: (file) => ask('conversation.attach', [file]),
|
|
239
|
+
attachment: (link) => ask('conversation.attachment', [link]),
|
|
274
240
|
pageMetadata: async (app, address) => pageMetadataBlock(app, address, [...observations]
|
|
275
241
|
.sort(([left], [right]) => left - right)
|
|
276
242
|
.flatMap(([, { topic, input }]) => (topic === 'query' ? [input[0]] : []))),
|
|
@@ -283,9 +249,10 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
283
249
|
},
|
|
284
250
|
history: (locator, path, query) => ask('history', [locator, path, query]),
|
|
285
251
|
resolve: (room, path, destination) => ask('resolve', [room, path, destination]),
|
|
286
|
-
|
|
287
|
-
read: (room, path, revision) => ask('
|
|
288
|
-
|
|
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]),
|
|
289
256
|
download,
|
|
290
257
|
},
|
|
291
258
|
call: (name, input) => ask('call', [name, input]),
|
|
@@ -295,12 +262,13 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
|
|
|
295
262
|
retry: () => ask('retry', []),
|
|
296
263
|
cleanUp: () => ask('cleanUp', []),
|
|
297
264
|
unsent: () => ask('unsent', []),
|
|
265
|
+
sent: () => ask('sent', []),
|
|
298
266
|
reset: () => ask('reset', []),
|
|
299
267
|
readAgain: () => ask('readAgain', []),
|
|
300
268
|
observe: ((topic, ...input) => watch(topic, input)),
|
|
301
269
|
reauthorize: () => ask('reauthorize', []),
|
|
302
270
|
settled,
|
|
303
|
-
}
|
|
271
|
+
};
|
|
304
272
|
}
|
|
305
273
|
const turns = new WeakMap();
|
|
306
274
|
export function inTurn(client, work) {
|
|
@@ -310,5 +278,7 @@ export function inTurn(client, work) {
|
|
|
310
278
|
}
|
|
311
279
|
export { chainedWindows } from './chain.js';
|
|
312
280
|
export { roomDraftRevision } from './identity.js';
|
|
313
|
-
export {
|
|
314
|
-
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;AAsfD,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
2
|
import { binaryRecord } from './binary.js';
|
|
3
|
-
import { definitionsAt } from './collection.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, directory) {
|
|
13
|
+
return fragment(`(${path} = ? OR (${path} >= ? AND ${path} < ?))`, [
|
|
14
|
+
directory,
|
|
15
|
+
`${directory}/`,
|
|
16
|
+
`${directory}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: binaryRecord(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,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,CAuGzE"}
|
package/dist/connection.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { notReadyWaitMs } from '@agentshouse/mdmodel';
|
|
1
2
|
import { submitLater } from './acceptance.js';
|
|
2
3
|
import { invokeAction, called, readConversationHistory, resendLater } from './actions.js';
|
|
3
|
-
import { builtInModel,
|
|
4
|
+
import { builtInModel, NO_ROOM_TYPES } from './attached-model.js';
|
|
4
5
|
import { createLiveConversations } from './conversation-live.js';
|
|
5
6
|
import { writeRule } from './declaration.js';
|
|
6
7
|
import { refusedForSpace } from './durability.js';
|
|
@@ -19,15 +20,16 @@ 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';
|
|
22
24
|
const ROOM_ATTEMPTS = 16;
|
|
23
25
|
export function composeRuntime(options) {
|
|
24
26
|
const { adapter, shell } = options;
|
|
25
|
-
const roomTypes =
|
|
27
|
+
const roomTypes = adapter.roomTypes ?? NO_ROOM_TYPES;
|
|
26
28
|
const builtIn = builtInModel(roomTypes);
|
|
27
29
|
const typedPaths = adapter.typedPaths ?? [];
|
|
28
30
|
const retries = createRetries(shell);
|
|
29
31
|
const socket = createSocket(adapter, retries, options.authorization);
|
|
30
|
-
const presence = createPresence();
|
|
32
|
+
const presence = createPresence(notReadyWaitMs);
|
|
31
33
|
const store = createStore({
|
|
32
34
|
retries,
|
|
33
35
|
database: {
|
|
@@ -47,6 +49,7 @@ export function composeRuntime(options) {
|
|
|
47
49
|
typedPaths,
|
|
48
50
|
persistence: shell.persistence,
|
|
49
51
|
lost: presence.lost,
|
|
52
|
+
losing: presence.losing,
|
|
50
53
|
opening: (local) => open(runtime, local),
|
|
51
54
|
unpublished: uncaught,
|
|
52
55
|
changed(set) {
|
|
@@ -56,7 +59,7 @@ export function composeRuntime(options) {
|
|
|
56
59
|
submitLater(runtime, locator);
|
|
57
60
|
return publishChangeSet(runtime, set);
|
|
58
61
|
},
|
|
59
|
-
deliverReadiness: (owed) => deliverOwedReadiness(runtime, owed),
|
|
62
|
+
deliverReadiness: (owed, rooms) => deliverOwedReadiness(runtime, owed, rooms),
|
|
60
63
|
spaceFreed: () => spaceFreed(runtime),
|
|
61
64
|
});
|
|
62
65
|
const recovery = (options.recovery ?? createRecovery()).scope(ROOM_ATTEMPTS);
|
|
@@ -71,8 +74,8 @@ export function composeRuntime(options) {
|
|
|
71
74
|
roomTypes,
|
|
72
75
|
builtIn,
|
|
73
76
|
typedPaths,
|
|
77
|
+
renamedActions: adapter.renamedActions ?? new Map(),
|
|
74
78
|
writeRule: (declaration) => writeRule(declaration, adapter.pathRule ?? (() => true), adapter.localSaves === true),
|
|
75
|
-
usableWhenHeld: options.usableWhenHeld ?? [],
|
|
76
79
|
build: options.build ?? '',
|
|
77
80
|
conversations: createLiveConversations({
|
|
78
81
|
call: (name, input, attempt) => invokeAction(runtime, name, input, { attempt }),
|
|
@@ -115,7 +118,9 @@ export function composeRuntime(options) {
|
|
|
115
118
|
full: store.space.full,
|
|
116
119
|
filled: () => filled(runtime),
|
|
117
120
|
}),
|
|
121
|
+
discover: () => discover(runtime),
|
|
122
|
+
adopt: (unstored) => adopt(runtime, unstored),
|
|
118
123
|
};
|
|
119
|
-
start(runtime, options.signal);
|
|
124
|
+
start(runtime, options.signal, options.storeOnNeed === true);
|
|
120
125
|
return composedRuntime(runtime);
|
|
121
126
|
}
|
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