@earendil-works/chord 1.4.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 (820) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +79 -14
  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 +1 -1
  7. package/dist/context/index.d.ts.map +1 -1
  8. package/dist/context/index.js +1 -1
  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 +1 -1
  743. package/dist/output.d.ts.map +1 -1
  744. package/dist/output.js +4 -2
  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 +2 -0
  754. package/dist/sqlite/cloudflare.d.ts.map +1 -1
  755. package/dist/sqlite/cloudflare.js +10 -0
  756. package/dist/sqlite/cloudflare.js.map +1 -1
  757. package/dist/sqlite/database.d.ts +5 -2
  758. package/dist/sqlite/database.d.ts.map +1 -1
  759. package/dist/sqlite/database.js.map +1 -1
  760. package/dist/sqlite/node.d.ts +4 -1
  761. package/dist/sqlite/node.d.ts.map +1 -1
  762. package/dist/sqlite/node.js +22 -5
  763. package/dist/sqlite/node.js.map +1 -1
  764. package/dist/watch.d.ts +194 -0
  765. package/dist/watch.d.ts.map +1 -0
  766. package/dist/watch.js +383 -0
  767. package/dist/watch.js.map +1 -0
  768. package/dist/wire.d.ts +174 -193
  769. package/dist/wire.d.ts.map +1 -1
  770. package/dist/wire.js +81 -80
  771. package/dist/wire.js.map +1 -1
  772. package/docs/guide.md +15 -15
  773. package/docs/next/benchmarks.md +959 -0
  774. package/docs/next/decisions.md +2957 -0
  775. package/docs/next/dependencies/book.md +1671 -0
  776. package/docs/next/dependencies/index.html +2641 -0
  777. package/docs/next/dependencies/model.md +330 -0
  778. package/docs/next/design.md +2554 -0
  779. package/docs/next/durable-observers/book.md +432 -0
  780. package/docs/next/durable-observers/index.html +517 -0
  781. package/docs/next/flow-control/book.md +333 -0
  782. package/docs/next/flow-control/fold/index.html +265 -0
  783. package/docs/next/flow-control/index.html +548 -0
  784. package/docs/next/flow-control/window/index.html +228 -0
  785. package/docs/next/guide-plugins-hosts/book.md +607 -0
  786. package/docs/next/guide-plugins-hosts/index.html +652 -0
  787. package/docs/next/http-workers/book.md +378 -0
  788. package/docs/next/http-workers/index.html +515 -0
  789. package/docs/next/layer-1.md +311 -0
  790. package/docs/next/layer-2.md +216 -0
  791. package/docs/next/plugin-model/book.md +186 -0
  792. package/docs/next/plugin-model/index.html +310 -0
  793. package/docs/next/plugin-primer/book.md +273 -0
  794. package/docs/next/plugin-primer/index.html +430 -0
  795. package/docs/next/slice-1.md +236 -0
  796. package/docs/next/slice-10.md +285 -0
  797. package/docs/next/slice-11.md +93 -0
  798. package/docs/next/slice-2.md +174 -0
  799. package/docs/next/slice-3a.md +296 -0
  800. package/docs/next/slice-3b.md +197 -0
  801. package/docs/next/slice-4.md +146 -0
  802. package/docs/next/slice-4a.md +418 -0
  803. package/docs/next/slice-4b.md +208 -0
  804. package/docs/next/slice-5.md +281 -0
  805. package/docs/next/slice-6a.md +676 -0
  806. package/docs/next/slice-6b.md +332 -0
  807. package/docs/next/slice-7a.md +130 -0
  808. package/docs/next/slice-7b/book.md +608 -0
  809. package/docs/next/slice-7b/index.html +842 -0
  810. package/docs/next/slice-7b.md +255 -0
  811. package/docs/next/slice-7c.md +165 -0
  812. package/docs/next/slice-8.md +194 -0
  813. package/docs/next/slices.md +230 -0
  814. package/docs/next/store/book.md +665 -0
  815. package/docs/next/store/index.html +861 -0
  816. package/docs/next/store/walkthrough.md +193 -0
  817. package/docs/spec.md +9 -9
  818. package/docs/tutorial.md +26 -25
  819. package/package.json +22 -6
  820. package/src/delta/README.md +69 -0
