@optimystic/db-core 0.13.4 → 0.14.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 (447) hide show
  1. package/dist/src/cluster/structs.d.ts +29 -0
  2. package/dist/src/cluster/structs.d.ts.map +1 -1
  3. package/dist/src/cohort-topic/addressing.d.ts +53 -0
  4. package/dist/src/cohort-topic/addressing.d.ts.map +1 -0
  5. package/dist/src/cohort-topic/addressing.js +95 -0
  6. package/dist/src/cohort-topic/addressing.js.map +1 -0
  7. package/dist/src/cohort-topic/antidos/bootstrap-evidence-envelope.d.ts +105 -0
  8. package/dist/src/cohort-topic/antidos/bootstrap-evidence-envelope.d.ts.map +1 -0
  9. package/dist/src/cohort-topic/antidos/bootstrap-evidence-envelope.js +197 -0
  10. package/dist/src/cohort-topic/antidos/bootstrap-evidence-envelope.js.map +1 -0
  11. package/dist/src/cohort-topic/antidos/bootstrap-evidence.d.ts +50 -0
  12. package/dist/src/cohort-topic/antidos/bootstrap-evidence.d.ts.map +1 -0
  13. package/dist/src/cohort-topic/antidos/bootstrap-evidence.js +62 -0
  14. package/dist/src/cohort-topic/antidos/bootstrap-evidence.js.map +1 -0
  15. package/dist/src/cohort-topic/antidos/index.d.ts +6 -0
  16. package/dist/src/cohort-topic/antidos/index.d.ts.map +1 -0
  17. package/dist/src/cohort-topic/antidos/index.js +6 -0
  18. package/dist/src/cohort-topic/antidos/index.js.map +1 -0
  19. package/dist/src/cohort-topic/antidos/rate-limiter.d.ts +95 -0
  20. package/dist/src/cohort-topic/antidos/rate-limiter.d.ts.map +1 -0
  21. package/dist/src/cohort-topic/antidos/rate-limiter.js +146 -0
  22. package/dist/src/cohort-topic/antidos/rate-limiter.js.map +1 -0
  23. package/dist/src/cohort-topic/antidos/replay-guard.d.ts +37 -0
  24. package/dist/src/cohort-topic/antidos/replay-guard.d.ts.map +1 -0
  25. package/dist/src/cohort-topic/antidos/replay-guard.js +78 -0
  26. package/dist/src/cohort-topic/antidos/replay-guard.js.map +1 -0
  27. package/dist/src/cohort-topic/antidos/topic-budget.d.ts +50 -0
  28. package/dist/src/cohort-topic/antidos/topic-budget.d.ts.map +1 -0
  29. package/dist/src/cohort-topic/antidos/topic-budget.js +95 -0
  30. package/dist/src/cohort-topic/antidos/topic-budget.js.map +1 -0
  31. package/dist/src/cohort-topic/antiflood/index.d.ts +3 -0
  32. package/dist/src/cohort-topic/antiflood/index.d.ts.map +1 -0
  33. package/dist/src/cohort-topic/antiflood/index.js +3 -0
  34. package/dist/src/cohort-topic/antiflood/index.js.map +1 -0
  35. package/dist/src/cohort-topic/antiflood/invariants.d.ts +70 -0
  36. package/dist/src/cohort-topic/antiflood/invariants.d.ts.map +1 -0
  37. package/dist/src/cohort-topic/antiflood/invariants.js +86 -0
  38. package/dist/src/cohort-topic/antiflood/invariants.js.map +1 -0
  39. package/dist/src/cohort-topic/antiflood/jitter.d.ts +65 -0
  40. package/dist/src/cohort-topic/antiflood/jitter.d.ts.map +1 -0
  41. package/dist/src/cohort-topic/antiflood/jitter.js +75 -0
  42. package/dist/src/cohort-topic/antiflood/jitter.js.map +1 -0
  43. package/dist/src/cohort-topic/coldstart.d.ts +117 -0
  44. package/dist/src/cohort-topic/coldstart.d.ts.map +1 -0
  45. package/dist/src/cohort-topic/coldstart.js +127 -0
  46. package/dist/src/cohort-topic/coldstart.js.map +1 -0
  47. package/dist/src/cohort-topic/dmax.d.ts +44 -0
  48. package/dist/src/cohort-topic/dmax.d.ts.map +1 -0
  49. package/dist/src/cohort-topic/dmax.js +70 -0
  50. package/dist/src/cohort-topic/dmax.js.map +1 -0
  51. package/dist/src/cohort-topic/gossip/bus.d.ts +85 -0
  52. package/dist/src/cohort-topic/gossip/bus.d.ts.map +1 -0
  53. package/dist/src/cohort-topic/gossip/bus.js +146 -0
  54. package/dist/src/cohort-topic/gossip/bus.js.map +1 -0
  55. package/dist/src/cohort-topic/gossip/index.d.ts +4 -0
  56. package/dist/src/cohort-topic/gossip/index.d.ts.map +1 -0
  57. package/dist/src/cohort-topic/gossip/index.js +4 -0
  58. package/dist/src/cohort-topic/gossip/index.js.map +1 -0
  59. package/dist/src/cohort-topic/gossip/records.d.ts +12 -0
  60. package/dist/src/cohort-topic/gossip/records.d.ts.map +1 -0
  61. package/dist/src/cohort-topic/gossip/records.js +41 -0
  62. package/dist/src/cohort-topic/gossip/records.js.map +1 -0
  63. package/dist/src/cohort-topic/gossip/view.d.ts +39 -0
  64. package/dist/src/cohort-topic/gossip/view.d.ts.map +1 -0
  65. package/dist/src/cohort-topic/gossip/view.js +30 -0
  66. package/dist/src/cohort-topic/gossip/view.js.map +1 -0
  67. package/dist/src/cohort-topic/index.d.ts +21 -0
  68. package/dist/src/cohort-topic/index.d.ts.map +1 -0
  69. package/dist/src/cohort-topic/index.js +21 -0
  70. package/dist/src/cohort-topic/index.js.map +1 -0
  71. package/dist/src/cohort-topic/load/barometer.d.ts +78 -0
  72. package/dist/src/cohort-topic/load/barometer.d.ts.map +1 -0
  73. package/dist/src/cohort-topic/load/barometer.js +93 -0
  74. package/dist/src/cohort-topic/load/barometer.js.map +1 -0
  75. package/dist/src/cohort-topic/load/index.d.ts +2 -0
  76. package/dist/src/cohort-topic/load/index.d.ts.map +1 -0
  77. package/dist/src/cohort-topic/load/index.js +2 -0
  78. package/dist/src/cohort-topic/load/index.js.map +1 -0
  79. package/dist/src/cohort-topic/member-engine.d.ts +134 -0
  80. package/dist/src/cohort-topic/member-engine.d.ts.map +1 -0
  81. package/dist/src/cohort-topic/member-engine.js +264 -0
  82. package/dist/src/cohort-topic/member-engine.js.map +1 -0
  83. package/dist/src/cohort-topic/membership/index.d.ts +4 -0
  84. package/dist/src/cohort-topic/membership/index.d.ts.map +1 -0
  85. package/dist/src/cohort-topic/membership/index.js +4 -0
  86. package/dist/src/cohort-topic/membership/index.js.map +1 -0
  87. package/dist/src/cohort-topic/membership/publisher.d.ts +82 -0
  88. package/dist/src/cohort-topic/membership/publisher.d.ts.map +1 -0
  89. package/dist/src/cohort-topic/membership/publisher.js +107 -0
  90. package/dist/src/cohort-topic/membership/publisher.js.map +1 -0
  91. package/dist/src/cohort-topic/membership/source.d.ts +31 -0
  92. package/dist/src/cohort-topic/membership/source.d.ts.map +1 -0
  93. package/dist/src/cohort-topic/membership/source.js +32 -0
  94. package/dist/src/cohort-topic/membership/source.js.map +1 -0
  95. package/dist/src/cohort-topic/membership/verifier.d.ts +96 -0
  96. package/dist/src/cohort-topic/membership/verifier.d.ts.map +1 -0
  97. package/dist/src/cohort-topic/membership/verifier.js +250 -0
  98. package/dist/src/cohort-topic/membership/verifier.js.map +1 -0
  99. package/dist/src/cohort-topic/ports.d.ts +149 -0
  100. package/dist/src/cohort-topic/ports.d.ts.map +1 -0
  101. package/dist/src/cohort-topic/ports.js +25 -0
  102. package/dist/src/cohort-topic/ports.js.map +1 -0
  103. package/dist/src/cohort-topic/promotion.d.ts +135 -0
  104. package/dist/src/cohort-topic/promotion.d.ts.map +1 -0
  105. package/dist/src/cohort-topic/promotion.js +269 -0
  106. package/dist/src/cohort-topic/promotion.js.map +1 -0
  107. package/dist/src/cohort-topic/registration/bytes.d.ts +16 -0
  108. package/dist/src/cohort-topic/registration/bytes.d.ts.map +1 -0
  109. package/dist/src/cohort-topic/registration/bytes.js +32 -0
  110. package/dist/src/cohort-topic/registration/bytes.js.map +1 -0
  111. package/dist/src/cohort-topic/registration/handoff.d.ts +69 -0
  112. package/dist/src/cohort-topic/registration/handoff.d.ts.map +1 -0
  113. package/dist/src/cohort-topic/registration/handoff.js +98 -0
  114. package/dist/src/cohort-topic/registration/handoff.js.map +1 -0
  115. package/dist/src/cohort-topic/registration/index.d.ts +7 -0
  116. package/dist/src/cohort-topic/registration/index.d.ts.map +1 -0
  117. package/dist/src/cohort-topic/registration/index.js +7 -0
  118. package/dist/src/cohort-topic/registration/index.js.map +1 -0
  119. package/dist/src/cohort-topic/registration/renewal.d.ts +115 -0
  120. package/dist/src/cohort-topic/registration/renewal.d.ts.map +1 -0
  121. package/dist/src/cohort-topic/registration/renewal.js +306 -0
  122. package/dist/src/cohort-topic/registration/renewal.js.map +1 -0
  123. package/dist/src/cohort-topic/registration/sharding.d.ts +31 -0
  124. package/dist/src/cohort-topic/registration/sharding.d.ts.map +1 -0
  125. package/dist/src/cohort-topic/registration/sharding.js +48 -0
  126. package/dist/src/cohort-topic/registration/sharding.js.map +1 -0
  127. package/dist/src/cohort-topic/registration/store.d.ts +13 -0
  128. package/dist/src/cohort-topic/registration/store.d.ts.map +1 -0
  129. package/dist/src/cohort-topic/registration/store.js +72 -0
  130. package/dist/src/cohort-topic/registration/store.js.map +1 -0
  131. package/dist/src/cohort-topic/registration/types.d.ts +71 -0
  132. package/dist/src/cohort-topic/registration/types.d.ts.map +1 -0
  133. package/dist/src/cohort-topic/registration/types.js +27 -0
  134. package/dist/src/cohort-topic/registration/types.js.map +1 -0
  135. package/dist/src/cohort-topic/ring-hash.d.ts +27 -0
  136. package/dist/src/cohort-topic/ring-hash.d.ts.map +1 -0
  137. package/dist/src/cohort-topic/ring-hash.js +45 -0
  138. package/dist/src/cohort-topic/ring-hash.js.map +1 -0
  139. package/dist/src/cohort-topic/service.d.ts +157 -0
  140. package/dist/src/cohort-topic/service.d.ts.map +1 -0
  141. package/dist/src/cohort-topic/service.js +237 -0
  142. package/dist/src/cohort-topic/service.js.map +1 -0
  143. package/dist/src/cohort-topic/sig/index.d.ts +3 -0
  144. package/dist/src/cohort-topic/sig/index.d.ts.map +1 -0
  145. package/dist/src/cohort-topic/sig/index.js +3 -0
  146. package/dist/src/cohort-topic/sig/index.js.map +1 -0
  147. package/dist/src/cohort-topic/sig/payloads.d.ts +25 -0
  148. package/dist/src/cohort-topic/sig/payloads.d.ts.map +1 -0
  149. package/dist/src/cohort-topic/sig/payloads.js +25 -0
  150. package/dist/src/cohort-topic/sig/payloads.js.map +1 -0
  151. package/dist/src/cohort-topic/sig/threshold.d.ts +33 -0
  152. package/dist/src/cohort-topic/sig/threshold.d.ts.map +1 -0
  153. package/dist/src/cohort-topic/sig/threshold.js +51 -0
  154. package/dist/src/cohort-topic/sig/threshold.js.map +1 -0
  155. package/dist/src/cohort-topic/tiers.d.ts +58 -0
  156. package/dist/src/cohort-topic/tiers.d.ts.map +1 -0
  157. package/dist/src/cohort-topic/tiers.js +49 -0
  158. package/dist/src/cohort-topic/tiers.js.map +1 -0
  159. package/dist/src/cohort-topic/traffic.d.ts +90 -0
  160. package/dist/src/cohort-topic/traffic.d.ts.map +1 -0
  161. package/dist/src/cohort-topic/traffic.js +146 -0
  162. package/dist/src/cohort-topic/traffic.js.map +1 -0
  163. package/dist/src/cohort-topic/walk.d.ts +123 -0
  164. package/dist/src/cohort-topic/walk.d.ts.map +1 -0
  165. package/dist/src/cohort-topic/walk.js +150 -0
  166. package/dist/src/cohort-topic/walk.js.map +1 -0
  167. package/dist/src/cohort-topic/willingness.d.ts +123 -0
  168. package/dist/src/cohort-topic/willingness.d.ts.map +1 -0
  169. package/dist/src/cohort-topic/willingness.js +143 -0
  170. package/dist/src/cohort-topic/willingness.js.map +1 -0
  171. package/dist/src/cohort-topic/wire/codec.d.ts +42 -0
  172. package/dist/src/cohort-topic/wire/codec.d.ts.map +1 -0
  173. package/dist/src/cohort-topic/wire/codec.js +163 -0
  174. package/dist/src/cohort-topic/wire/codec.js.map +1 -0
  175. package/dist/src/cohort-topic/wire/index.d.ts +6 -0
  176. package/dist/src/cohort-topic/wire/index.d.ts.map +1 -0
  177. package/dist/src/cohort-topic/wire/index.js +6 -0
  178. package/dist/src/cohort-topic/wire/index.js.map +1 -0
  179. package/dist/src/cohort-topic/wire/payloads.d.ts +38 -0
  180. package/dist/src/cohort-topic/wire/payloads.d.ts.map +1 -0
  181. package/dist/src/cohort-topic/wire/payloads.js +102 -0
  182. package/dist/src/cohort-topic/wire/payloads.js.map +1 -0
  183. package/dist/src/cohort-topic/wire/types.d.ts +304 -0
  184. package/dist/src/cohort-topic/wire/types.d.ts.map +1 -0
  185. package/dist/src/cohort-topic/wire/types.js +16 -0
  186. package/dist/src/cohort-topic/wire/types.js.map +1 -0
  187. package/dist/src/cohort-topic/wire/validate.d.ts +25 -0
  188. package/dist/src/cohort-topic/wire/validate.d.ts.map +1 -0
  189. package/dist/src/cohort-topic/wire/validate.js +427 -0
  190. package/dist/src/cohort-topic/wire/validate.js.map +1 -0
  191. package/dist/src/collection/collection.d.ts +58 -1
  192. package/dist/src/collection/collection.d.ts.map +1 -1
  193. package/dist/src/collection/collection.js +76 -0
  194. package/dist/src/collection/collection.js.map +1 -1
  195. package/dist/src/collections/tree/tree.d.ts +58 -2
  196. package/dist/src/collections/tree/tree.d.ts.map +1 -1
  197. package/dist/src/collections/tree/tree.js +59 -2
  198. package/dist/src/collections/tree/tree.js.map +1 -1
  199. package/dist/src/index.d.ts +3 -0
  200. package/dist/src/index.d.ts.map +1 -1
  201. package/dist/src/index.js +3 -0
  202. package/dist/src/index.js.map +1 -1
  203. package/dist/src/log/log.d.ts +42 -4
  204. package/dist/src/log/log.d.ts.map +1 -1
  205. package/dist/src/log/log.js +71 -3
  206. package/dist/src/log/log.js.map +1 -1
  207. package/dist/src/log/struct.d.ts +122 -2
  208. package/dist/src/log/struct.d.ts.map +1 -1
  209. package/dist/src/log/struct.js.map +1 -1
  210. package/dist/src/matchmaking/capability-filter.d.ts +24 -0
  211. package/dist/src/matchmaking/capability-filter.d.ts.map +1 -0
  212. package/dist/src/matchmaking/capability-filter.js +37 -0
  213. package/dist/src/matchmaking/capability-filter.js.map +1 -0
  214. package/dist/src/matchmaking/config.d.ts +77 -0
  215. package/dist/src/matchmaking/config.d.ts.map +1 -0
  216. package/dist/src/matchmaking/config.js +69 -0
  217. package/dist/src/matchmaking/config.js.map +1 -0
  218. package/dist/src/matchmaking/index.d.ts +21 -0
  219. package/dist/src/matchmaking/index.d.ts.map +1 -0
  220. package/dist/src/matchmaking/index.js +21 -0
  221. package/dist/src/matchmaking/index.js.map +1 -0
  222. package/dist/src/matchmaking/multi-cohort-seeker.d.ts +133 -0
  223. package/dist/src/matchmaking/multi-cohort-seeker.d.ts.map +1 -0
  224. package/dist/src/matchmaking/multi-cohort-seeker.js +142 -0
  225. package/dist/src/matchmaking/multi-cohort-seeker.js.map +1 -0
  226. package/dist/src/matchmaking/provider.d.ts +70 -0
  227. package/dist/src/matchmaking/provider.d.ts.map +1 -0
  228. package/dist/src/matchmaking/provider.js +93 -0
  229. package/dist/src/matchmaking/provider.js.map +1 -0
  230. package/dist/src/matchmaking/query-eval.d.ts +53 -0
  231. package/dist/src/matchmaking/query-eval.d.ts.map +1 -0
  232. package/dist/src/matchmaking/query-eval.js +69 -0
  233. package/dist/src/matchmaking/query-eval.js.map +1 -0
  234. package/dist/src/matchmaking/seeker-walk.d.ts +95 -0
  235. package/dist/src/matchmaking/seeker-walk.d.ts.map +1 -0
  236. package/dist/src/matchmaking/seeker-walk.js +75 -0
  237. package/dist/src/matchmaking/seeker-walk.js.map +1 -0
  238. package/dist/src/matchmaking/seeker.d.ts +51 -0
  239. package/dist/src/matchmaking/seeker.d.ts.map +1 -0
  240. package/dist/src/matchmaking/seeker.js +62 -0
  241. package/dist/src/matchmaking/seeker.js.map +1 -0
  242. package/dist/src/matchmaking/topic-anchor.d.ts +54 -0
  243. package/dist/src/matchmaking/topic-anchor.d.ts.map +1 -0
  244. package/dist/src/matchmaking/topic-anchor.js +67 -0
  245. package/dist/src/matchmaking/topic-anchor.js.map +1 -0
  246. package/dist/src/matchmaking/voting-quorum.d.ts +233 -0
  247. package/dist/src/matchmaking/voting-quorum.d.ts.map +1 -0
  248. package/dist/src/matchmaking/voting-quorum.js +238 -0
  249. package/dist/src/matchmaking/voting-quorum.js.map +1 -0
  250. package/dist/src/matchmaking/wire.d.ts +259 -0
  251. package/dist/src/matchmaking/wire.d.ts.map +1 -0
  252. package/dist/src/matchmaking/wire.js +484 -0
  253. package/dist/src/matchmaking/wire.js.map +1 -0
  254. package/dist/src/network/i-repo.d.ts +19 -0
  255. package/dist/src/network/i-repo.d.ts.map +1 -1
  256. package/dist/src/network/repo-protocol.d.ts +3 -1
  257. package/dist/src/network/repo-protocol.d.ts.map +1 -1
  258. package/dist/src/network/struct.d.ts +23 -1
  259. package/dist/src/network/struct.d.ts.map +1 -1
  260. package/dist/src/reactivity/backfill.d.ts +118 -0
  261. package/dist/src/reactivity/backfill.d.ts.map +1 -0
  262. package/dist/src/reactivity/backfill.js +137 -0
  263. package/dist/src/reactivity/backfill.js.map +1 -0
  264. package/dist/src/reactivity/backpressure.d.ts +99 -0
  265. package/dist/src/reactivity/backpressure.d.ts.map +1 -0
  266. package/dist/src/reactivity/backpressure.js +153 -0
  267. package/dist/src/reactivity/backpressure.js.map +1 -0
  268. package/dist/src/reactivity/checkpoint.d.ts +165 -0
  269. package/dist/src/reactivity/checkpoint.d.ts.map +1 -0
  270. package/dist/src/reactivity/checkpoint.js +232 -0
  271. package/dist/src/reactivity/checkpoint.js.map +1 -0
  272. package/dist/src/reactivity/config.d.ts +131 -0
  273. package/dist/src/reactivity/config.d.ts.map +1 -0
  274. package/dist/src/reactivity/config.js +135 -0
  275. package/dist/src/reactivity/config.js.map +1 -0
  276. package/dist/src/reactivity/dedupe.d.ts +51 -0
  277. package/dist/src/reactivity/dedupe.d.ts.map +1 -0
  278. package/dist/src/reactivity/dedupe.js +90 -0
  279. package/dist/src/reactivity/dedupe.js.map +1 -0
  280. package/dist/src/reactivity/forwarder.d.ts +50 -0
  281. package/dist/src/reactivity/forwarder.d.ts.map +1 -0
  282. package/dist/src/reactivity/forwarder.js +52 -0
  283. package/dist/src/reactivity/forwarder.js.map +1 -0
  284. package/dist/src/reactivity/index.d.ts +34 -0
  285. package/dist/src/reactivity/index.d.ts.map +1 -0
  286. package/dist/src/reactivity/index.js +34 -0
  287. package/dist/src/reactivity/index.js.map +1 -0
  288. package/dist/src/reactivity/notification.d.ts +72 -0
  289. package/dist/src/reactivity/notification.d.ts.map +1 -0
  290. package/dist/src/reactivity/notification.js +92 -0
  291. package/dist/src/reactivity/notification.js.map +1 -0
  292. package/dist/src/reactivity/policy.d.ts +59 -0
  293. package/dist/src/reactivity/policy.d.ts.map +1 -0
  294. package/dist/src/reactivity/policy.js +64 -0
  295. package/dist/src/reactivity/policy.js.map +1 -0
  296. package/dist/src/reactivity/push-state.d.ts +140 -0
  297. package/dist/src/reactivity/push-state.d.ts.map +1 -0
  298. package/dist/src/reactivity/push-state.js +270 -0
  299. package/dist/src/reactivity/push-state.js.map +1 -0
  300. package/dist/src/reactivity/recover.d.ts +75 -0
  301. package/dist/src/reactivity/recover.d.ts.map +1 -0
  302. package/dist/src/reactivity/recover.js +105 -0
  303. package/dist/src/reactivity/recover.js.map +1 -0
  304. package/dist/src/reactivity/replay-buffer.d.ts +57 -0
  305. package/dist/src/reactivity/replay-buffer.d.ts.map +1 -0
  306. package/dist/src/reactivity/replay-buffer.js +88 -0
  307. package/dist/src/reactivity/replay-buffer.js.map +1 -0
  308. package/dist/src/reactivity/resume.d.ts +214 -0
  309. package/dist/src/reactivity/resume.d.ts.map +1 -0
  310. package/dist/src/reactivity/resume.js +358 -0
  311. package/dist/src/reactivity/resume.js.map +1 -0
  312. package/dist/src/reactivity/rotation.d.ts +283 -0
  313. package/dist/src/reactivity/rotation.d.ts.map +1 -0
  314. package/dist/src/reactivity/rotation.js +265 -0
  315. package/dist/src/reactivity/rotation.js.map +1 -0
  316. package/dist/src/reactivity/subscriber.d.ts +66 -0
  317. package/dist/src/reactivity/subscriber.d.ts.map +1 -0
  318. package/dist/src/reactivity/subscriber.js +75 -0
  319. package/dist/src/reactivity/subscriber.js.map +1 -0
  320. package/dist/src/reactivity/subscription.d.ts +52 -0
  321. package/dist/src/reactivity/subscription.d.ts.map +1 -0
  322. package/dist/src/reactivity/subscription.js +28 -0
  323. package/dist/src/reactivity/subscription.js.map +1 -0
  324. package/dist/src/reactivity/topic-anchor.d.ts +46 -0
  325. package/dist/src/reactivity/topic-anchor.d.ts.map +1 -0
  326. package/dist/src/reactivity/topic-anchor.js +61 -0
  327. package/dist/src/reactivity/topic-anchor.js.map +1 -0
  328. package/dist/src/reactivity/verify.d.ts +41 -0
  329. package/dist/src/reactivity/verify.d.ts.map +1 -0
  330. package/dist/src/reactivity/verify.js +48 -0
  331. package/dist/src/reactivity/verify.js.map +1 -0
  332. package/dist/src/reactivity/wire-validate.d.ts +28 -0
  333. package/dist/src/reactivity/wire-validate.d.ts.map +1 -0
  334. package/dist/src/reactivity/wire-validate.js +79 -0
  335. package/dist/src/reactivity/wire-validate.js.map +1 -0
  336. package/dist/src/reactivity/wire.d.ts +102 -0
  337. package/dist/src/reactivity/wire.d.ts.map +1 -0
  338. package/dist/src/reactivity/wire.js +129 -0
  339. package/dist/src/reactivity/wire.js.map +1 -0
  340. package/dist/src/transaction/coordinator.d.ts +9 -5
  341. package/dist/src/transaction/coordinator.d.ts.map +1 -1
  342. package/dist/src/transaction/coordinator.js +48 -25
  343. package/dist/src/transaction/coordinator.js.map +1 -1
  344. package/dist/src/transactor/change-notifier.d.ts +74 -0
  345. package/dist/src/transactor/change-notifier.d.ts.map +1 -0
  346. package/dist/src/transactor/change-notifier.js +4 -0
  347. package/dist/src/transactor/change-notifier.js.map +1 -0
  348. package/dist/src/transactor/index.d.ts +1 -0
  349. package/dist/src/transactor/index.d.ts.map +1 -1
  350. package/dist/src/transactor/index.js +1 -0
  351. package/dist/src/transactor/index.js.map +1 -1
  352. package/dist/src/transactor/network-transactor.d.ts +44 -2
  353. package/dist/src/transactor/network-transactor.d.ts.map +1 -1
  354. package/dist/src/transactor/network-transactor.js +132 -17
  355. package/dist/src/transactor/network-transactor.js.map +1 -1
  356. package/package.json +3 -2
  357. package/src/cluster/structs.ts +86 -57
  358. package/src/cohort-topic/addressing.ts +112 -0
  359. package/src/cohort-topic/antidos/bootstrap-evidence-envelope.ts +253 -0
  360. package/src/cohort-topic/antidos/bootstrap-evidence.ts +94 -0
  361. package/src/cohort-topic/antidos/index.ts +5 -0
  362. package/src/cohort-topic/antidos/rate-limiter.ts +210 -0
  363. package/src/cohort-topic/antidos/replay-guard.ts +109 -0
  364. package/src/cohort-topic/antidos/topic-budget.ts +145 -0
  365. package/src/cohort-topic/antiflood/index.ts +2 -0
  366. package/src/cohort-topic/antiflood/invariants.ts +108 -0
  367. package/src/cohort-topic/antiflood/jitter.ts +117 -0
  368. package/src/cohort-topic/coldstart.ts +204 -0
  369. package/src/cohort-topic/dmax.ts +88 -0
  370. package/src/cohort-topic/gossip/bus.ts +217 -0
  371. package/src/cohort-topic/gossip/index.ts +3 -0
  372. package/src/cohort-topic/gossip/records.ts +45 -0
  373. package/src/cohort-topic/gossip/view.ts +66 -0
  374. package/src/cohort-topic/index.ts +20 -0
  375. package/src/cohort-topic/load/barometer.ts +134 -0
  376. package/src/cohort-topic/load/index.ts +1 -0
  377. package/src/cohort-topic/member-engine.ts +409 -0
  378. package/src/cohort-topic/membership/index.ts +3 -0
  379. package/src/cohort-topic/membership/publisher.ts +171 -0
  380. package/src/cohort-topic/membership/source.ts +41 -0
  381. package/src/cohort-topic/membership/verifier.ts +345 -0
  382. package/src/cohort-topic/ports.ts +157 -0
  383. package/src/cohort-topic/promotion.ts +384 -0
  384. package/src/cohort-topic/registration/bytes.ts +37 -0
  385. package/src/cohort-topic/registration/handoff.ts +154 -0
  386. package/src/cohort-topic/registration/index.ts +6 -0
  387. package/src/cohort-topic/registration/renewal.ts +423 -0
  388. package/src/cohort-topic/registration/sharding.ts +61 -0
  389. package/src/cohort-topic/registration/store.ts +81 -0
  390. package/src/cohort-topic/registration/types.ts +76 -0
  391. package/src/cohort-topic/ring-hash.ts +50 -0
  392. package/src/cohort-topic/service.ts +390 -0
  393. package/src/cohort-topic/sig/index.ts +2 -0
  394. package/src/cohort-topic/sig/payloads.ts +39 -0
  395. package/src/cohort-topic/sig/threshold.ts +64 -0
  396. package/src/cohort-topic/tiers.ts +74 -0
  397. package/src/cohort-topic/traffic.ts +211 -0
  398. package/src/cohort-topic/walk.ts +255 -0
  399. package/src/cohort-topic/willingness.ts +237 -0
  400. package/src/cohort-topic/wire/codec.ts +204 -0
  401. package/src/cohort-topic/wire/index.ts +16 -0
  402. package/src/cohort-topic/wire/payloads.ts +117 -0
  403. package/src/cohort-topic/wire/types.ts +343 -0
  404. package/src/cohort-topic/wire/validate.ts +478 -0
  405. package/src/collection/collection.ts +93 -1
  406. package/src/collections/tree/tree.ts +84 -3
  407. package/src/index.ts +3 -0
  408. package/src/log/log.ts +86 -7
  409. package/src/log/struct.ts +126 -2
  410. package/src/matchmaking/capability-filter.ts +45 -0
  411. package/src/matchmaking/config.ts +98 -0
  412. package/src/matchmaking/index.ts +21 -0
  413. package/src/matchmaking/multi-cohort-seeker.ts +234 -0
  414. package/src/matchmaking/provider.ts +123 -0
  415. package/src/matchmaking/query-eval.ts +105 -0
  416. package/src/matchmaking/seeker-walk.ts +127 -0
  417. package/src/matchmaking/seeker.ts +86 -0
  418. package/src/matchmaking/topic-anchor.ts +90 -0
  419. package/src/matchmaking/voting-quorum.ts +394 -0
  420. package/src/matchmaking/wire.ts +680 -0
  421. package/src/network/i-repo.ts +19 -0
  422. package/src/network/repo-protocol.ts +3 -2
  423. package/src/network/struct.ts +24 -1
  424. package/src/reactivity/backfill.ts +220 -0
  425. package/src/reactivity/backpressure.ts +191 -0
  426. package/src/reactivity/checkpoint.ts +308 -0
  427. package/src/reactivity/config.ts +172 -0
  428. package/src/reactivity/dedupe.ts +132 -0
  429. package/src/reactivity/forwarder.ts +87 -0
  430. package/src/reactivity/index.ts +34 -0
  431. package/src/reactivity/notification.ts +123 -0
  432. package/src/reactivity/policy.ts +79 -0
  433. package/src/reactivity/push-state.ts +343 -0
  434. package/src/reactivity/recover.ts +153 -0
  435. package/src/reactivity/replay-buffer.ts +141 -0
  436. package/src/reactivity/resume.ts +549 -0
  437. package/src/reactivity/rotation.ts +415 -0
  438. package/src/reactivity/subscriber.ts +132 -0
  439. package/src/reactivity/subscription.ts +66 -0
  440. package/src/reactivity/topic-anchor.ts +71 -0
  441. package/src/reactivity/verify.ts +73 -0
  442. package/src/reactivity/wire-validate.ts +87 -0
  443. package/src/reactivity/wire.ts +224 -0
  444. package/src/transaction/coordinator.ts +53 -27
  445. package/src/transactor/change-notifier.ts +80 -0
  446. package/src/transactor/index.ts +1 -0
  447. package/src/transactor/network-transactor.ts +162 -19
