@agentshouse/mdruntime 0.1.0-c6bf34fa9e444 → 0.1.0-c6d3d5d8beeb0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -19
- package/dist/acceptance.d.ts +0 -3
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +105 -166
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +180 -85
- package/dist/adapter.d.ts +222 -73
- 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 +345 -0
- package/dist/bootstrap.d.ts +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +6 -18
- package/dist/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/change.d.ts +6 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +7 -2
- 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 +30 -23
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +55 -68
- package/dist/collection.d.ts +27 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +34 -10
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +4 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +101 -63
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +45 -28
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +150 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +260 -0
- package/dist/conversation-row.d.ts +23 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +39 -4
- package/dist/conversation.d.ts +67 -49
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +993 -1032
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +47 -47
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +5 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +26 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +126 -36
- package/dist/expectation.d.ts +26 -13
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +72 -19
- package/dist/failure.d.ts +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +8 -0
- package/dist/figures.d.ts +2 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +8 -6
- 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 +24 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +108 -32
- 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 +30 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -8
- package/dist/install.d.ts +10 -6
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +93 -116
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +81 -56
- package/dist/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +16 -0
- package/dist/listing.d.ts +29 -22
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +71 -78
- package/dist/live.d.ts +19 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +97 -39
- 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 +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +12 -39
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +11 -23
- package/dist/media.d.ts +20 -4
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +184 -37
- package/dist/memory.d.ts +10 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +103 -40
- package/dist/messages.d.ts +21 -6
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +54 -42
- 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 -8
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -5
- package/dist/models.d.ts +4 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +97 -137
- 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 +217 -85
- 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 +6 -6
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +7 -7
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +26 -11
- package/dist/outcome.d.ts +33 -13
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +36 -6
- package/dist/overlay.d.ts +23 -8
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +132 -48
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +6 -58
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +28 -110
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +22 -0
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +210 -92
- package/dist/presence.d.ts +58 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +231 -0
- package/dist/queries.d.ts +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +138 -80
- package/dist/query.d.ts +2 -3
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +3 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +6 -7
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +482 -0
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +200 -40
- package/dist/react.d.ts +21 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- package/dist/readiness.d.ts +23 -5
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +5 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +64 -11
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +6 -6
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +5 -6
- package/dist/replica.d.ts +6 -16
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +20 -21
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +32 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +282 -72
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +29 -23
- 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 +28 -15
- 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 +16 -21
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +43 -86
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +337 -232
- package/dist/saves.d.ts +9 -45
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +208 -748
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +4 -5
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shared.d.ts +1 -6
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -95
- package/dist/shown.d.ts +10 -6
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +108 -75
- package/dist/socket/lanes.d.ts +12 -4
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +34 -8
- package/dist/socket/session.d.ts +4 -2
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +7 -7
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +13 -16
- package/dist/source.d.ts +42 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +81 -13
- 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 +33 -11
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +94 -28
- 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/space.d.ts +1 -1
- package/dist/store/space.d.ts.map +1 -1
- package/dist/store/space.js +0 -2
- package/dist/store/watchers.js +1 -2
- package/dist/store.d.ts +26 -16
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +50 -18
- package/dist/stored.d.ts +42 -17
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +236 -66
- package/dist/surface.d.ts +21 -9
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +74 -38
- package/dist/sync.d.ts +4 -3
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +136 -110
- package/dist/tables.d.ts +43 -58
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +114 -334
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +8 -9
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +51 -11
- package/dist/wire.d.ts +72 -12
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +31 -14
- package/package.json +4 -3
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- package/dist/job.d.ts +0 -33
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -54
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/socket/rooms.d.ts +0 -43
- package/dist/socket/rooms.d.ts.map +0 -1
- package/dist/socket/rooms.js +0 -90
- package/dist/store/fences.d.ts +0 -16
- package/dist/store/fences.d.ts.map +0 -1
- package/dist/store/fences.js +0 -26
package/dist/collection.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import { 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
|
}
|
|
@@ -33,6 +34,16 @@ export function governing(composition, path) {
|
|
|
33
34
|
? composition.selection.model
|
|
34
35
|
: composition.model;
|
|
35
36
|
}
|
|
37
|
+
function definitionsUnder(composition, path, typedPaths, typesOf) {
|
|
38
|
+
const types = typesOf(governing(composition, path));
|
|
39
|
+
return types === null ? () => undefined : definitionAt({ types }, path, typedPaths);
|
|
40
|
+
}
|
|
41
|
+
export function definitionsAt(composition, path) {
|
|
42
|
+
return definitionsUnder(composition, path, composition.typedPaths, (model) => model.status === 'unavailable' ? null : model.types);
|
|
43
|
+
}
|
|
44
|
+
export function definitionsIn(room, path, typedPaths) {
|
|
45
|
+
return definitionsUnder({ model: room.model, selection: room.typedSelection }, path, typedPaths, ({ types }) => types === null ? null : Object.fromEntries(types.map((type) => [type.name, type])));
|
|
46
|
+
}
|
|
36
47
|
export function collectionOf(text, composition) {
|
|
37
48
|
const parsed = new Map();
|
|
38
49
|
return {
|
|
@@ -44,7 +55,7 @@ export function collectionOf(text, composition) {
|
|
|
44
55
|
const content = text[path];
|
|
45
56
|
if (content === undefined)
|
|
46
57
|
return undefined;
|
|
47
|
-
const read = parse(content, path);
|
|
58
|
+
const read = parse(content, path, definitionsAt(composition, path));
|
|
48
59
|
parsed.set(path, read.ok ? read.document : null);
|
|
49
60
|
return read.ok ? read.document : undefined;
|
|
50
61
|
},
|
|
@@ -63,6 +74,19 @@ export function* documentsOf(collection) {
|
|
|
63
74
|
export function validRoot(root) {
|
|
64
75
|
return typeof root === 'string' && normalize(root) === root;
|
|
65
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
|
+
}
|
|
66
90
|
export function available(composition) {
|
|
67
91
|
return composition.model.status !== 'unavailable';
|
|
68
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,11 +331,20 @@ 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
|
-
const fileId = row.file_id
|
|
317
|
-
const revision = row.revision
|
|
346
|
+
const fileId = row.file_id;
|
|
347
|
+
const revision = row.revision;
|
|
318
348
|
if (type === null) {
|
|
319
349
|
const binary = row.binary === null ? null : JSON.parse(row.binary);
|
|
320
350
|
const content = row.content ?? null;
|
|
@@ -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,
|
|
@@ -365,7 +396,7 @@ function changeOf(row) {
|
|
|
365
396
|
function heldFacts(shape, row) {
|
|
366
397
|
return {
|
|
367
398
|
...(shape.size ? { size: row.bytes === null ? null : Number(row.bytes) } : {}),
|
|
368
|
-
...(shape.created ? { created: row.created
|
|
399
|
+
...(shape.created ? { created: row.created } : {}),
|
|
369
400
|
};
|
|
370
401
|
}
|
|
371
402
|
function backlinksOf(connection, bound, rows) {
|
|
@@ -377,10 +408,10 @@ function backlinksOf(connection, bound, rows) {
|
|
|
377
408
|
held.push(row.path);
|
|
378
409
|
byKey.set(key, held);
|
|
379
410
|
}
|
|
411
|
+
const reach = reached(bound, 's.key', 's.path');
|
|
380
412
|
for (const [key, targets] of byKey) {
|
|
381
|
-
const reach = reached(bound, 's');
|
|
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) ?? [];
|
|
@@ -395,22 +426,19 @@ function documents(connection, bound, plan, shape, budget) {
|
|
|
395
426
|
const filter = filtered(bound, plan);
|
|
396
427
|
const cursor = plan.after?.values ?? null;
|
|
397
428
|
const room = located('d');
|
|
398
|
-
const
|
|
429
|
+
const after = cursor === null
|
|
399
430
|
? null
|
|
400
431
|
: (() => {
|
|
401
432
|
const key = cursor[shape.orderBy.length];
|
|
402
|
-
return any([
|
|
433
|
+
return sql.following(terms.map(({ term }, index) => sql.beyond(bound.collate, term, cursor[index])), any([
|
|
403
434
|
fragment(`${room.sql} > ?`, [...room.bind, roomOfKey(key)]),
|
|
404
435
|
fragment(`${room.sql} = ? AND d.path > ?`, [
|
|
405
436
|
...room.bind,
|
|
406
437
|
roomOfKey(key),
|
|
407
438
|
pathOfKey(key),
|
|
408
439
|
]),
|
|
409
|
-
]);
|
|
440
|
+
]));
|
|
410
441
|
})();
|
|
411
|
-
const after = cursor === null || tie === null
|
|
412
|
-
? null
|
|
413
|
-
: sql.following(terms.map(({ term }, index) => sql.beyond(bound.collate, term, cursor[index])), tie);
|
|
414
442
|
const selected = joined([
|
|
415
443
|
fragment('SELECT d.id, d.key, d.path, d.type, d.binary, d.revision, d.fields, d.change, d.file_id, d.bytes, d.created'),
|
|
416
444
|
...terms.map(({ term }, index) => joined([
|
|
@@ -431,8 +459,9 @@ function documents(connection, bound, plan, shape, budget) {
|
|
|
431
459
|
const kept = bodied(shape) ? withContent(connection, windowed, budget) : windowed;
|
|
432
460
|
const cut = kept.length;
|
|
433
461
|
const roomOf = new Map(bound.rooms.map(({ key, locator }) => [key, locator]));
|
|
462
|
+
const queried = new Map(bound.rooms.map((one) => [one.key, one]));
|
|
434
463
|
const linked = shape.backlinks ? backlinksOf(connection, bound, kept) : new Map();
|
|
435
|
-
const found = kept.map((row) => documentOf(shape,
|
|
464
|
+
const found = kept.map((row) => documentOf(shape, queried.get(Number(row.key)), row, linked));
|
|
436
465
|
const last = kept.at(-1);
|
|
437
466
|
const cursorAt = (row) => cursorOf([
|
|
438
467
|
...shape.orderBy.map(({ key }, index) => decodedKey(key, row, index)),
|
|
@@ -497,7 +526,7 @@ function storedFolders(bound, plan, subfolder) {
|
|
|
497
526
|
const key = bound.keys.get(area.room);
|
|
498
527
|
if (key === undefined)
|
|
499
528
|
return [];
|
|
500
|
-
const fence = fenced('f', key, area, true);
|
|
529
|
+
const fence = fenced('f.key', 'f.path', key, area, true);
|
|
501
530
|
return [fragment(`NOT ${grouped(fence).sql}`, fence.bind)];
|
|
502
531
|
});
|
|
503
532
|
const under = prefix === ''
|
|
@@ -645,17 +674,14 @@ function groups(connection, bound, plan, shape) {
|
|
|
645
674
|
{ ordering: GROUP_TIES, kind: fragment("'string'"), value: fragment(`k${index}`) },
|
|
646
675
|
]);
|
|
647
676
|
const cursor = plan.after?.values ?? null;
|
|
648
|
-
const
|
|
677
|
+
const after = cursor === null
|
|
649
678
|
? null
|
|
650
|
-
:
|
|
651
|
-
value,
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
: sql.following(ordered.map((term, index) => sql.beyond(bound.collate, term, cursor[index])), sql.following(ties
|
|
657
|
-
.slice(0, -1)
|
|
658
|
-
.map((term, index) => sql.beyond(bound.collate, term, tieValues[index])), sql.beyond(bound.collate, ties.at(-1), tieValues.at(-1)).beyond));
|
|
679
|
+
: (() => {
|
|
680
|
+
const tieValues = cursor[shape.orderBy.length].flatMap((value) => [value, heldKind(value ?? null)]);
|
|
681
|
+
return sql.following(ordered.map((term, index) => sql.beyond(bound.collate, term, cursor[index])), sql.following(ties
|
|
682
|
+
.slice(0, -1)
|
|
683
|
+
.map((term, index) => sql.beyond(bound.collate, term, tieValues[index])), sql.beyond(bound.collate, ties.at(-1), tieValues.at(-1)).beyond));
|
|
684
|
+
})();
|
|
659
685
|
const grouping = joined([fragment(`SELECT ${columns} FROM (`), ranked, fragment(`) GROUP BY ${held}`)], '');
|
|
660
686
|
const windowed = joined([
|
|
661
687
|
fragment('SELECT * FROM ('),
|
|
@@ -696,16 +722,28 @@ function groups(connection, bound, plan, shape) {
|
|
|
696
722
|
...(total === undefined ? {} : { total }),
|
|
697
723
|
};
|
|
698
724
|
}
|
|
699
|
-
function boundOf(connection, plan, rooms) {
|
|
725
|
+
function boundOf(connection, plan, rooms, follows) {
|
|
700
726
|
return {
|
|
701
727
|
rooms: [...rooms].sort((left, right) => left.locator < right.locator ? -1 : left.locator > right.locator ? 1 : 0),
|
|
702
|
-
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)),
|
|
703
730
|
reach: plan.reach,
|
|
704
731
|
collate: collating(connection),
|
|
705
732
|
};
|
|
706
733
|
}
|
|
707
|
-
export function
|
|
708
|
-
|
|
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);
|
|
709
747
|
if (rooms.length === 0) {
|
|
710
748
|
return plan.shape.kind === 'groups'
|
|
711
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,CA4GzE"}
|
package/dist/connection.js
CHANGED
|
@@ -1,33 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { notReadyWaitMs } from '@agentshouse/mdmodel';
|
|
2
|
+
import { submitLater } from './acceptance.js';
|
|
2
3
|
import { invokeAction, called, readConversationHistory, resendLater } from './actions.js';
|
|
3
|
-
import { builtInModel,
|
|
4
|
-
import {
|
|
4
|
+
import { builtInModel, NO_ROOM_TYPES } from './attached-model.js';
|
|
5
|
+
import { createLiveConversations } from './conversation-live.js';
|
|
6
|
+
import { writeRule } from './declaration.js';
|
|
5
7
|
import { refusedForSpace } from './durability.js';
|
|
8
|
+
import { uncaught } from './failure.js';
|
|
6
9
|
import { createFigures } from './figures.js';
|
|
7
10
|
import { scheduleCurrency, spaceFreed, start } from './lifecycle.js';
|
|
8
11
|
import { createLiveQueries } from './live.js';
|
|
9
|
-
import { createLog } from './log.js';
|
|
10
|
-
import { scoped } from './models.js';
|
|
11
12
|
import { open } from './opening.js';
|
|
12
|
-
import { deliverOwedReadiness, filled } from './preparation.js';
|
|
13
|
+
import { deliverOwedReadiness, filled, prepare } from './preparation.js';
|
|
14
|
+
import { createPresence } from './presence.js';
|
|
13
15
|
import { answeredPlan, figuresCover, roomTallies } from './queries.js';
|
|
14
16
|
import { readAnswers } from './reads.js';
|
|
15
17
|
import { createRecovery } from './recovery.js';
|
|
16
|
-
import {
|
|
18
|
+
import { createRetries } from './retried.js';
|
|
17
19
|
import { publishChangeSet, show } from './shown.js';
|
|
18
20
|
import { createSocket } from './socket.js';
|
|
19
21
|
import { createStore } from './store.js';
|
|
20
22
|
import { composedRuntime } from './surface.js';
|
|
21
|
-
import {
|
|
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;
|
|
25
|
-
const roomTypes =
|
|
30
|
+
const roomTypes = adapter.roomTypes ?? NO_ROOM_TYPES;
|
|
26
31
|
const builtIn = builtInModel(roomTypes);
|
|
27
32
|
const typedPaths = adapter.typedPaths ?? [];
|
|
28
|
-
const
|
|
29
|
-
const socket = createSocket(adapter,
|
|
33
|
+
const retries = createRetries(shell);
|
|
34
|
+
const socket = createSocket(adapter, retries, options.authorization);
|
|
35
|
+
const presence = createPresence(notReadyWaitMs);
|
|
30
36
|
const store = createStore({
|
|
37
|
+
retries,
|
|
31
38
|
database: {
|
|
32
39
|
async ask(request) {
|
|
33
40
|
try {
|
|
@@ -44,29 +51,38 @@ export function composeRuntime(options) {
|
|
|
44
51
|
builtIn,
|
|
45
52
|
typedPaths,
|
|
46
53
|
persistence: shell.persistence,
|
|
54
|
+
lost: presence.lost,
|
|
55
|
+
losing: presence.losing,
|
|
47
56
|
opening: (local) => open(runtime, local),
|
|
48
|
-
unpublished
|
|
49
|
-
|
|
57
|
+
unpublished: uncaught,
|
|
58
|
+
changed(set) {
|
|
59
|
+
if (set.unindexed.length > 0)
|
|
60
|
+
prepare(runtime, set.unindexed);
|
|
61
|
+
for (const locator of set.due)
|
|
62
|
+
submitLater(runtime, locator);
|
|
63
|
+
return publishChangeSet(runtime, set);
|
|
50
64
|
},
|
|
51
|
-
|
|
52
|
-
deliverReadiness: (owed) => deliverOwedReadiness(runtime, owed),
|
|
65
|
+
deliverReadiness: (owed, rooms) => deliverOwedReadiness(runtime, owed, rooms),
|
|
53
66
|
spaceFreed: () => spaceFreed(runtime),
|
|
54
67
|
});
|
|
55
68
|
const recovery = (options.recovery ?? createRecovery()).scope(ROOM_ATTEMPTS);
|
|
56
69
|
const runtime = {
|
|
57
70
|
store,
|
|
58
71
|
socket,
|
|
59
|
-
|
|
72
|
+
presence,
|
|
60
73
|
recovery,
|
|
74
|
+
retries,
|
|
61
75
|
shell,
|
|
62
|
-
|
|
76
|
+
savesLocally: (locator) => adapter.localSaves === true && !writable(presence.room(locator)),
|
|
63
77
|
roomTypes,
|
|
64
78
|
builtIn,
|
|
65
79
|
typedPaths,
|
|
66
|
-
|
|
80
|
+
renamedActions: adapter.renamedActions ?? new Map(),
|
|
81
|
+
rewrittenInputs: adapter.rewrittenInputs ?? new Map(),
|
|
82
|
+
writeRule: (declaration) => writeRule(declaration, adapter.pathRule ?? (() => true), adapter.localSaves === true && !writable(declaration)),
|
|
67
83
|
build: options.build ?? '',
|
|
68
|
-
conversations:
|
|
69
|
-
call: (name, input) => invokeAction(runtime, name, input),
|
|
84
|
+
conversations: createLiveConversations({
|
|
85
|
+
call: (name, input, attempt) => invokeAction(runtime, name, input, { attempt }),
|
|
70
86
|
history: (request) => readConversationHistory(runtime, request),
|
|
71
87
|
durably: store.durably,
|
|
72
88
|
local: store.open,
|
|
@@ -82,6 +98,9 @@ export function composeRuntime(options) {
|
|
|
82
98
|
full: store.space.full,
|
|
83
99
|
closed: socket.closed,
|
|
84
100
|
unanswered: () => resendLater(runtime),
|
|
101
|
+
heard: (operation, lost) => socket.lanes.settle(operation, lost),
|
|
102
|
+
recovery: recovery.scope(),
|
|
103
|
+
retries,
|
|
85
104
|
}),
|
|
86
105
|
liveQueries: createLiveQueries((plan, cover) => answeredPlan(runtime, plan, cover), store.covering),
|
|
87
106
|
figures: createFigures({
|
|
@@ -95,19 +114,17 @@ export function composeRuntime(options) {
|
|
|
95
114
|
unkept: adapter.unkeptReads ?? [],
|
|
96
115
|
leading: adapter.leadingReads ?? [],
|
|
97
116
|
recovery: recovery.scope(),
|
|
98
|
-
|
|
117
|
+
retries,
|
|
118
|
+
call: (name, input, attempt) => called(runtime, name, input, attempt),
|
|
99
119
|
online: socket.reached,
|
|
120
|
+
streaming: socket.isOpen,
|
|
100
121
|
closed: socket.closed,
|
|
101
122
|
full: store.space.full,
|
|
102
123
|
filled: () => filled(runtime),
|
|
103
124
|
}),
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
submitLater: (locator) => submitLater(runtime, locator),
|
|
107
|
-
unpair: (local) => unpair(runtime, local),
|
|
108
|
-
advanced: (...held) => advanced(runtime, ...held),
|
|
109
|
-
withhold: (...held) => withhold(runtime, ...held),
|
|
125
|
+
discover: () => discover(runtime),
|
|
126
|
+
adopt: (unstored) => adopt(runtime, unstored),
|
|
110
127
|
};
|
|
111
|
-
start(runtime, options.signal);
|
|
128
|
+
start(runtime, options.signal, options.storeOnNeed === true);
|
|
112
129
|
return composedRuntime(runtime);
|
|
113
130
|
}
|
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