@jam-overture/loom 0.1.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 (401) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +743 -0
  3. package/dist/catalogue.d.ts +70 -0
  4. package/dist/catalogue.js +88 -0
  5. package/dist/cli/args.d.ts +17 -0
  6. package/dist/cli/args.js +83 -0
  7. package/dist/cli/filesystem.d.ts +15 -0
  8. package/dist/cli/filesystem.js +31 -0
  9. package/dist/cli/index.d.ts +12 -0
  10. package/dist/cli/index.js +12 -0
  11. package/dist/cli/main.d.ts +3 -0
  12. package/dist/cli/main.js +30 -0
  13. package/dist/cli/namespace.d.ts +40 -0
  14. package/dist/cli/namespace.js +40 -0
  15. package/dist/cli/plan.d.ts +84 -0
  16. package/dist/cli/plan.js +113 -0
  17. package/dist/cli/run.d.ts +17 -0
  18. package/dist/cli/run.js +75 -0
  19. package/dist/cli/templates.d.ts +43 -0
  20. package/dist/cli/templates.js +134 -0
  21. package/dist/closed-set.d.ts +34 -0
  22. package/dist/closed-set.js +34 -0
  23. package/dist/data/adapter.d.ts +123 -0
  24. package/dist/data/adapter.js +91 -0
  25. package/dist/data/binding.d.ts +48 -0
  26. package/dist/data/binding.js +39 -0
  27. package/dist/data/catalogue.d.ts +26 -0
  28. package/dist/data/catalogue.js +6 -0
  29. package/dist/data/index.d.ts +14 -0
  30. package/dist/data/index.js +14 -0
  31. package/dist/data/plan.d.ts +58 -0
  32. package/dist/data/plan.js +0 -0
  33. package/dist/data/resolution.d.ts +91 -0
  34. package/dist/data/resolution.js +96 -0
  35. package/dist/data/resolve.d.ts +46 -0
  36. package/dist/data/resolve.js +37 -0
  37. package/dist/data/source.d.ts +40 -0
  38. package/dist/data/source.js +45 -0
  39. package/dist/deadline.d.ts +57 -0
  40. package/dist/deadline.js +78 -0
  41. package/dist/frame/catalogue.d.ts +24 -0
  42. package/dist/frame/catalogue.js +5 -0
  43. package/dist/frame/index.d.ts +12 -0
  44. package/dist/frame/index.js +12 -0
  45. package/dist/frame/origin.d.ts +87 -0
  46. package/dist/frame/origin.js +114 -0
  47. package/dist/frame/resolution.d.ts +85 -0
  48. package/dist/frame/resolution.js +79 -0
  49. package/dist/grammar.d.ts +26 -0
  50. package/dist/grammar.js +28 -0
  51. package/dist/ids.d.ts +57 -0
  52. package/dist/ids.js +104 -0
  53. package/dist/index.d.ts +26 -0
  54. package/dist/index.js +26 -0
  55. package/dist/interactivity.d.ts +50 -0
  56. package/dist/interactivity.js +22 -0
  57. package/dist/interpretation/anthropic.d.ts +22 -0
  58. package/dist/interpretation/anthropic.js +76 -0
  59. package/dist/interpretation/client.d.ts +83 -0
  60. package/dist/interpretation/client.js +2 -0
  61. package/dist/interpretation/draft.d.ts +234 -0
  62. package/dist/interpretation/draft.js +84 -0
  63. package/dist/interpretation/index.d.ts +15 -0
  64. package/dist/interpretation/index.js +15 -0
  65. package/dist/interpretation/interpreter.d.ts +62 -0
  66. package/dist/interpretation/interpreter.js +151 -0
  67. package/dist/interpretation/materialize.d.ts +42 -0
  68. package/dist/interpretation/materialize.js +107 -0
  69. package/dist/interpretation/prompt.d.ts +229 -0
  70. package/dist/interpretation/prompt.js +285 -0
  71. package/dist/interpretation/render.d.ts +76 -0
  72. package/dist/interpretation/render.js +272 -0
  73. package/dist/interpretation/schema.d.ts +49 -0
  74. package/dist/interpretation/schema.js +131 -0
  75. package/dist/json.d.ts +35 -0
  76. package/dist/json.js +11 -0
  77. package/dist/paging.d.ts +60 -0
  78. package/dist/paging.js +49 -0
  79. package/dist/primitive-type.d.ts +32 -0
  80. package/dist/primitive-type.js +39 -0
  81. package/dist/render/addressing.d.ts +59 -0
  82. package/dist/render/addressing.js +60 -0
  83. package/dist/render/anchor.d.ts +105 -0
  84. package/dist/render/anchor.js +84 -0
  85. package/dist/render/behaviour-adjust.d.ts +62 -0
  86. package/dist/render/behaviour-adjust.js +78 -0
  87. package/dist/render/behaviour-copy.d.ts +53 -0
  88. package/dist/render/behaviour-copy.js +75 -0
  89. package/dist/render/behaviour-disclose.d.ts +74 -0
  90. package/dist/render/behaviour-disclose.js +77 -0
  91. package/dist/render/behaviour-present.d.ts +123 -0
  92. package/dist/render/behaviour-present.js +173 -0
  93. package/dist/render/behaviour.d.ts +243 -0
  94. package/dist/render/behaviour.js +284 -0
  95. package/dist/render/control.d.ts +81 -0
  96. package/dist/render/control.js +80 -0
  97. package/dist/render/decorative.d.ts +62 -0
  98. package/dist/render/decorative.js +2 -0
  99. package/dist/render/diagnostics.d.ts +260 -0
  100. package/dist/render/diagnostics.js +61 -0
  101. package/dist/render/disclosed.d.ts +37 -0
  102. package/dist/render/disclosed.js +37 -0
  103. package/dist/render/editable.d.ts +34 -0
  104. package/dist/render/editable.js +35 -0
  105. package/dist/render/frame.d.ts +42 -0
  106. package/dist/render/frame.js +31 -0
  107. package/dist/render/index.d.ts +35 -0
  108. package/dist/render/index.js +35 -0
  109. package/dist/render/inline-variables.d.ts +77 -0
  110. package/dist/render/inline-variables.js +220 -0
  111. package/dist/render/presented.d.ts +82 -0
  112. package/dist/render/presented.js +82 -0
  113. package/dist/render/primitive.d.ts +228 -0
  114. package/dist/render/primitive.js +36 -0
  115. package/dist/render/props.d.ts +48 -0
  116. package/dist/render/props.js +2 -0
  117. package/dist/render/reads.d.ts +73 -0
  118. package/dist/render/reads.js +45 -0
  119. package/dist/render/render.d.ts +164 -0
  120. package/dist/render/render.js +571 -0
  121. package/dist/render/request.d.ts +111 -0
  122. package/dist/render/request.js +60 -0
  123. package/dist/render/text.d.ts +91 -0
  124. package/dist/render/text.js +44 -0
  125. package/dist/render/theme.d.ts +61 -0
  126. package/dist/render/theme.js +52 -0
  127. package/dist/reserved-props.d.ts +35 -0
  128. package/dist/reserved-props.js +45 -0
  129. package/dist/result.d.ts +27 -0
  130. package/dist/result.js +30 -0
  131. package/dist/role.d.ts +71 -0
  132. package/dist/role.js +22 -0
  133. package/dist/runtime/analysis.d.ts +149 -0
  134. package/dist/runtime/analysis.js +187 -0
  135. package/dist/runtime/assessment.d.ts +35 -0
  136. package/dist/runtime/assessment.js +13 -0
  137. package/dist/runtime/disposition.d.ts +102 -0
  138. package/dist/runtime/disposition.js +59 -0
  139. package/dist/runtime/events.d.ts +187 -0
  140. package/dist/runtime/events.js +7 -0
  141. package/dist/runtime/gate.d.ts +43 -0
  142. package/dist/runtime/gate.js +169 -0
  143. package/dist/runtime/index.d.ts +27 -0
  144. package/dist/runtime/index.js +27 -0
  145. package/dist/runtime/intent.d.ts +60 -0
  146. package/dist/runtime/intent.js +36 -0
  147. package/dist/runtime/interpreter.d.ts +117 -0
  148. package/dist/runtime/interpreter.js +46 -0
  149. package/dist/runtime/inverse-interpreter.d.ts +90 -0
  150. package/dist/runtime/inverse-interpreter.js +56 -0
  151. package/dist/runtime/inverse.d.ts +87 -0
  152. package/dist/runtime/inverse.js +48 -0
  153. package/dist/runtime/narration.d.ts +24 -0
  154. package/dist/runtime/narration.js +36 -0
  155. package/dist/runtime/nesting.d.ts +31 -0
  156. package/dist/runtime/nesting.js +46 -0
  157. package/dist/runtime/pipeline.d.ts +124 -0
  158. package/dist/runtime/pipeline.js +178 -0
  159. package/dist/runtime/policy-fingerprint.d.ts +29 -0
  160. package/dist/runtime/policy-fingerprint.js +119 -0
  161. package/dist/runtime/policy-source.d.ts +42 -0
  162. package/dist/runtime/policy-source.js +8 -0
  163. package/dist/runtime/policy.d.ts +156 -0
  164. package/dist/runtime/policy.js +107 -0
  165. package/dist/runtime/proposal.d.ts +423 -0
  166. package/dist/runtime/proposal.js +109 -0
  167. package/dist/runtime/redirection.d.ts +53 -0
  168. package/dist/runtime/redirection.js +38 -0
  169. package/dist/runtime/repointing.d.ts +71 -0
  170. package/dist/runtime/repointing.js +0 -0
  171. package/dist/runtime/reversibility.d.ts +36 -0
  172. package/dist/runtime/reversibility.js +39 -0
  173. package/dist/runtime/stake-level.d.ts +33 -0
  174. package/dist/runtime/stake-level.js +58 -0
  175. package/dist/runtime/stakes.d.ts +47 -0
  176. package/dist/runtime/stakes.js +305 -0
  177. package/dist/runtime/vocabulary.d.ts +122 -0
  178. package/dist/runtime/vocabulary.js +87 -0
  179. package/dist/sdk/audit.d.ts +195 -0
  180. package/dist/sdk/audit.js +128 -0
  181. package/dist/sdk/catalogue.d.ts +37 -0
  182. package/dist/sdk/catalogue.js +16 -0
  183. package/dist/sdk/conformance.d.ts +342 -0
  184. package/dist/sdk/conformance.js +494 -0
  185. package/dist/sdk/copy.d.ts +105 -0
  186. package/dist/sdk/copy.js +90 -0
  187. package/dist/sdk/definition.d.ts +242 -0
  188. package/dist/sdk/definition.js +64 -0
  189. package/dist/sdk/index.d.ts +19 -0
  190. package/dist/sdk/index.js +19 -0
  191. package/dist/sdk/interactivity.d.ts +29 -0
  192. package/dist/sdk/interactivity.js +34 -0
  193. package/dist/sdk/pairings.d.ts +124 -0
  194. package/dist/sdk/pairings.js +81 -0
  195. package/dist/sdk/registry.d.ts +162 -0
  196. package/dist/sdk/registry.js +329 -0
  197. package/dist/sdk/selection.d.ts +46 -0
  198. package/dist/sdk/selection.js +24 -0
  199. package/dist/sdk/text.d.ts +100 -0
  200. package/dist/sdk/text.js +105 -0
  201. package/dist/sdk/vocabulary.d.ts +39 -0
  202. package/dist/sdk/vocabulary.js +36 -0
  203. package/dist/signals/broadcast.d.ts +134 -0
  204. package/dist/signals/broadcast.js +451 -0
  205. package/dist/signals/collect.d.ts +184 -0
  206. package/dist/signals/collect.js +196 -0
  207. package/dist/signals/deliver.d.ts +64 -0
  208. package/dist/signals/deliver.js +85 -0
  209. package/dist/signals/fold.d.ts +112 -0
  210. package/dist/signals/fold.js +76 -0
  211. package/dist/signals/index.d.ts +31 -0
  212. package/dist/signals/index.js +31 -0
  213. package/dist/signals/ingest.d.ts +51 -0
  214. package/dist/signals/ingest.js +70 -0
  215. package/dist/signals/intake.d.ts +149 -0
  216. package/dist/signals/intake.js +154 -0
  217. package/dist/signals/journal.d.ts +94 -0
  218. package/dist/signals/journal.js +11 -0
  219. package/dist/signals/kinds.d.ts +22 -0
  220. package/dist/signals/kinds.js +22 -0
  221. package/dist/signals/ledger.d.ts +46 -0
  222. package/dist/signals/ledger.js +81 -0
  223. package/dist/signals/memory.d.ts +17 -0
  224. package/dist/signals/memory.js +99 -0
  225. package/dist/signals/migrate.d.ts +27 -0
  226. package/dist/signals/migrate.js +78 -0
  227. package/dist/signals/postgres.d.ts +7 -0
  228. package/dist/signals/postgres.js +295 -0
  229. package/dist/signals/rollup.d.ts +142 -0
  230. package/dist/signals/rollup.js +0 -0
  231. package/dist/signals/schema.d.ts +534 -0
  232. package/dist/signals/schema.js +92 -0
  233. package/dist/signals/signal.d.ts +381 -0
  234. package/dist/signals/signal.js +150 -0
  235. package/dist/signals/tally.d.ts +70 -0
  236. package/dist/signals/tally.js +2 -0
  237. package/dist/signals/view.d.ts +51 -0
  238. package/dist/signals/view.js +54 -0
  239. package/dist/store/attribution.d.ts +125 -0
  240. package/dist/store/attribution.js +116 -0
  241. package/dist/store/database.d.ts +14 -0
  242. package/dist/store/database.js +2 -0
  243. package/dist/store/driver.d.ts +29 -0
  244. package/dist/store/driver.js +39 -0
  245. package/dist/store/errors.d.ts +56 -0
  246. package/dist/store/errors.js +37 -0
  247. package/dist/store/index.d.ts +16 -0
  248. package/dist/store/index.js +16 -0
  249. package/dist/store/memory.d.ts +3 -0
  250. package/dist/store/memory.js +115 -0
  251. package/dist/store/migrate.d.ts +54 -0
  252. package/dist/store/migrate.js +122 -0
  253. package/dist/store/postgres-holds.d.ts +4 -0
  254. package/dist/store/postgres-holds.js +192 -0
  255. package/dist/store/postgres.d.ts +8 -0
  256. package/dist/store/postgres.js +262 -0
  257. package/dist/store/replay.d.ts +94 -0
  258. package/dist/store/replay.js +82 -0
  259. package/dist/store/revert.d.ts +116 -0
  260. package/dist/store/revert.js +243 -0
  261. package/dist/store/schema.d.ts +371 -0
  262. package/dist/store/schema.js +78 -0
  263. package/dist/store/source.d.ts +23 -0
  264. package/dist/store/source.js +37 -0
  265. package/dist/store/store.d.ts +231 -0
  266. package/dist/store/store.js +52 -0
  267. package/dist/store/undone.d.ts +18 -0
  268. package/dist/store/undone.js +89 -0
  269. package/dist/submit/catalogue.d.ts +20 -0
  270. package/dist/submit/catalogue.js +5 -0
  271. package/dist/submit/declaration.d.ts +39 -0
  272. package/dist/submit/declaration.js +30 -0
  273. package/dist/submit/endpoint.d.ts +131 -0
  274. package/dist/submit/endpoint.js +160 -0
  275. package/dist/submit/index.d.ts +13 -0
  276. package/dist/submit/index.js +13 -0
  277. package/dist/submit/plan.d.ts +49 -0
  278. package/dist/submit/plan.js +47 -0
  279. package/dist/submit/resolution.d.ts +61 -0
  280. package/dist/submit/resolution.js +64 -0
  281. package/dist/submit/resolve.d.ts +45 -0
  282. package/dist/submit/resolve.js +36 -0
  283. package/dist/telemetry/calibration.d.ts +132 -0
  284. package/dist/telemetry/calibration.js +151 -0
  285. package/dist/telemetry/episode.d.ts +140 -0
  286. package/dist/telemetry/episode.js +272 -0
  287. package/dist/telemetry/event.d.ts +2310 -0
  288. package/dist/telemetry/event.js +405 -0
  289. package/dist/telemetry/index.d.ts +15 -0
  290. package/dist/telemetry/index.js +15 -0
  291. package/dist/telemetry/journal.d.ts +116 -0
  292. package/dist/telemetry/journal.js +11 -0
  293. package/dist/telemetry/memory.d.ts +24 -0
  294. package/dist/telemetry/memory.js +75 -0
  295. package/dist/telemetry/migrate.d.ts +26 -0
  296. package/dist/telemetry/migrate.js +40 -0
  297. package/dist/telemetry/postgres.d.ts +6 -0
  298. package/dist/telemetry/postgres.js +139 -0
  299. package/dist/telemetry/retention.d.ts +131 -0
  300. package/dist/telemetry/retention.js +217 -0
  301. package/dist/telemetry/schema.d.ts +113 -0
  302. package/dist/telemetry/schema.js +33 -0
  303. package/dist/telemetry/sink.d.ts +42 -0
  304. package/dist/telemetry/sink.js +61 -0
  305. package/dist/testing/contracts.d.ts +34 -0
  306. package/dist/testing/contracts.js +34 -0
  307. package/dist/testing/definitions.d.ts +15 -0
  308. package/dist/testing/definitions.js +48 -0
  309. package/dist/testing/doubles.d.ts +94 -0
  310. package/dist/testing/doubles.js +141 -0
  311. package/dist/testing/episode-harness.d.ts +49 -0
  312. package/dist/testing/episode-harness.js +65 -0
  313. package/dist/testing/filesystem.d.ts +17 -0
  314. package/dist/testing/filesystem.js +17 -0
  315. package/dist/testing/fixtures.d.ts +57 -0
  316. package/dist/testing/fixtures.js +84 -0
  317. package/dist/testing/hold-contract.d.ts +19 -0
  318. package/dist/testing/hold-contract.js +374 -0
  319. package/dist/testing/index.d.ts +41 -0
  320. package/dist/testing/index.js +41 -0
  321. package/dist/testing/journal-contract.d.ts +17 -0
  322. package/dist/testing/journal-contract.js +353 -0
  323. package/dist/testing/model-replies.d.ts +34 -0
  324. package/dist/testing/model-replies.js +101 -0
  325. package/dist/testing/primitives.d.ts +7 -0
  326. package/dist/testing/primitives.js +29 -0
  327. package/dist/testing/reader-signal-contract.d.ts +38 -0
  328. package/dist/testing/reader-signal-contract.js +318 -0
  329. package/dist/testing/row-security.d.ts +17 -0
  330. package/dist/testing/row-security.js +21 -0
  331. package/dist/testing/store-contract.d.ts +25 -0
  332. package/dist/testing/store-contract.js +500 -0
  333. package/dist/theme/apply.d.ts +17 -0
  334. package/dist/theme/apply.js +60 -0
  335. package/dist/theme/contrast.d.ts +197 -0
  336. package/dist/theme/contrast.js +259 -0
  337. package/dist/theme/derive.d.ts +77 -0
  338. package/dist/theme/derive.js +167 -0
  339. package/dist/theme/faces.d.ts +73 -0
  340. package/dist/theme/faces.js +119 -0
  341. package/dist/theme/font-packs.d.ts +25 -0
  342. package/dist/theme/font-packs.js +257 -0
  343. package/dist/theme/index.d.ts +20 -0
  344. package/dist/theme/index.js +20 -0
  345. package/dist/theme/lab.d.ts +30 -0
  346. package/dist/theme/lab.js +46 -0
  347. package/dist/theme/library.d.ts +114 -0
  348. package/dist/theme/library.js +300 -0
  349. package/dist/theme/measure.d.ts +144 -0
  350. package/dist/theme/measure.js +145 -0
  351. package/dist/theme/palettes.d.ts +64 -0
  352. package/dist/theme/palettes.js +497 -0
  353. package/dist/theme/registry.d.ts +59 -0
  354. package/dist/theme/registry.js +60 -0
  355. package/dist/theme/separation.d.ts +177 -0
  356. package/dist/theme/separation.js +203 -0
  357. package/dist/theme/style-presets.d.ts +60 -0
  358. package/dist/theme/style-presets.js +124 -0
  359. package/dist/theme/theme.d.ts +253 -0
  360. package/dist/theme/theme.js +171 -0
  361. package/dist/tree/apply.d.ts +16 -0
  362. package/dist/tree/apply.js +104 -0
  363. package/dist/tree/builders.d.ts +19 -0
  364. package/dist/tree/builders.js +20 -0
  365. package/dist/tree/compare.d.ts +68 -0
  366. package/dist/tree/compare.js +75 -0
  367. package/dist/tree/configuration.d.ts +25 -0
  368. package/dist/tree/configuration.js +108 -0
  369. package/dist/tree/delta.d.ts +288 -0
  370. package/dist/tree/delta.js +88 -0
  371. package/dist/tree/errors.d.ts +69 -0
  372. package/dist/tree/errors.js +34 -0
  373. package/dist/tree/identity.d.ts +117 -0
  374. package/dist/tree/identity.js +145 -0
  375. package/dist/tree/index.d.ts +21 -0
  376. package/dist/tree/index.js +21 -0
  377. package/dist/tree/inverse.d.ts +24 -0
  378. package/dist/tree/inverse.js +112 -0
  379. package/dist/tree/mutation.d.ts +18 -0
  380. package/dist/tree/mutation.js +49 -0
  381. package/dist/tree/naming.d.ts +4 -0
  382. package/dist/tree/naming.js +35 -0
  383. package/dist/tree/navigation.d.ts +38 -0
  384. package/dist/tree/navigation.js +83 -0
  385. package/dist/tree/node.d.ts +103 -0
  386. package/dist/tree/node.js +46 -0
  387. package/dist/tree/outline.d.ts +28 -0
  388. package/dist/tree/outline.js +10 -0
  389. package/dist/tree/tree.d.ts +83 -0
  390. package/dist/tree/tree.js +62 -0
  391. package/dist/write/commit.d.ts +124 -0
  392. package/dist/write/commit.js +234 -0
  393. package/dist/write/held.d.ts +674 -0
  394. package/dist/write/held.js +185 -0
  395. package/dist/write/index.d.ts +11 -0
  396. package/dist/write/index.js +11 -0
  397. package/dist/write/liveness.d.ts +132 -0
  398. package/dist/write/liveness.js +91 -0
  399. package/dist/write/revert.d.ts +79 -0
  400. package/dist/write/revert.js +134 -0
  401. package/package.json +160 -0
