@jam-overture/loom 0.1.0 → 0.3.0

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 (414) hide show
  1. package/README.md +3 -1
  2. package/dist/application/application.d.ts +109 -0
  3. package/dist/application/application.js +97 -0
  4. package/dist/application/memory.d.ts +20 -0
  5. package/dist/application/memory.js +79 -0
  6. package/dist/application/store.d.ts +101 -0
  7. package/dist/application/store.js +25 -0
  8. package/dist/audience/audience.d.ts +36 -0
  9. package/dist/audience/audience.js +41 -0
  10. package/dist/audience/compose.d.ts +112 -0
  11. package/dist/audience/compose.js +134 -0
  12. package/dist/audience/memory.d.ts +14 -0
  13. package/dist/audience/memory.js +71 -0
  14. package/dist/audience/overlay-store.d.ts +343 -0
  15. package/dist/audience/overlay-store.js +217 -0
  16. package/dist/audience/rule.d.ts +121 -0
  17. package/dist/audience/rule.js +78 -0
  18. package/dist/cli/index.d.ts +3 -4
  19. package/dist/cli/index.js +3 -4
  20. package/dist/cli/templates.js +19 -0
  21. package/dist/data/adapter.d.ts +9 -1
  22. package/dist/data/adapter.js +2 -0
  23. package/dist/data/plan.js +0 -0
  24. package/dist/data/resolution.d.ts +23 -1
  25. package/dist/data/resolve.d.ts +31 -4
  26. package/dist/data/resolve.js +11 -3
  27. package/dist/ids.d.ts +10 -0
  28. package/dist/ids.js +11 -1
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.js +1 -0
  31. package/dist/interpretation/anthropic.d.ts +1 -1
  32. package/dist/interpretation/anthropic.js +2 -22
  33. package/dist/interpretation/client.d.ts +1 -1
  34. package/dist/interpretation/materialize.js +67 -22
  35. package/dist/interpretation/openai-compatible.d.ts +36 -0
  36. package/dist/interpretation/openai-compatible.js +79 -0
  37. package/dist/interpretation/status.d.ts +19 -0
  38. package/dist/interpretation/status.js +26 -0
  39. package/dist/live/index.d.ts +73 -0
  40. package/dist/live/index.js +73 -0
  41. package/dist/live/pages.d.ts +187 -0
  42. package/dist/live/pages.js +161 -0
  43. package/dist/live/pull.d.ts +147 -0
  44. package/dist/live/pull.js +398 -0
  45. package/dist/live/pulling.d.ts +79 -0
  46. package/dist/live/pulling.js +117 -0
  47. package/dist/live/window.d.ts +129 -0
  48. package/dist/live/window.js +132 -0
  49. package/dist/patch.d.ts +54 -0
  50. package/dist/patch.js +44 -0
  51. package/dist/project/closing.d.ts +51 -0
  52. package/dist/project/closing.js +53 -0
  53. package/dist/project/memory.d.ts +20 -0
  54. package/dist/project/memory.js +97 -0
  55. package/dist/project/project.d.ts +90 -0
  56. package/dist/project/project.js +91 -0
  57. package/dist/project/store.d.ts +135 -0
  58. package/dist/project/store.js +41 -0
  59. package/dist/registered.d.ts +64 -0
  60. package/dist/registered.js +118 -0
  61. package/dist/render/addressed.d.ts +35 -0
  62. package/dist/render/addressed.js +79 -0
  63. package/dist/render/behaviour-adjust.d.ts +11 -19
  64. package/dist/render/behaviour-adjust.js +75 -21
  65. package/dist/render/behaviour-present.d.ts +8 -0
  66. package/dist/render/behaviour-present.js +57 -6
  67. package/dist/render/behaviour.d.ts +98 -17
  68. package/dist/render/behaviour.js +91 -26
  69. package/dist/render/control-name.d.ts +68 -0
  70. package/dist/render/control-name.js +37 -0
  71. package/dist/render/diagnostics.d.ts +72 -0
  72. package/dist/render/diagnostics.js +7 -0
  73. package/dist/render/document-theme.d.ts +70 -0
  74. package/dist/render/document-theme.js +139 -0
  75. package/dist/render/editable.d.ts +15 -1
  76. package/dist/render/editable.js +13 -1
  77. package/dist/render/expected.d.ts +98 -0
  78. package/dist/render/expected.js +88 -0
  79. package/dist/render/index.d.ts +4 -0
  80. package/dist/render/index.js +4 -0
  81. package/dist/render/reads.d.ts +11 -0
  82. package/dist/render/reads.js +12 -1
  83. package/dist/render/render.d.ts +11 -0
  84. package/dist/render/render.js +294 -53
  85. package/dist/render/request.d.ts +8 -1
  86. package/dist/render/request.js +1 -0
  87. package/dist/render/slots.d.ts +52 -0
  88. package/dist/render/slots.js +24 -0
  89. package/dist/render/theme.d.ts +54 -1
  90. package/dist/render/theme.js +23 -1
  91. package/dist/render/unshown.d.ts +152 -0
  92. package/dist/render/unshown.js +80 -0
  93. package/dist/runtime/analysis.d.ts +94 -9
  94. package/dist/runtime/analysis.js +54 -9
  95. package/dist/runtime/assessment.d.ts +36 -2
  96. package/dist/runtime/assessment.js +27 -2
  97. package/dist/runtime/auto-apply-ceiling.d.ts +54 -0
  98. package/dist/runtime/auto-apply-ceiling.js +66 -0
  99. package/dist/runtime/checks.d.ts +148 -0
  100. package/dist/runtime/checks.js +112 -0
  101. package/dist/runtime/disposition.d.ts +96 -0
  102. package/dist/runtime/disposition.js +46 -0
  103. package/dist/runtime/gate.js +91 -10
  104. package/dist/runtime/index.d.ts +4 -0
  105. package/dist/runtime/index.js +4 -0
  106. package/dist/runtime/irreversibility.d.ts +64 -0
  107. package/dist/runtime/irreversibility.js +45 -0
  108. package/dist/runtime/nesting.d.ts +13 -1
  109. package/dist/runtime/nesting.js +41 -24
  110. package/dist/runtime/pipeline.d.ts +43 -0
  111. package/dist/runtime/pipeline.js +10 -2
  112. package/dist/runtime/policy-change.d.ts +93 -0
  113. package/dist/runtime/policy-change.js +305 -0
  114. package/dist/runtime/policy-log.d.ts +406 -0
  115. package/dist/runtime/policy-log.js +285 -0
  116. package/dist/runtime/policy.d.ts +8 -6
  117. package/dist/runtime/policy.js +5 -2
  118. package/dist/runtime/repointing.js +0 -0
  119. package/dist/runtime/reversibility.d.ts +11 -9
  120. package/dist/runtime/stakes.d.ts +129 -1
  121. package/dist/runtime/stakes.js +240 -26
  122. package/dist/runtime/vocabulary.d.ts +164 -7
  123. package/dist/runtime/vocabulary.js +181 -8
  124. package/dist/sdk/audit.d.ts +174 -3
  125. package/dist/sdk/audit.js +176 -17
  126. package/dist/sdk/catalogue.d.ts +9 -1
  127. package/dist/sdk/conformance.d.ts +37 -3
  128. package/dist/sdk/conformance.js +25 -4
  129. package/dist/sdk/definition.d.ts +129 -5
  130. package/dist/sdk/definition.js +66 -0
  131. package/dist/sdk/registry.d.ts +45 -2
  132. package/dist/sdk/registry.js +102 -1
  133. package/dist/signals/acted.contract.d.ts +21 -0
  134. package/dist/signals/acted.contract.js +236 -0
  135. package/dist/signals/acted.d.ts +359 -0
  136. package/dist/signals/acted.js +135 -0
  137. package/dist/signals/action-change.d.ts +507 -0
  138. package/dist/signals/action-change.js +265 -0
  139. package/dist/signals/action.d.ts +331 -0
  140. package/dist/signals/action.js +182 -0
  141. package/dist/signals/agenda.d.ts +585 -0
  142. package/dist/signals/agenda.js +295 -0
  143. package/dist/signals/applied-window.contract.d.ts +23 -0
  144. package/dist/signals/applied-window.contract.js +160 -0
  145. package/dist/signals/arrivals.contract.d.ts +21 -0
  146. package/dist/signals/arrivals.contract.js +180 -0
  147. package/dist/signals/arrivals.d.ts +375 -0
  148. package/dist/signals/arrivals.js +254 -0
  149. package/dist/signals/arriving.d.ts +210 -0
  150. package/dist/signals/arriving.js +133 -0
  151. package/dist/signals/audiences.d.ts +528 -0
  152. package/dist/signals/audiences.js +255 -0
  153. package/dist/signals/broadcast.d.ts +33 -17
  154. package/dist/signals/broadcast.js +255 -32
  155. package/dist/signals/change.d.ts +378 -0
  156. package/dist/signals/change.js +327 -0
  157. package/dist/signals/collect.d.ts +169 -34
  158. package/dist/signals/collect.js +186 -38
  159. package/dist/signals/conversion.d.ts +348 -0
  160. package/dist/signals/conversion.js +235 -0
  161. package/dist/signals/copy-change.d.ts +553 -0
  162. package/dist/signals/copy-change.js +377 -0
  163. package/dist/signals/copy.d.ts +337 -0
  164. package/dist/signals/copy.js +211 -0
  165. package/dist/signals/correlated.contract.d.ts +24 -0
  166. package/dist/signals/correlated.contract.js +94 -0
  167. package/dist/signals/counters.d.ts +97 -0
  168. package/dist/signals/counters.js +160 -0
  169. package/dist/signals/deliver.d.ts +23 -4
  170. package/dist/signals/deliver.js +34 -6
  171. package/dist/signals/deployment-change.d.ts +395 -0
  172. package/dist/signals/deployment-change.js +309 -0
  173. package/dist/signals/deployment.d.ts +278 -0
  174. package/dist/signals/deployment.js +178 -0
  175. package/dist/signals/door.d.ts +114 -0
  176. package/dist/signals/door.js +77 -0
  177. package/dist/signals/expire.d.ts +192 -0
  178. package/dist/signals/expire.js +213 -0
  179. package/dist/signals/fold.d.ts +10 -0
  180. package/dist/signals/fold.js +5 -1
  181. package/dist/signals/form-action.d.ts +302 -0
  182. package/dist/signals/form-action.js +169 -0
  183. package/dist/signals/form-copy.d.ts +523 -0
  184. package/dist/signals/form-copy.js +346 -0
  185. package/dist/signals/forms.d.ts +247 -0
  186. package/dist/signals/forms.js +147 -0
  187. package/dist/signals/frontier.d.ts +268 -0
  188. package/dist/signals/frontier.js +145 -0
  189. package/dist/signals/funnel-change.d.ts +548 -0
  190. package/dist/signals/funnel-change.js +361 -0
  191. package/dist/signals/funnel-hours.contract.d.ts +21 -0
  192. package/dist/signals/funnel-hours.contract.js +221 -0
  193. package/dist/signals/funnel-hours.d.ts +293 -0
  194. package/dist/signals/funnel-hours.js +99 -0
  195. package/dist/signals/funnel.d.ts +592 -0
  196. package/dist/signals/funnel.js +231 -0
  197. package/dist/signals/health.d.ts +694 -0
  198. package/dist/signals/health.js +573 -0
  199. package/dist/signals/index.d.ts +60 -0
  200. package/dist/signals/index.js +60 -0
  201. package/dist/signals/ingest.d.ts +56 -1
  202. package/dist/signals/ingest.js +91 -1
  203. package/dist/signals/inside.d.ts +190 -0
  204. package/dist/signals/inside.js +263 -0
  205. package/dist/signals/join.d.ts +56 -0
  206. package/dist/signals/join.js +60 -0
  207. package/dist/signals/journal.d.ts +123 -9
  208. package/dist/signals/kept.contract.d.ts +22 -0
  209. package/dist/signals/kept.contract.js +111 -0
  210. package/dist/signals/kinds.d.ts +8 -6
  211. package/dist/signals/kinds.js +14 -6
  212. package/dist/signals/library-action.d.ts +430 -0
  213. package/dist/signals/library-action.js +336 -0
  214. package/dist/signals/library-agenda-change.d.ts +324 -0
  215. package/dist/signals/library-agenda-change.js +199 -0
  216. package/dist/signals/library-agenda.d.ts +258 -0
  217. package/dist/signals/library-agenda.js +167 -0
  218. package/dist/signals/library-change.d.ts +477 -0
  219. package/dist/signals/library-change.js +335 -0
  220. package/dist/signals/library-copy-change.d.ts +498 -0
  221. package/dist/signals/library-copy-change.js +476 -0
  222. package/dist/signals/library-pace.d.ts +319 -0
  223. package/dist/signals/library-pace.js +305 -0
  224. package/dist/signals/library-reach-change.d.ts +646 -0
  225. package/dist/signals/library-reach-change.js +542 -0
  226. package/dist/signals/library-reach.d.ts +377 -0
  227. package/dist/signals/library-reach.js +227 -0
  228. package/dist/signals/library-senders-change.d.ts +457 -0
  229. package/dist/signals/library-senders-change.js +367 -0
  230. package/dist/signals/library-senders-reach-change.d.ts +486 -0
  231. package/dist/signals/library-senders-reach-change.js +538 -0
  232. package/dist/signals/library-senders-reach.d.ts +340 -0
  233. package/dist/signals/library-senders-reach.js +252 -0
  234. package/dist/signals/library-senders.d.ts +271 -0
  235. package/dist/signals/library-senders.js +180 -0
  236. package/dist/signals/library-word-reach-change.d.ts +567 -0
  237. package/dist/signals/library-word-reach-change.js +564 -0
  238. package/dist/signals/library.d.ts +306 -0
  239. package/dist/signals/library.js +178 -0
  240. package/dist/signals/memory.d.ts +9 -0
  241. package/dist/signals/memory.js +246 -14
  242. package/dist/signals/migrate.d.ts +20 -4
  243. package/dist/signals/migrate.js +269 -8
  244. package/dist/signals/notice.d.ts +389 -0
  245. package/dist/signals/notice.js +250 -0
  246. package/dist/signals/pace-change.d.ts +501 -0
  247. package/dist/signals/pace-change.js +310 -0
  248. package/dist/signals/pace.d.ts +296 -0
  249. package/dist/signals/pace.js +291 -0
  250. package/dist/signals/page-views.d.ts +365 -0
  251. package/dist/signals/page-views.js +218 -0
  252. package/dist/signals/part-pace.d.ts +378 -0
  253. package/dist/signals/part-pace.js +333 -0
  254. package/dist/signals/parts.d.ts +354 -0
  255. package/dist/signals/parts.js +232 -0
  256. package/dist/signals/postgres.d.ts +16 -2
  257. package/dist/signals/postgres.js +753 -76
  258. package/dist/signals/progress.d.ts +212 -0
  259. package/dist/signals/progress.js +150 -0
  260. package/dist/signals/ratios.d.ts +108 -0
  261. package/dist/signals/ratios.js +40 -0
  262. package/dist/signals/reach.d.ts +309 -0
  263. package/dist/signals/reach.js +93 -0
  264. package/dist/signals/readable.d.ts +34 -0
  265. package/dist/signals/readable.js +34 -0
  266. package/dist/signals/readership.d.ts +381 -0
  267. package/dist/signals/readership.js +308 -0
  268. package/dist/signals/region-pages.d.ts +173 -0
  269. package/dist/signals/region-pages.js +62 -0
  270. package/dist/signals/region.d.ts +287 -0
  271. package/dist/signals/region.js +198 -0
  272. package/dist/signals/retention.d.ts +163 -0
  273. package/dist/signals/retention.js +75 -0
  274. package/dist/signals/rhythm.d.ts +302 -0
  275. package/dist/signals/rhythm.js +262 -0
  276. package/dist/signals/rollup.d.ts +194 -4
  277. package/dist/signals/rollup.js +0 -0
  278. package/dist/signals/schema.d.ts +1069 -1
  279. package/dist/signals/schema.js +393 -3
  280. package/dist/signals/signal.d.ts +237 -11
  281. package/dist/signals/signal.js +70 -10
  282. package/dist/signals/silence-census.d.ts +205 -0
  283. package/dist/signals/silence-census.js +87 -0
  284. package/dist/signals/silences.d.ts +1147 -0
  285. package/dist/signals/silences.js +996 -0
  286. package/dist/signals/subtrees.d.ts +123 -0
  287. package/dist/signals/subtrees.js +102 -0
  288. package/dist/signals/tally.d.ts +262 -12
  289. package/dist/signals/unread.d.ts +292 -0
  290. package/dist/signals/unread.js +137 -0
  291. package/dist/signals/window-agenda.d.ts +276 -0
  292. package/dist/signals/window-agenda.js +83 -0
  293. package/dist/signals/window-figures.d.ts +148 -0
  294. package/dist/signals/window-figures.js +42 -0
  295. package/dist/signals/window-funnels.d.ts +88 -0
  296. package/dist/signals/window-funnels.js +47 -0
  297. package/dist/signals/window.d.ts +866 -0
  298. package/dist/signals/window.js +693 -0
  299. package/dist/signals/words.d.ts +24 -0
  300. package/dist/signals/words.js +24 -0
  301. package/dist/store/cache.d.ts +101 -0
  302. package/dist/store/cache.js +149 -0
  303. package/dist/store/history.d.ts +82 -0
  304. package/dist/store/history.js +36 -0
  305. package/dist/store/index.d.ts +30 -0
  306. package/dist/store/index.js +30 -0
  307. package/dist/store/memory.d.ts +2 -1
  308. package/dist/store/memory.js +48 -12
  309. package/dist/store/migrate.d.ts +106 -0
  310. package/dist/store/migrate.js +323 -7
  311. package/dist/store/postgres-applications.d.ts +4 -0
  312. package/dist/store/postgres-applications.js +197 -0
  313. package/dist/store/postgres-audience.d.ts +14 -0
  314. package/dist/store/postgres-audience.js +272 -0
  315. package/dist/store/postgres-holds.d.ts +10 -1
  316. package/dist/store/postgres-holds.js +116 -101
  317. package/dist/store/postgres-policy-log.d.ts +14 -0
  318. package/dist/store/postgres-policy-log.js +240 -0
  319. package/dist/store/postgres-projects.d.ts +4 -0
  320. package/dist/store/postgres-projects.js +217 -0
  321. package/dist/store/postgres.d.ts +17 -1
  322. package/dist/store/postgres.js +60 -9
  323. package/dist/store/replay.d.ts +102 -1
  324. package/dist/store/replay.js +190 -19
  325. package/dist/store/reseed.d.ts +238 -0
  326. package/dist/store/reseed.js +308 -0
  327. package/dist/store/schema.d.ts +762 -2
  328. package/dist/store/schema.js +218 -5
  329. package/dist/store/source.d.ts +57 -1
  330. package/dist/store/source.js +65 -1
  331. package/dist/store/store.d.ts +29 -6
  332. package/dist/submit/resolve.d.ts +1 -1
  333. package/dist/submit/resolve.js +2 -1
  334. package/dist/telemetry/calibration.d.ts +25 -0
  335. package/dist/telemetry/calibration.js +27 -1
  336. package/dist/telemetry/event.d.ts +391 -33
  337. package/dist/telemetry/event.js +84 -20
  338. package/dist/telemetry/index.d.ts +2 -0
  339. package/dist/telemetry/index.js +2 -0
  340. package/dist/telemetry/journal.d.ts +104 -3
  341. package/dist/telemetry/journal.js +9 -0
  342. package/dist/telemetry/lookup.d.ts +27 -0
  343. package/dist/telemetry/lookup.js +18 -0
  344. package/dist/telemetry/memory.js +33 -1
  345. package/dist/telemetry/migrate.js +22 -1
  346. package/dist/telemetry/postgres.d.ts +10 -1
  347. package/dist/telemetry/postgres.js +188 -90
  348. package/dist/telemetry/remeasure.d.ts +78 -0
  349. package/dist/telemetry/remeasure.js +83 -0
  350. package/dist/telemetry/retention.d.ts +2 -2
  351. package/dist/telemetry/schema.d.ts +17 -0
  352. package/dist/telemetry/schema.js +27 -1
  353. package/dist/telemetry/sink.d.ts +2 -2
  354. package/dist/telemetry/window.d.ts +135 -0
  355. package/dist/telemetry/window.js +101 -0
  356. package/dist/testing/application-contract.d.ts +14 -0
  357. package/dist/testing/application-contract.js +270 -0
  358. package/dist/testing/audience-overlay-contract.d.ts +31 -0
  359. package/dist/testing/audience-overlay-contract.js +354 -0
  360. package/dist/testing/contracts.d.ts +13 -7
  361. package/dist/testing/contracts.js +13 -7
  362. package/dist/testing/definitions.d.ts +78 -0
  363. package/dist/testing/definitions.js +134 -9
  364. package/dist/testing/doubles.d.ts +103 -0
  365. package/dist/testing/doubles.js +143 -0
  366. package/dist/testing/index.d.ts +2 -2
  367. package/dist/testing/index.js +2 -2
  368. package/dist/testing/journal-contract.js +297 -6
  369. package/dist/testing/model-contract.d.ts +110 -0
  370. package/dist/testing/model-contract.js +150 -0
  371. package/dist/testing/policy-log-contract.d.ts +26 -0
  372. package/dist/testing/policy-log-contract.js +344 -0
  373. package/dist/testing/project-contract.d.ts +14 -0
  374. package/dist/testing/project-contract.js +266 -0
  375. package/dist/testing/reader-signal-contract.d.ts +27 -2
  376. package/dist/testing/reader-signal-contract.js +475 -5
  377. package/dist/testing/store-contract.d.ts +7 -1
  378. package/dist/testing/store-contract.js +84 -3
  379. package/dist/theme/apply.d.ts +20 -1
  380. package/dist/theme/apply.js +5 -3
  381. package/dist/theme/contrast.d.ts +19 -14
  382. package/dist/theme/contrast.js +181 -17
  383. package/dist/theme/derive.d.ts +22 -0
  384. package/dist/theme/derive.js +54 -1
  385. package/dist/theme/library.js +1 -1
  386. package/dist/theme/measure.d.ts +34 -0
  387. package/dist/theme/measure.js +30 -1
  388. package/dist/theme/palettes.js +7 -7
  389. package/dist/theme/ramp.d.ts +64 -0
  390. package/dist/theme/ramp.js +114 -0
  391. package/dist/theme/registry.d.ts +9 -0
  392. package/dist/theme/registry.js +11 -1
  393. package/dist/theme/separation.d.ts +97 -3
  394. package/dist/theme/separation.js +75 -0
  395. package/dist/tree/apply.js +13 -0
  396. package/dist/tree/compare.d.ts +9 -0
  397. package/dist/tree/compare.js +18 -0
  398. package/dist/tree/mutation.d.ts +18 -0
  399. package/dist/tree/mutation.js +24 -12
  400. package/dist/tree/navigation.d.ts +5 -0
  401. package/dist/tree/navigation.js +32 -10
  402. package/dist/tree/outline.d.ts +7 -0
  403. package/dist/tree/outline.js +9 -5
  404. package/dist/write/computed.d.ts +60 -0
  405. package/dist/write/computed.js +61 -0
  406. package/dist/write/held.d.ts +59 -0
  407. package/dist/write/index.d.ts +5 -2
  408. package/dist/write/index.js +5 -2
  409. package/dist/write/reseed.d.ts +151 -0
  410. package/dist/write/reseed.js +184 -0
  411. package/dist/write/revert.js +2 -16
  412. package/package.json +25 -3
  413. package/dist/runtime/inverse-interpreter.d.ts +0 -90
  414. package/dist/runtime/inverse-interpreter.js +0 -56
