@agentshouse/mdruntime 0.1.0-c806ecaf4afed → 0.1.0-c809974611fbc

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 (287) hide show
  1. package/README.md +21 -19
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +45 -25
  4. package/dist/act-lanes.d.ts +11 -14
  5. package/dist/act-lanes.d.ts.map +1 -1
  6. package/dist/act-lanes.js +53 -5
  7. package/dist/actions.d.ts +8 -2
  8. package/dist/actions.d.ts.map +1 -1
  9. package/dist/actions.js +161 -71
  10. package/dist/adapter.d.ts +165 -29
  11. package/dist/adapter.d.ts.map +1 -1
  12. package/dist/attached-model.d.ts +0 -1
  13. package/dist/attached-model.d.ts.map +1 -1
  14. package/dist/attached-model.js +2 -7
  15. package/dist/{binary.d.ts → attachment.d.ts} +8 -4
  16. package/dist/attachment.d.ts.map +1 -0
  17. package/dist/attachment.js +15 -0
  18. package/dist/authored.d.ts +88 -0
  19. package/dist/authored.d.ts.map +1 -0
  20. package/dist/authored.js +347 -0
  21. package/dist/chain.d.ts +1 -1
  22. package/dist/chain.d.ts.map +1 -1
  23. package/dist/chain.js +5 -2
  24. package/dist/change.d.ts +6 -2
  25. package/dist/change.d.ts.map +1 -1
  26. package/dist/change.js +3 -0
  27. package/dist/chat-types.d.ts +0 -2
  28. package/dist/chat-types.d.ts.map +1 -1
  29. package/dist/chat-types.js +2 -4
  30. package/dist/client.d.ts +27 -15
  31. package/dist/client.d.ts.map +1 -1
  32. package/dist/client.js +29 -57
  33. package/dist/collection.d.ts +6 -1
  34. package/dist/collection.d.ts.map +1 -1
  35. package/dist/collection.js +23 -9
  36. package/dist/column.d.ts +5 -0
  37. package/dist/column.d.ts.map +1 -0
  38. package/dist/column.js +9 -0
  39. package/dist/compile.d.ts +4 -1
  40. package/dist/compile.d.ts.map +1 -1
  41. package/dist/compile.js +88 -44
  42. package/dist/connection.d.ts +1 -1
  43. package/dist/connection.d.ts.map +1 -1
  44. package/dist/connection.js +23 -16
  45. package/dist/context.d.ts.map +1 -1
  46. package/dist/context.js +1 -1
  47. package/dist/conversation-live.d.ts +23 -10
  48. package/dist/conversation-live.d.ts.map +1 -1
  49. package/dist/conversation-live.js +18 -8
  50. package/dist/conversation-row.d.ts +8 -1
  51. package/dist/conversation-row.d.ts.map +1 -1
  52. package/dist/conversation-row.js +20 -7
  53. package/dist/conversation.d.ts +31 -12
  54. package/dist/conversation.d.ts.map +1 -1
  55. package/dist/conversation.js +264 -190
  56. package/dist/declaration.js +3 -3
  57. package/dist/discovery.d.ts +3 -1
  58. package/dist/discovery.d.ts.map +1 -1
  59. package/dist/discovery.js +36 -9
  60. package/dist/download.d.ts +6 -0
  61. package/dist/download.d.ts.map +1 -0
  62. package/dist/download.js +42 -0
  63. package/dist/durability.d.ts +5 -0
  64. package/dist/durability.d.ts.map +1 -1
  65. package/dist/durability.js +7 -0
  66. package/dist/entry.d.ts +25 -1
  67. package/dist/entry.d.ts.map +1 -1
  68. package/dist/entry.js +111 -34
  69. package/dist/expectation.d.ts +25 -14
  70. package/dist/expectation.d.ts.map +1 -1
  71. package/dist/expectation.js +51 -20
  72. package/dist/failure.d.ts +2 -0
  73. package/dist/failure.d.ts.map +1 -1
  74. package/dist/failure.js +6 -1
  75. package/dist/figures.d.ts +1 -1
  76. package/dist/figures.d.ts.map +1 -1
  77. package/dist/figures.js +6 -4
  78. package/dist/file.d.ts +1 -1
  79. package/dist/file.d.ts.map +1 -1
  80. package/dist/file.js +3 -2
  81. package/dist/host.d.ts +7 -2
  82. package/dist/host.d.ts.map +1 -1
  83. package/dist/host.js +78 -32
  84. package/dist/house-query.d.ts +24 -0
  85. package/dist/house-query.d.ts.map +1 -0
  86. package/dist/house-query.js +102 -0
  87. package/dist/identity.d.ts +1 -1
  88. package/dist/identity.d.ts.map +1 -1
  89. package/dist/identity.js +1 -1
  90. package/dist/index.d.ts +24 -13
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +15 -7
  93. package/dist/install.d.ts +10 -4
  94. package/dist/install.d.ts.map +1 -1
  95. package/dist/install.js +45 -46
  96. package/dist/lifecycle.d.ts +1 -1
  97. package/dist/lifecycle.d.ts.map +1 -1
  98. package/dist/lifecycle.js +52 -32
  99. package/dist/listing.d.ts +24 -12
  100. package/dist/listing.d.ts.map +1 -1
  101. package/dist/listing.js +50 -21
  102. package/dist/live.d.ts +19 -3
  103. package/dist/live.d.ts.map +1 -1
  104. package/dist/live.js +94 -36
  105. package/dist/loaded.d.ts +7 -0
  106. package/dist/loaded.d.ts.map +1 -0
  107. package/dist/loaded.js +46 -0
  108. package/dist/locks.d.ts.map +1 -1
  109. package/dist/locks.js +4 -3
  110. package/dist/lost.d.ts.map +1 -1
  111. package/dist/lost.js +2 -3
  112. package/dist/media.d.ts +19 -3
  113. package/dist/media.d.ts.map +1 -1
  114. package/dist/media.js +181 -34
  115. package/dist/memory.d.ts +7 -3
  116. package/dist/memory.d.ts.map +1 -1
  117. package/dist/memory.js +66 -22
  118. package/dist/messages.d.ts +17 -3
  119. package/dist/messages.d.ts.map +1 -1
  120. package/dist/messages.js +29 -10
  121. package/dist/modal.d.ts +2 -0
  122. package/dist/modal.d.ts.map +1 -0
  123. package/dist/modal.js +11 -0
  124. package/dist/model.d.ts +10 -7
  125. package/dist/model.d.ts.map +1 -1
  126. package/dist/model.js +7 -1
  127. package/dist/models.d.ts.map +1 -1
  128. package/dist/models.js +5 -8
  129. package/dist/name.d.ts +0 -1
  130. package/dist/name.d.ts.map +1 -1
  131. package/dist/name.js +3 -7
  132. package/dist/observation.d.ts +29 -12
  133. package/dist/observation.d.ts.map +1 -1
  134. package/dist/observation.js +206 -69
  135. package/dist/online.d.ts +7 -0
  136. package/dist/online.d.ts.map +1 -0
  137. package/dist/online.js +29 -0
  138. package/dist/opened.d.ts +5 -5
  139. package/dist/opened.d.ts.map +1 -1
  140. package/dist/opened.js +2 -2
  141. package/dist/opening.d.ts.map +1 -1
  142. package/dist/opening.js +22 -10
  143. package/dist/outcome.d.ts +33 -13
  144. package/dist/outcome.d.ts.map +1 -1
  145. package/dist/outcome.js +36 -6
  146. package/dist/overlay.d.ts +21 -7
  147. package/dist/overlay.d.ts.map +1 -1
  148. package/dist/overlay.js +112 -39
  149. package/dist/parts.d.ts +4 -9
  150. package/dist/parts.d.ts.map +1 -1
  151. package/dist/parts.js +30 -15
  152. package/dist/paths.d.ts +1 -1
  153. package/dist/paths.js +1 -1
  154. package/dist/preparation.d.ts +33 -7
  155. package/dist/preparation.d.ts.map +1 -1
  156. package/dist/preparation.js +198 -87
  157. package/dist/presence.d.ts +8 -2
  158. package/dist/presence.d.ts.map +1 -1
  159. package/dist/presence.js +24 -13
  160. package/dist/queries.d.ts +2 -2
  161. package/dist/queries.d.ts.map +1 -1
  162. package/dist/queries.js +133 -73
  163. package/dist/query.d.ts +2 -2
  164. package/dist/query.d.ts.map +1 -1
  165. package/dist/questions.d.ts +1 -5
  166. package/dist/questions.d.ts.map +1 -1
  167. package/dist/questions.js +3 -8
  168. package/dist/queue.d.ts +2 -2
  169. package/dist/queue.d.ts.map +1 -1
  170. package/dist/queue.js +73 -48
  171. package/dist/reach.d.ts +15 -6
  172. package/dist/reach.d.ts.map +1 -1
  173. package/dist/reach.js +180 -39
  174. package/dist/react.d.ts +16 -11
  175. package/dist/react.d.ts.map +1 -1
  176. package/dist/react.js +22 -4
  177. package/dist/readiness.d.ts +23 -4
  178. package/dist/readiness.d.ts.map +1 -1
  179. package/dist/readiness.js +18 -10
  180. package/dist/reads.d.ts +4 -2
  181. package/dist/reads.d.ts.map +1 -1
  182. package/dist/reads.js +22 -7
  183. package/dist/recovery.d.ts +4 -1
  184. package/dist/recovery.d.ts.map +1 -1
  185. package/dist/recovery.js +31 -8
  186. package/dist/reference-forms.d.ts +4 -0
  187. package/dist/reference-forms.d.ts.map +1 -0
  188. package/dist/reference-forms.js +74 -0
  189. package/dist/refresh.d.ts +1 -1
  190. package/dist/refresh.js +4 -4
  191. package/dist/refusal.d.ts.map +1 -1
  192. package/dist/refusal.js +1 -3
  193. package/dist/replica.d.ts +3 -8
  194. package/dist/replica.d.ts.map +1 -1
  195. package/dist/replica.js +5 -5
  196. package/dist/retried.d.ts +30 -0
  197. package/dist/retried.d.ts.map +1 -0
  198. package/dist/retried.js +72 -0
  199. package/dist/room-draft.d.ts +31 -6
  200. package/dist/room-draft.d.ts.map +1 -1
  201. package/dist/room-draft.js +262 -36
  202. package/dist/room-drafts.d.ts.map +1 -1
  203. package/dist/room-drafts.js +12 -7
  204. package/dist/room-list.d.ts +10 -0
  205. package/dist/room-list.d.ts.map +1 -0
  206. package/dist/room-list.js +47 -0
  207. package/dist/rows.d.ts +11 -2
  208. package/dist/rows.d.ts.map +1 -1
  209. package/dist/rows.js +24 -10
  210. package/dist/run-tables.d.ts +25 -0
  211. package/dist/run-tables.d.ts.map +1 -0
  212. package/dist/run-tables.js +94 -0
  213. package/dist/running.d.ts +5 -0
  214. package/dist/running.d.ts.map +1 -0
  215. package/dist/running.js +10 -0
  216. package/dist/runs.d.ts +27 -0
  217. package/dist/runs.d.ts.map +1 -0
  218. package/dist/runs.js +90 -0
  219. package/dist/runtime.d.ts +7 -4
  220. package/dist/runtime.d.ts.map +1 -1
  221. package/dist/save.d.ts +2 -0
  222. package/dist/save.d.ts.map +1 -1
  223. package/dist/save.js +105 -124
  224. package/dist/saves.d.ts +7 -5
  225. package/dist/saves.d.ts.map +1 -1
  226. package/dist/saves.js +107 -57
  227. package/dist/seed.d.ts.map +1 -1
  228. package/dist/seed.js +2 -2
  229. package/dist/selector.d.ts +3 -0
  230. package/dist/selector.d.ts.map +1 -0
  231. package/dist/selector.js +22 -0
  232. package/dist/shown.d.ts +5 -2
  233. package/dist/shown.d.ts.map +1 -1
  234. package/dist/shown.js +79 -43
  235. package/dist/socket/lanes.d.ts +12 -4
  236. package/dist/socket/lanes.d.ts.map +1 -1
  237. package/dist/socket/lanes.js +34 -8
  238. package/dist/socket/session.d.ts +4 -1
  239. package/dist/socket/session.d.ts.map +1 -1
  240. package/dist/socket/session.js +3 -0
  241. package/dist/socket.d.ts +7 -4
  242. package/dist/socket.d.ts.map +1 -1
  243. package/dist/socket.js +11 -9
  244. package/dist/source.d.ts +7 -7
  245. package/dist/source.d.ts.map +1 -1
  246. package/dist/source.js +15 -2
  247. package/dist/store/installs.d.ts +2 -2
  248. package/dist/store/installs.d.ts.map +1 -1
  249. package/dist/store/installs.js +10 -4
  250. package/dist/store/readiness.d.ts +5 -4
  251. package/dist/store/readiness.d.ts.map +1 -1
  252. package/dist/store/readiness.js +28 -12
  253. package/dist/store/records.d.ts +30 -8
  254. package/dist/store/records.d.ts.map +1 -1
  255. package/dist/store/records.js +70 -26
  256. package/dist/store/rooms-shown.d.ts +8 -0
  257. package/dist/store/rooms-shown.d.ts.map +1 -0
  258. package/dist/store/rooms-shown.js +13 -0
  259. package/dist/store.d.ts +17 -10
  260. package/dist/store.d.ts.map +1 -1
  261. package/dist/store.js +18 -6
  262. package/dist/stored.d.ts +41 -16
  263. package/dist/stored.d.ts.map +1 -1
  264. package/dist/stored.js +215 -57
  265. package/dist/surface.d.ts +20 -8
  266. package/dist/surface.d.ts.map +1 -1
  267. package/dist/surface.js +62 -27
  268. package/dist/sync.d.ts +4 -2
  269. package/dist/sync.d.ts.map +1 -1
  270. package/dist/sync.js +76 -40
  271. package/dist/tables.d.ts +41 -52
  272. package/dist/tables.d.ts.map +1 -1
  273. package/dist/tables.js +110 -326
  274. package/dist/tallies.d.ts.map +1 -1
  275. package/dist/tallies.js +3 -4
  276. package/dist/validation.d.ts +2 -0
  277. package/dist/validation.d.ts.map +1 -1
  278. package/dist/validation.js +50 -10
  279. package/dist/wire.d.ts +40 -16
  280. package/dist/wire.d.ts.map +1 -1
  281. package/dist/wire.js +22 -14
  282. package/package.json +4 -4
  283. package/dist/binary.d.ts.map +0 -1
  284. package/dist/binary.js +0 -8
  285. package/dist/log.d.ts +0 -6
  286. package/dist/log.d.ts.map +0 -1
  287. package/dist/log.js +0 -14