@@ -0,0 +1,318 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { nodeIdSchema, treeIdSchema } from "../ids.js";
3
+ import { primitiveTypeSchema } from "../primitive-type.js";
4
+ /**
5
+ * Two suites, run against every implementation of the buffer and of the
6
+ * counters.
7
+ *
8
+ * The same argument as `store-contract.ts` and `journal-contract.ts`: an
9
+ * interface is only tested once a second implementation exists, and a
10
+ * disagreement between what runs under `pnpm dev` and what runs in production
11
+ * should be a failing test rather than a number somebody queries six weeks
12
+ * later and cannot explain.
13
+ */
14
+ export const TREE = treeIdSchema.parse("t_contract");
15
+ export const OTHER_TREE = treeIdSchema.parse("t_other");
16
+ export const nodeId = (name) => nodeIdSchema.parse(`n_${name}`);
17
+ export const primitiveType = (name) => primitiveTypeSchema.parse(name);
18
+ /** A key of the right shape, spelled so a failing assertion says which view it was. */
19
+ export const viewKey = (nth) => String(nth).padStart(32, "0");
20
+ export const batchOf = (signals, overrides = {}) => ({
21
+ treeId: TREE,
22
+ revision: 1,
23
+ sentAt: 1_000,
24
+ ...overrides,
25
+ signals: [...signals],
26
+ });
27
+ export const viewed = (name) => ({
28
+ kind: "viewed",
29
+ nodeId: nodeId(name),
30
+ type: primitiveType("loom.section"),
31
+ at: 1_000,
32
+ });
33
+ export const activated = (name) => ({
34
+ kind: "activated",
35
+ nodeId: nodeId(name),
36
+ type: primitiveType("loom.button"),
37
+ at: 1_100,
38
+ });
39
+ /**
40
+ * A press, and the regions it happened inside — nearest first, which is the
41
+ * order a broadcaster walks in.
42
+ *
43
+ * Spelled out rather than spread onto `activated`, because the ancestry is the
44
+ * thing under test and a helper that hid it would let a test pass while the
45
+ * field was absent.
46
+ */
47
+ export const activatedIn = (name, ...regions) => ({
48
+ kind: "activated",
49
+ nodeId: nodeId(name),
50
+ type: primitiveType("loom.button"),
51
+ at: 1_100,
52
+ within: regions.map((region) => ({ nodeId: nodeId(region), type: primitiveType("loom.section") })),
53
+ });
54
+ export const disclosedIn = (name, open, ...regions) => ({
55
+ kind: "disclosed",
56
+ nodeId: nodeId(name),
57
+ type: primitiveType("loom.faq"),
58
+ open,
59
+ at: 1_200,
60
+ within: regions.map((region) => ({ nodeId: nodeId(region), type: primitiveType("loom.section") })),
61
+ });
62
+ export const dwelled = (name, ms) => ({
63
+ kind: "dwelled",
64
+ nodeId: nodeId(name),
65
+ type: primitiveType("loom.section"),
66
+ ms,
67
+ });
68
+ const tally = (overrides = {}) => ({
69
+ treeId: TREE,
70
+ revision: 1,
71
+ nodeId: nodeId("hero"),
72
+ type: primitiveType("loom.section"),
73
+ views: 1,
74
+ reached: 1,
75
+ engaged: 0,
76
+ dwellMs: 500,
77
+ activations: 0,
78
+ opens: 0,
79
+ closes: 0,
80
+ ...overrides,
81
+ });
82
+ const PAIR = {
83
+ from: { nodeId: nodeId("pricing"), kind: "viewed" },
84
+ to: { nodeId: nodeId("buy"), kind: "activated" },
85
+ };
86
+ const AT = "2026-09-14T00:00:00.000Z";
87
+ const LATER = "2026-09-14T01:00:00.000Z";
88
+ const unwrap = (result) => {
89
+ if (!result.ok)
90
+ throw new Error(`expected ok, got ${JSON.stringify(result.error)}`);
91
+ return result.value;
92
+ };
93
+ export const describeReaderSignalJournalContract = (name, make) => {
94
+ describe(`${name} — ReaderSignalJournal contract`, () => {
95
+ it("reads back batches in the order they arrived", async () => {
96
+ const journal = await make();
97
+ await journal.receive([batchOf([viewed("a")]), batchOf([viewed("b")])]);
98
+ const page = unwrap(await journal.read());
99
+ expect(page.batches.map((batch) => batch.signals[0]?.nodeId)).toEqual([nodeId("a"), nodeId("b")]);
100
+ });
101
+ it("reads a tree it has never heard of as an empty page", async () => {
102
+ const journal = await make();
103
+ expect(unwrap(await journal.read({ treeId: OTHER_TREE })).batches).toEqual([]);
104
+ });
105
+ it("accepts a delivery of nothing", async () => {
106
+ const journal = await make();
107
+ expect(unwrap(await journal.receive([]))).toBeUndefined();
108
+ expect(unwrap(await journal.read()).batches).toEqual([]);
109
+ });
110
+ it("survives the round trip with every kind intact", async () => {
111
+ const journal = await make();
112
+ const signals = [
113
+ viewed("a"),
114
+ dwelled("a", 2_500),
115
+ activated("b"),
116
+ { kind: "disclosed", nodeId: nodeId("c"), type: primitiveType("loom.disclosure"), open: true, at: 1_200 },
117
+ ];
118
+ await journal.receive([batchOf(signals)]);
119
+ expect(unwrap(await journal.read()).batches[0]?.signals).toEqual(signals);
120
+ });
121
+ it("carries the view key through storage", async () => {
122
+ const journal = await make();
123
+ await journal.receive([batchOf([viewed("a")], { view: viewKey(7) })]);
124
+ expect(unwrap(await journal.read()).batches[0]?.view).toBe(viewKey(7));
125
+ });
126
+ it("keeps a batch that never had a view key distinguishable from one that did", async () => {
127
+ const journal = await make();
128
+ await journal.receive([batchOf([viewed("a")]), batchOf([viewed("b")], { view: viewKey(1) })]);
129
+ expect(unwrap(await journal.read()).batches.map((batch) => batch.view)).toEqual([
130
+ undefined,
131
+ viewKey(1),
132
+ ]);
133
+ });
134
+ it("keeps trees apart", async () => {
135
+ const journal = await make();
136
+ await journal.receive([batchOf([viewed("a")]), batchOf([viewed("b")], { treeId: OTHER_TREE })]);
137
+ const page = unwrap(await journal.read({ treeId: OTHER_TREE }));
138
+ expect(page.batches).toHaveLength(1);
139
+ expect(page.batches[0]?.treeId).toBe(OTHER_TREE);
140
+ });
141
+ it("stamps an arrival instant the sender never supplied", async () => {
142
+ const journal = await make();
143
+ await journal.receive([batchOf([viewed("a")], { sentAt: 0 })]);
144
+ const [batch] = unwrap(await journal.read()).batches;
145
+ expect(batch?.receivedAt).toMatch(/^\d{4}-\d{2}-\d{2}T/);
146
+ });
147
+ it("increases seq across separate deliveries", async () => {
148
+ const journal = await make();
149
+ await journal.receive([batchOf([viewed("a")])]);
150
+ await journal.receive([batchOf([viewed("b")])]);
151
+ const [first, second] = unwrap(await journal.read()).batches;
152
+ expect((second?.seq ?? 0) > (first?.seq ?? 0)).toBe(true);
153
+ });
154
+ describe("paging", () => {
155
+ const many = (count) => Array.from({ length: count }, (_unused, index) => batchOf([viewed(`n${index}`)]));
156
+ it("hands back a cursor and resumes after it", async () => {
157
+ const journal = await make();
158
+ await journal.receive(many(5));
159
+ const first = unwrap(await journal.read({ limit: 2 }));
160
+ expect(first.batches).toHaveLength(2);
161
+ expect(first.newer).not.toBeNull();
162
+ const next = unwrap(await journal.read({ limit: 2, cursor: first.newer }));
163
+ expect(next.batches.map((batch) => batch.signals[0]?.nodeId)).toEqual([
164
+ nodeId("n2"),
165
+ nodeId("n3"),
166
+ ]);
167
+ });
168
+ it("reports no cursor on the last page", async () => {
169
+ const journal = await make();
170
+ await journal.receive(many(2));
171
+ expect(unwrap(await journal.read({ limit: 50 })).newer).toBeNull();
172
+ });
173
+ it("clamps a limit rather than honouring it", async () => {
174
+ const journal = await make();
175
+ await journal.receive(many(3));
176
+ expect(unwrap(await journal.read({ limit: 10_000 })).batches).toHaveLength(3);
177
+ });
178
+ it("starts from the beginning when the cursor cannot be read", async () => {
179
+ const journal = await make();
180
+ await journal.receive(many(3));
181
+ expect(unwrap(await journal.read({ cursor: "not a position" })).batches).toHaveLength(3);
182
+ });
183
+ it("reads the newest page when asked for older with no cursor", async () => {
184
+ const journal = await make();
185
+ await journal.receive(many(5));
186
+ const page = unwrap(await journal.read({ direction: "older", limit: 2 }));
187
+ expect(page.batches.map((batch) => batch.signals[0]?.nodeId)).toEqual([
188
+ nodeId("n3"),
189
+ nodeId("n4"),
190
+ ]);
191
+ });
192
+ });
193
+ describe("forgetting", () => {
194
+ it("drops the batches below a position and keeps the rest", async () => {
195
+ const journal = await make();
196
+ await journal.receive([batchOf([viewed("a")]), batchOf([viewed("b")]), batchOf([viewed("c")])]);
197
+ const seqs = unwrap(await journal.read()).batches.map((batch) => batch.seq);
198
+ const forgotten = unwrap(await journal.forget({ before: seqs[2] }));
199
+ expect(forgotten.removed).toBe(2);
200
+ expect(unwrap(await journal.read()).batches.map((batch) => batch.signals[0]?.nodeId)).toEqual([
201
+ nodeId("c"),
202
+ ]);
203
+ });
204
+ it("is a no-op the second time", async () => {
205
+ const journal = await make();
206
+ await journal.receive([batchOf([viewed("a")])]);
207
+ const seqs = unwrap(await journal.read()).batches.map((batch) => batch.seq);
208
+ const before = seqs[0] + 1;
209
+ expect(unwrap(await journal.forget({ before })).removed).toBe(1);
210
+ expect(unwrap(await journal.forget({ before })).removed).toBe(0);
211
+ });
212
+ it("does not reuse the positions it forgot", async () => {
213
+ const journal = await make();
214
+ await journal.receive([batchOf([viewed("a")])]);
215
+ const [gone] = unwrap(await journal.read()).batches;
216
+ await journal.forget({ before: (gone?.seq ?? 0) + 1 });
217
+ await journal.receive([batchOf([viewed("b")])]);
218
+ const [fresh] = unwrap(await journal.read()).batches;
219
+ expect((fresh?.seq ?? 0) > (gone?.seq ?? 0)).toBe(true);
220
+ });
221
+ it("forgets across every tree, because a position is buffer-wide", async () => {
222
+ const journal = await make();
223
+ await journal.receive([batchOf([viewed("a")]), batchOf([viewed("b")], { treeId: OTHER_TREE })]);
224
+ const seqs = unwrap(await journal.read()).batches.map((batch) => batch.seq);
225
+ await journal.forget({ before: seqs[1] + 1 });
226
+ expect(unwrap(await journal.read()).batches).toEqual([]);
227
+ });
228
+ });
229
+ });
230
+ };
231
+ export const describeReaderTallyStoreContract = (name, make) => {
232
+ describe(`${name} — ReaderTallyStore contract`, () => {
233
+ it("reads back a tally it was given", async () => {
234
+ const store = await make();
235
+ await store.apply({ tallies: [tally()], funnels: [] }, AT);
236
+ const [row] = unwrap(await store.tallies());
237
+ expect(row).toMatchObject({ nodeId: nodeId("hero"), dwellMs: 500, views: 1, updatedAt: AT });
238
+ });
239
+ it("reads nothing from a store nothing has been applied to", async () => {
240
+ const store = await make();
241
+ expect(unwrap(await store.tallies())).toEqual([]);
242
+ expect(unwrap(await store.funnels())).toEqual([]);
243
+ });
244
+ it("accepts a rollup with nothing in it", async () => {
245
+ const store = await make();
246
+ expect(unwrap(await store.apply({ tallies: [], funnels: [] }, AT))).toBeUndefined();
247
+ });
248
+ /**
249
+ * The property the whole design rests on. Rollup reports what one window
250
+ * added, so a second window must add to the first rather than replace it —
251
+ * a store that overwrote would describe only the last few minutes and look
252
+ * entirely plausible doing it.
253
+ */
254
+ it("adds a second window to the first rather than replacing it", async () => {
255
+ const store = await make();
256
+ await store.apply({ tallies: [tally({ dwellMs: 500, activations: 1 })], funnels: [] }, AT);
257
+ await store.apply({ tallies: [tally({ dwellMs: 250, activations: 2 })], funnels: [] }, LATER);
258
+ const [row] = unwrap(await store.tallies());
259
+ expect(row).toMatchObject({ dwellMs: 750, activations: 3, views: 2, updatedAt: LATER });
260
+ });
261
+ /**
262
+ * The counter regions are reported by, held to the same rule as the rest.
263
+ * It is a view count, so adding windows over-counts a reader whose visit
264
+ * straddled a boundary — the same bound that already applies to `views` and
265
+ * `reached` (0147), and the reason a store must add rather than replace all
266
+ * the same.
267
+ */
268
+ it("adds the engaged views of a second window to the first", async () => {
269
+ const store = await make();
270
+ await store.apply({ tallies: [tally({ engaged: 2 })], funnels: [] }, AT);
271
+ await store.apply({ tallies: [tally({ engaged: 3 })], funnels: [] }, LATER);
272
+ const [row] = unwrap(await store.tallies());
273
+ expect(row).toMatchObject({ engaged: 5, updatedAt: LATER });
274
+ });
275
+ it("keeps revisions of the same node apart", async () => {
276
+ const store = await make();
277
+ await store.apply({ tallies: [tally({ revision: 1, dwellMs: 500 }), tally({ revision: 2, dwellMs: 30 })], funnels: [] }, AT);
278
+ expect(unwrap(await store.tallies({ revision: 2 })).map((row) => row.dwellMs)).toEqual([30]);
279
+ });
280
+ it("keeps trees apart", async () => {
281
+ const store = await make();
282
+ await store.apply({ tallies: [tally(), tally({ treeId: OTHER_TREE, dwellMs: 11 })], funnels: [] }, AT);
283
+ expect(unwrap(await store.tallies({ treeId: OTHER_TREE })).map((row) => row.dwellMs)).toEqual([11]);
284
+ });
285
+ it("keeps nodes of the same revision apart", async () => {
286
+ const store = await make();
287
+ await store.apply({ tallies: [tally({ nodeId: nodeId("hero") }), tally({ nodeId: nodeId("pricing") })], funnels: [] }, AT);
288
+ expect(unwrap(await store.tallies())).toHaveLength(2);
289
+ });
290
+ it("reads back a funnel answer as the pair it was asked about", async () => {
291
+ const store = await make();
292
+ await store.apply({ tallies: [], funnels: [{ treeId: TREE, revision: 1, pair: PAIR, reached: 40, converted: 9 }] }, AT);
293
+ const [row] = unwrap(await store.funnels());
294
+ expect(row?.pair).toEqual(PAIR);
295
+ expect(row).toMatchObject({ reached: 40, converted: 9 });
296
+ });
297
+ it("adds funnel windows together too", async () => {
298
+ const store = await make();
299
+ const answer = { treeId: TREE, revision: 1, pair: PAIR, reached: 40, converted: 9 };
300
+ await store.apply({ tallies: [], funnels: [answer] }, AT);
301
+ await store.apply({ tallies: [], funnels: [{ ...answer, reached: 10, converted: 1 }] }, LATER);
302
+ expect(unwrap(await store.funnels())[0]).toMatchObject({ reached: 50, converted: 10 });
303
+ });
304
+ it("keeps two funnels that share a starting node apart", async () => {
305
+ const store = await make();
306
+ const other = { from: PAIR.from, to: { nodeId: nodeId("contact"), kind: "activated" } };
307
+ await store.apply({
308
+ tallies: [],
309
+ funnels: [
310
+ { treeId: TREE, revision: 1, pair: PAIR, reached: 40, converted: 9 },
311
+ { treeId: TREE, revision: 1, pair: other, reached: 40, converted: 3 },
312
+ ],
313
+ }, AT);
314
+ expect(unwrap(await store.funnels()).map((row) => row.converted).sort()).toEqual([3, 9]);
315
+ });
316
+ });
317
+ };
318
+ //# sourceMappingURL=reader-signal-contract.js.map
@@ -0,0 +1,17 @@
1
+ import type { LoomDatabase } from "../store/database.js";
2
+ /**
3
+ * Asking Postgres whether a table really is protected.
4
+ *
5
+ * A test helper, shared so that the store's suite and the journal's check the
6
+ * same promise the same way.
7
+ */
8
+ /**
9
+ * Whether Postgres has row level security on a table, read from the catalogue
10
+ * rather than inferred from having run the statement.
11
+ *
12
+ * Shared because the store's DDL and the journal's both make the same promise,
13
+ * and a promise checked two different ways is a promise one of them will stop
14
+ * checking. `db.execute` hands back `{ rows }` on both drivers Loom runs on.
15
+ */
16
+ export declare const rowSecurityOn: (db: LoomDatabase, table: string) => Promise<boolean>;
17
+ //# sourceMappingURL=row-security.d.ts.map
@@ -0,0 +1,21 @@
1
+ import { sql } from "drizzle-orm";
2
+ /**
3
+ * Asking Postgres whether a table really is protected.
4
+ *
5
+ * A test helper, shared so that the store's suite and the journal's check the
6
+ * same promise the same way.
7
+ */
8
+ /**
9
+ * Whether Postgres has row level security on a table, read from the catalogue
10
+ * rather than inferred from having run the statement.
11
+ *
12
+ * Shared because the store's DDL and the journal's both make the same promise,
13
+ * and a promise checked two different ways is a promise one of them will stop
14
+ * checking. `db.execute` hands back `{ rows }` on both drivers Loom runs on.
15
+ */
16
+ export const rowSecurityOn = async (db, table) => {
17
+ const result = await db.execute(sql `SELECT relrowsecurity FROM pg_class WHERE relname = ${table}`);
18
+ const rows = result.rows;
19
+ return rows?.[0]?.relrowsecurity === true;
20
+ };
21
+ //# sourceMappingURL=row-security.js.map
@@ -0,0 +1,25 @@
1
+ import type { AppendRequest, TreeStore } from "../store/store.js";
2
+ import type { TreeDelta } from "../tree/delta.js";
3
+ import { type LoomTree } from "../tree/tree.js";
4
+ /**
5
+ * One suite, run against every `TreeStore`.
6
+ *
7
+ * `memory.ts` has described itself as "the reference implementation ... what a
8
+ * SQL or KV implementation will be checked against" since the day it was written.
9
+ * That was a promise; this is what makes it true. A behavioural disagreement
10
+ * between the in-memory store and Postgres is now a test failure rather than
11
+ * something discovered in production.
12
+ *
13
+ * Only behaviour the *contract* promises belongs here. Anything specific to one
14
+ * implementation — how it reports a connection failure, what it exposes beyond
15
+ * the interface — stays in that implementation's own test file.
16
+ */
17
+ export declare const appendOf: (delta: TreeDelta, proposal?: string) => AppendRequest;
18
+ export declare const removalOf: (tree: LoomTree, nodeId: string, baseRevision?: number) => TreeDelta;
19
+ export declare const treeNamed: (namespace: string) => LoomTree;
20
+ /**
21
+ * `makeStore` returns a store with nothing in it. Each test gets its own, so the
22
+ * suite never depends on the order it runs in.
23
+ */
24
+ export declare const describeTreeStoreContract: (name: string, makeStore: () => Promise<TreeStore> | TreeStore) => void;
25
+ //# sourceMappingURL=store-contract.d.ts.map