@agentshouse/mdruntime 0.1.0-c7fd3d0e03135 → 0.1.0-c80bb5b77602a

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 (425) hide show
  1. package/README.md +24 -19
  2. package/dist/acceptance.d.ts +3 -0
  3. package/dist/acceptance.d.ts.map +1 -0
  4. package/dist/acceptance.js +299 -0
  5. package/dist/act-lanes.d.ts +30 -0
  6. package/dist/act-lanes.d.ts.map +1 -0
  7. package/dist/act-lanes.js +225 -0
  8. package/dist/actions.d.ts +26 -0
  9. package/dist/actions.d.ts.map +1 -0
  10. package/dist/actions.js +321 -0
  11. package/dist/adapter.d.ts +254 -129
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +6 -10
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +35 -41
  16. package/dist/authored.d.ts +88 -0
  17. package/dist/authored.d.ts.map +1 -0
  18. package/dist/authored.js +347 -0
  19. package/dist/binary.d.ts +6 -7
  20. package/dist/binary.d.ts.map +1 -1
  21. package/dist/binary.js +10 -3
  22. package/dist/bootstrap.d.ts +30 -11
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +309 -113
  25. package/dist/cell.d.ts +6 -0
  26. package/dist/cell.d.ts.map +1 -0
  27. package/dist/cell.js +9 -0
  28. package/dist/chain.d.ts +12 -0
  29. package/dist/chain.d.ts.map +1 -0
  30. package/dist/chain.js +64 -0
  31. package/dist/change-set.d.ts +13 -16
  32. package/dist/change-set.d.ts.map +1 -1
  33. package/dist/change-set.js +17 -89
  34. package/dist/change.d.ts +36 -1
  35. package/dist/change.d.ts.map +1 -1
  36. package/dist/change.js +17 -3
  37. package/dist/chat-types.d.ts +3 -0
  38. package/dist/chat-types.d.ts.map +1 -0
  39. package/dist/chat-types.js +11 -0
  40. package/dist/client.d.ts +49 -27
  41. package/dist/client.d.ts.map +1 -1
  42. package/dist/client.js +91 -26
  43. package/dist/collection.d.ts +33 -21
  44. package/dist/collection.d.ts.map +1 -1
  45. package/dist/collection.js +54 -288
  46. package/dist/column.d.ts +5 -0
  47. package/dist/column.d.ts.map +1 -0
  48. package/dist/column.js +9 -0
  49. package/dist/compile.d.ts +18 -0
  50. package/dist/compile.d.ts.map +1 -0
  51. package/dist/compile.js +721 -0
  52. package/dist/connection.d.ts +7 -134
  53. package/dist/connection.d.ts.map +1 -1
  54. package/dist/connection.js +111 -3612
  55. package/dist/context.d.ts +2 -0
  56. package/dist/context.d.ts.map +1 -0
  57. package/dist/{chat/context.js → context.js} +2 -5
  58. package/dist/conversation-live.d.ts +149 -0
  59. package/dist/conversation-live.d.ts.map +1 -0
  60. package/dist/conversation-live.js +259 -0
  61. package/dist/conversation-row.d.ts +40 -0
  62. package/dist/conversation-row.d.ts.map +1 -0
  63. package/dist/conversation-row.js +66 -0
  64. package/dist/conversation.d.ts +79 -51
  65. package/dist/conversation.d.ts.map +1 -1
  66. package/dist/conversation.js +1047 -775
  67. package/dist/declaration.d.ts +10 -0
  68. package/dist/declaration.d.ts.map +1 -0
  69. package/dist/declaration.js +24 -0
  70. package/dist/digest.d.ts +7 -0
  71. package/dist/digest.d.ts.map +1 -0
  72. package/dist/digest.js +113 -0
  73. package/dist/discovery.d.ts +12 -0
  74. package/dist/discovery.d.ts.map +1 -0
  75. package/dist/discovery.js +175 -0
  76. package/dist/download.d.ts +6 -0
  77. package/dist/download.d.ts.map +1 -0
  78. package/dist/download.js +42 -0
  79. package/dist/durability.d.ts +21 -4
  80. package/dist/durability.d.ts.map +1 -1
  81. package/dist/durability.js +12 -0
  82. package/dist/entry.d.ts +19 -2
  83. package/dist/entry.d.ts.map +1 -1
  84. package/dist/entry.js +65 -31
  85. package/dist/expectation.d.ts +26 -13
  86. package/dist/expectation.d.ts.map +1 -1
  87. package/dist/expectation.js +72 -19
  88. package/dist/failure.d.ts +3 -0
  89. package/dist/failure.d.ts.map +1 -1
  90. package/dist/failure.js +8 -0
  91. package/dist/figures.d.ts +49 -0
  92. package/dist/figures.d.ts.map +1 -0
  93. package/dist/figures.js +199 -0
  94. package/dist/file.d.ts +2 -19
  95. package/dist/file.d.ts.map +1 -1
  96. package/dist/file.js +8 -122
  97. package/dist/holdings.d.ts +29 -0
  98. package/dist/holdings.d.ts.map +1 -0
  99. package/dist/holdings.js +95 -0
  100. package/dist/host.d.ts +25 -11
  101. package/dist/host.d.ts.map +1 -1
  102. package/dist/host.js +163 -58
  103. package/dist/house-query.d.ts +18 -0
  104. package/dist/house-query.d.ts.map +1 -0
  105. package/dist/house-query.js +54 -0
  106. package/dist/identity.d.ts +0 -2
  107. package/dist/identity.d.ts.map +1 -1
  108. package/dist/identity.js +0 -6
  109. package/dist/index.d.ts +45 -16
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +22 -4
  112. package/dist/install.d.ts +60 -0
  113. package/dist/install.d.ts.map +1 -0
  114. package/dist/install.js +537 -0
  115. package/dist/lifecycle.d.ts +7 -0
  116. package/dist/lifecycle.d.ts.map +1 -0
  117. package/dist/lifecycle.js +290 -0
  118. package/dist/listing.d.ts +60 -0
  119. package/dist/listing.d.ts.map +1 -0
  120. package/dist/listing.js +168 -0
  121. package/dist/live.d.ts +25 -0
  122. package/dist/live.d.ts.map +1 -0
  123. package/dist/live.js +206 -0
  124. package/dist/loaded.d.ts +7 -0
  125. package/dist/loaded.d.ts.map +1 -0
  126. package/dist/loaded.js +46 -0
  127. package/dist/locks.d.ts +7 -0
  128. package/dist/locks.d.ts.map +1 -0
  129. package/dist/locks.js +34 -0
  130. package/dist/lost.d.ts +5 -0
  131. package/dist/lost.d.ts.map +1 -0
  132. package/dist/lost.js +49 -0
  133. package/dist/media.d.ts +24 -0
  134. package/dist/media.d.ts.map +1 -0
  135. package/dist/media.js +352 -0
  136. package/dist/memory.d.ts +22 -9
  137. package/dist/memory.d.ts.map +1 -1
  138. package/dist/memory.js +318 -126
  139. package/dist/messages.d.ts +63 -0
  140. package/dist/messages.d.ts.map +1 -0
  141. package/dist/messages.js +169 -0
  142. package/dist/modal.d.ts +2 -0
  143. package/dist/modal.d.ts.map +1 -0
  144. package/dist/modal.js +11 -0
  145. package/dist/model.d.ts +12 -13
  146. package/dist/model.d.ts.map +1 -1
  147. package/dist/model.js +11 -22
  148. package/dist/models.d.ts +10 -0
  149. package/dist/models.d.ts.map +1 -0
  150. package/dist/models.js +153 -0
  151. package/dist/name.d.ts +3 -0
  152. package/dist/name.d.ts.map +1 -0
  153. package/dist/name.js +118 -0
  154. package/dist/observation.d.ts +40 -10
  155. package/dist/observation.d.ts.map +1 -1
  156. package/dist/observation.js +265 -44
  157. package/dist/online.d.ts +7 -0
  158. package/dist/online.d.ts.map +1 -0
  159. package/dist/online.js +29 -0
  160. package/dist/opened.d.ts +22 -0
  161. package/dist/opened.d.ts.map +1 -0
  162. package/dist/opened.js +107 -0
  163. package/dist/opening.d.ts +4 -0
  164. package/dist/opening.d.ts.map +1 -0
  165. package/dist/opening.js +69 -0
  166. package/dist/outcome.d.ts +65 -10
  167. package/dist/outcome.d.ts.map +1 -1
  168. package/dist/outcome.js +72 -3
  169. package/dist/overlay.d.ts +10 -8
  170. package/dist/overlay.d.ts.map +1 -1
  171. package/dist/overlay.js +121 -182
  172. package/dist/page-metadata.d.ts +8 -0
  173. package/dist/page-metadata.d.ts.map +1 -0
  174. package/dist/page-metadata.js +19 -0
  175. package/dist/parts.d.ts +6 -0
  176. package/dist/parts.d.ts.map +1 -0
  177. package/dist/parts.js +36 -0
  178. package/dist/paths.d.ts +2 -0
  179. package/dist/paths.d.ts.map +1 -1
  180. package/dist/paths.js +26 -0
  181. package/dist/preparation.d.ts +46 -0
  182. package/dist/preparation.d.ts.map +1 -0
  183. package/dist/preparation.js +344 -0
  184. package/dist/presence.d.ts +58 -0
  185. package/dist/presence.d.ts.map +1 -0
  186. package/dist/presence.js +231 -0
  187. package/dist/queries.d.ts +16 -0
  188. package/dist/queries.d.ts.map +1 -0
  189. package/dist/queries.js +287 -0
  190. package/dist/query.d.ts +23 -209
  191. package/dist/query.d.ts.map +1 -1
  192. package/dist/query.js +3 -493
  193. package/dist/{chat/questions.d.ts → questions.d.ts} +6 -7
  194. package/dist/questions.d.ts.map +1 -0
  195. package/dist/{chat/questions.js → questions.js} +14 -8
  196. package/dist/queue.d.ts +40 -0
  197. package/dist/queue.d.ts.map +1 -0
  198. package/dist/queue.js +480 -0
  199. package/dist/reach.d.ts +31 -11
  200. package/dist/reach.d.ts.map +1 -1
  201. package/dist/reach.js +444 -115
  202. package/dist/react.d.ts +22 -5
  203. package/dist/react.d.ts.map +1 -1
  204. package/dist/react.js +35 -15
  205. package/dist/{chat/read.d.ts → read.d.ts} +2 -0
  206. package/dist/read.d.ts.map +1 -0
  207. package/dist/{chat/read.js → read.js} +4 -0
  208. package/dist/readiness.d.ts +33 -21
  209. package/dist/readiness.d.ts.map +1 -1
  210. package/dist/readiness.js +19 -18
  211. package/dist/reads.d.ts +38 -10
  212. package/dist/reads.d.ts.map +1 -1
  213. package/dist/reads.js +163 -83
  214. package/dist/recovery.d.ts +6 -2
  215. package/dist/recovery.d.ts.map +1 -1
  216. package/dist/recovery.js +67 -9
  217. package/dist/reference-forms.d.ts +4 -0
  218. package/dist/reference-forms.d.ts.map +1 -0
  219. package/dist/reference-forms.js +74 -0
  220. package/dist/refresh.d.ts +18 -15
  221. package/dist/refresh.d.ts.map +1 -1
  222. package/dist/refresh.js +145 -60
  223. package/dist/refusal.d.ts +5 -0
  224. package/dist/refusal.d.ts.map +1 -0
  225. package/dist/refusal.js +55 -0
  226. package/dist/replica.d.ts +49 -36
  227. package/dist/replica.d.ts.map +1 -1
  228. package/dist/replica.js +322 -198
  229. package/dist/retried.d.ts +30 -0
  230. package/dist/retried.d.ts.map +1 -0
  231. package/dist/retried.js +72 -0
  232. package/dist/room-draft.d.ts +55 -13
  233. package/dist/room-draft.d.ts.map +1 -1
  234. package/dist/room-draft.js +420 -123
  235. package/dist/room-drafts.d.ts +24 -0
  236. package/dist/room-drafts.d.ts.map +1 -0
  237. package/dist/room-drafts.js +222 -0
  238. package/dist/room-list.d.ts +10 -0
  239. package/dist/room-list.d.ts.map +1 -0
  240. package/dist/room-list.js +45 -0
  241. package/dist/rows.d.ts +32 -31
  242. package/dist/rows.d.ts.map +1 -1
  243. package/dist/rows.js +60 -124
  244. package/dist/running.d.ts +5 -0
  245. package/dist/running.d.ts.map +1 -0
  246. package/dist/running.js +10 -0
  247. package/dist/runtime.d.ts +35 -0
  248. package/dist/runtime.d.ts.map +1 -0
  249. package/dist/runtime.js +1 -0
  250. package/dist/save.d.ts +44 -49
  251. package/dist/save.d.ts.map +1 -1
  252. package/dist/save.js +736 -304
  253. package/dist/saves.d.ts +34 -0
  254. package/dist/saves.d.ts.map +1 -0
  255. package/dist/saves.js +457 -0
  256. package/dist/search.d.ts +12 -95
  257. package/dist/search.d.ts.map +1 -1
  258. package/dist/search.js +10 -266
  259. package/dist/seed.d.ts +11 -2
  260. package/dist/seed.d.ts.map +1 -1
  261. package/dist/seed.js +71 -1
  262. package/dist/shared.d.ts +6 -7
  263. package/dist/shared.d.ts.map +1 -1
  264. package/dist/shared.js +75 -104
  265. package/dist/shown.d.ts +35 -0
  266. package/dist/shown.d.ts.map +1 -0
  267. package/dist/shown.js +326 -0
  268. package/dist/socket/admission.d.ts +7 -0
  269. package/dist/socket/admission.d.ts.map +1 -0
  270. package/dist/socket/admission.js +39 -0
  271. package/dist/socket/answers.d.ts +6 -0
  272. package/dist/socket/answers.d.ts.map +1 -0
  273. package/dist/socket/answers.js +20 -0
  274. package/dist/socket/lanes.d.ts +28 -0
  275. package/dist/socket/lanes.d.ts.map +1 -0
  276. package/dist/socket/lanes.js +103 -0
  277. package/dist/socket/reads.d.ts +10 -0
  278. package/dist/socket/reads.d.ts.map +1 -0
  279. package/dist/socket/reads.js +31 -0
  280. package/dist/socket/session.d.ts +41 -0
  281. package/dist/socket/session.d.ts.map +1 -0
  282. package/dist/socket/session.js +26 -0
  283. package/dist/socket.d.ts +68 -0
  284. package/dist/socket.d.ts.map +1 -0
  285. package/dist/socket.js +165 -0
  286. package/dist/source.d.ts +61 -0
  287. package/dist/source.d.ts.map +1 -0
  288. package/dist/source.js +95 -0
  289. package/dist/status.d.ts +4 -5
  290. package/dist/status.d.ts.map +1 -1
  291. package/dist/status.js +3 -7
  292. package/dist/store/installs.d.ts +30 -0
  293. package/dist/store/installs.d.ts.map +1 -0
  294. package/dist/store/installs.js +40 -0
  295. package/dist/store/readiness.d.ts +11 -0
  296. package/dist/store/readiness.d.ts.map +1 -0
  297. package/dist/store/readiness.js +68 -0
  298. package/dist/store/records.d.ts +227 -0
  299. package/dist/store/records.d.ts.map +1 -0
  300. package/dist/store/records.js +468 -0
  301. package/dist/store/room-held.d.ts +8 -0
  302. package/dist/store/room-held.d.ts.map +1 -0
  303. package/dist/store/room-held.js +17 -0
  304. package/dist/store/rooms-shown.d.ts +8 -0
  305. package/dist/store/rooms-shown.d.ts.map +1 -0
  306. package/dist/store/rooms-shown.js +13 -0
  307. package/dist/store/space.d.ts +11 -0
  308. package/dist/store/space.d.ts.map +1 -0
  309. package/dist/store/space.js +41 -0
  310. package/dist/store/watchers.d.ts +17 -0
  311. package/dist/store/watchers.d.ts.map +1 -0
  312. package/dist/store/watchers.js +56 -0
  313. package/dist/store/writes.d.ts +24 -0
  314. package/dist/store/writes.d.ts.map +1 -0
  315. package/dist/store/writes.js +125 -0
  316. package/dist/store.d.ts +115 -163
  317. package/dist/store.d.ts.map +1 -1
  318. package/dist/store.js +166 -750
  319. package/dist/stored.d.ts +174 -0
  320. package/dist/stored.d.ts.map +1 -0
  321. package/dist/stored.js +785 -0
  322. package/dist/surface.d.ts +94 -0
  323. package/dist/surface.d.ts.map +1 -0
  324. package/dist/surface.js +255 -0
  325. package/dist/sync.d.ts +21 -0
  326. package/dist/sync.d.ts.map +1 -0
  327. package/dist/sync.js +557 -0
  328. package/dist/tables.d.ts +377 -0
  329. package/dist/tables.d.ts.map +1 -0
  330. package/dist/tables.js +500 -0
  331. package/dist/tallies.d.ts +18 -0
  332. package/dist/tallies.d.ts.map +1 -0
  333. package/dist/tallies.js +128 -0
  334. package/dist/transfer.d.ts +0 -5
  335. package/dist/transfer.d.ts.map +1 -1
  336. package/dist/turn.d.ts +5 -3
  337. package/dist/turn.d.ts.map +1 -1
  338. package/dist/turn.js +51 -21
  339. package/dist/validation.d.ts +29 -0
  340. package/dist/validation.d.ts.map +1 -0
  341. package/dist/validation.js +98 -0
  342. package/dist/windows.d.ts +1 -16
  343. package/dist/windows.d.ts.map +1 -1
  344. package/dist/windows.js +2 -79
  345. package/dist/wire.d.ts +106 -11
  346. package/dist/wire.d.ts.map +1 -1
  347. package/dist/wire.js +41 -13
  348. package/package.json +19 -19
  349. package/AGENTS.md +0 -299
  350. package/dist/acquisition.d.ts +0 -14
  351. package/dist/acquisition.d.ts.map +0 -1
  352. package/dist/acquisition.js +0 -24
  353. package/dist/attempt.d.ts +0 -16
  354. package/dist/attempt.d.ts.map +0 -1
  355. package/dist/attempt.js +0 -70
  356. package/dist/chat/acts.d.ts +0 -33
  357. package/dist/chat/acts.d.ts.map +0 -1
  358. package/dist/chat/acts.js +0 -36
  359. package/dist/chat/context.d.ts +0 -3
  360. package/dist/chat/context.d.ts.map +0 -1
  361. package/dist/chat/earlier.d.ts +0 -10
  362. package/dist/chat/earlier.d.ts.map +0 -1
  363. package/dist/chat/earlier.js +0 -54
  364. package/dist/chat/input.d.ts +0 -9
  365. package/dist/chat/input.d.ts.map +0 -1
  366. package/dist/chat/input.js +0 -99
  367. package/dist/chat/kit.d.ts +0 -61
  368. package/dist/chat/kit.d.ts.map +0 -1
  369. package/dist/chat/kit.js +0 -123
  370. package/dist/chat/lasting.d.ts +0 -6
  371. package/dist/chat/lasting.d.ts.map +0 -1
  372. package/dist/chat/lasting.js +0 -19
  373. package/dist/chat/list.d.ts +0 -27
  374. package/dist/chat/list.d.ts.map +0 -1
  375. package/dist/chat/list.js +0 -99
  376. package/dist/chat/markdown.d.ts +0 -20
  377. package/dist/chat/markdown.d.ts.map +0 -1
  378. package/dist/chat/markdown.js +0 -188
  379. package/dist/chat/message.d.ts +0 -6
  380. package/dist/chat/message.d.ts.map +0 -1
  381. package/dist/chat/message.js +0 -192
  382. package/dist/chat/messages.d.ts +0 -22
  383. package/dist/chat/messages.d.ts.map +0 -1
  384. package/dist/chat/messages.js +0 -155
  385. package/dist/chat/name.d.ts +0 -6
  386. package/dist/chat/name.d.ts.map +0 -1
  387. package/dist/chat/name.js +0 -37
  388. package/dist/chat/opened.d.ts +0 -11
  389. package/dist/chat/opened.d.ts.map +0 -1
  390. package/dist/chat/opened.js +0 -17
  391. package/dist/chat/overlay.d.ts +0 -31
  392. package/dist/chat/overlay.d.ts.map +0 -1
  393. package/dist/chat/overlay.js +0 -97
  394. package/dist/chat/parts.d.ts +0 -57
  395. package/dist/chat/parts.d.ts.map +0 -1
  396. package/dist/chat/parts.js +0 -119
  397. package/dist/chat/process.d.ts +0 -20
  398. package/dist/chat/process.d.ts.map +0 -1
  399. package/dist/chat/process.js +0 -32
  400. package/dist/chat/provider.d.ts +0 -63
  401. package/dist/chat/provider.d.ts.map +0 -1
  402. package/dist/chat/provider.js +0 -635
  403. package/dist/chat/question.d.ts +0 -9
  404. package/dist/chat/question.d.ts.map +0 -1
  405. package/dist/chat/question.js +0 -69
  406. package/dist/chat/questions.d.ts.map +0 -1
  407. package/dist/chat/read.d.ts.map +0 -1
  408. package/dist/chat/ready.d.ts +0 -34
  409. package/dist/chat/ready.d.ts.map +0 -1
  410. package/dist/chat/ready.js +0 -91
  411. package/dist/chat/style.d.ts +0 -4
  412. package/dist/chat/style.d.ts.map +0 -1
  413. package/dist/chat/style.js +0 -302
  414. package/dist/chat.d.ts +0 -14
  415. package/dist/chat.d.ts.map +0 -1
  416. package/dist/chat.js +0 -8
  417. package/dist/fence.d.ts +0 -6
  418. package/dist/fence.d.ts.map +0 -1
  419. package/dist/fence.js +0 -10
  420. package/dist/log.d.ts +0 -5
  421. package/dist/log.d.ts.map +0 -1
  422. package/dist/log.js +0 -14
  423. package/dist/read-side.d.ts +0 -25
  424. package/dist/read-side.d.ts.map +0 -1
  425. package/dist/read-side.js +0 -767
