@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/next-node/http/index.ts"],"names":[],"mappings":"AAKA,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,KAAK,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,KAAK,mBAAmB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EACN,UAAU,EACV,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,YAAY,GACjB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC7D,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EACN,IAAI,EACJ,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,SAAS,GACd,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,12 @@
1
+ // Chord v2's HTTP component (`@earendil-works/chord/next/http`, slice 10 §2): a Web-standard `fetch` handler built
2
+ // from the routes, wraps and sockets plugins contribute to the registry `Http`, with the security baseline on by
3
+ // default, Chord's own Node listener, a Node upgrade adapter and the Node request conversion for apps that mount it.
4
+ // Node-only; `ws` is an optional peer dependency, imported only here.
5
+ export { Authenticators } from "./authenticate.js";
6
+ export { cookie, readCookie } from "./cookies.js";
7
+ export { fileResponse } from "./file.js";
8
+ export { createHttp, HttpListener, } from "./http.js";
9
+ export { nodeRequest } from "./node.js";
10
+ export { HttpFailure } from "./request.js";
11
+ export { Http, } from "./router.js";
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/next-node/http/index.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,iHAAiH;AACjH,qHAAqH;AACrH,sEAAsE;AAGtE,OAAO,EAAsB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAsB,MAAM,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAA4B,YAAY,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EACN,UAAU,EAIV,YAAY,GAGZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAwC,WAAW,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAoB,MAAM,cAAc,CAAC;AAE7D,OAAO,EACN,IAAI,GAUJ,MAAM,aAAa,CAAC","sourcesContent":["// Chord v2's HTTP component (`@earendil-works/chord/next/http`, slice 10 §2): a Web-standard `fetch` handler built\n// from the routes, wraps and sockets plugins contribute to the registry `Http`, with the security baseline on by\n// default, Chord's own Node listener, a Node upgrade adapter and the Node request conversion for apps that mount it.\n// Node-only; `ws` is an optional peer dependency, imported only here.\n\nexport type { Connection, Provenance } from \"./admission.ts\";\nexport { type Authenticator, Authenticators } from \"./authenticate.ts\";\nexport { type CookieOptions, cookie, readCookie } from \"./cookies.ts\";\nexport { type FileResponseOptions, fileResponse } from \"./file.ts\";\nexport {\n\tcreateHttp,\n\ttype HookName,\n\ttype HttpComponent,\n\ttype HttpError,\n\tHttpListener,\n\ttype HttpOptions,\n\ttype LinksOptions,\n} from \"./http.ts\";\nexport { type ListenAddress, type NodeRequest, nodeRequest } from \"./node.ts\";\nexport { HttpFailure, type HttpRequest } from \"./request.ts\";\nexport type { HttpResponse } from \"./response.ts\";\nexport {\n\tHttp,\n\ttype HttpContribution,\n\ttype HttpRelay,\n\ttype HttpRoute,\n\ttype HttpRouteOptions,\n\ttype HttpSocket,\n\ttype HttpWrap,\n\ttype Router,\n\ttype WebSocketHandle,\n\ttype WrapPhase,\n} from \"./router.ts\";\nexport type { LinkOptions } from \"./upgrades.ts\";\n"]}
@@ -0,0 +1,78 @@
1
+ import { type IncomingMessage, type ServerResponse } from "node:http";
2
+ import type { Duplex } from "node:stream";
3
+ import type { Context } from "../../context/index.ts";
4
+ import type { Connection } from "./admission.ts";
5
+ import { type Incoming } from "./incoming.ts";
6
+ import type { Answer } from "./response.ts";
7
+ /** Where a listener listens. */
8
+ export type ListenAddress = {
9
+ readonly host: string;
10
+ readonly port: number;
11
+ };
12
+ /** An answer and what its consumer calls once the body is written or abandoned (the request's scope then ends). */
13
+ export type Served = {
14
+ readonly answer: Answer;
15
+ readonly finished: () => void;
16
+ };
17
+ /** What the listener needs of the component. */
18
+ export interface Handler {
19
+ /** Serves a request: never throws. */
20
+ serve(incoming: Incoming, connection: Connection): Promise<Served>;
21
+ /** The answer for a request refused before it could be made one (default headers only). */
22
+ refusal(status: number): Answer;
23
+ readonly upgrade: (message: IncomingMessage, socket: Duplex, head: Buffer) => void;
24
+ }
25
+ /** The listener's native value: a listening Node server. */
26
+ export declare class NodeListener {
27
+ #private;
28
+ readonly address: ListenAddress;
29
+ private constructor();
30
+ /** A Node server for `handler` listening at `listen`; rejects with the listen error (a port in use). */
31
+ static listen(handler: Handler, listen: ListenAddress, context: Context): Promise<NodeListener>;
32
+ /** Stops accepting connections and closes the idle ones (the component's close runs next). */
33
+ stop(): void;
34
+ /** Closes every connection still open and resolves once the server closed. */
35
+ closed(): Promise<void>;
36
+ }
37
+ /**
38
+ * A Node request as the component reads it: Node's parsed headers, its URL parsed once, the Web `Request` made only
39
+ * when something asks for it (a route's `headers` or body, a relay).
40
+ */
41
+ export declare class NodeIncoming implements Incoming {
42
+ #private;
43
+ readonly method: string;
44
+ readonly url: string;
45
+ private constructor();
46
+ /**
47
+ * `message` as the component reads it, or what refuses it at the wire (the listener and `nodeRequest` alike): an
48
+ * absolute-form target 403, a target that does not parse 400, a `Host` with userinfo 403 (never a loopback or
49
+ * allowed name), a method a Web `Request` cannot carry (`CONNECT`, `TRACE`, `TRACK`) 501: served for no resource.
50
+ */
51
+ static of(message: IncomingMessage, res?: ServerResponse): NodeIncoming | WireRefusal;
52
+ header(name: string): string | null;
53
+ forwarded(): boolean;
54
+ cancelled(abort: (reason: unknown) => void): void;
55
+ request(): Request;
56
+ }
57
+ /** What refuses a Node request at the wire, with its status. */
58
+ export type WireRefusal = {
59
+ readonly kind: "refused";
60
+ readonly status: 400 | 403 | 501;
61
+ };
62
+ /** A Node request as an app mounting `fetch` on its own Node server gets it: a Web `Request`, or refused. */
63
+ export type NodeRequest = {
64
+ readonly kind: "request";
65
+ readonly request: Request;
66
+ readonly connection: Connection;
67
+ } | WireRefusal;
68
+ /**
69
+ * Converts `message` for `http.fetch` on an app's own Node server, the whole conversion being the wire boundary: what
70
+ * the listener refuses is refused with the same status (`NodeIncoming.of`), any other construction failure 400, never a
71
+ * throw (Sol's rechecks N6 and A: a hand-made `Request` crashed the app on a malformed target, `TRACE /` or
72
+ * `Host: user@…`). Raw headers keep their duplicates (two `Host`s: admission refuses); the signal aborts when the
73
+ * client goes away before `res` finished.
74
+ */
75
+ export declare function nodeRequest(message: IncomingMessage, res: ServerResponse): NodeRequest;
76
+ /** What a Node socket knows of its connection. */
77
+ export declare function connectionOf(message: IncomingMessage): Connection;
78
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/next-node/http/node.ts"],"names":[],"mappings":"AAMA,OAAO,EAAgB,KAAK,eAAe,EAAe,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AACjG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,KAAK,QAAQ,EAAgB,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C,gCAAgC;AAChC,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,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AAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAElC;IAED,SAAS,IAAI,OAAO,CAGnB;IAED,SAAS,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAMhD;IAED,OAAO,IAAI,OAAO,CAGjB;CACD;AAED,gEAAgE;AAChE,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;CAAE,CAAC;AAEzF,6GAA6G;AAC7G,MAAM,MAAM,WAAW,GACpB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAA;CAAE,GACxF,WAAW,CAAC;AAEf;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,GAAG,WAAW,CAYtF;AAmBD,kDAAkD;AAClD,wBAAgB,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,UAAU,CAOjE"}
@@ -0,0 +1,291 @@
1
+ // Chord's own Node server (decision "The HTTP server is a native object"; "The HTTP core is a fetch handler; Chord's
2
+ // own Node server is the easy path"): the listener's native, a Node `http` server that hands each request to the
3
+ // component as it reads requests (origin-form targets only; a Web `Request` made only when something asks for one, its
4
+ // body streamed with backpressure), and writes its answer: whole, or pulled piece by piece as the socket drains. A body the route left unread is drained after the
5
+ // response when small, else the connection closes; the request's scope ends once the response is flushed or abandoned.
6
+ import { createServer } from "node:http";
7
+ import { isForwarding } from "./incoming.js";
8
+ import { UNCARRIED } from "./router.js";
9
+ /** The listener's native value: a listening Node server. */
10
+ export class NodeListener {
11
+ address;
12
+ #server;
13
+ #closed;
14
+ constructor(server, address) {
15
+ this.#server = server;
16
+ this.address = address;
17
+ this.#closed = new Promise((resolve) => server.once("close", () => resolve()));
18
+ }
19
+ /** A Node server for `handler` listening at `listen`; rejects with the listen error (a port in use). */
20
+ static async listen(handler, listen, context) {
21
+ const server = createServer((message, res) => {
22
+ void request(handler, message, res).catch(() => res.destroy());
23
+ });
24
+ server.on("upgrade", handler.upgrade);
25
+ await new Promise((resolve, reject) => {
26
+ const failed = (error) => reject(error);
27
+ server.once("error", failed);
28
+ server.listen(listen.port, listen.host, () => {
29
+ server.removeListener("error", failed);
30
+ resolve();
31
+ });
32
+ });
33
+ if (context.abortSignal?.aborted) {
34
+ server.close();
35
+ throw context.abortSignal.reason;
36
+ }
37
+ const address = server.address();
38
+ const port = typeof address === "object" && address !== null ? address.port : listen.port;
39
+ return new NodeListener(server, { host: listen.host, port });
40
+ }
41
+ /** Stops accepting connections and closes the idle ones (the component's close runs next). */
42
+ stop() {
43
+ this.#server.close();
44
+ this.#server.closeIdleConnections();
45
+ }
46
+ /** Closes every connection still open and resolves once the server closed. */
47
+ async closed() {
48
+ this.#server.close();
49
+ this.#server.closeAllConnections();
50
+ await this.#closed;
51
+ }
52
+ }
53
+ /**
54
+ * A Node request as the component reads it: Node's parsed headers, its URL parsed once, the Web `Request` made only
55
+ * when something asks for it (a route's `headers` or body, a relay).
56
+ */
57
+ export class NodeIncoming {
58
+ method;
59
+ url;
60
+ #message;
61
+ /** The response, to notice a client gone (none for an upgrade). */
62
+ #res;
63
+ #request;
64
+ constructor(message, url, res) {
65
+ this.method = message.method ?? "GET";
66
+ this.url = url;
67
+ this.#message = message;
68
+ this.#res = res;
69
+ }
70
+ /**
71
+ * `message` as the component reads it, or what refuses it at the wire (the listener and `nodeRequest` alike): an
72
+ * absolute-form target 403, a target that does not parse 400, a `Host` with userinfo 403 (never a loopback or
73
+ * allowed name), a method a Web `Request` cannot carry (`CONNECT`, `TRACE`, `TRACK`) 501: served for no resource.
74
+ */
75
+ static of(message, res) {
76
+ const target = message.url ?? "";
77
+ // Only origin-form targets: an absolute-form one names an authority of its own, `*` none.
78
+ if (!target.startsWith("/"))
79
+ return { kind: "refused", status: 403 };
80
+ if (UNCARRIED.has(message.method ?? "GET"))
81
+ return { kind: "refused", status: 501 };
82
+ let url;
83
+ try {
84
+ // The authority is the `Host` the client sent; admission checks it, so a strange one parses but is refused.
85
+ url = new URL(`http://${message.headers.host ?? "invalid"}${target}`);
86
+ }
87
+ catch {
88
+ return { kind: "refused", status: 400 };
89
+ }
90
+ if (url.username !== "" || url.password !== "")
91
+ return { kind: "refused", status: 403 };
92
+ return new NodeIncoming(message, url.href, res);
93
+ }
94
+ header(name) {
95
+ return this.#message.headersDistinct[name]?.join(", ") ?? null;
96
+ }
97
+ forwarded() {
98
+ for (const name in this.#message.headersDistinct)
99
+ if (isForwarding(name))
100
+ return true;
101
+ return false;
102
+ }
103
+ cancelled(abort) {
104
+ const res = this.#res;
105
+ if (res === undefined)
106
+ return;
107
+ const gone = () => abort(new Error("http: the client disconnected"));
108
+ if (res.closed)
109
+ gone();
110
+ else
111
+ res.once("close", () => res.writableFinished || gone());
112
+ }
113
+ request() {
114
+ this.#request ??= webRequestOf(this.#message, this.url);
115
+ return this.#request;
116
+ }
117
+ }
118
+ /**
119
+ * Converts `message` for `http.fetch` on an app's own Node server, the whole conversion being the wire boundary: what
120
+ * the listener refuses is refused with the same status (`NodeIncoming.of`), any other construction failure 400, never a
121
+ * throw (Sol's rechecks N6 and A: a hand-made `Request` crashed the app on a malformed target, `TRACE /` or
122
+ * `Host: user@…`). Raw headers keep their duplicates (two `Host`s: admission refuses); the signal aborts when the
123
+ * client goes away before `res` finished.
124
+ */
125
+ export function nodeRequest(message, res) {
126
+ const incoming = NodeIncoming.of(message, res);
127
+ if (!(incoming instanceof NodeIncoming))
128
+ return incoming;
129
+ const gone = new AbortController();
130
+ incoming.cancelled((reason) => gone.abort(reason));
131
+ let request;
132
+ try {
133
+ request = webRequestOf(message, incoming.url, gone.signal);
134
+ }
135
+ catch {
136
+ return { kind: "refused", status: 400 };
137
+ }
138
+ return { kind: "request", request, connection: connectionOf(message) };
139
+ }
140
+ /**
141
+ * The Web `Request` of `message` at `url`: its raw headers (duplicates kept), its body streamed when it has one, and
142
+ * `signal` when the caller follows the client.
143
+ */
144
+ function webRequestOf(message, url, signal) {
145
+ const headers = new Headers();
146
+ const raw = message.rawHeaders;
147
+ for (let index = 0; index < raw.length; index += 2)
148
+ headers.append(raw[index], raw[index + 1]);
149
+ const method = message.method ?? "GET";
150
+ const init = { method, headers, ...(signal === undefined ? {} : { signal }) };
151
+ if (hasBody(message) && method !== "GET" && method !== "HEAD") {
152
+ init.body = bodyOf(message);
153
+ init.duplex = "half";
154
+ }
155
+ return new Request(url, init);
156
+ }
157
+ /** What a Node socket knows of its connection. */
158
+ export function connectionOf(message) {
159
+ const { localAddress, localPort, remoteAddress } = message.socket;
160
+ return {
161
+ ...(localAddress === undefined ? {} : { localAddress }),
162
+ ...(localPort === undefined ? {} : { localPort }),
163
+ ...(remoteAddress === undefined ? {} : { remoteAddress }),
164
+ };
165
+ }
166
+ /** One request: served (an absolute-form target: 403; a URL that does not parse: 400), its answer written. */
167
+ async function request(handler, message, res) {
168
+ const incoming = NodeIncoming.of(message, res);
169
+ if (!(incoming instanceof NodeIncoming)) {
170
+ return write(message, res, { answer: handler.refusal(incoming.status), finished: () => { } });
171
+ }
172
+ await write(message, res, await handler.serve(incoming, connectionOf(message)));
173
+ }
174
+ /** What `json` and `body` leave unread that is drained after the response, keeping the connection: 64 KiB. */
175
+ const DRAIN_LIMIT = 64 * 1024;
176
+ /** Writes `served`'s answer to `res`; what is left of the request's body is drained after it or closes the connection. */
177
+ async function write(message, res, { answer, finished }) {
178
+ // A client gone before its answer: nothing to write.
179
+ if (res.closed)
180
+ return finished();
181
+ res.once("close", finished);
182
+ const left = message.complete || !hasBody(message) ? "none" : declared(message) <= DRAIN_LIMIT ? "drain" : "close";
183
+ const headers = [];
184
+ for (const [name, value] of answer.headers.lines())
185
+ headers.push(name, value);
186
+ if (left === "close")
187
+ headers.push("connection", "close");
188
+ res.writeHead(answer.status, headers);
189
+ const { body } = answer;
190
+ if (body instanceof ReadableStream)
191
+ await pump(body, res);
192
+ else
193
+ res.end(body ?? undefined);
194
+ if (left === "drain")
195
+ drain(message);
196
+ }
197
+ /** Writes `body` to `res` as the socket drains; a body that fails (reported by the component) destroys the connection. */
198
+ async function pump(body, res) {
199
+ const reader = body.getReader();
200
+ const cancel = () => void reader.cancel().catch(() => { });
201
+ res.once("close", cancel);
202
+ for (;;) {
203
+ let next;
204
+ try {
205
+ next = await reader.read();
206
+ }
207
+ catch {
208
+ res.destroy();
209
+ return;
210
+ }
211
+ if (next.done)
212
+ break;
213
+ if (res.destroyed)
214
+ return;
215
+ if (!res.write(next.value))
216
+ await drained(res);
217
+ }
218
+ res.removeListener("close", cancel);
219
+ res.end();
220
+ }
221
+ /** Resolves once `res` drained or closed. */
222
+ function drained(res) {
223
+ return new Promise((resolve) => {
224
+ const done = () => {
225
+ res.removeListener("drain", done);
226
+ res.removeListener("close", done);
227
+ resolve();
228
+ };
229
+ res.once("drain", done);
230
+ res.once("close", done);
231
+ });
232
+ }
233
+ /** A request body as a Web stream: read as its consumer pulls (the socket paused meanwhile); a disconnect errors it. */
234
+ function bodyOf(message) {
235
+ // Whether the stream still takes chunks (not ended, errored or cancelled).
236
+ let open = true;
237
+ return new ReadableStream({
238
+ start: (controller) => {
239
+ message.on("data", (chunk) => {
240
+ if (!open)
241
+ return;
242
+ controller.enqueue(chunk);
243
+ if ((controller.desiredSize ?? 0) <= 0)
244
+ message.pause();
245
+ });
246
+ message.once("end", () => {
247
+ if (open)
248
+ controller.close();
249
+ open = false;
250
+ });
251
+ message.once("close", () => {
252
+ if (open && !message.complete)
253
+ controller.error(new Error("http: the client disconnected"));
254
+ open = false;
255
+ });
256
+ message.pause();
257
+ },
258
+ pull: () => {
259
+ message.resume();
260
+ },
261
+ // The rest stays unread: the response closes the connection (or drains a small rest).
262
+ cancel: () => {
263
+ open = false;
264
+ message.pause();
265
+ },
266
+ }, new ByteLengthQueuingStrategy({ highWaterMark: DRAIN_LIMIT }));
267
+ }
268
+ /** Reads and drops the rest of the body (at most 64 KiB); more than that, or an error, closes the connection. */
269
+ function drain(message) {
270
+ let read = 0;
271
+ message.on("data", (chunk) => {
272
+ read += chunk.byteLength;
273
+ if (read > DRAIN_LIMIT)
274
+ message.socket.destroy();
275
+ });
276
+ message.on("error", () => message.socket.destroy());
277
+ message.resume();
278
+ }
279
+ /** Whether `message` carries a body (a declared length above zero, or chunked). */
280
+ function hasBody(message) {
281
+ const length = message.headers["content-length"];
282
+ if (length !== undefined)
283
+ return Number(length) > 0;
284
+ return message.headers["transfer-encoding"] !== undefined;
285
+ }
286
+ /** The declared length of `message`'s body; infinite when chunked. */
287
+ function declared(message) {
288
+ const length = Number(message.headers["content-length"] ?? Number.NaN);
289
+ return Number.isFinite(length) ? length : Number.POSITIVE_INFINITY;
290
+ }
291
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../../src/next-node/http/node.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,iHAAiH;AACjH,uHAAuH;AACvH,mKAAmK;AACnK,uHAAuH;AAEvH,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAC;AAIjG,OAAO,EAAiB,YAAY,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAiBxC,4DAA4D;AAC5D,MAAM,OAAO,YAAY;IACf,OAAO,CAAgB;IACvB,OAAO,CAAS;IAChB,OAAO,CAAgB;IAEhC,YAAoB,MAAc,EAAE,OAAsB;QACzD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,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AC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC;AACpE,CAAC","sourcesContent":["// Chord's own Node server (decision \"The HTTP server is a native object\"; \"The HTTP core is a fetch handler; Chord's\n// own Node server is the easy path\"): the listener's native, a Node `http` server that hands each request to the\n// component as it reads requests (origin-form targets only; a Web `Request` made only when something asks for one, its\n// body streamed with backpressure), and writes its answer: whole, or pulled piece by piece as the socket drains. A body the route left unread is drained after the\n// response when small, else the connection closes; the request's scope ends once the response is flushed or abandoned.\n\nimport { createServer, type IncomingMessage, type Server, type ServerResponse } from \"node:http\";\nimport type { Duplex } from \"node:stream\";\nimport type { Context } from \"../../context/index.ts\";\nimport type { Connection } from \"./admission.ts\";\nimport { type Incoming, isForwarding } from \"./incoming.ts\";\nimport type { Answer } from \"./response.ts\";\nimport { UNCARRIED } from \"./router.ts\";\n\n/** Where a listener listens. */\nexport type ListenAddress = { readonly host: string; readonly port: number };\n\n/** An answer and what its consumer calls once the body is written or abandoned (the request's scope then ends). */\nexport type Served = { readonly answer: Answer; readonly finished: () => void };\n\n/** What the listener needs of the component. */\nexport interface Handler {\n\t/** Serves a request: never throws. */\n\tserve(incoming: Incoming, connection: Connection): Promise<Served>;\n\t/** The answer for a request refused before it could be made one (default headers only). */\n\trefusal(status: number): Answer;\n\treadonly upgrade: (message: IncomingMessage, socket: Duplex, head: Buffer) => void;\n}\n\n/** The listener's native value: a listening Node server. */\nexport class NodeListener {\n\treadonly address: ListenAddress;\n\treadonly #server: Server;\n\treadonly #closed: Promise<void>;\n\n\tprivate constructor(server: Server, address: ListenAddress) {\n\t\tthis.#server = server;\n\t\tthis.address = address;\n\t\tthis.#closed = new Promise((resolve) => server.once(\"close\", () => resolve()));\n\t}\n\n\t/** A Node server for `handler` listening at `listen`; rejects with the listen error (a port in use). */\n\tstatic async listen(handler: Handler, listen: ListenAddress, context: Context): Promise<NodeListener> {\n\t\tconst server = createServer((message, res) => {\n\t\t\tvoid request(handler, message, res).catch(() => res.destroy());\n\t\t});\n\t\tserver.on(\"upgrade\", handler.upgrade);\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tconst failed = (error: Error): void => reject(error);\n\t\t\tserver.once(\"error\", failed);\n\t\t\tserver.listen(listen.port, listen.host, () => {\n\t\t\t\tserver.removeListener(\"error\", failed);\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\t\tif (context.abortSignal?.aborted) {\n\t\t\tserver.close();\n\t\t\tthrow context.abortSignal.reason;\n\t\t}\n\t\tconst address = server.address();\n\t\tconst port = typeof address === \"object\" && address !== null ? address.port : listen.port;\n\t\treturn new NodeListener(server, { host: listen.host, port });\n\t}\n\n\t/** Stops accepting connections and closes the idle ones (the component's close runs next). */\n\tstop(): void {\n\t\tthis.#server.close();\n\t\tthis.#server.closeIdleConnections();\n\t}\n\n\t/** Closes every connection still open and resolves once the server closed. */\n\tasync closed(): Promise<void> {\n\t\tthis.#server.close();\n\t\tthis.#server.closeAllConnections();\n\t\tawait this.#closed;\n\t}\n}\n\n/**\n * A Node request as the component reads it: Node's parsed headers, its URL parsed once, the Web `Request` made only\n * when something asks for it (a route's `headers` or body, a relay).\n */\nexport class NodeIncoming implements Incoming {\n\treadonly method: string;\n\treadonly url: string;\n\treadonly #message: IncomingMessage;\n\t/** The response, to notice a client gone (none for an upgrade). */\n\treadonly #res: ServerResponse | undefined;\n\t#request: Request | undefined;\n\n\tprivate constructor(message: IncomingMessage, url: string, res: ServerResponse | undefined) {\n\t\tthis.method = message.method ?? \"GET\";\n\t\tthis.url = url;\n\t\tthis.#message = message;\n\t\tthis.#res = res;\n\t}\n\n\t/**\n\t * `message` as the component reads it, or what refuses it at the wire (the listener and `nodeRequest` alike): an\n\t * absolute-form target 403, a target that does not parse 400, a `Host` with userinfo 403 (never a loopback or\n\t * allowed name), a method a Web `Request` cannot carry (`CONNECT`, `TRACE`, `TRACK`) 501: served for no resource.\n\t */\n\tstatic of(message: IncomingMessage, res?: ServerResponse): NodeIncoming | WireRefusal {\n\t\tconst target = message.url ?? \"\";\n\t\t// Only origin-form targets: an absolute-form one names an authority of its own, `*` none.\n\t\tif (!target.startsWith(\"/\")) return { kind: \"refused\", status: 403 };\n\t\tif (UNCARRIED.has(message.method ?? \"GET\")) return { kind: \"refused\", status: 501 };\n\t\tlet url: URL;\n\t\ttry {\n\t\t\t// The authority is the `Host` the client sent; admission checks it, so a strange one parses but is refused.\n\t\t\turl = new URL(`http://${message.headers.host ?? \"invalid\"}${target}`);\n\t\t} catch {\n\t\t\treturn { kind: \"refused\", status: 400 };\n\t\t}\n\t\tif (url.username !== \"\" || url.password !== \"\") return { kind: \"refused\", status: 403 };\n\t\treturn new NodeIncoming(message, url.href, res);\n\t}\n\n\theader(name: string): string | null {\n\t\treturn this.#message.headersDistinct[name]?.join(\", \") ?? null;\n\t}\n\n\tforwarded(): boolean {\n\t\tfor (const name in this.#message.headersDistinct) if (isForwarding(name)) return true;\n\t\treturn false;\n\t}\n\n\tcancelled(abort: (reason: unknown) => void): void {\n\t\tconst res = this.#res;\n\t\tif (res === undefined) return;\n\t\tconst gone = (): void => abort(new Error(\"http: the client disconnected\"));\n\t\tif (res.closed) gone();\n\t\telse res.once(\"close\", () => res.writableFinished || gone());\n\t}\n\n\trequest(): Request {\n\t\tthis.#request ??= webRequestOf(this.#message, this.url);\n\t\treturn this.#request;\n\t}\n}\n\n/** What refuses a Node request at the wire, with its status. */\nexport type WireRefusal = { readonly kind: \"refused\"; readonly status: 400 | 403 | 501 };\n\n/** A Node request as an app mounting `fetch` on its own Node server gets it: a Web `Request`, or refused. */\nexport type NodeRequest =\n\t| { readonly kind: \"request\"; readonly request: Request; readonly connection: Connection }\n\t| WireRefusal;\n\n/**\n * Converts `message` for `http.fetch` on an app's own Node server, the whole conversion being the wire boundary: what\n * the listener refuses is refused with the same status (`NodeIncoming.of`), any other construction failure 400, never a\n * throw (Sol's rechecks N6 and A: a hand-made `Request` crashed the app on a malformed target, `TRACE /` or\n * `Host: user@…`). Raw headers keep their duplicates (two `Host`s: admission refuses); the signal aborts when the\n * client goes away before `res` finished.\n */\nexport function nodeRequest(message: IncomingMessage, res: ServerResponse): NodeRequest {\n\tconst incoming = NodeIncoming.of(message, res);\n\tif (!(incoming instanceof NodeIncoming)) return incoming;\n\tconst gone = new AbortController();\n\tincoming.cancelled((reason) => gone.abort(reason));\n\tlet request: Request;\n\ttry {\n\t\trequest = webRequestOf(message, incoming.url, gone.signal);\n\t} catch {\n\t\treturn { kind: \"refused\", status: 400 };\n\t}\n\treturn { kind: \"request\", request, connection: connectionOf(message) };\n}\n\n/**\n * The Web `Request` of `message` at `url`: its raw headers (duplicates kept), its body streamed when it has one, and\n * `signal` when the caller follows the client.\n */\nfunction webRequestOf(message: IncomingMessage, url: string, signal?: AbortSignal): Request {\n\tconst headers = new Headers();\n\tconst raw = message.rawHeaders;\n\tfor (let index = 0; index < raw.length; index += 2) headers.append(raw[index]!, raw[index + 1]!);\n\tconst method = message.method ?? \"GET\";\n\tconst init: RequestInit & { duplex?: \"half\" } = { method, headers, ...(signal === undefined ? {} : { signal }) };\n\tif (hasBody(message) && method !== \"GET\" && method !== \"HEAD\") {\n\t\tinit.body = bodyOf(message);\n\t\tinit.duplex = \"half\";\n\t}\n\treturn new Request(url, init);\n}\n\n/** What a Node socket knows of its connection. */\nexport function connectionOf(message: IncomingMessage): Connection {\n\tconst { localAddress, localPort, remoteAddress } = message.socket;\n\treturn {\n\t\t...(localAddress === undefined ? {} : { localAddress }),\n\t\t...(localPort === undefined ? {} : { localPort }),\n\t\t...(remoteAddress === undefined ? {} : { remoteAddress }),\n\t};\n}\n\n/** One request: served (an absolute-form target: 403; a URL that does not parse: 400), its answer written. */\nasync function request(handler: Handler, message: IncomingMessage, res: ServerResponse): Promise<void> {\n\tconst incoming = NodeIncoming.of(message, res);\n\tif (!(incoming instanceof NodeIncoming)) {\n\t\treturn write(message, res, { answer: handler.refusal(incoming.status), finished: () => {} });\n\t}\n\tawait write(message, res, await handler.serve(incoming, connectionOf(message)));\n}\n\n/** What `json` and `body` leave unread that is drained after the response, keeping the connection: 64 KiB. */\nconst DRAIN_LIMIT = 64 * 1024;\n\n/** Writes `served`'s answer to `res`; what is left of the request's body is drained after it or closes the connection. */\nasync function write(message: IncomingMessage, res: ServerResponse, { answer, finished }: Served): Promise<void> {\n\t// A client gone before its answer: nothing to write.\n\tif (res.closed) return finished();\n\tres.once(\"close\", finished);\n\tconst left = message.complete || !hasBody(message) ? \"none\" : declared(message) <= DRAIN_LIMIT ? \"drain\" : \"close\";\n\tconst headers: string[] = [];\n\tfor (const [name, value] of answer.headers.lines()) headers.push(name, value);\n\tif (left === \"close\") headers.push(\"connection\", \"close\");\n\tres.writeHead(answer.status, headers);\n\tconst { body } = answer;\n\tif (body instanceof ReadableStream) await pump(body, res);\n\telse res.end(body ?? undefined);\n\tif (left === \"drain\") drain(message);\n}\n\n/** Writes `body` to `res` as the socket drains; a body that fails (reported by the component) destroys the connection. */\nasync function pump(body: ReadableStream<Uint8Array>, res: ServerResponse): Promise<void> {\n\tconst reader = body.getReader();\n\tconst cancel = (): void => void reader.cancel().catch(() => {});\n\tres.once(\"close\", cancel);\n\tfor (;;) {\n\t\tlet next: Awaited<ReturnType<typeof reader.read>>;\n\t\ttry {\n\t\t\tnext = await reader.read();\n\t\t} catch {\n\t\t\tres.destroy();\n\t\t\treturn;\n\t\t}\n\t\tif (next.done) break;\n\t\tif (res.destroyed) return;\n\t\tif (!res.write(next.value)) await drained(res);\n\t}\n\tres.removeListener(\"close\", cancel);\n\tres.end();\n}\n\n/** Resolves once `res` drained or closed. */\nfunction drained(res: ServerResponse): Promise<void> {\n\treturn new Promise((resolve) => {\n\t\tconst done = (): void => {\n\t\t\tres.removeListener(\"drain\", done);\n\t\t\tres.removeListener(\"close\", done);\n\t\t\tresolve();\n\t\t};\n\t\tres.once(\"drain\", done);\n\t\tres.once(\"close\", done);\n\t});\n}\n\n/** A request body as a Web stream: read as its consumer pulls (the socket paused meanwhile); a disconnect errors it. */\nfunction bodyOf(message: IncomingMessage): ReadableStream<Uint8Array> {\n\t// Whether the stream still takes chunks (not ended, errored or cancelled).\n\tlet open = true;\n\treturn new ReadableStream<Uint8Array>(\n\t\t{\n\t\t\tstart: (controller) => {\n\t\t\t\tmessage.on(\"data\", (chunk: Buffer) => {\n\t\t\t\t\tif (!open) return;\n\t\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t\t\tif ((controller.desiredSize ?? 0) <= 0) message.pause();\n\t\t\t\t});\n\t\t\t\tmessage.once(\"end\", () => {\n\t\t\t\t\tif (open) controller.close();\n\t\t\t\t\topen = false;\n\t\t\t\t});\n\t\t\t\tmessage.once(\"close\", () => {\n\t\t\t\t\tif (open && !message.complete) controller.error(new Error(\"http: the client disconnected\"));\n\t\t\t\t\topen = false;\n\t\t\t\t});\n\t\t\t\tmessage.pause();\n\t\t\t},\n\t\t\tpull: () => {\n\t\t\t\tmessage.resume();\n\t\t\t},\n\t\t\t// The rest stays unread: the response closes the connection (or drains a small rest).\n\t\t\tcancel: () => {\n\t\t\t\topen = false;\n\t\t\t\tmessage.pause();\n\t\t\t},\n\t\t},\n\t\tnew ByteLengthQueuingStrategy({ highWaterMark: DRAIN_LIMIT }),\n\t);\n}\n\n/** Reads and drops the rest of the body (at most 64 KiB); more than that, or an error, closes the connection. */\nfunction drain(message: IncomingMessage): void {\n\tlet read = 0;\n\tmessage.on(\"data\", (chunk: Buffer) => {\n\t\tread += chunk.byteLength;\n\t\tif (read > DRAIN_LIMIT) message.socket.destroy();\n\t});\n\tmessage.on(\"error\", () => message.socket.destroy());\n\tmessage.resume();\n}\n\n/** Whether `message` carries a body (a declared length above zero, or chunked). */\nfunction hasBody(message: IncomingMessage): boolean {\n\tconst length = message.headers[\"content-length\"];\n\tif (length !== undefined) return Number(length) > 0;\n\treturn message.headers[\"transfer-encoding\"] !== undefined;\n}\n\n/** The declared length of `message`'s body; infinite when chunked. */\nfunction declared(message: IncomingMessage): number {\n\tconst length = Number(message.headers[\"content-length\"] ?? Number.NaN);\n\treturn Number.isFinite(length) ? length : Number.POSITIVE_INFINITY;\n}\n"]}
@@ -0,0 +1,54 @@
1
+ import type { JsonValue } from "../../json.ts";
2
+ import type { Provenance } from "./admission.ts";
3
+ import type { Incoming } from "./incoming.ts";
4
+ /** A request as routes see it, once admitted: `origin` and `provenance` come only from admission. */
5
+ export interface HttpRequest {
6
+ readonly method: string;
7
+ /** The path, without the query, percent-encoded, its dot segments resolved (by the URL parser). */
8
+ readonly path: string;
9
+ /** The matched pattern's params, percent-decoded (`*` for the rest of a `/*` pattern). */
10
+ readonly params: Readonly<Record<string, string>>;
11
+ readonly query: URLSearchParams;
12
+ /** The request's headers; read only. */
13
+ readonly headers: Headers;
14
+ /** `http://<host>` on loopback, `https://<host>` for an allowed host, a relay's origin for a relayed request. */
15
+ readonly origin: string;
16
+ /** Where it came from (decision "The HTTP component's security baseline" (1), "Relays"). */
17
+ readonly provenance: Provenance;
18
+ /** The server's script nonce: a page's inline scripts carry it (`<script nonce="…">`), the CSP allows them. */
19
+ readonly nonce: string;
20
+ /** The body as JSON, at most `limit` bytes (1 MiB by default): `HttpFailure` 400 when malformed, 413 when larger. */
21
+ json(limit?: number): Promise<JsonValue>;
22
+ /** The body's chunks, at most `limit` bytes (1 MiB by default): `HttpFailure` 413 past it, 400 when cut short. */
23
+ body(limit?: number): AsyncIterable<Uint8Array>;
24
+ }
25
+ /** A failure that answers its request with `status` when it escapes a route (400 malformed, 413 too large). */
26
+ export declare class HttpFailure extends Error {
27
+ readonly status: number;
28
+ constructor(status: number, message: string);
29
+ }
30
+ /** A request over what the component reads of it; the component sets its params once it matched a route. */
31
+ export declare class WebRequest implements HttpRequest {
32
+ #private;
33
+ readonly method: string;
34
+ readonly path: string;
35
+ params: Readonly<Record<string, string>>;
36
+ readonly origin: string;
37
+ readonly provenance: Provenance;
38
+ readonly nonce: string;
39
+ constructor(incoming: Incoming, admitted: {
40
+ readonly origin: string;
41
+ readonly provenance: Provenance;
42
+ }, nonce: string);
43
+ /** The headers: on Chord's Node server the Web `Request` is made only when something reads them. */
44
+ get headers(): Headers;
45
+ get query(): URLSearchParams;
46
+ json(limit?: number): Promise<JsonValue>;
47
+ body(limit?: number): AsyncIterable<Uint8Array>;
48
+ }
49
+ /** A serialized URL's path (from the first `/` after the authority) and query (without `?`, no fragment). */
50
+ export declare function splitUrl(url: string): {
51
+ readonly path: string;
52
+ readonly search: string;
53
+ };
54
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/next-node/http/request.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,qGAAqG;AACrG,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,mGAAmG;IACnG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0FAA0F;IAC1F,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC,wCAAwC;IACxC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,iHAAiH;IACjH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,4FAA4F;IAC5F,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,+GAA+G;IAC/G,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,qHAAqH;IACrH,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACzC,kHAAkH;IAClH,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;CAChD;AAED,+GAA+G;AAC/G,qBAAa,WAAY,SAAQ,KAAK;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,YAAY,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAI1C;CACD;AAQD,4GAA4G;AAC5G,qBAAa,UAAW,YAAW,WAAW;;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAa;IACrD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAQvB,YACC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAA;KAAE,EACtE,KAAK,EAAE,MAAM,EAWb;IAED,oGAAoG;IACpG,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,KAAK,IAAI,eAAe,CAG3B;IAEK,IAAI,CAAC,KAAK,SAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CASpD;IAEM,IAAI,CAAC,KAAK,SAAgB,GAAG,aAAa,CAAC,UAAU,CAAC,CA6B5D;CACD;AAED,6GAA6G;AAC7G,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAYxF"}
@@ -0,0 +1,116 @@
1
+ // Requests (slice 10 §2, D4): what a route, a wrap, a socket handler and an authenticator see of an HTTP request (a
2
+ // Web `Request` once admitted), and its body, read only when asked: `json(limit?)` (1 MiB by default, malformed 400,
3
+ // too large 413) and `body(limit?)`, an async iterable of chunks.
4
+ /** A failure that answers its request with `status` when it escapes a route (400 malformed, 413 too large). */
5
+ export class HttpFailure extends Error {
6
+ status;
7
+ constructor(status, message) {
8
+ super(message);
9
+ this.name = "HttpFailure";
10
+ this.status = status;
11
+ }
12
+ }
13
+ /** What `json` and `body` read unless a route says otherwise: 1 MiB. */
14
+ const DEFAULT_LIMIT = 1024 * 1024;
15
+ /** The params of a request no pattern matched (yet). */
16
+ const NO_PARAMS = {};
17
+ /** A request over what the component reads of it; the component sets its params once it matched a route. */
18
+ export class WebRequest {
19
+ method;
20
+ path;
21
+ params = NO_PARAMS;
22
+ origin;
23
+ provenance;
24
+ nonce;
25
+ #incoming;
26
+ /** The query string (without `?`), parsed when first read. */
27
+ #search;
28
+ #query;
29
+ /** Whether a reader took the body (it is read once). */
30
+ #taken = false;
31
+ constructor(incoming, admitted, nonce) {
32
+ this.method = incoming.method;
33
+ // The URL is parsed and serialized already (dot segments resolved, `\` as `/`): only split it here.
34
+ const { path, search } = splitUrl(incoming.url);
35
+ this.path = path;
36
+ this.#search = search;
37
+ this.origin = admitted.origin;
38
+ this.provenance = admitted.provenance;
39
+ this.nonce = nonce;
40
+ this.#incoming = incoming;
41
+ }
42
+ /** The headers: on Chord's Node server the Web `Request` is made only when something reads them. */
43
+ get headers() {
44
+ return this.#incoming.request().headers;
45
+ }
46
+ get query() {
47
+ this.#query ??= new URLSearchParams(this.#search);
48
+ return this.#query;
49
+ }
50
+ async json(limit = DEFAULT_LIMIT) {
51
+ const chunks = [];
52
+ for await (const chunk of this.body(limit))
53
+ chunks.push(chunk);
54
+ const text = Buffer.concat(chunks).toString("utf8");
55
+ try {
56
+ return JSON.parse(text);
57
+ }
58
+ catch {
59
+ throw new HttpFailure(400, "the body is no JSON");
60
+ }
61
+ }
62
+ async *body(limit = DEFAULT_LIMIT) {
63
+ if (this.#taken)
64
+ throw new Error("request body: read twice");
65
+ this.#taken = true;
66
+ const declared = Number(this.#incoming.header("content-length") ?? Number.NaN);
67
+ if (declared > limit)
68
+ throw new HttpFailure(413, `the body is larger than ${limit} bytes`);
69
+ const stream = this.#incoming.request().body;
70
+ if (stream === null)
71
+ return;
72
+ const reader = stream.getReader();
73
+ let read = 0;
74
+ try {
75
+ for (;;) {
76
+ let next;
77
+ try {
78
+ next = await reader.read();
79
+ }
80
+ catch {
81
+ // A body cut short (a disconnect, a broken stream) is no body: a prefix must never parse as the
82
+ // whole (Sol's recheck N4: valid JSON then an error ran the route).
83
+ throw new HttpFailure(400, "the body could not be read whole");
84
+ }
85
+ if (next.done)
86
+ return;
87
+ read += next.value.byteLength;
88
+ if (read > limit)
89
+ throw new HttpFailure(413, `the body is larger than ${limit} bytes`);
90
+ yield next.value;
91
+ }
92
+ }
93
+ finally {
94
+ // Past the limit, or a reader that stopped early: the rest stays unread (its server closes the connection
95
+ // after the response); a cancel could reset the connection before the response is written.
96
+ reader.releaseLock();
97
+ }
98
+ }
99
+ }
100
+ /** A serialized URL's path (from the first `/` after the authority) and query (without `?`, no fragment). */
101
+ export function splitUrl(url) {
102
+ const authority = url.indexOf("//") + 2;
103
+ let start = url.indexOf("/", authority);
104
+ let end = url.indexOf("#", authority);
105
+ if (end < 0)
106
+ end = url.length;
107
+ const mark = url.indexOf("?", authority);
108
+ if (start < 0 || (mark >= 0 && start > mark))
109
+ start = -1;
110
+ const pathEnd = mark >= 0 && mark < end ? mark : end;
111
+ return {
112
+ path: start < 0 ? "/" : url.slice(start, pathEnd),
113
+ search: mark >= 0 && mark < end ? url.slice(mark + 1, end) : "",
114
+ };
115
+ }
116
+ //# sourceMappingURL=request.js.map