@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,254 @@
1
+ import { err, ok } from "../result.js";
2
+ import { ratioOf } from "./ratios.js";
3
+ /**
4
+ * **When** readers arrived, which is the one thing every counter in this
5
+ * subsystem had thrown away.
6
+ *
7
+ * `page-views.ts` counts the page views that *began* on a revision — exact,
8
+ * counted once, at the door, from the marker a delivery carries
9
+ * ([0214](../../decisions/0214-where-readers-are-is-a-floored-bucket-counted-at-the-door-and-a-page-view-says-when-it-began.md)).
10
+ * It is one number per revision for all time, so it can answer *how many
11
+ * readers* and can never answer *how many yesterday*. Nothing else could
12
+ * either: a tally keeps no time (rule 5 of `docs/signals.md`), and the only
13
+ * rows with an instant on them are the kept deliveries, which are paged by
14
+ * delivery and bounded by the window a deployment keeps them for (0351). A
15
+ * thirty-day chart read from those is thirty days of rows on every render, and
16
+ * a bar drawn from a capped scan is a **wrong number** rather than a shorter
17
+ * list — which is why `Loom portal` filed for this rather than drawing one.
18
+ *
19
+ * So this is the third thing derived from the same marker, after the opening
20
+ * count and the region bucket: **the same arrivals, filed under the hour they
21
+ * arrived in.** Nothing is sent for it, nothing is stored about anybody, and
22
+ * the browser is not involved — the hour is the instant the door was already
23
+ * stamping every counter this delivery moves.
24
+ *
25
+ * ## Why it is a counter and not a read of the kept deliveries
26
+ *
27
+ * The deliveries could answer it, twice over, and both routes are worse.
28
+ *
29
+ * - **Grouping the kept rows by `view` key** and taking each key's earliest
30
+ * receipt is a scan of the whole kept window, and it is a query *about view
31
+ * keys* — the one value in this seam that exists so a funnel can be
32
+ * correlated inside one page view and for nothing else (0146). A counter that
33
+ * needs no key at all is strictly the safer of the two.
34
+ * - **Counting deliveries per hour** needs neither, and counts a reader who
35
+ * stayed ten minutes as a hundred readers. 0214 refused that shape for the
36
+ * region map and it is refused here for the same reason.
37
+ *
38
+ * And a counter answers for as long as the counters live, where either read
39
+ * answers only for the kept window. **The hour outlives the row it could have
40
+ * been derived from**, which is the one consequence of this worth saying out
41
+ * loud rather than leaving to be noticed: a deployment that keeps deliveries
42
+ * for thirty days can still say how many readers arrived in an hour last year.
43
+ * It names no reader, no place and no page view — it is a count of page views
44
+ * of one revision, which is the figure `page-views.ts` already calls *nowhere
45
+ * and nobody* — but it is a count against a clock, and that is new.
46
+ *
47
+ * ## The hour is the unit
48
+ *
49
+ * Finer is not available and coarser would not serve the screen that asked.
50
+ * A *last 24 hours* chart needs twenty-four bars, so a day bucket cannot draw
51
+ * it; a minute bucket is sixty times the rows for a resolution no reading has
52
+ * ever asked for. A surface wanting days sums hours, which is addition over
53
+ * counts that were each counted once.
54
+ *
55
+ * **The hour is UTC and the bucket is its start instant.** A deployment that
56
+ * draws local time shifts the labels, which is a decision about a reader's
57
+ * screen rather than about a counter; storing an offset would make the same row
58
+ * mean two things in two places.
59
+ *
60
+ * Pure: no store, no clock, no DOM, and no import that reaches a package.
61
+ */
62
+ /** One hour, in milliseconds, which is the bucket every row here is filed in. */
63
+ export const ARRIVAL_HOUR_MS = 3_600_000;
64
+ /**
65
+ * The hour an instant falls in, as the instant that hour began.
66
+ *
67
+ * `undefined` where the argument is not an instant. It is the caller's clock
68
+ * and so should never be, but the alternative to saying so is a bucket of
69
+ * `NaN` in a counter — and a counter row nothing can read is worse than a
70
+ * write that refused.
71
+ */
72
+ export const arrivalHourOf = (instant) => {
73
+ const at = Date.parse(instant);
74
+ return Number.isFinite(at) ? Math.floor(at / ARRIVAL_HOUR_MS) * ARRIVAL_HOUR_MS : undefined;
75
+ };
76
+ /**
77
+ * What one delivery adds, which is its openings filed under the hour the door
78
+ * read them in.
79
+ *
80
+ * **It is handed the openings rather than the delivery**, exactly as
81
+ * `regionCountsOf` is and for the same reason: the walk that finds them, and
82
+ * the deduplication that makes a retried opening inside one delivery a single
83
+ * arrival, is `openingsOf` in `page-views.ts`. Three counters derived from one
84
+ * walk cannot disagree about how many readers arrived; three walks would, and
85
+ * the disagreement would surface as an hourly chart whose bars do not sum to
86
+ * the number of page views there were.
87
+ *
88
+ * **The instant is the one every other counter on this delivery is stamped
89
+ * with**, so an hour is never a second opinion about when the delivery was
90
+ * received. A failure rather than an empty list where that instant will not
91
+ * parse: openings written to one counter and not the other would make the two
92
+ * numbers differ for a reason no reading could name.
93
+ */
94
+ export const arrivalHoursOf = (openings, at) => {
95
+ if (openings.length === 0)
96
+ return ok([]);
97
+ const hour = arrivalHourOf(at);
98
+ if (hour === undefined) {
99
+ return err({
100
+ code: "unavailable",
101
+ detail: `could not place ${openings.length} page views in an hour: ${at} is not an instant`,
102
+ });
103
+ }
104
+ return ok(openings.map(({ treeId, revision, views }) => ({ treeId, revision, hour, views })));
105
+ };
106
+ /**
107
+ * The whole hours ending with the hour an instant falls in.
108
+ *
109
+ * `arrivalRangeOf(now, 24)` is *the last 24 hours*: twenty-three hours that are
110
+ * over and the one in progress. Hour-aligned on both ends, which is what the
111
+ * comparison needs — {@link arrivalRangeBefore} of an aligned range is aligned, so the
112
+ * two periods a change is taken over hold the same number of buckets, and a
113
+ * percentage of two honest counts stays honest.
114
+ */
115
+ export const arrivalRangeOf = (now, hours) => {
116
+ const current = Math.floor(now / ARRIVAL_HOUR_MS) * ARRIVAL_HOUR_MS;
117
+ return {
118
+ from: current - (Math.max(1, Math.trunc(hours)) - 1) * ARRIVAL_HOUR_MS,
119
+ to: current + ARRIVAL_HOUR_MS,
120
+ };
121
+ };
122
+ const hourAt = (instant) => Math.floor(instant / ARRIVAL_HOUR_MS) * ARRIVAL_HOUR_MS;
123
+ /** The first bucket of a range, which is the first hour that begins inside it. */
124
+ const firstHourOf = (from) => Math.ceil(from / ARRIVAL_HOUR_MS) * ARRIVAL_HOUR_MS;
125
+ /**
126
+ * The hours of a range, as the counter answers for them.
127
+ *
128
+ * Rows are summed into their hour, which is what makes this readable over a
129
+ * scope holding several trees, revisions or audiences: **arrivals add**, because
130
+ * a reader who arrived arrived once whichever form of whichever page they were
131
+ * served (0297, 0299). A caller wanting them apart asks for one tree.
132
+ *
133
+ * Rows outside the range are ignored rather than refused. A store answers the
134
+ * range it was asked for, and a reading that threw on a row it did not expect
135
+ * would be a reading that cannot be given a wider read to narrow — which is
136
+ * exactly what {@link arrivalChangeOf} does with it.
137
+ */
138
+ export const arrivalSeriesOf = (stored, range, options = {}) => {
139
+ const filled = hourlySeriesOf(stored.hours, stored.begins, range, (row) => row.views, options);
140
+ return {
141
+ range,
142
+ hours: filled.hours.map(({ hour, count, whole }) => ({ hour, views: count, whole })),
143
+ views: filled.total,
144
+ ...(stored.begins === undefined ? {} : { begins: stored.begins }),
145
+ clipped: filled.clipped,
146
+ };
147
+ };
148
+ /**
149
+ * The rule every hourly series in this subsystem follows, spelled once.
150
+ *
151
+ * Three readings now draw bars over a range — page views by hour (0356), and
152
+ * what readers did by hour (`acted.ts`), in a series and in a comparison — and
153
+ * the rule they share is not the arithmetic but the **honesty**: an hour with
154
+ * no row is a nought that is drawn, an hour before counting began is not drawn
155
+ * at all, and the hour in progress is marked rather than drawn as a fall. Three
156
+ * spellings of that would be three chances for one chart to claim a quiet week
157
+ * the deployment never had.
158
+ *
159
+ * It is exported rather than private because `acted.ts` is a module and not a
160
+ * function in this one. A reading hands over its rows, the first hour its scope
161
+ * ever counted, the range, and which number on a row it is counting.
162
+ */
163
+ export const hourlySeriesOf = (rows, begins, range, count, options = {}) => {
164
+ const clipped = begins !== undefined && begins > range.from;
165
+ const first = Math.max(firstHourOf(range.from), begins ?? 0);
166
+ const last = hourAt(range.to - 1);
167
+ const counted = new Map();
168
+ for (const row of rows) {
169
+ if (row.hour < range.from || row.hour >= range.to)
170
+ continue;
171
+ counted.set(row.hour, (counted.get(row.hour) ?? 0) + count(row));
172
+ }
173
+ const hours = [];
174
+ if (begins !== undefined) {
175
+ for (let hour = first; hour <= last; hour += ARRIVAL_HOUR_MS) {
176
+ const ends = hour + ARRIVAL_HOUR_MS;
177
+ hours.push({
178
+ hour,
179
+ count: counted.get(hour) ?? 0,
180
+ whole: ends <= range.to && (options.now === undefined || options.now >= ends),
181
+ });
182
+ }
183
+ }
184
+ return {
185
+ hours,
186
+ total: hours.reduce((sum, hour) => sum + hour.count, 0),
187
+ clipped,
188
+ };
189
+ };
190
+ /**
191
+ * The stretch of the same length immediately before a range.
192
+ *
193
+ * The period a *page views in the range* figure is compared against, computed
194
+ * here rather than at a call site so that the two ranges a comparison is taken
195
+ * over cannot be of different lengths — which is the one way to make a
196
+ * percentage of two honest counts dishonest.
197
+ */
198
+ export const arrivalRangeBefore = (range) => ({
199
+ from: range.from - (range.to - range.from),
200
+ to: range.from,
201
+ });
202
+ /**
203
+ * Both figures and the quotient, from one read.
204
+ *
205
+ * The read has to span both periods, which is what `arrivalRangeBefore` is for: a
206
+ * caller asks the store for `{ from: arrivalRangeBefore(range).from, to: range.to }`
207
+ * and hands the result here. Taking two reads would be two scans and a seam
208
+ * where the clock moved between them.
209
+ */
210
+ export const arrivalChangeOf = (stored, range, options = {}) => {
211
+ const before = arrivalRangeBefore(range);
212
+ const now = arrivalSeriesOf(stored, range, options);
213
+ const earlier = arrivalSeriesOf(stored, before, options);
214
+ const was = stored.begins === undefined || stored.begins > before.from ? null : earlier.views;
215
+ return {
216
+ range,
217
+ before,
218
+ views: now.views,
219
+ was,
220
+ ratio: ratioOf(was, now.views),
221
+ };
222
+ };
223
+ /**
224
+ * The chart, the range's figure and the change on the period before it, in one
225
+ * call against a counter handle.
226
+ *
227
+ * **It exists because the composition has a wrong version that type-checks.**
228
+ * The change is over two periods, so the read has to span both — and a caller
229
+ * who read `{ from: range.from }`, which is the obvious line, would get a
230
+ * comparison whose earlier period is empty **because it was not read** rather
231
+ * than because nobody arrived in it. That reads as *every reader you have is
232
+ * new*, on a screen, from a store that holds the right answer. This takes the
233
+ * range a surface is drawing and derives the read from it, so there is nothing
234
+ * to get wrong.
235
+ *
236
+ * The store handle is narrowed to the one method, so a reading cannot reach a
237
+ * counter it was not asked about.
238
+ */
239
+ export const readReaderArrivals = async (store, request) => {
240
+ const { range, now, ...narrowing } = request;
241
+ const read = await store.arrivals({
242
+ ...narrowing,
243
+ from: arrivalRangeBefore(range).from,
244
+ to: range.to,
245
+ });
246
+ if (!read.ok)
247
+ return read;
248
+ const options = now === undefined ? {} : { now };
249
+ return ok({
250
+ series: arrivalSeriesOf(read.value, range, options),
251
+ change: arrivalChangeOf(read.value, range, options),
252
+ });
253
+ };
254
+ //# sourceMappingURL=arrivals.js.map
@@ -0,0 +1,210 @@
1
+ import type { CollectionHealth } from "./health.js";
2
+ /**
3
+ * Whether nothing is arriving because nothing is posting, or because this
4
+ * deployment's door is turning it away.
5
+ *
6
+ * Every reading in this subsystem is a reading of rows that arrived. A part
7
+ * that nobody reached, a window with no page views, a funnel nobody entered, a
8
+ * census of the reasons a reading went dark — all of them are computed from
9
+ * counters, and a counter that was never written looks exactly like a counter
10
+ * that was written with a nought. So the most ordinary failure a new
11
+ * deployment has — a snippet posting from an origin its project does not name
12
+ * — makes **forty-odd readings and nine comparisons all say the same wrong
13
+ * thing**: *nobody read this page.*
14
+ *
15
+ * The evidence that it is wrong has existed since
16
+ * [0311](../../decisions/0311-a-refusal-whose-key-was-right-is-counted-against-its-project-and-one-without-one-is-not.md):
17
+ * the door counts what it refused, per reason, with the newest one's origin
18
+ * beside it. **Nothing joined the two.** A person could read a refusal count
19
+ * in one box on a screen and a page of nought-view pages in another and draw
20
+ * the conclusion themselves; no reading drew it, so no verdict, no fault and no
21
+ * sentence anywhere in this subsystem could.
22
+ *
23
+ * ## Why it is not a collection fault
24
+ *
25
+ * {@link collectionHealthOf} publishes seven faults and every one of them is
26
+ * **about one revision of one page**, because every one is derived from that
27
+ * revision's own rows. A refusal names no page: a delivery turned away for
28
+ * naming the wrong site was turned away before anything read which tree it was
29
+ * about, and reading the body to find out would spend the deployment's database
30
+ * on exactly the sender the gate exists to stop (0311). So this is deployment-
31
+ * wide by construction, which is a different subject (0240) and therefore a
32
+ * reading beside health rather than an eighth member of a closed set inside it.
33
+ *
34
+ * ## The reasons stay the deployment's
35
+ *
36
+ * Why a host turned a sender away is the host's business — which is why the
37
+ * counter is the deployment's table and not the runtime's — so this reading is
38
+ * generic in the reason and never names one. A host hands in its own closed
39
+ * set and gets it back on {@link ArrivalStanding.newest}, where its own
40
+ * sentence and its own remedy can be chosen from it. The framework's part is
41
+ * the join and the standing, both of which hold whatever the reasons are.
42
+ *
43
+ * Pure, linear in the tallies handed in, and reaches no store, clock or DOM.
44
+ */
45
+ /**
46
+ * One reason a door turned deliveries away, as a deployment's own counter holds
47
+ * it.
48
+ *
49
+ * Structural rather than imported, for the reason above: the three members this
50
+ * deployment happens to count are not the framework's to know. `TReason` is
51
+ * whatever a host's closed set is, and it travels through to `newest` so that
52
+ * the one place a reason is acted on is the host's own switch over its own set.
53
+ */
54
+ export type TurnedAwayTally<TReason extends string = string> = {
55
+ readonly reason: TReason;
56
+ /** Deliveries turned away for this reason, cumulative since the counter existed. */
57
+ readonly refused: number;
58
+ /** When the newest of them was turned away, in epoch milliseconds. */
59
+ readonly lastAt: number;
60
+ /**
61
+ * The site the newest of them came from, as an origin, or `null` where it
62
+ * named none.
63
+ *
64
+ * Carried because for the commonest reason it is the whole remedy: *from
65
+ * `https://loomjs.org`* beside a project that names `www.loomjs.org` needs no
66
+ * other explanation.
67
+ */
68
+ readonly lastOrigin: string | null;
69
+ };
70
+ /** The newest delivery this door turned away, which is the one an operator acts on. */
71
+ export type NewestTurnedAway<TReason extends string = string> = {
72
+ readonly reason: TReason;
73
+ readonly origin: string | null;
74
+ /** When it was turned away, in epoch milliseconds, as the counter holds it. */
75
+ readonly atMs: number;
76
+ /**
77
+ * How long before the instant handed in it was turned away, or `null` where
78
+ * no instant was.
79
+ *
80
+ * The one number that tells a live fault from a fixed one: a cumulative
81
+ * counter cannot say whether its own figure is current, and a deployment that
82
+ * was misconfigured a month ago and fixed it still holds every refusal it
83
+ * ever counted. Negative where the counter is ahead of the instant, by the
84
+ * same subtraction rather than by a special case (0274).
85
+ */
86
+ readonly sinceMs: number | null;
87
+ };
88
+ /** Whether anything is arriving at this deployment, and why not. */
89
+ export type ArrivalStandingName =
90
+ /**
91
+ * Nothing offered a count of what the door turned away, so the question
92
+ * cannot be answered either way.
93
+ *
94
+ * The refusal rather than the gap, and it wins over every other state for the
95
+ * reason an absent region store is not an empty map (0240): a window with
96
+ * nothing in it and no refusal counter beside it is *two* states, and calling
97
+ * it `silent` would publish the more comforting one. A deployment that keeps
98
+ * no such counter — or whose store was not reachable on this read — gets the
99
+ * figures it does have and no verdict.
100
+ */
101
+ "unasked"
102
+ /**
103
+ * Nothing has been collected and nothing has been turned away.
104
+ *
105
+ * No page is posting to this deployment at all: the snippet is absent, or the
106
+ * broadcaster was never called, or the signals never left the browser. The
107
+ * strongest of the quiet answers, because the door is the one place a
108
+ * delivery cannot arrive without being seen, and it saw none.
109
+ */
110
+ | "silent"
111
+ /**
112
+ * Nothing has been collected and deliveries have been turned away.
113
+ *
114
+ * **The state this reading exists for.** A page is posting and this door is
115
+ * refusing it, and every other reading in the subsystem is reporting that
116
+ * nobody read anything. It is the one standing here that no amount of age on
117
+ * the counter can weaken: whenever those refusals happened, nothing has ever
118
+ * been collected, so there is no window in which this deployment was working.
119
+ */
120
+ | "turned-away"
121
+ /** Something has been collected and nothing has been turned away. */
122
+ | "collecting"
123
+ /**
124
+ * Something has been collected and deliveries have been turned away.
125
+ *
126
+ * Both are true and neither is the whole picture: a second sender with a
127
+ * stale key, one page of several carrying the wrong snippet, or a
128
+ * misconfiguration since fixed. `newest.sinceMs` is what tells those apart
129
+ * and this standing deliberately does not try to.
130
+ */
131
+ | "mixed";
132
+ /** The closed set, in the order a surface reads them: the refusal, then the two quiet states, then the two live ones. */
133
+ export declare const ARRIVAL_STANDINGS: readonly ArrivalStandingName[];
134
+ /** What is arriving at a deployment, what is being turned away, and what that means together. */
135
+ export type ArrivalStanding<TReason extends string = string> = {
136
+ readonly standing: ArrivalStandingName;
137
+ /**
138
+ * Revisions anything at all was collected about, which is **not** a count of
139
+ * readers.
140
+ *
141
+ * A revision stands here if the window held one counter, one funnel answer,
142
+ * one door row or one region bucket for it, so a deployment whose senders
143
+ * never mark an opening still reads as collecting — which it is. Reading this
144
+ * off `arrivals` instead would call that deployment `turned-away` and send an
145
+ * operator after a gate that is letting everything through.
146
+ */
147
+ readonly collected: number;
148
+ /**
149
+ * Page views counted at the door across every revision read, added.
150
+ *
151
+ * The headcount behind `collected`, carried through unchanged. Nought with a
152
+ * positive `collected` is an ordinary state and its own fault already
153
+ * (`door-unscaled`), not a sign that nothing arrived.
154
+ */
155
+ readonly arrivals: number;
156
+ /**
157
+ * Deliveries turned away, added across the reasons, or `null` where nothing
158
+ * offered a count.
159
+ *
160
+ * The two kinds of nothing kept apart (0240): `null` is *nobody counted*, and
161
+ * `0` is *the counter was read and holds none*.
162
+ */
163
+ readonly refused: number | null;
164
+ /** The newest delivery turned away, or `null` where none was. */
165
+ readonly newest: NewestTurnedAway<TReason> | null;
166
+ /**
167
+ * Tallies beyond the first for one reason, dropped.
168
+ *
169
+ * A store keys its rows by the reason, so this is nought from every store in
170
+ * this repository. It is counted because the one lie a sum can be told is a
171
+ * row handed in twice, and a count that has been added cannot be unadded
172
+ * (0158) — a caller that concatenated two reads would otherwise publish twice
173
+ * the refusals with nothing saying so.
174
+ */
175
+ readonly duplicated: number;
176
+ };
177
+ /**
178
+ * Read a window's health and a door's refusals together, into the one question
179
+ * neither can answer alone.
180
+ *
181
+ * The health is taken as the `Pick` a reading of the window already produced
182
+ * rather than as two loose numbers, so what is judged here is what that reading
183
+ * published, by construction rather than by a reviewer — the shape
184
+ * {@link retentionPromiseOf} takes the retention in (0321). The two fields are
185
+ * the two it needs and the two a caller could most plausibly get wrong by hand:
186
+ * a view floor is not an arrival count (0212), and a count of readers is not a
187
+ * count of pages.
188
+ *
189
+ * **A delivery was turned away if any reason reports a positive count**, which
190
+ * is the one rule the standing turns on, and it is the same rule `newest` is
191
+ * found by — so a standing that names a refusal always carries the refusal it
192
+ * named.
193
+ *
194
+ * **The instant is optional and nothing here reads a clock.** A caller that
195
+ * states one gets `sinceMs` and can tell a live fault from a fixed one; a
196
+ * caller that does not gets every other figure and no age, which is the shape a
197
+ * collection schedule already takes (0274). A reading that read the wall clock
198
+ * would answer differently on two calls over one set of rows.
199
+ */
200
+ export declare const arrivalStandingOf: <TReason extends string>(health: Pick<CollectionHealth, "pages" | "arrivals">, turnedAway: readonly TurnedAwayTally<TReason>[] | undefined, at?: number) => ArrivalStanding<TReason>;
201
+ /**
202
+ * One line for the operator setting a deployment up, because they are the only
203
+ * person who can close the gap.
204
+ *
205
+ * It names the reason as the deployment spelled it and never translates one: a
206
+ * host's own set is the host's to put a sentence and a remedy to, and a
207
+ * framework that worded them would be wording a vocabulary it does not define.
208
+ */
209
+ export declare const describeArrivalStanding: (standing: ArrivalStanding) => string;
210
+ //# sourceMappingURL=arriving.d.ts.map
@@ -0,0 +1,133 @@
1
+ import { everyMemberOf } from "../closed-set.js";
2
+ /** The closed set, in the order a surface reads them: the refusal, then the two quiet states, then the two live ones. */
3
+ export const ARRIVAL_STANDINGS = everyMemberOf()([
4
+ "unasked",
5
+ "silent",
6
+ "turned-away",
7
+ "collecting",
8
+ "mixed",
9
+ ]);
10
+ /** The first tally per reason, and how many were dropped. */
11
+ const firstPerReason = (tallies) => {
12
+ const seen = new Set();
13
+ const kept = [];
14
+ let duplicated = 0;
15
+ for (const tally of tallies) {
16
+ if (seen.has(tally.reason)) {
17
+ duplicated += 1;
18
+ continue;
19
+ }
20
+ seen.add(tally.reason);
21
+ kept.push(tally);
22
+ }
23
+ return { kept, duplicated };
24
+ };
25
+ /**
26
+ * The newest tally reporting a positive count, or `null` where none does.
27
+ *
28
+ * A reason with a nought is a row that says nothing was turned away for it, so
29
+ * it cannot be the newest thing that was. Ties keep the earlier of the two, so
30
+ * two reasons counted at one instant do not reorder on a refresh.
31
+ */
32
+ const newestOf = (kept, at) => {
33
+ let newest = null;
34
+ for (const tally of kept) {
35
+ if (tally.refused <= 0)
36
+ continue;
37
+ if (newest === null || tally.lastAt > newest.lastAt)
38
+ newest = tally;
39
+ }
40
+ if (newest === null)
41
+ return null;
42
+ return {
43
+ reason: newest.reason,
44
+ origin: newest.lastOrigin,
45
+ atMs: newest.lastAt,
46
+ sinceMs: at === undefined ? null : at - newest.lastAt,
47
+ };
48
+ };
49
+ /**
50
+ * Read a window's health and a door's refusals together, into the one question
51
+ * neither can answer alone.
52
+ *
53
+ * The health is taken as the `Pick` a reading of the window already produced
54
+ * rather than as two loose numbers, so what is judged here is what that reading
55
+ * published, by construction rather than by a reviewer — the shape
56
+ * {@link retentionPromiseOf} takes the retention in (0321). The two fields are
57
+ * the two it needs and the two a caller could most plausibly get wrong by hand:
58
+ * a view floor is not an arrival count (0212), and a count of readers is not a
59
+ * count of pages.
60
+ *
61
+ * **A delivery was turned away if any reason reports a positive count**, which
62
+ * is the one rule the standing turns on, and it is the same rule `newest` is
63
+ * found by — so a standing that names a refusal always carries the refusal it
64
+ * named.
65
+ *
66
+ * **The instant is optional and nothing here reads a clock.** A caller that
67
+ * states one gets `sinceMs` and can tell a live fault from a fixed one; a
68
+ * caller that does not gets every other figure and no age, which is the shape a
69
+ * collection schedule already takes (0274). A reading that read the wall clock
70
+ * would answer differently on two calls over one set of rows.
71
+ */
72
+ export const arrivalStandingOf = (health, turnedAway, at) => {
73
+ const collected = health.pages.length;
74
+ if (turnedAway === undefined) {
75
+ return {
76
+ standing: "unasked",
77
+ collected,
78
+ arrivals: health.arrivals,
79
+ refused: null,
80
+ newest: null,
81
+ duplicated: 0,
82
+ };
83
+ }
84
+ const { kept, duplicated } = firstPerReason(turnedAway);
85
+ const newest = newestOf(kept, at);
86
+ const refused = kept.reduce((sum, tally) => sum + tally.refused, 0);
87
+ const standing = collected > 0
88
+ ? newest === null
89
+ ? "collecting"
90
+ : "mixed"
91
+ : newest === null
92
+ ? "silent"
93
+ : "turned-away";
94
+ return { standing, collected, arrivals: health.arrivals, refused, newest, duplicated };
95
+ };
96
+ const versions = (collected) => collected === 1 ? "1 version of 1 page" : `${collected} versions`;
97
+ /** The count and its verb together, because one page view *was* and two *were*. */
98
+ const readers = (arrivals) => arrivals === 1 ? "1 page view was" : `${arrivals} page views were`;
99
+ const deliveries = (refused) => refused === 1 ? "1 delivery was" : `${refused} deliveries were`;
100
+ /** Where the newest refusal came from, named so that `null` is a sentence rather than a blank. */
101
+ const from = (newest) => newest.origin === null
102
+ ? `the latest of them ${newest.reason} and naming no site`
103
+ : `the latest of them ${newest.reason}, from ${newest.origin}`;
104
+ /**
105
+ * One line for the operator setting a deployment up, because they are the only
106
+ * person who can close the gap.
107
+ *
108
+ * It names the reason as the deployment spelled it and never translates one: a
109
+ * host's own set is the host's to put a sentence and a remedy to, and a
110
+ * framework that worded them would be wording a vocabulary it does not define.
111
+ */
112
+ export const describeArrivalStanding = (standing) => {
113
+ switch (standing.standing) {
114
+ case "unasked":
115
+ return ("nothing counted what this door turned away, so a deployment nobody is posting to " +
116
+ "cannot be told from one whose deliveries are being refused");
117
+ case "silent":
118
+ return ("nothing has been collected and nothing has been turned away, " +
119
+ "so no page is posting to this deployment at all");
120
+ case "turned-away":
121
+ return (`nothing has been collected and ${deliveries(standing.refused ?? 0)} turned away, ` +
122
+ `${standing.newest === null ? "with no reason given" : from(standing.newest)}: ` +
123
+ "a page is posting and this door is refusing it");
124
+ case "collecting":
125
+ return (`${readers(standing.arrivals)} counted at the door across ${versions(standing.collected)}, ` +
126
+ "and nothing has been turned away");
127
+ case "mixed":
128
+ return (`${readers(standing.arrivals)} counted at the door across ${versions(standing.collected)}, ` +
129
+ `and ${deliveries(standing.refused ?? 0)} turned away, ` +
130
+ `${standing.newest === null ? "with no reason given" : from(standing.newest)}`);
131
+ }
132
+ };
133
+ //# sourceMappingURL=arriving.js.map