@earendil-works/chord 1.3.0 → 1.5.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 (841) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +129 -10
  3. package/dist/cell.d.ts +7 -7
  4. package/dist/cell.d.ts.map +1 -1
  5. package/dist/cell.js.map +1 -1
  6. package/dist/context/index.d.ts +8 -0
  7. package/dist/context/index.d.ts.map +1 -1
  8. package/dist/context/index.js +15 -0
  9. package/dist/context/index.js.map +1 -1
  10. package/dist/contract.d.ts +51 -52
  11. package/dist/contract.d.ts.map +1 -1
  12. package/dist/contract.js +19 -24
  13. package/dist/contract.js.map +1 -1
  14. package/dist/delta/apply-immutable-trusted.js +3 -4
  15. package/dist/delta/apply-immutable-trusted.js.map +1 -1
  16. package/dist/delta/diff.d.ts.map +1 -1
  17. package/dist/delta/diff.js +5 -3
  18. package/dist/delta/diff.js.map +1 -1
  19. package/dist/delta/index.d.ts +9 -1
  20. package/dist/delta/index.d.ts.map +1 -1
  21. package/dist/delta/index.js +15 -11
  22. package/dist/delta/index.js.map +1 -1
  23. package/dist/delta/pending.d.ts +36 -0
  24. package/dist/delta/pending.d.ts.map +1 -0
  25. package/dist/delta/pending.js +143 -0
  26. package/dist/delta/pending.js.map +1 -0
  27. package/dist/delta/tracker.d.ts +12 -0
  28. package/dist/delta/tracker.d.ts.map +1 -1
  29. package/dist/delta/tracker.js +109 -39
  30. package/dist/delta/tracker.js.map +1 -1
  31. package/dist/host.d.ts.map +1 -1
  32. package/dist/host.js +9 -7
  33. package/dist/host.js.map +1 -1
  34. package/dist/index.d.ts +1 -0
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +1 -0
  37. package/dist/index.js.map +1 -1
  38. package/dist/next/contracts/accepts.d.ts +81 -0
  39. package/dist/next/contracts/accepts.d.ts.map +1 -0
  40. package/dist/next/contracts/accepts.js +123 -0
  41. package/dist/next/contracts/accepts.js.map +1 -0
  42. package/dist/next/contracts/contract.d.ts +121 -0
  43. package/dist/next/contracts/contract.d.ts.map +1 -0
  44. package/dist/next/contracts/contract.js +50 -0
  45. package/dist/next/contracts/contract.js.map +1 -0
  46. package/dist/next/contracts/declare.d.ts +107 -0
  47. package/dist/next/contracts/declare.d.ts.map +1 -0
  48. package/dist/next/contracts/declare.js +136 -0
  49. package/dist/next/contracts/declare.js.map +1 -0
  50. package/dist/next/contracts/evolve.d.ts +92 -0
  51. package/dist/next/contracts/evolve.d.ts.map +1 -0
  52. package/dist/next/contracts/evolve.js +179 -0
  53. package/dist/next/contracts/evolve.js.map +1 -0
  54. package/dist/next/contracts/fingerprint.d.ts +16 -0
  55. package/dist/next/contracts/fingerprint.d.ts.map +1 -0
  56. package/dist/next/contracts/fingerprint.js +50 -0
  57. package/dist/next/contracts/fingerprint.js.map +1 -0
  58. package/dist/next/contracts/history.d.ts +71 -0
  59. package/dist/next/contracts/history.d.ts.map +1 -0
  60. package/dist/next/contracts/history.js +3 -0
  61. package/dist/next/contracts/history.js.map +1 -0
  62. package/dist/next/contracts/host-kind.d.ts +40 -0
  63. package/dist/next/contracts/host-kind.d.ts.map +1 -0
  64. package/dist/next/contracts/host-kind.js +37 -0
  65. package/dist/next/contracts/host-kind.js.map +1 -0
  66. package/dist/next/contracts/index.d.ts +7 -0
  67. package/dist/next/contracts/index.d.ts.map +1 -0
  68. package/dist/next/contracts/index.js +6 -0
  69. package/dist/next/contracts/index.js.map +1 -0
  70. package/dist/next/contracts/internal.d.ts +10 -0
  71. package/dist/next/contracts/internal.d.ts.map +1 -0
  72. package/dist/next/contracts/internal.js +9 -0
  73. package/dist/next/contracts/internal.js.map +1 -0
  74. package/dist/next/contracts/names.d.ts +3 -0
  75. package/dist/next/contracts/names.d.ts.map +1 -0
  76. package/dist/next/contracts/names.js +13 -0
  77. package/dist/next/contracts/names.js.map +1 -0
  78. package/dist/next/contracts/params.d.ts +28 -0
  79. package/dist/next/contracts/params.d.ts.map +1 -0
  80. package/dist/next/contracts/params.js +50 -0
  81. package/dist/next/contracts/params.js.map +1 -0
  82. package/dist/next/contracts/schema.d.ts +102 -0
  83. package/dist/next/contracts/schema.d.ts.map +1 -0
  84. package/dist/next/contracts/schema.js +103 -0
  85. package/dist/next/contracts/schema.js.map +1 -0
  86. package/dist/next/contracts/snapshot.d.ts +16 -0
  87. package/dist/next/contracts/snapshot.d.ts.map +1 -0
  88. package/dist/next/contracts/snapshot.js +167 -0
  89. package/dist/next/contracts/snapshot.js.map +1 -0
  90. package/dist/next/data/args.d.ts +50 -0
  91. package/dist/next/data/args.d.ts.map +1 -0
  92. package/dist/next/data/args.js +83 -0
  93. package/dist/next/data/args.js.map +1 -0
  94. package/dist/next/data/errors.d.ts +73 -0
  95. package/dist/next/data/errors.d.ts.map +1 -0
  96. package/dist/next/data/errors.js +107 -0
  97. package/dist/next/data/errors.js.map +1 -0
  98. package/dist/next/data/failure.d.ts +26 -0
  99. package/dist/next/data/failure.d.ts.map +1 -0
  100. package/dist/next/data/failure.js +72 -0
  101. package/dist/next/data/failure.js.map +1 -0
  102. package/dist/next/data/index.d.ts +4 -0
  103. package/dist/next/data/index.d.ts.map +1 -0
  104. package/dist/next/data/index.js +4 -0
  105. package/dist/next/data/index.js.map +1 -0
  106. package/dist/next/data/internal.d.ts +7 -0
  107. package/dist/next/data/internal.d.ts.map +1 -0
  108. package/dist/next/data/internal.js +8 -0
  109. package/dist/next/data/internal.js.map +1 -0
  110. package/dist/next/data/params.d.ts +20 -0
  111. package/dist/next/data/params.d.ts.map +1 -0
  112. package/dist/next/data/params.js +31 -0
  113. package/dist/next/data/params.js.map +1 -0
  114. package/dist/next/data/principal.d.ts +17 -0
  115. package/dist/next/data/principal.d.ts.map +1 -0
  116. package/dist/next/data/principal.js +41 -0
  117. package/dist/next/data/principal.js.map +1 -0
  118. package/dist/next/data/validator.d.ts +12 -0
  119. package/dist/next/data/validator.d.ts.map +1 -0
  120. package/dist/next/data/validator.js +34 -0
  121. package/dist/next/data/validator.js.map +1 -0
  122. package/dist/next/documents/address-source.d.ts +20 -0
  123. package/dist/next/documents/address-source.d.ts.map +1 -0
  124. package/dist/next/documents/address-source.js +44 -0
  125. package/dist/next/documents/address-source.js.map +1 -0
  126. package/dist/next/documents/definition.d.ts +84 -0
  127. package/dist/next/documents/definition.d.ts.map +1 -0
  128. package/dist/next/documents/definition.js +73 -0
  129. package/dist/next/documents/definition.js.map +1 -0
  130. package/dist/next/documents/documents.d.ts +106 -0
  131. package/dist/next/documents/documents.d.ts.map +1 -0
  132. package/dist/next/documents/documents.js +224 -0
  133. package/dist/next/documents/documents.js.map +1 -0
  134. package/dist/next/documents/fence.d.ts +9 -0
  135. package/dist/next/documents/fence.d.ts.map +1 -0
  136. package/dist/next/documents/fence.js +15 -0
  137. package/dist/next/documents/fence.js.map +1 -0
  138. package/dist/next/documents/handles.d.ts +76 -0
  139. package/dist/next/documents/handles.d.ts.map +1 -0
  140. package/dist/next/documents/handles.js +66 -0
  141. package/dist/next/documents/handles.js.map +1 -0
  142. package/dist/next/documents/index.d.ts +4 -0
  143. package/dist/next/documents/index.d.ts.map +1 -0
  144. package/dist/next/documents/index.js +3 -0
  145. package/dist/next/documents/index.js.map +1 -0
  146. package/dist/next/documents/internal.d.ts +9 -0
  147. package/dist/next/documents/internal.d.ts.map +1 -0
  148. package/dist/next/documents/internal.js +9 -0
  149. package/dist/next/documents/internal.js.map +1 -0
  150. package/dist/next/documents/keyed-slot.d.ts +103 -0
  151. package/dist/next/documents/keyed-slot.d.ts.map +1 -0
  152. package/dist/next/documents/keyed-slot.js +395 -0
  153. package/dist/next/documents/keyed-slot.js.map +1 -0
  154. package/dist/next/documents/line.d.ts +7 -0
  155. package/dist/next/documents/line.d.ts.map +1 -0
  156. package/dist/next/documents/line.js +14 -0
  157. package/dist/next/documents/line.js.map +1 -0
  158. package/dist/next/documents/persistence.d.ts +104 -0
  159. package/dist/next/documents/persistence.d.ts.map +1 -0
  160. package/dist/next/documents/persistence.js +128 -0
  161. package/dist/next/documents/persistence.js.map +1 -0
  162. package/dist/next/documents/residency.d.ts +31 -0
  163. package/dist/next/documents/residency.d.ts.map +1 -0
  164. package/dist/next/documents/residency.js +93 -0
  165. package/dist/next/documents/residency.js.map +1 -0
  166. package/dist/next/documents/slot.d.ts +109 -0
  167. package/dist/next/documents/slot.d.ts.map +1 -0
  168. package/dist/next/documents/slot.js +181 -0
  169. package/dist/next/documents/slot.js.map +1 -0
  170. package/dist/next/documents/transaction.d.ts +133 -0
  171. package/dist/next/documents/transaction.d.ts.map +1 -0
  172. package/dist/next/documents/transaction.js +409 -0
  173. package/dist/next/documents/transaction.js.map +1 -0
  174. package/dist/next/host/activity.d.ts +31 -0
  175. package/dist/next/host/activity.d.ts.map +1 -0
  176. package/dist/next/host/activity.js +40 -0
  177. package/dist/next/host/activity.js.map +1 -0
  178. package/dist/next/host/adapted.d.ts +49 -0
  179. package/dist/next/host/adapted.d.ts.map +1 -0
  180. package/dist/next/host/adapted.js +214 -0
  181. package/dist/next/host/adapted.js.map +1 -0
  182. package/dist/next/host/attempt.d.ts +278 -0
  183. package/dist/next/host/attempt.d.ts.map +1 -0
  184. package/dist/next/host/attempt.js +1072 -0
  185. package/dist/next/host/attempt.js.map +1 -0
  186. package/dist/next/host/backoff.d.ts +29 -0
  187. package/dist/next/host/backoff.d.ts.map +1 -0
  188. package/dist/next/host/backoff.js +69 -0
  189. package/dist/next/host/backoff.js.map +1 -0
  190. package/dist/next/host/ctx.d.ts +47 -0
  191. package/dist/next/host/ctx.d.ts.map +1 -0
  192. package/dist/next/host/ctx.js +108 -0
  193. package/dist/next/host/ctx.js.map +1 -0
  194. package/dist/next/host/deadline.d.ts +12 -0
  195. package/dist/next/host/deadline.d.ts.map +1 -0
  196. package/dist/next/host/deadline.js +40 -0
  197. package/dist/next/host/deadline.js.map +1 -0
  198. package/dist/next/host/dependencies.d.ts +65 -0
  199. package/dist/next/host/dependencies.d.ts.map +1 -0
  200. package/dist/next/host/dependencies.js +115 -0
  201. package/dist/next/host/dependencies.js.map +1 -0
  202. package/dist/next/host/destination.d.ts +48 -0
  203. package/dist/next/host/destination.d.ts.map +1 -0
  204. package/dist/next/host/destination.js +101 -0
  205. package/dist/next/host/destination.js.map +1 -0
  206. package/dist/next/host/facet.d.ts +79 -0
  207. package/dist/next/host/facet.d.ts.map +1 -0
  208. package/dist/next/host/facet.js +55 -0
  209. package/dist/next/host/facet.js.map +1 -0
  210. package/dist/next/host/follow.d.ts +52 -0
  211. package/dist/next/host/follow.d.ts.map +1 -0
  212. package/dist/next/host/follow.js +207 -0
  213. package/dist/next/host/follow.js.map +1 -0
  214. package/dist/next/host/host.d.ts +495 -0
  215. package/dist/next/host/host.d.ts.map +1 -0
  216. package/dist/next/host/host.js +1075 -0
  217. package/dist/next/host/host.js.map +1 -0
  218. package/dist/next/host/index.d.ts +17 -0
  219. package/dist/next/host/index.d.ts.map +1 -0
  220. package/dist/next/host/index.js +6 -0
  221. package/dist/next/host/index.js.map +1 -0
  222. package/dist/next/host/internal.d.ts +10 -0
  223. package/dist/next/host/internal.d.ts.map +1 -0
  224. package/dist/next/host/internal.js +8 -0
  225. package/dist/next/host/internal.js.map +1 -0
  226. package/dist/next/host/members.d.ts +50 -0
  227. package/dist/next/host/members.d.ts.map +1 -0
  228. package/dist/next/host/members.js +107 -0
  229. package/dist/next/host/members.js.map +1 -0
  230. package/dist/next/host/native.d.ts +55 -0
  231. package/dist/next/host/native.d.ts.map +1 -0
  232. package/dist/next/host/native.js +92 -0
  233. package/dist/next/host/native.js.map +1 -0
  234. package/dist/next/host/object.d.ts +290 -0
  235. package/dist/next/host/object.d.ts.map +1 -0
  236. package/dist/next/host/object.js +1127 -0
  237. package/dist/next/host/object.js.map +1 -0
  238. package/dist/next/host/parked.d.ts +23 -0
  239. package/dist/next/host/parked.d.ts.map +1 -0
  240. package/dist/next/host/parked.js +79 -0
  241. package/dist/next/host/parked.js.map +1 -0
  242. package/dist/next/host/presence.d.ts +34 -0
  243. package/dist/next/host/presence.d.ts.map +1 -0
  244. package/dist/next/host/presence.js +117 -0
  245. package/dist/next/host/presence.js.map +1 -0
  246. package/dist/next/host/ref-state.d.ts +53 -0
  247. package/dist/next/host/ref-state.d.ts.map +1 -0
  248. package/dist/next/host/ref-state.js +83 -0
  249. package/dist/next/host/ref-state.js.map +1 -0
  250. package/dist/next/host/reference-keys.d.ts +36 -0
  251. package/dist/next/host/reference-keys.d.ts.map +1 -0
  252. package/dist/next/host/reference-keys.js +168 -0
  253. package/dist/next/host/reference-keys.js.map +1 -0
  254. package/dist/next/host/reference-source.d.ts +65 -0
  255. package/dist/next/host/reference-source.d.ts.map +1 -0
  256. package/dist/next/host/reference-source.js +285 -0
  257. package/dist/next/host/reference-source.js.map +1 -0
  258. package/dist/next/host/reference.d.ts +308 -0
  259. package/dist/next/host/reference.d.ts.map +1 -0
  260. package/dist/next/host/reference.js +775 -0
  261. package/dist/next/host/reference.js.map +1 -0
  262. package/dist/next/host/retry-on.d.ts +28 -0
  263. package/dist/next/host/retry-on.d.ts.map +1 -0
  264. package/dist/next/host/retry-on.js +52 -0
  265. package/dist/next/host/retry-on.js.map +1 -0
  266. package/dist/next/host/revocation.d.ts +16 -0
  267. package/dist/next/host/revocation.d.ts.map +1 -0
  268. package/dist/next/host/revocation.js +27 -0
  269. package/dist/next/host/revocation.js.map +1 -0
  270. package/dist/next/host/root.d.ts +27 -0
  271. package/dist/next/host/root.d.ts.map +1 -0
  272. package/dist/next/host/root.js +68 -0
  273. package/dist/next/host/root.js.map +1 -0
  274. package/dist/next/host/route.d.ts +64 -0
  275. package/dist/next/host/route.d.ts.map +1 -0
  276. package/dist/next/host/route.js +190 -0
  277. package/dist/next/host/route.js.map +1 -0
  278. package/dist/next/host/routines.d.ts +76 -0
  279. package/dist/next/host/routines.d.ts.map +1 -0
  280. package/dist/next/host/routines.js +350 -0
  281. package/dist/next/host/routines.js.map +1 -0
  282. package/dist/next/host/sleep.d.ts +9 -0
  283. package/dist/next/host/sleep.d.ts.map +1 -0
  284. package/dist/next/host/sleep.js +40 -0
  285. package/dist/next/host/sleep.js.map +1 -0
  286. package/dist/next/host/staging.d.ts +94 -0
  287. package/dist/next/host/staging.d.ts.map +1 -0
  288. package/dist/next/host/staging.js +302 -0
  289. package/dist/next/host/staging.js.map +1 -0
  290. package/dist/next/host/unbound.d.ts +30 -0
  291. package/dist/next/host/unbound.d.ts.map +1 -0
  292. package/dist/next/host/unbound.js +67 -0
  293. package/dist/next/host/unbound.js.map +1 -0
  294. package/dist/next/host/uuid.d.ts +3 -0
  295. package/dist/next/host/uuid.d.ts.map +1 -0
  296. package/dist/next/host/uuid.js +38 -0
  297. package/dist/next/host/uuid.js.map +1 -0
  298. package/dist/next/index.d.ts +28 -0
  299. package/dist/next/index.d.ts.map +1 -0
  300. package/dist/next/index.js +18 -0
  301. package/dist/next/index.js.map +1 -0
  302. package/dist/next/jobs/definition.d.ts +96 -0
  303. package/dist/next/jobs/definition.d.ts.map +1 -0
  304. package/dist/next/jobs/definition.js +83 -0
  305. package/dist/next/jobs/definition.js.map +1 -0
  306. package/dist/next/jobs/index.d.ts +5 -0
  307. package/dist/next/jobs/index.d.ts.map +1 -0
  308. package/dist/next/jobs/index.js +3 -0
  309. package/dist/next/jobs/index.js.map +1 -0
  310. package/dist/next/jobs/internal.d.ts +3 -0
  311. package/dist/next/jobs/internal.d.ts.map +1 -0
  312. package/dist/next/jobs/internal.js +4 -0
  313. package/dist/next/jobs/internal.js.map +1 -0
  314. package/dist/next/jobs/job.d.ts +152 -0
  315. package/dist/next/jobs/job.d.ts.map +1 -0
  316. package/dist/next/jobs/job.js +320 -0
  317. package/dist/next/jobs/job.js.map +1 -0
  318. package/dist/next/jobs/persisted.d.ts +38 -0
  319. package/dist/next/jobs/persisted.d.ts.map +1 -0
  320. package/dist/next/jobs/persisted.js +95 -0
  321. package/dist/next/jobs/persisted.js.map +1 -0
  322. package/dist/next/jobs/records.d.ts +231 -0
  323. package/dist/next/jobs/records.d.ts.map +1 -0
  324. package/dist/next/jobs/records.js +869 -0
  325. package/dist/next/jobs/records.js.map +1 -0
  326. package/dist/next/jobs/run-states.d.ts +69 -0
  327. package/dist/next/jobs/run-states.d.ts.map +1 -0
  328. package/dist/next/jobs/run-states.js +228 -0
  329. package/dist/next/jobs/run-states.js.map +1 -0
  330. package/dist/next/jobs/run.d.ts +113 -0
  331. package/dist/next/jobs/run.d.ts.map +1 -0
  332. package/dist/next/jobs/run.js +200 -0
  333. package/dist/next/jobs/run.js.map +1 -0
  334. package/dist/next/jobs/running.d.ts +44 -0
  335. package/dist/next/jobs/running.d.ts.map +1 -0
  336. package/dist/next/jobs/running.js +117 -0
  337. package/dist/next/jobs/running.js.map +1 -0
  338. package/dist/next/jobs/stored.d.ts +63 -0
  339. package/dist/next/jobs/stored.d.ts.map +1 -0
  340. package/dist/next/jobs/stored.js +55 -0
  341. package/dist/next/jobs/stored.js.map +1 -0
  342. package/dist/next/link/binary.d.ts +4 -0
  343. package/dist/next/link/binary.d.ts.map +1 -0
  344. package/dist/next/link/binary.js +534 -0
  345. package/dist/next/link/binary.js.map +1 -0
  346. package/dist/next/link/channel.d.ts +63 -0
  347. package/dist/next/link/channel.d.ts.map +1 -0
  348. package/dist/next/link/channel.js +202 -0
  349. package/dist/next/link/channel.js.map +1 -0
  350. package/dist/next/link/errors.d.ts +7 -0
  351. package/dist/next/link/errors.d.ts.map +1 -0
  352. package/dist/next/link/errors.js +21 -0
  353. package/dist/next/link/errors.js.map +1 -0
  354. package/dist/next/link/index.d.ts +8 -0
  355. package/dist/next/link/index.d.ts.map +1 -0
  356. package/dist/next/link/index.js +8 -0
  357. package/dist/next/link/index.js.map +1 -0
  358. package/dist/next/link/internal.d.ts +9 -0
  359. package/dist/next/link/internal.d.ts.map +1 -0
  360. package/dist/next/link/internal.js +10 -0
  361. package/dist/next/link/internal.js.map +1 -0
  362. package/dist/next/link/ipc.d.ts +22 -0
  363. package/dist/next/link/ipc.d.ts.map +1 -0
  364. package/dist/next/link/ipc.js +64 -0
  365. package/dist/next/link/ipc.js.map +1 -0
  366. package/dist/next/link/link.d.ts +34 -0
  367. package/dist/next/link/link.d.ts.map +1 -0
  368. package/dist/next/link/link.js +87 -0
  369. package/dist/next/link/link.js.map +1 -0
  370. package/dist/next/link/message.d.ts +249 -0
  371. package/dist/next/link/message.d.ts.map +1 -0
  372. package/dist/next/link/message.js +123 -0
  373. package/dist/next/link/message.js.map +1 -0
  374. package/dist/next/link/part.d.ts +80 -0
  375. package/dist/next/link/part.d.ts.map +1 -0
  376. package/dist/next/link/part.js +164 -0
  377. package/dist/next/link/part.js.map +1 -0
  378. package/dist/next/link/text.d.ts +6 -0
  379. package/dist/next/link/text.d.ts.map +1 -0
  380. package/dist/next/link/text.js +335 -0
  381. package/dist/next/link/text.js.map +1 -0
  382. package/dist/next/link/values.d.ts +40 -0
  383. package/dist/next/link/values.d.ts.map +1 -0
  384. package/dist/next/link/values.js +117 -0
  385. package/dist/next/link/values.js.map +1 -0
  386. package/dist/next/link/websocket.d.ts +26 -0
  387. package/dist/next/link/websocket.d.ts.map +1 -0
  388. package/dist/next/link/websocket.js +91 -0
  389. package/dist/next/link/websocket.js.map +1 -0
  390. package/dist/next/registries/contribution.d.ts +50 -0
  391. package/dist/next/registries/contribution.d.ts.map +1 -0
  392. package/dist/next/registries/contribution.js +129 -0
  393. package/dist/next/registries/contribution.js.map +1 -0
  394. package/dist/next/registries/entries.d.ts +18 -0
  395. package/dist/next/registries/entries.d.ts.map +1 -0
  396. package/dist/next/registries/entries.js +42 -0
  397. package/dist/next/registries/entries.js.map +1 -0
  398. package/dist/next/registries/index.d.ts +3 -0
  399. package/dist/next/registries/index.d.ts.map +1 -0
  400. package/dist/next/registries/index.js +5 -0
  401. package/dist/next/registries/index.js.map +1 -0
  402. package/dist/next/registries/internal.d.ts +4 -0
  403. package/dist/next/registries/internal.d.ts.map +1 -0
  404. package/dist/next/registries/internal.js +5 -0
  405. package/dist/next/registries/internal.js.map +1 -0
  406. package/dist/next/registries/record.d.ts +94 -0
  407. package/dist/next/registries/record.d.ts.map +1 -0
  408. package/dist/next/registries/record.js +253 -0
  409. package/dist/next/registries/record.js.map +1 -0
  410. package/dist/next/registries/registry.d.ts +74 -0
  411. package/dist/next/registries/registry.d.ts.map +1 -0
  412. package/dist/next/registries/registry.js +14 -0
  413. package/dist/next/registries/registry.js.map +1 -0
  414. package/dist/next/registries/value.d.ts +48 -0
  415. package/dist/next/registries/value.d.ts.map +1 -0
  416. package/dist/next/registries/value.js +199 -0
  417. package/dist/next/registries/value.js.map +1 -0
  418. package/dist/next/remote/calls.d.ts +25 -0
  419. package/dist/next/remote/calls.d.ts.map +1 -0
  420. package/dist/next/remote/calls.js +62 -0
  421. package/dist/next/remote/calls.js.map +1 -0
  422. package/dist/next/remote/consumer.d.ts +42 -0
  423. package/dist/next/remote/consumer.d.ts.map +1 -0
  424. package/dist/next/remote/consumer.js +343 -0
  425. package/dist/next/remote/consumer.js.map +1 -0
  426. package/dist/next/remote/hold.d.ts +130 -0
  427. package/dist/next/remote/hold.d.ts.map +1 -0
  428. package/dist/next/remote/hold.js +537 -0
  429. package/dist/next/remote/hold.js.map +1 -0
  430. package/dist/next/remote/host-link.d.ts +77 -0
  431. package/dist/next/remote/host-link.d.ts.map +1 -0
  432. package/dist/next/remote/host-link.js +182 -0
  433. package/dist/next/remote/host-link.js.map +1 -0
  434. package/dist/next/remote/internal.d.ts +6 -0
  435. package/dist/next/remote/internal.d.ts.map +1 -0
  436. package/dist/next/remote/internal.js +6 -0
  437. package/dist/next/remote/internal.js.map +1 -0
  438. package/dist/next/remote/path.d.ts +46 -0
  439. package/dist/next/remote/path.d.ts.map +1 -0
  440. package/dist/next/remote/path.js +73 -0
  441. package/dist/next/remote/path.js.map +1 -0
  442. package/dist/next/remote/provider.d.ts +76 -0
  443. package/dist/next/remote/provider.d.ts.map +1 -0
  444. package/dist/next/remote/provider.js +506 -0
  445. package/dist/next/remote/provider.js.map +1 -0
  446. package/dist/next/remote/relay.d.ts +58 -0
  447. package/dist/next/remote/relay.d.ts.map +1 -0
  448. package/dist/next/remote/relay.js +117 -0
  449. package/dist/next/remote/relay.js.map +1 -0
  450. package/dist/next/remote/remote-object.d.ts +133 -0
  451. package/dist/next/remote/remote-object.d.ts.map +1 -0
  452. package/dist/next/remote/remote-object.js +411 -0
  453. package/dist/next/remote/remote-object.js.map +1 -0
  454. package/dist/next/remote/replica.d.ts +59 -0
  455. package/dist/next/remote/replica.d.ts.map +1 -0
  456. package/dist/next/remote/replica.js +125 -0
  457. package/dist/next/remote/replica.js.map +1 -0
  458. package/dist/next/state/batch.d.ts +64 -0
  459. package/dist/next/state/batch.d.ts.map +1 -0
  460. package/dist/next/state/batch.js +163 -0
  461. package/dist/next/state/batch.js.map +1 -0
  462. package/dist/next/state/derive.d.ts +52 -0
  463. package/dist/next/state/derive.d.ts.map +1 -0
  464. package/dist/next/state/derive.js +182 -0
  465. package/dist/next/state/derive.js.map +1 -0
  466. package/dist/next/state/index.d.ts +6 -0
  467. package/dist/next/state/index.d.ts.map +1 -0
  468. package/dist/next/state/index.js +4 -0
  469. package/dist/next/state/index.js.map +1 -0
  470. package/dist/next/state/internal.d.ts +6 -0
  471. package/dist/next/state/internal.d.ts.map +1 -0
  472. package/dist/next/state/internal.js +8 -0
  473. package/dist/next/state/internal.js.map +1 -0
  474. package/dist/next/state/native-source.d.ts +106 -0
  475. package/dist/next/state/native-source.d.ts.map +1 -0
  476. package/dist/next/state/native-source.js +240 -0
  477. package/dist/next/state/native-source.js.map +1 -0
  478. package/dist/next/state/watchable.d.ts +114 -0
  479. package/dist/next/state/watchable.d.ts.map +1 -0
  480. package/dist/next/state/watchable.js +156 -0
  481. package/dist/next/state/watchable.js.map +1 -0
  482. package/dist/next/state/writable.d.ts +32 -0
  483. package/dist/next/state/writable.d.ts.map +1 -0
  484. package/dist/next/state/writable.js +49 -0
  485. package/dist/next/state/writable.js.map +1 -0
  486. package/dist/next/store/adapter.d.ts +67 -0
  487. package/dist/next/store/adapter.d.ts.map +1 -0
  488. package/dist/next/store/adapter.js +118 -0
  489. package/dist/next/store/adapter.js.map +1 -0
  490. package/dist/next/store/allocator.d.ts +17 -0
  491. package/dist/next/store/allocator.d.ts.map +1 -0
  492. package/dist/next/store/allocator.js +30 -0
  493. package/dist/next/store/allocator.js.map +1 -0
  494. package/dist/next/store/applier.d.ts +8 -0
  495. package/dist/next/store/applier.d.ts.map +1 -0
  496. package/dist/next/store/applier.js +375 -0
  497. package/dist/next/store/applier.js.map +1 -0
  498. package/dist/next/store/apply-batch.d.ts +12 -0
  499. package/dist/next/store/apply-batch.d.ts.map +1 -0
  500. package/dist/next/store/apply-batch.js +83 -0
  501. package/dist/next/store/apply-batch.js.map +1 -0
  502. package/dist/next/store/archive.d.ts +32 -0
  503. package/dist/next/store/archive.d.ts.map +1 -0
  504. package/dist/next/store/archive.js +129 -0
  505. package/dist/next/store/archive.js.map +1 -0
  506. package/dist/next/store/backend.d.ts +10 -0
  507. package/dist/next/store/backend.d.ts.map +1 -0
  508. package/dist/next/store/backend.js +15 -0
  509. package/dist/next/store/backend.js.map +1 -0
  510. package/dist/next/store/catalog.d.ts +24 -0
  511. package/dist/next/store/catalog.d.ts.map +1 -0
  512. package/dist/next/store/catalog.js +17 -0
  513. package/dist/next/store/catalog.js.map +1 -0
  514. package/dist/next/store/claims.d.ts +23 -0
  515. package/dist/next/store/claims.d.ts.map +1 -0
  516. package/dist/next/store/claims.js +65 -0
  517. package/dist/next/store/claims.js.map +1 -0
  518. package/dist/next/store/columns.d.ts +77 -0
  519. package/dist/next/store/columns.d.ts.map +1 -0
  520. package/dist/next/store/columns.js +77 -0
  521. package/dist/next/store/columns.js.map +1 -0
  522. package/dist/next/store/engine.d.ts +176 -0
  523. package/dist/next/store/engine.d.ts.map +1 -0
  524. package/dist/next/store/engine.js +283 -0
  525. package/dist/next/store/engine.js.map +1 -0
  526. package/dist/next/store/evaluate.d.ts +17 -0
  527. package/dist/next/store/evaluate.d.ts.map +1 -0
  528. package/dist/next/store/evaluate.js +128 -0
  529. package/dist/next/store/evaluate.js.map +1 -0
  530. package/dist/next/store/export.d.ts +17 -0
  531. package/dist/next/store/export.d.ts.map +1 -0
  532. package/dist/next/store/export.js +200 -0
  533. package/dist/next/store/export.js.map +1 -0
  534. package/dist/next/store/expression.d.ts +150 -0
  535. package/dist/next/store/expression.d.ts.map +1 -0
  536. package/dist/next/store/expression.js +268 -0
  537. package/dist/next/store/expression.js.map +1 -0
  538. package/dist/next/store/import.d.ts +10 -0
  539. package/dist/next/store/import.d.ts.map +1 -0
  540. package/dist/next/store/import.js +276 -0
  541. package/dist/next/store/import.js.map +1 -0
  542. package/dist/next/store/index.d.ts +16 -0
  543. package/dist/next/store/index.d.ts.map +1 -0
  544. package/dist/next/store/index.js +13 -0
  545. package/dist/next/store/index.js.map +1 -0
  546. package/dist/next/store/json-column.d.ts +33 -0
  547. package/dist/next/store/json-column.d.ts.map +1 -0
  548. package/dist/next/store/json-column.js +61 -0
  549. package/dist/next/store/json-column.js.map +1 -0
  550. package/dist/next/store/jsonl.d.ts +9 -0
  551. package/dist/next/store/jsonl.d.ts.map +1 -0
  552. package/dist/next/store/jsonl.js +61 -0
  553. package/dist/next/store/jsonl.js.map +1 -0
  554. package/dist/next/store/outbox.d.ts +26 -0
  555. package/dist/next/store/outbox.d.ts.map +1 -0
  556. package/dist/next/store/outbox.js +80 -0
  557. package/dist/next/store/outbox.js.map +1 -0
  558. package/dist/next/store/query.d.ts +39 -0
  559. package/dist/next/store/query.d.ts.map +1 -0
  560. package/dist/next/store/query.js +97 -0
  561. package/dist/next/store/query.js.map +1 -0
  562. package/dist/next/store/refusal.d.ts +15 -0
  563. package/dist/next/store/refusal.d.ts.map +1 -0
  564. package/dist/next/store/refusal.js +36 -0
  565. package/dist/next/store/refusal.js.map +1 -0
  566. package/dist/next/store/rows.d.ts +80 -0
  567. package/dist/next/store/rows.d.ts.map +1 -0
  568. package/dist/next/store/rows.js +183 -0
  569. package/dist/next/store/rows.js.map +1 -0
  570. package/dist/next/store/schema.d.ts +25 -0
  571. package/dist/next/store/schema.d.ts.map +1 -0
  572. package/dist/next/store/schema.js +115 -0
  573. package/dist/next/store/schema.js.map +1 -0
  574. package/dist/next/store/sql.d.ts +73 -0
  575. package/dist/next/store/sql.d.ts.map +1 -0
  576. package/dist/next/store/sql.js +234 -0
  577. package/dist/next/store/sql.js.map +1 -0
  578. package/dist/next/store/step.d.ts +48 -0
  579. package/dist/next/store/step.d.ts.map +1 -0
  580. package/dist/next/store/step.js +50 -0
  581. package/dist/next/store/step.js.map +1 -0
  582. package/dist/next/store/store.d.ts +161 -0
  583. package/dist/next/store/store.d.ts.map +1 -0
  584. package/dist/next/store/store.js +627 -0
  585. package/dist/next/store/store.js.map +1 -0
  586. package/dist/next/store/table-changes.d.ts +29 -0
  587. package/dist/next/store/table-changes.d.ts.map +1 -0
  588. package/dist/next/store/table-changes.js +102 -0
  589. package/dist/next/store/table-changes.js.map +1 -0
  590. package/dist/next/store/table-evolve.d.ts +74 -0
  591. package/dist/next/store/table-evolve.d.ts.map +1 -0
  592. package/dist/next/store/table-evolve.js +201 -0
  593. package/dist/next/store/table-evolve.js.map +1 -0
  594. package/dist/next/store/table-handle.d.ts +67 -0
  595. package/dist/next/store/table-handle.d.ts.map +1 -0
  596. package/dist/next/store/table-handle.js +101 -0
  597. package/dist/next/store/table-handle.js.map +1 -0
  598. package/dist/next/store/table-history.d.ts +75 -0
  599. package/dist/next/store/table-history.d.ts.map +1 -0
  600. package/dist/next/store/table-history.js +42 -0
  601. package/dist/next/store/table-history.js.map +1 -0
  602. package/dist/next/store/table-migration.d.ts +16 -0
  603. package/dist/next/store/table-migration.d.ts.map +1 -0
  604. package/dist/next/store/table-migration.js +202 -0
  605. package/dist/next/store/table-migration.js.map +1 -0
  606. package/dist/next/store/table-writes.d.ts +125 -0
  607. package/dist/next/store/table-writes.d.ts.map +1 -0
  608. package/dist/next/store/table-writes.js +165 -0
  609. package/dist/next/store/table-writes.js.map +1 -0
  610. package/dist/next/store/table.d.ts +80 -0
  611. package/dist/next/store/table.d.ts.map +1 -0
  612. package/dist/next/store/table.js +103 -0
  613. package/dist/next/store/table.js.map +1 -0
  614. package/dist/next/store/text.d.ts +14 -0
  615. package/dist/next/store/text.d.ts.map +1 -0
  616. package/dist/next/store/text.js +51 -0
  617. package/dist/next/store/text.js.map +1 -0
  618. package/dist/next/store/writes.d.ts +5 -0
  619. package/dist/next/store/writes.d.ts.map +1 -0
  620. package/dist/next/store/writes.js +4 -0
  621. package/dist/next/store/writes.js.map +1 -0
  622. package/dist/next-node/compression.d.ts +7 -0
  623. package/dist/next-node/compression.d.ts.map +1 -0
  624. package/dist/next-node/compression.js +24 -0
  625. package/dist/next-node/compression.js.map +1 -0
  626. package/dist/next-node/http/admission.d.ts +63 -0
  627. package/dist/next-node/http/admission.d.ts.map +1 -0
  628. package/dist/next-node/http/admission.js +134 -0
  629. package/dist/next-node/http/admission.js.map +1 -0
  630. package/dist/next-node/http/authenticate.d.ts +21 -0
  631. package/dist/next-node/http/authenticate.d.ts.map +1 -0
  632. package/dist/next-node/http/authenticate.js +34 -0
  633. package/dist/next-node/http/authenticate.js.map +1 -0
  634. package/dist/next-node/http/cookies.d.ts +24 -0
  635. package/dist/next-node/http/cookies.d.ts.map +1 -0
  636. package/dist/next-node/http/cookies.js +62 -0
  637. package/dist/next-node/http/cookies.js.map +1 -0
  638. package/dist/next-node/http/file.d.ts +23 -0
  639. package/dist/next-node/http/file.d.ts.map +1 -0
  640. package/dist/next-node/http/file.js +94 -0
  641. package/dist/next-node/http/file.js.map +1 -0
  642. package/dist/next-node/http/headers.d.ts +37 -0
  643. package/dist/next-node/http/headers.d.ts.map +1 -0
  644. package/dist/next-node/http/headers.js +129 -0
  645. package/dist/next-node/http/headers.js.map +1 -0
  646. package/dist/next-node/http/http.d.ts +100 -0
  647. package/dist/next-node/http/http.d.ts.map +1 -0
  648. package/dist/next-node/http/http.js +462 -0
  649. package/dist/next-node/http/http.js.map +1 -0
  650. package/dist/next-node/http/incoming.d.ts +19 -0
  651. package/dist/next-node/http/incoming.d.ts.map +1 -0
  652. package/dist/next-node/http/incoming.js +31 -0
  653. package/dist/next-node/http/incoming.js.map +1 -0
  654. package/dist/next-node/http/index.d.ts +11 -0
  655. package/dist/next-node/http/index.d.ts.map +1 -0
  656. package/dist/next-node/http/index.js +12 -0
  657. package/dist/next-node/http/index.js.map +1 -0
  658. package/dist/next-node/http/node.d.ts +78 -0
  659. package/dist/next-node/http/node.d.ts.map +1 -0
  660. package/dist/next-node/http/node.js +291 -0
  661. package/dist/next-node/http/node.js.map +1 -0
  662. package/dist/next-node/http/request.d.ts +54 -0
  663. package/dist/next-node/http/request.d.ts.map +1 -0
  664. package/dist/next-node/http/request.js +116 -0
  665. package/dist/next-node/http/request.js.map +1 -0
  666. package/dist/next-node/http/response.d.ts +63 -0
  667. package/dist/next-node/http/response.d.ts.map +1 -0
  668. package/dist/next-node/http/response.js +202 -0
  669. package/dist/next-node/http/response.js.map +1 -0
  670. package/dist/next-node/http/router.d.ts +114 -0
  671. package/dist/next-node/http/router.d.ts.map +1 -0
  672. package/dist/next-node/http/router.js +261 -0
  673. package/dist/next-node/http/router.js.map +1 -0
  674. package/dist/next-node/http/upgrades.d.ts +58 -0
  675. package/dist/next-node/http/upgrades.d.ts.map +1 -0
  676. package/dist/next-node/http/upgrades.js +184 -0
  677. package/dist/next-node/http/upgrades.js.map +1 -0
  678. package/dist/next-node/plugins/build.d.ts +57 -0
  679. package/dist/next-node/plugins/build.d.ts.map +1 -0
  680. package/dist/next-node/plugins/build.js +334 -0
  681. package/dist/next-node/plugins/build.js.map +1 -0
  682. package/dist/next-node/plugins/discover.d.ts +36 -0
  683. package/dist/next-node/plugins/discover.d.ts.map +1 -0
  684. package/dist/next-node/plugins/discover.js +91 -0
  685. package/dist/next-node/plugins/discover.js.map +1 -0
  686. package/dist/next-node/plugins/evaluate.d.ts +33 -0
  687. package/dist/next-node/plugins/evaluate.d.ts.map +1 -0
  688. package/dist/next-node/plugins/evaluate.js +98 -0
  689. package/dist/next-node/plugins/evaluate.js.map +1 -0
  690. package/dist/next-node/plugins/index.d.ts +9 -0
  691. package/dist/next-node/plugins/index.d.ts.map +1 -0
  692. package/dist/next-node/plugins/index.js +11 -0
  693. package/dist/next-node/plugins/index.js.map +1 -0
  694. package/dist/next-node/plugins/install.d.ts +13 -0
  695. package/dist/next-node/plugins/install.d.ts.map +1 -0
  696. package/dist/next-node/plugins/install.js +37 -0
  697. package/dist/next-node/plugins/install.js.map +1 -0
  698. package/dist/next-node/plugins/plugins.d.ts +135 -0
  699. package/dist/next-node/plugins/plugins.d.ts.map +1 -0
  700. package/dist/next-node/plugins/plugins.js +206 -0
  701. package/dist/next-node/plugins/plugins.js.map +1 -0
  702. package/dist/next-node/plugins/runtime.d.ts +41 -0
  703. package/dist/next-node/plugins/runtime.d.ts.map +1 -0
  704. package/dist/next-node/plugins/runtime.js +136 -0
  705. package/dist/next-node/plugins/runtime.js.map +1 -0
  706. package/dist/next-node/plugins/stack.d.ts +16 -0
  707. package/dist/next-node/plugins/stack.d.ts.map +1 -0
  708. package/dist/next-node/plugins/stack.js +61 -0
  709. package/dist/next-node/plugins/stack.js.map +1 -0
  710. package/dist/next-node/plugins/watcher.d.ts +58 -0
  711. package/dist/next-node/plugins/watcher.d.ts.map +1 -0
  712. package/dist/next-node/plugins/watcher.js +281 -0
  713. package/dist/next-node/plugins/watcher.js.map +1 -0
  714. package/dist/next-node/workers/control.d.ts +83 -0
  715. package/dist/next-node/workers/control.d.ts.map +1 -0
  716. package/dist/next-node/workers/control.js +77 -0
  717. package/dist/next-node/workers/control.js.map +1 -0
  718. package/dist/next-node/workers/index.d.ts +5 -0
  719. package/dist/next-node/workers/index.d.ts.map +1 -0
  720. package/dist/next-node/workers/index.js +7 -0
  721. package/dist/next-node/workers/index.js.map +1 -0
  722. package/dist/next-node/workers/lock.d.ts +21 -0
  723. package/dist/next-node/workers/lock.d.ts.map +1 -0
  724. package/dist/next-node/workers/lock.js +137 -0
  725. package/dist/next-node/workers/lock.js.map +1 -0
  726. package/dist/next-node/workers/main.d.ts +46 -0
  727. package/dist/next-node/workers/main.d.ts.map +1 -0
  728. package/dist/next-node/workers/main.js +230 -0
  729. package/dist/next-node/workers/main.js.map +1 -0
  730. package/dist/next-node/workers/process.d.ts +42 -0
  731. package/dist/next-node/workers/process.d.ts.map +1 -0
  732. package/dist/next-node/workers/process.js +125 -0
  733. package/dist/next-node/workers/process.js.map +1 -0
  734. package/dist/next-node/workers/workers.d.ts +80 -0
  735. package/dist/next-node/workers/workers.d.ts.map +1 -0
  736. package/dist/next-node/workers/workers.js +572 -0
  737. package/dist/next-node/workers/workers.js.map +1 -0
  738. package/dist/object.d.ts +4 -4
  739. package/dist/object.d.ts.map +1 -1
  740. package/dist/object.js +3 -4
  741. package/dist/object.js.map +1 -1
  742. package/dist/output.d.ts +9 -3
  743. package/dist/output.d.ts.map +1 -1
  744. package/dist/output.js +21 -9
  745. package/dist/output.js.map +1 -1
  746. package/dist/remote.d.ts.map +1 -1
  747. package/dist/remote.js +2 -2
  748. package/dist/remote.js.map +1 -1
  749. package/dist/schema.d.ts +8 -4
  750. package/dist/schema.d.ts.map +1 -1
  751. package/dist/schema.js +180 -5
  752. package/dist/schema.js.map +1 -1
  753. package/dist/sqlite/cloudflare.d.ts +54 -0
  754. package/dist/sqlite/cloudflare.d.ts.map +1 -0
  755. package/dist/sqlite/cloudflare.js +144 -0
  756. package/dist/sqlite/cloudflare.js.map +1 -0
  757. package/dist/sqlite/database.d.ts +40 -0
  758. package/dist/sqlite/database.d.ts.map +1 -0
  759. package/dist/sqlite/database.js +2 -0
  760. package/dist/sqlite/database.js.map +1 -0
  761. package/dist/sqlite/index.d.ts +4 -0
  762. package/dist/sqlite/index.d.ts.map +1 -0
  763. package/dist/sqlite/index.js +3 -0
  764. package/dist/sqlite/index.js.map +1 -0
  765. package/dist/sqlite/migrations.d.ts +10 -0
  766. package/dist/sqlite/migrations.d.ts.map +1 -0
  767. package/dist/sqlite/migrations.js +33 -0
  768. package/dist/sqlite/migrations.js.map +1 -0
  769. package/dist/sqlite/node.d.ts +41 -0
  770. package/dist/sqlite/node.d.ts.map +1 -0
  771. package/dist/sqlite/node.js +191 -0
  772. package/dist/sqlite/node.js.map +1 -0
  773. package/dist/sqlite/schema.d.ts +3 -0
  774. package/dist/sqlite/schema.d.ts.map +1 -0
  775. package/dist/sqlite/schema.js +10 -0
  776. package/dist/sqlite/schema.js.map +1 -0
  777. package/dist/telemetry-sqlite/index.d.ts +24 -0
  778. package/dist/telemetry-sqlite/index.d.ts.map +1 -0
  779. package/dist/telemetry-sqlite/index.js +273 -0
  780. package/dist/telemetry-sqlite/index.js.map +1 -0
  781. package/dist/telemetry-sqlite/store.d.ts +9 -0
  782. package/dist/telemetry-sqlite/store.d.ts.map +1 -0
  783. package/dist/telemetry-sqlite/store.js +110 -0
  784. package/dist/telemetry-sqlite/store.js.map +1 -0
  785. package/dist/watch.d.ts +194 -0
  786. package/dist/watch.d.ts.map +1 -0
  787. package/dist/watch.js +383 -0
  788. package/dist/watch.js.map +1 -0
  789. package/dist/wire.d.ts +174 -193
  790. package/dist/wire.d.ts.map +1 -1
  791. package/dist/wire.js +81 -80
  792. package/dist/wire.js.map +1 -1
  793. package/docs/guide.md +15 -15
  794. package/docs/next/benchmarks.md +959 -0
  795. package/docs/next/decisions.md +2957 -0
  796. package/docs/next/dependencies/book.md +1671 -0
  797. package/docs/next/dependencies/index.html +2641 -0
  798. package/docs/next/dependencies/model.md +330 -0
  799. package/docs/next/design.md +2554 -0
  800. package/docs/next/durable-observers/book.md +432 -0
  801. package/docs/next/durable-observers/index.html +517 -0
  802. package/docs/next/flow-control/book.md +333 -0
  803. package/docs/next/flow-control/fold/index.html +265 -0
  804. package/docs/next/flow-control/index.html +548 -0
  805. package/docs/next/flow-control/window/index.html +228 -0
  806. package/docs/next/guide-plugins-hosts/book.md +607 -0
  807. package/docs/next/guide-plugins-hosts/index.html +652 -0
  808. package/docs/next/http-workers/book.md +378 -0
  809. package/docs/next/http-workers/index.html +515 -0
  810. package/docs/next/layer-1.md +311 -0
  811. package/docs/next/layer-2.md +216 -0
  812. package/docs/next/plugin-model/book.md +186 -0
  813. package/docs/next/plugin-model/index.html +310 -0
  814. package/docs/next/plugin-primer/book.md +273 -0
  815. package/docs/next/plugin-primer/index.html +430 -0
  816. package/docs/next/slice-1.md +236 -0
  817. package/docs/next/slice-10.md +285 -0
  818. package/docs/next/slice-11.md +93 -0
  819. package/docs/next/slice-2.md +174 -0
  820. package/docs/next/slice-3a.md +296 -0
  821. package/docs/next/slice-3b.md +197 -0
  822. package/docs/next/slice-4.md +146 -0
  823. package/docs/next/slice-4a.md +418 -0
  824. package/docs/next/slice-4b.md +208 -0
  825. package/docs/next/slice-5.md +281 -0
  826. package/docs/next/slice-6a.md +676 -0
  827. package/docs/next/slice-6b.md +332 -0
  828. package/docs/next/slice-7a.md +130 -0
  829. package/docs/next/slice-7b/book.md +608 -0
  830. package/docs/next/slice-7b/index.html +842 -0
  831. package/docs/next/slice-7b.md +255 -0
  832. package/docs/next/slice-7c.md +165 -0
  833. package/docs/next/slice-8.md +194 -0
  834. package/docs/next/slices.md +230 -0
  835. package/docs/next/store/book.md +665 -0
  836. package/docs/next/store/index.html +861 -0
  837. package/docs/next/store/walkthrough.md +193 -0
  838. package/docs/spec.md +9 -9
  839. package/docs/tutorial.md +26 -25
  840. package/package.json +42 -5
  841. package/src/delta/README.md +69 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,59 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.5.0] - 2026-11-02