@@ -0,0 +1,137 @@
1
+ // Process locks (slice 10 §3, Chord v1's `processLock`): one live worker per address. A lock is a listening socket the
2
+ // kernel owns for the holder's lifetime (an abstract socket on Linux and Android, a named pipe on Windows, a socket file
3
+ // elsewhere), so there is no race between two would-be holders; a socket file a crashed holder left fails closed (the
4
+ // error names it: a takeover would race another taker). A child finding the lock held waits
5
+ // without polling: it connects to the holder's socket, which the holder never answers, and tries again when that
6
+ // connection closes (the holder exited).
7
+ import { createHash } from "node:crypto";
8
+ import { unlinkSync } from "node:fs";
9
+ import { lstat, mkdir } from "node:fs/promises";
10
+ import { connect, createServer } from "node:net";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
13
+ /**
14
+ * Takes the lock `name`, waiting while another process holds it (until `context` aborts: rejects with its reason).
15
+ * Throws what listening throws besides "in use", and for a stale socket file (macOS, the BSDs) an error naming it.
16
+ */
17
+ export async function processLock(name, context) {
18
+ const key = createHash("sha256").update(name).digest("hex").slice(0, 32);
19
+ if (process.platform === "win32")
20
+ return lockAt({ kind: "pipe", address: `\\\\.\\pipe\\chord-lock-${key}` }, context);
21
+ if (process.platform === "linux" || process.platform === "android") {
22
+ return lockAt({ kind: "abstract", address: `\0chord-lock-${key}` }, context);
23
+ }
24
+ return lockAt({ kind: "file", address: await socketPath(`chord-lock-${key}.sock`) }, context);
25
+ }
26
+ /**
27
+ * Takes the lock at `lock`, waiting while it is held. A socket file nobody accepts on (a crashed holder's) fails closed:
28
+ * taking it over races another taker (two could both unlink and listen), so the error names the file to remove.
29
+ */
30
+ export async function lockAt(lock, context) {
31
+ const { address } = lock;
32
+ const file = lock.kind === "file";
33
+ // Connections are kept open, never answered: a waiter learns of the release when its connection closes.
34
+ const waiters = new Set();
35
+ const server = createServer((socket) => {
36
+ waiters.add(socket);
37
+ socket.on("error", () => { });
38
+ socket.once("close", () => waiters.delete(socket));
39
+ });
40
+ for (;;) {
41
+ context.abortSignal?.throwIfAborted();
42
+ if (await listened(server, address))
43
+ break;
44
+ const held = await waitWhileHeld(address, context);
45
+ if (!held && file) {
46
+ throw new Error(`lock: ${address} is a stale lock file (no process holds it); remove it if no worker runs`);
47
+ }
48
+ }
49
+ const removeFile = () => {
50
+ try {
51
+ unlinkSync(address);
52
+ }
53
+ catch {
54
+ // Gone already.
55
+ }
56
+ };
57
+ if (file)
58
+ process.once("exit", removeFile);
59
+ return {
60
+ release: () => new Promise((resolve, reject) => {
61
+ if (file)
62
+ process.removeListener("exit", removeFile);
63
+ server.close((error) => (error ? reject(error) : resolve()));
64
+ // Waiters see their connections close (and `close` waits for them).
65
+ for (const socket of waiters)
66
+ socket.destroy();
67
+ }),
68
+ };
69
+ }
70
+ /** Whether `server` now listens on `address`; `false` when it is in use. */
71
+ function listened(server, address) {
72
+ return new Promise((resolve, reject) => {
73
+ const failed = (error) => {
74
+ if (error.code === "EADDRINUSE")
75
+ resolve(false);
76
+ else
77
+ reject(error);
78
+ };
79
+ server.once("error", failed);
80
+ server.listen(address, () => {
81
+ server.removeListener("error", failed);
82
+ resolve(true);
83
+ });
84
+ });
85
+ }
86
+ /**
87
+ * Connects to the holder of `address` and resolves when that connection closes or the address is gone (`true`: try
88
+ * again), or with `false` when nobody accepts on it (a leftover socket file); `context`'s abort rejects.
89
+ */
90
+ function waitWhileHeld(address, context) {
91
+ return new Promise((resolve, reject) => {
92
+ const signal = context.abortSignal;
93
+ if (signal?.aborted) {
94
+ reject(signal.reason);
95
+ return;
96
+ }
97
+ const socket = connect(address);
98
+ const abort = () => {
99
+ socket.destroy();
100
+ reject(signal?.reason);
101
+ };
102
+ signal?.addEventListener("abort", abort, { once: true });
103
+ const settle = (held) => {
104
+ signal?.removeEventListener("abort", abort);
105
+ resolve(held);
106
+ };
107
+ let connected = false;
108
+ socket.once("connect", () => {
109
+ connected = true;
110
+ });
111
+ socket.on("error", (error) => {
112
+ if (!connected && error.code === "ECONNREFUSED")
113
+ settle(false);
114
+ });
115
+ socket.once("close", () => settle(true));
116
+ });
117
+ }
118
+ /** sun_path holds 104 bytes on macOS and the BSDs, the terminating NUL included. */
119
+ const MAX_SOCKET_PATH_BYTES = 103;
120
+ /**
121
+ * A lock socket's path: in the temporary directory, or, when that does not fit in sun_path (a deep TMPDIR), in a
122
+ * private per-user directory under /tmp that only its owner can reach.
123
+ */
124
+ async function socketPath(file) {
125
+ const preferred = join(tmpdir(), file);
126
+ if (Buffer.byteLength(preferred) <= MAX_SOCKET_PATH_BYTES)
127
+ return preferred;
128
+ const uid = process.getuid?.() ?? 0;
129
+ const directory = `/tmp/chord-lock-${uid}`;
130
+ await mkdir(directory, { mode: 0o700, recursive: true });
131
+ const stats = await lstat(directory);
132
+ if (!stats.isDirectory() || stats.uid !== uid || (stats.mode & 0o077) !== 0) {
133
+ throw new Error(`lock directory ${directory} must be a directory only its owner can access`);
134
+ }
135
+ return join(directory, file);
136
+ }
137
+ //# sourceMappingURL=lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lock.js","sourceRoot":"","sources":["../../../src/next-node/workers/lock.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,yHAAyH;AACzH,sHAAsH;AACtH,4FAA4F;AAC5F,iHAAiH;AACjH,yCAAyC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,YAAY,EAA4B,MAAM,UAAU,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM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C;QAC7E,MAAM,IAAI,KAAK,CAAC,kBAAkB,SAAS,gDAAgD,CAAC,CAAC;IAC9F,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["// Process locks (slice 10 §3, Chord v1's `processLock`): one live worker per address. A lock is a listening socket the\n// kernel owns for the holder's lifetime (an abstract socket on Linux and Android, a named pipe on Windows, a socket file\n// elsewhere), so there is no race between two would-be holders; a socket file a crashed holder left fails closed (the\n// error names it: a takeover would race another taker). A child finding the lock held waits\n// without polling: it connects to the holder's socket, which the holder never answers, and tries again when that\n// connection closes (the holder exited).\n\nimport { createHash } from \"node:crypto\";\nimport { unlinkSync } from \"node:fs\";\nimport { lstat, mkdir } from \"node:fs/promises\";\nimport { connect, createServer, type Server, type Socket } from \"node:net\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport type { Context } from \"../../context/index.ts\";\n\n/** A held lock: `release` frees it (the process's exit does too). */\nexport type ProcessLock = { release(): Promise<void> };\n\n/** Where a lock lives: an abstract socket (Linux, Android), a named pipe (Windows) or a socket file (elsewhere). */\nexport type LockAddress = { readonly kind: \"abstract\" | \"pipe\" | \"file\"; readonly address: string };\n\n/**\n * Takes the lock `name`, waiting while another process holds it (until `context` aborts: rejects with its reason).\n * Throws what listening throws besides \"in use\", and for a stale socket file (macOS, the BSDs) an error naming it.\n */\nexport async function processLock(name: string, context: Context): Promise<ProcessLock> {\n\tconst key = createHash(\"sha256\").update(name).digest(\"hex\").slice(0, 32);\n\tif (process.platform === \"win32\")\n\t\treturn lockAt({ kind: \"pipe\", address: `\\\\\\\\.\\\\pipe\\\\chord-lock-${key}` }, context);\n\tif (process.platform === \"linux\" || process.platform === \"android\") {\n\t\treturn lockAt({ kind: \"abstract\", address: `\\0chord-lock-${key}` }, context);\n\t}\n\treturn lockAt({ kind: \"file\", address: await socketPath(`chord-lock-${key}.sock`) }, context);\n}\n\n/**\n * Takes the lock at `lock`, waiting while it is held. A socket file nobody accepts on (a crashed holder's) fails closed:\n * taking it over races another taker (two could both unlink and listen), so the error names the file to remove.\n */\nexport async function lockAt(lock: LockAddress, context: Context): Promise<ProcessLock> {\n\tconst { address } = lock;\n\tconst file = lock.kind === \"file\";\n\t// Connections are kept open, never answered: a waiter learns of the release when its connection closes.\n\tconst waiters = new Set<Socket>();\n\tconst server = createServer((socket) => {\n\t\twaiters.add(socket);\n\t\tsocket.on(\"error\", () => {});\n\t\tsocket.once(\"close\", () => waiters.delete(socket));\n\t});\n\tfor (;;) {\n\t\tcontext.abortSignal?.throwIfAborted();\n\t\tif (await listened(server, address)) break;\n\t\tconst held = await waitWhileHeld(address, context);\n\t\tif (!held && file) {\n\t\t\tthrow new Error(`lock: ${address} is a stale lock file (no process holds it); remove it if no worker runs`);\n\t\t}\n\t}\n\tconst removeFile = (): void => {\n\t\ttry {\n\t\t\tunlinkSync(address);\n\t\t} catch {\n\t\t\t// Gone already.\n\t\t}\n\t};\n\tif (file) process.once(\"exit\", removeFile);\n\treturn {\n\t\trelease: () =>\n\t\t\tnew Promise<void>((resolve, reject) => {\n\t\t\t\tif (file) process.removeListener(\"exit\", removeFile);\n\t\t\t\tserver.close((error) => (error ? reject(error) : resolve()));\n\t\t\t\t// Waiters see their connections close (and `close` waits for them).\n\t\t\t\tfor (const socket of waiters) socket.destroy();\n\t\t\t}),\n\t};\n}\n\n/** Whether `server` now listens on `address`; `false` when it is in use. */\nfunction listened(server: Server, address: string): Promise<boolean> {\n\treturn new Promise<boolean>((resolve, reject) => {\n\t\tconst failed = (error: NodeJS.ErrnoException): void => {\n\t\t\tif (error.code === \"EADDRINUSE\") resolve(false);\n\t\t\telse reject(error);\n\t\t};\n\t\tserver.once(\"error\", failed);\n\t\tserver.listen(address, () => {\n\t\t\tserver.removeListener(\"error\", failed);\n\t\t\tresolve(true);\n\t\t});\n\t});\n}\n\n/**\n * Connects to the holder of `address` and resolves when that connection closes or the address is gone (`true`: try\n * again), or with `false` when nobody accepts on it (a leftover socket file); `context`'s abort rejects.\n */\nfunction waitWhileHeld(address: string, context: Context): Promise<boolean> {\n\treturn new Promise<boolean>((resolve, reject) => {\n\t\tconst signal = context.abortSignal;\n\t\tif (signal?.aborted) {\n\t\t\treject(signal.reason);\n\t\t\treturn;\n\t\t}\n\t\tconst socket = connect(address);\n\t\tconst abort = (): void => {\n\t\t\tsocket.destroy();\n\t\t\treject(signal?.reason);\n\t\t};\n\t\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\t\tconst settle = (held: boolean): void => {\n\t\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\t\tresolve(held);\n\t\t};\n\t\tlet connected = false;\n\t\tsocket.once(\"connect\", () => {\n\t\t\tconnected = true;\n\t\t});\n\t\tsocket.on(\"error\", (error: NodeJS.ErrnoException) => {\n\t\t\tif (!connected && error.code === \"ECONNREFUSED\") settle(false);\n\t\t});\n\t\tsocket.once(\"close\", () => settle(true));\n\t});\n}\n\n/** sun_path holds 104 bytes on macOS and the BSDs, the terminating NUL included. */\nconst MAX_SOCKET_PATH_BYTES = 103;\n\n/**\n * A lock socket's path: in the temporary directory, or, when that does not fit in sun_path (a deep TMPDIR), in a\n * private per-user directory under /tmp that only its owner can reach.\n */\nasync function socketPath(file: string): Promise<string> {\n\tconst preferred = join(tmpdir(), file);\n\tif (Buffer.byteLength(preferred) <= MAX_SOCKET_PATH_BYTES) return preferred;\n\tconst uid = process.getuid?.() ?? 0;\n\tconst directory = `/tmp/chord-lock-${uid}`;\n\tawait mkdir(directory, { mode: 0o700, recursive: true });\n\tconst stats = await lstat(directory);\n\tif (!stats.isDirectory() || stats.uid !== uid || (stats.mode & 0o077) !== 0) {\n\t\tthrow new Error(`lock directory ${directory} must be a directory only its owner can access`);\n\t}\n\treturn join(directory, file);\n}\n"]}
@@ -0,0 +1,46 @@
1
+ import { type Context } from "../../context/index.ts";
2
+ import type { JsonValue } from "../../json.ts";
3
+ import type { Address } from "../../next/contracts/index.ts";
4
+ import type { Principal } from "../../next/data/index.ts";
5
+ import type { Host, LoadReport, PluginFacet } from "../../next/host/index.ts";
6
+ import { type Link } from "../../next/link/index.ts";
7
+ import type { Watchable } from "../../watch.ts";
8
+ import type { HostPackages } from "../plugins/evaluate.ts";
9
+ import { type CrossedError } from "./control.ts";
10
+ /** What the app's function gets. */
11
+ export type WorkerStart = {
12
+ readonly address: Address;
13
+ /** The start data the server's `start(address)` gave. */
14
+ readonly start: JsonValue;
15
+ /** The link to the server: `connect` it before anything slow (`started` goes out then). */
16
+ readonly parent: Link;
17
+ readonly plugins: WorkerPlugins;
18
+ /** Registers a closer: closers run in reverse order at shutdown. */
19
+ onClose(closer: (context: Context) => Promise<void> | void): void;
20
+ };
21
+ /** The worker's plugins: the shipped scripts of its kind, loaded on its host; the server's reloads applied to it. */
22
+ export interface WorkerPlugins {
23
+ /** Loads `host` with the start message's scripts of `kind` and `core` (the app's own facets). */
24
+ load<P extends Principal>(host: Host<P>, options: {
25
+ readonly kind: string;
26
+ readonly core: readonly PluginFacet<P>[];
27
+ }, context: Context): Promise<LoadReport>;
28
+ }
29
+ /** What the app's function returns: extra keep-alive counts (busy while any is nonzero). */
30
+ export type WorkerResult = {
31
+ readonly busy?: Watchable<Readonly<Record<string, number>>>;
32
+ };
33
+ /** What `workerMain` takes besides the app's function. */
34
+ export type WorkerMainOptions = {
35
+ /** The host packages by specifier: this process's own instances (functions cannot cross IPC). */
36
+ readonly hostPackages: HostPackages;
37
+ /** What crosses as `fatal` for an error (never the original message unless this returns it). */
38
+ readonly redact: (error: unknown) => CrossedError;
39
+ readonly onError: (error: unknown) => void;
40
+ };
41
+ /**
42
+ * Runs this process as a worker: `fn` once the start message arrived and the lock is taken. An uncaught error or a
43
+ * throwing `fn` sends `fatal` (redacted) and exits.
44
+ */
45
+ export declare function workerMain(fn: (start: WorkerStart, context: Context) => Promise<WorkerResult | undefined>, options: WorkerMainOptions): void;
46
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"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WAAW,CAAC,CAAC,CAAC,EAAE,CAAA;KAAE,EAC5E,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,UAAU,CAAC,CAAC;CACvB;AAED,4FAA4F;AAC5F,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AAE3F,0DAA0D;AAC1D,MAAM,MAAM,iBAAiB,GAAG;IAC/B,iGAAiG;IACjG,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,gGAAgG;IAChG,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,YAAY,CAAC;IAClD,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,UAAU,CACzB,EAAE,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,EAC/E,OAAO,EAAE,iBAAiB,GACxB,IAAI,CAGN"}
@@ -0,0 +1,230 @@
1
+ // The worker's side (slice 10 §3): `workerMain` reads the start message, takes the address's lock, makes the link to
2
+ // the server (`started` goes out when the app's host listens on it), runs the app's function with a plugin runtime over
3
+ // the shipped scripts, reports `ready` and each idle flip, applies reloads, and on `shutdown`, the parent's disconnect,
4
+ // `SIGTERM` or `SIGINT` aborts its context, runs the app's closers in reverse order and exits.
5
+ import { BACKGROUND_CONTEXT, withAbortSignal } from "../../context/index.js";
6
+ import { ipcLink } from "../../next/link/index.js";
7
+ import { createPluginRuntime } from "../plugins/runtime.js";
8
+ import { controlOf, crossed, crossedReport, envelope, } from "./control.js";
9
+ import { processLock } from "./lock.js";
10
+ /**
11
+ * Runs this process as a worker: `fn` once the start message arrived and the lock is taken. An uncaught error or a
12
+ * throwing `fn` sends `fatal` (redacted) and exits.
13
+ */
14
+ export function workerMain(fn, options) {
15
+ // `process` is the IPC port of a forked child.
16
+ new Worker(process, options).run(fn);
17
+ }
18
+ /** How long a shutdown's closers get before the worker exits anyway: 3 s. */
19
+ const FORCED_EXIT = 3_000;
20
+ class Worker {
21
+ #port;
22
+ #options;
23
+ #controller = new AbortController();
24
+ #context;
25
+ #closers = [];
26
+ #start = Promise.withResolvers();
27
+ /** Reloads that arrived, applied one after another once `fn` returned. */
28
+ #reloads = [];
29
+ #loaded;
30
+ #ready = false;
31
+ #reloading = false;
32
+ #busy;
33
+ /** The last idle state sent. */
34
+ #idle;
35
+ #stopping = false;
36
+ constructor(port, options) {
37
+ this.#port = port;
38
+ this.#options = options;
39
+ this.#context = withAbortSignal(this.#controller.signal, BACKGROUND_CONTEXT);
40
+ port.on("message", (message) => this.#message(controlOf(message)));
41
+ port.on("disconnect", () => void this.#shutdown());
42
+ for (const signal of ["SIGTERM", "SIGINT"])
43
+ process.once(signal, () => void this.#shutdown());
44
+ process.once("uncaughtException", (error) => this.#fatal(error));
45
+ process.once("unhandledRejection", (error) => this.#fatal(error));
46
+ }
47
+ /** Takes the lock, makes the parent link, runs `fn`, then reports `ready` and applies reloads. */
48
+ run(fn) {
49
+ // A throw while shutting down is the shutdown's own cancellation (its `ctx` aborted): no fatal, the closers run.
50
+ void this.#run(fn).catch((error) => {
51
+ if (!this.#stopping)
52
+ this.#fatal(error);
53
+ });
54
+ }
55
+ async #run(fn) {
56
+ const message = await this.#start.promise;
57
+ await processLock(message.lock, this.#context);
58
+ const parent = new ParentLink(ipcLink(this.#port), () => this.#send({ kind: "started" }));
59
+ const runtime = createPluginRuntime();
60
+ const plugins = {
61
+ load: async (host, { kind, core }, context) => {
62
+ this.#loaded = { host: host, runtime };
63
+ return runtime.load(host, { kind, core, scripts: message.scripts, modules: this.#options.hostPackages }, context);
64
+ },
65
+ };
66
+ let report = { failed: [] };
67
+ const loading = {
68
+ load: async (host, options, context) => {
69
+ report = await plugins.load(host, options, context);
70
+ return report;
71
+ },
72
+ };
73
+ const start = {
74
+ address: message.address,
75
+ start: message.start,
76
+ parent,
77
+ plugins: loading,
78
+ onClose: (closer) => void this.#closers.push(closer),
79
+ };
80
+ const result = await fn(start, this.#context);
81
+ if (this.#stopping)
82
+ return;
83
+ this.#busy = result?.busy;
84
+ await this.#follow();
85
+ this.#ready = true;
86
+ const failed = new Set(report.failed.map(({ plugin }) => plugin));
87
+ const added = message.scripts.map(({ plugin }) => plugin.name).filter((name) => !failed.has(name));
88
+ const loaded = { plugins: { added, changed: [], removed: [] }, failed: report.failed, objects: [] };
89
+ this.#idle = this.#isIdle();
90
+ this.#send({ kind: "ready", idle: this.#idle, report: crossedReport(loaded) });
91
+ void this.#applyReloads();
92
+ }
93
+ /** Follows the host's activity and the app's `busy`: each idle flip is reported. */
94
+ async #follow() {
95
+ const sources = [];
96
+ if (this.#loaded !== undefined)
97
+ sources.push(this.#loaded.host.activity);
98
+ if (this.#busy !== undefined)
99
+ sources.push(this.#busy);
100
+ for (const source of sources) {
101
+ const watch = await source.watch(this.#context);
102
+ watch.start(async () => this.#flip());
103
+ }
104
+ }
105
+ /** Whether every count is zero: the host's references, jobs and lingering objects, the app's `busy`, no reload. */
106
+ #isIdle() {
107
+ if (this.#reloading)
108
+ return false;
109
+ const activity = this.#loaded?.host.activity.value;
110
+ if (activity !== undefined && activity.references + activity.jobs + activity.lingering > 0)
111
+ return false;
112
+ return Object.values(this.#busy?.value ?? {}).every((count) => count === 0);
113
+ }
114
+ /** Reports the idle state when it flipped (after `ready`). */
115
+ #flip() {
116
+ if (!this.#ready)
117
+ return;
118
+ const idle = this.#isIdle();
119
+ if (idle === this.#idle)
120
+ return;
121
+ this.#idle = idle;
122
+ this.#send({ kind: "idle", idle });
123
+ }
124
+ /** A control message from the server. */
125
+ #message(message) {
126
+ if (message === undefined)
127
+ return;
128
+ switch (message.kind) {
129
+ case "start":
130
+ this.#start.resolve(message);
131
+ return;
132
+ case "shutdown":
133
+ void this.#shutdown();
134
+ return;
135
+ case "reload":
136
+ // A worker shutting down applies no reload (its exit answers it).
137
+ if (this.#stopping)
138
+ return;
139
+ this.#reloads.push(message.scripts);
140
+ if (this.#ready)
141
+ void this.#applyReloads();
142
+ }
143
+ }
144
+ /** Applies the reloads that arrived, one after another, each answered `reloaded`. */
145
+ async #applyReloads() {
146
+ if (this.#reloading || this.#reloads.length === 0)
147
+ return;
148
+ const loaded = this.#loaded;
149
+ this.#reloading = true;
150
+ this.#flip();
151
+ for (let scripts = this.#reloads.shift(); scripts !== undefined && !this.#stopping; scripts = this.#reloads.shift()) {
152
+ if (loaded === undefined) {
153
+ this.#send({ kind: "reloaded", error: { message: "worker: plugins.load was never called" } });
154
+ continue;
155
+ }
156
+ try {
157
+ const report = await loaded.runtime.reload(loaded.host, scripts, this.#context);
158
+ this.#send({ kind: "reloaded", report: crossedReport(report) });
159
+ }
160
+ catch (error) {
161
+ this.#send({ kind: "reloaded", error: crossed(error) });
162
+ }
163
+ }
164
+ this.#reloading = false;
165
+ this.#flip();
166
+ }
167
+ /** Aborts the context, runs the closers in reverse order and exits (forced after 3 s). */
168
+ async #shutdown() {
169
+ if (this.#stopping)
170
+ return;
171
+ this.#stopping = true;
172
+ this.#controller.abort(new Error("worker: shutting down"));
173
+ setTimeout(() => process.exit(0), FORCED_EXIT).unref();
174
+ const context = BACKGROUND_CONTEXT;
175
+ for (const closer of this.#closers.reverse()) {
176
+ try {
177
+ await closer(context);
178
+ }
179
+ catch (error) {
180
+ this.#options.onError(error);
181
+ }
182
+ }
183
+ process.exit(0);
184
+ }
185
+ /** Sends `fatal` with the redacted error, then exits. */
186
+ #fatal(error) {
187
+ this.#options.onError(error);
188
+ let redacted;
189
+ try {
190
+ redacted = this.#options.redact(error);
191
+ }
192
+ catch {
193
+ redacted = { message: "worker: fatal error" };
194
+ }
195
+ if (!this.#port.connected)
196
+ process.exit(1);
197
+ // `process.send` takes a callback once the message is out.
198
+ process.send(envelope({ kind: "fatal", error: redacted }), () => process.exit(1));
199
+ }
200
+ /** Sends a control message; dropped when the server is gone. */
201
+ #send(message) {
202
+ if (this.#port.connected)
203
+ process.send?.(envelope(message), undefined, undefined, () => { });
204
+ }
205
+ }
206
+ /** The link to the server as the app gets it: `started` goes out when the app's host sets its listener (`connect`). */
207
+ class ParentLink {
208
+ #inner;
209
+ #started;
210
+ constructor(inner, started) {
211
+ this.#inner = inner;
212
+ this.#started = started;
213
+ }
214
+ send(message) {
215
+ this.#inner.send(message);
216
+ }
217
+ onMessage(listener) {
218
+ this.#inner.onMessage(listener);
219
+ const started = this.#started;
220
+ this.#started = undefined;
221
+ started?.();
222
+ }
223
+ close() {
224
+ this.#inner.close();
225
+ }
226
+ onClose(listener) {
227
+ this.#inner.onClose(listener);
228
+ }
229
+ }
230
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/next-node/workers/main.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,wHAAwH;AACxH,wHAAwH;AACxH,+FAA+F;AAE/F,OAAO,EAAE,kBAAkB,EAAgB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAK3F,OAAO,EAAgB,OAAO,EAAa,MAAM,0BAA0B,CAAC;AAG5E,OAAO,EAAE,mBAAmB,EAAqB,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAEN,SAAS,EACT,OAAO,EACP,aAAa,EACb,QAAQ,GAGR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAoCxC;;;GAGG;AACH,MAAM,UAAU,UAAU,CACzB,EAA+E,EAC/E,OAA0B;IAE1B,+CAA+C;IAC/C,IAAI,MAAM,CAAC,OAA6B,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED,6EAA6E;AAC7E,MAAM,WAAW,GAAG,KAAK,CAAC;AAE1B,MAAM,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H;AACvH,MAAM,UAAU;IACN,MAAM,CAAO;IACtB,QAAQ,CAA2B;IAEnC,YAAY,KAAW,EAAE,OAAmB;QAC3C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,IAAI,CAAC,OAAmB;QACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,SAAS,CAAC,QAAuC;QAChD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAChC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC1B,OAAO,EAAE,EAAE,CAAC;IACb,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,OAAO,CAAC,QAAoB;QAC3B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;CACD","sourcesContent":["// The worker's side (slice 10 §3): `workerMain` reads the start message, takes the address's lock, makes the link to\n// the server (`started` goes out when the app's host listens on it), runs the app's function with a plugin runtime over\n// the shipped scripts, reports `ready` and each idle flip, applies reloads, and on `shutdown`, the parent's disconnect,\n// `SIGTERM` or `SIGINT` aborts its context, runs the app's closers in reverse order and exits.\n\nimport { BACKGROUND_CONTEXT, type Context, withAbortSignal } from \"../../context/index.ts\";\nimport type { JsonValue } from \"../../json.ts\";\nimport type { Address } from \"../../next/contracts/index.ts\";\nimport type { Principal } from \"../../next/data/index.ts\";\nimport type { Host, LoadReport, PluginFacet, ReloadReport } from \"../../next/host/index.ts\";\nimport { type IpcPort, ipcLink, type Link } from \"../../next/link/index.ts\";\nimport type { Watchable } from \"../../watch.ts\";\nimport type { HostPackages } from \"../plugins/evaluate.ts\";\nimport { createPluginRuntime, type PluginScript } from \"../plugins/runtime.ts\";\nimport {\n\ttype CrossedError,\n\tcontrolOf,\n\tcrossed,\n\tcrossedReport,\n\tenvelope,\n\ttype FromWorker,\n\ttype ToWorker,\n} from \"./control.ts\";\nimport { processLock } from \"./lock.ts\";\n\n/** What the app's function gets. */\nexport type WorkerStart = {\n\treadonly address: Address;\n\t/** The start data the server's `start(address)` gave. */\n\treadonly start: JsonValue;\n\t/** The link to the server: `connect` it before anything slow (`started` goes out then). */\n\treadonly parent: Link;\n\treadonly plugins: WorkerPlugins;\n\t/** Registers a closer: closers run in reverse order at shutdown. */\n\tonClose(closer: (context: Context) => Promise<void> | void): void;\n};\n\n/** The worker's plugins: the shipped scripts of its kind, loaded on its host; the server's reloads applied to it. */\nexport interface WorkerPlugins {\n\t/** Loads `host` with the start message's scripts of `kind` and `core` (the app's own facets). */\n\tload<P extends Principal>(\n\t\thost: Host<P>,\n\t\toptions: { readonly kind: string; readonly core: readonly PluginFacet<P>[] },\n\t\tcontext: Context,\n\t): Promise<LoadReport>;\n}\n\n/** What the app's function returns: extra keep-alive counts (busy while any is nonzero). */\nexport type WorkerResult = { readonly busy?: Watchable<Readonly<Record<string, number>>> };\n\n/** What `workerMain` takes besides the app's function. */\nexport type WorkerMainOptions = {\n\t/** The host packages by specifier: this process's own instances (functions cannot cross IPC). */\n\treadonly hostPackages: HostPackages;\n\t/** What crosses as `fatal` for an error (never the original message unless this returns it). */\n\treadonly redact: (error: unknown) => CrossedError;\n\treadonly onError: (error: unknown) => void;\n};\n\n/**\n * Runs this process as a worker: `fn` once the start message arrived and the lock is taken. An uncaught error or a\n * throwing `fn` sends `fatal` (redacted) and exits.\n */\nexport function workerMain(\n\tfn: (start: WorkerStart, context: Context) => Promise<WorkerResult | undefined>,\n\toptions: WorkerMainOptions,\n): void {\n\t// `process` is the IPC port of a forked child.\n\tnew Worker(process as unknown as IpcPort, options).run(fn);\n}\n\n/** How long a shutdown's closers get before the worker exits anyway: 3 s. */\nconst FORCED_EXIT = 3_000;\n\nclass Worker {\n\treadonly #port: IpcPort;\n\treadonly #options: WorkerMainOptions;\n\treadonly #controller = new AbortController();\n\treadonly #context: Context;\n\treadonly #closers: ((context: Context) => Promise<void> | void)[] = [];\n\treadonly #start = Promise.withResolvers<Extract<ToWorker, { readonly kind: \"start\" }>>();\n\t/** Reloads that arrived, applied one after another once `fn` returned. */\n\treadonly #reloads: (readonly PluginScript[])[] = [];\n\t#loaded: { readonly host: Host<Principal>; readonly runtime: ReturnType<typeof createPluginRuntime> } | undefined;\n\t#ready = false;\n\t#reloading = false;\n\t#busy: Watchable<Readonly<Record<string, number>>> | undefined;\n\t/** The last idle state sent. */\n\t#idle: boolean | undefined;\n\t#stopping = false;\n\n\tconstructor(port: IpcPort, options: WorkerMainOptions) {\n\t\tthis.#port = port;\n\t\tthis.#options = options;\n\t\tthis.#context = withAbortSignal(this.#controller.signal, BACKGROUND_CONTEXT);\n\t\tport.on(\"message\", (message) => this.#message(controlOf<ToWorker>(message)));\n\t\tport.on(\"disconnect\", () => void this.#shutdown());\n\t\tfor (const signal of [\"SIGTERM\", \"SIGINT\"] as const) process.once(signal, () => void this.#shutdown());\n\t\tprocess.once(\"uncaughtException\", (error) => this.#fatal(error));\n\t\tprocess.once(\"unhandledRejection\", (error) => this.#fatal(error));\n\t}\n\n\t/** Takes the lock, makes the parent link, runs `fn`, then reports `ready` and applies reloads. */\n\trun(fn: (start: WorkerStart, context: Context) => Promise<WorkerResult | undefined>): void {\n\t\t// A throw while shutting down is the shutdown's own cancellation (its `ctx` aborted): no fatal, the closers run.\n\t\tvoid this.#run(fn).catch((error: unknown) => {\n\t\t\tif (!this.#stopping) this.#fatal(error);\n\t\t});\n\t}\n\n\tasync #run(fn: (start: WorkerStart, context: Context) => Promise<WorkerResult | undefined>): Promise<void> {\n\t\tconst message = await this.#start.promise;\n\t\tawait processLock(message.lock, this.#context);\n\t\tconst parent = new ParentLink(ipcLink(this.#port), () => this.#send({ kind: \"started\" }));\n\t\tconst runtime = createPluginRuntime();\n\t\tconst plugins: WorkerPlugins = {\n\t\t\tload: async (host, { kind, core }, context) => {\n\t\t\t\tthis.#loaded = { host: host as unknown as Host<Principal>, runtime };\n\t\t\t\treturn runtime.load(\n\t\t\t\t\thost,\n\t\t\t\t\t{ kind, core, scripts: message.scripts, modules: this.#options.hostPackages },\n\t\t\t\t\tcontext,\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t\tlet report: LoadReport = { failed: [] };\n\t\tconst loading: WorkerPlugins = {\n\t\t\tload: async (host, options, context) => {\n\t\t\t\treport = await plugins.load(host, options, context);\n\t\t\t\treturn report;\n\t\t\t},\n\t\t};\n\t\tconst start: WorkerStart = {\n\t\t\taddress: message.address,\n\t\t\tstart: message.start,\n\t\t\tparent,\n\t\t\tplugins: loading,\n\t\t\tonClose: (closer) => void this.#closers.push(closer),\n\t\t};\n\t\tconst result = await fn(start, this.#context);\n\t\tif (this.#stopping) return;\n\t\tthis.#busy = result?.busy;\n\t\tawait this.#follow();\n\t\tthis.#ready = true;\n\t\tconst failed = new Set(report.failed.map(({ plugin }) => plugin));\n\t\tconst added = message.scripts.map(({ plugin }) => plugin.name).filter((name) => !failed.has(name));\n\t\tconst loaded: ReloadReport = { plugins: { added, changed: [], removed: [] }, failed: report.failed, objects: [] };\n\t\tthis.#idle = this.#isIdle();\n\t\tthis.#send({ kind: \"ready\", idle: this.#idle, report: crossedReport(loaded) });\n\t\tvoid this.#applyReloads();\n\t}\n\n\t/** Follows the host's activity and the app's `busy`: each idle flip is reported. */\n\tasync #follow(): Promise<void> {\n\t\tconst sources: Watchable<unknown>[] = [];\n\t\tif (this.#loaded !== undefined) sources.push(this.#loaded.host.activity);\n\t\tif (this.#busy !== undefined) sources.push(this.#busy);\n\t\tfor (const source of sources) {\n\t\t\tconst watch = await source.watch(this.#context);\n\t\t\twatch.start(async () => this.#flip());\n\t\t}\n\t}\n\n\t/** Whether every count is zero: the host's references, jobs and lingering objects, the app's `busy`, no reload. */\n\t#isIdle(): boolean {\n\t\tif (this.#reloading) return false;\n\t\tconst activity = this.#loaded?.host.activity.value;\n\t\tif (activity !== undefined && activity.references + activity.jobs + activity.lingering > 0) return false;\n\t\treturn Object.values(this.#busy?.value ?? {}).every((count) => count === 0);\n\t}\n\n\t/** Reports the idle state when it flipped (after `ready`). */\n\t#flip(): void {\n\t\tif (!this.#ready) return;\n\t\tconst idle = this.#isIdle();\n\t\tif (idle === this.#idle) return;\n\t\tthis.#idle = idle;\n\t\tthis.#send({ kind: \"idle\", idle });\n\t}\n\n\t/** A control message from the server. */\n\t#message(message: ToWorker | undefined): void {\n\t\tif (message === undefined) return;\n\t\tswitch (message.kind) {\n\t\t\tcase \"start\":\n\t\t\t\tthis.#start.resolve(message);\n\t\t\t\treturn;\n\t\t\tcase \"shutdown\":\n\t\t\t\tvoid this.#shutdown();\n\t\t\t\treturn;\n\t\t\tcase \"reload\":\n\t\t\t\t// A worker shutting down applies no reload (its exit answers it).\n\t\t\t\tif (this.#stopping) return;\n\t\t\t\tthis.#reloads.push(message.scripts);\n\t\t\t\tif (this.#ready) void this.#applyReloads();\n\t\t}\n\t}\n\n\t/** Applies the reloads that arrived, one after another, each answered `reloaded`. */\n\tasync #applyReloads(): Promise<void> {\n\t\tif (this.#reloading || this.#reloads.length === 0) return;\n\t\tconst loaded = this.#loaded;\n\t\tthis.#reloading = true;\n\t\tthis.#flip();\n\t\tfor (\n\t\t\tlet scripts = this.#reloads.shift();\n\t\t\tscripts !== undefined && !this.#stopping;\n\t\t\tscripts = this.#reloads.shift()\n\t\t) {\n\t\t\tif (loaded === undefined) {\n\t\t\t\tthis.#send({ kind: \"reloaded\", error: { message: \"worker: plugins.load was never called\" } });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst report = await loaded.runtime.reload(loaded.host, scripts, this.#context);\n\t\t\t\tthis.#send({ kind: \"reloaded\", report: crossedReport(report) });\n\t\t\t} catch (error) {\n\t\t\t\tthis.#send({ kind: \"reloaded\", error: crossed(error) });\n\t\t\t}\n\t\t}\n\t\tthis.#reloading = false;\n\t\tthis.#flip();\n\t}\n\n\t/** Aborts the context, runs the closers in reverse order and exits (forced after 3 s). */\n\tasync #shutdown(): Promise<void> {\n\t\tif (this.#stopping) return;\n\t\tthis.#stopping = true;\n\t\tthis.#controller.abort(new Error(\"worker: shutting down\"));\n\t\tsetTimeout(() => process.exit(0), FORCED_EXIT).unref();\n\t\tconst context = BACKGROUND_CONTEXT;\n\t\tfor (const closer of this.#closers.reverse()) {\n\t\t\ttry {\n\t\t\t\tawait closer(context);\n\t\t\t} catch (error) {\n\t\t\t\tthis.#options.onError(error);\n\t\t\t}\n\t\t}\n\t\tprocess.exit(0);\n\t}\n\n\t/** Sends `fatal` with the redacted error, then exits. */\n\t#fatal(error: unknown): void {\n\t\tthis.#options.onError(error);\n\t\tlet redacted: CrossedError;\n\t\ttry {\n\t\t\tredacted = this.#options.redact(error);\n\t\t} catch {\n\t\t\tredacted = { message: \"worker: fatal error\" };\n\t\t}\n\t\tif (!this.#port.connected) process.exit(1);\n\t\t// `process.send` takes a callback once the message is out.\n\t\t(process.send as (message: unknown, callback: () => void) => void)(\n\t\t\tenvelope({ kind: \"fatal\", error: redacted }),\n\t\t\t() => process.exit(1),\n\t\t);\n\t}\n\n\t/** Sends a control message; dropped when the server is gone. */\n\t#send(message: FromWorker): void {\n\t\tif (this.#port.connected) process.send?.(envelope(message), undefined, undefined, () => {});\n\t}\n}\n\n/** The link to the server as the app gets it: `started` goes out when the app's host sets its listener (`connect`). */\nclass ParentLink implements Link {\n\treadonly #inner: Link;\n\t#started: (() => void) | undefined;\n\n\tconstructor(inner: Link, started: () => void) {\n\t\tthis.#inner = inner;\n\t\tthis.#started = started;\n\t}\n\n\tsend(message: Uint8Array): void {\n\t\tthis.#inner.send(message);\n\t}\n\n\tonMessage(listener: (message: Uint8Array) => void): void {\n\t\tthis.#inner.onMessage(listener);\n\t\tconst started = this.#started;\n\t\tthis.#started = undefined;\n\t\tstarted?.();\n\t}\n\n\tclose(): void {\n\t\tthis.#inner.close();\n\t}\n\n\tonClose(listener: () => void): void {\n\t\tthis.#inner.onClose(listener);\n\t}\n}\n"]}
@@ -0,0 +1,42 @@
1
+ import type { Link } from "../../next/link/index.ts";
2
+ import { type FromWorker, type ToWorker } from "./control.ts";
3
+ /** How a worker process is started: the bootstrap options of the workers component. */
4
+ export type ForkOptions = {
5
+ readonly entry: string;
6
+ readonly execArgv?: readonly string[];
7
+ readonly env?: Readonly<Record<string, string>>;
8
+ /** Its output; without it, mirrored to this process's own. */
9
+ readonly onOutput?: (stream: "stdout" | "stderr", chunk: Uint8Array) => void;
10
+ };
11
+ /** How a worker process ended. */
12
+ export type Exit = {
13
+ readonly code: number | null;
14
+ readonly signal: NodeJS.Signals | null;
15
+ };
16
+ /** What a worker process tells as it happens. */
17
+ export type ProcessEvents = {
18
+ readonly control: (message: FromWorker) => void;
19
+ /** Its link was closed by this side (the heartbeat, a protocol error) while the child may live. */
20
+ readonly linkLost: () => void;
21
+ /** Its link was closed by the child's side (it exits, or it closed its IPC channel and may live on). */
22
+ readonly linkClosed: () => void;
23
+ readonly exited: (exit: Exit) => void;
24
+ };
25
+ /** One forked worker process. */
26
+ export declare class WorkerProcess {
27
+ #private;
28
+ readonly pid: number;
29
+ readonly startedAt: number;
30
+ /** The link to the child's host, made at the fork. */
31
+ readonly link: Link;
32
+ /** Resolves with its exit; every process it spawned is killed then. */
33
+ readonly exited: Promise<Exit>;
34
+ constructor(options: ForkOptions, events: ProcessEvents);
35
+ /** The last bytes it wrote to stderr, if any. */
36
+ get stderrTail(): string | undefined;
37
+ /** Sends a control message; dropped when the child is gone (its exit tells). */
38
+ send(message: ToWorker): void;
39
+ /** Kills the child and every process it spawned. */
40
+ kill(): void;
41
+ }
42
+ //# sourceMappingURL=process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../../src/next-node/workers/process.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAA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