package/dist/client.js CHANGED
@@ -1,26 +1,11 @@
1
- import { shownBy } from './media.js';
1
+ import { handedCopy, handedLink } from './download.js';
2
2
  import { pageMetadataBlock } from './page-metadata.js';
3
- import { observed } from './observation.js';
3
+ import { appRooms, observed } from './observation.js';
4
4
  import { runtimeError } from './failure.js';
5
+ import { attachmentBlob, } from './outcome.js';
5
6
  import { AUTHORIZATION_ENDED, PORT_CLOSED, wireAnswer, } from './wire.js';
6
7
  // React renders an arrived value in a later task and opens what that render observes as it commits, so this many frames opening nothing mean the page drew what it observes.
7
8
  const SETTLED_FRAMES = 2;
8
- // A browser reads a download's address only after the click that hands it returns, so a copy's address is released a minute later.
9
- const HANDED_COPY_MS = 60_000;
10
- const PAGE = /\.html?$/iu;
11
- const STARTED = { kind: 'started' };
12
- const BLOCKED = {
13
- kind: 'blocked',
14
- code: 'popup-blocked',
15
- fields: {},
16
- retryable: true,
17
- };
18
- function handed(url, name) {
19
- const anchor = document.createElement('a');
20
- anchor.href = url;
21
- anchor.download = name;
22
- anchor.click();
23
- }
24
9
  function refused(refusal) {
25
10
  return runtimeError(refusal.code);
26
11
  }