@@ -23,28 +23,84 @@ const seedReplay = (seed) => ({
23
23
  tree: seed,
24
24
  idHistory: seedIdHistory(seed),
25
25
  });
26
+ /** Nothing a later page holds can change an answer. */
27
+ const settled = (fold) => fold.mismatch !== null || (fold.seeking !== null && fold.seeking.size === 0);
26
28
  /**
27
- * Folds a whole log by walking it forward one page at a time.
29
+ * Keeps the walk's current state if it is one a caller named.
28
30
  *
29
- * The log is read in pages (0026), so the only caller that legitimately needs
30
- * all of it walks it here rather than every caller being handed an unbounded
31
+ * `ReplayedTree` is immutable and `IdHistory` is rebuilt rather than mutated
32
+ * (0038), so remembering a position costs a reference — which is what makes
33
+ * several stops in one walk as cheap as one.
34
+ */
35
+ const stopped = (fold, revision) => fold.seeking === null || !fold.seeking.has(revision)
36
+ ? fold
37
+ : {
38
+ ...fold,
39
+ seeking: new Set([...fold.seeking].filter((wanted) => wanted !== revision)),
40
+ reached: new Map([...fold.reached, [revision, fold.replayed]]),
41
+ };
42
+ const stepFold = (fold, entry) => {
43
+ if (entry.revision !== fold.replayed.tree.revision + 1) {
44
+ return {
45
+ ...fold,
46
+ mismatch: {
47
+ code: "revision-gap",
48
+ expected: fold.replayed.tree.revision + 1,
49
+ found: entry.revision,
50
+ },
51
+ };
52
+ }
53
+ const applied = applyDelta(fold.replayed.tree, entry.delta);
54
+ if (!applied.ok) {
55
+ return {
56
+ ...fold,
57
+ mismatch: { code: "delta-rejected", revision: entry.revision, detail: applied.error.code },
58
+ };
59
+ }
60
+ return stopped({
61
+ ...fold,
62
+ replayed: {
63
+ tree: applied.value,
64
+ idHistory: trackIds(fold.replayed.idHistory, fold.replayed.tree, applied.value),
65
+ },
66
+ }, entry.revision);
67
+ };
68
+ /**
69
+ * A fold about to begin, with the seed's own revision already counted as a stop.
70
+ *
71
+ * A caller may legitimately ask for the revision the seed is at — the tree as it
72
+ * was is the seed itself — and that answer costs no read at all, because
73
+ * `settled` is already true when it is the only one wanted.
74
+ */
75
+ const startFold = (seed, seeking) => stopped({ replayed: seedReplay(seed), seeking, reached: new Map(), mismatch: null }, seed.revision);
76
+ /**
77
+ * Walks the log forward one page at a time, from the seed and no further than it
78
+ * has to go.
79
+ *
80
+ * The log is read in pages (0026), so the only callers that legitimately need a
81
+ * span of it walk it here rather than every caller being handed an unbounded
31
82
  * read. Each page is folded into the tree the previous one produced, which is
32
83
  * the same fold `replayTree` performs — a page boundary is not a semantic
33
84
  * boundary, it is just where the read stopped.
34
85
  *
86
+ * **It opens at the seed rather than at the oldest entry.** A seed is usually
87
+ * revision 0 and then the two are the same page; a host that checkpoints may
88
+ * supply a later one (0028), and a walk that started at the beginning would meet
89
+ * an entry the seed already contains and call it a gap. `at` is inclusive, so
90
+ * `seedRevision + 1` is the first entry the seed has not applied — and because
91
+ * revisions are dense (0026), nothing can hide between the two.
92
+ *
35
93
  * `newer` is the contract's "there is more forward of here", so following it
36
- * until it is `null` visits every entry exactly once.
94
+ * until it is `null` visits every entry after the seed exactly once.
37
95
  */
