@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
@@ -1,13 +1,26 @@
1
1
  import { sql } from "drizzle-orm";
2
2
  import { bigint, bigserial, index, integer, jsonb, pgTable, primaryKey, text, timestamp, } from "drizzle-orm/pg-core";
3
3
  /**
4
- * Three tables: the buffer batches wait in, and the two counters that outlive
4
+ * Six tables: the buffer batches wait in, and the five counters that outlive
5
5
  * them.
6
6
  *
7
7
  * The split is 0146's — raw signals are short-lived and aggregates are durable
8
8
  * — and it is in the schema rather than in a policy because a single table
9
9
  * would make the retention rule a `DELETE` somebody has to remember to write
10
10
  * correctly forever.
11
+ *
12
+ * All six carry `application_id` (0269), led by it in every key and every
13
+ * index, on the same terms as the store's four: a reader is filed against the
14
+ * application whose page they read, and no reading here spans two.
15
+ *
16
+ * All six then carry `audience_id` immediately after it
17
+ * ([0284](../../decisions/0284-a-signal-names-the-audience-it-was-collected-under-and-the-predicate-stays-in-the-control-plane.md)),
18
+ * which is the second of the two migrations
19
+ * [0273](../../decisions/0273-the-reader-tables-take-the-application-now-and-the-audience-when-it-is-ratified.md)
20
+ * chose to take rather than wait for. The two dimensions differ in kind, and
21
+ * the difference is why one is a handle's scope and the other is a column: no
22
+ * reading spans two applications, where comparing two audiences is the whole
23
+ * point of serving two.
11
24
  */
12
25
  /**
13
26
  * The buffer.
@@ -24,6 +37,32 @@ import { bigint, bigserial, index, integer, jsonb, pgTable, primaryKey, text, ti
24
37
  */
25
38
  export const loomReaderSignals = pgTable("loom_reader_signals", {
26
39
  seq: bigserial("seq", { mode: "number" }).primaryKey(),
40
+ /**
41
+ * The application the reading belongs to (0269). First in the key and in
42
+ * every index, as it is on the store's tables, because every read of this
43
+ * table is already inside one application.
44
+ *
45
+ * Defaulted so a database written before applications existed keeps
46
+ * answering, and so that every rollup, door and screen that names no
47
+ * application goes on meaning what it meant. `DEFAULT_APPLICATION_ID` is
48
+ * the value, spelled out because DDL cannot import it — `scoped.test.ts`
49
+ * holds the two together.
50
+ */
51
+ applicationId: text("application_id").notNull().default("app_default"),
52
+ /**
53
+ * The audience this batch's reader was served under (0284). Second in the
54
+ * key and in every index, immediately after the application.
55
+ *
56
+ * Defaulted for the same reason the application is, and to the same effect:
57
+ * a batch that names no audience, and every row written before the
58
+ * dimension existed, reads as `aud_everyone` — the audience that matches
59
+ * every reader. `DEFAULT_AUDIENCE_ID` is the value, spelled out because DDL
60
+ * cannot import it; `scoped.test.ts` holds the two together.
61
+ *
62
+ * Opaque. What an `aud_` means is the control plane's to say, and no column
63
+ * here holds the predicate that selected it.
64
+ */
65
+ audienceId: text("audience_id").notNull().default("aud_everyone"),
27
66
  treeId: text("tree_id").notNull(),
28
67
  revision: integer("revision").notNull(),
29
68
  /** What the page said the time was, which is a number a page said. */
@@ -33,7 +72,47 @@ export const loomReaderSignals = pgTable("loom_reader_signals", {
33
72
  receivedAt: timestamp("received_at", { withTimezone: true })
34
73
  .notNull()
35
74
  .default(sql `now()`),
36
- }, (table) => [index("loom_reader_signals_tree_seq_idx").on(table.treeId, table.seq)]);
75
+ /**
76
+ * When a fold counted this delivery into the counters (0351).
77
+ *
78
+ * Nullable and undefaulted, and null is a state rather than a gap: *not yet
79
+ * counted*. It is the only column on this table a second statement ever
80
+ * writes, and the only writer is the collection run — which is why the
81
+ * `UPDATE` that sets it carries `folded_at IS NULL`, so a repeat of that
82
+ * statement cannot move an instant a reading has been taken against.
83
+ *
84
+ * A row written before the column existed reads as uncounted, which is
85
+ * conservative in the one direction that matters: retention will not delete
86
+ * what nothing says was counted, so the first fold after the migration
87
+ * stamps it and the second sweep takes it.
88
+ */
89
+ foldedAt: timestamp("folded_at", { withTimezone: true }),
90
+ }, (table) => [
91
+ /**
92
+ * Unchanged by the audience dimension, which is not the shape the
93
+ * application took (0284).
94
+ *
95
+ * The index was widened to lead with the application because every read of
96
+ * the buffer is inside one (0273), so it belongs in the prefix. Nothing reads the
97
+ * buffer by audience: a rollup folds a whole window and groups by the
98
+ * column, so putting the audience second here would displace `tree_id` and
99
+ * `seq` from the prefix and make every read that exists scan wider, to
100
+ * serve a filter no caller expresses.
101
+ */
102
+ index("loom_reader_signals_tree_seq_idx").on(table.applicationId, table.treeId, table.seq),
103
+ /**
104
+ * The oldest end of the whole application, which both sweeps start from
105
+ * (0351).
106
+ *
107
+ * It did not exist while the table held an hour of deliveries, because a
108
+ * scan of an hour is cheap however it is served. The kept window makes it
109
+ * thirty days by default and invites a deployment to lengthen it, so the
110
+ * two reads that run from the oldest end across every tree — the fold's
111
+ * scan and retention's — are the two reads whose cost would have grown with
112
+ * the setting.
113
+ */
114
+ index("loom_reader_signals_seq_idx").on(table.applicationId, table.seq),
115
+ ]);
37
116
  /**
38
117
  * One node at one revision, summed.
39
118
  *
@@ -42,6 +121,10 @@ export const loomReaderSignals = pgTable("loom_reader_signals", {
42
121
  * surrogate id would mean a lookup before every one of those.
43
122
  */