4
+
5
+ ### Breaking Changes
6
+
7
+ - Schemas are JSON Schema checked by `@earendil-works/pi-schema` instead of TypeBox, which is no longer a dependency of Chord. Contracts, `self.state(...)` schemas and method signatures take pi-schema builders or any JSON Schema object (TypeBox-built schemas still validate, being JSON Schema, but type as `unknown`); handler and reference types come from pi-schema's `Static`. Validation, input defaults and the stripping of unknown fields work on any JSON Schema by its shape (before, defaults and stripping applied only to TypeBox-built schemas). `format` is an annotation, no longer checked: `str({ format: "email" })` accepts `"nope"` (TypeBox checked the formats it knew); check a format in the handler where it matters. An `invalid` error's message is now `<path> <message>` with pi-schema's paths and messages (a missing field at its own path, `missing`; `expected string, got number` instead of `must be string`), and its `details` are pi-schema's `ValidationError`s (`{ path, keyword, message }`) instead of TypeBox's errors. Link frames, descriptions, fingerprints and identities are unchanged for schemas with the same JSON. Migration, keeping a contract's fingerprint (it is computed from the schema's JSON): `Type.String/Number/Integer/Boolean/Null/Unknown/Array/Union/Optional(...)` become `str/num/int/bool/nul/unknown/arr/union/opt(...)` with the same options; `Type.Object(p)` becomes `obj(p, { open: true })` (pi-schema's `obj` is closed by default) and `Type.Object(p, { additionalProperties: false })` `obj(p)`; `Type.Enum(values)` becomes `oneOf(values)`; `Type.Literal(v)` becomes `{ type: typeof v, const: v }` (pi-schema's `lit(v)` has no `type`); `Type.Record(Type.String(), v)` becomes `{ type: "object", patternProperties: { "^.*$": v } }` (pi-schema's `map(v)` uses `additionalProperties`); `Type.Intersect(list)` becomes `{ allOf: list }`; `Type.Function(params, result)` and `Type.Void()` become `{ type: "function", parameters, returnType }` and `{ type: "void" }`; `Type.Unsafe<T>(schema)` becomes `schema as Schema<T>`; `Type.Immutable(schema)` becomes the schema (cast its `Schema<readonly T[]>` type); `opt(...)` marks only an `obj` property; `Static` and `TSchema` come from pi-schema (`Static`, `Schema`). pi-schema's own `lit`, `map` and closed `obj` give other JSON and so other fingerprints, which matters only while peers of both versions talk.
8
+ - `traceIn(options, fn, context)` takes the context last (was `traceIn(context, options, fn)`), like the rest of the API.
9
+ - Watch listeners take one change object before the context: `WatchHandle.start((change, context) => …)` with `change: WatchChange<T>` = `{ value, ops, retired }`, and `NativeWatchHandle.start(({ value }, context) => …)` with `NativeWatchChange<T>`. A change is plain data, those fields only; the frame's context is the second argument. `Watch.advance(change, context)` takes the same object, and a frame delivered alone, with nothing folded into it, reaches the listener as the object the source passed. Migration: `start(async (value, ops, ctx) => …)` becomes `start(async ({ value, ops }, ctx) => …)`, `start(async (value, ctx) => …)` on a native watch `start(async ({ value }, ctx) => …)`, and `advance(value, ops, ctx)` becomes `advance({ value, ops, retired: false }, ctx)`.
10
+ - `SqliteExecutor.runCounted(sql, ...params)` runs one statement like `run` and resolves with the rows it inserted, updated or deleted, as SQLite's `changes()` counts them (index writes and rows changed by triggers do not count). The Node driver takes it from `node:sqlite`; the Durable Object driver reads `SELECT changes()` after the statement (the cursor's `rowsWritten` also counts index writes), so `run` stays as cheap as before. Migration: custom `SqliteDatabase` and `SqliteExecutor` implementations add `runCounted`.
11
+ - Retirement is a flag, not an end: `WatchEnd` loses `retired`, and `Watch.retire(context)` is removed. A source reports a retirement with `advance({ value, ops, retired: true }, context)`, whose value is what the address shows after it, and the watch goes on: the next call has `retired: true`, folded with every other pending frame, so a document created at the address afterwards arrives in the same or a later call as `[["r", value]]`. `endAfterDelivery()` tells a watch its source sends nothing more: it takes no more frames, delivers what is pending, and ends `ended` after its last call returned, at once when nothing is pending and no call runs; it stays attached until then, so the source's `end()` (such as at its close), `stop()`, cancellation, or a throwing listener still end it first. Migration: a listener that waited for `closed` to give `retired` or tested for a `null` value tests `change.retired`; a source that called `retire(ctx)` calls `advance({ value, ops, retired: true }, ctx)`, then `endAfterDelivery()` when its owner ends with the retirement.
12
+ - Watch listeners get a tagged call, and a watch stays open through a failure its source recovers from: `WatchCall<T>` is `{ kind: "value", value, ops, retired }` or `{ kind: "failed", error }`, and `NativeWatchCall<T>` is `{ kind: "value", value }` or `{ kind: "failed", error }` (replacing `WatchChange<T>` and `NativeWatchChange<T>`). After a `failed` call `watch.value` keeps the last value and the next value arrives as `[["r", value]]`; while the listener is busy, a failure drops the pending values (`value` then `failed` folds into the failure) and a value replaces a pending failure (`failed` then `value` folds into the value, as `r`). `Watch.advance(call, context)` takes a `WatchCall`, a value call delivered alone still reaches the listener as the object the source passed (no allocation), and `Watch.fail(error, context)` and `NativeWatch.fail(error, context)` send a failure. Migration: `start(async ({ value, ops }, ctx) => …)` becomes `start(async (call, ctx) => { if (call.kind === "failed") return; const { value, ops } = call; … })`, a native `start(async ({ value }, ctx) => …)` likewise; `advance({ value, ops, retired }, ctx)` becomes `advance({ kind: "value", value, ops, retired }, ctx)`.
13
+ - `WatchEnd` is tagged by `kind` instead of `reason`, and a watch whose acquisition context is aborted ends `aborted` instead of `cancelled`: `{ kind: "stopped" | "aborted" | "ended" }`, `{ kind: "listener_error", error }`, or `{ kind: "failed", error }` (a final failure only). `Watch.cancel()` is `abort()`, `observeCancellation(signal)` is `observeAbort(signal)`, and `end(failure?)` takes the end: `end({ kind: "ended" })` or `end({ kind: "failed", error })`. Migration: `end.reason === "cancelled"` becomes `end.kind === "aborted"`, every other `end.reason` becomes `end.kind`; `watch.end()` becomes `watch.end({ kind: "ended" })`, `watch.end({ error })` becomes `watch.end({ kind: "failed", error })`.
14
+
15
+ ### Added
16
+
17
+ - Chord v2's store (`@earendil-works/chord/next`) gains `ChordStore.commitSeries(commits, receive, ctx)`: several commits in one backend transaction, each at its own seq with its own outbox row, the store metadata written once. Each commit's check runs on a step that sees the commits before it, before its writes; a check that throws refuses that commit and stores the ones before it, while a failed statement or write rolls the whole series back, and a failed `COMMIT` stops the store. It replaces `commitInBatch`, which is removed. Durable's `StoreStorage` stores each Session commit call through it.
18
+ - Chord v2 has a package export again, `@earendil-works/chord/next` (experimental): every layer's API for apps (contracts, data, documents, hosts, jobs, links, state, the store), and, marked internal, the store's surface for adapters (`StoreOwnerTables`, `OwnerTable`, the documents engine's reads and writes, the commit step, `applyBatch`). v2's store gains one id allocator for every id in it, claims per table and per document namespace, Durable's Storage semantics for a refused commit (it rejects that commit only; an unknown outcome stops the store), document histories `none`, `latest` and `rewindable` with reads at a point, archives carrying document revisions, and batch apply; v2 objects gain `self.follow` (another runtime's synchronous observers as sources) and persisted jobs (`persist: { resume }`, a stored `abort(id, ctx)`, deferred state changes).
19
+ - Chord v2 (`@earendil-works/chord/next`) gains registries, writables, wake signals and root scopes (slice 8): `defineRegistry<C, V>(name, { version })` tokens shared by plugins, served by the defining plugin's facet with `host.serve(R, { compose, accepts? })`; contributions from facets (`defineFacet((host, self) => self.contribute(R, value))`) and host-lifetime objects (`StoreSelf.contribute`), plain values or Chord watchables, in a table sorted by plugin name and composed lazily (once at the end of `load`'s setups, then when read or followed, in the batch that changed the table); readers through `self.registry(R)` (a declared dependency: an object activates once the registry has a value, and fails `transient` with the new reason `unavailable/undeclared` when nobody serves it) and `host.registry(R, ctx)`, a `RegistryValue<V>` with `observe(observer, ctx)`; older contributions and readers adapted by `accepts`; the helpers `keyedEntries` and `orderedEntries`; the `onError` kinds `registry_conflict`, `registry_failed`, `contribution_failed` and `contribution_refused`. `self.writable(initial)` is an in-process value an attempt sets (identity compared); native sources (writables, registry values, `ref.state`) are derive sources. `self.retryOn(...sources)` retries a failed object when a registry value changes. `host.root(fn, context, { principal? })` runs code outside objects with a handler's `ctx`, sealed when `fn` settles, `context` aborts or the host closes.
20
+ - Chord v2 gains plugins (slice 7c): `src/next-node/plugins` (Node, to be exported as `@earendil-works/chord/next/plugins`) finds plugin directories, builds each facet with esbuild (now an optional peer dependency of `@earendil-works/chord`, imported only there), evaluates it with `vm.Script`, maps plugin stack traces (`mapStack`), installs plugin dependencies, watches plugin and base code, and rolls reloads out across hosts. `host.load` and `host.reload` work per plugin: a plugin whose setup, factory or declarations fail is left out at `load` (`{ failed }`) or kept on its old code at `reload` (`failed` in the report, `reload(facets, ctx, { failed })` for build and evaluation failures), with a closure rule keeping a consumer old when its provider was kept old; an abort after a reload's commit rejects with `details.committed`.
21
+ - Chord v2 gains HTTP and workers (slice 10): `src/next-node/http` (to be exported as `@earendil-works/chord/next/http`) builds a Web-standard `fetch` handler from the routes, wraps, sockets, hosts, relays and CSP sources plugins contribute to the registry `Http`, with authenticators from the registry `Authenticators`, responses as descriptions (`json`, `html`, `bytes` with ranges, `redirect`, `error`; `fileResponse`), and a security baseline on by default (provenance by the socket and `Host`, foreign requests anonymous, `Origin` checks, default headers with a per-response CSP nonce, signed cookies, safe downloads); Chord's own Node listener as a host-lifetime object, `nodeRequest` for apps mounting it on their own Node server, the links endpoint and plugin sockets with a heartbeat, closed at once when their contribution leaves. `ws` is an optional peer dependency, imported only there. `src/next-node/workers` (`createWorkers`, `workerMain`) runs a forked worker per address of a host kind, started on demand, stopped when idle, never restarted by itself (a failure stays until `retry` or a rollout), its plugins built by the server and shipped. The plugins component defines one definition per facet kind (`kinds: { name: { platform, hostPackages } }`, modules given at `plugins.load(host, { kind, core, modules })`), splits loading into `createPluginRuntime()` (no esbuild), offers `scripts(kind)`, rolls out with one result per host (`RolloutStep` returns `{ hosts }`), and resolves cross-plugin imports by plugin name (`@app/notes/contract`). Kernel: `host.route` returns a `RouteHandle` (`retry`, `suspend`) and a route has no backoff timer (a failed `resolve` fails its holders `waiting`); `host.root(fn, ctx, { principal: undefined })` runs anonymous; a link reads `origin` only on parent and route links (a protocol error on a child link) and drops a per-origin record once it is idle.
22
+ - Chord v2, experimental and not exported yet: the next object runtime in `src/next` (contracts, hosts and objects, documents, derives, links and relays, routines and jobs, the store), with its tests and runnable examples in `test/next` and its design in `docs/next` (`design.md`, the decision log `decisions.md`, the slice plan `slices.md`). Its API changes with every slice until it gets an entry point.
23
+ - `NativeWatchable<T>`: an in-process value that changes and can be watched (`value`, `watch(context)` returning a `NativeWatchHandle<T>`), the in-process counterpart of `Watchable<T>`.
24
+ - `WatchHandle<T>` and `WatchEnd`, the one watch API, moved from Durable: a serialized observation with `value`, `start(listener)`, `stop()`, and `closed`; the listener gets a `WatchChange<T>` (`{ value, ops, retired }`) and the context. `WatchEnd` reasons are `stopped`, `cancelled`, `ended`, `listener_error`, and `failed`.
25
+ - `Watch<T>`, the one watch handle implementation, moved from Durable: a source creates one per watch and feeds it with `advance(change, context)` (`retired: true` for a retirement), `end()` or `end({ error })`, `endAfterDelivery()`, and `observeCancellation(signal)`. Frames that arrive while the listener runs (or before `start`) are delivered in one call with the newest value, their ops folded by `PendingOps` and the newest frame's context; past 10,000 pending ops after folding, the call gets one root replacement `[["r", newest]]` instead (replaces the collapse after 100 undelivered frames); termination drops the listener and every reference into the source.
26
+ - `Watchable<T>`: a value that changes and can be watched (`value`, `watch(context)` returning a `WatchHandle<T>`), the common interface of documents, derives and other observable values.
27
+ - `NativeWatchHandle<T>` and its implementation `NativeWatch<T>`: the same lifecycle for in-process values, with listener `({ value }, context)` (`NativeWatchChange<T>`) and no ops: one call per value in order, and past 100 pending values one call with the value of the optional `replace()` or the newest value.
28
+ - `PendingOps` and `PendingTake` in `@earendil-works/chord/delta`: the pending ops of one slow consumer, kept raw and folded while they wait (appends to one path join, a primitive set replaces earlier leaf ops on its path, `r` drops everything before it); `size` counts the pending ops after folding; `take()` empties the queue and hands over the folded ops, or `replace` past 10,000 pending ops. Received batches and op tuples are never mutated.
29
+ - `ownedSlice(text, start, end?)` in `@earendil-works/chord/delta`: a slice of a string that does not keep the whole string alive ([#9265](https://github.com/earendil-works/pi/issues/9265))
30
+ - `appendText(draft, key, text)` in `@earendil-works/chord/delta`: append to a string in a draft at O(text) cost, recorded as an append op without comparing the old and new strings (a plain `draft[key] += text` makes `prepare()` read the whole string, O(length) per change); `StringKeys<T>` names the keys it accepts ([#9265](https://github.com/earendil-works/pi/issues/9265))
31
+
32
+ ### Changed
33
+
34
+ - Chord v2 (`@earendil-works/chord/next`) checks its schemas with `@earendil-works/pi-schema` instead of TypeBox: its helpers (`str`, `num`, `int`, `bool`, `nul`, `lit`, `oneOf`, `union`, `obj`, `arr`, `map`, `opt`, `bytes`, `unknown`) build on pi-schema's builders and keep the JSON contracts were fingerprinted with, so every fingerprint, normal form and stored record stays the same (a test records them and reads a store written before the switch). `Static` and `Schema` (was `TSchema`) come from pi-schema; `opt(...)` marks an object field or a table column and is no schema elsewhere (a top-level `opt` had no effect before); a schema with a non-enumerable key (a TypeBox schema's metadata) is refused at declaration; `map(bytes())` is accepted now (it was refused while `bytes()` carried a TypeBox refinement). `format` is an annotation, no longer checked (`{ type: "string", format: "email" }` accepts `"nope"`; TypeBox checked the formats it knew). A failed check's message comes from pi-schema (`args/title: expected string, got integer`), its `details.path` escapes `~` and `/` (JSON Pointer); reasons and codes are unchanged. Declaring and compiling are cheaper (a 20-method contract 1.07 ms to 0.86 ms, a validator's first use 172 µs to 48 µs), a check costs the same (0.25 µs), the message envelope check up to 100 ns more per message.
35
+ - The delta tracker keeps its one open change in a plain field and needs a `WeakRef` only for a second change open at the same time (one per change before). A `WeakRef` target survives the scavenges of its job, so a run of changes in one job promoted every change's overlay to old space: 200,000 small changes in one job now promote 2 MB instead of 47.5 MB and take 3.1 µs each instead of 3.8 µs (3.0 instead of 3.5 µs when they span jobs). A draft dropped without `prepare()` or `abort()` now stays referenced by its tracker until the tracker's next `beginChange()` or `adopt()`.
36
+ - `applyImmutable()`, `applyImmutableBatches()` and tracker revisions copy each container on a changed path with spread (or `Object.assign()` onto a null-prototype object) instead of one `Object.defineProperty()` per key, about 25 times faster per container ([#9265](https://github.com/earendil-works/pi/issues/9265))
37
+
38
+ ### Fixed
39
+
40
+ - A host a route resolves is admitted even when the relayed reference that asked for it is released, its client disconnects, or its principal is refused or revoked while the route resolves. Before, the parent never read the new host's link: a spawned worker's own references to its parent (its `lifetime: "host"` objects' upstream references) waited until they failed `unavailable/ready_timeout`, reported as a possible reference cycle across hosts.
41
+ - The Node SQLite driver keeps the 256 most recently used prepared statements per connection instead of every statement it ever prepared, so callers generating SQL of unbounded shapes (a query builder) no longer grow memory without bound.
42
+ - Fixed append ops from the delta tracker and `diffRevisions()` keeping the whole string they were cut from alive (V8 represents a slice as a view of its source), so a delta chain, a watch backlog or a replica built from appends to a growing text held one copy of the text per commit ([#9265](https://github.com/earendil-works/pi/issues/9265))
43
+
44
+ ## [1.4.0] - 2026-10-21
45
+
46
+ ### Breaking Changes
47
+
48
+ - Custom `Context` implementations must provide `telemetry: TelemetrySpan`; use the no-op span `NOOP_TELEMETRY_CONTEXT` when disabled. `withTelemetry()` accepts spans, not adapters.
49
+
50
+ ### Added
51
+
52
+ - `@earendil-works/chord/telemetry-sqlite`: portable SQLite telemetry recording with bounded settled-span queues, ten-second metric aggregates, periodic flushes, and retention cleanup.
53
+ - `Context.telemetry` is an explicit, non-optional telemetry parent (no-op by default). `withTelemetry(telemetry, context)` derives it without changing values or cancellation; `traceIn(context, options, fn)` starts a child span and passes its derived context to the callback.
54
+ - `@earendil-works/chord/sqlite`: portable SQLite interfaces, atomic migration runner, and schema-prefix validation, with Node (`/sqlite/node`) and Cloudflare Durable Object (`/sqlite/cloudflare`) drivers. Moved from Durable, which keeps its storage implementations and re-exports the moved public names.
55
+ - `@earendil-works/chord/output`: `Progress` takes an optional `ProgressClock` (`now`, `setTimer`) to pace commits on, by default `Date.now` and `setTimeout`.
56
+
3
57
  ## [1.3.0] - 2026-10-15
4
58
 
5
59
  ### Breaking Changes
package/README.md CHANGED
@@ -8,33 +8,37 @@ Chord builds applications out of **objects** that live in several processes (a s
8
8
  - **State** is observable JSON. Remote viewers get a snapshot followed by deltas.
9
9
  - **Hot reload** swaps code while it runs. Work in flight finishes on the code it started with, state is kept, and incompatible changes migrate at a safe point.
10
10
 
11
- Contracts are runtime values described with [TypeBox](https://github.com/sinclairzx81/typebox) schemas. Hosts exchange JSON frames over links: in memory, a Node IPC channel, or a WebSocket.
11
+ Contracts are runtime values described with JSON Schema, written with the builders of `@earendil-works/pi-schema` (any JSON Schema object works; `format` is an annotation, never checked). Hosts exchange JSON frames over links: in memory, a Node IPC channel, or a WebSocket.
12
12
 
13
13
  ## Entry points
14
14
 
15
15
  | Import | Contents | Runs in |
16
16
  |--------|----------|---------|
17
- | `@earendil-works/chord` | Contracts (`local`, `remote`, `method`, `opaque`), declarations (through the factory's `self`: `state`, `derive`, `resource`, `on`, `task`), hosts (`createHost`, `defineFacet`, `defineRegistry`), links (`memoryLinkPair`, `ipcLink`, `webSocketLink`, `acceptWebSockets`), errors (`ChordError`, `isChordError`, `forbidden`, `invalid`). Also the shared base: `Context`, `JsonValue`, `JsonRepresentation`, `Draft`, `copyJson`, `isJsonValue`, and `replicatedState` with its types. | Node and browsers |
17
+ | `@earendil-works/chord` | Contracts (`local`, `remote`, `method`, `opaque`), declarations (through the factory's `self`: `state`, `derive`, `resource`, `on`, `task`), hosts (`createHost`, `defineFacet`, `defineRegistry`), links (`memoryLinkPair`, `ipcLink`, `webSocketLink`, `acceptWebSockets`), errors (`ChordError`, `isChordError`, `forbidden`, `invalid`). Also the shared base: `Context`, `JsonValue`, `JsonRepresentation`, `Draft`, `copyJson`, `isJsonValue`, `replicatedState` with its types, and the watch types `WatchHandle`, `NativeWatchHandle`, `WatchCall`, `NativeWatchCall`, and `WatchEnd` with their implementations `Watch` and `NativeWatch`. | Node and browsers |
18
18
  | `@earendil-works/chord/node` | Child host processes: `createHostManager`, `forkDriver`, `childControl`, `processLock`; the facet module loader `nodeLoader`. | Node |
19
- | `@earendil-works/chord/context` | Explicit cancellation and invocation values: `BACKGROUND_CONTEXT`, `withCancel`, `withAbortSignal`, `withoutAbortSignal`, `withContextValue`, `awaitWithContext`. | Node and browsers |
19
+ | `@earendil-works/chord/context` | Explicit cancellation, telemetry, and invocation values: `BACKGROUND_CONTEXT`, `withCancel`, `withAbortSignal`, `withoutAbortSignal`, `withTelemetry`, `traceIn`, `withContextValue`, `awaitWithContext`. | Node and browsers |
20
20
  | `@earendil-works/chord/delta` | The transactional JSON tracker, structural diff, immutable apply, and the wire encoder/decoder for operation batches. | Node and browsers |
21
21
  | `@earendil-works/chord/output` | Bounded output streams and paced progress: `OutputBuffer` (head or tail window of a stream, `OutputLimits`, `OutputSkip`), `boundOutput`, `sanitizeOutput`, `utf8ByteLength`, and `Progress` (adaptive commits of a changing value). | Node and browsers |
22
+ | `@earendil-works/chord/telemetry-sqlite` | `createSqliteTelemetry(db, { retentionMs?, maxQueuedSpans? })`: buffered recording and backend-independent `TelemetryStore` queries. | Any SQLite adapter |
23
+ | `@earendil-works/chord/sqlite` | Portable `SqliteDatabase`, `SqliteExecutor`, and `SqliteValue`, atomic `applySqliteMigrations(database, migrations, { table })`, and `validateSqliteSchemaPrefix`. The metadata table must be a valid, non-reserved SQLite identifier; migration versions start at 1 and are contiguous. | Any SQLite adapter |
24
+ | `@earendil-works/chord/sqlite/node` | `NodeSqliteDatabase`, `openNodeSqliteDatabase`, and `NodeSqliteDatabaseOptions`. | Node |
25
+ | `@earendil-works/chord/sqlite/cloudflare` | `DurableObjectSqliteDatabase` and the structural `DurableObjectSqliteStorage` binding type. | Cloudflare Durable Objects |
22
26
 
23
27
  ## Quick start
24
28
 
25
29
  ```ts
26
- import { Type } from "typebox";
30
+ import { num, obj, str } from "@earendil-works/pi-schema";
27
31
  import { createHost, hostNamed, method, remote } from "@earendil-works/chord";
28
32
 
29
33
  // contract.ts: shared by provider and consumers
30
34
  export const Counter = remote("demo.counter", {
31
35
  version: 1,
32
- input: Type.Object({ name: Type.String() }),
36
+ input: obj({ name: str() }),
33
37
  host: hostNamed("server"), // where its objects live; callers never name a host
34
38
  variants: {
35
39
  default: {
36
- state: { count: Type.Number() },
37
- methods: { increment: method(Type.Object({ by: Type.Number() })) },
40
+ state: { count: num() },
41
+ methods: { increment: method(obj({ by: num() })) },
38
42
  },
39
43
  },
40
44
  });
@@ -42,7 +46,7 @@ export const Counter = remote("demo.counter", {
42
46
  const host = createHost({ name: "server", self: { kind: "server" } });
43
47
 
44
48
  host.serve(Counter, ({ name }, _principal, self) => {
45
- const count = self.state("count", Type.Number(), 0);
49
+ const count = self.state("count", num(), 0);
46
50
  return {
47
51
  variant: "default",
48
52
  count,
@@ -66,6 +70,60 @@ await host.root(async (ctx) => {
66
70
  - [Specification](docs/spec.md): compatibility, lifetime, and reload semantics, plus known limitations and implementation decisions.
67
71
  - [Delta guide](src/delta/README.md): ownership, lifecycle, operation, and replica contracts of `@earendil-works/chord/delta`.
68
72
 
73
+ ## Explicit Context telemetry
74
+
75
+ `Context` always carries a `telemetry: TelemetrySpan`, alongside `abortSignal`. `BACKGROUND_CONTEXT` and `TODO_CONTEXT` use the shared no-op span `NOOP_TELEMETRY_CONTEXT`. Adapters (`TelemetryContext`) belong to hosts and start root spans; adapters are never placed in a `Context`.
76
+
77
+ ```ts
78
+ import { BACKGROUND_CONTEXT, traceIn, withTelemetry } from '@earendil-works/chord/context';
79
+ import { InMemoryTelemetryContext } from '@earendil-works/pi-telemetry';
80
+
81
+ const telemetry = new InMemoryTelemetryContext();
82
+ await telemetry.startSpan({ name: 'app.request' }, async (span) => {
83
+ const context = withTelemetry(span, BACKGROUND_CONTEXT);
84
+ await traceIn(
85
+ { name: 'app.load' },
86
+ async (child) => {
87
+ child.telemetry.addEvent('cache.miss');
88
+ return traceIn({ name: 'app.read' }, (nested) => readAccount(nested), child);
89
+ },
90
+ context,
91
+ );
92
+ });
93
+ ```
94
+
95
+ `withTelemetry(span, context)` derives a new context; it never changes its parent, cancellation, or typed values. `traceIn(options, fn, context)` creates a callback-managed child span, and `fn` receives its derived context. Every context already supports `telemetry.addEvent()` and `telemetry.addLink()`. Values, cancellation, callback results, and rejection identities are preserved. Concurrent calls keep independent parents; there is no ambient current span. `value()`, `ContextKey`, and `withContextValue()` remain supported.
96
+
97
+ These helpers operate on the standalone `Context` API. They do not yet instrument Chord hosts, methods, or network frames.
98
+
99
+ ## SQLite telemetry
100
+
101
+ ```ts
102
+ import { createSqliteTelemetry } from '@earendil-works/chord/telemetry-sqlite';
103
+ import { openNodeSqliteDatabase } from '@earendil-works/chord/sqlite/node';
104
+ import { renderTrace } from '@earendil-works/pi-telemetry/render';
105
+
106
+ const db = await openNodeSqliteDatabase('telemetry.db');
107
+ const telemetry = await createSqliteTelemetry(db);
108
+ try {
109
+ await telemetry.startSpan({ name: 'app.request' }, async (span) => {
110
+ span.addEvent('request.accepted');
111
+ await span.startSpan({ name: 'app.read' }, () => readAccount());
112
+ });
113
+ await telemetry.flush();
114
+ const { traces } = await telemetry.findTraces({ name: 'app.request', limit: 10 });
115
+ for (const trace of traces) console.log(renderTrace(trace.spans));
116
+ } finally {
117
+ try { await telemetry.close(); } finally { await db.close(); }
118
+ }
119
+ ```
120
+
121
+ The adapter is portable over `SqliteDatabase` and owns no connection. Recording performs no SQL. A one-second timer flushes settled spans and completed ten-second metric intervals in one transaction, including retention cleanup. Metrics retain count, sum, minimum, and maximum per name/kind/unit/attribute series, not raw samples, buckets, or exemplars. `close()` stops recording and drains partial metric intervals without waiting for business callbacks or closing the database. Late span completions are ignored.
122
+
123
+ Retention defaults to seven days. `maxQueuedSpans` defaults to 10,000 and counts settled spans awaiting commit, including an in-flight batch. The same limit independently bounds pending metric interval/series pairs. Overflow increments `droppedSpans` or `droppedMeasurements`; the limits bound counts, not bytes or active spans. A write failure stops recording permanently: `flush()` and `close()` reject with the original error without retrying.
124
+
125
+ The adapter implements `TelemetryStore`: `findTraces()`, `getTrace()`, and `findMetrics()` read committed rows, including after adapter close while the database remains open. See [stored telemetry](../telemetry/README.md#stored-telemetry) for filters, pagination, and cross-process trace assembly. Schema tables are `telemetry_spans`, `telemetry_metrics`, and `telemetry_schema`.
126
+
69
127
  ## Tracking JSON deltas
70
128
 
71
129
  Import the standalone transactional tracker from `@earendil-works/chord/delta`:
@@ -98,8 +156,7 @@ their containers with the provider; mutating a consumed value violates the contr
98
156
  and can corrupt authority. Clone or serialize at any mutable trust boundary.
99
157
 
100
158
  Replicated state provides the same model through a callback. `replicatedState` is a
101
- standalone observable value, independent of hosts; Durable uses it for document,
102
- view, and task-graph states:
159
+ standalone observable value, independent of hosts:
103
160
 
104
161
  ```ts
105
162
  import { replicatedState } from "@earendil-works/chord";
@@ -146,3 +203,65 @@ running callback.
146
203
 
147
204
  Cells of Chord objects and their remote readables have their own subscription
148
205
  model; see [State](docs/guide.md#state) in the usage guide.
206
+
207
+ ### Watches
208
+
209
+ `WatchHandle<T>` is the one watch interface, implemented by watch sources such as
210
+ Durable's documents, conversation views, and task graph. `watch.value` is the value
211
+ at acquisition until `start(listener)` installs the sole asynchronous listener; each
212
+ later change arrives as `(call, context)`, one call at a time, with
213
+ `call: WatchCall<T>` tagged by `kind` (plain data; the context is the second
214
+ argument):
215
+
216
+ - `{ kind: "value", value, ops, retired }`: the new value, and `watch.value`
217
+ advances to it;
218
+ - `{ kind: "failed", error }`: the source cannot compute its value now. The watch
219
+ stays open and `watch.value` keeps the last value; the next value arrives as
220
+ `[["r", value]]`.
221
+
222
+ ```ts
223
+ watch.start(async (call) => {
224
+ if (call.kind === "failed") return showError(call.error);
225
+ render(call.value);
226
+ });
227
+ ```
228
+
229
+ Changes made while the listener runs (or before `start`) arrive in one call: the
230
+ newest value, the ops of all of them folded by Delta's `PendingOps`, and the newest
231
+ change's context. Past 10,000 pending ops after folding the call gets one root
232
+ replacement `[["r", newest]]` instead. A failure drops the pending values and waits
233
+ as one `failed` call (the newest failure); a value after it replaces it, as one
234
+ `[["r", value]]` call.
235
+
236
+ `retired` says the document the watch follows was retired since the previous value
237
+ call. It does not end the watch: the call carries what the address shows after the
238
+ retirement (the source decides; a Durable document keeps the last value the watch
239
+ was given, with no ops), and a document created there later arrives as
240
+ `[["r", value]]`, folded with what is pending, so one call can report a retirement
241
+ and carry the new value.
242
+
243
+ A watch ends only for good. `stop()` is idempotent, drops pending frames, and
244
+ neither aborts nor awaits a running call; it and `closed` give the `WatchEnd`,
245
+ tagged by `kind`:
246
+
247
+ - `stopped`: `stop()` was called;
248
+ - `aborted`: the context the watch was acquired with was aborted;
249
+ - `ended`: the source closed (its owner ended or closed);
250
+ - `listener_error` with `error`: the listener threw or rejected;
251
+ - `failed` with `error`: the source failed for good.
252
+
253
+ An ended watch drops every reference into its source, so a stopped watch that is
254
+ still referenced keeps only its last value alive.
255
+
256
+ Sources implement handles with `Watch<T>`, fed through `advance(call, context)`
257
+ (a `WatchCall`: a value with `retired` set for a retirement, or a failure),
258
+ `fail(error, context)` (a failure the source may recover from), `end(end)` (a
259
+ `WatchEnd`, at once, dropping what is pending), `endAfterDelivery()` (take no more
260
+ frames, deliver what is pending, then end `ended` once the last call returned; the
261
+ source's `end()` still ends it first), and `observeAbort(signal)`.
262
+ `NativeWatch<T>` implements `NativeWatchHandle<T>`, the same lifecycle for
263
+ in-process values: the listener gets a `NativeWatchCall<T>`
264
+ (`{ kind: "value", value }` without ops, or `{ kind: "failed", error }`), one call
265
+ per value in order; past 100 pending values they collapse to one, the value of the
266
+ optional `replace()` or the newest. A failure drops the pending values; values
267
+ after it are delivered in order.
package/dist/cell.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { TSchema } from "typebox";
1
+ import type { Schema } from "@earendil-works/pi-schema";
2
2
  import { type Draft } from "./delta/index.ts";
3
3
  import { ChordError } from "./errors.ts";
4
4
  import type { Ctx, Readable, StateEvent } from "./types.ts";
@@ -40,7 +40,7 @@ export declare abstract class Source<T> implements Readable<T> {
40
40
  readonly seq: number;
41
41
  readonly dependents: Set<Derived<unknown>>;
42
42
  /** Schemas of remote state members currently exposing this source (checked per write in dev mode). */
43
- schemas: readonly TSchema[];
43
+ schemas: readonly Schema[];
44
44
  protected readonly options: SourceOptions;
45
45
  protected readonly fanout: Fanout<T>;
46
46
  constructor(key: string, options: SourceOptions);
@@ -49,23 +49,23 @@ export declare abstract class Source<T> implements Readable<T> {
49
49
  events(listener: (event: StateEvent<T>) => void): () => void;
50
50
  /** Per-write validation, dev mode only. */
51
51
  validate(value: unknown): void;
52
- protected ownSchemas(): readonly TSchema[];
52
+ protected ownSchemas(): readonly Schema[];
53
53
  }
54
54
  /** A state cell holding any JSON value, validated against its schema at creation and (dev mode) on writes. */
55
55
  export declare class Cell<T> extends Source<T> {
56
56
  #private;
57
57
  /** Replaced at a reload commit that changes the schema (state-version bump). */
58
- schema: TSchema;
58
+ schema: Schema;
59
59
  /**
60
60
  * `initial` is always validated against `schema`; ownership moves to the cell. Without `initial`, the cell has no
61
61
  * value until `initialize` (a cell declared with `init`, filled before its object goes live).
62
62
  */
63
- constructor(key: string, schema: TSchema, initial: {
63
+ constructor(key: string, schema: Schema, initial: {
64
64
  readonly value: T;
65
65
  } | undefined, guard: WriteGuard, options: SourceOptions);
66
66
  /** Sets the first value of a cell declared with `init` (validated; ownership moves to the cell). Publishes nothing. */
67
67
  initialize(value: T): void;
68
- protected ownSchemas(): readonly TSchema[];
68
+ protected ownSchemas(): readonly Schema[];
69
69
  get value(): T;
70
70
  /**
71
71
  * Mutates a draft (only mutated paths are published), or returns a new value (`n => n + 1`). A returned value is
@@ -87,7 +87,7 @@ export declare class Cell<T> extends Source<T> {
87
87
  * Installs a migrated value and its schema (reload commit). The caller validated the value and the derivations
88
88
  * over it against every schema that will apply, so nothing is checked here. Subscribers receive a reset.
89
89
  */
90
- reset(value: T, schema: TSchema): void;
90
+ reset(value: T, schema: Schema): void;
91
91
  }
92
92
  export type Sources = readonly Readable<unknown>[];
93
93
  export type SourceValues<S extends Sources> = {
@@ -1 +1 @@
1
- {"version":3,"file":"cell.d.ts","sourceRoot":"","sources":["../src/cell.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,KAAK,KAAK,EAA+D,MAAM,kBAAkB,CAAC;AAC3G,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C;AAED,2EAA2E;AAC3E,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;AAI5C,gGAAgG;AAChG,cAAM,MAAM,CAAC,CAAC;;IAKb,YAAY,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,EAE3C;IAED,SAAS,CAAC,QAAQ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M,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;IACF,CAAC;IAED,OAAO,CAAC,IAAO;QACd,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,MAAM,GAAG,GACR,MAAM,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS;YACzC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,IAAI,CAAc,CAAC,CAAC;YACtC,CAAC,CAAC,aAAa,CAAC,MAAmB,EAAE,IAAiB,CAAC,CAAC;QAC1D,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACzE,CAAC;CACD;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA6C,EAAE,CAAC,KAAK,YAAY,MAAM,CAAC;AAE/G,8DAA8D;AAC9D,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAc,EAAE,CAAC,IAAI,UAAU,CAAC,WAAW,EAAE,GAAG,IAAI,eAAe,CAAC,CAAC","sourcesContent":["import type { TSchema } from \"typebox\";\nimport { type Draft, diffRevisions, type JsonValue, type Op, type Tracker, track } from \"./delta/index.ts\";\nimport { ChordError } from \"./errors.ts\";\nimport { enqueue, holdPublications } from \"./publish.ts\";\nimport { assertValid } from \"./schema.ts\";\nimport type { Ctx, Readable, StateEvent } from \"./types.ts\";\n\nexport interface SourceOptions {\n\treadonly dev: boolean;\n\treadonly report: (error: unknown) => void;\n}\n\n/** Checks that `ctx` may write an object's cells now; throws otherwise. */\nexport type WriteGuard = (ctx: Ctx) => void;\n\nlet sequence = 0;\n\n/** Fans out values and delta events; listener errors are reported, not thrown to the writer. */\nclass Fanout<T> {\n\treadonly #values = new Set<(value: T) => void>();\n\treadonly #events = new Set<(event: StateEvent<T>) => void>();\n\treadonly #report: (error: unknown) => void;\n\n\tconstructor(report: (error: unknown) => void) {\n\t\tthis.#report = report;\n\t}\n\n\tsubscribe(listener: (value: T) => void, current: T): () => void {\n\t\tthis.#values.add(listener);\n\t\tthis.#call(listener, current);\n\t\treturn () => this.#values.delete(listener);\n\t}\n\n\tevents(listener: (event: StateEvent<T>) => void, current: T): () => void {\n\t\tthis.#events.add(listener);\n\t\tthis.#call(listener, { type: \"snap\", value: current });\n\t\treturn () => this.#events.delete(listener);\n\t}\n\n\t/**\n\t * Queues delivery to the listeners subscribed now. A listener that subscribes later already got this revision in\n\t * its snapshot; one that unsubscribes before delivery is skipped.\n\t */\n\temit(event: StateEvent<T>): void {\n\t\tconst events = [...this.#events];\n\t\tconst values = [...this.#values];\n\t\tenqueue(() => {\n\t\t\tfor (const listener of events) if (this.#events.has(listener)) this.#call(listener, event);\n\t\t\tfor (const listener of values) if (this.#values.has(listener)) this.#call(listener, event.value);\n\t\t});\n\t}\n\n\t#call<V>(listener: (value: V) => void, value: V): void {\n\t\ttry {\n\t\t\tlistener(value);\n\t\t} catch (error) {\n\t\t\tthis.#report(error);\n\t\t}\n\t}\n}\n\n/**\n * Whether a state source has its value (entry 8): a remote reference's member before its first snapshot has none, and\n * neither has anything derived from or forwarding it. Sources without this symbol always have their value.\n */\nexport const HYDRATION: unique symbol = Symbol(\"chord.hydration\");\n\nexport interface Hydration {\n\treadonly hydrated: boolean;\n\t/** Resolves once hydrated; rejects if the source ends first. */\n\twhenHydrated(): Promise<void>;\n}\n\n/** The hydration of a readable, or undefined for a source that always has its value. */\nexport function hydrationOf(value: unknown): Hydration | undefined {\n\tif (value === null || typeof value !== \"object\") return undefined;\n\treturn (value as { readonly [HYDRATION]?: Hydration })[HYDRATION];\n}\n\n/** The hydrations of `sources` that are not hydrated yet. */\nexport const unhydrated = (sources: Iterable<unknown>): Hydration[] =>\n\t[...sources].map(hydrationOf).filter((hydration): hydration is Hydration => hydration?.hydrated === false);\n\n/** An object-owned state source (cell or derivation). Writes recompute dependents atomically. */\nexport abstract class Source<T> implements Readable<T> {\n\treadonly key: string;\n\treadonly seq = ++sequence;\n\treadonly dependents = new Set<Derived<unknown>>();\n\t/** Schemas of remote state members currently exposing this source (checked per write in dev mode). */\n\tschemas: readonly TSchema[] = [];\n\tprotected readonly options: SourceOptions;\n\tprotected readonly fanout: Fanout<T>;\n\n\tconstructor(key: string, options: SourceOptions) {\n\t\tthis.key = key;\n\t\tthis.options = options;\n\t\tthis.fanout = new Fanout(options.report);\n\t}\n\n\tabstract get value(): T;\n\n\tsubscribe(listener: (value: T) => void): () => void {\n\t\treturn this.fanout.subscribe(listener, this.value);\n\t}\n\n\tevents(listener: (event: StateEvent<T>) => void): () => void {\n\t\treturn this.fanout.events(listener, this.value);\n\t}\n\n\t/** Per-write validation, dev mode only. */\n\tvalidate(value: unknown): void {\n\t\tif (!this.options.dev) return;\n\t\tfor (const schema of this.ownSchemas()) assertValid(\"state\", `state ${this.key}`, schema, value);\n\t\tfor (const schema of this.schemas) assertValid(\"state\", `state ${this.key}`, schema, value);\n\t}\n\n\tprotected ownSchemas(): readonly TSchema[] {\n\t\treturn [];\n\t}\n}\n\n/** The tracker tracks containers, so a cell tracks `{ v: value }` and strips the box from published ops. */\ninterface Box<T> {\n\tv: T;\n}\n\nfunction unbox(ops: readonly Op[], value: unknown): Op[] {\n\tconst result: Op[] = [];\n\tfor (const op of ops) {\n\t\tif (op[0] === \"r\" || op[1].length === 0) return [[\"r\", value as JsonValue]];\n\t\tconst path = op[1].slice(1);\n\t\tswitch (op[0]) {\n\t\t\tcase \"p\":\n\t\t\t\tresult.push([\"p\", path, op[2], op[3], op[4]]);\n\t\t\t\tbreak;\n\t\t\tcase \"m\":\n\t\t\t\tresult.push([\"m\", path, op[2]]);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\t// s/d/a/t on the value itself replace it.\n\t\t\t\tif (path.length === 0) return [[\"r\", value as JsonValue]];\n\t\t\t\tif (op[0] === \"d\") result.push([\"d\", path as [string | number, ...(string | number)[]]]);\n\t\t\t\telse result.push([op[0], path as [string | number, ...(string | number)[]], op[2]] as Op);\n\t\t}\n\t}\n\treturn result;\n}\n\n/** A state cell holding any JSON value, validated against its schema at creation and (dev mode) on writes. */\nexport class Cell<T> extends Source<T> {\n\t/** Replaced at a reload commit that changes the schema (state-version bump). */\n\tschema: TSchema;\n\t#tracker: Tracker<Box<T>>;\n\treadonly #guard: WriteGuard;\n\t/** False until `initialize` for a cell declared with `init`: reads and writes throw `not_ready`. */\n\t#initialized: boolean;\n\n\t/**\n\t * `initial` is always validated against `schema`; ownership moves to the cell. Without `initial`, the cell has no\n\t * value until `initialize` (a cell declared with `init`, filled before its object goes live).\n\t */\n\tconstructor(\n\t\tkey: string,\n\t\tschema: TSchema,\n\t\tinitial: { readonly value: T } | undefined,\n\t\tguard: WriteGuard,\n\t\toptions: SourceOptions,\n\t) {\n\t\tsuper(key, options);\n\t\tif (initial !== undefined) assertValid(\"state\", `initial value of state ${key}`, schema, initial.value);\n\t\tthis.schema = schema;\n\t\tthis.#tracker = track<Box<T>>({ v: (initial?.value ?? null) as T });\n\t\tthis.#guard = guard;\n\t\tthis.#initialized = initial !== undefined;\n\t}\n\n\t/** Sets the first value of a cell declared with `init` (validated; ownership moves to the cell). Publishes nothing. */\n\tinitialize(value: T): void {\n\t\tif (this.#initialized) throw new Error(`state ${this.key} is already initialized`);\n\t\tassertValid(\"state\", `initial value of state ${this.key}`, this.schema, value);\n\t\tthis.#tracker = track<Box<T>>({ v: value });\n\t\tthis.#initialized = true;\n\t}\n\n\tprotected override ownSchemas(): readonly TSchema[] {\n\t\treturn [this.schema];\n\t}\n\n\tget value(): T {\n\t\tif (!this.#initialized) throw notReady(`state ${this.key} (its init has not run)`);\n\t\treturn this.#tracker.value.v;\n\t}\n\n\t/**\n\t * Mutates a draft (only mutated paths are published), or returns a new value (`n => n + 1`). A returned value is\n\t * always validated against the schema. The draft is unusable after `fn` returns.\n\t */\n\tchange(ctx: Ctx, fn: (draft: Draft<T>) => T): void;\n\tchange(ctx: Ctx, fn: (draft: Draft<T>) => void): void;\n\tchange(ctx: Ctx, fn: (draft: Draft<T>) => unknown): void {\n\t\tthis.#guard(ctx);\n\t\tif (!this.#initialized) throw notReady(`state ${this.key} (its init has not run)`);\n\t\tconst change = this.#tracker.beginChange();\n\t\tlet prepared: ReturnType<typeof change.prepare>;\n\t\ttry {\n\t\t\tconst draft = change.state as Draft<Box<T>>;\n\t\t\tconst result: unknown = fn(draft.v as Draft<T>);\n\t\t\tif (result instanceof Promise) throw new TypeError(\"cell.change callbacks must be synchronous\");\n\t\t\tif (result !== undefined) {\n\t\t\t\tif (result !== draft.v) assertValid(\"state\", `state ${this.key}`, this.schema, result);\n\t\t\t\tdraft.v = result as Draft<T>;\n\t\t\t}\n\t\t\tprepared = change.prepare();\n\t\t} catch (error) {\n\t\t\tchange.abort();\n\t\t\tthrow error;\n\t\t}\n\t\tthis.#publish(prepared, \"ops\");\n\t}\n\n\t/**\n\t * Replaces the whole value. Ownership of `value` moves to the cell: never mutate it afterwards.\n\t *\n\t * Subscribers get a structural diff (`diffRevisions`) when `diff` is true, or by default when the new value shares\n\t * containers with the old one (a new immutable revision of the same state, e.g. mirrored from another store);\n\t * otherwise a single `r` op. The resulting value is the same either way; only the ops differ.\n\t */\n\treplace(ctx: Ctx, value: T, options: { readonly diff?: boolean } = {}): void {\n\t\tthis.#guard(ctx);\n\t\tif (!this.#initialized) throw notReady(`state ${this.key} (its init has not run)`);\n\t\tconst before = this.value;\n\t\tconst diff = options.diff ?? sharesStructure(before, value);\n\t\tconst ops = diff ? diffRevisions(before as JsonValue, value as JsonValue) : undefined;\n\t\tthis.#publish(this.#tracker.prepareReplace({ v: value }), \"ops\", true, ops);\n\t}\n\n\t/**\n\t * Installs a migrated value and its schema (reload commit). The caller validated the value and the derivations\n\t * over it against every schema that will apply, so nothing is checked here. Subscribers receive a reset.\n\t */\n\treset(value: T, schema: TSchema): void {\n\t\tthis.schema = schema;\n\t\tthis.#publish(this.#tracker.prepareReplace({ v: value }), \"reset\", false);\n\t}\n\n\t/** Adopts this revision and every derived one, then queues all notifications (cell first, then derivations). */\n\t#publish(\n\t\tprepared: ReturnType<Tracker<Box<T>>[\"prepareReplace\"]>,\n\t\ttype: \"ops\" | \"reset\",\n\t\tvalidate = true,\n\t\tops?: readonly Op[],\n\t): void {\n\t\tif (prepared.ops.length === 0 && type === \"ops\") {\n\t\t\tthis.#tracker.adopt(prepared);\n\t\t\treturn;\n\t\t}\n\t\tconst value = prepared.value.v;\n\t\tlet candidates: Map<Derived<unknown>, unknown>;\n\t\ttry {\n\t\t\tif (validate) this.validate(value);\n\t\t\tcandidates = computeDependents(this as Source<unknown>, value, validate);\n\t\t} catch (error) {\n\t\t\tprepared.abort();\n\t\t\tthrow error;\n\t\t}\n\t\tholdPublications(() => {\n\t\t\tthis.#tracker.adopt(prepared);\n\t\t\tconst published = ops !== undefined && ops.length > 0 ? ops : unbox(prepared.ops, value);\n\t\t\tthis.fanout.emit(type === \"reset\" ? { type, value } : { type, ops: published, value });\n\t\t\tfor (const [derived, next] of candidates) derived.install(next);\n\t\t});\n\t}\n}\n\n/** True if `b` reuses at least one container of `a` at the same key: a new revision of the same state. */\nfunction sharesStructure(a: unknown, b: unknown): boolean {\n\tif (a === null || b === null || typeof a !== \"object\" || typeof b !== \"object\" || a === b) return false;\n\tif (Array.isArray(a) !== Array.isArray(b)) return false;\n\tfor (const [key, child] of Object.entries(b)) {\n\t\tif (child !== null && typeof child === \"object\" && (a as Record<string, unknown>)[key] === child) return true;\n\t}\n\treturn false;\n}\n\n/** Recomputes every transitive dependent of `changed` against candidate values and validates them. */\nfunction computeDependents(changed: Source<unknown>, value: unknown, validate = true): Map<Derived<unknown>, unknown> {\n\tconst pending = new Set<Derived<unknown>>();\n\tconst visit = (source: Source<unknown>): void => {\n\t\tfor (const derived of source.dependents) {\n\t\t\tif (pending.has(derived)) continue;\n\t\t\tpending.add(derived);\n\t\t\tvisit(derived);\n\t\t}\n\t};\n\tvisit(changed);\n\tconst values = new Map<Readable<unknown>, unknown>([[changed, value]]);\n\tconst result = new Map<Derived<unknown>, unknown>();\n\tfor (const derived of [...pending].sort((a, b) => a.seq - b.seq)) {\n\t\tconst next = derived.compute((source) => (values.has(source) ? values.get(source) : source.value));\n\t\tif (validate) derived.validate(next);\n\t\tvalues.set(derived, next);\n\t\tresult.set(derived, next);\n\t}\n\treturn result;\n}\n\nexport type Sources = readonly Readable<unknown>[];\nexport type SourceValues<S extends Sources> = { [K in keyof S]: S[K] extends Readable<infer T> ? T : never };\n\nconst isReadable = (value: unknown): value is Readable<unknown> =>\n\tvalue !== null &&\n\ttypeof value === \"object\" &&\n\ttypeof (value as Readable<unknown>).subscribe === \"function\" &&\n\t\"value\" in value;\n\n/**\n * A synchronous derivation. Sources are object cells/derivations (recomputed atomically with the write) or other\n * readables such as reference state members (recomputed when they publish). Subscribers receive diffs.\n */\nexport class Derived<T> extends Source<T> {\n\treadonly sources: readonly Readable<unknown>[];\n\treadonly #fn: (...values: never[]) => unknown;\n\t#value: T;\n\t#external: (() => void)[] = [];\n\n\tconstructor(key: string, sources: Sources, fn: (...values: never[]) => unknown, options: SourceOptions) {\n\t\tsuper(key, options);\n\t\tthis.sources = sources.map((source) => {\n\t\t\tif (!isReadable(source)) throw new TypeError(`derive ${key}: sources must be readables`);\n\t\t\treturn source;\n\t\t});\n\t\tthis.#fn = fn;\n\t\tthis.#value = undefined as T;\n\t}\n\n\tget value(): T {\n\t\treturn this.#value;\n\t}\n\n\t/** Hydrated once every source is (a derivation over a remote member waits for its snapshot). */\n\tget [HYDRATION](): Hydration | undefined {\n\t\tconst pending = unhydrated(this.sources);\n\t\tif (pending.length === 0) return undefined;\n\t\treturn {\n\t\t\thydrated: false,\n\t\t\twhenHydrated: () => Promise.all(pending.map((hydration) => hydration.whenHydrated())).then(() => {}),\n\t\t};\n\t}\n\n\t/**\n\t * Computes the first value (or takes it from `precomputed`, a reload's validated dry run) and starts following\n\t * the sources (at install, never inside a factory).\n\t */\n\tattach(precomputed?: ReadonlyMap<unknown, unknown>): void {\n\t\tthis.#value = precomputed?.has(this) ? (precomputed.get(this) as T) : this.compute((source) => source.value);\n\t\tfor (const source of this.sources) {\n\t\t\tif (source instanceof Source) source.dependents.add(this as Derived<unknown>);\n\t\t\telse this.#external.push(source.subscribe(() => this.refresh()));\n\t\t}\n\t}\n\n\tdetach(): void {\n\t\tfor (const source of this.sources)\n\t\t\tif (source instanceof Source) source.dependents.delete(this as Derived<unknown>);\n\t\tfor (const unsubscribe of this.#external.splice(0)) unsubscribe();\n\t}\n\n\tcompute(read: (source: Readable<unknown>) => unknown): T {\n\t\tconst result: unknown = this.#fn(...(this.sources.map(read) as never[]));\n\t\tif (result instanceof Promise) throw new TypeError(`derive ${this.key}: fn must be synchronous`);\n\t\treturn result as T;\n\t}\n\n\t/** Recomputes and republishes, including dependents. Errors are reported (the source write already happened). */\n\trefresh(): void {\n\t\ttry {\n\t\t\tconst next = this.compute((source) => source.value);\n\t\t\tconst dependents = computeDependents(this as Derived<unknown>, next);\n\t\t\tholdPublications(() => {\n\t\t\t\tthis.install(next);\n\t\t\t\tfor (const [derived, value] of dependents) derived.install(value);\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthis.options.report(error);\n\t\t}\n\t}\n\n\tinstall(next: T): void {\n\t\tconst before = this.#value;\n\t\tthis.#value = next;\n\t\tconst ops: Op[] =\n\t\t\tbefore === undefined || next === undefined\n\t\t\t\t? [[\"r\", (next ?? null) as JsonValue]]\n\t\t\t\t: diffRevisions(before as JsonValue, next as JsonValue);\n\t\tif (ops.length > 0) this.fanout.emit({ type: \"ops\", ops, value: next });\n\t}\n}\n\nexport const isSource = (value: unknown): value is Cell<unknown> | Derived<unknown> => value instanceof Source;\n\n/** Thrown by placeholders used before activation finished. */\nexport const notReady = (what: string): ChordError => new ChordError(\"not_ready\", `${what} is not ready`);\n"]}
1
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\nimport { type Draft, diffRevisions, type JsonValue, type Op, type Tracker, track } from \"./delta/index.ts\";\nimport { ChordError } from \"./errors.ts\";\nimport { enqueue, holdPublications } from \"./publish.ts\";\nimport { assertValid } from \"./schema.ts\";\nimport type { Ctx, Readable, StateEvent } from \"./types.ts\";\n\nexport interface SourceOptions {\n\treadonly dev: boolean;\n\treadonly report: (error: unknown) => void;\n}\n\n/** Checks that `ctx` may write an object's cells now; throws otherwise. */\nexport type WriteGuard = (ctx: Ctx) => void;\n\nlet sequence = 0;\n\n/** Fans out values and delta events; listener errors are reported, not thrown to the writer. */\nclass Fanout<T> {\n\treadonly #values = new Set<(value: T) => void>();\n\treadonly #events = new Set<(event: StateEvent<T>) => void>();\n\treadonly #report: (error: unknown) => void;\n\n\tconstructor(report: (error: unknown) => void) {\n\t\tthis.#report = report;\n\t}\n\n\tsubscribe(listener: (value: T) => void, current: T): () => void {\n\t\tthis.#values.add(listener);\n\t\tthis.#call(listener, current);\n\t\treturn () => this.#values.delete(listener);\n\t}\n\n\tevents(listener: (event: StateEvent<T>) => void, current: T): () => void {\n\t\tthis.#events.add(listener);\n\t\tthis.#call(listener, { type: \"snap\", value: current });\n\t\treturn () => this.#events.delete(listener);\n\t}\n\n\t/**\n\t * Queues delivery to the listeners subscribed now. A listener that subscribes later already got this revision in\n\t * its snapshot; one that unsubscribes before delivery is skipped.\n\t */\n\temit(event: StateEvent<T>): void {\n\t\tconst events = [...this.#events];\n\t\tconst values = [...this.#values];\n\t\tenqueue(() => {\n\t\t\tfor (const listener of events) if (this.#events.has(listener)) this.#call(listener, event);\n\t\t\tfor (const listener of values) if (this.#values.has(listener)) this.#call(listener, event.value);\n\t\t});\n\t}\n\n\t#call<V>(listener: (value: V) => void, value: V): void {\n\t\ttry {\n\t\t\tlistener(value);\n\t\t} catch (error) {\n\t\t\tthis.#report(error);\n\t\t}\n\t}\n}\n\n/**\n * Whether a state source has its value (entry 8): a remote reference's member before its first snapshot has none, and\n * neither has anything derived from or forwarding it. Sources without this symbol always have their value.\n */\nexport const HYDRATION: unique symbol = Symbol(\"chord.hydration\");\n\nexport interface Hydration {\n\treadonly hydrated: boolean;\n\t/** Resolves once hydrated; rejects if the source ends first. */\n\twhenHydrated(): Promise<void>;\n}\n\n/** The hydration of a readable, or undefined for a source that always has its value. */\nexport function hydrationOf(value: unknown): Hydration | undefined {\n\tif (value === null || typeof value !== \"object\") return undefined;\n\treturn (value as { readonly [HYDRATION]?: Hydration })[HYDRATION];\n}\n\n/** The hydrations of `sources` that are not hydrated yet. */\nexport const unhydrated = (sources: Iterable<unknown>): Hydration[] =>\n\t[...sources].map(hydrationOf).filter((hydration): hydration is Hydration => hydration?.hydrated === false);\n\n/** An object-owned state source (cell or derivation). Writes recompute dependents atomically. */\nexport abstract class Source<T> implements Readable<T> {\n\treadonly key: string;\n\treadonly seq = ++sequence;\n\treadonly dependents = new Set<Derived<unknown>>();\n\t/** Schemas of remote state members currently exposing this source (checked per write in dev mode). */\n\tschemas: readonly Schema[] = [];\n\tprotected readonly options: SourceOptions;\n\tprotected readonly fanout: Fanout<T>;\n\n\tconstructor(key: string, options: SourceOptions) {\n\t\tthis.key = key;\n\t\tthis.options = options;\n\t\tthis.fanout = new Fanout(options.report);\n\t}\n\n\tabstract get value(): T;\n\n\tsubscribe(listener: (value: T) => void): () => void {\n\t\treturn this.fanout.subscribe(listener, this.value);\n\t}\n\n\tevents(listener: (event: StateEvent<T>) => void): () => void {\n\t\treturn this.fanout.events(listener, this.value);\n\t}\n\n\t/** Per-write validation, dev mode only. */\n\tvalidate(value: unknown): void {\n\t\tif (!this.options.dev) return;\n\t\tfor (const schema of this.ownSchemas()) assertValid(\"state\", `state ${this.key}`, schema, value);\n\t\tfor (const schema of this.schemas) assertValid(\"state\", `state ${this.key}`, schema, value);\n\t}\n\n\tprotected ownSchemas(): readonly Schema[] {\n\t\treturn [];\n\t}\n}\n\n/** The tracker tracks containers, so a cell tracks `{ v: value }` and strips the box from published ops. */\ninterface Box<T> {\n\tv: T;\n}\n\nfunction unbox(ops: readonly Op[], value: unknown): Op[] {\n\tconst result: Op[] = [];\n\tfor (const op of ops) {\n\t\tif (op[0] === \"r\" || op[1].length === 0) return [[\"r\", value as JsonValue]];\n\t\tconst path = op[1].slice(1);\n\t\tswitch (op[0]) {\n\t\t\tcase \"p\":\n\t\t\t\tresult.push([\"p\", path, op[2], op[3], op[4]]);\n\t\t\t\tbreak;\n\t\t\tcase \"m\":\n\t\t\t\tresult.push([\"m\", path, op[2]]);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\t// s/d/a/t on the value itself replace it.\n\t\t\t\tif (path.length === 0) return [[\"r\", value as JsonValue]];\n\t\t\t\tif (op[0] === \"d\") result.push([\"d\", path as [string | number, ...(string | number)[]]]);\n\t\t\t\telse result.push([op[0], path as [string | number, ...(string | number)[]], op[2]] as Op);\n\t\t}\n\t}\n\treturn result;\n}\n\n/** A state cell holding any JSON value, validated against its schema at creation and (dev mode) on writes. */\nexport class Cell<T> extends Source<T> {\n\t/** Replaced at a reload commit that changes the schema (state-version bump). */\n\tschema: Schema;\n\t#tracker: Tracker<Box<T>>;\n\treadonly #guard: WriteGuard;\n\t/** False until `initialize` for a cell declared with `init`: reads and writes throw `not_ready`. */\n\t#initialized: boolean;\n\n\t/**\n\t * `initial` is always validated against `schema`; ownership moves to the cell. Without `initial`, the cell has no\n\t * value until `initialize` (a cell declared with `init`, filled before its object goes live).\n\t */\n\tconstructor(\n\t\tkey: string,\n\t\tschema: Schema,\n\t\tinitial: { readonly value: T } | undefined,\n\t\tguard: WriteGuard,\n\t\toptions: SourceOptions,\n\t) {\n\t\tsuper(key, options);\n\t\tif (initial !== undefined) assertValid(\"state\", `initial value of state ${key}`, schema, initial.value);\n\t\tthis.schema = schema;\n\t\tthis.#tracker = track<Box<T>>({ v: (initial?.value ?? null) as T });\n\t\tthis.#guard = guard;\n\t\tthis.#initialized = initial !== undefined;\n\t}\n\n\t/** Sets the first value of a cell declared with `init` (validated; ownership moves to the cell). Publishes nothing. */\n\tinitialize(value: T): void {\n\t\tif (this.#initialized) throw new Error(`state ${this.key} is already initialized`);\n\t\tassertValid(\"state\", `initial value of state ${this.key}`, this.schema, value);\n\t\tthis.#tracker = track<Box<T>>({ v: value });\n\t\tthis.#initialized = true;\n\t}\n\n\tprotected override ownSchemas(): readonly Schema[] {\n\t\treturn [this.schema];\n\t}\n\n\tget value(): T {\n\t\tif (!this.#initialized) throw notReady(`state ${this.key} (its init has not run)`);\n\t\treturn this.#tracker.value.v;\n\t}\n\n\t/**\n\t * Mutates a draft (only mutated paths are published), or returns a new value (`n => n + 1`). A returned value is\n\t * always validated against the schema. The draft is unusable after `fn` returns.\n\t */\n\tchange(ctx: Ctx, fn: (draft: Draft<T>) => T): void;\n\tchange(ctx: Ctx, fn: (draft: Draft<T>) => void): void;\n\tchange(ctx: Ctx, fn: (draft: Draft<T>) => unknown): void {\n\t\tthis.#guard(ctx);\n\t\tif (!this.#initialized) throw notReady(`state ${this.key} (its init has not run)`);\n\t\tconst change = this.#tracker.beginChange();\n\t\tlet prepared: ReturnType<typeof change.prepare>;\n\t\ttry {\n\t\t\tconst draft = change.state as Draft<Box<T>>;\n\t\t\tconst result: unknown = fn(draft.v as Draft<T>);\n\t\t\tif (result instanceof Promise) throw new TypeError(\"cell.change callbacks must be synchronous\");\n\t\t\tif (result !== undefined) {\n\t\t\t\tif (result !== draft.v) assertValid(\"state\", `state ${this.key}`, this.schema, result);\n\t\t\t\tdraft.v = result as Draft<T>;\n\t\t\t}\n\t\t\tprepared = change.prepare();\n\t\t} catch (error) {\n\t\t\tchange.abort();\n\t\t\tthrow error;\n\t\t}\n\t\tthis.#publish(prepared, \"ops\");\n\t}\n\n\t/**\n\t * Replaces the whole value. Ownership of `value` moves to the cell: never mutate it afterwards.\n\t *\n\t * Subscribers get a structural diff (`diffRevisions`) when `diff` is true, or by default when the new value shares\n\t * containers with the old one (a new immutable revision of the same state, e.g. mirrored from another store);\n\t * otherwise a single `r` op. The resulting value is the same either way; only the ops differ.\n\t */\n\treplace(ctx: Ctx, value: T, options: { readonly diff?: boolean } = {}): void {\n\t\tthis.#guard(ctx);\n\t\tif (!this.#initialized) throw notReady(`state ${this.key} (its init has not run)`);\n\t\tconst before = this.value;\n\t\tconst diff = options.diff ?? sharesStructure(before, value);\n\t\tconst ops = diff ? diffRevisions(before as JsonValue, value as JsonValue) : undefined;\n\t\tthis.#publish(this.#tracker.prepareReplace({ v: value }), \"ops\", true, ops);\n\t}\n\n\t/**\n\t * Installs a migrated value and its schema (reload commit). The caller validated the value and the derivations\n\t * over it against every schema that will apply, so nothing is checked here. Subscribers receive a reset.\n\t */\n\treset(value: T, schema: Schema): void {\n\t\tthis.schema = schema;\n\t\tthis.#publish(this.#tracker.prepareReplace({ v: value }), \"reset\", false);\n\t}\n\n\t/** Adopts this revision and every derived one, then queues all notifications (cell first, then derivations). */\n\t#publish(\n\t\tprepared: ReturnType<Tracker<Box<T>>[\"prepareReplace\"]>,\n\t\ttype: \"ops\" | \"reset\",\n\t\tvalidate = true,\n\t\tops?: readonly Op[],\n\t): void {\n\t\tif (prepared.ops.length === 0 && type === \"ops\") {\n\t\t\tthis.#tracker.adopt(prepared);\n\t\t\treturn;\n\t\t}\n\t\tconst value = prepared.value.v;\n\t\tlet candidates: Map<Derived<unknown>, unknown>;\n\t\ttry {\n\t\t\tif (validate) this.validate(value);\n\t\t\tcandidates = computeDependents(this as Source<unknown>, value, validate);\n\t\t} catch (error) {\n\t\t\tprepared.abort();\n\t\t\tthrow error;\n\t\t}\n\t\tholdPublications(() => {\n\t\t\tthis.#tracker.adopt(prepared);\n\t\t\tconst published = ops !== undefined && ops.length > 0 ? ops : unbox(prepared.ops, value);\n\t\t\tthis.fanout.emit(type === \"reset\" ? { type, value } : { type, ops: published, value });\n\t\t\tfor (const [derived, next] of candidates) derived.install(next);\n\t\t});\n\t}\n}\n\n/** True if `b` reuses at least one container of `a` at the same key: a new revision of the same state. */\nfunction sharesStructure(a: unknown, b: unknown): boolean {\n\tif (a === null || b === null || typeof a !== \"object\" || typeof b !== \"object\" || a === b) return false;\n\tif (Array.isArray(a) !== Array.isArray(b)) return false;\n\tfor (const [key, child] of Object.entries(b)) {\n\t\tif (child !== null && typeof child === \"object\" && (a as Record<string, unknown>)[key] === child) return true;\n\t}\n\treturn false;\n}\n\n/** Recomputes every transitive dependent of `changed` against candidate values and validates them. */\nfunction computeDependents(changed: Source<unknown>, value: unknown, validate = true): Map<Derived<unknown>, unknown> {\n\tconst pending = new Set<Derived<unknown>>();\n\tconst visit = (source: Source<unknown>): void => {\n\t\tfor (const derived of source.dependents) {\n\t\t\tif (pending.has(derived)) continue;\n\t\t\tpending.add(derived);\n\t\t\tvisit(derived);\n\t\t}\n\t};\n\tvisit(changed);\n\tconst values = new Map<Readable<unknown>, unknown>([[changed, value]]);\n\tconst result = new Map<Derived<unknown>, unknown>();\n\tfor (const derived of [...pending].sort((a, b) => a.seq - b.seq)) {\n\t\tconst next = derived.compute((source) => (values.has(source) ? values.get(source) : source.value));\n\t\tif (validate) derived.validate(next);\n\t\tvalues.set(derived, next);\n\t\tresult.set(derived, next);\n\t}\n\treturn result;\n}\n\nexport type Sources = readonly Readable<unknown>[];\nexport type SourceValues<S extends Sources> = { [K in keyof S]: S[K] extends Readable<infer T> ? T : never };\n\nconst isReadable = (value: unknown): value is Readable<unknown> =>\n\tvalue !== null &&\n\ttypeof value === \"object\" &&\n\ttypeof (value as Readable<unknown>).subscribe === \"function\" &&\n\t\"value\" in value;\n\n/**\n * A synchronous derivation. Sources are object cells/derivations (recomputed atomically with the write) or other\n * readables such as reference state members (recomputed when they publish). Subscribers receive diffs.\n */\nexport class Derived<T> extends Source<T> {\n\treadonly sources: readonly Readable<unknown>[];\n\treadonly #fn: (...values: never[]) => unknown;\n\t#value: T;\n\t#external: (() => void)[] = [];\n\n\tconstructor(key: string, sources: Sources, fn: (...values: never[]) => unknown, options: SourceOptions) {\n\t\tsuper(key, options);\n\t\tthis.sources = sources.map((source) => {\n\t\t\tif (!isReadable(source)) throw new TypeError(`derive ${key}: sources must be readables`);\n\t\t\treturn source;\n\t\t});\n\t\tthis.#fn = fn;\n\t\tthis.#value = undefined as T;\n\t}\n\n\tget value(): T {\n\t\treturn this.#value;\n\t}\n\n\t/** Hydrated once every source is (a derivation over a remote member waits for its snapshot). */\n\tget [HYDRATION](): Hydration | undefined {\n\t\tconst pending = unhydrated(this.sources);\n\t\tif (pending.length === 0) return undefined;\n\t\treturn {\n\t\t\thydrated: false,\n\t\t\twhenHydrated: () => Promise.all(pending.map((hydration) => hydration.whenHydrated())).then(() => {}),\n\t\t};\n\t}\n\n\t/**\n\t * Computes the first value (or takes it from `precomputed`, a reload's validated dry run) and starts following\n\t * the sources (at install, never inside a factory).\n\t */\n\tattach(precomputed?: ReadonlyMap<unknown, unknown>): void {\n\t\tthis.#value = precomputed?.has(this) ? (precomputed.get(this) as T) : this.compute((source) => source.value);\n\t\tfor (const source of this.sources) {\n\t\t\tif (source instanceof Source) source.dependents.add(this as Derived<unknown>);\n\t\t\telse this.#external.push(source.subscribe(() => this.refresh()));\n\t\t}\n\t}\n\n\tdetach(): void {\n\t\tfor (const source of this.sources)\n\t\t\tif (source instanceof Source) source.dependents.delete(this as Derived<unknown>);\n\t\tfor (const unsubscribe of this.#external.splice(0)) unsubscribe();\n\t}\n\n\tcompute(read: (source: Readable<unknown>) => unknown): T {\n\t\tconst result: unknown = this.#fn(...(this.sources.map(read) as never[]));\n\t\tif (result instanceof Promise) throw new TypeError(`derive ${this.key}: fn must be synchronous`);\n\t\treturn result as T;\n\t}\n\n\t/** Recomputes and republishes, including dependents. Errors are reported (the source write already happened). */\n\trefresh(): void {\n\t\ttry {\n\t\t\tconst next = this.compute((source) => source.value);\n\t\t\tconst dependents = computeDependents(this as Derived<unknown>, next);\n\t\t\tholdPublications(() => {\n\t\t\t\tthis.install(next);\n\t\t\t\tfor (const [derived, value] of dependents) derived.install(value);\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthis.options.report(error);\n\t\t}\n\t}\n\n\tinstall(next: T): void {\n\t\tconst before = this.#value;\n\t\tthis.#value = next;\n\t\tconst ops: Op[] =\n\t\t\tbefore === undefined || next === undefined\n\t\t\t\t? [[\"r\", (next ?? null) as JsonValue]]\n\t\t\t\t: diffRevisions(before as JsonValue, next as JsonValue);\n\t\tif (ops.length > 0) this.fanout.emit({ type: \"ops\", ops, value: next });\n\t}\n}\n\nexport const isSource = (value: unknown): value is Cell<unknown> | Derived<unknown> => value instanceof Source;\n\n/** Thrown by placeholders used before activation finished. */\nexport const notReady = (what: string): ChordError => new ChordError(\"not_ready\", `${what} is not ready`);\n"]}
@@ -1,3 +1,4 @@
1
+ import { type SpanOptions, type TelemetrySpan } from "@earendil-works/pi-telemetry";
1
2
  /** Typed identity for one value carried by a {@link Context}. */
2
3
  export interface ContextKey<T> {
3
4
  readonly token: symbol;
@@ -7,6 +8,7 @@ export interface ContextKey<T> {
7
8
  /** Immutable invocation-scoped values passed explicitly through operations. */
8
9
  export interface Context {
9
10
  readonly abortSignal: AbortSignal | undefined;
11
+ readonly telemetry: TelemetrySpan;
10
12
  value<T>(key: ContextKey<T>): T | undefined;
11
13
  toString(): string;
12
14
  }
@@ -15,6 +17,12 @@ export declare const TODO_CONTEXT: Context;
15
17
  export declare function createContextKey<T>(description: string): ContextKey<T>;
16
18
  /** Derive a context containing one additional or replaced value. */
17
19
  export declare function withContextValue<T>(key: ContextKey<T>, value: T, parent: Context): Context;
20
+ /** Derive an explicit telemetry parent without changing cancellation or application values. */
21
+ export declare function withTelemetry<T extends TelemetrySpan>(telemetry: T, context: Context): Context & {
22
+ readonly telemetry: T;
23
+ };
24
+ /** Run a child span with a derived context whose telemetry member is that span. */
25
+ export declare function traceIn<T>(options: SpanOptions, fn: (context: Context) => T | Promise<T>, context: Context): Promise<T>;
18
26
  /**
19
27
  * Derive a context cancelled by either the parent signal or the supplied signal.
20
28
  * The parent context remains unchanged.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d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,EAAE,CAAC,CAAA;CAAE,CAErC;AAED,mFAAmF;AACnF,wBAAgB,OAAO,CAAC,CAAC,EACxB,OAAO,EAAE,WAAW,EACpB,EAAE,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EACxC,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAI9E;AAED,6GAA6G;AAC7G,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAE5D;AAED,yDAAyD;AACzD,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG;IAC7C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5C,CAMA;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAkBrF"}
@@ -1,10 +1,17 @@
1
+ import { NOOP_TELEMETRY_CONTEXT } from "@earendil-works/pi-telemetry";
1
2
  const ABORT_SIGNAL_CONTEXT_KEY = Object.freeze({
2
3
  token: Symbol("chord.abortSignal"),
3
4
  });
5
+ const TELEMETRY_CONTEXT_KEY = Object.freeze({
6
+ token: Symbol("chord.telemetry"),
7
+ });
4
8
  class BaseContext {
5
9
  get abortSignal() {
6
10
  return this.value(ABORT_SIGNAL_CONTEXT_KEY);
7
11
  }
12
+ get telemetry() {
13
+ return this.value(TELEMETRY_CONTEXT_KEY) ?? NOOP_TELEMETRY_CONTEXT;
14
+ }
8
15
  }
9
16
  class EmptyContext extends BaseContext {
10
17
  #name;
@@ -47,6 +54,14 @@ export function createContextKey(description) {
47
54
  export function withContextValue(key, value, parent) {
48
55
  return new ContextValue(parent, key, value);
49
56
  }
57
+ /** Derive an explicit telemetry parent without changing cancellation or application values. */
58
+ export function withTelemetry(telemetry, context) {
59
+ return withContextValue(TELEMETRY_CONTEXT_KEY, telemetry, context);
60
+ }
61
+ /** Run a child span with a derived context whose telemetry member is that span. */
62
+ export function traceIn(options, fn, context) {
63
+ return context.telemetry.startSpan(options, (span) => fn(withTelemetry(span, context)));
64
+ }
50
65
  /**
51
66
  * Derive a context cancelled by either the parent signal or the supplied signal.
52
67
  * The parent context remains unchanged.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAcA,MAAM,wBAAwB,GAAwC,MAAM,CAAC,MAAM,CAAC;IACnF,KAAK,EAAE,MAAM,CAAC,mBAAmB,CAAC;CAClC,CAAC,CAAC;AAEH,MAAe,WAAW;IAIzB,IAAI,WAAW;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC7C,CAAC;CACD;AAED,MAAM,YAAa,SAAQ,WAAW;IAC5B,KAAK,CAAS;IAEvB,YAAY,IAAY;QACvB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAI,IAAmB;QAC3B,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;CACD;AAED,MAAM,YAAgB,SAAQ,WAAW;IAC/B,OAAO,CAAU;IACjB,IAAI,CAAgB;IACpB,MAAM,CAAI;IAEnB,YAAY,MAAe,EAAE,GAAkB,EAAE,KAAQ;QACxD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,KAAK,CAA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AACJ,CAAC;AAED,SAAS,UAAU,CAAC,MAAmB;IACtC,MAAM,MAAM,GAAY,MAAM,CAAC,MAAM,CAAC;IACtC,OAAO,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC;AACvG,CAAC","sourcesContent":["/** Typed identity for one value carried by a {@link Context}. */\nexport interface ContextKey<T> {\n\treadonly token: symbol;\n\t/** Type-only marker that prevents keys with different value types from being interchangeable. */\n\treadonly valueType?: (value: T) => T;\n}\n\n/** Immutable invocation-scoped values passed explicitly through operations. */\nexport interface Context {\n\treadonly abortSignal: AbortSignal | undefined;\n\tvalue<T>(key: ContextKey<T>): T | undefined;\n\ttoString(): string;\n}\n\nconst ABORT_SIGNAL_CONTEXT_KEY: ContextKey<AbortSignal | undefined> = Object.freeze({\n\ttoken: Symbol(\"chord.abortSignal\"),\n});\n\nabstract class BaseContext implements Context {\n\tabstract value<T>(key: ContextKey<T>): T | undefined;\n\tabstract toString(): string;\n\n\tget abortSignal(): AbortSignal | undefined {\n\t\treturn this.value(ABORT_SIGNAL_CONTEXT_KEY);\n\t}\n}\n\nclass EmptyContext extends BaseContext {\n\treadonly #name: string;\n\n\tconstructor(name: string) {\n\t\tsuper();\n\t\tthis.#name = name;\n\t}\n\n\tvalue<T>(_key: ContextKey<T>): T | undefined {\n\t\treturn undefined;\n\t}\n\n\ttoString(): string {\n\t\treturn this.#name;\n\t}\n}\n\nclass ContextValue<T> extends BaseContext {\n\treadonly #parent: Context;\n\treadonly #key: ContextKey<T>;\n\treadonly #value: T;\n\n\tconstructor(parent: Context, key: ContextKey<T>, value: T) {\n\t\tsuper();\n\t\tthis.#parent = parent;\n\t\tthis.#key = key;\n\t\tthis.#value = value;\n\t}\n\n\tvalue<Value>(key: ContextKey<Value>): Value | undefined {\n\t\tif (key.token === this.#key.token) return this.#value as unknown as Value;\n\t\treturn this.#parent.value(key);\n\t}\n\n\ttoString(): string {\n\t\treturn `${this.#parent}.WithValue(${this.#key.token.description ?? \"anonymous\"})`;\n\t}\n}\n\nexport const BACKGROUND_CONTEXT: Context = new EmptyContext(\"[Context BACKGROUND_CONTEXT]\");\nexport const TODO_CONTEXT: Context = new EmptyContext(\"[Context TODO_CONTEXT]\");\n\nexport function createContextKey<T>(description: string): ContextKey<T> {\n\treturn Object.freeze({ token: Symbol(description) });\n}\n\n/** Derive a context containing one additional or replaced value. */\nexport function withContextValue<T>(key: ContextKey<T>, value: T, parent: Context): Context {\n\treturn new ContextValue(parent, key, value);\n}\n\n/**\n * Derive a context cancelled by either the parent signal or the supplied signal.\n * The parent context remains unchanged.\n */\nexport function withAbortSignal(signal: AbortSignal, context: Context): Context {\n\tconst parentSignal = context.abortSignal;\n\tconst combined = parentSignal === undefined ? signal : AbortSignal.any([parentSignal, signal]);\n\treturn withContextValue(ABORT_SIGNAL_CONTEXT_KEY, combined, context);\n}\n\n/** Derive a context retaining all values except caller cancellation. Intended for mandatory cleanup only. */\nexport function withoutAbortSignal(context: Context): Context {\n\treturn withContextValue(ABORT_SIGNAL_CONTEXT_KEY, undefined, context);\n}\n\n/** Derive an independently cancellable child context. */\nexport function withCancel(context: Context): {\n\treadonly context: Context;\n\treadonly cancel: (reason?: unknown) => void;\n} {\n\tconst controller = new AbortController();\n\treturn {\n\t\tcontext: withAbortSignal(controller.signal, context),\n\t\tcancel: (reason?: unknown) => controller.abort(reason),\n\t};\n}\n\n/**\n * Observe a promise until it settles or the invocation is cancelled.\n * Cancellation rejects only this waiter; it does not cancel the underlying promise.\n */\nexport function awaitWithContext<T>(promise: Promise<T>, context: Context): Promise<T> {\n\tconst signal = context.abortSignal;\n\tif (signal === undefined) return promise;\n\tif (signal.aborted) return Promise.reject(abortError(signal));\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst onAbort = (): void => reject(abortError(signal));\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tvoid promise.then(\n\t\t\t(value) => {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tresolve(value);\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\treject(error);\n\t\t\t},\n\t\t);\n\t});\n}\n\nfunction abortError(signal: AbortSignal): Error {\n\tconst reason: unknown = signal.reason;\n\treturn reason instanceof Error ? reason : new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAwC,MAAM,8BAA8B,CAAC;AAiB5G,MAAM,wBAAwB,GAAwC,MAAM,CAAC,MAAM,CAAC;IACnF,KAAK,EAAE,MAAM,CAAC,mBAAmB,CAAC;CAClC,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAA8B,MAAM,CAAC,MAAM,CAAC;IACtE,KAAK,EAAE,MAAM,CAAC,iBAAiB,CAAC;CAChC,CAAC,CAAC;AAEH,MAAe,WAAW;IAIzB,IAAI,WAAW;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,SAAS;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,IAAI,sBAAsB,CAAC;IACpE,CAAC;CACD;AAED,MAAM,YAAa,SAAQ,WAAW;IAC5B,KAAK,CAAS;IAEvB,YAAY,IAAY;QACvB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAI,IAAmB;QAC3B,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,KAAK,CAAC;IACnB,CAAC;CACD;AAED,MAAM,YAAgB,SAAQ,WAAW;IAC/B,OAAO,CAAU;IACjB,IAAI,CAAgB;IACpB,MAAM,CAAI;IAEnB,YAAY,MAAe,EA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AAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzC,MAAM,OAAO,GAAG,GAAS,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;QACvD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,KAAK,OAAO,CAAC,IAAI,CAChB,CAAC,KAAK,EAAE,EAAE;YACT,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC7C,OAAO,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,EACD,CAAC,KAAc,EAAE,EAAE;YAClB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC7C,MAAM,CAAC,KAAK,CAAC,CAAC;QACf,CAAC,CACD,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,MAAmB;IACtC,MAAM,MAAM,GAAY,MAAM,CAAC,MAAM,CAAC;IACtC,OAAO,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC;AACvG,CAAC","sourcesContent":["import { NOOP_TELEMETRY_CONTEXT, type SpanOptions, type TelemetrySpan } from \"@earendil-works/pi-telemetry\";\n\n/** Typed identity for one value carried by a {@link Context}. */\nexport interface ContextKey<T> {\n\treadonly token: symbol;\n\t/** Type-only marker that prevents keys with different value types from being interchangeable. */\n\treadonly valueType?: (value: T) => T;\n}\n\n/** Immutable invocation-scoped values passed explicitly through operations. */\nexport interface Context {\n\treadonly abortSignal: AbortSignal | undefined;\n\treadonly telemetry: TelemetrySpan;\n\tvalue<T>(key: ContextKey<T>): T | undefined;\n\ttoString(): string;\n}\n\nconst ABORT_SIGNAL_CONTEXT_KEY: ContextKey<AbortSignal | undefined> = Object.freeze({\n\ttoken: Symbol(\"chord.abortSignal\"),\n});\n\nconst TELEMETRY_CONTEXT_KEY: ContextKey<TelemetrySpan> = Object.freeze({\n\ttoken: Symbol(\"chord.telemetry\"),\n});\n\nabstract class BaseContext implements Context {\n\tabstract value<T>(key: ContextKey<T>): T | undefined;\n\tabstract toString(): string;\n\n\tget abortSignal(): AbortSignal | undefined {\n\t\treturn this.value(ABORT_SIGNAL_CONTEXT_KEY);\n\t}\n\n\tget telemetry(): TelemetrySpan {\n\t\treturn this.value(TELEMETRY_CONTEXT_KEY) ?? NOOP_TELEMETRY_CONTEXT;\n\t}\n}\n\nclass EmptyContext extends BaseContext {\n\treadonly #name: string;\n\n\tconstructor(name: string) {\n\t\tsuper();\n\t\tthis.#name = name;\n\t}\n\n\tvalue<T>(_key: ContextKey<T>): T | undefined {\n\t\treturn undefined;\n\t}\n\n\ttoString(): string {\n\t\treturn this.#name;\n\t}\n}\n\nclass ContextValue<T> extends BaseContext {\n\treadonly #parent: Context;\n\treadonly #key: ContextKey<T>;\n\treadonly #value: T;\n\n\tconstructor(parent: Context, key: ContextKey<T>, value: T) {\n\t\tsuper();\n\t\tthis.#parent = parent;\n\t\tthis.#key = key;\n\t\tthis.#value = value;\n\t}\n\n\tvalue<Value>(key: ContextKey<Value>): Value | undefined {\n\t\tif (key.token === this.#key.token) return this.#value as unknown as Value;\n\t\treturn this.#parent.value(key);\n\t}\n\n\ttoString(): string {\n\t\treturn `${this.#parent}.WithValue(${this.#key.token.description ?? \"anonymous\"})`;\n\t}\n}\n\nexport const BACKGROUND_CONTEXT: Context = new EmptyContext(\"[Context BACKGROUND_CONTEXT]\");\nexport const TODO_CONTEXT: Context = new EmptyContext(\"[Context TODO_CONTEXT]\");\n\nexport function createContextKey<T>(description: string): ContextKey<T> {\n\treturn Object.freeze({ token: Symbol(description) });\n}\n\n/** Derive a context containing one additional or replaced value. */\nexport function withContextValue<T>(key: ContextKey<T>, value: T, parent: Context): Context {\n\treturn new ContextValue(parent, key, value);\n}\n\n/** Derive an explicit telemetry parent without changing cancellation or application values. */\nexport function withTelemetry<T extends TelemetrySpan>(\n\ttelemetry: T,\n\tcontext: Context,\n): Context & { readonly telemetry: T } {\n\treturn withContextValue(TELEMETRY_CONTEXT_KEY, telemetry, context) as Context & { readonly telemetry: T };\n}\n\n/** Run a child span with a derived context whose telemetry member is that span. */\nexport function traceIn<T>(\n\toptions: SpanOptions,\n\tfn: (context: Context) => T | Promise<T>,\n\tcontext: Context,\n): Promise<T> {\n\treturn context.telemetry.startSpan(options, (span) => fn(withTelemetry(span, context)));\n}\n\n/**\n * Derive a context cancelled by either the parent signal or the supplied signal.\n * The parent context remains unchanged.\n */\nexport function withAbortSignal(signal: AbortSignal, context: Context): Context {\n\tconst parentSignal = context.abortSignal;\n\tconst combined = parentSignal === undefined ? signal : AbortSignal.any([parentSignal, signal]);\n\treturn withContextValue(ABORT_SIGNAL_CONTEXT_KEY, combined, context);\n}\n\n/** Derive a context retaining all values except caller cancellation. Intended for mandatory cleanup only. */\nexport function withoutAbortSignal(context: Context): Context {\n\treturn withContextValue(ABORT_SIGNAL_CONTEXT_KEY, undefined, context);\n}\n\n/** Derive an independently cancellable child context. */\nexport function withCancel(context: Context): {\n\treadonly context: Context;\n\treadonly cancel: (reason?: unknown) => void;\n} {\n\tconst controller = new AbortController();\n\treturn {\n\t\tcontext: withAbortSignal(controller.signal, context),\n\t\tcancel: (reason?: unknown) => controller.abort(reason),\n\t};\n}\n\n/**\n * Observe a promise until it settles or the invocation is cancelled.\n * Cancellation rejects only this waiter; it does not cancel the underlying promise.\n */\nexport function awaitWithContext<T>(promise: Promise<T>, context: Context): Promise<T> {\n\tconst signal = context.abortSignal;\n\tif (signal === undefined) return promise;\n\tif (signal.aborted) return Promise.reject(abortError(signal));\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst onAbort = (): void => reject(abortError(signal));\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tvoid promise.then(\n\t\t\t(value) => {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tresolve(value);\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\tsignal.removeEventListener(\"abort\", onAbort);\n\t\t\t\treject(error);\n\t\t\t},\n\t\t);\n\t});\n}\n\nfunction abortError(signal: AbortSignal): Error {\n\tconst reason: unknown = signal.reason;\n\treturn reason instanceof Error ? reason : new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n"]}