@agentshouse/mdruntime 0.1.0-cc5745cd9af96 → 0.1.0-ccbb89b0ca151

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 (225) hide show
  1. package/README.md +18 -15
  2. package/dist/adapter.d.ts +56 -32
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/attached-model.d.ts +5 -1
  5. package/dist/attached-model.d.ts.map +1 -1
  6. package/dist/attached-model.js +21 -4
  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 +30 -8
  11. package/dist/bootstrap.d.ts.map +1 -1
  12. package/dist/bootstrap.js +186 -85
  13. package/dist/chain.d.ts +11 -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 -94
  19. package/dist/change.d.ts +31 -1
  20. package/dist/change.d.ts.map +1 -1
  21. package/dist/change.js +10 -1
  22. package/dist/client.d.ts +9 -5
  23. package/dist/client.d.ts.map +1 -1
  24. package/dist/client.js +80 -6
  25. package/dist/collection.d.ts +6 -20
  26. package/dist/collection.d.ts.map +1 -1
  27. package/dist/collection.js +31 -354
  28. package/dist/compile.d.ts +16 -0
  29. package/dist/compile.d.ts.map +1 -0
  30. package/dist/compile.js +765 -0
  31. package/dist/connection.d.ts +16 -9
  32. package/dist/connection.d.ts.map +1 -1
  33. package/dist/connection.js +2399 -952
  34. package/dist/conversation.d.ts +3 -3
  35. package/dist/conversation.d.ts.map +1 -1
  36. package/dist/conversation.js +80 -68
  37. package/dist/digest.d.ts +7 -0
  38. package/dist/digest.d.ts.map +1 -0
  39. package/dist/digest.js +113 -0
  40. package/dist/durability.d.ts +3 -5
  41. package/dist/durability.d.ts.map +1 -1
  42. package/dist/durability.js +5 -0
  43. package/dist/entry.d.ts +3 -1
  44. package/dist/entry.d.ts.map +1 -1
  45. package/dist/entry.js +18 -24
  46. package/dist/file.d.ts +2 -19
  47. package/dist/file.d.ts.map +1 -1
  48. package/dist/file.js +7 -122
  49. package/dist/fulltext.d.ts +27 -0
  50. package/dist/fulltext.d.ts.map +1 -0
  51. package/dist/fulltext.js +368 -0
  52. package/dist/host.d.ts +4 -4
  53. package/dist/host.d.ts.map +1 -1
  54. package/dist/host.js +45 -15
  55. package/dist/identity.d.ts +0 -1
  56. package/dist/identity.d.ts.map +1 -1
  57. package/dist/identity.js +0 -3
  58. package/dist/index.d.ts +11 -9
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +4 -1
  61. package/dist/live.d.ts +22 -0
  62. package/dist/live.d.ts.map +1 -0
  63. package/dist/live.js +124 -0
  64. package/dist/media.d.ts +8 -0
  65. package/dist/media.d.ts.map +1 -0
  66. package/dist/media.js +195 -0
  67. package/dist/memory.d.ts +2 -1
  68. package/dist/memory.d.ts.map +1 -1
  69. package/dist/memory.js +63 -22
  70. package/dist/messages.d.ts +28 -0
  71. package/dist/messages.d.ts.map +1 -0
  72. package/dist/messages.js +90 -0
  73. package/dist/model.d.ts.map +1 -1
  74. package/dist/model.js +1 -1
  75. package/dist/name.d.ts +4 -0
  76. package/dist/name.d.ts.map +1 -0
  77. package/dist/name.js +122 -0
  78. package/dist/observation.d.ts +12 -0
  79. package/dist/observation.d.ts.map +1 -1
  80. package/dist/observation.js +84 -0
  81. package/dist/opened.d.ts +22 -0
  82. package/dist/opened.d.ts.map +1 -0
  83. package/dist/opened.js +107 -0
  84. package/dist/outcome.d.ts +40 -5
  85. package/dist/outcome.d.ts.map +1 -1
  86. package/dist/outcome.js +36 -2
  87. package/dist/overlay.d.ts +1 -4
  88. package/dist/overlay.d.ts.map +1 -1
  89. package/dist/overlay.js +22 -148
  90. package/dist/query.d.ts +11 -1
  91. package/dist/query.d.ts.map +1 -1
  92. package/dist/query.js +13 -1
  93. package/dist/reach.d.ts +11 -3
  94. package/dist/reach.d.ts.map +1 -1
  95. package/dist/reach.js +198 -69
  96. package/dist/readiness.d.ts +20 -9
  97. package/dist/readiness.d.ts.map +1 -1
  98. package/dist/readiness.js +6 -6
  99. package/dist/reads.d.ts.map +1 -1
  100. package/dist/reads.js +4 -2
  101. package/dist/recovery.d.ts +2 -2
  102. package/dist/recovery.d.ts.map +1 -1
  103. package/dist/recovery.js +8 -7
  104. package/dist/refresh.d.ts +15 -14
  105. package/dist/refresh.d.ts.map +1 -1
  106. package/dist/refresh.js +113 -75
  107. package/dist/replica.d.ts +56 -39
  108. package/dist/replica.d.ts.map +1 -1
  109. package/dist/replica.js +277 -197
  110. package/dist/room-draft.d.ts +4 -1
  111. package/dist/room-draft.d.ts.map +1 -1
  112. package/dist/room-draft.js +54 -13
  113. package/dist/rows.d.ts +38 -31
  114. package/dist/rows.d.ts.map +1 -1
  115. package/dist/rows.js +173 -101
  116. package/dist/save.d.ts +49 -14
  117. package/dist/save.d.ts.map +1 -1
  118. package/dist/save.js +352 -98
  119. package/dist/search.d.ts +11 -43
  120. package/dist/search.d.ts.map +1 -1
  121. package/dist/search.js +0 -213
  122. package/dist/shared.d.ts +4 -3
  123. package/dist/shared.d.ts.map +1 -1
  124. package/dist/shared.js +67 -34
  125. package/dist/store.d.ts +83 -95
  126. package/dist/store.d.ts.map +1 -1
  127. package/dist/store.js +317 -720
  128. package/dist/stored.d.ts +152 -0
  129. package/dist/stored.d.ts.map +1 -0
  130. package/dist/stored.js +607 -0
  131. package/dist/tables.d.ts +352 -0
  132. package/dist/tables.d.ts.map +1 -0
  133. package/dist/tables.js +624 -0
  134. package/dist/turn.d.ts +1 -1
  135. package/dist/turn.d.ts.map +1 -1
  136. package/dist/turn.js +31 -20
  137. package/dist/validation.d.ts +30 -0
  138. package/dist/validation.d.ts.map +1 -0
  139. package/dist/validation.js +162 -0
  140. package/dist/windows.d.ts +2 -6
  141. package/dist/windows.d.ts.map +1 -1
  142. package/dist/windows.js +30 -34
  143. package/dist/wire.d.ts +17 -1
  144. package/dist/wire.d.ts.map +1 -1
  145. package/dist/wire.js +5 -1
  146. package/dist/words.d.ts +19 -0
  147. package/dist/words.d.ts.map +1 -0
  148. package/dist/words.js +150 -0
  149. package/package.json +18 -19
  150. package/AGENTS.md +0 -299
  151. package/dist/chat/acts.d.ts +0 -33
  152. package/dist/chat/acts.d.ts.map +0 -1
  153. package/dist/chat/acts.js +0 -36
  154. package/dist/chat/context.d.ts +0 -3
  155. package/dist/chat/context.d.ts.map +0 -1
  156. package/dist/chat/context.js +0 -10
  157. package/dist/chat/earlier.d.ts +0 -10
  158. package/dist/chat/earlier.d.ts.map +0 -1
  159. package/dist/chat/earlier.js +0 -54
  160. package/dist/chat/input.d.ts +0 -9
  161. package/dist/chat/input.d.ts.map +0 -1
  162. package/dist/chat/input.js +0 -99
  163. package/dist/chat/kit.d.ts +0 -61
  164. package/dist/chat/kit.d.ts.map +0 -1
  165. package/dist/chat/kit.js +0 -123
  166. package/dist/chat/lasting.d.ts +0 -6
  167. package/dist/chat/lasting.d.ts.map +0 -1
  168. package/dist/chat/lasting.js +0 -19
  169. package/dist/chat/list.d.ts +0 -28
  170. package/dist/chat/list.d.ts.map +0 -1
  171. package/dist/chat/list.js +0 -103
  172. package/dist/chat/markdown.d.ts +0 -21
  173. package/dist/chat/markdown.d.ts.map +0 -1
  174. package/dist/chat/markdown.js +0 -246
  175. package/dist/chat/message.d.ts +0 -7
  176. package/dist/chat/message.d.ts.map +0 -1
  177. package/dist/chat/message.js +0 -202
  178. package/dist/chat/messages.d.ts +0 -24
  179. package/dist/chat/messages.d.ts.map +0 -1
  180. package/dist/chat/messages.js +0 -187
  181. package/dist/chat/name.d.ts +0 -6
  182. package/dist/chat/name.d.ts.map +0 -1
  183. package/dist/chat/name.js +0 -37
  184. package/dist/chat/opened.d.ts +0 -11
  185. package/dist/chat/opened.d.ts.map +0 -1
  186. package/dist/chat/opened.js +0 -17
  187. package/dist/chat/overlay.d.ts +0 -32
  188. package/dist/chat/overlay.d.ts.map +0 -1
  189. package/dist/chat/overlay.js +0 -107
  190. package/dist/chat/parts.d.ts +0 -57
  191. package/dist/chat/parts.d.ts.map +0 -1
  192. package/dist/chat/parts.js +0 -119
  193. package/dist/chat/pieces.d.ts +0 -62
  194. package/dist/chat/pieces.d.ts.map +0 -1
  195. package/dist/chat/pieces.js +0 -1110
  196. package/dist/chat/process.d.ts +0 -20
  197. package/dist/chat/process.d.ts.map +0 -1
  198. package/dist/chat/process.js +0 -32
  199. package/dist/chat/provider.d.ts +0 -64
  200. package/dist/chat/provider.d.ts.map +0 -1
  201. package/dist/chat/provider.js +0 -638
  202. package/dist/chat/question.d.ts +0 -9
  203. package/dist/chat/question.d.ts.map +0 -1
  204. package/dist/chat/question.js +0 -69
  205. package/dist/chat/questions.d.ts +0 -31
  206. package/dist/chat/questions.d.ts.map +0 -1
  207. package/dist/chat/questions.js +0 -111
  208. package/dist/chat/read.d.ts +0 -5
  209. package/dist/chat/read.d.ts.map +0 -1
  210. package/dist/chat/read.js +0 -13
  211. package/dist/chat/ready.d.ts +0 -34
  212. package/dist/chat/ready.d.ts.map +0 -1
  213. package/dist/chat/ready.js +0 -91
  214. package/dist/chat/steady.d.ts +0 -3
  215. package/dist/chat/steady.d.ts.map +0 -1
  216. package/dist/chat/steady.js +0 -26
  217. package/dist/chat/style.d.ts +0 -4
  218. package/dist/chat/style.d.ts.map +0 -1
  219. package/dist/chat/style.js +0 -302
  220. package/dist/chat.d.ts +0 -14
  221. package/dist/chat.d.ts.map +0 -1
  222. package/dist/chat.js +0 -8
  223. package/dist/read-side.d.ts +0 -27
  224. package/dist/read-side.d.ts.map +0 -1
  225. package/dist/read-side.js +0 -826