@@ -42,7 +27,7 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
42
27
  observations.delete(id);
43
28
  if (refusal === null)
44
29
  send({ kind: 'stop', id });
45
- }, topic === 'query');
30
+ }, topic);
46
31
  observations.set(id, { topic, input, handle });
47
32
  return handle.observation;
48
33
  }
@@ -90,7 +75,7 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
90
75
  }
91
76
  if (message.kind === 'ended') {
92
77
  for (const { topic, handle } of observations.values()) {
93
- if (topic === 'member')
78
+ if (topic === 'member' || topic === 'time-zone')
94
79
  handle.receive(null);
95
80
  }
96
81
  end(runtimeError('authorization-ended', AUTHORIZATION_ENDED));
@@ -160,12 +145,12 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
160
145
  let received = 0;
161
146
  const stream = new ReadableStream({
162
147
  async pull(controller) {
163
- const bytes = await ask('binaryFile.part', [file, part]);
148
+ const bytes = await ask('attachment.part', [file, part]);
164
149
  if (bytes === null) {
165
150
  if (received === byteLength)
166
151
  controller.close();
167
152
  else
168
- controller.error(runtimeError('binary-file-absent', 'The file ended early'));
153
+ controller.error(runtimeError('attachment-absent', 'The file ended early'));
169
154
  return;
170
155
  }
171
156
  part += 1;
@@ -176,32 +161,13 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
176
161
  return { kind: 'binary', stream, byteLength, mediaType };
177
162
  }
178
163
  async function download(room, path, revision) {
179
- const tab = PAGE.test(path) ? globalThis.open('', '_blank') : null;
180
- const linked = await ask('binaryFile.link', [room, path, revision]);
181
- if (linked.kind === 'link' && PAGE.test(linked.name)) {
182
- const away = tab ?? globalThis.open('', '_blank');
183
- if (away === null)
184
- return BLOCKED;
185
- away.location.replace(linked.url);
186
- return STARTED;
187
- }
188
- tab?.close();
189
- if (linked.kind === 'link') {
190
- handed(linked.url, linked.name);
191
- return STARTED;
192
- }
164
+ const linked = await handedLink(path, () => ask('attachment.link', [room, path, revision]));
193
165
  if (linked.kind !== 'absent')
194
166
  return linked;
195
- const read = streamed(await ask('binaryFile.read', [room, path, revision]));
167
+ const read = streamed(await ask('attachment.read', [room, path, revision]));
196
168
  if (read.kind !== 'binary')
197
169
  return read;
198
- const copy = await new Response(read.stream, {
199
- headers: { 'content-type': read.mediaType },
200
- }).blob();
201
- const url = URL.createObjectURL(copy);
202
- handed(url, path.slice(path.lastIndexOf('/') + 1));
203
- setTimeout(() => URL.revokeObjectURL(url), HANDED_COPY_MS);
204
- return STARTED;
170
+ return handedCopy(await attachmentBlob(read), path.slice(path.lastIndexOf('/') + 1));
205
171
  }
206
172
  function settled() {
207
173
  if (settling !== null)
@@ -232,12 +198,12 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
232
198
  });
233
199
  return settling;
234
200
  }
235
- const show = (room, path, revision) => ask('binaryFile.show', [room, path, revision]).then((shown) => streamed(shown));
236
- return shownBy(show, {
201
+ return {
237
202
  buildFile,
238
- rooms: () => ask('rooms', []),
203
+ rooms: () => ask('rooms', []).then(appRooms),
239
204
  query: ((query) => ask('query', [query])),
240
205
  search: (request) => ask('search', [request]),
206
+ queryHouse: (query, options) => ask('queryHouse', options === undefined ? [query] : [query, options]),
241
207
  types: (locator) => ask('types', [locator]),
242
208
  roomDraft: {
243
209
  list: () => ask('roomDraft.list', []),
@@ -264,12 +230,13 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
264
230
  takeOut: (conversation, message, operation) => ask('conversation.takeOut', [conversation, message, operation]),
265
231
  decide: (request, decision, operation) => ask('conversation.decide', [request, decision, operation]),
266
232
  rename: (conversation, name, operation) => ask('conversation.rename', [conversation, name, operation]),
267
- option: (conversation, option, value, operation) => ask('conversation.option', [conversation, option, value, operation]),
233
+ set: (conversation, settings, operation) => ask('conversation.set', [conversation, settings, operation]),
268
234
  retry: (conversation, message, operation) => ask('conversation.retry', [conversation, message, operation]),
269
- pins: () => ask('conversation.pins', []),
270
235
  pin: (figures) => ask('conversation.pin', [figures]),
271
- openedTurns: () => ask('conversation.openedTurns', []),
272
236
  openTurn: (conversation, turn) => ask('conversation.openTurn', [conversation, turn]),
237
+ dismissSuggestion: (conversation, suggestion) => ask('conversation.dismissSuggestion', [conversation, suggestion]),
238
+ attach: (file) => ask('conversation.attach', [file]),
239
+ attachment: (link) => ask('conversation.attachment', [link]),
273
240
  pageMetadata: async (app, address) => pageMetadataBlock(app, address, [...observations]
274
241
  .sort(([left], [right]) => left - right)
275
242
  .flatMap(([, { topic, input }]) => (topic === 'query' ? [input[0]] : []))),
@@ -277,28 +244,31 @@ export function connectMdRuntime(port, buildFile = UNBUILT) {
277
244
  chatDraft: {
278
245
  write: (conversation, draft, revision) => ask('chatDraft.write', [conversation, draft, revision]),
279
246
  prepend: (conversation, draft) => ask('chatDraft.prepend', [conversation, draft]),
247
+ append: (conversation, draft) => ask('chatDraft.append', [conversation, draft]),
280
248
  discard: (conversation) => ask('chatDraft.discard', [conversation]),
281
249
  },
282
250
  history: (locator, path, query) => ask('history', [locator, path, query]),
283
251
  resolve: (room, path, destination) => ask('resolve', [room, path, destination]),
284
- binaryFile: {
285
- read: (room, path, revision) => ask('binaryFile.read', [room, path, revision]).then((read) => streamed(read)),
286
- attach: (room, file) => ask('binaryFile.attach', [room, file]),
252
+ attachment: {
253
+ read: (room, path, revision) => ask('attachment.read', [room, path, revision]).then((read) => streamed(read)),
254
+ show: (room, path, revision) => ask('attachment.show', [room, path, revision]).then((shown) => streamed(shown)),
255
+ attach: (room, file) => ask('attachment.attach', [room, file]),
287
256
  download,
288
257
  },
289
258
  call: (name, input) => ask('call', [name, input]),
259
+ answered: (operation) => ask('answered', [operation]),
290
260
  reached: (locator, roomVersion, path) => ask('reached', [locator, roomVersion, path]),
291
- log: () => ask('log', []),
292
261
  persistence: () => ask('persistence', []),
293
262
  retry: () => ask('retry', []),
294
263
  cleanUp: () => ask('cleanUp', []),
295
264
  unsent: () => ask('unsent', []),
265
+ sent: () => ask('sent', []),
296
266
  reset: () => ask('reset', []),
297
267
  readAgain: () => ask('readAgain', []),
298
268
  observe: ((topic, ...input) => watch(topic, input)),
299
269
  reauthorize: () => ask('reauthorize', []),
300
270
  settled,
301
- });
271
+ };
302
272
  }
303
273
  const turns = new WeakMap();
304
274
  export function inTurn(client, work) {
@@ -308,5 +278,7 @@ export function inTurn(client, work) {
308
278
  }
309
279
  export { chainedWindows } from './chain.js';
310
280
  export { roomDraftRevision } from './identity.js';
311
- export { defineRoomMedia, ROOM_MEDIA } from './media.js';
312
- export { unanswered } from './wire.js';
281
+ export { atAddress, importedFile } from './loaded.js';
282
+ export { defineRoomMedia, ROOM_MEDIA, viewFile } from './media.js';
283
+ export { shownModal } from './modal.js';
284
+ export { unanswered, undelivered } from './wire.js';
@@ -1,4 +1,4 @@
1
- import { type DefinitionOf, type Document, type TypedPath } from '@agentshouse/mdmodel';
1
+ import { type DefinitionOf, type Document, type ParseResult, type TypedPath, type VerifiedModel } from '@agentshouse/mdmodel';
2
2
  import type { ModelState, TypesResult } from './model.js';
3
3
  import type { AppTypedSelection } from './listing.js';
4
4
  import type { MdModelIdentity } from './adapter.js';
@@ -20,6 +20,7 @@ export type Composed = {
20
20
  readonly composition: Composition;
21
21
  readonly fingerprint: string;
22
22
  };
23
+ export declare function typesPrint(types: VerifiedModel['types']): string;
23
24
  export declare function composedOf(composition: Composition): Composed;
24
25
  type Selecting<M> = {
25
26
  readonly model: M;
@@ -42,6 +43,10 @@ export declare function definitionsIn(room: {
42
43
  export declare function collectionOf(text: Readonly<Record<string, string>>, composition: Composition): Collection;
43
44
  export declare function documentsOf(collection: Collection): Generator<number, Iterable<readonly [string, Document]>, void>;
44
45
  export declare function validRoot(root: unknown): root is string;
46
+ export declare const UNTYPED = "any";
47
+ export declare function textType(read: ParseResult): string | undefined;
48
+ export declare function typeAt(composition: Composition, path: string, read: ParseResult): string | undefined;
49
+ export declare function typedText(read: ParseResult): boolean;
45
50
  export declare function available(composition: Composition): boolean;
46
51
  export {};
47
52
  //# sourceMappingURL=collection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,SAAS,EAEf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAIpD,eAAO,MAAM,QAAQ,EAAE,eAAwE,CAAC;AAEhG,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACvC,WAAW,EAAE,WAAW,CAAC;IACzB,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AAC,cAAc,EAAE,iBAAiB,GAAG,IAAI,CAAA;CAAE,EACxF,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,SAAS,SAAS,EAAE,GAC/B,YAAY,CAQd;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,WAAW,EAAE,WAAW,GACvB,UAAU,CAcZ;AAED,wBAAiB,WAAW,CAC1B,UAAU,EAAE,UAAU,GACrB,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAQhE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAEvD;AAED,eAAO,MAAM,OAAO,QAAQ,CAAC;AAE7B,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAE9D;AAED,wBAAgB,MAAM,CACpB,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,WAAW,GAChB,MAAM,GAAG,SAAS,CAIpB;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAEpD;AAED,wBAAgB,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAE3D"}
@@ -1,26 +1,27 @@
1
- import { definitionAt, parse, VERSION, } from '@agentshouse/mdmodel';
1
+ import { definitionAt, folderType, parse, VERSION, } from '@agentshouse/mdmodel';
2
2
  import { beneath, normalize } from './paths.js';
3
3
  import { hashed } from './observation.js';
4
4
  import { sortedKeys } from './shared.js';
5
5
  export const MD_MODEL = { identity: '@agentshouse/mdmodel', version: VERSION };
6
6
  const typesPrinted = new WeakMap();
7
- function typesPrint(model) {
8
- if (model.status === 'unavailable')
9
- return '';
10
- let print = typesPrinted.get(model.types);
7
+ export function typesPrint(types) {
8
+ let print = typesPrinted.get(types);
11
9
  if (print === undefined) {
12
- print = hashed(JSON.stringify(model.types)).toString(36);
13
- typesPrinted.set(model.types, print);
10
+ print = hashed(JSON.stringify(types)).toString(36);
11
+ typesPrinted.set(types, print);
14
12
  }
15
13
  return print;
16
14
  }
15
+ function modelPrint(model) {
16
+ return model.status === 'unavailable' ? '' : typesPrint(model.types);
17
+ }
17
18
  export function composedOf(composition) {
18
19
  const { model, selection } = composition;
19
20
  return {
20
21
  composition,
21
22
  fingerprint: JSON.stringify([
22
- typesPrint(model),
23
- selection === null ? null : [selection.roots, typesPrint(selection.model)],
23
+ modelPrint(model),
24
+ selection === null ? null : [selection.roots, modelPrint(selection.model)],
24
25
  ]),
25
26
  };
26
27
  }
@@ -73,6 +74,19 @@ export function* documentsOf(collection) {
73
74
  export function validRoot(root) {
74
75
  return typeof root === 'string' && normalize(root) === root;
75
76
  }
77
+ export const UNTYPED = 'any';
78
+ export function textType(read) {
79
+ return read.ok ? (read.document.type ?? UNTYPED) : undefined;
80
+ }
81
+ export function typeAt(composition, path, read) {
82
+ if (!read.ok || read.document.type !== undefined)
83
+ return textType(read);
84
+ const model = governing(composition, path);
85
+ return (model.status === 'unavailable' ? undefined : folderType(model, path)) ?? UNTYPED;
86
+ }
87
+ export function typedText(read) {
88
+ return (textType(read) ?? UNTYPED) !== UNTYPED;
89
+ }
76
90
  export function available(composition) {
77
91
  return composition.model.status !== 'unavailable';
78
92
  }
@@ -0,0 +1,5 @@
1
+ import type { Row, Value } from './tables.js';
2
+ export declare function text(value: Value | undefined): string;
3
+ export declare function texts(rows: readonly Row[], column: string): string[];
4
+ export declare function count(value: Value | undefined): number;
5
+ //# sourceMappingURL=column.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column.d.ts","sourceRoot":"","sources":["../src/column.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE9C,wBAAgB,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAErD;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAEpE;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAEtD"}
package/dist/column.js ADDED
@@ -0,0 +1,9 @@
1
+ export function text(value) {
2
+ return typeof value === 'string' ? value : String(value);
3
+ }
4
+ export function texts(rows, column) {
5
+ return rows.map((row) => text(row[column]));
6
+ }
7
+ export function count(value) {
8
+ return typeof value === 'bigint' ? Number(value) : typeof value === 'number' ? value : 0;
9
+ }
package/dist/compile.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { sql } from '@agentshouse/mdmodel';
2
+ import { type Composition } from './collection.js';
2
3
  import type { Plan, QueryRows } from './query.js';
3
4
  import type { Connection } from './tables.js';
4
5
  export type QueryRoom = {
5
6
  readonly locator: string;
6
7
  readonly key: number;
8
+ readonly composition?: Composition;
7
9
  };
8
10
  type Fragment = sql.Fragment;
9
11
  export declare const VISIBLE: (alias: string) => string;
@@ -11,6 +13,7 @@ export declare function within(alias: string, path: string): Fragment;
11
13
  export type QueryAnswer = QueryRows & {
12
14
  readonly more?: string;
13
15
  };
14
- export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null): QueryAnswer;
16
+ export declare function namedHandles(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], handles: readonly string[]): readonly string[];
17
+ export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null, follows?: readonly QueryRoom[]): QueryAnswer;
15
18
  export {};
16
19
  //# sourceMappingURL=compile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,GAAG,EAOJ,MAAM,sBAAsB,CAAC;AAI9B,OAAO,KAAK,E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AAI7B,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,MAAyD,CAAC;AAsBlG,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAE5D;AAufD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAkajE,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,MAAM,EAAE,CAenB;AAED,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,OAAO,GAAE,SAAS,SAAS,EAAO,GACjC,WAAW,CAUb"}
package/dist/compile.js CHANGED
@@ -1,19 +1,24 @@
1
1
  import { ARRAY_INDEX, bodied, byCodePoint, compared, cursorOf, heldKind, parse, pointerSegments, sql, } from '@agentshouse/mdmodel';
2
- import { binaryRecord } from './binary.js';
2
+ import { attachmentRecord } from './attachment.js';
3
+ import { definitionsAt, UNTYPED } from './collection.js';
3
4
  import { documentKey, pathOfKey, roomOfKey } from './rows.js';
5
+ import { ROOM_HANDLE } from './stored.js';
4
6
  import { FROM_START, MAXIMUM_WINDOW } from './windows.js';
5
7
  const { all, any, exists, fragment, grouped, joined, listed } = sql;
6
- export const VISIBLE = (alias) => `${alias}.visible = 1 AND ${alias}.present = 1 AND ${alias}.queried = 1`;
8
+ export const VISIBLE = (alias) => `${alias}.visible = 1 AND ${alias}.present = 1`;
7
9
  function located(alias) {
8
10
  return fragment(`(SELECT k.locator FROM replica_keys k WHERE k.key = ${alias}.key)`);
9
11
  }
10
- export function within(alias, path) {
11
- return fragment(`(${alias}.path = ? OR (${alias}.path >= ? AND ${alias}.path < ?))`, [
12
- path,
13
- `${path}/`,
14
- `${path}0`,
12
+ function inside(path, folder) {
13
+ return fragment(`(${path} = ? OR (${path} >= ? AND ${path} < ?))`, [
14
+ folder,
15
+ `${folder}/`,
16
+ `${folder}0`,
15
17
  ]);
16
18
  }
19
+ export function within(alias, path) {
20
+ return inside(`${alias}.path`, path);
21
+ }
17
22
  function ancestors(area) {
18
23
  const depth = area.path.split('/').length;
19
24
  return area.open.flatMap((open) => {
@@ -21,18 +26,18 @@ function ancestors(area) {
21
26
  return segments.slice(depth - 1, -1).map((_, at) => segments.slice(0, depth + at).join('/'));
22
27
  });
23
28
  }
24
- function fenced(alias, key, area, folders) {
29
+ function fenced(key, path, held, area, folders) {
25
30
  const opened = any([
26
- ...area.open.map((open) => within(alias, open)),
27
- ...(folders ? ancestors(area).map((path) => fragment(`${alias}.path = ?`, [path])) : []),
31
+ ...area.open.map((open) => inside(path, open)),
32
+ ...(folders ? ancestors(area).map((ancestor) => fragment(`${path} = ?`, [ancestor])) : []),
28
33
  ]);
29
34
  return all([
30
- fragment(`${alias}.key = ?`, [key]),
31
- within(alias, area.path),
35
+ fragment(`${key} = ?`, [held]),
36
+ inside(path, area.path),
32
37
  fragment(`NOT ${grouped(opened).sql}`, opened.bind),
33
38
  ]);
34
39
  }
35
- function reached(bound, alias) {
40
+ function reached(bound, key, path) {
36
41
  const reach = bound.reach;
37
42
  if (reach === null)
38
43
  return fragment('1');
@@ -45,49 +50,65 @@ function reached(bound, alias) {
45
50
  return key === undefined ? [] : [[key, pathOfKey(held)]];
46
51
  });
47
52
  const outside = any(reach.areas.flatMap((area) => {
48
- const key = bound.keys.get(area.room);
49
- return key === undefined ? [] : [fenced(alias, key, area, false)];
53
+ const held = bound.keys.get(area.room);
54
+ return held === undefined ? [] : [fenced(key, path, held, area, false)];
50
55
  }));
51
56
  return all([
52
57
  any([
53
- ...(rooms.length === 0 ? [] : [fragment(`${alias}.key IN ${listed(rooms).sql}`, rooms)]),
58
+ ...(rooms.length === 0 ? [] : [fragment(`${key} IN ${listed(rooms).sql}`, rooms)]),
54
59
  ...(documents.length === 0
55
60
  ? []
56
61
  : [
57
- fragment(`EXISTS (SELECT 1 FROM json_each(?) j WHERE j.value ->> 0 = ${alias}.key AND j.value ->> 1 = ${alias}.path)`, [JSON.stringify(documents)]),
62
+ fragment(`EXISTS (SELECT 1 FROM json_each(?) j WHERE j.value ->> 0 = ${key} AND j.value ->> 1 = ${path})`, [JSON.stringify(documents)]),
58
63
  ]),
59
64
  ]),
60
65
  ...(reach.areas.length === 0 ? [] : [fragment(`NOT ${grouped(outside).sql}`, outside.bind)]),
61
66
  ]);
62
67
  }
68
+ function handled(bound, link) {
69
+ return fragment(`FROM replica_rooms h WHERE ${ROOM_HANDLE('h')} = ${link}.handle AND h.key IN (SELECT value FROM json_each(?))`, [bound.follows]);
70
+ }
71
+ function followed(bound) {
72
+ return {
73
+ targets: (link, document) => {
74
+ const room = handled(bound, link);
75
+ return joined([
76
+ fragment(`replica_entries ${document} ON ${document}.key = CASE WHEN ${link}.handle IS NULL THEN d.key ELSE (SELECT h.key ${room.sql}) END AND ${document}.path = ${link}.target AND ${VISIBLE(document)} AND`, room.bind),
77
+ grouped(reached(bound, `${document}.key`, `${document}.path`)),
78
+ ], ' ');
79
+ },
80
+ unfollowed: (link) => {
81
+ const own = reached(bound, 'd.key', `${link}.target`);
82
+ const room = handled(bound, link);
83
+ const other = reached(bound, 'h.key', `${link}.target`);
84
+ return fragment(`NOT ((${link}.handle IS NULL AND ${own.sql}) OR EXISTS (SELECT 1 ${room.sql} AND ${other.sql}))`, [...own.bind, ...room.bind, ...other.bind]);
85
+ },
86
+ };
87
+ }
63
88
  function related(bound, plan) {
64
89
  const parts = [];
65
- if (plan.hop !== null) {
66
- parts.push(exists(joined([
67
- fragment(`SELECT 1 FROM replica_links l JOIN replica_entries m ON m.key = d.key AND m.path = l.target AND ${VISIBLE('m')} WHERE l.doc = d.id AND l.kind = 'field' AND`),
68
- grouped(sql.placed('l', plan.hop.field, 'link')),
69
- fragment('AND'),
70
- grouped(all([sql.scoped('m', plan.hop), reached(bound, 'm')])),
71
- ], ' ')));
72
- }
90
+ if (plan.hop !== null)
91
+ parts.push(sql.hopped('d', plan.hop, followed(bound)));
73
92
  if (plan.backlinks !== null) {
74
93
  const field = plan.backlinks.field;
75
94
  parts.push(exists(joined([
76
- fragment(`SELECT 1 FROM replica_links l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE l.key = d.key AND l.target = d.path AND l.kind = 'field' AND`),
95
+ fragment(`SELECT 1 FROM replica_links l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE l.key = d.key AND l.handle IS NULL AND l.target = d.path AND l.kind = 'field' AND`),
77
96
  ...(field === null ? [] : [grouped(sql.placed('l', field, 'link')), fragment('AND')]),
78
- grouped(all([sql.scoped('s', plan.backlinks), reached(bound, 's')])),
97
+ grouped(all([sql.scoped('s', plan.backlinks), reached(bound, 's.key', 's.path')])),
79
98
  ], ' ')));
80
99
  }
81
100
  return parts;
82
101
  }
83
- function filtered(bound, plan) {
102
+ function tested(bound, plan) {
84
103
  const keys = bound.rooms.map(({ key }) => key);
85
- return all([
104
+ return [
86
105
  fragment(`d.key IN ${listed(keys).sql} AND ${VISIBLE('d')}`, keys),
87
- reached(bound, 'd'),
106
+ reached(bound, 'd.key', 'd.path'),
88
107
  sql.tests('d', plan),
89
- ...related(bound, plan),
90
- ]);
108
+ ];
109
+ }
110
+ function filtered(bound, plan) {
111
+ return all([...tested(bound, plan), ...related(bound, plan)]);
91
112
  }
92
113
  function orderingOf(options) {
93
114
  const stringSort = options.stringSort ?? 'locale';
@@ -310,7 +331,16 @@ function sectionsOf(sections, names) {
310
331
  return sections;
311
332
  return Object.fromEntries(names.flatMap((name) => (Object.hasOwn(sections, name) ? [[name, sections[name]]] : [])));
312
333
  }
313
- function documentOf(shape, room, row, linked) {
334
+ function freeParts(room, path, type, content) {
335
+ const definitions = room.composition === undefined ? undefined : definitionsAt(room.composition, path);
336
+ const definition = definitions?.(type === UNTYPED ? undefined : type);
337
+ if (definition === undefined && type !== UNTYPED)
338
+ return null;
339
+ const read = parse(content, path, definition);
340
+ return read.ok ? read.document : null;
341
+ }
342
+ function documentOf(shape, queried, row, linked) {
343
+ const room = queried.locator;
314
344
  const path = row.path;
315
345
  const type = row.type;
316
346
  const fileId = row.file_id;
@@ -324,7 +354,7 @@ function documentOf(shape, room, row, linked) {
324
354
  ...(binary === null
325
355
  ? {}
326
356
  : {
327
- binaryFile: binaryRecord(path, binary, revision ?? undefined),
357
+ attachment: attachmentRecord(path, binary, revision ?? undefined),
328
358
  }),
329
359
  ...(shape.markdown && content !== null ? { markdown: content } : {}),
330
360
  ...(shape.change ? { change: changeOf(row) } : {}),
@@ -333,8 +363,9 @@ function documentOf(shape, room, row, linked) {
333
363
  ...heldFacts(shape, row),
334
364
  };
335
365
  }
336
- const read = shape.sections !== null || shape.preamble ? parse(row.content, path) : null;
337
- const body = read?.ok === true ? read.document : null;
366
+ const body = shape.sections !== null || shape.preamble
367
+ ? freeParts(queried, path, type, row.content)
368
+ : null;
338
369
  const fields = JSON.parse(row.fields ?? '{}');
339
370
  return {
340
371
  room,
@@ -377,10 +408,10 @@ function backlinksOf(connection, bound, rows) {
377
408
  held.push(row.path);
378
409
  byKey.set(key, held);
379
410
  }
380
- const reach = reached(bound, 's');
411
+ const reach = reached(bound, 's.key', 's.path');
381
412
  for (const [key, targets] of byKey) {
382
413
  const room = bound.rooms.find((one) => one.key === key).locator;
383
- const found = connection.rows(`SELECT target, path, type, field FROM (SELECT l.target, s.path, s.type, l.field, ROW_NUMBER() OVER (PARTITION BY l.target ORDER BY s.path, l.field) AS rank FROM (SELECT DISTINCT doc, target, field FROM replica_links WHERE key = ? AND kind = 'field' AND target IN (SELECT value FROM json_each(?))) l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE ${reach.sql}) WHERE rank <= ? ORDER BY target, path, field`, [key, JSON.stringify(targets), ...reach.bind, MAXIMUM_WINDOW]);
414
+ const found = connection.rows(`SELECT target, path, type, field FROM (SELECT l.target, s.path, s.type, l.field, ROW_NUMBER() OVER (PARTITION BY l.target ORDER BY s.path, l.field) AS rank FROM (SELECT DISTINCT doc, target, field FROM replica_links WHERE key = ? AND kind = 'field' AND handle IS NULL AND target IN (SELECT value FROM json_each(?))) l JOIN replica_entries s ON s.id = l.doc AND ${VISIBLE('s')} WHERE ${reach.sql}) WHERE rank <= ? ORDER BY target, path, field`, [key, JSON.stringify(targets), ...reach.bind, MAXIMUM_WINDOW]);
384
415
  for (const row of found) {
385
416
  const at = documentKey(room, row.target);
386
417
  const held = linked.get(at) ?? [];
@@ -428,8 +459,9 @@ function documents(connection, bound, plan, shape, budget) {
428
459
  const kept = bodied(shape) ? withContent(connection, windowed, budget) : windowed;
429
460
  const cut = kept.length;
430
461
  const roomOf = new Map(bound.rooms.map(({ key, locator }) => [key, locator]));
462
+ const queried = new Map(bound.rooms.map((one) => [one.key, one]));
431
463
  const linked = shape.backlinks ? backlinksOf(connection, bound, kept) : new Map();
432
- const found = kept.map((row) => documentOf(shape, roomOf.get(Number(row.key)), row, linked));
464
+ const found = kept.map((row) => documentOf(shape, queried.get(Number(row.key)), row, linked));
433
465
  const last = kept.at(-1);
434
466
  const cursorAt = (row) => cursorOf([
435
467
  ...shape.orderBy.map(({ key }, index) => decodedKey(key, row, index)),
@@ -494,7 +526,7 @@ function storedFolders(bound, plan, subfolder) {
494
526
  const key = bound.keys.get(area.room);
495
527
  if (key === undefined)
496
528
  return [];
497
- const fence = fenced('f', key, area, true);
529
+ const fence = fenced('f.key', 'f.path', key, area, true);
498
530
  return [fragment(`NOT ${grouped(fence).sql}`, fence.bind)];
499
531
  });
500
532
  const under = prefix === ''
@@ -690,16 +722,28 @@ function groups(connection, bound, plan, shape) {
690
722
  ...(total === undefined ? {} : { total }),
691
723
  };
692
724
  }
693
- function boundOf(connection, plan, rooms) {
725
+ function boundOf(connection, plan, rooms, follows) {
694
726
  return {
695
727
  rooms: [...rooms].sort((left, right) => left.locator < right.locator ? -1 : left.locator > right.locator ? 1 : 0),
696
- keys: new Map(rooms.map(({ locator, key }) => [locator, key])),
728
+ keys: new Map([...rooms, ...follows].map(({ locator, key }) => [locator, key])),
729
+ follows: JSON.stringify(follows.map(({ key }) => key)),
697
730
  reach: plan.reach,
698
731
  collate: collating(connection),
699
732
  };
700
733
  }
701
- export function answerQuery(connection, plan, rooms, budget = null) {
702
- const bound = boundOf(connection, plan, rooms);
734
+ export function namedHandles(connection, plan, rooms, handles) {
735
+ if (plan.hop === null)
736
+ return [];
737
+ const statement = joined([
738
+ fragment("SELECT DISTINCT l.handle FROM replica_entries d JOIN replica_links l ON l.doc = d.id AND l.kind = 'field' AND l.handle IN (SELECT value FROM json_each(?)) AND ", [JSON.stringify(handles)]),
739
+ grouped(sql.placed('l', plan.hop.field, 'link')),
740
+ fragment(' WHERE '),
741
+ all(tested(boundOf(connection, plan, rooms, []), plan)),
742
+ ], '');
743
+ return connection.rows(statement.sql, statement.bind).map((row) => row.handle);
744
+ }
745
+ export function answerQuery(connection, plan, rooms, budget = null, follows = []) {
746
+ const bound = boundOf(connection, plan, rooms, follows);
703
747
  if (rooms.length === 0) {
704
748
  return plan.shape.kind === 'groups'
705
749
  ? { groups: [], ...(plan.total ? { total: 0 } : {}) }
@@ -10,8 +10,8 @@ export type MdRuntimeOptions = {
10
10
  authorization?: Authorization;
11
11
  signal?: AbortSignal;
12
12
  recovery?: Recovery;
13
- usableWhenHeld?: readonly string[];
14
13
  build?: string;
14
+ storeOnNeed?: boolean;
15
15
  };
16
16
  export declare function composeRuntime(options: MdRuntimeOptions): ComposedRuntime;
17
17
  //# sourceMappingURL=connection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAsB,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