@agentshouse/mdruntime 0.1.0-ce131cb435f8b → 0.1.0-ce41fec66d91b
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 +18 -15
- package/dist/adapter.d.ts +110 -72
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +5 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +38 -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 +25 -10
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +180 -103
- package/dist/chain.d.ts +11 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +9 -16
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -89
- package/dist/change.d.ts +31 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +10 -1
- package/dist/client.d.ts +11 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +80 -7
- package/dist/collection.d.ts +10 -22
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +39 -356
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +786 -0
- package/dist/connection.d.ts +17 -11
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +2779 -1329
- package/dist/conversation.d.ts +19 -11
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +298 -166
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/durability.d.ts +2 -5
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +4 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +18 -24
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- package/dist/fulltext.d.ts +27 -0
- package/dist/fulltext.d.ts.map +1 -0
- package/dist/fulltext.js +370 -0
- package/dist/host.d.ts +3 -5
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +48 -21
- package/dist/identity.d.ts +0 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -3
- package/dist/index.d.ts +14 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/live.d.ts +22 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +123 -0
- 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 +10 -6
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +195 -102
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +90 -0
- package/dist/model.d.ts +6 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -10
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +13 -0
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +84 -0
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/outcome.d.ts +40 -8
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +38 -2
- package/dist/overlay.d.ts +2 -6
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +87 -176
- 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 +11 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +13 -1
- package/dist/reach.d.ts +13 -4
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +200 -78
- package/dist/readiness.d.ts +14 -15
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +2 -8
- package/dist/recovery.d.ts +3 -2
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +34 -7
- package/dist/refresh.d.ts +18 -15
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +136 -58
- package/dist/replica.d.ts +55 -38
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +278 -198
- package/dist/room-draft.d.ts +21 -3
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +102 -28
- package/dist/rows.d.ts +38 -31
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +173 -101
- package/dist/save.d.ts +52 -15
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +504 -182
- package/dist/search.d.ts +11 -43
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +0 -213
- package/dist/shared.d.ts +4 -3
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +62 -35
- 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 +81 -101
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +300 -693
- package/dist/stored.d.ts +130 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +560 -0
- package/dist/tables.d.ts +325 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +578 -0
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/turn.d.ts +2 -2
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +34 -23
- package/dist/validation.d.ts +29 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +101 -0
- package/dist/windows.d.ts +2 -6
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +30 -34
- package/dist/wire.d.ts +17 -5
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +5 -2
- package/dist/words.d.ts +19 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +156 -0
- package/package.json +18 -19
- package/AGENTS.md +0 -299
- 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/context.js +0 -10
- 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/input.d.ts +0 -9
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -99
- 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 -27
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -99
- package/dist/chat/markdown.d.ts +0 -20
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -188
- package/dist/chat/message.d.ts +0 -6
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -192
- package/dist/chat/messages.d.ts +0 -22
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -155
- package/dist/chat/name.d.ts +0 -6
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -11
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -17
- package/dist/chat/overlay.d.ts +0 -31
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -97
- package/dist/chat/parts.d.ts +0 -57
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/parts.js +0 -119
- 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 -63
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -628
- 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 -34
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -91
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -302
- package/dist/chat.d.ts +0 -14
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -8
- package/dist/read-side.d.ts +0 -27
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -824
- package/dist/reads.d.ts +0 -11
- package/dist/reads.d.ts.map +0 -1
- package/dist/reads.js +0 -98
package/dist/collection.js
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parse, VERSION } from '@agentshouse/mdmodel';
|
|
2
2
|
import { beneath, normalize } from './paths.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { after, finished, inUnits, ROW_WEIGHT } from './turn.js';
|
|
3
|
+
import { hashed } from './observation.js';
|
|
4
|
+
import { sortedKeys } from './shared.js';
|
|
6
5
|
export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
|
|
7
|
-
const
|
|
8
|
-
function
|
|
6
|
+
const typesPrinted = new WeakMap();
|
|
7
|
+
function typesPrint(model) {
|
|
8
|
+
if (model.status === 'unavailable')
|
|
9
|
+
return '';
|
|
10
|
+
let print = typesPrinted.get(model.types);
|
|
11
|
+
if (print === undefined) {
|
|
12
|
+
print = hashed(JSON.stringify(model.types)).toString(36);
|
|
13
|
+
typesPrinted.set(model.types, print);
|
|
14
|
+
}
|
|
15
|
+
return print;
|
|
16
|
+
}
|
|
17
|
+
export function composedOf(composition) {
|
|
18
|
+
const { model, selection } = composition;
|
|
19
|
+
return {
|
|
20
|
+
composition,
|
|
21
|
+
fingerprint: JSON.stringify([
|
|
22
|
+
typesPrint(model),
|
|
23
|
+
selection === null ? null : [selection.roots, typesPrint(selection.model)],
|
|
24
|
+
]),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function selected(composition, path) {
|
|
9
28
|
return (composition.selection !== null &&
|
|
10
29
|
composition.selection.roots.some((root) => beneath(root, path)));
|
|
11
30
|
}
|
|
@@ -14,372 +33,36 @@ export function governing(composition, path) {
|
|
|
14
33
|
? composition.selection.model
|
|
15
34
|
: composition.model;
|
|
16
35
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (held === undefined)
|
|
21
|
-
return shared({});
|
|
22
|
-
const kept = yield* patching(held.base, held.added);
|
|
23
|
-
held.base = kept;
|
|
24
|
-
held.added = new Map();
|
|
25
|
-
return yield* patching(kept, [], yield* differences(previous.text, text));
|
|
26
|
-
}
|
|
27
|
-
function cachedIn(collection, path) {
|
|
28
|
-
const held = parsedIn.get(collection);
|
|
29
|
-
if (held === undefined)
|
|
30
|
-
return undefined;
|
|
31
|
-
if (held.added.has(path))
|
|
32
|
-
return held.added.get(path);
|
|
33
|
-
return Object.hasOwn(held.base, path) ? held.base[path] : undefined;
|
|
34
|
-
}
|
|
35
|
-
export function collectionOf(text, composition, previous) {
|
|
36
|
-
return finished(collecting(text, composition, previous));
|
|
37
|
-
}
|
|
38
|
-
export function* collecting(text, composition, previous) {
|
|
39
|
-
const parsed = {
|
|
40
|
-
base: previous === undefined ? shared({}) : yield* carried(previous, text),
|
|
41
|
-
added: new Map(),
|
|
42
|
-
};
|
|
43
|
-
const collection = {
|
|
36
|
+
export function collectionOf(text, composition) {
|
|
37
|
+
const parsed = new Map();
|
|
38
|
+
return {
|
|
44
39
|
text,
|
|
45
40
|
composition,
|
|
46
41
|
document(path) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return held ?? undefined;
|
|
42
|
+
if (parsed.has(path))
|
|
43
|
+
return parsed.get(path) ?? undefined;
|
|
50
44
|
const content = text[path];
|
|
51
45
|
if (content === undefined)
|
|
52
46
|
return undefined;
|
|
53
47
|
const read = parse(content, path);
|
|
54
|
-
parsed.
|
|
48
|
+
parsed.set(path, read.ok ? read.document : null);
|
|
55
49
|
return read.ok ? read.document : undefined;
|
|
56
50
|
},
|
|
57
51
|
};
|
|
58
|
-
parsedIn.set(collection, parsed);
|
|
59
|
-
return collection;
|
|
60
|
-
}
|
|
61
|
-
export function passingFrontmatter(collection, path) {
|
|
62
|
-
const held = cachedIn(collection, path);
|
|
63
|
-
if (held !== undefined)
|
|
64
|
-
return held ?? undefined;
|
|
65
|
-
const content = collection.text[path];
|
|
66
|
-
if (content === undefined)
|
|
67
|
-
return undefined;
|
|
68
|
-
const read = parseFrontmatter(content, path);
|
|
69
|
-
return read.ok ? read.frontmatter : undefined;
|
|
70
52
|
}
|
|
71
53
|
export function* documentsOf(collection) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
continue;
|
|
54
|
+
const paths = yield* sortedKeys(collection.text);
|
|
55
|
+
return (function* () {
|
|
56
|
+
for (const path of paths) {
|
|
57
|
+
const document = collection.document(path);
|
|
58
|
+
if (document !== undefined)
|
|
59
|
+
yield [path, document];
|
|
79
60
|
}
|
|
80
|
-
|
|
81
|
-
if (read.ok)
|
|
82
|
-
yield [path, read.document];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
export function* unreadable(text, previous) {
|
|
86
|
-
const paths = previous === undefined
|
|
87
|
-
? Object.keys(text)
|
|
88
|
-
: [...(yield* differences(previous, text))].filter((path) => text[path] !== undefined);
|
|
89
|
-
for (const path of paths.sort()) {
|
|
90
|
-
const read = parse(text[path], path);
|
|
91
|
-
if (!read.ok)
|
|
92
|
-
return { kind: 'refused', refusal: read.refusal };
|
|
93
|
-
yield ROW_WEIGHT + text[path].length;
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
61
|
+
})();
|
|
96
62
|
}
|
|
97
63
|
export function validRoot(root) {
|
|
98
64
|
return typeof root === 'string' && normalize(root) === root;
|
|
99
65
|
}
|
|
100
|
-
function* validateAgainst(documents, binaryTargets, model) {
|
|
101
|
-
if (model.status === 'unavailable') {
|
|
102
|
-
for (const path of Object.keys(documents)) {
|
|
103
|
-
const content = documents[path];
|
|
104
|
-
const parsed = parse(content);
|
|
105
|
-
if (parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any')
|
|
106
|
-
return { verdict: 'refuse', rule: 'model-unavailable', file: path };
|
|
107
|
-
yield ROW_WEIGHT + content.length;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const steps = validating(documents, { binaryTargets }, model.status === 'unavailable' ? NO_TYPES : { types: model.types });
|
|
111
|
-
for (let step = steps.next();; step = steps.next()) {
|
|
112
|
-
if (step.done === true)
|
|
113
|
-
return step.value;
|
|
114
|
-
yield ROW_WEIGHT + documents[step.value].length;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
export function* validateCollection(text, binaryTargets, composition) {
|
|
118
|
-
const collection = {};
|
|
119
|
-
const selection = {};
|
|
120
|
-
for (const path of Object.keys(text)) {
|
|
121
|
-
if (selected(composition, path))
|
|
122
|
-
selection[path] = text[path];
|
|
123
|
-
else
|
|
124
|
-
collection[path] = text[path];
|
|
125
|
-
yield ROW_WEIGHT;
|
|
126
|
-
}
|
|
127
|
-
const verdicts = [
|
|
128
|
-
yield* validateAgainst(collection, binaryTargets.filter((path) => !selected(composition, path)), composition.model),
|
|
129
|
-
];
|
|
130
|
-
if (composition.selection !== null) {
|
|
131
|
-
verdicts.push(yield* validateAgainst(selection, binaryTargets.filter((path) => selected(composition, path)), composition.selection.model));
|
|
132
|
-
}
|
|
133
|
-
const refusals = verdicts.filter((verdict) => verdict.verdict === 'refuse');
|
|
134
|
-
if (refusals.length === 0)
|
|
135
|
-
return verdicts[0];
|
|
136
|
-
return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
|
|
137
|
-
}
|
|
138
|
-
const NO_REFERRERS = shared({});
|
|
139
|
-
const referrersOf = new WeakMap();
|
|
140
|
-
function typing(left, right) {
|
|
141
|
-
return (sameTyping(left.model, right.model) &&
|
|
142
|
-
(left.selection === null || right.selection === null
|
|
143
|
-
? left.selection === right.selection
|
|
144
|
-
: sameTyping(left.selection.model, right.selection.model)) &&
|
|
145
|
-
JSON.stringify(left.selection?.roots ?? null) === JSON.stringify(right.selection?.roots ?? null));
|
|
146
|
-
}
|
|
147
|
-
function declared(content) {
|
|
148
|
-
if (content === undefined)
|
|
149
|
-
return undefined;
|
|
150
|
-
const read = parseFrontmatter(content);
|
|
151
|
-
return read.ok ? (read.frontmatter.type ?? 'any') : undefined;
|
|
152
|
-
}
|
|
153
|
-
function typedIn(content) {
|
|
154
|
-
const type = declared(content);
|
|
155
|
-
return type !== undefined && type !== 'any';
|
|
156
|
-
}
|
|
157
|
-
function modelOf(composition, path) {
|
|
158
|
-
const model = governing(composition, path);
|
|
159
|
-
return model.status === 'unavailable' ? null : { types: model.types };
|
|
160
|
-
}
|
|
161
|
-
function checked(path, content, composition) {
|
|
162
|
-
return checkDocument(path, content, modelOf(composition, path) ?? NO_TYPES);
|
|
163
|
-
}
|
|
164
|
-
function targetsOf(check) {
|
|
165
|
-
if (!check.ok)
|
|
166
|
-
return [];
|
|
167
|
-
return [...new Set(check.references.flatMap(({ target }) => (target === null ? [] : [target])))];
|
|
168
|
-
}
|
|
169
|
-
function referencedBy(path, content, composition) {
|
|
170
|
-
const model = modelOf(composition, path);
|
|
171
|
-
if (model === null)
|
|
172
|
-
return [];
|
|
173
|
-
const read = parseFrontmatter(content, path);
|
|
174
|
-
const type = read.ok ? read.frontmatter.type : undefined;
|
|
175
|
-
if (!read.ok || type === undefined || !Object.hasOwn(model.types, type))
|
|
176
|
-
return [];
|
|
177
|
-
const definition = model.types[type];
|
|
178
|
-
return [
|
|
179
|
-
...new Set([
|
|
180
|
-
...references(read.frontmatter, definition).flatMap(({ value }) => {
|
|
181
|
-
const found = target(path, value);
|
|
182
|
-
return found === null ? [] : [found];
|
|
183
|
-
}),
|
|
184
|
-
...sectionReferences(path, content, definition).flatMap(({ target }) => target === null ? [] : [target]),
|
|
185
|
-
]),
|
|
186
|
-
];
|
|
187
|
-
}
|
|
188
|
-
function referrersOfTarget(index, target) {
|
|
189
|
-
return Object.hasOwn(index.referrers, target) ? index.referrers[target] : NO_REFERRERS;
|
|
190
|
-
}
|
|
191
|
-
function* reindexed(index, changed) {
|
|
192
|
-
const moved = new Map();
|
|
193
|
-
const movesOf = (target) => {
|
|
194
|
-
const held = moved.get(target) ?? { gained: [], lost: [] };
|
|
195
|
-
moved.set(target, held);
|
|
196
|
-
return held;
|
|
197
|
-
};
|
|
198
|
-
const targeting = [];
|
|
199
|
-
const targetless = [];
|
|
200
|
-
for (const [path, found] of changed) {
|
|
201
|
-
const before = Object.hasOwn(index.targets, path) ? index.targets[path] : [];
|
|
202
|
-
for (const target of before)
|
|
203
|
-
if (!found.includes(target))
|
|
204
|
-
movesOf(target).lost.push(path);
|
|
205
|
-
for (const target of found) {
|
|
206
|
-
if (!before.includes(target))
|
|
207
|
-
movesOf(target).gained.push([path, true]);
|
|
208
|
-
}
|
|
209
|
-
if (found.length > 0)
|
|
210
|
-
targeting.push([path, found]);
|
|
211
|
-
else
|
|
212
|
-
targetless.push(path);
|
|
213
|
-
yield ROW_WEIGHT * (1 + before.length + found.length);
|
|
214
|
-
}
|
|
215
|
-
const referred = [];
|
|
216
|
-
const unreferred = [];
|
|
217
|
-
for (const [target, { gained, lost }] of moved) {
|
|
218
|
-
const files = yield* patching(referrersOfTarget(index, target), gained, lost);
|
|
219
|
-
if (sizeOf(files) > 0)
|
|
220
|
-
referred.push([target, files]);
|
|
221
|
-
else
|
|
222
|
-
unreferred.push(target);
|
|
223
|
-
}
|
|
224
|
-
return {
|
|
225
|
-
composition: index.composition,
|
|
226
|
-
targets: yield* patching(index.targets, targeting, targetless),
|
|
227
|
-
referrers: yield* patching(index.referrers, referred, unreferred),
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
function storedIn(entries) {
|
|
231
|
-
let stored = shared({});
|
|
232
|
-
let unit = [];
|
|
233
|
-
return after(inUnits(entries, (entry) => {
|
|
234
|
-
unit.push(entry);
|
|
235
|
-
return ROW_WEIGHT;
|
|
236
|
-
}, () => {
|
|
237
|
-
stored = patched(stored, unit);
|
|
238
|
-
unit = [];
|
|
239
|
-
}), () => stored);
|
|
240
|
-
}
|
|
241
|
-
function storedReferrers(referrers) {
|
|
242
|
-
const sets = new Map();
|
|
243
|
-
let unit = new Map();
|
|
244
|
-
const pairs = function* () {
|
|
245
|
-
for (const [target, files] of referrers)
|
|
246
|
-
for (const file of files)
|
|
247
|
-
yield [target, file];
|
|
248
|
-
};
|
|
249
|
-
return after(inUnits(pairs(), ([target, file]) => {
|
|
250
|
-
const files = unit.get(target);
|
|
251
|
-
if (files === undefined)
|
|
252
|
-
unit.set(target, [file]);
|
|
253
|
-
else
|
|
254
|
-
files.push(file);
|
|
255
|
-
return ROW_WEIGHT;
|
|
256
|
-
}, () => {
|
|
257
|
-
for (const [target, files] of unit) {
|
|
258
|
-
sets.set(target, patched(sets.get(target) ?? NO_REFERRERS, files.map((file) => [file, true])));
|
|
259
|
-
}
|
|
260
|
-
unit = new Map();
|
|
261
|
-
}), () => storedIn(sets));
|
|
262
|
-
}
|
|
263
|
-
function heldIndex(held, composition) {
|
|
264
|
-
const index = referrersOf.get(held.text);
|
|
265
|
-
return index !== undefined && typing(index.composition, composition) ? index : null;
|
|
266
|
-
}
|
|
267
|
-
const indexing = new WeakMap();
|
|
268
|
-
export function indexReferrers(held, composition) {
|
|
269
|
-
if (heldIndex(held, composition) !== null)
|
|
270
|
-
return;
|
|
271
|
-
const running = indexing.get(held.text);
|
|
272
|
-
if (running !== undefined)
|
|
273
|
-
return running;
|
|
274
|
-
const targets = new Map();
|
|
275
|
-
const referrers = new Map();
|
|
276
|
-
const filled = inUnits(Object.keys(held.text), (path) => {
|
|
277
|
-
const content = held.text[path];
|
|
278
|
-
const found = referencedBy(path, content, composition);
|
|
279
|
-
if (found.length > 0)
|
|
280
|
-
targets.set(path, found);
|
|
281
|
-
for (const target of found) {
|
|
282
|
-
const files = referrers.get(target);
|
|
283
|
-
if (files === undefined)
|
|
284
|
-
referrers.set(target, [path]);
|
|
285
|
-
else
|
|
286
|
-
files.push(path);
|
|
287
|
-
}
|
|
288
|
-
return ROW_WEIGHT + content.length;
|
|
289
|
-
});
|
|
290
|
-
const indexed = after(filled, () => after(storedIn(targets), (storedTargets) => after(storedReferrers(referrers), (stored) => {
|
|
291
|
-
referrersOf.set(held.text, { composition, targets: storedTargets, referrers: stored });
|
|
292
|
-
})));
|
|
293
|
-
if (!(indexed instanceof Promise))
|
|
294
|
-
return;
|
|
295
|
-
const building = indexed.finally(() => indexing.delete(held.text));
|
|
296
|
-
indexing.set(held.text, building);
|
|
297
|
-
return building;
|
|
298
|
-
}
|
|
299
|
-
export function referencesIndexed(held, composition) {
|
|
300
|
-
return heldIndex(held, composition) !== null;
|
|
301
|
-
}
|
|
302
|
-
export function referring(held, composition, targets) {
|
|
303
|
-
const index = heldIndex(held, composition);
|
|
304
|
-
if (index === null)
|
|
305
|
-
return null;
|
|
306
|
-
const found = new Set();
|
|
307
|
-
for (const target of targets) {
|
|
308
|
-
for (const file of Object.keys(referrersOfTarget(index, target)))
|
|
309
|
-
found.add(file);
|
|
310
|
-
}
|
|
311
|
-
return found;
|
|
312
|
-
}
|
|
313
66
|
export function available(composition) {
|
|
314
|
-
return
|
|
315
|
-
(composition.selection === null || composition.selection.model.status !== 'unavailable'));
|
|
316
|
-
}
|
|
317
|
-
export function* changedCleanly(next, previous, composition) {
|
|
318
|
-
if (!typing(previous.composition, composition))
|
|
319
|
-
return false;
|
|
320
|
-
const paths = new Set([
|
|
321
|
-
...(yield* differences(previous.text, next.text)),
|
|
322
|
-
...(yield* differences(previous.binaries, next.binaries, () => true)),
|
|
323
|
-
]);
|
|
324
|
-
const binary = (path) => Object.hasOwn(next.binaries, path);
|
|
325
|
-
const within = (file) => (path) => selected(composition, path) === selected(composition, file);
|
|
326
|
-
const reaching = (file, check) => {
|
|
327
|
-
if (!check.ok)
|
|
328
|
-
return false;
|
|
329
|
-
const part = within(file);
|
|
330
|
-
return check.references.every((reference) => resolves(reference, (path) => (part(path) ? declared(next.text[path]) : undefined), (path) => part(path) && binary(path)));
|
|
331
|
-
};
|
|
332
|
-
const changedTargets = new Map();
|
|
333
|
-
const shifted = [];
|
|
334
|
-
const admitted = (path) => {
|
|
335
|
-
const now = next.text[path];
|
|
336
|
-
const was = previous.text[path];
|
|
337
|
-
const modeled = modelOf(composition, path) !== null;
|
|
338
|
-
if ((now === undefined) !== (was === undefined) ||
|
|
339
|
-
declared(now) !== declared(was) ||
|
|
340
|
-
binary(path) !== Object.hasOwn(previous.binaries, path)) {
|
|
341
|
-
shifted.push(path);
|
|
342
|
-
}
|
|
343
|
-
if (!modeled && typedIn(was) && !typedIn(now))
|
|
344
|
-
return false;
|
|
345
|
-
if (now === undefined) {
|
|
346
|
-
if (modeled)
|
|
347
|
-
changedTargets.set(path, []);
|
|
348
|
-
return true;
|
|
349
|
-
}
|
|
350
|
-
if (binary(path))
|
|
351
|
-
return false;
|
|
352
|
-
if (!modeled) {
|
|
353
|
-
if (declared(now) === undefined)
|
|
354
|
-
return false;
|
|
355
|
-
return typedIn(now) || checked(path, now, composition).ok;
|
|
356
|
-
}
|
|
357
|
-
const check = checked(path, now, composition);
|
|
358
|
-
if (!reaching(path, check))
|
|
359
|
-
return false;
|
|
360
|
-
changedTargets.set(path, targetsOf(check));
|
|
361
|
-
return true;
|
|
362
|
-
};
|
|
363
|
-
for (const path of paths) {
|
|
364
|
-
if (!admitted(path))
|
|
365
|
-
return false;
|
|
366
|
-
yield ROW_WEIGHT + (next.text[path]?.length ?? 0);
|
|
367
|
-
}
|
|
368
|
-
const index = heldIndex(previous, composition);
|
|
369
|
-
if (index === null && shifted.length > 0)
|
|
370
|
-
return false;
|
|
371
|
-
for (const target of shifted) {
|
|
372
|
-
const files = index === null ? [] : Object.keys(referrersOfTarget(index, target));
|
|
373
|
-
for (const file of files) {
|
|
374
|
-
if (paths.has(file))
|
|
375
|
-
continue;
|
|
376
|
-
if (!reaching(file, checked(file, next.text[file], composition)))
|
|
377
|
-
return false;
|
|
378
|
-
yield ROW_WEIGHT + next.text[file].length;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
if (index !== null) {
|
|
382
|
-
referrersOf.set(next.text, changedTargets.size === 0 ? index : yield* reindexed(index, changedTargets));
|
|
383
|
-
}
|
|
384
|
-
return true;
|
|
67
|
+
return composition.model.status !== 'unavailable';
|
|
385
68
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Plan, QueryRows } from './query.js';
|
|
2
|
+
import type { Connection, Value } from './tables.js';
|
|
3
|
+
export type QueryRoom = {
|
|
4
|
+
readonly locator: string;
|
|
5
|
+
readonly key: number;
|
|
6
|
+
};
|
|
7
|
+
export type Fragment = {
|
|
8
|
+
readonly sql: string;
|
|
9
|
+
readonly bind: readonly Value[];
|
|
10
|
+
};
|
|
11
|
+
export type QueryAnswer = QueryRows & {
|
|
12
|
+
readonly more?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function selected(connection: Connection, plan: Plan, rooms: readonly QueryRoom[]): Fragment;
|
|
15
|
+
export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null): QueryAnswer;
|
|
16
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAOV,IAAI,EAIJ,SAAS,EAIV,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,UAAU,EAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAU1D,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,KAAK,EAAE,CAAA;CAAE,CAAC;AAmtBjF,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAqTjE,wBAAgB,QAAQ,CACtB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,GAC1B,QAAQ,CAEV;AAED,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,MAAM,GAAE,MAAM,GAAG,IAAW,GAC3B,WAAW,CAUb"}
|