@agentshouse/mdruntime 0.1.0-c2c52158b7381 → 0.1.0-c2ef9303a058d

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