@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,361 @@
1
+ import { everyMemberOf } from "../closed-set.js";
2
+ import { audienceScopeRead, comparedAudiencesOf, crossesAudiences, } from "./audiences.js";
3
+ import { funnelPairKey } from "./funnel.js";
4
+ import { ratioOf } from "./ratios.js";
5
+ /** The closed set, for a surface that has to account for every absent figure. */
6
+ export const FUNNEL_CHANGE_SILENCES = everyMemberOf()([
7
+ "different-trees",
8
+ "different-audiences",
9
+ "audiences-mixed",
10
+ "unscaled",
11
+ "unopened",
12
+ "uncounted",
13
+ "unasked",
14
+ ]);
15
+ /** One line per silence, for a surface saying why a figure is not there. */
16
+ export const describeFunnelChangeSilence = (silence) => {
17
+ switch (silence) {
18
+ case "different-trees":
19
+ return "the two readings are of different pages";
20
+ case "different-audiences":
21
+ return "the two readings are of different audiences, and so of different readers";
22
+ case "audiences-mixed":
23
+ return "one of the two windows holds two forms of the page and says which readers neither";
24
+ case "unscaled":
25
+ return "one of the two windows has no count of the readers who arrived";
26
+ case "unopened":
27
+ return "one of the two windows has nothing saying a page view began";
28
+ case "uncounted":
29
+ return "one of the two windows has arrivals no rollup has counted yet";
30
+ case "unasked":
31
+ return "the two windows have no funnel question in common";
32
+ }
33
+ };
34
+ /** The closed set, for a surface accounting for every pair it was handed. */
35
+ export const FUNNEL_MOVEMENTS = everyMemberOf()([
36
+ "taken-up",
37
+ "abandoned",
38
+ "still-unconverted",
39
+ "held",
40
+ "unknown",
41
+ ]);
42
+ /** One line per movement, for a surface putting a funnel in front of a person. */
43
+ export const describeFunnelMovement = (movement) => {
44
+ switch (movement) {
45
+ case "taken-up":
46
+ return "readers got to the start of this funnel and none finished it, and now some do";
47
+ case "abandoned":
48
+ return "readers finished this funnel, and now they get to its start and do not";
49
+ case "still-unconverted":
50
+ return "readers get to the start of this funnel and do not finish it, before and after";
51
+ case "held":
52
+ return "readers finished this funnel, before and after";
53
+ case "unknown":
54
+ return "one of the two windows cannot say whether readers finished it";
55
+ }
56
+ };
57
+ /** The closed set, for a surface accounting for every compared pair. */
58
+ export const QUESTION_MOVEMENTS = everyMemberOf()([
59
+ "asked",
60
+ "broken",
61
+ "restored",
62
+ "stale",
63
+ ]);
64
+ /** One line per movement, for a surface saying what a change did to a question. */
65
+ export const describeQuestionMovement = (movement) => {
66
+ switch (movement) {
67
+ case "asked":
68
+ return "both revisions have the parts this question names";
69
+ case "broken":
70
+ return "the change removed a part this question names, so it can no longer be answered";
71
+ case "restored":
72
+ return "the change put back a part this question names, so it can be answered again";
73
+ case "stale":
74
+ return "neither revision has a part this question names";
75
+ }
76
+ };
77
+ /**
78
+ * The closed set, and it is **one member shorter than every other
79
+ * counterfactual here**, which is a property of the arithmetic rather than a
80
+ * decision.
81
+ *
82
+ * 0244 and 0279 both publish a fourth answer — *neither alone was enough and
83
+ * the two together were* — and both need it, because the figure they split is a
84
+ * sum: traffic can move toward the places whose reading moved, and the
85
+ * interaction is then the whole of the movement.
86
+ *
87
+ * **A product has no such case.** The two counterfactuals of a product multiply
88
+ * to the product of the two levels: `(entryNow × rateWas) × (entryWas ×
89
+ * rateNow) = conversionWas × conversionNow`. So if the conversion share rose,
90
+ * the two counterfactuals multiply to more than `conversionWas` squared and at
91
+ * least one of them is above it; if it fell, at least one is below. Neither
92
+ * being enough is arithmetically unreachable, and publishing a member for it
93
+ * would be a state a surface had to handle and nothing could ever produce.
94
+ */
95
+ export const CONVERSION_CAUSES = everyMemberOf()([
96
+ "entry",
97
+ "closing",
98
+ "either",
99
+ ]);
100
+ /** One line per cause, for a surface saying what moved a conversion share. */
101
+ export const describeConversionCause = (cause) => {
102
+ switch (cause) {
103
+ case "entry":
104
+ return "the readers who got to the start of the funnel would have moved it on their own";
105
+ case "closing":
106
+ return "the share of them who finished would have moved it on its own";
107
+ case "either":
108
+ return "either would have moved it on its own";
109
+ }
110
+ };
111
+ const NO_MOVEMENTS = Object.freeze({
112
+ "taken-up": 0,
113
+ abandoned: 0,
114
+ "still-unconverted": 0,
115
+ held: 0,
116
+ unknown: 0,
117
+ });
118
+ const NO_QUESTIONS = Object.freeze({
119
+ asked: 0,
120
+ broken: 0,
121
+ restored: 0,
122
+ stale: 0,
123
+ });
124
+ /**
125
+ * The door's state, said of the pair rather than of either window.
126
+ *
127
+ * Taken in the set's own order so that two windows in two different states
128
+ * report the worse of them, which is the rule a deployment reading reports one
129
+ * state for a pair of pages by (0240): the condition is what the two sides have
130
+ * in common and no more, and each side's own reading carries which it was.
131
+ */
132
+ const doorSilenceOf = (was, now) => {
133
+ const sides = [was.silence, now.silence];
134
+ if (sides.includes("unmeasured"))
135
+ return "unscaled";
136
+ if (sides.includes("unopened"))
137
+ return "unopened";
138
+ if (sides.includes("uncounted"))
139
+ return "uncounted";
140
+ return null;
141
+ };
142
+ const questionMovementOf = (was, now) => {
143
+ if (!was.stale && !now.stale)
144
+ return "asked";
145
+ if (!was.stale)
146
+ return "broken";
147
+ return now.stale ? "stale" : "restored";
148
+ };
149
+ const movementOf = (was, now) => {
150
+ if (was.rate === null || now.rate === null)
151
+ return "unknown";
152
+ const before = was.converted > 0;
153
+ const after = now.converted > 0;
154
+ if (before && after)
155
+ return "held";
156
+ if (after)
157
+ return "taken-up";
158
+ return before ? "abandoned" : "still-unconverted";
159
+ };
160
+ /**
161
+ * Which side was enough on its own, by the direction each counterfactual
162
+ * carries — the sufficiency rule the two earlier counterfactuals here publish
163
+ * (0244, 0279), asked of a product.
164
+ *
165
+ * Published rather than private so that the one answer a funnel cannot produce
166
+ * can be shown to be handled rather than argued away: handed four numbers that
167
+ * are not a funnel's two factors, where neither counterfactual carries the
168
+ * movement, it returns `null` rather than attributing the movement to a side
169
+ * that did not cause it.
170
+ *
171
+ * `null` where nothing moved, which is the rule both earlier counterfactuals
172
+ * state: a figure that did not move has nothing to attribute.
173
+ */
174
+ export const conversionCauseOf = (was, now, ifOnlyEntryMoved, ifOnlyClosingMoved) => {
175
+ const direction = Math.sign(now - was);
176
+ if (direction === 0)
177
+ return null;
178
+ const entry = Math.sign(ifOnlyEntryMoved - was) === direction;
179
+ const closing = Math.sign(ifOnlyClosingMoved - was) === direction;
180
+ if (entry && closing)
181
+ return "either";
182
+ if (entry)
183
+ return "entry";
184
+ return closing ? "closing" : null;
185
+ };
186
+ const comparedOf = (pair, was, now, opened) => {
187
+ const rateRatio = ratioOf(was.rate, now.rate);
188
+ /**
189
+ * Both ends of the bracket or neither, because half of an interval is a
190
+ * figure a surface would draw as a bound. `was.rateAtMost` is at least
191
+ * `was.rate` and `was.rate` is above nought wherever there is a ratio at all,
192
+ * so neither division here can be by nought.
193
+ */
194
+ const bracket = rateRatio.ratio !== null && was.rate !== null && now.rate !== null
195
+ ? was.rateAtMost !== null && now.rateAtMost !== null
196
+ ? {
197
+ atLeast: now.rate / was.rateAtMost,
198
+ atMost: now.rateAtMost / was.rate,
199
+ }
200
+ : null
201
+ : null;
202
+ /**
203
+ * The counterfactuals use each side's own `rate`, which is the figure the
204
+ * reading publishes as its estimate: a sufficiency verdict needs the two
205
+ * diagonals of one table, and mixing an estimate on one diagonal with a
206
+ * ceiling on the other would answer a question neither window was asked.
207
+ */
208
+ const entryWas = was.entry.share;
209
+ const entryNow = now.entry.share;
210
+ const conversionWas = was.conversion.share;
211
+ const conversionNow = now.conversion.share;
212
+ const measured = entryWas !== null &&
213
+ entryNow !== null &&
214
+ conversionWas !== null &&
215
+ conversionNow !== null &&
216
+ was.rate !== null &&
217
+ now.rate !== null;
218
+ const ifOnlyEntryMoved = measured ? entryNow * was.rate : null;
219
+ const ifOnlyClosingMoved = measured ? entryWas * now.rate : null;
220
+ return {
221
+ pair,
222
+ was,
223
+ now,
224
+ movement: movementOf(was, now),
225
+ question: questionMovementOf(was, now),
226
+ rateRatio,
227
+ rateRatioAtLeast: bracket?.atLeast ?? null,
228
+ rateRatioAtMost: bracket?.atMost ?? null,
229
+ rateMoved: bracket === null ? null : bracket.atLeast > 1 || bracket.atMost < 1,
230
+ entryRatio: ratioOf(entryWas, entryNow),
231
+ conversionRatio: ratioOf(conversionWas, conversionNow),
232
+ ifOnlyEntryMoved,
233
+ ifOnlyClosingMoved,
234
+ cause: conversionWas === null ||
235
+ conversionNow === null ||
236
+ ifOnlyEntryMoved === null ||
237
+ ifOnlyClosingMoved === null
238
+ ? null
239
+ : conversionCauseOf(conversionWas, conversionNow, ifOnlyEntryMoved, ifOnlyClosingMoved),
240
+ readersMoved: conversionWas === null || conversionNow === null
241
+ ? null
242
+ : (conversionNow - conversionWas) * opened,
243
+ };
244
+ };
245
+ /** One question per key, later occurrences dropped and counted (0158). */
246
+ const byQuestion = (pairs) => {
247
+ const byKey = new Map();
248
+ let duplicated = 0;
249
+ for (const pair of pairs) {
250
+ const key = funnelPairKey(pair.pair);
251
+ if (byKey.has(key)) {
252
+ duplicated += 1;
253
+ continue;
254
+ }
255
+ byKey.set(key, pair);
256
+ }
257
+ return { pairs: byKey, duplicated };
258
+ };
259
+ /** The one that moved more, `>` keeping the first in the compared order on a tie. */
260
+ const furtherOf = (standing, next, sign) => {
261
+ const moved = next.readersMoved;
262
+ if (moved === null || moved * sign <= 0)
263
+ return standing;
264
+ if (standing === null)
265
+ return next;
266
+ return moved * sign > (standing.readersMoved ?? 0) * sign ? next : standing;
267
+ };
268
+ /**
269
+ * Hold two windows of one page's funnels against each other.
270
+ *
271
+ * Both sides are readings `funnelReachOf` built, so the revision each belongs
272
+ * to, the rows it dropped and the arrivals it was read against travel with it
273
+ * and nothing is inferred here (0231).
274
+ *
275
+ * Linear in the pairs of the two readings, with one pass over each.
276
+ */
277
+ export const funnelChangeOf = (was, now) => {
278
+ const earlier = byQuestion(was.pairs);
279
+ const later = byQuestion(now.pairs);
280
+ const duplicated = earlier.duplicated + later.duplicated;
281
+ const empty = {
282
+ treeId: was.treeId,
283
+ revisions: { was: was.revision, now: now.revision },
284
+ audiences: comparedAudiencesOf(was, now),
285
+ readings: { was, now },
286
+ movements: NO_MOVEMENTS,
287
+ questions: NO_QUESTIONS,
288
+ mostGained: null,
289
+ mostLost: null,
290
+ undecided: 0,
291
+ exact: false,
292
+ duplicated,
293
+ };
294
+ /** The two states in which no question is held against any other. */
295
+ const refusing = (silence) => ({
296
+ ...empty,
297
+ compared: [],
298
+ added: [],
299
+ removed: [],
300
+ silence,
301
+ });
302
+ if (was.treeId !== now.treeId)
303
+ return refusing("different-trees");
304
+ if (crossesAudiences(was, now))
305
+ return refusing("different-audiences");
306
+ /**
307
+ * Refused rather than paired, because an empty side **pairs cleanly**: a
308
+ * reading that was read as neither form holds no question, so every question
309
+ * of the other side comes back as added or removed and the comparison reads
310
+ * as *the change added every funnel question you ask* about a window that was
311
+ * simply never read. Taken beside the other two refusals, so that all three
312
+ * states of the pair are settled before any question is held against any
313
+ * other.
314
+ */
315
+ if (audienceScopeRead(was).reading === "mixed" || audienceScopeRead(now).reading === "mixed")
316
+ return refusing("audiences-mixed");
317
+ const keys = [...earlier.pairs.keys(), ...later.pairs.keys()].sort((one, other) => one.localeCompare(other));
318
+ const added = [...later.pairs].filter(([key]) => !earlier.pairs.has(key)).map(([, pair]) => pair);
319
+ const removed = [...earlier.pairs]
320
+ .filter(([key]) => !later.pairs.has(key))
321
+ .map(([, pair]) => pair);
322
+ const door = doorSilenceOf(was, now);
323
+ const movements = { ...NO_MOVEMENTS };
324
+ const questions = { ...NO_QUESTIONS };
325
+ const compared = [];
326
+ let mostGained = null;
327
+ let mostLost = null;
328
+ let undecided = 0;
329
+ const seen = new Set();
330
+ for (const key of keys) {
331
+ if (seen.has(key))
332
+ continue;
333
+ seen.add(key);
334
+ const before = earlier.pairs.get(key);
335
+ const after = later.pairs.get(key);
336
+ if (before === undefined || after === undefined)
337
+ continue;
338
+ const row = comparedOf(after.pair, before, after, now.opened);
339
+ compared.push(row);
340
+ movements[row.movement] += 1;
341
+ questions[row.question] += 1;
342
+ if (row.rateMoved === false)
343
+ undecided += 1;
344
+ mostGained = furtherOf(mostGained, row, 1);
345
+ mostLost = furtherOf(mostLost, row, -1);
346
+ }
347
+ return {
348
+ ...empty,
349
+ compared,
350
+ added,
351
+ removed,
352
+ movements,
353
+ questions,
354
+ mostGained,
355
+ mostLost,
356
+ undecided,
357
+ exact: door === null && was.exact && now.exact,
358
+ silence: door ?? (compared.length === 0 ? "unasked" : null),
359
+ };
360
+ };
361
+ //# sourceMappingURL=funnel-change.js.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The eighth contract suite both reader-signal tally stores are run against: **a
3
+ * funnel pair's answer filed under the hour the readers in it entered it, and a
4
+ * pair's hours summing to the pair's own row** (`funnel-hours.ts`).
5
+ *
6
+ * Here rather than beside the three in `src/testing/reader-signal-contract.ts`
7
+ * for the reason the arrivals and acted suites are: that directory is another
8
+ * lane's and this is reader-signal work.
9
+ *
10
+ * **Every property here needs two implementations to be worth asserting**, and
11
+ * they are the three hazards the two hourly suites before it name, one table
12
+ * deeper. The hour is a `timestamptz` in one store and a number in the other;
13
+ * the four end columns are a pair in one and an object in the other, so *what
14
+ * makes two rows the same question* is answered twice; and two rows naming one
15
+ * pair-hour inside a single call are an `ON CONFLICT` Postgres **raises** on
16
+ * and a `Map` silently overwrites. Each is a way for a step's two sides to stop
17
+ * summing to the step's own figure, which is permanent (0158).
18
+ */
19
+ import type { ReaderTallyStore } from "./tally.js";
20
+ export declare const describeFunnelHourContract: (name: string, make: () => Promise<ReaderTallyStore> | ReaderTallyStore) => void;
21
+ //# sourceMappingURL=funnel-hours.contract.d.ts.map
@@ -0,0 +1,221 @@
1
+ /**
2
+ * The eighth contract suite both reader-signal tally stores are run against: **a
3
+ * funnel pair's answer filed under the hour the readers in it entered it, and a
4
+ * pair's hours summing to the pair's own row** (`funnel-hours.ts`).
5
+ *
6
+ * Here rather than beside the three in `src/testing/reader-signal-contract.ts`
7
+ * for the reason the arrivals and acted suites are: that directory is another
8
+ * lane's and this is reader-signal work.
9
+ *
10
+ * **Every property here needs two implementations to be worth asserting**, and
11
+ * they are the three hazards the two hourly suites before it name, one table
12
+ * deeper. The hour is a `timestamptz` in one store and a number in the other;
13
+ * the four end columns are a pair in one and an object in the other, so *what
14
+ * makes two rows the same question* is answered twice; and two rows naming one
15
+ * pair-hour inside a single call are an `ON CONFLICT` Postgres **raises** on
16
+ * and a `Map` silently overwrites. Each is a way for a step's two sides to stop
17
+ * summing to the step's own figure, which is permanent (0158).
18
+ */
19
+ import { describe, expect, it } from "vitest";
20
+ import { nodeId, OTHER_TREE, RIDERS, SKIERS, TREE } from "../testing/reader-signal-contract.js";
21
+ import { ARRIVAL_HOUR_MS } from "./arrivals.js";
22
+ const HOUR = ARRIVAL_HOUR_MS;
23
+ const MIDNIGHT = Date.parse("2026-11-06T00:00:00.000Z");
24
+ const at = (hour, minutes = 0) => new Date(MIDNIGHT + hour * HOUR + minutes * 60_000).toISOString();
25
+ const hourOf = (hour) => MIDNIGHT + hour * HOUR;
26
+ const PAIR = {
27
+ from: { nodeId: nodeId("pricing"), kind: "viewed" },
28
+ to: { nodeId: nodeId("buy"), kind: "activated" },
29
+ };
30
+ /** A second question over the same first end, which is the one a read must not sum in. */
31
+ const OTHER_PAIR = {
32
+ from: { nodeId: nodeId("pricing"), kind: "viewed" },
33
+ to: { nodeId: nodeId("signup"), kind: "completed" },
34
+ };
35
+ const entered = (hour, overrides = {}) => ({
36
+ treeId: TREE,
37
+ revision: 1,
38
+ pair: PAIR,
39
+ hour: hourOf(hour),
40
+ reached: 4,
41
+ converted: 1,
42
+ ...overrides,
43
+ });
44
+ const unwrap = (result) => {
45
+ if (!result.ok)
46
+ throw new Error(result.error.detail);
47
+ return result.value;
48
+ };
49
+ export const describeFunnelHourContract = (name, make) => {
50
+ describe(`${name} — a funnel, by the hour its readers entered it`, () => {
51
+ const counted = async () => {
52
+ const store = await make();
53
+ unwrap(await store.apply({ tallies: [], funnels: [], funnelHours: [entered(9)] }, at(9, 30), SKIERS));
54
+ return store;
55
+ };
56
+ it("files a cohort under the hour it was folded with", async () => {
57
+ const store = await counted();
58
+ const { hours } = unwrap(await store.funnelHours());
59
+ expect(hours).toEqual([
60
+ {
61
+ audienceId: SKIERS,
62
+ treeId: TREE,
63
+ revision: 1,
64
+ pair: PAIR,
65
+ hour: hourOf(9),
66
+ reached: 4,
67
+ converted: 1,
68
+ updatedAt: at(9, 30),
69
+ },
70
+ ]);
71
+ });
72
+ it("adds a second window's cohort to the same pair-hour", async () => {
73
+ const store = await counted();
74
+ unwrap(await store.apply({ tallies: [], funnels: [], funnelHours: [entered(9)] }, at(9, 55), SKIERS));
75
+ const { hours } = unwrap(await store.funnelHours());
76
+ expect(hours).toHaveLength(1);
77
+ expect(hours[0]).toMatchObject({ reached: 8, converted: 2 });
78
+ });
79
+ it("keeps the next hour's cohort in its own row", async () => {
80
+ const store = await counted();
81
+ unwrap(await store.apply({ tallies: [], funnels: [], funnelHours: [entered(10)] }, at(10), SKIERS));
82
+ const { hours } = unwrap(await store.funnelHours());
83
+ expect(hours.map((row) => [row.hour, row.reached])).toEqual(expect.arrayContaining([
84
+ [hourOf(9), 4],
85
+ [hourOf(10), 4],
86
+ ]));
87
+ });
88
+ /**
89
+ * Two rows naming one pair-hour inside a single call are added, which is the
90
+ * guarantee `counters.ts` gives in front of the driver: Postgres refuses to
91
+ * affect one row twice in one command and a `Map` would keep the last.
92
+ */
93
+ it("adds two rows of one pair-hour handed over together", async () => {
94
+ const store = await make();
95
+ unwrap(await store.apply({
96
+ tallies: [],
97
+ funnels: [],
98
+ funnelHours: [entered(9), entered(9, { reached: 2, converted: 2 })],
99
+ }, at(9), SKIERS));
100
+ const { hours } = unwrap(await store.funnelHours());
101
+ expect(hours).toHaveLength(1);
102
+ expect(hours[0]).toMatchObject({ reached: 6, converted: 3 });
103
+ });
104
+ /**
105
+ * The identity both stores have to agree about: two questions over the same
106
+ * first end are two rows, and a read of one must not sum the other's — the
107
+ * same page view is in both.
108
+ */
109
+ it("keeps two questions over one first end apart", async () => {
110
+ const store = await counted();
111
+ unwrap(await store.apply({ tallies: [], funnels: [], funnelHours: [entered(9, { pair: OTHER_PAIR })] }, at(9, 45), SKIERS));
112
+ expect(unwrap(await store.funnelHours()).hours).toHaveLength(2);
113
+ const mine = unwrap(await store.funnelHours({ pair: PAIR })).hours;
114
+ expect(mine).toHaveLength(1);
115
+ expect(mine[0]).toMatchObject({ pair: PAIR, reached: 4 });
116
+ });
117
+ it("reads a question asked with a scope as the same question, because a row carries none", async () => {
118
+ const store = await counted();
119
+ const { hours } = unwrap(await store.funnelHours({ pair: { ...PAIR, pages: [TREE] } }));
120
+ expect(hours).toHaveLength(1);
121
+ expect(hours[0]?.pair).toEqual(PAIR);
122
+ });
123
+ it("keeps an hour of two audiences apart (0284)", async () => {
124
+ const store = await counted();
125
+ unwrap(await store.apply({ tallies: [], funnels: [], funnelHours: [entered(9)] }, at(9), RIDERS));
126
+ expect(unwrap(await store.funnelHours()).hours).toHaveLength(2);
127
+ expect(unwrap(await store.funnelHours({ audience: RIDERS })).hours[0]).toMatchObject({
128
+ reached: 4,
129
+ });
130
+ });
131
+ it("keeps an hour of two trees apart", async () => {
132
+ const store = await counted();
133
+ unwrap(await store.apply({ tallies: [], funnels: [], funnelHours: [entered(9, { treeId: OTHER_TREE })] }, at(9), SKIERS));
134
+ expect(unwrap(await store.funnelHours()).hours).toHaveLength(2);
135
+ expect(unwrap(await store.funnelHours({ treeId: TREE })).hours).toHaveLength(1);
136
+ });
137
+ it("keeps an hour of two revisions apart, so a change can be read across one", async () => {
138
+ const store = await counted();
139
+ unwrap(await store.apply({ tallies: [], funnels: [], funnelHours: [entered(9, { revision: 2 })] }, at(9), SKIERS));
140
+ expect(unwrap(await store.funnelHours()).hours).toHaveLength(2);
141
+ expect(unwrap(await store.funnelHours({ revision: 2 })).hours[0]).toMatchObject({ reached: 4 });
142
+ });
143
+ it("writes nothing for a window nobody entered a funnel in", async () => {
144
+ const store = await make();
145
+ unwrap(await store.apply({ tallies: [], funnels: [], funnelHours: [] }, at(9), SKIERS));
146
+ expect(unwrap(await store.funnelHours()).hours).toEqual([]);
147
+ expect(unwrap(await store.funnelHours()).begins).toBeUndefined();
148
+ });
149
+ describe("over a range", () => {
150
+ const spread = async () => {
151
+ const store = await make();
152
+ for (const hour of [1, 5, 9]) {
153
+ unwrap(await store.apply({ tallies: [], funnels: [], funnelHours: [entered(hour, { reached: hour })] }, at(hour), SKIERS));
154
+ }
155
+ return store;
156
+ };
157
+ it("holds the hours from the start of the range to the end, and not the ends' neighbours", async () => {
158
+ const store = await spread();
159
+ const { hours } = unwrap(await store.funnelHours({ from: hourOf(5), to: hourOf(9) }));
160
+ expect(hours.map((row) => row.reached)).toEqual([5]);
161
+ });
162
+ it("is unbounded on a side the request leaves out", async () => {
163
+ const store = await spread();
164
+ expect(unwrap(await store.funnelHours({ to: hourOf(9) })).hours).toHaveLength(2);
165
+ expect(unwrap(await store.funnelHours({ from: hourOf(5) })).hours).toHaveLength(2);
166
+ });
167
+ it("answers an empty range with no hours and the beginning still named", async () => {
168
+ const store = await spread();
169
+ const read = unwrap(await store.funnelHours({ from: hourOf(20), to: hourOf(21) }));
170
+ expect(read.hours).toEqual([]);
171
+ expect(read.begins).toBe(hourOf(1));
172
+ });
173
+ });
174
+ describe("the hour counting began", () => {
175
+ it("is the earliest hour the scope has, whatever range was asked for", async () => {
176
+ const store = await make();
177
+ unwrap(await store.apply({ tallies: [], funnels: [], funnelHours: [entered(9)] }, at(9), SKIERS));
178
+ unwrap(await store.apply({ tallies: [], funnels: [], funnelHours: [entered(2)] }, at(2), SKIERS));
179
+ expect(unwrap(await store.funnelHours({ from: hourOf(9), to: hourOf(10) })).begins).toBe(hourOf(2));
180
+ });
181
+ /**
182
+ * The clause a step's two sides depend on: a step set this afternoon has
183
+ * been measurable since this afternoon, and a beginning taken over the
184
+ * deployment would draw a fortnight of noughts before the question
185
+ * existed and call the step a collapse.
186
+ */
187
+ it("narrows to the pair, so a step says when its own question was first counted", async () => {
188
+ const store = await make();
189
+ unwrap(await store.apply({ tallies: [], funnels: [], funnelHours: [entered(2)] }, at(2), SKIERS));
190
+ unwrap(await store.apply({ tallies: [], funnels: [], funnelHours: [entered(9, { pair: OTHER_PAIR })] }, at(9), SKIERS));
191
+ expect(unwrap(await store.funnelHours({ pair: OTHER_PAIR })).begins).toBe(hourOf(9));
192
+ });
193
+ it("is absent where nothing has ever been counted", async () => {
194
+ const store = await make();
195
+ expect(unwrap(await store.funnelHours()).begins).toBeUndefined();
196
+ });
197
+ });
198
+ /**
199
+ * The invariant the whole design rests on: the hourly rows are a cut of the
200
+ * answers, so a window's hours add up to the same reaches and conversions
201
+ * its answers carry. Both are written here by one call, which is what the
202
+ * fold does.
203
+ */
204
+ it("holds the same reaches and conversions as the answer it cuts", async () => {
205
+ const store = await make();
206
+ unwrap(await store.apply({
207
+ tallies: [],
208
+ funnels: [{ treeId: TREE, revision: 1, pair: PAIR, reached: 7, converted: 3 }],
209
+ funnelHours: [
210
+ entered(9, { reached: 4, converted: 2 }),
211
+ entered(10, { reached: 3, converted: 1 }),
212
+ ],
213
+ }, at(10), SKIERS));
214
+ const answers = unwrap(await store.funnels());
215
+ const { hours } = unwrap(await store.funnelHours({ pair: PAIR }));
216
+ expect(hours.reduce((total, row) => total + row.reached, 0)).toBe(answers[0]?.reached);
217
+ expect(hours.reduce((total, row) => total + row.converted, 0)).toBe(answers[0]?.converted);
218
+ });
219
+ });
220
+ };
221
+ //# sourceMappingURL=funnel-hours.contract.js.map