44
123
  export const loomReaderTallies = pgTable("loom_reader_tallies", {
124
+ /** See `loomReaderSignals.applicationId`. */
125
+ applicationId: text("application_id").notNull().default("app_default"),
126
+ /** See `loomReaderSignals.audienceId`. In the key here, unlike the buffer's. */
127
+ audienceId: text("audience_id").notNull().default("aud_everyone"),
45
128
  treeId: text("tree_id").notNull(),
46
129
  revision: integer("revision").notNull(),
47
130
  nodeId: text("node_id").notNull(),
@@ -58,8 +141,24 @@ export const loomReaderTallies = pgTable("loom_reader_tallies", {
58
141
  activations: bigint("activations", { mode: "number" }).notNull(),
59
142
  opens: bigint("opens", { mode: "number" }).notNull(),
60
143
  closes: bigint("closes", { mode: "number" }).notNull(),
144
+ /**
145
+ * Added with the fifth kind, and defaulted for the same reason `engaged`
146
+ * is: a deployment whose table predates the question has rows for which
147
+ * `0` is the true answer, not a missing one.
148
+ */
149
+ completions: bigint("completions", { mode: "number" }).notNull().default(0),
61
150
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
62
- }, (table) => [primaryKey({ columns: [table.treeId, table.revision, table.nodeId] })]);
151
+ }, (table) => [
152
+ primaryKey({
153
+ columns: [
154
+ table.applicationId,
155
+ table.audienceId,
156
+ table.treeId,
157
+ table.revision,
158
+ table.nodeId,
159
+ ],
160
+ }),
161
+ ]);
63
162
  /**
64
163
  * One funnel pair at one revision.
65
164
  *
@@ -68,25 +167,316 @@ export const loomReaderTallies = pgTable("loom_reader_tallies", {
68
167
  * has instead of orphaning them.
69
168
  */
