@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
@@ -0,0 +1,693 @@
1
+ import { everyMemberOf } from "../closed-set.js";
2
+ import { ok } from "../result.js";
3
+ import { audiencesIn, formKeyOf, formOf, inFormOrder, readingKeyOf, } from "./audiences.js";
4
+ import { pageReadingOf } from "./parts.js";
5
+ import { regionReadingOf, } from "./region.js";
6
+ /**
7
+ * Read one window from the stores, with one scope rather than four.
8
+ *
9
+ * The four reads are independent and are made together. The first failure is
10
+ * the answer: a window half of whose rows arrived is not a narrower window, it
11
+ * is a reading whose every rate has a denominator from one read and a numerator
12
+ * from another, and the figures would look plausible.
13
+ *
14
+ * The request is the stores' own {@link TallyReadRequest}, passed through
15
+ * unchanged to each of them, so scoping a screen to one page, one revision or
16
+ * one audience is the one argument it already was.
17
+ */
18
+ export const readReaderWindow = async (sources, request) => {
19
+ const [tallies, funnels, pageViews, regions] = await Promise.all([
20
+ sources.tallies.tallies(request),
21
+ sources.tallies.funnels(request),
22
+ sources.tallies.pageViews(request),
23
+ sources.regions?.regions(request),
24
+ ]);
25
+ if (!tallies.ok)
26
+ return tallies;
27
+ if (!funnels.ok)
28
+ return funnels;
29
+ if (!pageViews.ok)
30
+ return pageViews;
31
+ if (regions !== undefined && !regions.ok)
32
+ return regions;
33
+ return ok({
34
+ tallies: tallies.value,
35
+ funnels: funnels.value,
36
+ pageViews: pageViews.value,
37
+ regions: regions?.value,
38
+ });
39
+ };
40
+ const revisionKeyOf = (where) => `${where.treeId}\u0000${where.revision}`;
41
+ const inRevisionOrder = (one, other) => one.treeId.localeCompare(other.treeId) || one.revision - other.revision;
42
+ /**
43
+ * Rows filed under each revision, in one pass over them.
44
+ *
45
+ * A pass per revision would be a walk of the whole window per page a deployment
46
+ * has, which is the quadratic shape rule 4 holds this subsystem to — the ledger
47
+ * was that once and a 6,000-node page took 314 ms. A window is the nodes of
48
+ * every revision a deployment keeps counters for, so the factor here is the
49
+ * number of pages and the input is already the largest thing in the subsystem.
50
+ */
51
+ const byRevision = (rows) => {
52
+ const filed = new Map();
53
+ for (const row of rows) {
54
+ const key = revisionKeyOf(row);
55
+ const held = filed.get(key);
56
+ if (held === undefined)
57
+ filed.set(key, [row]);
58
+ else
59
+ held.push(row);
60
+ }
61
+ return filed;
62
+ };
63
+ /**
64
+ * Every revision the window's rows name, deduplicated and in a stable order.
65
+ *
66
+ * **Taken over all four row sets and not only the counters.** A revision whose
67
+ * door opened and whose window no rollup has folded yet has page view rows and
68
+ * no tallies, and it is a page a deployment most wants to see rather than one
69
+ * to leave out: it is the difference between *nobody read this* and *nothing
70
+ * has counted this yet*, which the reach reading publishes as `uncounted` and
71
+ * can only publish about a revision it was handed.
72
+ *
73
+ * The audience is deliberately not part of this. A tree is one tree at one
74
+ * revision however many forms of it are served — two forms are the deltas an
75
+ * audience earns over one base (0263) — so asking for a tree per form would be
76
+ * asking the caller for the same tree twice.
77
+ */
78
+ export const revisionsIn = (window) => {
79
+ const found = new Map();
80
+ const note = (rows) => {
81
+ for (const row of rows) {
82
+ const where = { treeId: row.treeId, revision: row.revision };
83
+ const key = revisionKeyOf(where);
84
+ if (!found.has(key))
85
+ found.set(key, where);
86
+ }
87
+ };
88
+ note(window.tallies);
89
+ note(window.funnels);
90
+ note(window.pageViews);
91
+ note(window.regions ?? []);
92
+ return [...found.values()].sort(inRevisionOrder);
93
+ };
94
+ /**
95
+ * The trees a caller already holds, as a source.
96
+ *
97
+ * Keyed by tree **and** revision, because two revisions of one page are two
98
+ * trees to this join and keying by the page would answer one of them for both.
99
+ * The first of two trees at one revision wins and the second is ignored: they
100
+ * disagree about what a revision is, nothing here can say which is right, and
101
+ * a silent last-wins would make the answer depend on the order a store
102
+ * returned.
103
+ */
104
+ export const treesIn = (trees) => {
105
+ const held = new Map();
106
+ for (const tree of trees) {
107
+ const key = revisionKeyOf(tree);
108
+ if (!held.has(key))
109
+ held.set(key, tree);
110
+ }
111
+ return { treeFor: (where) => held.get(revisionKeyOf(where)) };
112
+ };
113
+ /** The closed set, for a surface accounting for every revision it cannot draw. */
114
+ export const UNJOINED_CAUSES = everyMemberOf()([
115
+ "no-tree",
116
+ "mismatched",
117
+ ]);
118
+ /** One line per cause, for a surface saying why a page is not on the screen. */
119
+ export const describeUnjoinedCause = (cause) => {
120
+ switch (cause) {
121
+ case "no-tree":
122
+ return "there are counters for this revision and no tree to read them against";
123
+ case "mismatched":
124
+ return "the tree offered for this revision was of another one, so the counters were not read";
125
+ }
126
+ };
127
+ /**
128
+ * The rows of a window with the repeats of one bucket dropped, which is the one
129
+ * thing every reading of a region row set has to do first.
130
+ *
131
+ * A store keeps one row per tree, revision, form and region, so this cannot
132
+ * come out of one read: it is a caller concatenating two windows whose counts
133
+ * are already running totals. **Adding them doubles a bucket**, which is the one
134
+ * error in this subsystem that cannot be undone afterwards (0158), and a doubled
135
+ * bucket is worse than a wrong number — it clears a floor it should not have
136
+ * cleared, so a place with too few readers to name gets named.
137
+ *
138
+ * Published because it is used twice and was written once. {@link
139
+ * WindowRegionReadings} folds it into the maps it builds; a reading that takes
140
+ * the **rows** rather than the maps — which is `regionPagesOf`, because a
141
+ * breakdown by page needs the cells and a map does not hold them — has to apply
142
+ * the same rule to the same rows or the two answers disagree about one window.
143
+ * Two spellings of one rule that agree today are a thing this subsystem has
144
+ * been bitten by before (0265).
145
+ *
146
+ * Linear in the rows, with one set.
147
+ */
148
+ export const distinctRegionRows = (rows) => {
149
+ const kept = [];
150
+ const seen = new Set();
151
+ let duplicated = 0;
152
+ for (const row of rows) {
153
+ const key = `${revisionKeyOf(row)}\u0000${row.audienceId ?? ""}\u0000${row.region}`;
154
+ if (seen.has(key)) {
155
+ duplicated += 1;
156
+ continue;
157
+ }
158
+ seen.add(key);
159
+ kept.push(row);
160
+ }
161
+ return { kept, duplicated };
162
+ };
163
+ const regionGroupsOf = (rows) => {
164
+ const groups = new Map();
165
+ const { kept, duplicated } = distinctRegionRows(rows);
166
+ for (const row of kept) {
167
+ const key = `${revisionKeyOf(row)}\u0000${row.audienceId ?? ""}`;
168
+ const held = groups.get(key);
169
+ if (held === undefined) {
170
+ groups.set(key, {
171
+ where: { treeId: row.treeId, revision: row.revision },
172
+ audienceId: row.audienceId ?? null,
173
+ rows: [row],
174
+ });
175
+ }
176
+ else
177
+ held.rows.push(row);
178
+ }
179
+ return { groups: [...groups.values()], kept, duplicated };
180
+ };
181
+ /**
182
+ * Nulls first, then by name, so two reads of one window are in one order.
183
+ *
184
+ * Orders **audiences** and not forms, which is what it is named for now: the
185
+ * published rule that orders forms is {@link inFormOrder}, this file imports it
186
+ * for the pairs below, and the two cannot carry one name. A form is a tree and
187
+ * an audience (0293) and this takes neither tree, so the old spelling claimed a
188
+ * rule it was not.
189
+ */
190
+ const inAudienceOrder = (one, other) => {
191
+ if (one === other)
192
+ return 0;
193
+ if (one === null)
194
+ return -1;
195
+ if (other === null)
196
+ return 1;
197
+ return one.localeCompare(other);
198
+ };
199
+ /**
200
+ * Read a window's region rows into the maps they hold.
201
+ *
202
+ * The floor is handed in rather than read, which is the line §7 draws: it is
203
+ * per-deployment configuration, `regionFloorOf` is raise-only, and a rung that
204
+ * went looking for it would be a reading path that depends on a configuration
205
+ * store. What this closes is the other half — a caller that passed **no** floor
206
+ * got the default rather than the deployment's, and nothing in the types said
207
+ * so.
208
+ */
209
+ const windowRegionsOf = (rows, options) => {
210
+ const { groups, kept, duplicated } = regionGroupsOf(rows);
211
+ const maps = groups.map(({ where, audienceId, rows: held }) => ({
212
+ ...where,
213
+ audienceId,
214
+ reading: { ...regionReadingOf(held, options), audienceId },
215
+ }));
216
+ return {
217
+ maps: maps.sort((one, other) => inRevisionOrder(one, other) || inAudienceOrder(one.audienceId, other.audienceId)),
218
+ readership: regionReadingOf(kept, options),
219
+ duplicated,
220
+ };
221
+ };
222
+ /**
223
+ * Join a window of counters to the pages it is about.
224
+ *
225
+ * **One reading per form, rather than one per revision read as neither.** A
226
+ * window holding two audiences at one revision is ambiguous to the join
227
+ * underneath — it reads neither, names both, and `health.ts` reports the fault
228
+ * (0290, 0300) — and that refusal is right for a caller that was handed a
229
+ * window and asked nothing. Here the question is *what does this window hold*,
230
+ * and the answer is both forms: the ambiguity was never in the rows, which say
231
+ * which form each belongs to, it was in asking one question of two
232
+ * populations. So the split is made rather than refused, and each form's
233
+ * reading is of its own readers.
234
+ *
235
+ * **The region maps are joined beside the pages and not under them.** They are
236
+ * maps of arrivals rather than of nodes, so they need no tree: a revision whose
237
+ * tree is gone is `unjoined` for its counters and still has its readers
238
+ * counted. See {@link WindowReadings.regions}.
239
+ *
240
+ * **Each reading is handed its revision's rows and told which form to read.**
241
+ * Not the window — a reading handed the whole of one would count every other
242
+ * page's rows as `foreign`, which is exactly what that field exists to report —
243
+ * and not one form's rows either, because then a reading could not say that the
244
+ * page has another form at all. `foreign` is therefore nought on every reading
245
+ * this produces, `audiences` is what the revision really holds, and
246
+ * `otherAudience` is the other form's rows, counted apart and not read.
247
+ */
248
+ export const windowReadingsOf = (window, trees, declarations, options = {}) => {
249
+ const pages = [];
250
+ const unjoined = [];
251
+ const counters = byRevision(window.tallies);
252
+ const funnels = byRevision(window.funnels);
253
+ const doors = byRevision(window.pageViews);
254
+ const regions = byRevision(window.regions ?? []);
255
+ for (const where of revisionsIn(window)) {
256
+ const key = revisionKeyOf(where);
257
+ const here = counters.get(key) ?? [];
258
+ const tree = trees.treeFor(where);
259
+ if (tree === undefined) {
260
+ unjoined.push({ ...where, cause: "no-tree", tallies: here.length });
261
+ continue;
262
+ }
263
+ if (revisionKeyOf(tree) !== key) {
264
+ unjoined.push({ ...where, cause: "mismatched", tallies: here.length });
265
+ continue;
266
+ }
267
+ /**
268
+ * The forms this revision was served in, taken over every row set rather
269
+ * than over the counters alone. A form whose readers arrived and whose
270
+ * window has not been folded is named by a door row and by nothing else,
271
+ * and leaving it out would publish one form's readers as the page's, which
272
+ * is the mistake the region map had one rung further up (0290).
273
+ */
274
+ const named = [
275
+ ...here,
276
+ ...(funnels.get(key) ?? []),
277
+ ...(doors.get(key) ?? []),
278
+ ...(regions.get(key) ?? []),
279
+ ];
280
+ const forms = audiencesIn(named);
281
+ /**
282
+ * No row named a form, so the window is one population by construction and
283
+ * is read whole — which is every window written before the column existed
284
+ * (0284) and every one a test builds by hand. Asking for `aud_everyone`
285
+ * here would assert what no row said.
286
+ */
287
+ if (forms.length === 0) {
288
+ pages.push(pageReadingOf(tree, here, declarations));
289
+ continue;
290
+ }
291
+ for (const form of forms)
292
+ pages.push(pageReadingOf(tree, here, declarations, form));
293
+ }
294
+ return {
295
+ pages,
296
+ unjoined,
297
+ regions: window.regions === undefined ? undefined : windowRegionsOf(window.regions, options),
298
+ };
299
+ };
300
+ /**
301
+ * Pair a window's readings into the before-and-afters the comparisons take.
302
+ *
303
+ * The second step of this rung and the one it left undone. Nine comparisons in
304
+ * this subsystem take two sides — `readingChangeOf`, `copyChangeOf`,
305
+ * `paceChangeOf`, `actionChangeOf`, `funnelChangeOf` and the four library
306
+ * comparisons — and not one of them could be reached from a store, because
307
+ * nothing turned a window into a pair. `deploymentChangeOf` says so in its own
308
+ * words: *a caller with two windows of counters reads each page's parts, then
309
+ * its progress, then its comparison, then this.* The pairing was the step with
310
+ * no owner, and a caller writing it is a caller writing 0293 again.
311
+ *
312
+ * After this the deployment-wide order over what a change did is three lines:
313
+ *
314
+ * ```ts
315
+ * const { pages } = windowReadingsOf(window, treesIn(trees), registry)
316
+ * const { pairs } = windowPairsOf(pages)
317
+ * const order = deploymentChangeOf(
318
+ * pairs.map(({ was, now }) => readingChangeOf(was, now)),
319
+ * window.pageViews
320
+ * )
321
+ * ```
322
+ *
323
+ * ## One pair per form, and it is the latest two revisions
324
+ *
325
+ * A form with revisions 3, 5 and 9 in the window has two consecutive pairs in
326
+ * it and this produces one: 5 against 9. Publishing both would make the page
327
+ * unreadable by the only consumer there is — `deploymentChangeOf` gates a form
328
+ * handed two different revision pairs as `ambiguous` and drops it, which is
329
+ * right of it, because *which page did the change hurt most* cannot be answered
330
+ * about a form that changed twice. So every page a deployment published three
331
+ * times inside one window would vanish from the order, and the figure it
332
+ * vanished out of would go on looking right (0158).
333
+ *
334
+ * The latest pair rather than the widest one, for the same reason: 3 against 9
335
+ * is two changes added together and labelled as one, and *what did this change
336
+ * do* is a question about the change that was made. What the window holds below
337
+ * `was` is on the pair as {@link WindowPair.superseded}, so nothing is hidden
338
+ * and an older pair is two readings and one call away.
339
+ *
340
+ * ## Paired by the form rule and nothing else, so no pair here can be refused
341
+ *
342
+ * The grouping is `formKeyOf` (0293), so both sides of every pair are of one
343
+ * tree and one audience by construction. Three of the four states
344
+ * `readingChangeOf` refuses are therefore unreachable from a pair this makes:
345
+ * `different-trees` needs two trees, `different-audiences` needs two named
346
+ * audiences, and `audiences-mixed` needs a side that holds two forms and names
347
+ * none, which is a reading {@link windowReadingsOf} does not produce — it
348
+ * splits a revision serving two forms into one reading each. What is left is
349
+ * `nothing-measured`, which is about the readers rather than about the pairing,
350
+ * and that is the division this rung is for: a comparison that comes back
351
+ * silent from here is silent about a deployment's readers and not about its
352
+ * caller.
353
+ *
354
+ * **The one pair it will not make, which is deliberate.** A deployment that
355
+ * upgraded across 0284 has revisions whose rows name no audience and revisions
356
+ * whose rows name one, and those are two forms under the published rule. So the
357
+ * comparison spanning the upgrade is not produced, and both of its sides are in
358
+ * {@link WindowPairs.unpaired}. It is the pair `crossesAudiences` deliberately
359
+ * allows — unprovable rather than proven alike — and allowing it is not the
360
+ * same as asserting it: nothing in the rows says the two are one population, a
361
+ * rung that paired them would be a tenth spelling of the pairing rule, and the
362
+ * caller who knows its own history makes that comparison in one call, where
363
+ * `audiences` on the result says what it was read across.
364
+ *
365
+ * ## It adds no figure of its own
366
+ *
367
+ * Nothing here counts, divides, sums or withholds, which is the rule the first
368
+ * step of this rung set: it decides **which pairs a window holds** and hands
369
+ * each of them the two readings it is a pair of. Every one of the nine
370
+ * comparisons is one call off a pair.
371
+ *
372
+ * **It does not assemble the two windows the four library comparisons take.**
373
+ * Those compare a whole library before against a whole library after, and a
374
+ * form with one revision cannot be put on a side out of anything here: a page
375
+ * published inside the window belongs to the later one, a page nobody has
376
+ * changed belongs to both, and nothing in the counters tells them apart.
377
+ * {@link windowLibrariesOf} is that step, and it asks the caller — the only
378
+ * party that knows what it published when — rather than guessing, because
379
+ * guessing publishes a page nobody touched as a page gained (0295). What this
380
+ * owes it is the two lists, which is why {@link WindowPairs.unpaired} is
381
+ * published rather than dropped.
382
+ *
383
+ * Linear in the readings but for one sort per form, which is a sort of that
384
+ * form's revisions and not of the window: the window sorted whole would be the
385
+ * shape rule 4 holds this subsystem to, and a deployment's revisions per page
386
+ * are a handful where its pages are not.
387
+ */
388
+ export const windowPairsOf = (readings) => {
389
+ const forms = new Map();
390
+ const seen = new Set();
391
+ let duplicated = 0;
392
+ for (const reading of readings) {
393
+ const key = readingKeyOf(reading);
394
+ /**
395
+ * The first of two readings of one key wins and the second is counted, for
396
+ * the reason it does in `treesIn`: they disagree about what one reading of
397
+ * one revision is, nothing here can say which is right, and a silent
398
+ * last-wins would make the answer depend on the order a store returned.
399
+ */
400
+ if (seen.has(key)) {
401
+ duplicated += 1;
402
+ continue;
403
+ }
404
+ seen.add(key);
405
+ const form = formKeyOf(reading);
406
+ const held = forms.get(form);
407
+ if (held === undefined)
408
+ forms.set(form, [reading]);
409
+ else
410
+ held.push(reading);
411
+ }
412
+ const pairs = [];
413
+ const unpaired = [];
414
+ for (const held of forms.values()) {
415
+ const inOrder = [...held].sort((one, other) => one.revision - other.revision);
416
+ const now = inOrder.at(-1);
417
+ const was = inOrder.at(-2);
418
+ if (now === undefined)
419
+ continue;
420
+ if (was === undefined) {
421
+ unpaired.push({ ...formOf(now), reading: now });
422
+ continue;
423
+ }
424
+ pairs.push({
425
+ ...formOf(now),
426
+ was,
427
+ now,
428
+ superseded: inOrder.slice(0, -2).map((reading) => reading.revision),
429
+ });
430
+ }
431
+ return {
432
+ pairs: pairs.sort(inFormOrder),
433
+ unpaired: unpaired.sort(inFormOrder),
434
+ duplicated,
435
+ };
436
+ };
437
+ /** The closed set, for a surface accounting for every form it was asked about. */
438
+ export const FORM_PLACINGS = everyMemberOf()([
439
+ "published",
440
+ "withdrawn",
441
+ "unchanged",
442
+ ]);
443
+ /** One line per placing, for a surface saying which library a page is in and why. */
444
+ export const describeFormPlacing = (placing) => {
445
+ switch (placing) {
446
+ case "published":
447
+ return "this page was first served inside the window, so only the later library holds it";
448
+ case "withdrawn":
449
+ return "this page stopped being served inside the window, so only the earlier library holds it";
450
+ case "unchanged":
451
+ return "this page was served throughout the window and never republished, so both hold it";
452
+ }
453
+ };
454
+ /**
455
+ * The placings a caller already holds, as a source.
456
+ *
457
+ * Keyed by the published form rule (0293), so a page served in two forms is
458
+ * placed twice and a caller that placed only one of them has the other
459
+ * reported rather than carried along with it: a page can be published in a
460
+ * second form while its first form stands unchanged, which is the distinction
461
+ * `formsGained` exists for.
462
+ *
463
+ * The first placing of a form wins and the second is ignored, as in
464
+ * {@link treesIn}: two answers disagree about one page, nothing here can say
465
+ * which is right, and a silent last-wins would make the libraries depend on the
466
+ * order a caller's history came back in.
467
+ */
468
+ export const placingsIn = (placed) => {
469
+ const held = new Map();
470
+ for (const form of placed) {
471
+ const key = formKeyOf(form);
472
+ if (!held.has(key))
473
+ held.set(key, form.placing);
474
+ }
475
+ return { placingFor: (form) => held.get(formKeyOf(form)) };
476
+ };
477
+ /**
478
+ * Assemble a window's pairs into the two libraries the library comparisons
479
+ * take.
480
+ *
481
+ * The third step of this rung, and the one {@link windowPairsOf} named as a gap
482
+ * the day it was built. Five of the nine comparisons take two **readings**, and
483
+ * a pair is one of those; the four library comparisons take two whole
484
+ * **libraries** — every page as it stood before against every page as it stands
485
+ * now — and a window holds both of those too, but not by any arrangement of its
486
+ * pairs alone.
487
+ *
488
+ * After this, every one of the nine is one call off a window:
489
+ *
490
+ * ```ts
491
+ * const { pages } = windowReadingsOf(window, treesIn(trees), registry)
492
+ * const held = windowPairsOf(pages)
493
+ * const { was, now } = windowLibrariesOf(held, window.pageViews, placingsIn(history))
494
+ *
495
+ * const kinds = libraryChangeOf(was.readings, now.readings)
496
+ * const reach = libraryReachChangeOf(was, now)
497
+ * ```
498
+ *
499
+ * ## The one line that composes and is wrong
500
+ *
501
+ * ```ts
502
+ * libraryChangeOf(pairs.map(({ was }) => was), pairs.map(({ now }) => now))
503
+ * ```
504
+ *
505
+ * That type-checks, it runs, and the result does not say what it left out. It
506
+ * drops every form in {@link WindowPairs.unpaired} — which is exactly where **a
507
+ * page published inside the window** lands, because a page published inside the
508
+ * window has one revision in it. So a deployment that published two pages this
509
+ * week reads `pagesGained: 0`, which is the figure `libraryChangeOf` exists to
510
+ * report, beside a `pages` count that looks right.
511
+ *
512
+ * ## So the placing is asked for, and a form nobody can place is named
513
+ *
514
+ * A form with one revision is a page published, a page withdrawn, or a page
515
+ * nobody touched, and the counters cannot tell them apart —
516
+ * `StoredTally.updatedAt` is when the fold ran, not when the page went up. The
517
+ * revision numbers cannot either: a revision number is a count of revisions
518
+ * rather than a date, and a deployment that has pruned old counters has a form
519
+ * at revision 7 with nothing below it.
520
+ *
521
+ * So {@link FormPlacings} is handed in, which is the line §7 draws and the
522
+ * shape the region floor took: hold configuration you were handed rather than
523
+ * configuration you went looking for. A form the source cannot place is in
524
+ * {@link WindowLibraries.unplaced} and on neither side, because **both guesses
525
+ * are assertions** — the later side says a page nobody touched was published,
526
+ * and both sides say a page published this week was always there.
527
+ *
528
+ * Paired forms are never asked about. A form with two revisions in the window
529
+ * has its earlier revision in the earlier library and its later one in the
530
+ * later library, by construction, so there is nothing for a caller to answer
531
+ * and nothing of its answer to ignore.
532
+ *
533
+ * ## Two generations of revisions, which is not two moments
534
+ *
535
+ * The sides are the library at its earlier revisions against the library at its
536
+ * later ones, and `republished` on the comparison is the published count of how
537
+ * many pages that moved. It is **not** a window split in half: an `unchanged`
538
+ * form carries one reading onto both sides, so its views are the window's views
539
+ * on both — the page contributed no change because it was not changed, and
540
+ * `LibraryChange.viewsWas` and `viewsNow` are the floors a reader checks the
541
+ * comparability of two windows against rather than numbers to subtract.
542
+ *
543
+ * One consequence worth stating, because it is a limit rather than a rule: a
544
+ * page published **and** then revised inside one window has two revisions, so it
545
+ * is paired and lands on both sides rather than being counted as a page gained.
546
+ * `pagesGained` is therefore a count of the forms whose only revision is new.
547
+ *
548
+ * ## The rows are the window's own, and both sides read them
549
+ *
550
+ * {@link LibraryWindow.rows} is the whole window of door rows on each side, not
551
+ * a slice of them. Each page's own row is picked out by `pageViewsFor` on the
552
+ * revision and the form the reading names (0290), and the two sides name
553
+ * different revisions, so one array answers both without either side borrowing
554
+ * the other's arrivals.
555
+ *
556
+ * ## It adds no figure of its own
557
+ *
558
+ * Nothing here counts, divides, sums or withholds, which is the rule the first
559
+ * two steps set. It decides **which library each form is in** out of what it was
560
+ * told, and hands each side the readings it holds.
561
+ *
562
+ * Linear in the forms, but for the two sorts that publish them in one order.
563
+ */
564
+ export const windowLibrariesOf = (held, rows, placings) => {
565
+ const was = [];
566
+ const now = [];
567
+ const unplaced = [];
568
+ const seen = new Set();
569
+ let duplicated = 0;
570
+ const first = (form) => {
571
+ const key = formKeyOf(form);
572
+ if (seen.has(key)) {
573
+ duplicated += 1;
574
+ return false;
575
+ }
576
+ seen.add(key);
577
+ return true;
578
+ };
579
+ for (const pair of held.pairs) {
580
+ if (!first(pair))
581
+ continue;
582
+ was.push(pair.was);
583
+ now.push(pair.now);
584
+ }
585
+ for (const form of held.unpaired) {
586
+ if (!first(form))
587
+ continue;
588
+ const placing = placings.placingFor(form);
589
+ if (placing === undefined) {
590
+ unplaced.push(form);
591
+ continue;
592
+ }
593
+ switch (placing) {
594
+ case "published":
595
+ now.push(form.reading);
596
+ break;
597
+ case "withdrawn":
598
+ was.push(form.reading);
599
+ break;
600
+ case "unchanged":
601
+ was.push(form.reading);
602
+ now.push(form.reading);
603
+ break;
604
+ }
605
+ }
606
+ /**
607
+ * One published order for both sides, rather than pairs first and then the
608
+ * forms a placing put there. The comparisons key their pages by form and do
609
+ * not read the order, so this is for the caller that prints a side.
610
+ */
611
+ const inOneOrder = (readings) => [...readings].sort((one, other) => inFormOrder(formOf(one), formOf(other)));
612
+ return {
613
+ was: { readings: inOneOrder(was), rows },
614
+ now: { readings: inOneOrder(now), rows },
615
+ unplaced: unplaced.sort(inFormOrder),
616
+ duplicated,
617
+ };
618
+ };
619
+ /**
620
+ * Assemble a window into every subject a reading or a comparison of it takes.
621
+ *
622
+ * The fourth step of this rung and the one that makes the first three a
623
+ * question rather than a recipe. Each of them is published and each is
624
+ * separately useful; what is published nowhere is **the one order they compose
625
+ * in**, and that order is not free.
626
+ *
627
+ * ```ts
628
+ * const { readings, pairs, libraries } = windowAssemblyOf(window, context)
629
+ *
630
+ * const order = deploymentChangeOf(
631
+ * pairs.pairs.map(({ was, now }) => readingChangeOf(was, now)),
632
+ * window.pageViews
633
+ * )
634
+ * const kinds = libraryChangeOf(libraries.was.readings, libraries.now.readings)
635
+ * ```
636
+ *
637
+ * ## What a caller writing those three lines had to get right
638
+ *
639
+ * **The libraries take the pairs that `windowPairsOf` produced**, and the
640
+ * tempting one-liner over `pairs` alone drops every unpaired form — which is
641
+ * where a page published inside the window lands, and `pagesGained` is the
642
+ * figure a library comparison exists to report (0319). **The door rows are the
643
+ * window's whole set on both sides**, not a slice per side, because each page's
644
+ * own row is picked out on the revision and the form its reading names. **And
645
+ * the floor reaches the regions through the readings**, which is the one of the
646
+ * four context fields with no step of its own to be handed to.
647
+ *
648
+ * None of those is hard. All of them are invisible when wrong: the result of
649
+ * getting any of them wrong is a figure that is plausible and a total that goes
650
+ * on looking right, which is the one error in this subsystem that cannot be
651
+ * undone afterwards (0158).
652
+ *
653
+ * ## The two repeats it cannot have, which is the only safety it adds
654
+ *
655
+ * `WindowPairs.duplicated` and `WindowLibraries.duplicated` are **nought from
656
+ * here, by construction.** `windowReadingsOf` never produces two readings of
657
+ * one `readingKeyOf`, and `windowPairsOf` files each form in exactly one of its
658
+ * two lists — so nothing this hands on can put two readings of one form on one
659
+ * side of a library, which is the repeat that makes a page `ambiguous` to
660
+ * `pairedWindowOf` and takes it out of every figure in the comparison while the
661
+ * counts above it look unchanged.
662
+ *
663
+ * Both fields stay published and are carried as they come, because they are not
664
+ * nought for the callers they exist for: a surface that concatenated two
665
+ * windows' readings, or assembled a {@link WindowPairs} of its own, still has
666
+ * them counted. {@link WindowRegionReadings.duplicated} is the one that can be
667
+ * other than nought from here, because a region row repeated under one bucket
668
+ * key is a repeat in the rows a caller was handed rather than one this made.
669
+ *
670
+ * ## It adds no figure, and publishes no total of what was dropped
671
+ *
672
+ * Nothing here counts, divides, sums or withholds — the rule all three steps
673
+ * under it keep. In particular there is deliberately **no one number for what
674
+ * the assembly left out**: the three `duplicated` counts are a count of region
675
+ * rows, a count of readings and a count of forms, and `unjoined`, `unpaired`
676
+ * and `unplaced` are three different reasons a page is absent from three
677
+ * different answers. A sum over them would be a figure in no unit at all, and
678
+ * the shortest way to a screen that reports *4 pages dropped* about one page.
679
+ *
680
+ * Linear in the window, being three linear passes over it.
681
+ */
682
+ export const windowAssemblyOf = (window, context) => {
683
+ const readings = windowReadingsOf(window, context.trees, context.declarations, {
684
+ floor: context.floor,
685
+ });
686
+ const pairs = windowPairsOf(readings.pages);
687
+ return {
688
+ readings,
689
+ pairs,
690
+ libraries: windowLibrariesOf(pairs, window.pageViews, context.placings),
691
+ };
692
+ };
693
+ //# sourceMappingURL=window.js.map