38
- const foldLog = async (store, treeId, from, cursor) => {
39
- const page = await store.revisions(treeId, cursor === undefined ? {} : { cursor });
96
+ const foldPages = async (reader, treeId, seedRevision, fold, cursor) => {
97
+ const page = await reader.revisions(treeId, cursor === undefined
98
+ ? { at: seedRevision + 1, direction: "newer" }
99
+ : { cursor, direction: "newer" });
40
100
  if (!page.ok)
41
101
  return page;
42
- const folded = replayFrom(from, page.value.revisions);
43
- if (!folded.ok)
44
- return ok(folded);
45
- return page.value.newer === null
46
- ? ok(folded)
47
- : await foldLog(store, treeId, folded.value, page.value.newer);
102
+ const walked = page.value.revisions.reduce((current, entry) => (settled(current) ? current : stepFold(current, entry)), fold);
103
+ return page.value.newer === null || settled(walked) ? ok(walked) : await foldPages(reader, treeId, seedRevision, walked, page.value.newer);
48
104
  };
49
105
  /**
50
106
  * Folds a tree's log from a known seed and compares the result to the stored
@@ -61,22 +117,137 @@ export const auditSnapshot = async (store, treeId, seed) => {
61
117
  const head = await store.head(treeId);
62
118
  if (!head.ok)
63
119
  return head;
64
- const folded = await foldLog(store, treeId, seedReplay(seed));
120
+ const folded = await foldPages(store, treeId, seed.revision, startFold(seed, null));
65
121
  if (!folded.ok)
66
122
  return folded;
67
- const replayed = folded.value;
68
- if (!replayed.ok)
69
- return ok({ outcome: "unreplayable", mismatch: replayed.error });
70
- const idReturns = idReturnsIn(replayed.value.idHistory);
71
- const agrees = JSON.stringify(replayed.value.tree) === JSON.stringify(head.value);
123
+ const fold = folded.value;
124
+ if (fold.mismatch !== null)
125
+ return ok({ outcome: "unreplayable", mismatch: fold.mismatch });
126
+ const idReturns = idReturnsIn(fold.replayed.idHistory);
127
+ const agrees = JSON.stringify(fold.replayed.tree) === JSON.stringify(head.value);
72
128
  return ok(agrees
73
129
  ? { outcome: "agrees", revision: head.value.revision, idReturns }
74
130
  : {
75
131
  outcome: "diverged",
76
132
  revision: head.value.revision,
77
133
  stored: head.value,
78
- replayed: replayed.value.tree,
134
+ replayed: fold.replayed.tree,
79
135
  idReturns,
80
136
  });
81
137
  };
138
+ export const describeTreeAt = (answer) => {
139
+ switch (answer.outcome) {
140
+ case "replayed":
141
+ return `revision ${answer.revision} replayed from the log`;
142
+ case "out-of-range":
143
+ return `revision ${answer.revision} is outside ${answer.earliest}–${answer.headRevision}`;
144
+ case "unreplayable":
145
+ return answer.mismatch.code === "revision-gap"
146
+ ? `revision ${answer.revision} is unreachable: the log jumps from ${answer.mismatch.expected - 1} to ${answer.mismatch.found}`
147
+ : `revision ${answer.revision} is unreachable: revision ${answer.mismatch.revision} no longer applies (${answer.mismatch.detail})`;
148
+ }
149
+ };
150
+ /**
151
+ * Reads head to establish the span, then folds once for every revision worth
152
+ * folding for.
153
+ *
154
+ * The head read is what makes `out-of-range` an answer instead of a guess: a
155
+ * revision past the head is not a gap in the log, it is a revision that has not
156
+ * happened, and a fold alone cannot tell those apart — it would simply run out
157
+ * of entries and report the shape of corruption.
158
+ */
159
+ const survey = async (reader, targets) => {
160
+ const head = await reader.head(targets.treeId);
161
+ if (!head.ok)
162
+ return head;
163
+ const earliest = targets.seed.revision;
164
+ const headRevision = head.value.revision;
165
+ const seeking = new Set(targets.revisions.filter((revision) => Number.isInteger(revision) && revision >= earliest && revision <= headRevision));
166
+ const fold = startFold(targets.seed, seeking);
167
+ if (settled(fold))
168
+ return ok({ fold, earliest, headRevision });
169
+ const walked = await foldPages(reader, targets.treeId, targets.seed.revision, fold);
170
+ return walked.ok ? ok({ fold: walked.value, earliest, headRevision }) : walked;
171
+ };
172
+ /**
173
+ * What one revision's answer is, given a walk that was told to look for it.
174
+ *
175
+ * The order the cases are read in is the order the walk would have met them
176
+ * folding to that revision alone, which is what makes a batched read the same
177
+ * answer as a solitary one: a revision outside the span was decided before the
178
+ * log was opened, and a revision inside it is either reached or stopped short of
179
+ * by the first obstacle the fold met.
180
+ */
181
+ const answerFrom = ({ fold, earliest, headRevision }, revision) => {
182
+ if (!Number.isInteger(revision) || revision < earliest || revision > headRevision) {
183
+ return { outcome: "out-of-range", revision, earliest, headRevision };
184
+ }
185
+ const replayed = fold.reached.get(revision);
186
+ if (replayed !== undefined)
187
+ return { outcome: "replayed", revision, replayed };
188
+ /**
189
+ * In the span, not reached, and the fold met nothing it could name: the log
190
+ * holds fewer entries than the snapshot's revision claims, so it ends before
191
+ * the revision asked for. The gap is between the last entry and the head, and
192
+ * saying so is the only honest thing left — this is the corruption
193
+ * `auditSnapshot` exists to find, met by a caller who was only asking for a
194
+ * tree.
195
+ */
196
+ return {
197
+ outcome: "unreplayable",
198
+ revision,
199
+ mismatch: fold.mismatch ?? {
200
+ code: "revision-gap",
201
+ expected: fold.replayed.tree.revision + 1,
202
+ found: headRevision,
203
+ },
204
+ };
205
+ };
206
+ /**
207
+ * The tree as it was at a chosen revision.
208
+ *
209
+ * A store materialises one revision — the head — because §3 renders per request
210
+ * and a fold per render is not affordable. Every earlier revision is in the log
211
+ * and nowhere else, so this is the fold, stopped where the caller said rather
212
+ * than at the end.
213
+ *
214
+ * It exists because a reading keyed to a revision needs the tree *of* that
215
+ * revision: reader counters are keyed by tree and revision deliberately (0147),
216
+ * and laying one revision's counters over another revision's tree makes most
217
+ * parts read "nobody got there" while every number stays plausible. The
218
+ * workaround — page `revisions()` and fold from the seed in the consumer — is
219
+ * the same walk with the stopping condition moved somewhere nothing tests it,
220
+ * and a consumer that gets it slightly wrong produces the one failure this
221
+ * reading can have that looks exactly like success.
222
+ */
223
+ export const treeAt = async (reader, target) => {
224
+ const surveyed = await survey(reader, {
225
+ treeId: target.treeId,
226
+ revisions: [target.revision],
227
+ seed: target.seed,
228
+ });
229
+ return surveyed.ok ? ok(answerFrom(surveyed.value, target.revision)) : surveyed;
230
+ };
231
+ /**
232
+ * The same answers for several revisions, from one read of the log.
233
+ *
234
+ * Each answer is exactly what `treeAt` would have produced for that revision on
235
+ * its own — the batch changes what it costs to ask, never what the answer is.
236
+ * Two revisions is the case it exists for: a before-and-after reading is one
237
+ * revision against another, and asking twice would fold the shared prefix twice
238
+ * and read the head twice, against a log that is still being appended to.
239
+ *
240
+ * Revisions are keyed rather than positional so a caller can ask about the ones
241
+ * it is comparing and read the answers back by revision; asking twice about one
242
+ * revision costs nothing and answers once.
243
+ */
244
+ export const treesAt = async (reader, targets) => {
245
+ const surveyed = await survey(reader, targets);
246
+ if (!surveyed.ok)
247
+ return surveyed;
248
+ return ok(new Map([...new Set(targets.revisions)].map((revision) => [
249
+ revision,
250
+ answerFrom(surveyed.value, revision),
251
+ ])));
252
+ };
82
253
  //# sourceMappingURL=replay.js.map
@@ -0,0 +1,238 @@
1
+ import type { NodeId, TreeId } from "../ids.js";
2
+ import { type Result } from "../result.js";
3
+ import type { DiscardedWork } from "../runtime/proposal.js";
4
+ import { type NodeFacet, type TreeDifference } from "../tree/compare.js";
5
+ import type { TreeOperation } from "../tree/delta.js";
6
+ import type { TreeError } from "../tree/errors.js";
7
+ import { type LoomTree } from "../tree/tree.js";
8
+ import type { StoreError } from "./errors.js";
9
+ import type { TreeReader } from "./store.js";
10
+ /**
11
+ * Planning a reseed: what it would take to put a stored page back to the shape
12
+ * its builder produces now.
13
+ *
14
+ * 0259 made this site's pages rows in the store, and seeding is deliberately
15
+ * create-if-absent — a page that exists has a history and a deploy that
16
+ * re-seeded over the top would throw it away on every release. The consequence
17
+ * `Loom portal` filed on 12 October is the one worth planning for: **once a page
18
+ * is in the store, editing its builder stops changing the site, and there was no
19
+ * supported way back.** A deployment in that position could append its way to
20
+ * the shape it wanted or open a SQL client.
21
+ *
22
+ * `TreeStore` gains nothing here, and that is the decision rather than an
23
+ * omission. A store whose rows are the audit trail has a good reason not to
24
+ * offer a delete: *the row is gone* is a worse answer than *the row says it was
25
+ * replaced*. So going back is a **change like any other** — operations against a
26
+ * known base revision, carrying provenance, judged by the Gate, invertible, and
27
+ * written into the log where it says what happened on the day it happened.
28
+ *
29
+ * ## This module decides nothing
30
+ *
31
+ * It is `revert.ts`'s sibling and has the same manners: it produces the
32
+ * operations and the obstacles, and the Gate judges. A revert undoes one entry
33
+ * in the log; a reseed carries the whole page to a tree somebody else built.
34
+ * Neither writes.
35
+ *
36
+ * ## Why the four operations are enough
37
+ *
38
+ * A reseed looks like it wants the whole-tree replacement 0009 deliberately
39
+ * refused. It does not, because node ids are minted once (0003) and are the join
40
+ * key between the two trees: a builder is pure and its id factory is
41
+ * deterministic, so the authored tree names the same nodes the stored one does.
42
+ * That turns a diff into a set join and a position pass — no structural
43
+ * alignment, no heuristics — and every operation it emits is one the Gate can
44
+ * read on its own.
45
+ *
46
+ * `configure` reaching a text node's `value` and a slot's `name` is what makes
47
+ * this exact rather than nearly exact. A builder whose headline changed produces
48
+ * a text node with the same id and a new value, which is the most likely reseed
49
+ * there is; without a settable `value` it would have needed the id back as a
50
+ * different node, and 0038 is the reason that is refused.
51
+ *
52
+ * ## The plan checks itself
53
+ *
54
+ * Every operation is planned against a simulation of the tree it will be applied
55
+ * to, and the simulation is compared to the authored tree at the end. A plan that
56
+ * did not land is reported as `unexpressible` rather than returned as a good one.
57
+ * So the two facets `configure` cannot reach — a node's kind, and an element's
58
+ * primitive — do not need enumerating twice: they are refused up front for a
59
+ * precise answer, and the comparison is what makes that list impossible to get
60
+ * wrong.
61
+ *
62
+ * `compareTrees` is the description and is still never a recipe (0016). Here it
63
+ * decides what the recipe may attempt and then proves that it worked, which is
64
+ * the one direction between the two that cannot put an entry in the log nobody
65
+ * proposed.
66
+ */
67
+ /**
68
+ * A node the authored tree names and the stored page no longer holds.
69
+ *
70
+ * The plan reports these rather than ruling on them, for `discards`' reason
71
+ * (0035): an insert under an id the log once retired is `restored` if the node
72
+ * that comes back is the node that left and `recycled` if it is not, and only
73
+ * the log can tell those apart — `idReturnsIn` is what answers it, and the
74
+ * answer is the audit's rather than this plan's. A caller that cares asks there;
75
+ * the Gate decides what a reseed that revives an address is worth.
76
+ */
77
+ export type NodeRevival = {
78
+ readonly nodeId: NodeId;
79
+ readonly label: string;
80
+ };
81
+ /** A node the stored page holds that the authored tree does not, so the reseed removes it. */
82
+ export type NodeRetirement = {
83
+ readonly nodeId: NodeId;
84
+ readonly label: string;
85
+ };
86
+ /** Why the authored tree is not a build of the stored page at all. */
87
+ export type PageMismatch = {
88
+ readonly facet: "treeId";
89
+ readonly stored: TreeId;
90
+ readonly authored: TreeId;
91
+ }
92
+ /** The root is neither detachable nor insertable, so two roots are two pages. */
93
+ | {
94
+ readonly facet: "rootId";
95
+ readonly stored: NodeId;
96
+ readonly authored: NodeId;
97
+ };
98
+ export type ReseedPlan =
99
+ /**
100
+ * The stored page is already the authored one, so there is nothing to propose.
101
+ * Its own outcome rather than an empty operation list, because a delta carries
102
+ * at least one operation (0009) and a caller that appended an empty one would
103
+ * put a revision in the log that changed nothing.
104
+ */
105
+ {
106
+ readonly outcome: "already-authored";
107
+ readonly headRevision: number;
108
+ } | {
109
+ readonly outcome: "reseedable";
110
+ /**
111
+ * The reseed, as operations. They become a delta when something proposes
112
+ * them; the id and base revision belong to that delta, not to this plan.
113
+ */
114
+ readonly operations: readonly TreeOperation[];
115
+ /** The head these operations were planned against. */
116
+ readonly headRevision: number;
117
+ readonly revives: readonly NodeRevival[];
118
+ /** What the reseed writes over — the changes since seeding that it undoes. */
119
+ readonly retires: readonly NodeRetirement[];
120
+ } | {
121
+ readonly outcome: "different-page";
122
+ readonly mismatch: PageMismatch;
123
+ }
124
+ /**
125
+ * Some difference between the two trees is not expressible in the four
126
+ * operations, so no reseed can be proposed. Carries every difference that
127
+ * stands in the way, named and labelled, which is the half a deployment can
128
+ * act on: the authored tree has to change, or the page does.
129
+ */
130
+ | {
131
+ readonly outcome: "unexpressible";
132
+ readonly blocking: readonly TreeDifference[];
133
+ }
134
+ /**
135
+ * An operation this module planned was refused by the tree it was planned
136
+ * against. Nothing a caller did wrong and nothing it can fix — a bug here,
137
+ * reported as a value so it surfaces as a refusal rather than a wrong page.
138
+ */
139
+ | {
140
+ readonly outcome: "unplannable";
141
+ readonly operation: TreeOperation;
142
+ readonly error: TreeError;
143
+ };
144
+ export type UnreseedablePlan = Exclude<ReseedPlan, {
145
+ readonly outcome: "reseedable";
146
+ }>;
147
+ /**
148
+ * The facets a `configure` cannot reach, so no plan can close them.
149
+ *
150
+ * A node's `kind` and an element's primitive `type` are what a node *is*, and
151
+ * changing either at a stable id would be a different node wearing the address —
152
+ * which is the case 0038 exists to refuse, not one to work around by removing
153
+ * and re-inserting. `name` and `text` are absent on purpose: both are settable
154
+ * (`configurationOf` exposes one key for each), which is what keeps a reseed
155
+ * exact.
156
+ *
157
+ * **The comparison at the end of the plan is what enforces this**, not a filter
158
+ * over this list: a facet nothing can close survives every pass and is still
159
+ * there to be reported. The list is the sentence a reader needs, and
160
+ * `reseed.test.ts` checks it against `NODE_FACETS` so a sixth facet cannot be
161
+ * left out of it.
162
+ */
163
+ export declare const UNRESEEDABLE_FACETS: readonly NodeFacet[];
164
+ /**
165
+ * What it would take to carry a stored page to the tree its builder produces now.
166
+ *
167
+ * `stored` is the head of the page in the store; `authored` is a fresh build. The
168
+ * two must be the same page — the same tree id and the same root — because a root
169
+ * can be neither removed nor moved (0009), so there is no operation that turns one
170
+ * root into another.
171
+ *
172
+ * Pure, and it reads no log: both trees are in the caller's hand already, and the
173
+ * one question that needs the log — whether an id this plan revives was retired as
174
+ * the node that is coming back — is `idReturnsIn`'s and travels on `revives` for
175
+ * the Gate rather than being answered here.
176
+ */
177
+ export declare const planReseed: (stored: LoomTree, authored: LoomTree) => ReseedPlan;
178
+ export declare const describeReseedPlan: (plan: ReseedPlan) => string;
179
+ /**
180
+ * What a reseed writes over: every entry in the log that touched a node the
181
+ * reseed is about to change.
182
+ *
183
+ * `planReseed` is pure and reads no log, which is right — it answers *can this
184
+ * page be carried back*, and two trees are enough to answer it. This answers the
185
+ * separate question the Gate needs: *whose work does carrying it back destroy*.
186
+ *
187
+ * It matters because of what the declaration buys. 0035 made discarded work a
188
+ * rule in the Gate rather than a level — a change that writes over work already
189
+ * in the log is never applied without a person, whatever latitude its origin
190
+ * has. So a reseed that declares its discards is **held for confirmation** by
191
+ * construction, and a reseed over a page nobody has edited since it was seeded
192
+ * declares nothing and applies straight through. That is the whole of the
193
+ * question `Loom marketing` filed as *who presses it*, answered by the Gate
194
+ * instead of by a new switch.
195
+ *
196
+ * Which makes the absence of this function the dangerous state rather than a
197
+ * missing nicety: a caller that proposed a reseed without it would be asking the
198
+ * Gate to weigh a change whose cost it declared nothing about, and 0035 is
199
+ * explicit that absence means *nobody looked at a log* rather than *the log was
200
+ * clean*. The proposal would have been auto-applied over somebody's accepted
201
+ * edit.
202
+ *
203
+ * Every entry is a candidate. There is no seed revision to skip past, unlike
204
+ * `planRevert`'s walk: revision 0 is the `create` and carries no delta, so every
205
+ * entry in the log is a change somebody accepted after the page was seeded.
206
+ */
207
+ export type ReseedDiscardsRequest = {
208
+ readonly treeId: TreeId;
209
+ /**
210
+ * The reseed's own operations, as `planReseed` produced them.
211
+ *
212
+ * The operations rather than the plan's `revives` and `retires`, because
213
+ * `namedNodeIds` already reaches every node any of the four operations names —
214
+ * so a reseed that only reconfigures a headline, naming no revival and no
215
+ * retirement, still declares the revision that last wrote that headline.
216
+ * Taking the two lists instead would have missed exactly the commonest reseed
217
+ * there is.
218
+ */
219
+ readonly operations: readonly TreeOperation[];
220
+ };
221
+ /**
222
+ * Reads the whole log once and reports the entries a reseed would write over.
223
+ *
224
+ * Ascending by revision, because `DiscardedWork` is read by a person answering a
225
+ * hold (0019) and *revisions 3, 7 and 8* is the sentence they can check against
226
+ * the history screen beside it.
227
+ *
228
+ * The walk is the whole log rather than a window, and that is the honest cost: a
229
+ * reseed's reach is every node it names, and a change from the page's first week
230
+ * is as discarded as one from this morning. It is the same walk `planRevert`
231
+ * takes and it is paid once per reseed, which is an operation a person presses.
232
+ *
233
+ * A `StoreError` means the log could not be read, so nothing is known about the
234
+ * cost — and a caller must not then propose the reseed with an empty
235
+ * declaration, which would read as *the log was clean*.
236
+ */
237
+ export declare const reseedDiscards: (reader: TreeReader, request: ReseedDiscardsRequest) => Promise<Result<readonly DiscardedWork[], StoreError>>;
238
+ //# sourceMappingURL=reseed.d.ts.map