70
169
  export const loomReaderFunnels = pgTable("loom_reader_funnels", {
170
+ /** See `loomReaderSignals.applicationId`. */
171
+ applicationId: text("application_id").notNull().default("app_default"),
172
+ /** See `loomReaderSignals.audienceId`. In the key here, unlike the buffer's. */
173
+ audienceId: text("audience_id").notNull().default("aud_everyone"),
174
+ treeId: text("tree_id").notNull(),
175
+ revision: integer("revision").notNull(),
176
+ fromNodeId: text("from_node_id").notNull(),
177
+ fromKind: text("from_kind").notNull(),
178
+ toNodeId: text("to_node_id").notNull(),
179
+ toKind: text("to_kind").notNull(),
180
+ reached: bigint("reached", { mode: "number" }).notNull(),
181
+ converted: bigint("converted", { mode: "number" }).notNull(),
182
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
183
+ }, (table) => [
184
+ primaryKey({
185
+ columns: [
186
+ table.applicationId,
187
+ table.audienceId,
188
+ table.treeId,
189
+ table.revision,
190
+ table.fromNodeId,
191
+ table.fromKind,
192
+ table.toNodeId,
193
+ table.toKind,
194
+ ],
195
+ }),
196
+ ]);
197
+ /**
198
+ * One region at one revision, as page views that began there.
199
+ *
200
+ * The narrowest table in the subsystem, and the narrowness is the point: a tree,
201
+ * a revision, a country and a number. There is no view key, no address, no
202
+ * digest of one and no per-arrival row, so there is nothing here to join against
203
+ * — which is what makes a region safe to keep for as long as the counters it
204
+ * sits beside.
205
+ *
206
+ * Written on the request path rather than by a rollup, because the request is
207
+ * the only place the region was ever knowable, and `views` counts openings so
208
+ * that a long visit is not a large number.
209
+ */
210
+ export const loomReaderRegions = pgTable("loom_reader_regions", {
211
+ /** See `loomReaderSignals.applicationId`. */
212
+ applicationId: text("application_id").notNull().default("app_default"),
213
+ /** See `loomReaderSignals.audienceId`. In the key here, unlike the buffer's. */
214
+ audienceId: text("audience_id").notNull().default("aud_everyone"),
215
+ treeId: text("tree_id").notNull(),
216
+ revision: integer("revision").notNull(),
217
+ /** A country code, or the word for not knowing. A closed set, so this column cannot be written freely. */
218
+ region: text("region").notNull(),
219
+ views: bigint("views", { mode: "number" }).notNull(),
220
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
221
+ }, (table) => [primaryKey({
222
+ columns: [table.applicationId, table.audienceId, table.treeId, table.revision, table.region],
223
+ })]);
224
+ /**
225
+ * One revision's page views, counted from both ends.
226
+ *
227
+ * Two columns rather than two tables, because they are two counts of the same
228
+ * page views and the only question anybody asks of them is their difference:
229
+ * `opened` is written at the door, once per page view that began, and
230
+ * `appearances` by each rollup that saw that page view in its window. Keeping
231
+ * them in one row makes the subtraction a column expression instead of a join,
232
+ * and makes it impossible for a reading to find one and not the other.
233
+ *
234
+ * Both default to nought because either side may create the row, and nought is
235
+ * the true answer for the column that has not been written yet rather than a
236
+ * missing one.
237
+ *
238
+ * As narrow as the regions table and for the same reason: a tree, a revision
239
+ * and two numbers. No view key, no region, nothing per arrival, nothing to join.
240
+ */
241
+ export const loomReaderPageViews = pgTable("loom_reader_page_views", {
242
+ /** See `loomReaderSignals.applicationId`. */
243
+ applicationId: text("application_id").notNull().default("app_default"),
244
+ /** See `loomReaderSignals.audienceId`. In the key here, unlike the buffer's. */
245
+ audienceId: text("audience_id").notNull().default("aud_everyone"),
246
+ treeId: text("tree_id").notNull(),
247
+ revision: integer("revision").notNull(),
248
+ /** Page views that began. Counted once, at the door, never recounted. */
249
+ opened: bigint("opened", { mode: "number" }).notNull().default(0),
250
+ /** The same page views, once per rollup window each appeared in (0147). */
251
+ appearances: bigint("appearances", { mode: "number" }).notNull().default(0),
252
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
253
+ /**
254
+ * When a rollup last folded a window holding page views of this revision.
255
+ *
256
+ * The one column in this subsystem written by exactly one of a row's two
257
+ * writers, and that is its whole purpose: `updated_at` moves on every
258
+ * delivery the door counts *and* on every fold, so a deployment whose
259
+ * rollup has stopped keeps a fresh timestamp on a row whose appearances
260
+ * never move again. This one moves only when something folded.
261
+ *
262
+ * Nullable and undefaulted, which is the honest value for a row nothing
263
+ * has folded yet and for a row written before this column existed — those
264
+ * two are the same state, *nothing attests a fold*, and no fault is raised
265
+ * from it.
266
+ */
267
+ foldedAt: timestamp("folded_at", { withTimezone: true }),
268
+ }, (table) => [
269
+ primaryKey({
270
+ columns: [table.applicationId, table.audienceId, table.treeId, table.revision],
271
+ }),
272
+ ]);
273
+ /**
274
+ * Page views that began, by the hour they began in.
275
+ *
276
+ * **The sixth table, and the first in this subsystem with a clock in its
277
+ * key** — the seventh, what readers did by hour, is the other. Everything else
278
+ * here is either timeless — a tally, a funnel answer, a
279
+ * region bucket and a page-view total say *so far* and nothing about when — or
280
+ * short-lived, which is the buffer. `docs/portal-wireframes.md` asks for a
281
+ * range picker and a chart of page views by hour, and neither is answerable
282
+ * from a counter with no time in it or from a capped scan of the deliveries
283
+ * (`arrivals.ts`, which says why at length).
284
+ *
285
+ * It is written by the door, in the same transaction as the page-view total it
286
+ * slices, from the same openings — so the hours of a revision sum to its
287
+ * `opened` for every arrival counted after this table existed, and the two can
288
+ * never disagree about how many readers arrived.
289
+ *
290
+ * Keyed like every other counter — the application, the audience, the tree and
291
+ * the revision — with the hour last, so a reading for one page is a prefix scan
292
+ * and a reading for the deployment is the second index below.
293
+ */
294
+ export const loomReaderArrivals = pgTable("loom_reader_arrivals", {
295
+ /** See `loomReaderSignals.applicationId`. */
296
+ applicationId: text("application_id").notNull().default("app_default"),
297
+ /** See `loomReaderSignals.audienceId`. In the key here, as it is on the other counters. */
298
+ audienceId: text("audience_id").notNull().default("aud_everyone"),
299
+ treeId: text("tree_id").notNull(),
300
+ revision: integer("revision").notNull(),
301
+ /**
302
+ * The hour, as the instant it began, in UTC.
303
+ *
304
+ * A `timestamptz` rather than a number of hours since an epoch, so that a
305
+ * range is a `BETWEEN` an operator can read and a bucket is an instant
306
+ * every other column in this schema is comparable with. The truncation is
307
+ * the writer's, not the column's: nothing here constrains it to the hour,
308
+ * and `arrivals.ts` is the one place the unit is decided.
309
+ */
310
+ hour: timestamp("hour", { withTimezone: true }).notNull(),
311
+ /** Page views that began in this hour. Counted once, at the door, never recounted. */
312
+ views: bigint("views", { mode: "number" }).notNull(),
313
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
314
+ }, (table) => [
315
+ primaryKey({
316
+ columns: [table.applicationId, table.audienceId, table.treeId, table.revision, table.hour],
317
+ }),
318
+ /**
319
+ * Every tree of one application, by hour, which is the deployment-wide
320
+ * chart and the only read here whose cost grows with the range.
321
+ *
322
+ * The primary key serves a reading of one page, because that read names the
323
+ * tree and the revision; a reading over the whole deployment names neither,
324
+ * and without this it would scan every row of every page to find a month.
325
+ */
326
+ index("loom_reader_arrivals_hour_idx").on(table.applicationId, table.hour),
327
+ ]);
328
+ /**
329
+ * What readers did to a part, by the hour they did it in.
330
+ *
331
+ * **The seventh table, and the second with a clock in its key.** Page views by
332
+ * hour (0356) let the portal draw a range picker and one chart; every other
333
+ * question on that screen — a goal's figure for the range, each goal's trend,
334
+ * the `By page` drawer's bars for what readers did — needs the *parts* counted
335
+ * by hour, and a tally keeps no time (`acted.ts`, which says why at length).
336
+ *
337
+ * **It holds the three delegated kinds and no others**, which is the whole of
338
+ * what keeps it affordable: `activations`, `opens`, `closes` and `completions`
339
+ * are things a reader aimed at something to cause (0167), so a row exists only
340
+ * where a reader did something. The distinct counters are not here because
341
+ * distinctness does not add across hours and the honest hourly denominator is
342
+ * the door's own arrivals; `dwell_ms` is not here because a `dwelled` signal is
343
+ * observed for every part that comes into view, so slicing it by hour would be
344
+ * thousands of rows an hour on one large page, for ever, in a table nothing
345
+ * sweeps.
346
+ *
347
+ * It is written by the fold, in the same transaction as the tallies it slices
348
+ * and from the same pass over the window — so a part's hours sum to the part's
349
+ * own counters for every window folded since this table existed.
350
+ *
351
+ * Keyed like the tallies with the hour last, so a reading of one part over a
352
+ * range is a prefix scan.
353
+ */
354
+ export const loomReaderActedHours = pgTable("loom_reader_acted_hours", {
355
+ /** See `loomReaderSignals.applicationId`. */
356
+ applicationId: text("application_id").notNull().default("app_default"),
357
+ /** See `loomReaderSignals.audienceId`. In the key here, as it is on the other counters. */
358
+ audienceId: text("audience_id").notNull().default("aud_everyone"),
359
+ treeId: text("tree_id").notNull(),
360
+ revision: integer("revision").notNull(),
361
+ nodeId: text("node_id").notNull(),
362
+ /**
363
+ * The hour, as the instant it began, in UTC — a `timestamptz` for the
364
+ * reasons `loomReaderArrivals.hour` gives, and truncated by the writer
365
+ * rather than by the column, because `arrivals.ts` is the one place the
366
+ * unit is decided.
367
+ */
368
+ hour: timestamp("hour", { withTimezone: true }).notNull(),
369
+ /** What the part is, as the latest signal about it said. Not in the key, as on a tally. */
370
+ type: text("type").notNull(),
371
+ activations: bigint("activations", { mode: "number" }).notNull().default(0),
372
+ opens: bigint("opens", { mode: "number" }).notNull().default(0),
373
+ closes: bigint("closes", { mode: "number" }).notNull().default(0),
374
+ completions: bigint("completions", { mode: "number" }).notNull().default(0),
375
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
376
+ }, (table) => [
377
+ primaryKey({
378
+ columns: [
379
+ table.applicationId,
380
+ table.audienceId,
381
+ table.treeId,
382
+ table.revision,
383
+ table.nodeId,
384
+ table.hour,
385
+ ],
386
+ }),
387
+ /**
388
+ * **One part of one page over a range**, which is a goal's series and the
389
+ * commonest read here.
390
+ *
391
+ * The primary key cannot serve it: a goal sums every revision a part has
392
+ * had and reads every audience unless it is comparing two, so a read naming
393
+ * the tree and the part names neither of the two columns that sit between
394
+ * them in the key.
395
+ */
396
+ index("loom_reader_acted_part_idx").on(table.applicationId, table.treeId, table.nodeId, table.hour),
397
+ /**
398
+ * **Every part of one application, by hour**, which is the deployment-wide
399
+ * reading and the only one here whose cost grows with the range.
400
+ */
401
+ index("loom_reader_acted_hour_idx").on(table.applicationId, table.hour),
402
+ ]);
403
+ /**
404
+ * A funnel pair's answer, by the hour the readers in it entered the funnel.
405
+ *
406
+ * **The eighth table and the third with a clock in its key.** The funnel row
407
+ * beside it is a revision and two ends summed over every window that revision
408
+ * was folded in, which answers *the share since this step was set* (0418) and
409
+ * cannot answer *the share over these fourteen days* — the two sides a change
410
+ * is scored over (0402 clause 6), which is what `Page history` needs and had to
411
+ * read off the kept deliveries instead.
412
+ *
413
+ * The two ends are four columns rather than a reference to a configured pair,
414
+ * for the reason the funnel table's are: a deployment that stops asking a
415
+ * question keeps the answers it already has.
416
+ *
417
+ * **Both counters are distinct counts of page views, which is a thing an
418
+ * hourly table may hold exactly once**: a view is filed under the single hour
419
+ * it first reached the pair's first end in, so the hours of a window partition
420
+ * that window's answer instead of being filed once per delivery
421
+ * (`funnel-hours.ts`, which says why at length). It is written by the fold, in
422
+ * the same transaction as the answers it slices and from the same pass over the
423
+ * window, so a pair's hours sum to the pair's own row.
424
+ *
425
+ * Keyed like the funnel table with the hour last, so a reading of one pair over
426
+ * a range is a prefix scan.
427
+ */
428
+ export const loomReaderFunnelHours = pgTable("loom_reader_funnel_hours", {
429
+ /** See `loomReaderSignals.applicationId`. */
430
+ applicationId: text("application_id").notNull().default("app_default"),
431
+ /** See `loomReaderSignals.audienceId`. In the key here, as it is on the other counters. */
432
+ audienceId: text("audience_id").notNull().default("aud_everyone"),
71
433
  treeId: text("tree_id").notNull(),
72
434
  revision: integer("revision").notNull(),
73
435
  fromNodeId: text("from_node_id").notNull(),
74
436
  fromKind: text("from_kind").notNull(),
75
437
  toNodeId: text("to_node_id").notNull(),
76
438
  toKind: text("to_kind").notNull(),
439
+ /**
440
+ * The hour the readers in this row entered the funnel, as the instant it
441
+ * began, in UTC — a `timestamptz` for the reasons
442
+ * `loomReaderArrivals.hour` gives, and truncated by the writer rather than
443
+ * by the column.
444
+ */
445
+ hour: timestamp("hour", { withTimezone: true }).notNull(),
446
+ /** Views that satisfied the first end in this hour. */
77
447
  reached: bigint("reached", { mode: "number" }).notNull(),
448
+ /** Of those, the ones that satisfied the second — whenever they did it. */
78
449
  converted: bigint("converted", { mode: "number" }).notNull(),
79
450
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
80
451
  }, (table) => [
81
452
  primaryKey({
82
453
  columns: [
454
+ table.applicationId,
455
+ table.audienceId,
83
456
  table.treeId,
84
457
  table.revision,
85
458
  table.fromNodeId,
86
459
  table.fromKind,
87
460
  table.toNodeId,
88
461
  table.toKind,
462
+ table.hour,
89
463
  ],
90
464
  }),
465
+ /**
466
+ * **One pair of one page over a range**, which is a step's two sides and
467
+ * the commonest read here.
468
+ *
469
+ * The primary key cannot serve it: a step sums every revision the pair has
470
+ * been asked of — which is the whole point of comparing two fortnights
471
+ * across a change — and reads every audience unless it is comparing two,
472
+ * so a read naming the tree and the two ends names neither of the columns
473
+ * that sit between them in the key.
474
+ */
475
+ index("loom_reader_funnel_hours_pair_idx").on(table.applicationId, table.treeId, table.fromNodeId, table.toNodeId, table.hour),
476
+ /**
477
+ * **Every pair of one application, by hour**, which is the deployment-wide
478
+ * reading and the only one here whose cost grows with the range.
479
+ */
480
+ index("loom_reader_funnel_hours_hour_idx").on(table.applicationId, table.hour),
91
481
  ]);
92
482
  //# sourceMappingURL=schema.js.map