@@ -0,0 +1,308 @@
1
+ /**
2
+ * Reactivity — parent checkpoint summaries (`docs/reactivity.md` §Parent checkpoint summaries).
3
+ *
4
+ * A `W`-revision replay buffer is too shallow for a phone asleep overnight. To extend recoverable range
5
+ * without ballooning replay memory, every parent forwarder cohort (and the tail cohort) maintains a
6
+ * rolling {@link CheckpointSummary} over the `W_checkpoint` revisions sitting **immediately below** the
7
+ * replay ring's low edge — the two windows *stack*, so a single round trip recovers `W + W_checkpoint`
8
+ * revisions (the authoritative stacked semantics, `docs/reactivity.md` §Replay window). As revisions
9
+ * retire from the ring, the forwarder feeds them to {@link RollingCheckpoint.retire}; the checkpoint
10
+ * rolls its `toRevision` forward and trims its low edge to span `W_checkpoint`.
11
+ *
12
+ * The checkpoint is a **hint summary, not a chain replacement**. Two design questions the ticket asks to
13
+ * resolve, decided here:
14
+ *
15
+ * - **`mergedDigest` semantics (resolved → system-level deterministic fold, per-collection override).**
16
+ * `NotificationV1.digest` carries the commit-vote signed payload `utf8(commitHash + ":approve")` —
17
+ * the exact bytes the commit threshold signature was computed over (see
18
+ * `packages/db-core/src/reactivity/notification.ts`). It is per-revision deterministic and identical
19
+ * across cohort members, so the default `mergedDigest` — a deterministic running fold over the
20
+ * per-revision digests in revision order ({@link defaultDigestFold}) — converges under gossip and the
21
+ * application can compare it against its own expectation. A collection MAY override the fold
22
+ * ({@link RollingCheckpointInit.fold}, e.g. a KV collection folding changed-key sets). The merged
23
+ * digest is **not** cryptographically verified — it is a hint; the cryptographic anchor is the
24
+ * bracketing endpoints (below).
25
+ *
26
+ * - **`mergedDelta` vs `delta_max` (resolved → omit when oversize, never split).** The per-revision
27
+ * deltas are coalesced ({@link RollingCheckpointInit.coalesceDeltas}, default concatenation) only when
28
+ * the coalesced result fits within `delta_max`; otherwise `mergedDelta` is omitted entirely and the
29
+ * subscriber relies on `mergedDigest` + the resume's `recentEntries`, or falls back to a chain read. No
30
+ * multi-frame splitting — a checkpoint is a bounded hint.
31
+ *
32
+ * The **bracketing endpoints** are carried as the two full endpoint {@link NotificationV1}s
33
+ * ({@link CheckpointSummary.bracketingEntries}). A bare signature is not independently verifiable — to
34
+ * verify an endpoint is a real committed revision a subscriber needs the signed payload (the commit
35
+ * digest) and the signers, which the full notification carries. {@link verifyCheckpointEndpoints} runs
36
+ * the standard {@link NotificationVerifier} over both endpoints (proving they are real committed
37
+ * revisions) and checks their revisions equal `fromRevision`/`toRevision`; a forged endpoint is rejected.
38
+ */
39
+
40
+ import { createRingHash } from "../cohort-topic/ring-hash.js";
41
+ import { bytesToB64url, b64urlToBytes } from "../cohort-topic/wire/codec.js";
42
+ import type { IRingHash } from "../cohort-topic/ports.js";
43
+ import type { VerifyResult } from "../cohort-topic/membership/verifier.js";
44
+ import { W_CHECKPOINT_DEFAULT } from "./config.js";
45
+ import type { RevisionEntry } from "./replay-buffer.js";
46
+ import type { NotificationVerifier } from "./verify.js";
47
+ import { asObject, b64urlField, failWire, reqIntInRange, reqString } from "./wire-validate.js";
48
+ import { validateNotificationV1, type NotificationV1 } from "./wire.js";
49
+
50
+ /**
51
+ * A parent checkpoint summary over `[fromRevision, toRevision]` (`docs/reactivity.md`
52
+ * §Parent checkpoint summaries). All byte fields base64url; `bracketingEntries` is exactly the two
53
+ * endpoint notifications, the verifiable anchor.
54
+ */
55
+ export interface CheckpointSummary {
56
+ /** Collection id, base64url. */
57
+ readonly collectionId: string;
58
+ /** Inclusive low edge of the summarized range. */
59
+ readonly fromRevision: number;
60
+ /** Inclusive high edge of the summarized range (`toRevision - fromRevision + 1 ≈ W_checkpoint`). */
61
+ readonly toRevision: number;
62
+ /** Deterministic fold of the per-revision commit digests across the range, base64url (a hint). */
63
+ readonly mergedDigest: string;
64
+ /** Optional coalesced delta, base64url; omitted when the coalesced size exceeds `delta_max`. */
65
+ readonly mergedDelta?: string;
66
+ /** The two endpoint notifications (at `fromRevision` and `toRevision`) — the verifiable proof. */
67
+ readonly bracketingEntries: readonly [NotificationV1, NotificationV1];
68
+ }
69
+
70
+ /** A fold of per-revision commit digests into one summary digest (`docs/reactivity.md` `mergedDigest`). */
71
+ export type DigestFold = (perRevisionDigests: readonly Uint8Array[]) => Uint8Array;
72
+
73
+ /** Coalesce per-revision deltas into one bounded delta (`docs/reactivity.md` `mergedDelta`). */
74
+ export type DeltaCoalesce = (perRevisionDeltas: readonly Uint8Array[]) => Uint8Array;
75
+
76
+ /**
77
+ * The default system-level `mergedDigest` fold: a deterministic running hash
78
+ * `acc₀ = H(∅); accᵢ = H(accᵢ₋₁ ‖ digestᵢ)` over the per-revision commit digests in revision order.
79
+ * Order-dependent and reproducible, so every cohort member folds to identical bytes (gossip converges).
80
+ */
81
+ export function defaultDigestFold(hash: IRingHash = createRingHash()): DigestFold {
82
+ return (digests: readonly Uint8Array[]): Uint8Array => {
83
+ let acc = hash.H(new Uint8Array(0));
84
+ for (const digest of digests) {
85
+ const input = new Uint8Array(acc.length + digest.length);
86
+ input.set(acc, 0);
87
+ input.set(digest, acc.length);
88
+ acc = hash.H(input);
89
+ }
90
+ return acc;
91
+ };
92
+ }
93
+
94
+ /** The default delta coalescer: ordered concatenation of the per-revision delta bytes. */
95
+ export function defaultDeltaCoalesce(deltas: readonly Uint8Array[]): Uint8Array {
96
+ const total = deltas.reduce((n, d) => n + d.length, 0);
97
+ const out = new Uint8Array(total);
98
+ let offset = 0;
99
+ for (const d of deltas) {
100
+ out.set(d, offset);
101
+ offset += d.length;
102
+ }
103
+ return out;
104
+ }
105
+
106
+ /** The fold/coalesce knobs shared by the rolling checkpoint and the rotation handoff. */
107
+ export interface CheckpointFoldOptions {
108
+ /** Collection id the summarized entries belong to, base64url. */
109
+ readonly collectionId: string;
110
+ /** `mergedDigest` fold over the per-revision commit digests. */
111
+ readonly fold: DigestFold;
112
+ /** `mergedDelta` coalescer over the per-revision deltas. */
113
+ readonly coalesceDeltas: DeltaCoalesce;
114
+ /** `delta_max`: omit `mergedDelta` when the coalesced size exceeds this. `0` ⇒ never emit a delta. */
115
+ readonly deltaMaxBytes: number;
116
+ }
117
+
118
+ /**
119
+ * Coalesce the per-revision deltas of `ordered`, returning the base64url result only when it fits within
120
+ * `deltaMaxBytes`. Omitted (`undefined`) when no entry carries a delta, when `deltaMaxBytes <= 0`, or when
121
+ * the coalesced size would exceed `deltaMaxBytes` (the resolved omit-when-oversize policy — never split).
122
+ */
123
+ export function coalesceMergedDelta(ordered: readonly RevisionEntry[], coalesceDeltas: DeltaCoalesce, deltaMaxBytes: number): string | undefined {
124
+ if (deltaMaxBytes <= 0) {
125
+ return undefined;
126
+ }
127
+ const deltas: Uint8Array[] = [];
128
+ for (const e of ordered) {
129
+ if (e.payload.delta !== undefined) {
130
+ deltas.push(b64urlToBytes(e.payload.delta));
131
+ }
132
+ }
133
+ if (deltas.length === 0) {
134
+ return undefined;
135
+ }
136
+ const coalesced = coalesceDeltas(deltas);
137
+ return coalesced.length > deltaMaxBytes ? undefined : bytesToB64url(coalesced);
138
+ }
139
+
140
+ /**
141
+ * Build a {@link CheckpointSummary} over `orderedEntries` (ascending by revision) — the shared fold the
142
+ * rolling checkpoint and the rotation buffer-to-checkpoint handoff both use. Returns `undefined` for an
143
+ * empty range. The two endpoints are carried as the full notifications (the verifiable anchor); the merged
144
+ * digest is the deterministic fold over the per-revision commit digests; the coalesced delta is included
145
+ * only when it fits within `deltaMaxBytes`.
146
+ */
147
+ export function buildCheckpointSummary(orderedEntries: readonly RevisionEntry[], opts: CheckpointFoldOptions): CheckpointSummary | undefined {
148
+ if (orderedEntries.length === 0) {
149
+ return undefined;
150
+ }
151
+ const digests = orderedEntries.map((e) => b64urlToBytes(e.payload.digest));
152
+ const mergedDigest = bytesToB64url(opts.fold(digests));
153
+ const first = orderedEntries[0]!.payload;
154
+ const last = orderedEntries[orderedEntries.length - 1]!.payload;
155
+ const summary: CheckpointSummary = {
156
+ collectionId: opts.collectionId,
157
+ fromRevision: first.revision,
158
+ toRevision: last.revision,
159
+ mergedDigest,
160
+ bracketingEntries: [first, last],
161
+ };
162
+ const mergedDelta = coalesceMergedDelta(orderedEntries, opts.coalesceDeltas, opts.deltaMaxBytes);
163
+ return mergedDelta !== undefined ? { ...summary, mergedDelta } : summary;
164
+ }
165
+
166
+ /** Construction inputs for a {@link RollingCheckpoint}. */
167
+ export interface RollingCheckpointInit {
168
+ /** Collection id, base64url (must match the entries retired into it). */
169
+ readonly collectionId: string;
170
+ /** Checkpoint span `W_checkpoint` (default {@link W_CHECKPOINT_DEFAULT}). */
171
+ readonly span?: number;
172
+ /** Ring hash for the default digest fold. Default db-core SHA-256. */
173
+ readonly hash?: IRingHash;
174
+ /** `mergedDigest` fold (default {@link defaultDigestFold} over the injected hash). */
175
+ readonly fold?: DigestFold;
176
+ /** `mergedDelta` coalescer (default {@link defaultDeltaCoalesce}). */
177
+ readonly coalesceDeltas?: DeltaCoalesce;
178
+ /** `delta_max`: omit `mergedDelta` when the coalesced size exceeds this. `0` ⇒ never emit a delta. */
179
+ readonly deltaMaxBytes?: number;
180
+ }
181
+
182
+ /**
183
+ * The rolling `W_checkpoint`-span parent checkpoint. Retains up to `span` retired {@link RevisionEntry}s
184
+ * (the documented per-cohort checkpoint memory cost) so it can fold a real `mergedDigest`, coalesce a
185
+ * `mergedDelta`, and carry the two endpoint notifications. It always covers the `span` revisions just
186
+ * below the replay ring's low edge.
187
+ */
188
+ export class RollingCheckpoint {
189
+ readonly collectionId: string;
190
+ readonly span: number;
191
+ private readonly hash: IRingHash;
192
+ private readonly fold: DigestFold;
193
+ private readonly coalesceDeltas: DeltaCoalesce;
194
+ private readonly deltaMaxBytes: number;
195
+ /** revision → retired entry; trimmed to the highest `span` revisions. */
196
+ private readonly byRevision = new Map<number, RevisionEntry>();
197
+
198
+ constructor(init: RollingCheckpointInit) {
199
+ const span = init.span ?? W_CHECKPOINT_DEFAULT;
200
+ if (!Number.isInteger(span) || span < 1) {
201
+ throw new RangeError(`reactivity checkpoint: span must be an integer >= 1, got ${span}`);
202
+ }
203
+ this.collectionId = init.collectionId;
204
+ this.span = span;
205
+ this.hash = init.hash ?? createRingHash();
206
+ this.fold = init.fold ?? defaultDigestFold(this.hash);
207
+ this.coalesceDeltas = init.coalesceDeltas ?? defaultDeltaCoalesce;
208
+ this.deltaMaxBytes = init.deltaMaxBytes ?? 0;
209
+ }
210
+
211
+ /** Number of retired revisions currently summarized. */
212
+ get size(): number {
213
+ return this.byRevision.size;
214
+ }
215
+
216
+ /** Lowest summarized revision, or `undefined` when empty. */
217
+ get fromRevision(): number | undefined {
218
+ return this.size === 0 ? undefined : Math.min(...this.byRevision.keys());
219
+ }
220
+
221
+ /** Highest summarized revision, or `undefined` when empty. */
222
+ get toRevision(): number | undefined {
223
+ return this.size === 0 ? undefined : Math.max(...this.byRevision.keys());
224
+ }
225
+
226
+ /** True iff `revision` is within the checkpoint's covered range. */
227
+ covers(revision: number): boolean {
228
+ const from = this.fromRevision;
229
+ const to = this.toRevision;
230
+ return from !== undefined && to !== undefined && revision >= from && revision <= to;
231
+ }
232
+
233
+ /**
234
+ * Fold one revision retired from the replay ring into the checkpoint. Entries arrive as the ring
235
+ * evicts its low edge; the checkpoint trims to its highest `span` revisions so it tracks the window
236
+ * immediately below the ring. A retransmit at an already-summarized revision replaces in place.
237
+ */
238
+ retire(entry: RevisionEntry): void {
239
+ if (entry.payload.collectionId !== this.collectionId) {
240
+ return; // an entry for a different collection is not ours to summarize
241
+ }
242
+ this.byRevision.set(entry.revision, entry);
243
+ while (this.byRevision.size > this.span) {
244
+ this.byRevision.delete(Math.min(...this.byRevision.keys()));
245
+ }
246
+ }
247
+
248
+ /** The retired entries, ascending by revision. */
249
+ private orderedEntries(): RevisionEntry[] {
250
+ return [...this.byRevision.values()].sort((a, b) => a.revision - b.revision);
251
+ }
252
+
253
+ /** The fold/coalesce knobs this checkpoint applies — reused by the rotation handoff for an identical fold. */
254
+ get foldOptions(): CheckpointFoldOptions {
255
+ return { collectionId: this.collectionId, fold: this.fold, coalesceDeltas: this.coalesceDeltas, deltaMaxBytes: this.deltaMaxBytes };
256
+ }
257
+
258
+ /** Build the {@link CheckpointSummary} over the currently-summarized range, or `undefined` if empty. */
259
+ summary(): CheckpointSummary | undefined {
260
+ return buildCheckpointSummary(this.orderedEntries(), this.foldOptions);
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Verify a checkpoint's bracketing endpoints are real committed revisions: run the standard
266
+ * {@link NotificationVerifier} over both endpoint notifications and confirm their revisions equal
267
+ * `fromRevision`/`toRevision` and their collection matches. Returns `"verified"` only if **both**
268
+ * endpoints verify and align; a forged or tampered endpoint yields `"untrusted"`.
269
+ */
270
+ export async function verifyCheckpointEndpoints(summary: CheckpointSummary, verifier: NotificationVerifier): Promise<VerifyResult> {
271
+ const [from, to] = summary.bracketingEntries;
272
+ if (
273
+ from.collectionId !== summary.collectionId ||
274
+ to.collectionId !== summary.collectionId ||
275
+ from.revision !== summary.fromRevision ||
276
+ to.revision !== summary.toRevision
277
+ ) {
278
+ return "untrusted";
279
+ }
280
+ const [fromVerdict, toVerdict] = await Promise.all([verifier.verify(from), verifier.verify(to)]);
281
+ return fromVerdict === "verified" && toVerdict === "verified" ? "verified" : "untrusted";
282
+ }
283
+
284
+ /**
285
+ * Narrow an already-parsed value to {@link CheckpointSummary}, throwing on any defect. Used by the resume
286
+ * codec to validate a checkpoint embedded in a `checkpoint_window` reply. The two `bracketingEntries` are
287
+ * validated as full {@link NotificationV1}s (the verifiable anchor); `mergedDelta` is optional.
288
+ */
289
+ export function validateCheckpointSummary(value: unknown, what = "CheckpointSummary"): CheckpointSummary {
290
+ const obj = asObject(value, what);
291
+ const fromRevision = reqIntInRange(obj, "fromRevision", what, 0);
292
+ const toRevision = reqIntInRange(obj, "toRevision", what, fromRevision);
293
+ const bracketing = obj["bracketingEntries"];
294
+ if (!Array.isArray(bracketing) || bracketing.length !== 2) {
295
+ failWire(`${what}: field "bracketingEntries" must be a length-2 array`);
296
+ }
297
+ const summary: CheckpointSummary = {
298
+ collectionId: b64urlField(reqString(obj, "collectionId", what), "collectionId", what),
299
+ fromRevision,
300
+ toRevision,
301
+ mergedDigest: b64urlField(reqString(obj, "mergedDigest", what), "mergedDigest", what),
302
+ bracketingEntries: [validateNotificationV1(bracketing[0]), validateNotificationV1(bracketing[1])],
303
+ };
304
+ if (obj["mergedDelta"] !== undefined) {
305
+ return { ...summary, mergedDelta: b64urlField(reqString(obj, "mergedDelta", what), "mergedDelta", what) };
306
+ }
307
+ return summary;
308
+ }
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Reactivity — configuration defaults (single source for the hot path).
3
+ *
4
+ * Transcribed from `docs/reactivity.md` §Configuration. Every tunable the reactivity hot path reads
5
+ * is sourced from {@link DEFAULT_REACTIVITY_CONFIG} — never hard-coded at a call site — so the
6
+ * simulator fold-back ([fold-simulator-findings-into-design-docs]) can retune `W` / `dedupe_window`
7
+ * without touching origination, forwarding, the replay buffer, or delivery.
8
+ *
9
+ * **Simulator-validated-pending.** `W` (replay buffer depth), `dedupe_window`, `T_drain`, `queue_max`,
10
+ * and `block_fill_size` are *provisional* pending the design simulator ([simulator-reactivity-replay],
11
+ * folded back by [fold-simulator-findings-into-design-docs]). The simulator's REVISED guidance is that `W`
12
+ * SHOULD become adaptive per measured commit-rate on hot collections (`W ≈ ⌈min_coverage × cps⌉`); the
13
+ * static `W = 256` is kept as the Edge/low-rate default. {@link resolveW} exposes that hook; the
14
+ * simulator's tail-rotation scenario also confirms the re-registration burst stays inside
15
+ * `cap_promote_fast` within `T_drain`, and flags whether `queue_max` should scale with cohort size/tier
16
+ * ({@link resolveQueueMax} is the parallel hook for that fold-back). Sourcing every tunable from this
17
+ * single table is what lets the fold-back revise the values without touching the protocol code.
18
+ *
19
+ * Ownership: `W` / `dedupe_window` ← [reactivity-origination-replay-delivery]; `W_checkpoint` ←
20
+ * [reactivity-backfill-resume-checkpoints]; `queue_max` / `delta_max` / `T_drain` / `warm_threshold` /
21
+ * `block_fill_size` ← [reactivity-rotation-backpressure-policy] (this ticket). `T_rejoin_jitter`, TTL, and
22
+ * ping are inherited from the cohort-topic defaults.
23
+ */
24
+
25
+ import type { NodeProfile } from "../cohort-topic/tiers.js";
26
+ import { DEFAULT_T_REJOIN_JITTER_MS } from "../cohort-topic/antiflood/jitter.js";
27
+
28
+ /** Replay buffer depth (revisions per cohort, per collection). Simulator-validated-pending. */
29
+ export const W_DEFAULT = 256;
30
+ /** Sliding dedupe-window size (revisions). Simulator-validated-pending. */
31
+ export const DEDUPE_WINDOW_DEFAULT = 64;
32
+ /** Parent-checkpoint span (revisions). Owned by the backfill/resume ticket; default carried here. */
33
+ export const W_CHECKPOINT_DEFAULT = 4096;
34
+ /** Per-subscriber bounded queue depth at a forwarder. Simulator-validated-pending (may scale with cohort/tier). */
35
+ export const QUEUE_MAX_DEFAULT = 32;
36
+ /** Max delta payload size on a Core node (bytes). */
37
+ export const DELTA_MAX_CORE_BYTES = 4096;
38
+ /** Max delta payload size on an Edge node (bytes) — Edge declines deltas (`0` ⇒ omit `delta`). */
39
+ export const DELTA_MAX_EDGE_BYTES = 0;
40
+ /** Subscriber registration TTL on a Core node (ms), inherited from cohort-topic. */
41
+ export const SUBSCRIBER_TTL_CORE_MS = 90_000;
42
+ /** Subscriber registration TTL on an Edge node (ms), inherited from cohort-topic. */
43
+ export const SUBSCRIBER_TTL_EDGE_MS = 60_000;
44
+ /** Transactions per block — drives tail rotation. Simulator-validated-pending. */
45
+ export const BLOCK_FILL_SIZE_DEFAULT = 64;
46
+ /** Old-tail drain time after rotation (ms). Simulator-validated-pending. */
47
+ export const T_DRAIN_MS = 60_000;
48
+ /** Transactions remaining in tail before anticipatory warm-up. Owned by the rotation ticket. */
49
+ export const WARM_THRESHOLD_DEFAULT = 8;
50
+ /** Subscriber re-registration jitter span after a rotation hint (ms). Inherited from cohort-topic `T_rejoin_jitter`. */
51
+ export const T_REJOIN_JITTER_MS = DEFAULT_T_REJOIN_JITTER_MS;
52
+
53
+ /** The full reactivity config, with the documented defaults. */
54
+ export interface ReactivityConfig {
55
+ /** Replay buffer depth `W`. Simulator-validated-pending. */
56
+ readonly w: number;
57
+ /** Sliding dedupe-window size. Simulator-validated-pending. */
58
+ readonly dedupeWindow: number;
59
+ /** Parent-checkpoint span (reserved; backfill/resume ticket). */
60
+ readonly wCheckpoint: number;
61
+ /** Per-subscriber bounded queue depth (reserved; backpressure ticket). */
62
+ readonly queueMax: number;
63
+ /** Max delta payload size on a Core node (bytes). */
64
+ readonly deltaMaxCoreBytes: number;
65
+ /** Max delta payload size on an Edge node (bytes). */
66
+ readonly deltaMaxEdgeBytes: number;
67
+ /** Subscriber TTL on a Core node (ms). */
68
+ readonly subscriberTtlCoreMs: number;
69
+ /** Subscriber TTL on an Edge node (ms). */
70
+ readonly subscriberTtlEdgeMs: number;
71
+ /** Transactions per block — drives tail rotation. Simulator-validated-pending. */
72
+ readonly blockFillSize: number;
73
+ /** Old-tail drain time after rotation (ms). Simulator-validated-pending. */
74
+ readonly tDrainMs: number;
75
+ /** Transactions remaining before anticipatory warm-up. */
76
+ readonly warmThreshold: number;
77
+ /** Subscriber re-registration jitter span after a rotation (ms); inherited from cohort-topic. */
78
+ readonly tRejoinJitterMs: number;
79
+ }
80
+
81
+ /** The default reactivity config (`docs/reactivity.md` §Configuration). */
82
+ export const DEFAULT_REACTIVITY_CONFIG: ReactivityConfig = {
83
+ w: W_DEFAULT,
84
+ dedupeWindow: DEDUPE_WINDOW_DEFAULT,
85
+ wCheckpoint: W_CHECKPOINT_DEFAULT,
86
+ queueMax: QUEUE_MAX_DEFAULT,
87
+ deltaMaxCoreBytes: DELTA_MAX_CORE_BYTES,
88
+ deltaMaxEdgeBytes: DELTA_MAX_EDGE_BYTES,
89
+ subscriberTtlCoreMs: SUBSCRIBER_TTL_CORE_MS,
90
+ subscriberTtlEdgeMs: SUBSCRIBER_TTL_EDGE_MS,
91
+ blockFillSize: BLOCK_FILL_SIZE_DEFAULT,
92
+ tDrainMs: T_DRAIN_MS,
93
+ warmThreshold: WARM_THRESHOLD_DEFAULT,
94
+ tRejoinJitterMs: T_REJOIN_JITTER_MS,
95
+ };
96
+
97
+ /** `delta_max` for a node profile: Core admits deltas up to `delta_max`, Edge declines them (`0`). */
98
+ export function deltaMaxForProfile(profile: NodeProfile, config: ReactivityConfig = DEFAULT_REACTIVITY_CONFIG): number {
99
+ return profile.kind === "edge" ? config.deltaMaxEdgeBytes : config.deltaMaxCoreBytes;
100
+ }
101
+
102
+ /** Subscriber TTL for a node profile (`docs/reactivity.md` §Subscription): Core 90 s / Edge 60 s. */
103
+ export function subscriberTtlForProfile(profile: NodeProfile, config: ReactivityConfig = DEFAULT_REACTIVITY_CONFIG): number {
104
+ return profile.kind === "edge" ? config.subscriberTtlEdgeMs : config.subscriberTtlCoreMs;
105
+ }
106
+
107
+ /**
108
+ * Resolve the replay-buffer depth `W` for a collection.
109
+ *
110
+ * Static default (no `cps`): returns the configured `config.w` unchanged — the simulator-confirmed
111
+ * Edge/low-rate default. Adaptive (a measured `cps` and `minCoverageSeconds`): returns
112
+ * `⌈minCoverageSeconds × cps⌉` clamped to `[config.w, maxW]`, the simulator's REVISED guidance for hot
113
+ * collections. This is the single hook the backfill/resume ticket extends; the hot path here only ever
114
+ * calls the static form, so behavior is unchanged until a `cps` is wired through.
115
+ */
116
+ export function resolveW(opts: { cps?: number; minCoverageSeconds?: number; maxW?: number; config?: ReactivityConfig } = {}): number {
117
+ const config = opts.config ?? DEFAULT_REACTIVITY_CONFIG;
118
+ if (opts.cps === undefined || opts.minCoverageSeconds === undefined) {
119
+ return config.w;
120
+ }
121
+ if (!Number.isFinite(opts.cps) || opts.cps <= 0 || !Number.isFinite(opts.minCoverageSeconds) || opts.minCoverageSeconds <= 0) {
122
+ return config.w;
123
+ }
124
+ const adaptive = Math.ceil(opts.minCoverageSeconds * opts.cps);
125
+ const maxW = opts.maxW ?? Number.POSITIVE_INFINITY;
126
+ return Math.min(Math.max(config.w, adaptive), maxW);
127
+ }
128
+
129
+ /** Default `W_checkpoint`-to-`W` ratio (`docs/reactivity.md` §Parent checkpoint summaries: 16×). */
130
+ export const W_CHECKPOINT_RATIO = 16;
131
+
132
+ /**
133
+ * Resolve the parent-checkpoint span `W_checkpoint` for a collection.
134
+ *
135
+ * Static default (no `cps`): the configured `config.wCheckpoint` (4096). Adaptive: `W_checkpoint`
136
+ * "scales the same way and may stay a fixed 16× multiple of the resolved `W`" (`docs/reactivity.md`
137
+ * §Configuration), so when a `cps` is supplied it tracks `W_CHECKPOINT_RATIO × resolveW(opts)`. This is
138
+ * the single hook the simulator fold-back ([fold-simulator-findings-into-design-docs]) retunes; the
139
+ * resume classifier reads it so a hot collection's stacked recovery range scales with the replay depth.
140
+ */
141
+ export function resolveWCheckpoint(opts: { cps?: number; minCoverageSeconds?: number; maxW?: number; ratio?: number; config?: ReactivityConfig } = {}): number {
142
+ const config = opts.config ?? DEFAULT_REACTIVITY_CONFIG;
143
+ if (opts.cps === undefined || opts.minCoverageSeconds === undefined) {
144
+ return config.wCheckpoint;
145
+ }
146
+ const ratio = opts.ratio ?? W_CHECKPOINT_RATIO;
147
+ return resolveW(opts) * ratio;
148
+ }
149
+
150
+ /**
151
+ * Resolve the per-subscriber bounded-queue depth `queue_max` for a cohort.
152
+ *
153
+ * Static default (no scaling input): the configured `config.queueMax` (32). The simulator flags whether
154
+ * `queue_max` should scale with cohort size / tier on hot collections; this is the single hook the
155
+ * fold-back ([fold-simulator-findings-into-design-docs]) retunes. When a `cohortSubscribers` count is
156
+ * supplied, the depth scales as `⌈queue_max × subscribers / scaleBaseline⌉` clamped to `[queueMax, maxQueue]`
157
+ * — never below the static default, optionally capped at a per-cohort memory budget. With no scaling input
158
+ * the hot path is unchanged (constant `queue_max`).
159
+ */
160
+ export function resolveQueueMax(opts: { cohortSubscribers?: number; scaleBaseline?: number; maxQueue?: number; config?: ReactivityConfig } = {}): number {
161
+ const config = opts.config ?? DEFAULT_REACTIVITY_CONFIG;
162
+ if (opts.cohortSubscribers === undefined) {
163
+ return config.queueMax;
164
+ }
165
+ const baseline = opts.scaleBaseline ?? 1;
166
+ if (!Number.isFinite(opts.cohortSubscribers) || opts.cohortSubscribers <= 0 || !(baseline > 0)) {
167
+ return config.queueMax;
168
+ }
169
+ const scaled = Math.ceil((config.queueMax * opts.cohortSubscribers) / baseline);
170
+ const maxQueue = opts.maxQueue ?? Number.POSITIVE_INFINITY;
171
+ return Math.min(Math.max(config.queueMax, scaled), maxQueue);
172
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Reactivity — per-revision dedupe (sliding-window set), `docs/reactivity.md` §Per-revision dedupe.
3
+ *
4
+ * A scalar `lastRevision` is insufficient under partition healing: the same revision may legitimately
5
+ * arrive from multiple parents during a merge, and dropping all but the first on `revision > lastRevision`
6
+ * would discard honest retransmits exactly when a subscriber needs them. Instead each forwarder keeps a
7
+ * sliding set of `(revision, sigDigest)` pairs for the last `dedupe_window` revisions (default 64).
8
+ *
9
+ * A notification is forwarded if:
10
+ * - it is for the *highest revision* seen in the window (normal case), OR
11
+ * - it is for an earlier revision, its `(revision, sigDigest)` is not already in the set, and it passes
12
+ * verification (recovery: a retransmit closing a gap).
13
+ *
14
+ * Both reduce to: **forward iff the `(revision, sigDigest)` key is not already present** (verification is
15
+ * the forwarder's prior step, applied to every inbound). Keys already in the set are dropped silently.
16
+ * The set is gossiped within the cohort ({@link DedupeWindow.serialize} / {@link DedupeWindow.merge}) so
17
+ * all members agree on what has been seen.
18
+ */
19
+
20
+ import { DEDUPE_WINDOW_DEFAULT } from "./config.js";
21
+
22
+ /** The dedupe decision for one inbound notification. */
23
+ export type DedupeOutcome = "forward" | "duplicate";
24
+
25
+ /** Serializable dedupe state for intra-cohort gossip convergence. */
26
+ export interface DedupeStateV1 {
27
+ /** Highest revision observed (anchors the sliding window's high edge). */
28
+ readonly highestRevision: number;
29
+ /** Seen `(revision, sigDigest)` keys with their revision, for window-bounded merge. */
30
+ readonly entries: ReadonlyArray<{ readonly key: string; readonly revision: number }>;
31
+ }
32
+
33
+ /** A sliding-window dedupe set over `(revision, sigDigest)` pairs. */
34
+ export interface DedupeWindow {
35
+ /** Highest revision observed so far (`-1` before any observation). */
36
+ readonly highestRevision: number;
37
+ /** Number of retained keys. */
38
+ readonly size: number;
39
+ /** True iff `(revision, sigDigest)` is already in the set. */
40
+ has(revision: number, sigDigest: string): boolean;
41
+ /**
42
+ * Record `(revision, sigDigest)` and report whether it should be forwarded. Returns `"duplicate"`
43
+ * (no state change) if already seen, else records it, advances the window, and returns `"forward"`.
44
+ */
45
+ observe(revision: number, sigDigest: string): DedupeOutcome;
46
+ /** Snapshot for gossip. */
47
+ serialize(): DedupeStateV1;
48
+ /** Union another member's gossiped state into this one (idempotent, commutative within the window). */
49
+ merge(state: DedupeStateV1): void;
50
+ }
51
+
52
+ class SlidingDedupeWindow implements DedupeWindow {
53
+ private readonly windowSize: number;
54
+ /** key → revision, for window-bounded eviction. */
55
+ private readonly seen = new Map<string, number>();
56
+ private highest = -1;
57
+
58
+ constructor(windowSize: number) {
59
+ if (!Number.isInteger(windowSize) || windowSize < 1) {
60
+ throw new RangeError(`reactivity dedupe: windowSize must be an integer >= 1, got ${windowSize}`);
61
+ }
62
+ this.windowSize = windowSize;
63
+ }
64
+
65
+ get highestRevision(): number {
66
+ return this.highest;
67
+ }
68
+
69
+ get size(): number {
70
+ return this.seen.size;
71
+ }
72
+
73
+ has(revision: number, sigDigest: string): boolean {
74
+ return this.seen.has(keyOf(revision, sigDigest));
75
+ }
76
+
77
+ observe(revision: number, sigDigest: string): DedupeOutcome {
78
+ const key = keyOf(revision, sigDigest);
79
+ if (this.seen.has(key)) {
80
+ return "duplicate";
81
+ }
82
+ this.insert(key, revision);
83
+ return "forward";
84
+ }
85
+
86
+ serialize(): DedupeStateV1 {
87
+ return {
88
+ highestRevision: this.highest,
89
+ entries: [...this.seen].map(([key, rev]) => ({ key, revision: rev })),
90
+ };
91
+ }
92
+
93
+ merge(state: DedupeStateV1): void {
94
+ if (state.highestRevision > this.highest) {
95
+ this.highest = state.highestRevision;
96
+ }
97
+ for (const { key, revision } of state.entries) {
98
+ if (!this.seen.has(key)) {
99
+ this.seen.set(key, revision);
100
+ }
101
+ }
102
+ this.evictBelowWindow();
103
+ }
104
+
105
+ private insert(key: string, revision: number): void {
106
+ if (revision > this.highest) {
107
+ this.highest = revision;
108
+ }
109
+ this.seen.set(key, revision);
110
+ this.evictBelowWindow();
111
+ }
112
+
113
+ /** Retain only revisions within `[highest - windowSize + 1, highest]`. */
114
+ private evictBelowWindow(): void {
115
+ const low = this.highest - this.windowSize + 1;
116
+ for (const [key, revision] of this.seen) {
117
+ if (revision < low) {
118
+ this.seen.delete(key);
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ /** `${revision}:${sigDigest}` — the dedupe-set key. */
125
+ function keyOf(revision: number, sigDigest: string): string {
126
+ return `${revision}:${sigDigest}`;
127
+ }
128
+
129
+ /** Build a {@link DedupeWindow} with the configured (default {@link DEDUPE_WINDOW_DEFAULT}) span. */
130
+ export function createDedupeWindow(windowSize: number = DEDUPE_WINDOW_DEFAULT): DedupeWindow {
131
+ return new SlidingDedupeWindow(windowSize);
132
+ }