@@ -1,11 +1,31 @@
1
- import { checkDocument, parseFrontmatter, references, sectionReferences, target, parse, resolves, validate, VERSION, } from '@agentshouse/mdmodel';
1
+ import { definitionAt, parse, VERSION, } from '@agentshouse/mdmodel';
2
2
  import { beneath, normalize } from './paths.js';
3
- import { sameTyping } from './model.js';
4
- import { differing, patched, shared } from './shared.js';
5
- import { 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 NO_TYPES = { types: {} };
8
- function selected(composition, path) {
6
+ const typesPrinted = new WeakMap();
7
+ export function typesPrint(types) {
8
+ let print = typesPrinted.get(types);
9
+ if (print === undefined) {
10
+ print = hashed(JSON.stringify(types)).toString(36);
11
+ typesPrinted.set(types, print);
12
+ }
13
+ return print;
14
+ }
15
+ function modelPrint(model) {
16
+ return model.status === 'unavailable' ? '' : typesPrint(model.types);
17
+ }
18
+ export function composedOf(composition) {
19
+ const { model, selection } = composition;
20
+ return {
21
+ composition,
22
+ fingerprint: JSON.stringify([
23
+ modelPrint(model),
24
+ selection === null ? null : [selection.roots, modelPrint(selection.model)],
25
+ ]),
26
+ };
27
+ }
28
+ export function selected(composition, path) {
9
29
  return (composition.selection !== null &&
10
30
  composition.selection.roots.some((root) => beneath(root, path)));
11
31
  }
@@ -14,307 +34,53 @@ export function governing(composition, path) {
14
34
  ? composition.selection.model
15
35
  : composition.model;
16
36
  }
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 = patched(held.base, held.added);
23
- held.base = kept;
24
- held.added = new Map();
25
- return patched(kept, [], differing(previous.text, text));
37
+ function definitionsUnder(composition, path, typedPaths, typesOf) {
38
+ const types = typesOf(governing(composition, path));
39
+ return types === null ? () => undefined : definitionAt({ types }, path, typedPaths);
26
40
  }
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;
41
+ export function definitionsAt(composition, path) {
42
+ return definitionsUnder(composition, path, composition.typedPaths, (model) => model.status === 'unavailable' ? null : model.types);
34
43
  }
35
- export function collectionOf(text, composition, previous) {
36
- const parsed = {
37
- base: previous === undefined ? shared({}) : carried(previous, text),
38
- added: new Map(),
39
- };
40
- const collection = {
44
+ export function definitionsIn(room, path, typedPaths) {
45
+ return definitionsUnder({ model: room.model, selection: room.typedSelection }, path, typedPaths, ({ types }) => types === null ? null : Object.fromEntries(types.map((type) => [type.name, type])));
46
+ }
47
+ export function collectionOf(text, composition) {
48
+ const parsed = new Map();
49
+ return {
41
50
  text,
42
51
  composition,
43
52
  document(path) {
44
- const held = cachedIn(collection, path);
45
- if (held !== undefined)
46
- return held ?? undefined;
53
+ if (parsed.has(path))
54
+ return parsed.get(path) ?? undefined;
47
55
  const content = text[path];
48
56
  if (content === undefined)
49
57
  return undefined;
50
- const read = parse(content, path);
51
- parsed.added.set(path, read.ok ? read.document : null);
58
+ const read = parse(content, path, definitionsAt(composition, path));
59
+ parsed.set(path, read.ok ? read.document : null);
52
60
  return read.ok ? read.document : undefined;
53
61
  },
54
62
  };
55
- parsedIn.set(collection, parsed);
56
- return collection;
57
- }
58
- export function passingFrontmatter(collection, path) {
59
- const held = cachedIn(collection, path);
60
- if (held !== undefined)
61
- return held ?? undefined;
62
- const content = collection.text[path];
63
- if (content === undefined)
64
- return undefined;
65
- const read = parseFrontmatter(content, path);
66
- return read.ok ? read.frontmatter : undefined;
67
63
  }
68
64
  export function* documentsOf(collection) {
69
- for (const path of Object.keys(collection.text).sort()) {
70
- const held = cachedIn(collection, path);
71
- if (held === null)
72
- continue;
73
- if (held !== undefined) {
74
- yield [path, held];
75
- continue;
65
+ const paths = yield* sortedKeys(collection.text);
66
+ return (function* () {
67
+ for (const path of paths) {
68
+ const document = collection.document(path);
69
+ if (document !== undefined)
70
+ yield [path, document];
76
71
  }
77
- const read = parse(collection.text[path], path);
78
- if (read.ok)
79
- yield [path, read.document];
80
- }
81
- }
82
- export function unreadable(text, previous) {
83
- const paths = previous === undefined
84
- ? Object.keys(text)
85
- : [...differing(previous, text)].filter((path) => text[path] !== undefined);
86
- for (const path of paths.sort()) {
87
- const read = parse(text[path], path);
88
- if (!read.ok)
89
- return { kind: 'refused', refusal: read.refusal };
90
- }
91
- return null;
72
+ })();
92
73
  }
93
74
  export function validRoot(root) {
94
75
  return typeof root === 'string' && normalize(root) === root;
95
76
  }
96
- function validateAgainst(documents, binaryTargets, model) {
97
- if (model.status === 'unavailable') {
98
- const typed = Object.entries(documents).find(([, content]) => {
99
- const parsed = parse(content);
100
- return parsed.ok && parsed.document.type !== undefined && parsed.document.type !== 'any';
101
- });
102
- if (typed !== undefined)
103
- return { verdict: 'refuse', rule: 'model-unavailable', file: typed[0] };
104
- }
105
- return validate(documents, { binaryTargets }, model.status === 'unavailable' ? NO_TYPES : { types: model.types });
106
- }
107
- export function validateCollection(text, binaryTargets, composition) {
108
- const collection = {};
109
- const selection = {};
110
- for (const [path, content] of Object.entries(text)) {
111
- if (selected(composition, path))
112
- selection[path] = content;
113
- else
114
- collection[path] = content;
115
- }
116
- const verdicts = [
117
- validateAgainst(collection, binaryTargets.filter((path) => !selected(composition, path)), composition.model),
118
- ];
119
- if (composition.selection !== null) {
120
- verdicts.push(validateAgainst(selection, binaryTargets.filter((path) => selected(composition, path)), composition.selection.model));
121
- }
122
- const refusals = verdicts.filter((verdict) => verdict.verdict === 'refuse');
123
- if (refusals.length === 0)
124
- return verdicts[0];
125
- return refusals.find((refusal) => refusal.rule !== 'model-unavailable') ?? refusals[0];
126
- }
127
- const referrersOf = new WeakMap();
128
- function typing(left, right) {
129
- return (sameTyping(left.model, right.model) &&
130
- (left.selection === null || right.selection === null
131
- ? left.selection === right.selection
132
- : sameTyping(left.selection.model, right.selection.model)) &&
133
- JSON.stringify(left.selection?.roots ?? null) === JSON.stringify(right.selection?.roots ?? null));
134
- }
135
- function declared(content) {
136
- if (content === undefined)
137
- return undefined;
138
- const read = parseFrontmatter(content);
139
- return read.ok ? (read.frontmatter.type ?? 'any') : undefined;
140
- }
141
- function typedIn(content) {
142
- const type = declared(content);
143
- return type !== undefined && type !== 'any';
144
- }
145
- function modelOf(composition, path) {
146
- const model = governing(composition, path);
147
- return model.status === 'unavailable' ? null : { types: model.types };
148
- }
149
- function checked(path, content, composition) {
150
- return checkDocument(path, content, modelOf(composition, path) ?? NO_TYPES);
77
+ export const UNTYPED = 'any';
78
+ export function textType(read) {
79
+ return read.ok ? (read.document.type ?? UNTYPED) : undefined;
151
80
  }
152
- function targetsOf(check) {
153
- if (!check.ok)
154
- return [];
155
- return [...new Set(check.references.flatMap(({ target }) => (target === null ? [] : [target])))];
156
- }
157
- function referencedBy(path, content, composition) {
158
- const model = modelOf(composition, path);
159
- if (model === null)
160
- return [];
161
- const read = parseFrontmatter(content, path);
162
- const type = read.ok ? read.frontmatter.type : undefined;
163
- if (!read.ok || type === undefined || !Object.hasOwn(model.types, type))
164
- return [];
165
- const definition = model.types[type];
166
- return [
167
- ...new Set([
168
- ...references(read.frontmatter, definition).flatMap(({ value }) => {
169
- const found = target(path, value);
170
- return found === null ? [] : [found];
171
- }),
172
- ...sectionReferences(path, content, definition).flatMap(({ target }) => target === null ? [] : [target]),
173
- ]),
174
- ];
175
- }
176
- function reindexed(index, changed) {
177
- const referrers = new Map();
178
- const touch = (target) => {
179
- let held = referrers.get(target);
180
- if (held === undefined) {
181
- held = new Set(Object.hasOwn(index.referrers, target) ? index.referrers[target] : []);
182
- referrers.set(target, held);
183
- }
184
- return held;
185
- };
186
- for (const [path, found] of changed) {
187
- const before = Object.hasOwn(index.targets, path) ? index.targets[path] : [];
188
- for (const target of before)
189
- touch(target).delete(path);
190
- for (const target of found)
191
- touch(target).add(path);
192
- }
193
- const emptied = [...referrers].filter(([, held]) => held.size === 0).map(([target]) => target);
194
- return {
195
- composition: index.composition,
196
- targets: patched(index.targets, [...changed].filter(([, found]) => found.length > 0), [...changed].filter(([, found]) => found.length === 0).map(([path]) => path)),
197
- referrers: patched(index.referrers, [...referrers]
198
- .filter(([, held]) => held.size > 0)
199
- .map(([target, held]) => [target, [...held]]), emptied),
200
- };
201
- }
202
- function heldIndex(held, composition) {
203
- const index = referrersOf.get(held.text);
204
- return index !== undefined && typing(index.composition, composition) ? index : null;
205
- }
206
- const indexing = new WeakMap();
207
- export function indexReferrers(held, composition) {
208
- if (heldIndex(held, composition) !== null)
209
- return;
210
- const running = indexing.get(held.text);
211
- if (running !== undefined)
212
- return running;
213
- const targets = new Map();
214
- const referrers = new Map();
215
- const filled = inUnits(Object.keys(held.text), (path) => {
216
- const content = held.text[path];
217
- const found = referencedBy(path, content, composition);
218
- if (found.length > 0)
219
- targets.set(path, found);
220
- for (const target of found)
221
- referrers.set(target, [...(referrers.get(target) ?? []), path]);
222
- return ROW_WEIGHT + content.length;
223
- });
224
- const indexed = () => {
225
- referrersOf.set(held.text, {
226
- composition,
227
- targets: patched(shared({}), targets),
228
- referrers: patched(shared({}), referrers),
229
- });
230
- };
231
- if (!(filled instanceof Promise))
232
- return indexed();
233
- const building = filled.then(indexed).finally(() => indexing.delete(held.text));
234
- indexing.set(held.text, building);
235
- return building;
236
- }
237
- export function referencesIndexed(held, composition) {
238
- return heldIndex(held, composition) !== null;
239
- }
240
- export function referring(held, composition, targets) {
241
- const index = heldIndex(held, composition);
242
- if (index === null)
243
- return null;
244
- const found = new Set();
245
- for (const target of targets) {
246
- if (!Object.hasOwn(index.referrers, target))
247
- continue;
248
- for (const file of index.referrers[target])
249
- found.add(file);
250
- }
251
- return found;
81
+ export function typedText(read) {
82
+ return (textType(read) ?? UNTYPED) !== UNTYPED;
252
83
  }
253
84
  export function available(composition) {
254
- return (composition.model.status !== 'unavailable' &&
255
- (composition.selection === null || composition.selection.model.status !== 'unavailable'));
256
- }
257
- export function changedCleanly(next, previous, composition) {
258
- if (!typing(previous.composition, composition))
259
- return false;
260
- const paths = new Set([
261
- ...differing(previous.text, next.text),
262
- ...differing(previous.binaries, next.binaries, () => true),
263
- ]);
264
- const binary = (path) => Object.hasOwn(next.binaries, path);
265
- const within = (file) => (path) => selected(composition, path) === selected(composition, file);
266
- const reaching = (file, check) => {
267
- if (!check.ok)
268
- return false;
269
- const part = within(file);
270
- return check.references.every((reference) => resolves(reference, (path) => (part(path) ? declared(next.text[path]) : undefined), (path) => part(path) && binary(path)));
271
- };
272
- const changedTargets = new Map();
273
- const shifted = [];
274
- for (const path of paths) {
275
- const now = next.text[path];
276
- const was = previous.text[path];
277
- const modeled = modelOf(composition, path) !== null;
278
- if ((now === undefined) !== (was === undefined) ||
279
- declared(now) !== declared(was) ||
280
- binary(path) !== Object.hasOwn(previous.binaries, path)) {
281
- shifted.push(path);
282
- }
283
- if (!modeled && typedIn(was) && !typedIn(now))
284
- return false;
285
- if (now === undefined) {
286
- if (modeled)
287
- changedTargets.set(path, []);
288
- continue;
289
- }
290
- if (binary(path))
291
- return false;
292
- if (!modeled) {
293
- if (declared(now) === undefined)
294
- return false;
295
- if (!typedIn(now) && !checked(path, now, composition).ok)
296
- return false;
297
- continue;
298
- }
299
- const check = checked(path, now, composition);
300
- if (!reaching(path, check))
301
- return false;
302
- changedTargets.set(path, targetsOf(check));
303
- }
304
- const index = heldIndex(previous, composition);
305
- if (index === null && shifted.length > 0)
306
- return false;
307
- for (const target of shifted) {
308
- const files = index !== null && Object.hasOwn(index.referrers, target) ? index.referrers[target] : [];
309
- for (const file of files) {
310
- if (paths.has(file))
311
- continue;
312
- if (!reaching(file, checked(file, next.text[file], composition)))
313
- return false;
314
- }
315
- }
316
- if (index !== null) {
317
- referrersOf.set(next.text, changedTargets.size === 0 ? index : reindexed(index, changedTargets));
318
- }
319
- return true;
85
+ return composition.model.status !== 'unavailable';
320
86
  }
@@ -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
+ }
@@ -0,0 +1,18 @@
1
+ import { sql } from '@agentshouse/mdmodel';
2
+ import { type Composition } from './collection.js';
3
+ import type { Plan, QueryRows } from './query.js';
4
+ import type { Connection } from './tables.js';
5
+ export type QueryRoom = {
6
+ readonly locator: string;
7
+ readonly key: number;
8
+ readonly composition?: Composition;
9
+ };
10
+ type Fragment = sql.Fragment;
11
+ export declare const VISIBLE: (alias: string) => string;
12
+ export declare function within(alias: string, path: string): Fragment;
13
+ export type QueryAnswer = QueryRows & {
14
+ readonly more?: string;
15
+ };
16
+ export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null): QueryAnswer;
17
+ export {};
18
+ //# sourceMappingURL=compile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,GAAG,EAQJ,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE3E,OAAO,KAAK,EAAE,IAAI,EAAuC,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvF,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAG1D,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;CACpC,CAAC;AAEF,KAAK,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;AAI7B,eAAO,MAAM,OAAO,UAAW,MAAM,KAAG,MAAyD,CAAC;AAalG,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAM5D;AAydD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AA4ZjE,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"}