@agentshouse/mdruntime 0.1.0-cee9c8aa4cd86 → 0.1.0-cf1e7fdb9c600
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 +11 -9
- package/dist/adapter.d.ts +96 -63
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +2 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +28 -4
- package/dist/binary.d.ts +0 -5
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +1 -1
- package/dist/bootstrap.d.ts +17 -9
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +143 -94
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/client.d.ts +12 -12
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +54 -8
- package/dist/collection.d.ts +7 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +24 -19
- package/dist/compile.d.ts +1 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +118 -247
- package/dist/connection.d.ts +11 -11
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1602 -1147
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/{chat/context.js → context.js} +1 -4
- package/dist/conversation.d.ts +18 -14
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +266 -150
- package/dist/durability.d.ts +1 -5
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +3 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +15 -6
- package/dist/file.d.ts +2 -11
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +6 -4
- package/dist/host.d.ts +3 -6
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +49 -35
- package/dist/index.d.ts +15 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/job.d.ts +14 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +28 -0
- package/dist/live.d.ts +2 -1
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +9 -5
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +11 -6
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +178 -100
- package/dist/messages.d.ts +2 -2
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +15 -16
- package/dist/model.d.ts +7 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -13
- package/dist/observation.d.ts +3 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +8 -3
- package/dist/outcome.d.ts +13 -6
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +16 -5
- package/dist/overlay.js +1 -1
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -0
- package/dist/query.d.ts +10 -205
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -494
- package/dist/reach.d.ts +14 -9
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +81 -71
- package/dist/react.d.ts +3 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +13 -16
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +2 -8
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +26 -0
- package/dist/refresh.d.ts +10 -4
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +104 -30
- package/dist/replica.d.ts +6 -5
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +8 -7
- package/dist/room-draft.d.ts +20 -3
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +131 -51
- package/dist/rows.d.ts +8 -15
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +51 -151
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +13 -7
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/shared.d.ts +0 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +0 -10
- package/dist/status.d.ts +4 -3
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -1
- package/dist/store.d.ts +32 -30
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +64 -58
- package/dist/stored.d.ts +42 -18
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +193 -194
- package/dist/tables.d.ts +60 -39
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +77 -59
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/validation.d.ts +3 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +39 -97
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +6 -9
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +3 -3
- package/package.json +11 -18
- package/AGENTS.md +0 -320
- package/dist/chat/acts.d.ts +0 -33
- package/dist/chat/acts.d.ts.map +0 -1
- package/dist/chat/acts.js +0 -36
- package/dist/chat/context.d.ts +0 -3
- package/dist/chat/context.d.ts.map +0 -1
- package/dist/chat/earlier.d.ts +0 -10
- package/dist/chat/earlier.d.ts.map +0 -1
- package/dist/chat/earlier.js +0 -54
- package/dist/chat/house.d.ts +0 -25
- package/dist/chat/house.d.ts.map +0 -1
- package/dist/chat/house.js +0 -38
- package/dist/chat/input.d.ts +0 -11
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -92
- package/dist/chat/kit.d.ts +0 -61
- package/dist/chat/kit.d.ts.map +0 -1
- package/dist/chat/kit.js +0 -123
- package/dist/chat/lasting.d.ts +0 -6
- package/dist/chat/lasting.d.ts.map +0 -1
- package/dist/chat/lasting.js +0 -19
- package/dist/chat/list.d.ts +0 -28
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -103
- package/dist/chat/markdown.d.ts +0 -21
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -246
- package/dist/chat/message.d.ts +0 -7
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -254
- package/dist/chat/messages.d.ts +0 -35
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -210
- package/dist/chat/name.d.ts +0 -7
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -12
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -19
- package/dist/chat/overlay.d.ts +0 -32
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -103
- package/dist/chat/parts.d.ts +0 -58
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/parts.js +0 -120
- package/dist/chat/pieces.d.ts +0 -62
- package/dist/chat/pieces.d.ts.map +0 -1
- package/dist/chat/pieces.js +0 -1110
- package/dist/chat/process.d.ts +0 -20
- package/dist/chat/process.d.ts.map +0 -1
- package/dist/chat/process.js +0 -32
- package/dist/chat/provider.d.ts +0 -70
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -635
- package/dist/chat/question.d.ts +0 -9
- package/dist/chat/question.d.ts.map +0 -1
- package/dist/chat/question.js +0 -69
- package/dist/chat/questions.d.ts +0 -31
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/questions.js +0 -111
- package/dist/chat/read.d.ts +0 -5
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat/read.js +0 -13
- package/dist/chat/ready.d.ts +0 -37
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -93
- package/dist/chat/room-file.d.ts +0 -8
- package/dist/chat/room-file.d.ts.map +0 -1
- package/dist/chat/room-file.js +0 -72
- package/dist/chat/steady.d.ts +0 -3
- package/dist/chat/steady.d.ts.map +0 -1
- package/dist/chat/steady.js +0 -26
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -307
- package/dist/chat.d.ts +0 -15
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -8
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -368
- package/dist/reads.d.ts +0 -11
- package/dist/reads.d.ts.map +0 -1
- package/dist/reads.js +0 -98
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -150
package/dist/compile.js
CHANGED
|
@@ -1,107 +1,36 @@
|
|
|
1
|
-
import { ARRAY_INDEX, parse, pointerSegments } from '@agentshouse/mdmodel';
|
|
1
|
+
import { ARRAY_INDEX, bodied, byCodePoint, compared, cursorOf, heldKind, parse, pointerSegments, sql, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { binaryRecord } from './binary.js';
|
|
3
|
-
import { documentKey,
|
|
4
|
-
import {
|
|
3
|
+
import { documentKey, pathOfKey, roomOfKey } from './rows.js';
|
|
4
|
+
import { FROM_START, MAXIMUM_WINDOW } from './windows.js';
|
|
5
|
+
const { all, any, exists, fragment, grouped, joined, listed } = sql;
|
|
5
6
|
const VISIBLE = (alias) => `${alias}.visible = 1 AND ${alias}.present = 1 AND ${alias}.queried = 1`;
|
|
6
|
-
function
|
|
7
|
-
return
|
|
7
|
+
function located(alias) {
|
|
8
|
+
return fragment(`(SELECT k.locator FROM replica_keys k WHERE k.key = ${alias}.key)`);
|
|
8
9
|
}
|
|
9
|
-
function
|
|
10
|
-
return {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function all(parts) {
|
|
16
|
-
return parts.length === 0 ? fragment('1') : joined(parts.map(grouped), ' AND ');
|
|
17
|
-
}
|
|
18
|
-
function any(parts) {
|
|
19
|
-
return parts.length === 0 ? fragment('0') : joined(parts.map(grouped), ' OR ');
|
|
20
|
-
}
|
|
21
|
-
function grouped(part) {
|
|
22
|
-
return { sql: `(${part.sql})`, bind: part.bind };
|
|
23
|
-
}
|
|
24
|
-
function list(values) {
|
|
25
|
-
return fragment(`(${values.map(() => '?').join(', ')})`, values);
|
|
26
|
-
}
|
|
27
|
-
function sqlValue(value) {
|
|
28
|
-
if (value === null)
|
|
29
|
-
return { kind: 'null', value: null };
|
|
30
|
-
if (typeof value === 'boolean')
|
|
31
|
-
return { kind: 'boolean', value: value ? 1 : 0 };
|
|
32
|
-
if (typeof value === 'number')
|
|
33
|
-
return { kind: 'number', value };
|
|
34
|
-
return { kind: 'string', value };
|
|
35
|
-
}
|
|
36
|
-
function same(alias, value) {
|
|
37
|
-
const held = sqlValue(value);
|
|
38
|
-
return held.kind === 'null'
|
|
39
|
-
? fragment(`${alias}.kind = 'null'`)
|
|
40
|
-
: fragment(`${alias}.kind = ? AND ${alias}.value = ?`, [held.kind, held.value]);
|
|
41
|
-
}
|
|
42
|
-
const BOUNDS = { gt: '>', gte: '>=', lt: '<', lte: '<=' };
|
|
43
|
-
function heldValues(doc, field, alias, where) {
|
|
44
|
-
return fragment(`SELECT 1 FROM replica_values ${alias} WHERE ${alias}.doc = ${doc}.id AND ${alias}.form = ? AND (${where.sql})`, [field, ...where.bind]);
|
|
45
|
-
}
|
|
46
|
-
function exists(part) {
|
|
47
|
-
return { sql: `EXISTS (${part.sql})`, bind: part.bind };
|
|
48
|
-
}
|
|
49
|
-
function matching(held, doc, field, values) {
|
|
50
|
-
return any(values.map((value) => any([
|
|
51
|
-
same(held, value),
|
|
52
|
-
all([
|
|
53
|
-
fragment(`${held}.kind = 'array'`),
|
|
54
|
-
exists(heldValues(doc, field, 'i', all([fragment(`i.held = ${held}.held AND i.item >= 0`), same('i', value)]))),
|
|
55
|
-
]),
|
|
56
|
-
])));
|
|
57
|
-
}
|
|
58
|
-
function tested(doc, field, test) {
|
|
59
|
-
const reached = exists(heldValues(doc, field, 'r', fragment('r.item = -1')));
|
|
60
|
-
if (test.op === 'exists')
|
|
61
|
-
return test.exists ? reached : fragment(`NOT ${reached.sql}`, reached.bind);
|
|
62
|
-
if (test.op === 'eq' || test.op === 'in') {
|
|
63
|
-
const values = test.op === 'eq' ? [test.value] : test.values;
|
|
64
|
-
return exists(heldValues(doc, field, 'v', any(values.map((value) => same('v', value)))));
|
|
65
|
-
}
|
|
66
|
-
if (test.op === 'ne' || test.op === 'nin') {
|
|
67
|
-
const values = test.op === 'ne' ? [test.value] : test.values;
|
|
68
|
-
const unmatched = matching('h', doc, field, values);
|
|
69
|
-
return any([
|
|
70
|
-
fragment(`NOT ${reached.sql}`, reached.bind),
|
|
71
|
-
exists(heldValues(doc, field, 'h', all([fragment('h.item = -1'), fragment(`NOT (${unmatched.sql})`, unmatched.bind)]))),
|
|
72
|
-
]);
|
|
73
|
-
}
|
|
74
|
-
if (test.op === 'range') {
|
|
75
|
-
return exists(heldValues(doc, field, 'v', all([
|
|
76
|
-
fragment('v.item = -1'),
|
|
77
|
-
...test.bounds.map(([operator, bound]) => {
|
|
78
|
-
const held = sqlValue(bound);
|
|
79
|
-
return fragment(`v.kind = ? AND v.value ${BOUNDS[operator]} ?`, [
|
|
80
|
-
held.kind,
|
|
81
|
-
held.value,
|
|
82
|
-
]);
|
|
83
|
-
}),
|
|
84
|
-
])));
|
|
85
|
-
}
|
|
86
|
-
if (test.op === 'all') {
|
|
87
|
-
return exists(heldValues(doc, field, 'h', all([
|
|
88
|
-
fragment("h.item = -1 AND h.kind = 'array'"),
|
|
89
|
-
...test.values.map((value) => exists(heldValues(doc, field, 'i', all([fragment('i.held = h.held AND i.item >= 0'), same('i', value)])))),
|
|
90
|
-
])));
|
|
91
|
-
}
|
|
92
|
-
return exists(heldValues(doc, field, 'v', fragment("v.item = -1 AND v.kind = 'array' AND v.size = ?", [test.size])));
|
|
10
|
+
function within(alias, path) {
|
|
11
|
+
return fragment(`(${alias}.path = ? OR (${alias}.path >= ? AND ${alias}.path < ?))`, [
|
|
12
|
+
path,
|
|
13
|
+
`${path}/`,
|
|
14
|
+
`${path}0`,
|
|
15
|
+
]);
|
|
93
16
|
}
|
|
94
|
-
function
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return
|
|
99
|
-
|
|
17
|
+
function ancestors(area) {
|
|
18
|
+
const depth = area.path.split('/').length;
|
|
19
|
+
return area.open.flatMap((open) => {
|
|
20
|
+
const segments = open.split('/');
|
|
21
|
+
return segments.slice(depth - 1, -1).map((_, at) => segments.slice(0, depth + at).join('/'));
|
|
22
|
+
});
|
|
100
23
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
24
|
+
function fenced(alias, key, area, folders) {
|
|
25
|
+
const opened = any([
|
|
26
|
+
...area.open.map((open) => within(alias, open)),
|
|
27
|
+
...(folders ? ancestors(area).map((path) => fragment(`${alias}.path = ?`, [path])) : []),
|
|
28
|
+
]);
|
|
29
|
+
return all([
|
|
30
|
+
fragment(`${alias}.key = ?`, [key]),
|
|
31
|
+
within(alias, area.path),
|
|
32
|
+
fragment(`NOT ${grouped(opened).sql}`, opened.bind),
|
|
33
|
+
]);
|
|
105
34
|
}
|
|
106
35
|
function reached(bound, alias) {
|
|
107
36
|
const reach = bound.reach;
|
|
@@ -115,44 +44,38 @@ function reached(bound, alias) {
|
|
|
115
44
|
const key = bound.keys.get(roomOfKey(held));
|
|
116
45
|
return key === undefined ? [] : [[key, pathOfKey(held)]];
|
|
117
46
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
: [
|
|
123
|
-
fragment(`EXISTS (SELECT 1 FROM json_each(?) j WHERE j.value ->> 0 = ${alias}.key AND j.value ->> 1 = ${alias}.path)`, [JSON.stringify(documents)]),
|
|
124
|
-
]),
|
|
125
|
-
]);
|
|
126
|
-
}
|
|
127
|
-
function scoped(alias, scope) {
|
|
47
|
+
const outside = any(reach.areas.flatMap((area) => {
|
|
48
|
+
const key = bound.keys.get(area.room);
|
|
49
|
+
return key === undefined ? [] : [fenced(alias, key, area, false)];
|
|
50
|
+
}));
|
|
128
51
|
return all([
|
|
129
|
-
|
|
130
|
-
? []
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
fragment(`${alias}.path >= ? AND ${alias}.path < ?`, [
|
|
136
|
-
`${scope.pathPrefix}/`,
|
|
137
|
-
`${scope.pathPrefix}0`,
|
|
52
|
+
any([
|
|
53
|
+
...(rooms.length === 0 ? [] : [fragment(`${alias}.key IN ${listed(rooms).sql}`, rooms)]),
|
|
54
|
+
...(documents.length === 0
|
|
55
|
+
? []
|
|
56
|
+
: [
|
|
57
|
+
fragment(`EXISTS (SELECT 1 FROM json_each(?) j WHERE j.value ->> 0 = ${alias}.key AND j.value ->> 1 = ${alias}.path)`, [JSON.stringify(documents)]),
|
|
138
58
|
]),
|
|
139
|
-
|
|
140
|
-
...(
|
|
59
|
+
]),
|
|
60
|
+
...(reach.areas.length === 0 ? [] : [fragment(`NOT ${grouped(outside).sql}`, outside.bind)]),
|
|
141
61
|
]);
|
|
142
62
|
}
|
|
143
63
|
function related(bound, plan) {
|
|
144
64
|
const parts = [];
|
|
145
65
|
if (plan.hop !== null) {
|
|
146
66
|
parts.push(exists(joined([
|
|
147
|
-
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
|
|
148
|
-
grouped(
|
|
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')])),
|
|
149
71
|
], ' ')));
|
|
150
72
|
}
|
|
151
73
|
if (plan.backlinks !== null) {
|
|
152
74
|
const field = plan.backlinks.field;
|
|
153
75
|
parts.push(exists(joined([
|
|
154
|
-
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'
|
|
155
|
-
grouped(
|
|
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`),
|
|
77
|
+
...(field === null ? [] : [grouped(sql.placed('l', field, 'link')), fragment('AND')]),
|
|
78
|
+
grouped(all([sql.scoped('s', plan.backlinks), reached(bound, 's')])),
|
|
156
79
|
], ' ')));
|
|
157
80
|
}
|
|
158
81
|
return parts;
|
|
@@ -160,11 +83,9 @@ function related(bound, plan) {
|
|
|
160
83
|
function filtered(bound, plan) {
|
|
161
84
|
const keys = bound.rooms.map(({ key }) => key);
|
|
162
85
|
return all([
|
|
163
|
-
fragment(`d.key IN ${
|
|
164
|
-
...(plan.paths === null ? [] : [fragment(`d.path IN ${list(plan.paths).sql}`, plan.paths)]),
|
|
165
|
-
...(plan.folder === null ? [] : [fragment('d.folder = ?', [plan.folder])]),
|
|
86
|
+
fragment(`d.key IN ${listed(keys).sql} AND ${VISIBLE('d')}`, keys),
|
|
166
87
|
reached(bound, 'd'),
|
|
167
|
-
|
|
88
|
+
sql.tests('d', plan),
|
|
168
89
|
...related(bound, plan),
|
|
169
90
|
]);
|
|
170
91
|
}
|
|
@@ -195,99 +116,25 @@ const GROUP_TIES = {
|
|
|
195
116
|
locale: undefined,
|
|
196
117
|
localeOptions: undefined,
|
|
197
118
|
};
|
|
198
|
-
function
|
|
199
|
-
if (value === null || value === undefined) {
|
|
200
|
-
return { placement: ordering.nulls === 'first' ? 0 : 2, klass: 0, scalar: null };
|
|
201
|
-
}
|
|
202
|
-
if (typeof value === 'boolean')
|
|
203
|
-
return { placement: 1, klass: 1, scalar: value ? 1 : 0 };
|
|
204
|
-
if (typeof value === 'number')
|
|
205
|
-
return { placement: 1, klass: 1, scalar: value };
|
|
206
|
-
if (typeof value === 'string')
|
|
207
|
-
return { placement: 1, klass: 2, scalar: value };
|
|
208
|
-
return { placement: 1, klass: 3, scalar: JSON.stringify(value) };
|
|
209
|
-
}
|
|
210
|
-
function placement(term) {
|
|
211
|
-
const nulls = term.ordering.nulls === 'first' ? 0 : 2;
|
|
212
|
-
return fragment(`CASE WHEN ${term.kind.sql} IS NULL OR ${term.kind.sql} = 'null' THEN ${nulls} ELSE 1 END`, [...term.kind.bind, ...term.kind.bind]);
|
|
213
|
-
}
|
|
214
|
-
function klass(term) {
|
|
215
|
-
return fragment(`CASE ${term.kind.sql} WHEN 'boolean' THEN 1 WHEN 'number' THEN 1 WHEN 'string' THEN 2 WHEN 'array' THEN 3 ELSE 4 END`, term.kind.bind);
|
|
216
|
-
}
|
|
217
|
-
function classed(term, which) {
|
|
218
|
-
const kinds = which === 1 ? "('boolean', 'number')" : which === 2 ? "('string')" : "('array')";
|
|
219
|
-
return fragment(`(CASE WHEN ${term.kind.sql} IN ${kinds} THEN ${term.value.sql} END)`, [
|
|
220
|
-
...term.kind.bind,
|
|
221
|
-
...term.value.bind,
|
|
222
|
-
]);
|
|
223
|
-
}
|
|
224
|
-
function collated(bound, term, which) {
|
|
225
|
-
if (which === 1)
|
|
226
|
-
return '';
|
|
227
|
-
const name = bound.collate(term.ordering, which === 3, term.total === true);
|
|
228
|
-
return name === null ? '' : ` COLLATE ${name}`;
|
|
229
|
-
}
|
|
230
|
-
function sorted(bound, term) {
|
|
231
|
-
const direction = term.ordering.direction === 'desc' ? 'DESC' : 'ASC';
|
|
232
|
-
return joined([
|
|
233
|
-
placement(term),
|
|
234
|
-
fragment(`${klass(term).sql} ${direction}`, klass(term).bind),
|
|
235
|
-
...[1, 2, 3].map((which) => {
|
|
236
|
-
const value = classed(term, which);
|
|
237
|
-
return fragment(`${value.sql}${collated(bound, term, which)} ${direction}`, value.bind);
|
|
238
|
-
}),
|
|
239
|
-
], ', ');
|
|
240
|
-
}
|
|
241
|
-
function beyond(bound, term, value) {
|
|
242
|
-
const held = classOf(value, term.ordering);
|
|
243
|
-
const place = placement(term);
|
|
244
|
-
if (held.placement !== 1) {
|
|
245
|
-
return {
|
|
246
|
-
beyond: fragment(`${place.sql} > ${held.placement}`, place.bind),
|
|
247
|
-
equal: fragment(`${place.sql} = ${held.placement}`, place.bind),
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
const after = term.ordering.direction === 'desc' ? '<' : '>';
|
|
251
|
-
const kind = klass(term);
|
|
252
|
-
const scalar = classed(term, held.klass);
|
|
253
|
-
const collation = collated(bound, term, held.klass);
|
|
254
|
-
return {
|
|
255
|
-
beyond: any([
|
|
256
|
-
fragment(`${place.sql} > 1`, place.bind),
|
|
257
|
-
all([
|
|
258
|
-
fragment(`${place.sql} = 1`, place.bind),
|
|
259
|
-
any([
|
|
260
|
-
fragment(`${kind.sql} ${after} ${held.klass}`, kind.bind),
|
|
261
|
-
all([
|
|
262
|
-
fragment(`${kind.sql} = ${held.klass}`, kind.bind),
|
|
263
|
-
fragment(`${scalar.sql} ${after} ?${collation}`, [...scalar.bind, held.scalar]),
|
|
264
|
-
]),
|
|
265
|
-
]),
|
|
266
|
-
]),
|
|
267
|
-
]),
|
|
268
|
-
equal: all([
|
|
269
|
-
fragment(`${place.sql} = 1 AND ${kind.sql} = ${held.klass}`, [...place.bind, ...kind.bind]),
|
|
270
|
-
fragment(`${scalar.sql} = ?${collation}`, [...scalar.bind, held.scalar]),
|
|
271
|
-
]),
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
function following(parts, tie) {
|
|
275
|
-
let condition = tie;
|
|
276
|
-
for (const part of [...parts].reverse()) {
|
|
277
|
-
condition = any([part.beyond, all([part.equal, condition])]);
|
|
278
|
-
}
|
|
279
|
-
return condition;
|
|
280
|
-
}
|
|
281
|
-
function keyTerm(bound, key, ordering, index) {
|
|
119
|
+
function keyTerm(key, ordering, index) {
|
|
282
120
|
if (key.of === 'field') {
|
|
283
121
|
const alias = `o${index}`;
|
|
284
122
|
return {
|
|
285
|
-
term: {
|
|
286
|
-
|
|
123
|
+
term: {
|
|
124
|
+
ordering,
|
|
125
|
+
kind: fragment(`${alias}.kind`),
|
|
126
|
+
value: fragment(`${alias}.value`),
|
|
127
|
+
instant: fragment(`${alias}.instant`),
|
|
128
|
+
},
|
|
129
|
+
join: joined([
|
|
130
|
+
fragment(`LEFT JOIN replica_values ${alias} ON ${alias}.doc = d.id AND `),
|
|
131
|
+
grouped(sql.placed(alias, key.field, 'exact')),
|
|
132
|
+
fragment(` AND ${alias}.item = -1 AND ${alias}.kind NOT IN ('object', 'undefined')`),
|
|
133
|
+
], ''),
|
|
287
134
|
};
|
|
288
135
|
}
|
|
289
136
|
const expression = key.of === 'room'
|
|
290
|
-
? located(
|
|
137
|
+
? located('d')
|
|
291
138
|
: key.of === 'path'
|
|
292
139
|
? fragment('d.path')
|
|
293
140
|
: key.of === 'type'
|
|
@@ -313,13 +160,20 @@ function decoded(kind, value) {
|
|
|
313
160
|
return JSON.parse(value);
|
|
314
161
|
return null;
|
|
315
162
|
}
|
|
163
|
+
function sortedValue(row, index) {
|
|
164
|
+
const kind = row[`k${index}`];
|
|
165
|
+
return sql.sortValue(kind, decoded(kind, row[`v${index}`]), row[`i${index}`]);
|
|
166
|
+
}
|
|
316
167
|
function decodedKey(key, row, index) {
|
|
317
168
|
if (key.of === 'field') {
|
|
318
169
|
const kind = row[`k${index}`];
|
|
319
|
-
return kind === null || kind === undefined ? undefined :
|
|
170
|
+
return kind === null || kind === undefined ? undefined : sortedValue(row, index);
|
|
320
171
|
}
|
|
321
172
|
return row[`v${index}`] ?? null;
|
|
322
173
|
}
|
|
174
|
+
function instantOf(term) {
|
|
175
|
+
return term.instant ?? fragment('NULL');
|
|
176
|
+
}
|
|
323
177
|
const registered = new WeakMap();
|
|
324
178
|
function hashed(text) {
|
|
325
179
|
let hash = 0x811c9dc5;
|
|
@@ -369,9 +223,6 @@ function collating(connection) {
|
|
|
369
223
|
return name;
|
|
370
224
|
};
|
|
371
225
|
}
|
|
372
|
-
function bodied(shape) {
|
|
373
|
-
return shape.sections !== null || shape.preamble || shape.markdown;
|
|
374
|
-
}
|
|
375
226
|
function masked(pointers) {
|
|
376
227
|
const root = { whole: false, members: new Map() };
|
|
377
228
|
for (const pointer of pointers) {
|
|
@@ -427,24 +278,26 @@ function documentOf(shape, room, row, linked) {
|
|
|
427
278
|
const path = row.path;
|
|
428
279
|
const type = row.type;
|
|
429
280
|
const fileId = row.file_id ?? null;
|
|
281
|
+
const revision = row.revision ?? null;
|
|
282
|
+
const content = row.content ?? null;
|
|
283
|
+
const unheld = Number(row.unheld) === 1 ? { textHeld: false } : {};
|
|
430
284
|
if (type === null) {
|
|
431
285
|
const binary = row.binary === null ? null : JSON.parse(row.binary);
|
|
432
|
-
const content = row.content ?? null;
|
|
433
286
|
return {
|
|
434
287
|
room,
|
|
435
288
|
path,
|
|
436
289
|
...(binary === null
|
|
437
290
|
? {}
|
|
438
291
|
: {
|
|
439
|
-
binaryFile: binaryRecord(path, binary,
|
|
292
|
+
binaryFile: binaryRecord(path, binary, revision ?? undefined),
|
|
440
293
|
}),
|
|
441
|
-
...(shape.markdown && content !== null
|
|
442
|
-
|
|
443
|
-
: {}),
|
|
294
|
+
...(shape.markdown && content !== null ? { markdown: content } : {}),
|
|
295
|
+
...unheld,
|
|
444
296
|
...(shape.fileId ? { fileId } : {}),
|
|
297
|
+
...(shape.revision ? { revision } : {}),
|
|
445
298
|
};
|
|
446
299
|
}
|
|
447
|
-
const read = bodied(shape) ? parse(
|
|
300
|
+
const read = bodied(shape) && content !== null ? parse(content, path) : null;
|
|
448
301
|
const body = read?.ok === true ? read.document : null;
|
|
449
302
|
const fields = JSON.parse(row.fields ?? '{}');
|
|
450
303
|
return {
|
|
@@ -462,7 +315,8 @@ function documentOf(shape, room, row, linked) {
|
|
|
462
315
|
? {}
|
|
463
316
|
: { sections: sectionsOf(body.sections, shape.sections) }),
|
|
464
317
|
...(shape.preamble && body !== null ? { preamble: body.preamble } : {}),
|
|
465
|
-
...(shape.markdown &&
|
|
318
|
+
...(shape.markdown && content !== null ? { markdown: content } : {}),
|
|
319
|
+
...unheld,
|
|
466
320
|
...(shape.backlinks ? { backlinks: linked.get(documentKey(room, path)) ?? [] } : {}),
|
|
467
321
|
...(shape.change
|
|
468
322
|
? {
|
|
@@ -470,6 +324,7 @@ function documentOf(shape, room, row, linked) {
|
|
|
470
324
|
}
|
|
471
325
|
: {}),
|
|
472
326
|
...(shape.fileId ? { fileId } : {}),
|
|
327
|
+
...(shape.revision ? { revision } : {}),
|
|
473
328
|
};
|
|
474
329
|
}
|
|
475
330
|
function backlinksOf(connection, bound, rows) {
|
|
@@ -495,10 +350,10 @@ function backlinksOf(connection, bound, rows) {
|
|
|
495
350
|
return linked;
|
|
496
351
|
}
|
|
497
352
|
function documents(connection, bound, plan, shape, budget) {
|
|
498
|
-
const terms = shape.orderBy.map(({ key, options }, index) => keyTerm(
|
|
353
|
+
const terms = shape.orderBy.map(({ key, options }, index) => keyTerm(key, orderingOf(options), index));
|
|
499
354
|
const filter = filtered(bound, plan);
|
|
500
355
|
const cursor = plan.after?.values ?? null;
|
|
501
|
-
const room = located(
|
|
356
|
+
const room = located('d');
|
|
502
357
|
const tie = cursor === null
|
|
503
358
|
? null
|
|
504
359
|
: (() => {
|
|
@@ -514,19 +369,20 @@ function documents(connection, bound, plan, shape, budget) {
|
|
|
514
369
|
})();
|
|
515
370
|
const after = cursor === null || tie === null
|
|
516
371
|
? null
|
|
517
|
-
: following(terms.map(({ term }, index) => beyond(bound, term, cursor[index])), tie);
|
|
372
|
+
: sql.following(terms.map(({ term }, index) => sql.beyond(bound.collate, term, cursor[index])), tie);
|
|
518
373
|
const selected = joined([
|
|
519
|
-
fragment('SELECT d.id, d.key, d.path, d.type, d.binary, d.revision, d.fields, d.change, d.file_id'),
|
|
374
|
+
fragment('SELECT d.id, d.key, d.path, d.type, d.binary, d.revision, d.fields, d.change, d.file_id, d.content IS NULL AND d.outline IS NOT NULL AS unheld'),
|
|
520
375
|
...terms.map(({ term }, index) => joined([
|
|
521
376
|
fragment(`, ${term.kind.sql} AS k${index}`, term.kind.bind),
|
|
522
377
|
fragment(`, ${term.value.sql} AS v${index}`, term.value.bind),
|
|
378
|
+
fragment(`, ${instantOf(term).sql} AS i${index}`, instantOf(term).bind),
|
|
523
379
|
], '')),
|
|
524
380
|
fragment(' FROM replica_entries d'),
|
|
525
381
|
...terms.flatMap(({ join }) => (join === null ? [] : [fragment(' '), join])),
|
|
526
382
|
fragment(' WHERE '),
|
|
527
383
|
after === null ? filter : all([filter, after]),
|
|
528
384
|
fragment(' ORDER BY '),
|
|
529
|
-
joined([...terms.map(({ term }) => sorted(bound, term)), room, fragment('d.path')], ', '),
|
|
385
|
+
joined([...terms.map(({ term }) => sql.sorted(bound.collate, term)), room, fragment('d.path')], ', '),
|
|
530
386
|
...(plan.limit === null ? [] : [fragment(' LIMIT ?', [plan.limit + 1])]),
|
|
531
387
|
], '');
|
|
532
388
|
const rows = connection.rows(selected.sql, selected.bind);
|
|
@@ -565,7 +421,7 @@ function withContent(connection, rows, budget) {
|
|
|
565
421
|
return rows;
|
|
566
422
|
const ids = rows.map((row) => row.id);
|
|
567
423
|
const sizes = new Map(connection
|
|
568
|
-
.rows(`SELECT id, octet_length(content) AS size FROM replica_entries WHERE id IN ${
|
|
424
|
+
.rows(`SELECT id, octet_length(content) AS size FROM replica_entries WHERE id IN ${listed(ids).sql}`, ids)
|
|
569
425
|
.map((row) => [row.id, Number(row.size ?? 0)]));
|
|
570
426
|
let cut = rows.length;
|
|
571
427
|
let spent = 0;
|
|
@@ -580,20 +436,30 @@ function withContent(connection, rows, budget) {
|
|
|
580
436
|
const kept = rows.slice(0, cut);
|
|
581
437
|
const read = kept.map((row) => row.id);
|
|
582
438
|
const held = new Map(connection
|
|
583
|
-
.rows(`SELECT id, content FROM replica_entries WHERE id IN ${
|
|
439
|
+
.rows(`SELECT id, content FROM replica_entries WHERE id IN ${listed(read).sql}`, read)
|
|
584
440
|
.map((row) => [row.id, row.content]));
|
|
585
441
|
return kept.map((row) => ({ ...row, content: held.get(row.id) ?? null }));
|
|
586
442
|
}
|
|
587
443
|
function storedFolders(bound, plan) {
|
|
588
|
-
if (plan.paths !== null || plan.
|
|
444
|
+
if (plan.paths !== null || plan.fileIds !== null)
|
|
445
|
+
return null;
|
|
446
|
+
if (plan.hop !== null || plan.backlinks !== null)
|
|
589
447
|
return null;
|
|
590
448
|
const whole = bound.rooms.filter(({ locator }) => bound.reach === null || bound.reach.rooms.includes(locator));
|
|
591
449
|
if (whole.length === 0)
|
|
592
450
|
return null;
|
|
593
451
|
const keys = whole.map(({ key }) => key);
|
|
594
452
|
const prefix = plan.root.pathPrefix;
|
|
453
|
+
const outside = (bound.reach?.areas ?? []).flatMap((area) => {
|
|
454
|
+
const key = bound.keys.get(area.room);
|
|
455
|
+
if (key === undefined)
|
|
456
|
+
return [];
|
|
457
|
+
const fence = fenced('f', key, area, true);
|
|
458
|
+
return [fragment(`NOT ${grouped(fence).sql}`, fence.bind)];
|
|
459
|
+
});
|
|
595
460
|
return all([
|
|
596
|
-
fragment(`f.key IN ${
|
|
461
|
+
fragment(`f.key IN ${listed(keys).sql} AND f.layer = 0 AND f.present = 1`, keys),
|
|
462
|
+
...outside,
|
|
597
463
|
...(prefix === null || prefix === ''
|
|
598
464
|
? []
|
|
599
465
|
: [
|
|
@@ -608,7 +474,7 @@ function storedFolders(bound, plan) {
|
|
|
608
474
|
}
|
|
609
475
|
function groups(connection, bound, plan, shape) {
|
|
610
476
|
const keyed = shape.groupBy.map((key, index) => {
|
|
611
|
-
const { term, join } = keyTerm(
|
|
477
|
+
const { term, join } = keyTerm(key, GROUP_ORDER, index);
|
|
612
478
|
const kind = fragment(`COALESCE(${term.kind.sql}, 'null')`, term.kind.bind);
|
|
613
479
|
return { term: { ...term, kind }, join };
|
|
614
480
|
});
|
|
@@ -618,6 +484,7 @@ function groups(connection, bound, plan, shape) {
|
|
|
618
484
|
joined(keyed.map(({ term }, index) => joined([
|
|
619
485
|
fragment(`${term.kind.sql} AS k${index}`, term.kind.bind),
|
|
620
486
|
fragment(`, ${term.value.sql} AS v${index}`, term.value.bind),
|
|
487
|
+
fragment(`, ${instantOf(term).sql} AS i${index}`, instantOf(term).bind),
|
|
621
488
|
], '')), ', '),
|
|
622
489
|
fragment(', 1 AS n FROM replica_entries d'),
|
|
623
490
|
...keyed.flatMap(({ join }) => (join === null ? [] : [fragment(' '), join])),
|
|
@@ -631,10 +498,15 @@ function groups(connection, bound, plan, shape) {
|
|
|
631
498
|
? inner
|
|
632
499
|
: joined([
|
|
633
500
|
inner,
|
|
634
|
-
fragment(" UNION ALL SELECT 'string' AS k0, f.path AS v0, 0 AS n FROM replica_folders f WHERE "),
|
|
501
|
+
fragment(" UNION ALL SELECT 'string' AS k0, f.path AS v0, NULL AS i0, 0 AS n FROM replica_folders f WHERE "),
|
|
635
502
|
folders,
|
|
636
503
|
], '');
|
|
637
|
-
const columns = keyed
|
|
504
|
+
const columns = keyed
|
|
505
|
+
.map((_, index) => `k${index}, min(v${index}) AS v${index}, i${index}`)
|
|
506
|
+
.join(', ');
|
|
507
|
+
const held = keyed
|
|
508
|
+
.map((_, index) => `k${index}, i${index}, CASE WHEN i${index} IS NULL THEN v${index} END`)
|
|
509
|
+
.join(', ');
|
|
638
510
|
const counted = {
|
|
639
511
|
ordering: { ...GROUP_ORDER },
|
|
640
512
|
kind: fragment("'number'"),
|
|
@@ -647,7 +519,7 @@ function groups(connection, bound, plan, shape) {
|
|
|
647
519
|
});
|
|
648
520
|
const ordered = shape.orderBy.map(({ by, direction }) => by === 'count'
|
|
649
521
|
? { ...counted, ordering: { ...GROUP_ORDER, direction } }
|
|
650
|
-
: outer(by, { ...GROUP_ORDER, direction }));
|
|
522
|
+
: { ...outer(by, { ...GROUP_ORDER, direction }), instant: fragment(`i${by}`) });
|
|
651
523
|
const ties = keyed.flatMap((_, index) => [
|
|
652
524
|
{ ...outer(index, GROUP_TIES), total: true },
|
|
653
525
|
{ ordering: GROUP_TIES, kind: fragment("'string'"), value: fragment(`k${index}`) },
|
|
@@ -657,19 +529,21 @@ function groups(connection, bound, plan, shape) {
|
|
|
657
529
|
? null
|
|
658
530
|
: cursor[shape.orderBy.length].flatMap((value) => [
|
|
659
531
|
value,
|
|
660
|
-
|
|
532
|
+
heldKind(value ?? null),
|
|
661
533
|
]);
|
|
662
534
|
const after = cursor === null || tieValues === null
|
|
663
535
|
? null
|
|
664
|
-
: following(ordered.map((term, index) => beyond(bound, term, cursor[index])), following(ties
|
|
665
|
-
|
|
536
|
+
: sql.following(ordered.map((term, index) => sql.beyond(bound.collate, term, cursor[index])), sql.following(ties
|
|
537
|
+
.slice(0, -1)
|
|
538
|
+
.map((term, index) => sql.beyond(bound.collate, term, tieValues[index])), sql.beyond(bound.collate, ties.at(-1), tieValues.at(-1)).beyond));
|
|
539
|
+
const grouping = joined([fragment(`SELECT ${columns}, sum(n) AS n FROM (`), source, fragment(`) GROUP BY ${held}`)], '');
|
|
666
540
|
const windowed = joined([
|
|
667
541
|
fragment('SELECT * FROM ('),
|
|
668
542
|
grouping,
|
|
669
543
|
fragment(')'),
|
|
670
544
|
...(after === null ? [] : [fragment(' WHERE '), after]),
|
|
671
545
|
fragment(' ORDER BY '),
|
|
672
|
-
joined([...ordered, ...ties].map((term) => sorted(bound, term)), ', '),
|
|
546
|
+
joined([...ordered, ...ties].map((term) => sql.sorted(bound.collate, term)), ', '),
|
|
673
547
|
...(plan.limit === null ? [] : [fragment(' LIMIT ?', [plan.limit + 1])]),
|
|
674
548
|
], '');
|
|
675
549
|
const rows = connection.rows(windowed.sql, windowed.bind);
|
|
@@ -682,7 +556,7 @@ function groups(connection, bound, plan, shape) {
|
|
|
682
556
|
: last === undefined
|
|
683
557
|
? (plan.after?.text ?? FROM_START)
|
|
684
558
|
: cursorOf([
|
|
685
|
-
...shape.orderBy.map(({ by }) => by === 'count' ? Number(last.n) :
|
|
559
|
+
...shape.orderBy.map(({ by }) => by === 'count' ? Number(last.n) : sortedValue(last, by)),
|
|
686
560
|
keyOf(last),
|
|
687
561
|
]);
|
|
688
562
|
const total = plan.total
|
|
@@ -702,9 +576,6 @@ function boundOf(connection, plan, rooms) {
|
|
|
702
576
|
collate: collating(connection),
|
|
703
577
|
};
|
|
704
578
|
}
|
|
705
|
-
export function selected(connection, plan, rooms) {
|
|
706
|
-
return filtered(boundOf(connection, plan, rooms), plan);
|
|
707
|
-
}
|
|
708
579
|
export function answerQuery(connection, plan, rooms, budget = null) {
|
|
709
580
|
const bound = boundOf(connection, plan, rooms);
|
|
710
581
|
if (rooms.length === 0) {
|
package/dist/connection.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
+
import { type DocumentQuery, type GroupQuery } from '@agentshouse/mdmodel';
|
|
1
2
|
import { type TypesResult } from './model.js';
|
|
2
3
|
import { type Observation } from './observation.js';
|
|
3
|
-
import { type
|
|
4
|
+
import { type DocumentResult, type GroupResult, type PendingResult } from './query.js';
|
|
4
5
|
import { type EntrySeed } from './seed.js';
|
|
5
6
|
import { type SearchRequest, type SearchResult } from './search.js';
|
|
6
7
|
import { type Adapter, type Authorization, type Member, type ProviderRefusal, type ServiceMode } from './adapter.js';
|
|
7
8
|
import { type ChatDraftSurface, type ConversationAgent, type ConversationEntry, type ConversationOptions, type ConversationSurface, type ConversationView } from './conversation.js';
|
|
8
9
|
import { type WrittenBy } from './change.js';
|
|
9
10
|
import type { Open } from './open.js';
|
|
10
|
-
import { type
|
|
11
|
-
import { type BinaryLinkAnswer, type CallResult, type HeldBinaryAnswer, type HistoryAnswer, type QueueEntry, type Resolution } from './outcome.js';
|
|
11
|
+
import { type AttachAnswer, type BinaryLinkAnswer, type CallResult, type HeldBinaryAnswer, type HeldShownAnswer, type HistoryAnswer, type QueueEntry, type Resolution } from './outcome.js';
|
|
12
12
|
import { type Recovery } from './recovery.js';
|
|
13
13
|
import { type SaveRefusal } from './save.js';
|
|
14
14
|
import { type RoomDraft, type RoomDraftParts, type RoomDraftWrite } from './room-draft.js';
|
|
15
15
|
import { type SyncStatus } from './status.js';
|
|
16
16
|
import { type RuntimeShell } from './durability.js';
|
|
17
|
-
import { type
|
|
17
|
+
import { type CodeAvailability, type Persistence, type Readiness } from './readiness.js';
|
|
18
18
|
import type { RuntimeDatabase } from './tables.js';
|
|
19
19
|
import { type NarrowedView, type PortReach, type RuntimeView } from './reach.js';
|
|
20
20
|
export type AppTypedSelection = {
|
|
@@ -55,6 +55,7 @@ export type MdRuntimeOptions = {
|
|
|
55
55
|
authorization?: Authorization;
|
|
56
56
|
signal?: AbortSignal;
|
|
57
57
|
recovery?: Recovery;
|
|
58
|
+
usableWhenHeld?: readonly string[];
|
|
58
59
|
};
|
|
59
60
|
export type SaveResult = {
|
|
60
61
|
outcome: 'saved';
|
|
@@ -73,7 +74,7 @@ export type SavedParts = {
|
|
|
73
74
|
export type RoomDraftSurface = {
|
|
74
75
|
list(): Promise<readonly RoomDraft[]>;
|
|
75
76
|
read(room: string, path: string): Promise<RoomDraft | null>;
|
|
76
|
-
write(room: string, path: string, revision: string | null, parts: unknown): Promise<RoomDraftWrite>;
|
|
77
|
+
write(room: string, path: string, revision: string | null, parts: unknown, next?: string): Promise<RoomDraftWrite>;
|
|
77
78
|
discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;
|
|
78
79
|
};
|
|
79
80
|
export type PresentationSurface = {
|
|
@@ -84,7 +85,8 @@ export type PresentationSurface = {
|
|
|
84
85
|
export type BinaryFileSurface = {
|
|
85
86
|
read(room: string, path: string, revision?: string): Promise<HeldBinaryAnswer>;
|
|
86
87
|
link(room: string, path: string, revision?: string): Promise<BinaryLinkAnswer>;
|
|
87
|
-
|
|
88
|
+
show(room: string, path: string, revision?: string): Promise<HeldShownAnswer>;
|
|
89
|
+
attach(room: string, file: File): Promise<AttachAnswer>;
|
|
88
90
|
part(file: string, part: number): Promise<Uint8Array | null>;
|
|
89
91
|
};
|
|
90
92
|
export type HistoryQuery = {
|
|
@@ -93,7 +95,7 @@ export type HistoryQuery = {
|
|
|
93
95
|
};
|
|
94
96
|
export type MdRuntime = {
|
|
95
97
|
loaded(): Promise<void>;
|
|
96
|
-
rooms(): readonly AppRoom[]
|
|
98
|
+
rooms(): Promise<readonly AppRoom[]>;
|
|
97
99
|
query: {
|
|
98
100
|
(query: DocumentQuery): Promise<DocumentResult | PendingResult>;
|
|
99
101
|
(query: GroupQuery): Promise<GroupResult | PendingResult>;
|
|
@@ -123,6 +125,7 @@ export type MdRuntime = {
|
|
|
123
125
|
(topic: 'sync-status'): Promise<Observation<SyncStatus>>;
|
|
124
126
|
(topic: 'service-mode'): Promise<Observation<ServiceMode>>;
|
|
125
127
|
(topic: 'member'): Promise<Observation<Member | null>>;
|
|
128
|
+
(topic: 'authority-changes'): Promise<Observation<number>>;
|
|
126
129
|
(topic: 'query', query: DocumentQuery): Promise<Observation<DocumentResult | PendingResult>>;
|
|
127
130
|
(topic: 'query', query: GroupQuery): Promise<Observation<GroupResult | PendingResult>>;
|
|
128
131
|
(topic: 'queue', locator: string): Promise<Observation<readonly QueueEntry[]>>;
|
|
@@ -134,17 +137,14 @@ export type MdRuntime = {
|
|
|
134
137
|
};
|
|
135
138
|
reauthorize(): Promise<void>;
|
|
136
139
|
};
|
|
137
|
-
export type RuntimeTopic = 'rooms' | 'readiness' | 'connection-refusal' | 'storage-loss' | 'sync-status' | 'service-mode' | 'member' | 'query' | 'queue' | 'room-drafts' | 'presentation' | 'conversation' | 'conversations' | 'agents';
|
|
140
|
+
export type RuntimeTopic = 'rooms' | 'readiness' | 'connection-refusal' | 'storage-loss' | 'sync-status' | 'service-mode' | 'member' | 'authority-changes' | 'query' | 'queue' | 'room-drafts' | 'presentation' | 'conversation' | 'conversations' | 'agents';
|
|
138
141
|
export type ReadinessPort = {
|
|
139
142
|
readonly target: string;
|
|
140
143
|
readonly code: CodeAvailability;
|
|
141
|
-
readonly capacity: CapacityCause | null;
|
|
142
|
-
readonly search: SearchObligation;
|
|
143
144
|
};
|
|
144
145
|
export type ComposedRuntime = RuntimeView & {
|
|
145
146
|
seed(entry: EntrySeed): void;
|
|
146
147
|
stop(): Promise<void>;
|
|
147
|
-
lose(locators: readonly string[]): Promise<void>;
|
|
148
148
|
persisted(answer: Persistence): void;
|
|
149
149
|
within(reach: PortReach | null, port: ReadinessPort): NarrowedView;
|
|
150
150
|
};
|