@@ -1,11 +1,9 @@
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, patched, patching, shared, sizeOf } from './shared.js';
5
- import { after, finished, inUnits, ROW_WEIGHT } from './turn.js';
3
+ import { keysIn, sortedKeys } from './shared.js';
4
+ import { ROW_WEIGHT } from './turn.js';
6
5
  export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
7
- const NO_TYPES = { types: {} };
8
- function selected(composition, path) {
6
+ export function selected(composition, path) {
9
7
  return (composition.selection !== null &&
10
8
  composition.selection.roots.some((root) => beneath(root, path)));
11
9
  }
@@ -14,372 +12,51 @@ export function governing(composition, path) {
14
12
  ? composition.selection.model
15
13
  : composition.model;
16
14
  }
17
- const parsedIn = new WeakMap();
18
- function* carried(previous, text) {
19
- const held = parsedIn.get(previous);
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 = {
15
+ export function collectionOf(text, composition) {
16
+ const parsed = new Map();
17
+ return {
44
18
  text,
45
19
  composition,
46
20
  document(path) {
47
- const held = cachedIn(collection, path);
48
- if (held !== undefined)
49
- return held ?? undefined;
21
+ if (parsed.has(path))
22
+ return parsed.get(path) ?? undefined;
50
23
  const content = text[path];
51
24
  if (content === undefined)
52
25
  return undefined;
53
26
  const read = parse(content, path);
54
- parsed.added.set(path, read.ok ? read.document : null);
27
+ parsed.set(path, read.ok ? read.document : null);
55
28
  return read.ok ? read.document : undefined;
56
29
  },
57
30
  };
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
31
  }
71
32
  export function* documentsOf(collection) {
72
- for (const path of Object.keys(collection.text).sort()) {
73
- const held = cachedIn(collection, path);
74
- if (held === null)
75
- continue;
76
- if (held !== undefined) {
77
- yield [path, held];
33
+ const paths = yield* sortedKeys(collection.text);
34
+ return (function* () {
35
+ for (const path of paths) {
36
+ const document = collection.document(path);
37
+ if (document !== undefined)
38
+ yield [path, document];
39
+ }
40
+ })();
41
+ }
42
+ export function* unreadable(text, paths = null) {
43
+ const named = paths ?? (yield* keysIn(text));
44
+ let least = null;
45
+ for (const path of named) {
46
+ const content = Object.hasOwn(text, path) ? text[path] : undefined;
47
+ if (content === undefined)
78
48
  continue;
49
+ const read = parse(content, path);
50
+ if (!read.ok && (least === null || path < least.path)) {
51
+ least = { path, refused: { kind: 'refused', refusal: read.refusal } };
79
52
  }
80
- const read = parse(collection.text[path], path);
81
- if (read.ok)
82
- yield [path, read.document];
53
+ yield ROW_WEIGHT + content.length;
83
54
  }
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;
55
+ return least?.refused ?? null;
96
56
  }
97
57
  export function validRoot(root) {
98
58
  return typeof root === 'string' && normalize(root) === root;
99
59
  }
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
60
  export function available(composition) {
314
- return (composition.model.status !== 'unavailable' &&
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;
61
+ return composition.model.status !== 'unavailable';
385
62
  }
@@ -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,EAGJ,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;AAwrBjF,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AA4TjE,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"}