@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 @@
1
+ {"version":3,"file":"import.js","sourceRoot":"","sources":["../../../src/next/store/import.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,qHAAqH;AACrH,iHAAiH;AACjH,qHAAqH;AACrH,sHAAsH;AACtH,sBAAsB;AAEtB,OAAO,EAAE,gBAAgB,EAAgB,MAAM,wBAAwB,CAAC;AAExE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAA0C,SAAS,EAAE,MAAM,cAAc,CAAC;AAEjG,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAgB,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAiC,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAChC,OAAgB,EAChB,KAAiD,EACjD,OAAgB,EAChB,OAAO,GAAiB,EAAE;IAE1B,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;IACvB,IAAI,CAAC;QACJ,OAAO,CAAC,WAAW,EAAE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AAM,KAAK,CAAC;gBAC/C,MAAM,IAAI,UAAU,CACnB,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,EAAE,EAC/C,EAAE,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,CACrC,CAAC;YACH,CAAC;YACD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;gBACjB,IAAI,GAAG,IAAI,CAAC;gBACZ,OAAO;YACR,CAAC;YACD,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;IACF,CAAC;YAAS,CAAC;QACV,oEAAoE;QACpE,IAAI,CAAC,IAAI;YAAE,KAAK,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACtE,CAAC;AACF,CAAC","sourcesContent":["// `importStore(backend, parts, ctx, { outbox? })` (slice 6a §13, rules 12, 24, 25): a store made from an archive, a\n// trust boundary. Every part is checked against the archive schema, its place in the archive's order and its content\n// (names, rows against their table's recorded columns, ids and seqs, lifetimes at one address never overlapping,\n// revisions in seq order from a base, versions, duplicates, the `end` count, the manifest); everything is applied in\n// one backend transaction with the applier, so a refused import leaves the backend as it was. An input that stalls is\n// cancelled by `ctx`.\n\nimport { awaitWithContext, type Context } from \"../../context/index.ts\";\nimport type { SqliteDatabase, SqliteExecutor } from \"../../sqlite/index.ts\";\nimport { ChordError } from \"../data/index.ts\";\nimport { invalid } from \"../data/internal.ts\";\nimport { IdAllocator } from \"./allocator.ts\";\nimport { applyWrite } from \"./applier.ts\";\nimport { ARCHIVE_FORMAT, type ArchiveManifest, type ArchivePart, checkPart } from \"./archive.ts\";\nimport type { Backend } from \"./backend.ts\";\nimport { readCatalog, writeCatalog } from \"./catalog.ts\";\nimport type { DocumentRecord } from \"./engine.ts\";\nimport { applyStoreSchema, type MetaRow, STORE_SCHEMA, TABLES } from \"./schema.ts\";\nimport { Step } from \"./step.ts\";\nimport { ChordStore, type Store, type StoreOptions } from \"./store.ts\";\nimport { storedText } from \"./text.ts\";\n\n/**\n * A store holding the archive `parts` on `backend`, which must not hold a store yet: at the manifest's `lastSeq`, its\n * outbox (when `options.outbox`) starting after it. A refused archive, a stalled input cancelled by `context` or a\n * backend error rejects; the backend is closed then (rule 12).\n */\nexport async function importStore(\n\tbackend: Backend,\n\tparts: AsyncIterable<unknown> | Iterable<unknown>,\n\tcontext: Context,\n\toptions: StoreOptions = {},\n): Promise<Store> {\n\tconst { db } = backend;\n\ttry {\n\t\tcontext.abortSignal?.throwIfAborted();\n\t\tconst existing = await db.get(`SELECT name FROM sqlite_master WHERE name = ?`, TABLES.meta);\n\t\tif (existing !== undefined) throw invalid(\"args\", \"import: the backend holds a store already\");\n\t\tconst meta = await db.transaction(async (executor) => {\n\t\t\tconst meta = await applyStoreSchema(inTransaction(executor));\n\t\t\tconst archive = new ArchiveImport(executor, context);\n\t\t\tawait each(parts, context, (part) => archive.take(part));\n\t\t\treturn archive.finish(meta, options.outbox === true);\n\t\t});\n\t\treturn new ChordStore(db, meta, await readCatalog(db));\n\t} catch (error) {\n\t\ttry {\n\t\t\tawait db.close();\n\t\t} catch {\n\t\t\t// The import's own failure is the one to report.\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/** The store's schema migrations run inside the import's backend transaction (they open none of their own). */\nfunction inTransaction(executor: SqliteExecutor): SqliteDatabase {\n\treturn {\n\t\texec: (sql) => executor.exec(sql),\n\t\trun: (sql, ...params) => executor.run(sql, ...params),\n\t\trunCounted: (sql, ...params) => executor.runCounted(sql, ...params),\n\t\tget: (sql, ...params) => executor.get(sql, ...params),\n\t\tall: (sql, ...params) => executor.all(sql, ...params),\n\t\ttransaction: (callback) => callback(executor),\n\t\tclose: () => Promise.reject(new Error(\"import: the backend closes after the import\")),\n\t};\n}\n\n/** A place in the archive's order: before the manifest, in a table group's puts or indexes, the documents, the end. */\ntype Place = \"manifest\" | \"puts\" | \"indexes\" | \"documents\" | \"ended\";\n\n/**\n * One archive being imported: the place reached in its order (the manifest, then table groups of a `table` write, its\n * `put`s and its `index` writes, then the documents, then `end`), what was seen (tables, ids, live addresses, the\n * write count) and the step its writes are applied in.\n */\nclass ArchiveImport {\n\treadonly #executor: SqliteExecutor;\n\treadonly #context: Context;\n\t#position = 0;\n\t#manifest: ArchiveManifest | undefined;\n\t#step: Step | undefined;\n\t/** Where the next part may go. */\n\t#place: Place = \"manifest\";\n\t/** The table whose group is open. */\n\t#table: string | undefined;\n\treadonly #tables = new Set<string>();\n\treadonly #ids = new Set<number>();\n\t/** The lifetimes seen at each address, `[createdAt, retiredAt)` (`Infinity` while live). */\n\treadonly #lifetimes = new Map<string, [number, number][]>();\n\t/** The record whose revisions may follow, with the last revision's seq and its base's version. */\n\t#document: { readonly record: DocumentRecord; seq: number; base: number | undefined } | undefined;\n\t#writes = 0;\n\n\tconstructor(executor: SqliteExecutor, context: Context) {\n\t\tthis.#executor = executor;\n\t\tthis.#context = context;\n\t}\n\n\t/** Checks the next part and applies it. */\n\tasync take(value: unknown): Promise<void> {\n\t\tconst position = this.#position++;\n\t\tconst part = checkPart(value, position, this.#context);\n\t\tconst what = `import: part ${position} (${part.kind})`;\n\t\tif (this.#place === \"ended\") throw invalid(\"args\", `${what}: after the end`);\n\t\tif (part.kind === \"manifest\" || this.#step === undefined) {\n\t\t\tthis.#start(part, what);\n\t\t\treturn;\n\t\t}\n\t\tif (part.kind === \"end\") {\n\t\t\tif (part.writes !== this.#writes) {\n\t\t\t\tthrow invalid(\"args\", `${what}: counts ${part.writes} writes, the archive has ${this.#writes}`);\n\t\t\t}\n\t\t\tthis.#endDocument(what);\n\t\t\tthis.#place = \"ended\";\n\t\t\treturn;\n\t\t}\n\t\tthis.#place = this.#placeOf(part, what);\n\t\tthis.#writes++;\n\t\tawait applyWrite(this.#step, part, what);\n\t}\n\n\t/** The stored metadata once the archive ended: its `lastSeq`, the allocator's next id and the outbox setting. */\n\tasync finish(meta: MetaRow, outbox: boolean): Promise<MetaRow> {\n\t\tif (this.#place !== \"ended\" || this.#step === undefined || this.#manifest === undefined) {\n\t\t\tthrow invalid(\"args\", \"import: the archive has no end part\");\n\t\t}\n\t\tconst { lastSeq, nextId } = this.#manifest;\n\t\tawait writeCatalog(this.#step);\n\t\tawait this.#executor.run(\n\t\t\t`UPDATE ${TABLES.meta} SET last_seq = ?, next_id = ?, outbox = ?, outbox_floor = ? WHERE singleton = 1`,\n\t\t\tlastSeq,\n\t\t\tnextId,\n\t\t\toutbox ? 1 : 0,\n\t\t\tlastSeq,\n\t\t);\n\t\treturn {\n\t\t\t...meta,\n\t\t\tlast_seq: lastSeq,\n\t\t\tnext_id: nextId,\n\t\t\toutbox: outbox ? 1 : 0,\n\t\t\toutbox_floor: lastSeq,\n\t\t};\n\t}\n\n\t/** The manifest, first: a format and schema this code reads. */\n\t#start(part: ArchivePart, what: string): void {\n\t\tif (part.kind !== \"manifest\" || this.#step !== undefined)\n\t\t\tthrow invalid(\"args\", `${what}: the manifest comes first, once`);\n\t\tif (part.format !== ARCHIVE_FORMAT)\n\t\t\tthrow invalid(\"args\", `${what}: format ${part.format} is not ${ARCHIVE_FORMAT}`);\n\t\tif (part.schema > STORE_SCHEMA)\n\t\t\tthrow invalid(\"args\", `${what}: schema ${part.schema} is newer than ${STORE_SCHEMA}`);\n\t\tthis.#manifest = part;\n\t\tthis.#step = new Step(this.#executor, part.lastSeq, new IdAllocator(part.nextId), new Map());\n\t}\n\n\t/** Where `part` puts the archive, refused when out of order, a duplicate, or outside the manifest's ranges. */\n\t#placeOf(part: Exclude<ArchivePart, { readonly kind: \"manifest\" | \"end\" }>, what: string): Place {\n\t\tconst place = this.#place;\n\t\tswitch (part.kind) {\n\t\t\tcase \"table\":\n\t\t\t\tif (place === \"documents\") throw invalid(\"args\", `${what}: tables come before the documents`);\n\t\t\t\tif (this.#tables.has(part.table)) throw invalid(\"args\", `${what}: table ${part.table} occurs twice`);\n\t\t\t\tthis.#tables.add(part.table);\n\t\t\t\tthis.#table = part.table;\n\t\t\t\treturn \"puts\";\n\t\t\tcase \"put\":\n\t\t\t\tif (place !== \"puts\" || part.table !== this.#table) {\n\t\t\t\t\tthrow invalid(\"args\", `${what}: a put follows its table's table write, before its indexes`);\n\t\t\t\t}\n\t\t\t\treturn \"puts\";\n\t\t\tcase \"index\":\n\t\t\t\tif ((place !== \"puts\" && place !== \"indexes\") || part.table !== this.#table) {\n\t\t\t\t\tthrow invalid(\"args\", `${what}: an index follows its table's table write and puts`);\n\t\t\t\t}\n\t\t\t\treturn \"indexes\";\n\t\t\tcase \"document.create\":\n\t\t\t\tthis.#checkDocument(part, what);\n\t\t\t\treturn \"documents\";\n\t\t\tcase \"document.revision\":\n\t\t\t\tthis.#checkRevision(part, what);\n\t\t\t\treturn \"documents\";\n\t\t}\n\t}\n\n\t/**\n\t * A record within the manifest's ids and seqs (an id equal to a saturated `nextId` too), unique, its lifetime\n\t * overlapping no other at its address; its address and meta well-formed text without NUL (SQLite would cut a NUL off,\n\t * slice 6a §8). The record before it must have ended well (`#endDocument`).\n\t */\n\t#checkDocument(part: Extract<ArchivePart, { readonly kind: \"document.create\" }>, what: string): void {\n\t\tthis.#endDocument(what);\n\t\tconst { record } = part;\n\t\tconst { lastSeq, nextId } = this.#manifest!;\n\t\tconst saturated = nextId === Number.MAX_SAFE_INTEGER && record.id === nextId;\n\t\tif (record.id >= nextId && !saturated) throw invalid(\"args\", `${what}: id ${record.id} is not below ${nextId}`);\n\t\tif (this.#ids.has(record.id)) throw invalid(\"args\", `${what}: id ${record.id} occurs twice`);\n\t\tconst { createdAt, retiredAt } = record;\n\t\tif (createdAt > lastSeq || (retiredAt !== undefined && (retiredAt < createdAt || retiredAt > lastSeq))) {\n\t\t\tthrow invalid(\"args\", `${what}: a lifetime outside the manifest's lastSeq`);\n\t\t}\n\t\tconst { namespace, owner, kind, meta } = record;\n\t\t// A singleton's record has no key; its column keeps `\"\"`.\n\t\tconst key = record.key ?? \"\";\n\t\tfor (const text of [namespace, owner, kind, key]) {\n\t\t\tif (storedText(text, what) !== text) throw invalid(\"args\", `${what}: an address is not well-formed text`);\n\t\t}\n\t\tif (meta !== undefined && storedText(meta, what) !== meta) {\n\t\t\tthrow invalid(\"args\", `${what}: the meta is not well-formed text`);\n\t\t}\n\t\tconst address = JSON.stringify([owner, namespace, kind, key]);\n\t\tconst lifetime: [number, number] = [createdAt, retiredAt ?? Number.POSITIVE_INFINITY];\n\t\tconst lifetimes = this.#lifetimes.get(address) ?? [];\n\t\t// Two live records are two infinite lifetimes, which overlap; an empty one (`createdAt = retiredAt`) overlaps none.\n\t\tif (lifetime[0] < lifetime[1] && lifetimes.some(([from, to]) => from < lifetime[1] && lifetime[0] < to)) {\n\t\t\tthrow invalid(\"args\", `${what}: a second record at one address for an overlapping lifetime`);\n\t\t}\n\t\tlifetimes.push(lifetime);\n\t\tthis.#lifetimes.set(address, lifetimes);\n\t\tthis.#ids.add(record.id);\n\t\tthis.#document = { record, seq: 0, base: undefined };\n\t}\n\n\t/**\n\t * A revision of the record before it, in seq order within its lifetime, from a base, each delta at its base's\n\t * version.\n\t */\n\t#checkRevision(part: Extract<ArchivePart, { readonly kind: \"document.revision\" }>, what: string): void {\n\t\tconst document = this.#document;\n\t\tif (document === undefined || document.record.id !== part.id) {\n\t\t\tthrow invalid(\"args\", `${what}: a revision follows its record's create`);\n\t\t}\n\t\tconst { record } = document;\n\t\tif (record.retiredAt !== undefined && record.history !== \"rewindable\") {\n\t\t\tthrow invalid(\"args\", `${what}: a retired ${record.history} record keeps no revisions`);\n\t\t}\n\t\tif (\n\t\t\tpart.seq <= document.seq ||\n\t\t\tpart.seq < record.createdAt ||\n\t\t\tpart.seq > (record.retiredAt ?? this.#manifest!.lastSeq)\n\t\t) {\n\t\t\tthrow invalid(\"args\", `${what}: a revision out of seq order or outside its lifetime`);\n\t\t}\n\t\tconst { content } = part;\n\t\tif (content.kind === \"base\") document.base = content.version;\n\t\telse if (document.base !== content.version) {\n\t\t\tthrow invalid(\"args\", `${what}: a delta without a base at its version`);\n\t\t}\n\t\tdocument.seq = part.seq;\n\t}\n\n\t/**\n\t * The record before ends well: its last base is at the record's version; only a retired `latest` record has none\n\t * (its content was dropped at retirement; a retired `rewindable` one keeps its history).\n\t */\n\t#endDocument(what: string): void {\n\t\tconst document = this.#document;\n\t\tthis.#document = undefined;\n\t\tif (document === undefined) return;\n\t\tconst { record, base } = document;\n\t\tconst contentless = record.retiredAt !== undefined && record.history === \"latest\";\n\t\tif (base === undefined ? !contentless : base !== record.version) {\n\t\t\tthrow invalid(\"args\", `${what}: record ${record.id} has no base at its version`);\n\t\t}\n\t}\n}\n\n/** Runs `take` on each part in turn; a wait for the next part ends when `context` aborts (the input is closed). */\nasync function each(\n\tparts: AsyncIterable<unknown> | Iterable<unknown>,\n\tcontext: Context,\n\ttake: (part: unknown) => Promise<void>,\n): Promise<void> {\n\tconst iterator = Symbol.asyncIterator in parts ? parts[Symbol.asyncIterator]() : parts[Symbol.iterator]();\n\tlet done = false;\n\ttry {\n\t\tfor (;;) {\n\t\t\tlet result: IteratorResult<unknown>;\n\t\t\ttry {\n\t\t\t\tresult = await awaitWithContext(Promise.resolve(iterator.next()), context);\n\t\t\t} catch (error) {\n\t\t\t\tif (!context.abortSignal?.aborted) throw error;\n\t\t\t\tthrow new ChordError(\n\t\t\t\t\t{ code: \"aborted\", message: \"import: aborted\" },\n\t\t\t\t\t{ cause: context.abortSignal.reason },\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (result.done) {\n\t\t\t\tdone = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait take(result.value);\n\t\t}\n\t} finally {\n\t\t// A stalled input is not awaited: the backend transaction ends now.\n\t\tif (!done) void Promise.resolve(iterator.return?.()).catch(() => {});\n\t}\n}\n"]}
@@ -0,0 +1,16 @@
1
+ export type { ArchiveManifest, ArchivePart } from "./archive.ts";
2
+ export { type Backend, sqliteBackend } from "./backend.ts";
3
+ export type { Columns, PutRowOf, RowOf } from "./columns.ts";
4
+ export { add, and, type ColumnRef, type Condition, coalesce, concat, type Expression, eq, gt, gte, inArray, isNull, lt, lte, max, min, ne, not, or, prefix, replacePrefix, type SetOf, sub, when, } from "./expression.ts";
5
+ export { importStore } from "./import.ts";
6
+ export { type JsonColumnOptions, type JsonColumnSchema, json } from "./json-column.ts";
7
+ export { decodeJsonl, encodeJsonl } from "./jsonl.ts";
8
+ export type { Outbox, OutboxCommit } from "./outbox.ts";
9
+ export { type ColumnRefs, type Query, query } from "./query.ts";
10
+ export { openStore, type Store, type StoreOptions } from "./store.ts";
11
+ export { defineTable, type KeyOf, type TableDefinition, type TableOptions } from "./table.ts";
12
+ export { type AddedColumn, evolveTable, type PatchOf, type TableEditor, type TableTailEditor, } from "./table-evolve.ts";
13
+ export type { Page, PageOptions, Table, TableOf } from "./table-handle.ts";
14
+ export { compareText } from "./text.ts";
15
+ export type { StoreWrite } from "./writes.ts";
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/next/store/index.ts"],"names":[],"mappings":"AAGA,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,KAAK,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3D,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EACN,GAAG,EACH,GAAG,EACH,KAAK,SAAS,EACd,KAAK,SAAS,EACd,QAAQ,EACR,MAAM,EACN,KAAK,UAAU,EACf,EAAE,EACF,EAAE,EACF,GAAG,EACH,OAAO,EACP,MAAM,EACN,EAAE,EACF,GAAG,EACH,GAAG,EACH,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,MAAM,EACN,aAAa,EACb,KAAK,KAAK,EACV,GAAG,EACH,IAAI,GACJ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACtD,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,KAAK,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,KAAK,KAAK,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAC9F,OAAO,EACN,KAAK,WAAW,EAChB,WAAW,EACX,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,eAAe,GACpB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,13 @@
1
+ // The store for apps: opening it over a backend, tables with their queries, writes and migrations, export and
2
+ // import of archives (with their JSONL encoding), the outbox, text order.
3
+ export { sqliteBackend } from "./backend.js";
4
+ export { add, and, coalesce, concat, eq, gt, gte, inArray, isNull, lt, lte, max, min, ne, not, or, prefix, replacePrefix, sub, when, } from "./expression.js";
5
+ export { importStore } from "./import.js";
6
+ export { json } from "./json-column.js";
7
+ export { decodeJsonl, encodeJsonl } from "./jsonl.js";
8
+ export { query } from "./query.js";
9
+ export { openStore } from "./store.js";
10
+ export { defineTable } from "./table.js";
11
+ export { evolveTable, } from "./table-evolve.js";
12
+ export { compareText } from "./text.js";
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/next/store/index.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,0EAA0E;AAG1E,OAAO,EAAgB,aAAa,EAAE,MAAM,cAAc,CAAC;AAE3D,OAAO,EACN,GAAG,EACH,GAAG,EAGH,QAAQ,EACR,MAAM,EAEN,EAAE,EACF,EAAE,EACF,GAAG,EACH,OAAO,EACP,MAAM,EACN,EAAE,EACF,GAAG,EACH,GAAG,EACH,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,MAAM,EACN,aAAa,EAEb,GAAG,EACH,IAAI,GACJ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAiD,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAA+B,KAAK,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,SAAS,EAAiC,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,WAAW,EAAuD,MAAM,YAAY,CAAC;AAC9F,OAAO,EAEN,WAAW,GAIX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC","sourcesContent":["// The store for apps: opening it over a backend, tables with their queries, writes and migrations, export and\n// import of archives (with their JSONL encoding), the outbox, text order.\n\nexport type { ArchiveManifest, ArchivePart } from \"./archive.ts\";\nexport { type Backend, sqliteBackend } from \"./backend.ts\";\nexport type { Columns, PutRowOf, RowOf } from \"./columns.ts\";\nexport {\n\tadd,\n\tand,\n\ttype ColumnRef,\n\ttype Condition,\n\tcoalesce,\n\tconcat,\n\ttype Expression,\n\teq,\n\tgt,\n\tgte,\n\tinArray,\n\tisNull,\n\tlt,\n\tlte,\n\tmax,\n\tmin,\n\tne,\n\tnot,\n\tor,\n\tprefix,\n\treplacePrefix,\n\ttype SetOf,\n\tsub,\n\twhen,\n} from \"./expression.ts\";\nexport { importStore } from \"./import.ts\";\nexport { type JsonColumnOptions, type JsonColumnSchema, json } from \"./json-column.ts\";\nexport { decodeJsonl, encodeJsonl } from \"./jsonl.ts\";\nexport type { Outbox, OutboxCommit } from \"./outbox.ts\";\nexport { type ColumnRefs, type Query, query } from \"./query.ts\";\nexport { openStore, type Store, type StoreOptions } from \"./store.ts\";\nexport { defineTable, type KeyOf, type TableDefinition, type TableOptions } from \"./table.ts\";\nexport {\n\ttype AddedColumn,\n\tevolveTable,\n\ttype PatchOf,\n\ttype TableEditor,\n\ttype TableTailEditor,\n} from \"./table-evolve.ts\";\nexport type { Page, PageOptions, Table, TableOf } from \"./table-handle.ts\";\nexport { compareText } from \"./text.ts\";\nexport type { StoreWrite } from \"./writes.ts\";\n"]}
@@ -0,0 +1,33 @@
1
+ import type { JsonSchema } from "@earendil-works/pi-schema";
2
+ import type { Context } from "../../context/index.ts";
3
+ import type { JsonValue } from "../../json.ts";
4
+ import type { Schema, Static } from "../contracts/index.ts";
5
+ /** What `json(...)` takes besides the schema. */
6
+ export type JsonColumnOptions<T> = {
7
+ /** The version of the cells' shape; a cell stores the version it was written at. */
8
+ readonly version: number;
9
+ /** Maps a cell of an older version `from` to this version's shape; pure. Without it older cells are refused. */
10
+ readonly migrate?: (old: JsonValue, from: number) => T;
11
+ };
12
+ /** A `json(...)` column as `columns` takes it: a schema of the cells' type carrying the column. */
13
+ export interface JsonColumnSchema<T> extends Schema<T> {
14
+ readonly json: JsonColumn;
15
+ }
16
+ /** A column holding one JSON value of `schema` per row, at `version`; wrap it in `opt(...)` to make it nullable. */
17
+ export declare function json<S extends Schema>(schema: S, options: JsonColumnOptions<Static<S>>): JsonColumnSchema<Static<S>>;
18
+ /** A `json(...)` column's definition: its schema snapshot, version and fingerprint, and the read of a stored cell. */
19
+ export declare class JsonColumn {
20
+ #private;
21
+ readonly schema: JsonSchema;
22
+ readonly version: number;
23
+ /** The fingerprint of the schema's normal form, recorded with the table: the same version with another is `broken`. */
24
+ readonly fingerprint: string;
25
+ constructor(schema: Schema, version: number, migrate: ((old: JsonValue, from: number) => unknown) | undefined);
26
+ /**
27
+ * The value of a stored cell written at `version`: parsed; an older one migrated and checked once (R8, counted). A
28
+ * newer version, a missing or throwing `migrate` and an invalid result throw `unavailable` (`what` names the cell);
29
+ * the caller fails the owner (slice 6a §1.4), the data stays.
30
+ */
31
+ read(text: string, version: number, what: string, context: Context): unknown;
32
+ }
33
+ //# sourceMappingURL=json-column.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-column.d.ts","sourceRoot":"","sources":["../../../src/next/store/json-column.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAM5D,iDAAiD;AACjD,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI;IAClC,oFAAoF;IACpF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gHAAgH;IAChH,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,CAAC;CACvD,CAAC;AAEF,mGAAmG;AACnG,MAAM,WAAW,gBAAgB,CAAC,CAAC,CAAE,SAAQ,MAAM,CAAC,CAAC,CAAC;IACrD,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC1B;AAED,oHAAoH;AACpH,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAGpH;AAED,sHAAsH;AACtH,qBAAa,UAAU;;IACtB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,uHAAuH;IACvH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAG7B,YAAY,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,SAAS,EAS5G;IAED;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAgB3E;CACD"}
@@ -0,0 +1,61 @@
1
+ // `json(schema, { version, migrate? })` table columns (decision "The `json(...)` column helper", W11): one JSON `TEXT`
2
+ // cell with its own version, typed when read, migrated on access (the result checked once, R8), never walked on write
3
+ // (R9).
4
+ import { fingerprintOf } from "../contracts/internal.js";
5
+ import { snapshotSchema } from "../contracts/snapshot.js";
6
+ import { ChordError } from "../data/index.js";
7
+ import { validatorFor } from "../data/internal.js";
8
+ /** A column holding one JSON value of `schema` per row, at `version`; wrap it in `opt(...)` to make it nullable. */
9
+ export function json(schema, options) {
10
+ // Typed as the cells' schema, so `opt(...)` and `Static` take it; the table reads its `json` field.
11
+ return { json: new JsonColumn(schema, options.version, options.migrate) };
12
+ }
13
+ /** A `json(...)` column's definition: its schema snapshot, version and fingerprint, and the read of a stored cell. */
14
+ export class JsonColumn {
15
+ schema;
16
+ version;
17
+ /** The fingerprint of the schema's normal form, recorded with the table: the same version with another is `broken`. */
18
+ fingerprint;
19
+ #migrate;
20
+ constructor(schema, version, migrate) {
21
+ // Declaration policy: JavaScript callers reach this check.
22
+ if (!Number.isSafeInteger(version) || version < 1)
23
+ throw new Error(`json(...): version ${version} is not a positive integer`);
24
+ const snapshot = snapshotSchema(schema, "json(...)");
25
+ this.schema = snapshot.schema;
26
+ this.version = version;
27
+ this.fingerprint = fingerprintOf(snapshot.normal);
28
+ this.#migrate = migrate;
29
+ }
30
+ /**
31
+ * The value of a stored cell written at `version`: parsed; an older one migrated and checked once (R8, counted). A
32
+ * newer version, a missing or throwing `migrate` and an invalid result throw `unavailable` (`what` names the cell);
33
+ * the caller fails the owner (slice 6a §1.4), the data stays.
34
+ */
35
+ read(text, version, what, context) {
36
+ const value = JSON.parse(text);
37
+ if (version === this.version)
38
+ return value;
39
+ if (version > this.version)
40
+ throw refused(`${what}: stored at version ${version}, newer than ${this.version}`);
41
+ if (this.#migrate === undefined)
42
+ throw refused(`${what}: no migrate from version ${version} to ${this.version}`);
43
+ let migrated;
44
+ try {
45
+ migrated = this.#migrate(value, version);
46
+ }
47
+ catch (error) {
48
+ throw refused(`${what}: migrate from version ${version} threw`, error);
49
+ }
50
+ context.telemetry.metrics?.counter("chord.data.validations").add(1);
51
+ if (!validatorFor(this, context).check(migrated)) {
52
+ throw refused(`${what}: migrate from version ${version} does not match the schema`);
53
+ }
54
+ return migrated;
55
+ }
56
+ }
57
+ /** The error of a cell the code cannot read: the owner fails `broken` with it. */
58
+ function refused(message, cause) {
59
+ return new ChordError({ code: "unavailable", message }, cause === undefined ? undefined : { cause });
60
+ }
61
+ //# sourceMappingURL=json-column.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-column.js","sourceRoot":"","sources":["../../../src/next/store/json-column.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,sHAAsH;AACtH,QAAQ;AAMR,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;A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AAC;QAC/G,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS;YAAE,MAAM,OAAO,CAAC,GAAG,IAAI,6BAA6B,OAAO,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACjH,IAAI,QAAiB,CAAC;QACtB,IAAI,CAAC;YACJ,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,OAAO,CAAC,GAAG,IAAI,0BAA0B,OAAO,QAAQ,EAAE,KAAK,CAAC,CAAC;QACxE,CAAC;QACD,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,wBAAwB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACpE,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YAClD,MAAM,OAAO,CAAC,GAAG,IAAI,0BAA0B,OAAO,4BAA4B,CAAC,CAAC;QACrF,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD;AAED,kFAAkF;AAClF,SAAS,OAAO,CAAC,OAAe,EAAE,KAAe;IAChD,OAAO,IAAI,UAAU,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AACtG,CAAC","sourcesContent":["// `json(schema, { version, migrate? })` table columns (decision \"The `json(...)` column helper\", W11): one JSON `TEXT`\n// cell with its own version, typed when read, migrated on access (the result checked once, R8), never walked on write\n// (R9).\n\nimport type { JsonSchema } from \"@earendil-works/pi-schema\";\nimport type { Context } from \"../../context/index.ts\";\nimport type { JsonValue } from \"../../json.ts\";\nimport type { Schema, Static } from \"../contracts/index.ts\";\nimport { fingerprintOf } from \"../contracts/internal.ts\";\nimport { snapshotSchema } from \"../contracts/snapshot.ts\";\nimport { ChordError } from \"../data/index.ts\";\nimport { validatorFor } from \"../data/internal.ts\";\n\n/** What `json(...)` takes besides the schema. */\nexport type JsonColumnOptions<T> = {\n\t/** The version of the cells' shape; a cell stores the version it was written at. */\n\treadonly version: number;\n\t/** Maps a cell of an older version `from` to this version's shape; pure. Without it older cells are refused. */\n\treadonly migrate?: (old: JsonValue, from: number) => T;\n};\n\n/** A `json(...)` column as `columns` takes it: a schema of the cells' type carrying the column. */\nexport interface JsonColumnSchema<T> extends Schema<T> {\n\treadonly json: JsonColumn;\n}\n\n/** A column holding one JSON value of `schema` per row, at `version`; wrap it in `opt(...)` to make it nullable. */\nexport function json<S extends Schema>(schema: S, options: JsonColumnOptions<Static<S>>): JsonColumnSchema<Static<S>> {\n\t// Typed as the cells' schema, so `opt(...)` and `Static` take it; the table reads its `json` field.\n\treturn { json: new JsonColumn(schema, options.version, options.migrate) };\n}\n\n/** A `json(...)` column's definition: its schema snapshot, version and fingerprint, and the read of a stored cell. */\nexport class JsonColumn {\n\treadonly schema: JsonSchema;\n\treadonly version: number;\n\t/** The fingerprint of the schema's normal form, recorded with the table: the same version with another is `broken`. */\n\treadonly fingerprint: string;\n\treadonly #migrate: ((old: JsonValue, from: number) => unknown) | undefined;\n\n\tconstructor(schema: Schema, version: number, migrate: ((old: JsonValue, from: number) => unknown) | undefined) {\n\t\t// Declaration policy: JavaScript callers reach this check.\n\t\tif (!Number.isSafeInteger(version) || version < 1)\n\t\t\tthrow new Error(`json(...): version ${version} is not a positive integer`);\n\t\tconst snapshot = snapshotSchema(schema, \"json(...)\");\n\t\tthis.schema = snapshot.schema;\n\t\tthis.version = version;\n\t\tthis.fingerprint = fingerprintOf(snapshot.normal);\n\t\tthis.#migrate = migrate;\n\t}\n\n\t/**\n\t * The value of a stored cell written at `version`: parsed; an older one migrated and checked once (R8, counted). A\n\t * newer version, a missing or throwing `migrate` and an invalid result throw `unavailable` (`what` names the cell);\n\t * the caller fails the owner (slice 6a §1.4), the data stays.\n\t */\n\tread(text: string, version: number, what: string, context: Context): unknown {\n\t\tconst value = JSON.parse(text) as JsonValue;\n\t\tif (version === this.version) return value;\n\t\tif (version > this.version) throw refused(`${what}: stored at version ${version}, newer than ${this.version}`);\n\t\tif (this.#migrate === undefined) throw refused(`${what}: no migrate from version ${version} to ${this.version}`);\n\t\tlet migrated: unknown;\n\t\ttry {\n\t\t\tmigrated = this.#migrate(value, version);\n\t\t} catch (error) {\n\t\t\tthrow refused(`${what}: migrate from version ${version} threw`, error);\n\t\t}\n\t\tcontext.telemetry.metrics?.counter(\"chord.data.validations\").add(1);\n\t\tif (!validatorFor(this, context).check(migrated)) {\n\t\t\tthrow refused(`${what}: migrate from version ${version} does not match the schema`);\n\t\t}\n\t\treturn migrated;\n\t}\n}\n\n/** The error of a cell the code cannot read: the owner fails `broken` with it. */\nfunction refused(message: string, cause?: unknown): ChordError {\n\treturn new ChordError({ code: \"unavailable\", message }, cause === undefined ? undefined : { cause });\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { ArchivePart } from "./archive.ts";
2
+ /** `parts` as JSONL bytes, in chunks of whole lines. */
3
+ export declare function encodeJsonl(parts: AsyncIterable<ArchivePart>): AsyncIterable<Uint8Array>;
4
+ /**
5
+ * The values of JSONL `bytes`, one per nonempty line, for `importStore` to check (a trust boundary: bytes that are
6
+ * no UTF-8 and a line that is no JSON are `invalid/args`).
7
+ */
8
+ export declare function decodeJsonl(bytes: AsyncIterable<Uint8Array>): AsyncIterable<unknown>;
9
+ //# sourceMappingURL=jsonl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonl.d.ts","sourceRoot":"","sources":["../../../src/next/store/jsonl.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKhD,wDAAwD;AACxD,wBAAuB,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAW/F;AAED;;;GAGG;AACH,wBAAuB,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CAgC3F"}
@@ -0,0 +1,61 @@
1
+ // Plain JSONL for archives (slice 6a §13): one part per line, UTF-8. The store yields and takes parts; this is the
2
+ // encoding it ships (others, compressed ones, come later without touching the applier).
3
+ import { invalid } from "../data/internal.js";
4
+ /** The bytes a chunk of encoded lines collects before it is yielded. */
5
+ const CHUNK = 64 * 1024;
6
+ /** `parts` as JSONL bytes, in chunks of whole lines. */
7
+ export async function* encodeJsonl(parts) {
8
+ const encoder = new TextEncoder();
9
+ let lines = "";
10
+ for await (const part of parts) {
11
+ lines += `${JSON.stringify(part)}\n`;
12
+ if (lines.length >= CHUNK) {
13
+ yield encoder.encode(lines);
14
+ lines = "";
15
+ }
16
+ }
17
+ if (lines.length > 0)
18
+ yield encoder.encode(lines);
19
+ }
20
+ /**
21
+ * The values of JSONL `bytes`, one per nonempty line, for `importStore` to check (a trust boundary: bytes that are
22
+ * no UTF-8 and a line that is no JSON are `invalid/args`).
23
+ */
24
+ export async function* decodeJsonl(bytes) {
25
+ const decoder = new TextDecoder("utf-8", { fatal: true });
26
+ let rest = "";
27
+ let line = 0;
28
+ const parse = (text) => {
29
+ try {
30
+ return JSON.parse(text);
31
+ }
32
+ catch {
33
+ throw invalid("args", `jsonl: line ${line} is not JSON`);
34
+ }
35
+ };
36
+ const decode = (chunk) => {
37
+ try {
38
+ return chunk === undefined ? decoder.decode() : decoder.decode(chunk, { stream: true });
39
+ }
40
+ catch {
41
+ throw invalid("args", `jsonl: line ${line + 1} is not UTF-8`);
42
+ }
43
+ };
44
+ for await (const chunk of bytes) {
45
+ rest += decode(chunk);
46
+ let start = 0;
47
+ for (let end = rest.indexOf("\n"); end >= 0; end = rest.indexOf("\n", start)) {
48
+ const text = rest.slice(start, end);
49
+ start = end + 1;
50
+ line++;
51
+ if (text.trim().length > 0)
52
+ yield parse(text);
53
+ }
54
+ rest = rest.slice(start);
55
+ }
56
+ rest += decode();
57
+ line++;
58
+ if (rest.trim().length > 0)
59
+ yield parse(rest);
60
+ }
61
+ //# sourceMappingURL=jsonl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonl.js","sourceRoot":"","sources":["../../../src/next/store/jsonl.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,wFAAwF;AAExF,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAG9C,wEAAwE;AACxE,MAAM,KAAK,GAAG,EAAE,GAAG,IAAI,CAAC;AAExB,wDAAwD;AACxD,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,WAAW,CAAC,KAAiC;IACnE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAChC,KAAK,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;QACrC,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC;YAC3B,MAAM,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC5B,KAAK,GAAG,EAAE,CAAC;QACZ,CAAC;IACF,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,WAAW,CAAC,KAAgC;IAClE,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,MAAM,KAAK,GAAG,CAAC,IAAY,EAA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,IAAI,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,CAAC;IACP,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["// Plain JSONL for archives (slice 6a §13): one part per line, UTF-8. The store yields and takes parts; this is the\n// encoding it ships (others, compressed ones, come later without touching the applier).\n\nimport { invalid } from \"../data/internal.ts\";\nimport type { ArchivePart } from \"./archive.ts\";\n\n/** The bytes a chunk of encoded lines collects before it is yielded. */\nconst CHUNK = 64 * 1024;\n\n/** `parts` as JSONL bytes, in chunks of whole lines. */\nexport async function* encodeJsonl(parts: AsyncIterable<ArchivePart>): AsyncIterable<Uint8Array> {\n\tconst encoder = new TextEncoder();\n\tlet lines = \"\";\n\tfor await (const part of parts) {\n\t\tlines += `${JSON.stringify(part)}\\n`;\n\t\tif (lines.length >= CHUNK) {\n\t\t\tyield encoder.encode(lines);\n\t\t\tlines = \"\";\n\t\t}\n\t}\n\tif (lines.length > 0) yield encoder.encode(lines);\n}\n\n/**\n * The values of JSONL `bytes`, one per nonempty line, for `importStore` to check (a trust boundary: bytes that are\n * no UTF-8 and a line that is no JSON are `invalid/args`).\n */\nexport async function* decodeJsonl(bytes: AsyncIterable<Uint8Array>): AsyncIterable<unknown> {\n\tconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\tlet rest = \"\";\n\tlet line = 0;\n\tconst parse = (text: string): unknown => {\n\t\ttry {\n\t\t\treturn JSON.parse(text);\n\t\t} catch {\n\t\t\tthrow invalid(\"args\", `jsonl: line ${line} is not JSON`);\n\t\t}\n\t};\n\tconst decode = (chunk?: Uint8Array): string => {\n\t\ttry {\n\t\t\treturn chunk === undefined ? decoder.decode() : decoder.decode(chunk, { stream: true });\n\t\t} catch {\n\t\t\tthrow invalid(\"args\", `jsonl: line ${line + 1} is not UTF-8`);\n\t\t}\n\t};\n\tfor await (const chunk of bytes) {\n\t\trest += decode(chunk);\n\t\tlet start = 0;\n\t\tfor (let end = rest.indexOf(\"\\n\"); end >= 0; end = rest.indexOf(\"\\n\", start)) {\n\t\t\tconst text = rest.slice(start, end);\n\t\t\tstart = end + 1;\n\t\t\tline++;\n\t\t\tif (text.trim().length > 0) yield parse(text);\n\t\t}\n\t\trest = rest.slice(start);\n\t}\n\trest += decode();\n\tline++;\n\tif (rest.trim().length > 0) yield parse(rest);\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import type { Context } from "../../context/index.ts";
2
+ import type { ChordStore } from "./store.ts";
3
+ import type { StoreWrite } from "./writes.ts";
4
+ /** The write vocabulary's version an outbox commit is stored in; a newer one is refused, data intact. */
5
+ export declare const OUTBOX_FORMAT = 1;
6
+ /** One commit as the outbox gives it: its seq, the allocator's value it persisted (D3) and its writes in applied order. */
7
+ export type OutboxCommit = {
8
+ readonly seq: number;
9
+ readonly nextId: number;
10
+ readonly writes: readonly StoreWrite[];
11
+ };
12
+ /** A store's outbox: its commits after the floor (the seq it was turned on at, advanced by `trim`). */
13
+ export declare class Outbox {
14
+ #private;
15
+ constructor(store: ChordStore, floor: number);
16
+ /** The seq the outbox starts after: `read` takes any `afterSeq` from it to `lastSeq`. */
17
+ get floor(): number;
18
+ /** Up to `limit` commits after `afterSeq`, in seq order; `afterSeq` outside floor..lastSeq is `invalid/args`. */
19
+ read(afterSeq: number, limit: number, context: Context): Promise<OutboxCommit[]>;
20
+ /**
21
+ * Drops the commits through `throughSeq` and advances the floor; idempotent; beyond `lastSeq` is `invalid/args`.
22
+ * Trims run one at a time, so the stored floor only rises and equals the one in memory.
23
+ */
24
+ trim(throughSeq: number, context: Context): Promise<void>;
25
+ }
26
+ //# sourceMappingURL=outbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../../../src/next/store/outbox.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAItD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,yGAAyG;AACzG,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,2HAA2H;AAC3H,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAA;CAAE,CAAC;AAIrH,uGAAuG;AACvG,qBAAa,MAAM;;IASlB,YAAY,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAG3C;IAED,yFAAyF;IACzF,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,iHAAiH;IAC3G,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAIrF;IAED;;;OAGG;IACH,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAUxD;CA6CD"}
@@ -0,0 +1,80 @@
1
+ // The outbox (slice 6a §2; decisions "The outbox is optional, internal and versioned", small items 3-4): the store's
2
+ // commits as the sync layer reads them, one `{ seq, writes }` per commit from its floor on, in the current format.
3
+ import { ChordError } from "../data/index.js";
4
+ import { invalid } from "../data/internal.js";
5
+ import { TABLES } from "./schema.js";
6
+ /** The write vocabulary's version an outbox commit is stored in; a newer one is refused, data intact. */
7
+ export const OUTBOX_FORMAT = 1;
8
+ const NOTHING = () => { };
9
+ /** A store's outbox: its commits after the floor (the seq it was turned on at, advanced by `trim`). */
10
+ export class Outbox {
11
+ #store;
12
+ #floor;
13
+ /**
14
+ * The outbox's reads and trims, one at a time: a read checks the floor and reads with no trim running (a trim's
15
+ * commit may have deleted rows before its floor is set), a trim waits for the reads in flight.
16
+ */
17
+ #queue = Promise.resolve();
18
+ constructor(store, floor) {
19
+ this.#store = store;
20
+ this.#floor = floor;
21
+ }
22
+ /** The seq the outbox starts after: `read` takes any `afterSeq` from it to `lastSeq`. */
23
+ get floor() {
24
+ return this.#floor;
25
+ }
26
+ /** Up to `limit` commits after `afterSeq`, in seq order; `afterSeq` outside floor..lastSeq is `invalid/args`. */
27
+ async read(afterSeq, limit, context) {
28
+ if (!Number.isSafeInteger(afterSeq))
29
+ throw invalid("args", `outbox: read after ${afterSeq}, not an integer`);
30
+ if (!Number.isSafeInteger(limit) || limit < 1)
31
+ throw invalid("args", "outbox: limit is a positive integer");
32
+ return this.#queued(() => this.#read(afterSeq, limit, context));
33
+ }
34
+ /**
35
+ * Drops the commits through `throughSeq` and advances the floor; idempotent; beyond `lastSeq` is `invalid/args`.
36
+ * Trims run one at a time, so the stored floor only rises and equals the one in memory.
37
+ */
38
+ trim(throughSeq, context) {
39
+ try {
40
+ context.abortSignal?.throwIfAborted();
41
+ if (!Number.isSafeInteger(throughSeq) || throughSeq > this.#store.lastSeq) {
42
+ throw invalid("args", `outbox: trim through ${throughSeq}, beyond ${this.#store.lastSeq}`);
43
+ }
44
+ }
45
+ catch (error) {
46
+ return Promise.reject(error);
47
+ }
48
+ return this.#queued(() => this.#trim(throughSeq));
49
+ }
50
+ /** Runs `operation` once the outbox operations before it settled. */
51
+ #queued(operation) {
52
+ const run = this.#queue.then(operation);
53
+ this.#queue = run.then(NOTHING, NOTHING);
54
+ return run;
55
+ }
56
+ /** `read`, its turn come: the floor as no trim moves it. */
57
+ async #read(afterSeq, limit, context) {
58
+ if (afterSeq < this.#floor || afterSeq > this.#store.lastSeq) {
59
+ throw invalid("args", `outbox: read after ${afterSeq}, outside ${this.#floor}..${this.#store.lastSeq}`);
60
+ }
61
+ const rows = await this.#store.read((executor) => executor.all(`SELECT seq, format, next_id, writes FROM ${TABLES.outbox} WHERE seq > ? ORDER BY seq LIMIT ?`, afterSeq, limit), context);
62
+ return rows.map(({ seq, format, next_id, writes }) => {
63
+ if (format !== OUTBOX_FORMAT) {
64
+ const message = `outbox: commit ${seq} is in format ${format}, newer than ${OUTBOX_FORMAT}`;
65
+ throw new ChordError({ code: "unavailable", message });
66
+ }
67
+ return { seq, nextId: next_id, writes: JSON.parse(writes) };
68
+ });
69
+ }
70
+ async #trim(throughSeq) {
71
+ if (throughSeq <= this.#floor)
72
+ return;
73
+ await this.#store.maintain(async (executor) => {
74
+ await executor.run(`DELETE FROM ${TABLES.outbox} WHERE seq <= ?`, throughSeq);
75
+ await executor.run(`UPDATE ${TABLES.meta} SET outbox_floor = ? WHERE singleton = 1`, throughSeq);
76
+ });
77
+ this.#floor = throughSeq;
78
+ }
79
+ }
80
+ //# sourceMappingURL=outbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outbox.js","sourceRoot":"","sources":["../../../src/next/store/outbox.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,mHAAmH;AAGnH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,yGAAyG;AACzG,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAK/B,MAAM,OAAO,GAAG,GAAS,EAAE,GAAE,CAAC,CAAC;AAE/B,uGAAuG;AACvG,MAAM,OAAO,MAAM;IACT,MAAM,CAAa;IAC5B,MAAM,CAAS;IACf;;;OAGG;IACH,MAAM,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAE1C,YAAY,KAAiB,EAAE,KAAa;QAC3C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,yFAAyF;IACzF,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IA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EAAE,EAAE;YAC7C,MAAM,QAAQ,CAAC,GAAG,CAAC,eAAe,MAAM,CAAC,MAAM,iBAAiB,EAAE,UAAU,CAAC,CAAC;YAC9E,MAAM,QAAQ,CAAC,GAAG,CAAC,UAAU,MAAM,CAAC,IAAI,2CAA2C,EAAE,UAAU,CAAC,CAAC;QAClG,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC;IAC1B,CAAC;CACD","sourcesContent":["// The outbox (slice 6a §2; decisions \"The outbox is optional, internal and versioned\", small items 3-4): the store's\n// commits as the sync layer reads them, one `{ seq, writes }` per commit from its floor on, in the current format.\n\nimport type { Context } from \"../../context/index.ts\";\nimport { ChordError } from \"../data/index.ts\";\nimport { invalid } from \"../data/internal.ts\";\nimport { TABLES } from \"./schema.ts\";\nimport type { ChordStore } from \"./store.ts\";\nimport type { StoreWrite } from \"./writes.ts\";\n\n/** The write vocabulary's version an outbox commit is stored in; a newer one is refused, data intact. */\nexport const OUTBOX_FORMAT = 1;\n\n/** One commit as the outbox gives it: its seq, the allocator's value it persisted (D3) and its writes in applied order. */\nexport type OutboxCommit = { readonly seq: number; readonly nextId: number; readonly writes: readonly StoreWrite[] };\n\nconst NOTHING = (): void => {};\n\n/** A store's outbox: its commits after the floor (the seq it was turned on at, advanced by `trim`). */\nexport class Outbox {\n\treadonly #store: ChordStore;\n\t#floor: number;\n\t/**\n\t * The outbox's reads and trims, one at a time: a read checks the floor and reads with no trim running (a trim's\n\t * commit may have deleted rows before its floor is set), a trim waits for the reads in flight.\n\t */\n\t#queue: Promise<void> = Promise.resolve();\n\n\tconstructor(store: ChordStore, floor: number) {\n\t\tthis.#store = store;\n\t\tthis.#floor = floor;\n\t}\n\n\t/** The seq the outbox starts after: `read` takes any `afterSeq` from it to `lastSeq`. */\n\tget floor(): number {\n\t\treturn this.#floor;\n\t}\n\n\t/** Up to `limit` commits after `afterSeq`, in seq order; `afterSeq` outside floor..lastSeq is `invalid/args`. */\n\tasync read(afterSeq: number, limit: number, context: Context): Promise<OutboxCommit[]> {\n\t\tif (!Number.isSafeInteger(afterSeq)) throw invalid(\"args\", `outbox: read after ${afterSeq}, not an integer`);\n\t\tif (!Number.isSafeInteger(limit) || limit < 1) throw invalid(\"args\", \"outbox: limit is a positive integer\");\n\t\treturn this.#queued(() => this.#read(afterSeq, limit, context));\n\t}\n\n\t/**\n\t * Drops the commits through `throughSeq` and advances the floor; idempotent; beyond `lastSeq` is `invalid/args`.\n\t * Trims run one at a time, so the stored floor only rises and equals the one in memory.\n\t */\n\ttrim(throughSeq: number, context: Context): Promise<void> {\n\t\ttry {\n\t\t\tcontext.abortSignal?.throwIfAborted();\n\t\t\tif (!Number.isSafeInteger(throughSeq) || throughSeq > this.#store.lastSeq) {\n\t\t\t\tthrow invalid(\"args\", `outbox: trim through ${throughSeq}, beyond ${this.#store.lastSeq}`);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t\treturn this.#queued(() => this.#trim(throughSeq));\n\t}\n\n\t/** Runs `operation` once the outbox operations before it settled. */\n\t#queued<T>(operation: () => Promise<T>): Promise<T> {\n\t\tconst run = this.#queue.then(operation);\n\t\tthis.#queue = run.then(NOTHING, NOTHING);\n\t\treturn run;\n\t}\n\n\t/** `read`, its turn come: the floor as no trim moves it. */\n\tasync #read(afterSeq: number, limit: number, context: Context): Promise<OutboxCommit[]> {\n\t\tif (afterSeq < this.#floor || afterSeq > this.#store.lastSeq) {\n\t\t\tthrow invalid(\"args\", `outbox: read after ${afterSeq}, outside ${this.#floor}..${this.#store.lastSeq}`);\n\t\t}\n\t\tconst rows = await this.#store.read(\n\t\t\t(executor) =>\n\t\t\t\texecutor.all<{\n\t\t\t\t\treadonly seq: number;\n\t\t\t\t\treadonly format: number;\n\t\t\t\t\treadonly next_id: number;\n\t\t\t\t\treadonly writes: string;\n\t\t\t\t}>(\n\t\t\t\t\t`SELECT seq, format, next_id, writes FROM ${TABLES.outbox} WHERE seq > ? ORDER BY seq LIMIT ?`,\n\t\t\t\t\tafterSeq,\n\t\t\t\t\tlimit,\n\t\t\t\t),\n\t\t\tcontext,\n\t\t);\n\t\treturn rows.map(({ seq, format, next_id, writes }) => {\n\t\t\tif (format !== OUTBOX_FORMAT) {\n\t\t\t\tconst message = `outbox: commit ${seq} is in format ${format}, newer than ${OUTBOX_FORMAT}`;\n\t\t\t\tthrow new ChordError({ code: \"unavailable\", message });\n\t\t\t}\n\t\t\treturn { seq, nextId: next_id, writes: JSON.parse(writes) as StoreWrite[] };\n\t\t});\n\t}\n\n\tasync #trim(throughSeq: number): Promise<void> {\n\t\tif (throughSeq <= this.#floor) return;\n\t\tawait this.#store.maintain(async (executor) => {\n\t\t\tawait executor.run(`DELETE FROM ${TABLES.outbox} WHERE seq <= ?`, throughSeq);\n\t\t\tawait executor.run(`UPDATE ${TABLES.meta} SET outbox_floor = ? WHERE singleton = 1`, throughSeq);\n\t\t});\n\t\tthis.#floor = throughSeq;\n\t}\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import type { SqliteValue } from "../../sqlite/index.ts";
2
+ import type { Columns, ColumnTypeOf, ValueOf } from "./columns.ts";
3
+ import { type ColumnRef, type Condition, type WhereNode } from "./expression.ts";
4
+ import type { Order } from "./sql.ts";
5
+ import type { TableDefinition } from "./table.ts";
6
+ /** The column references a table's callbacks get: `e.path`, `e.at`. */
7
+ export type ColumnRefs<C extends Columns> = {
8
+ readonly [K in keyof C & string]: ColumnRef<ValueOf<C[K]>, ColumnTypeOf<C[K]>>;
9
+ };
10
+ /** A query of `table`: its rows, in key order. */
11
+ export declare function query<C extends Columns, K extends readonly string[]>(table: TableDefinition<C, K>): Query<C, K>;
12
+ /**
13
+ * An immutable query of one table: an optional condition (several `where`s are `and`ed) and an order (`orderBy`
14
+ * columns, one direction, the key appended unless already there).
15
+ */
16
+ export declare class Query<C extends Columns = Columns, K extends readonly string[] = readonly string[]> {
17
+ #private;
18
+ readonly table: TableDefinition<C, K>;
19
+ readonly condition: WhereNode | undefined;
20
+ constructor(table: TableDefinition<C, K>, condition: WhereNode | undefined, orderBy: readonly string[], direction: "asc" | "desc" | undefined);
21
+ /** This query with `fn`'s condition too. */
22
+ where(fn: (row: ColumnRefs<C>) => Condition): Query<C, K>;
23
+ /**
24
+ * This query ordered by `fn`'s column next (a non-`opt` `str` or `int` one), in `direction`: one direction per
25
+ * query, no column twice (`invalid/args`).
26
+ */
27
+ orderBy(fn: (row: ColumnRefs<C>) => ColumnRef<unknown, "str" | "int">, direction?: "asc" | "desc"): Query<C, K>;
28
+ /** The order of its rows: the `orderBy` columns, then the key columns not among them. */
29
+ get order(): Order;
30
+ }
31
+ /** The cursor of the position after a row with the order values `values` in the table named `table` (its SQL name). */
32
+ export declare function encodeCursor(table: string, order: Order, values: readonly SqliteValue[]): string;
33
+ /**
34
+ * The order values of `cursor` (a trust boundary: an app hands it back): one made for `table`'s `order` (any
35
+ * condition) in the table named `sqlName` (another object's table of the same definition is another table), each value
36
+ * of its column's type; `invalid/args` otherwise.
37
+ */
38
+ export declare function decodeCursor(table: TableDefinition, sqlName: string, order: Order, cursor: unknown): SqliteValue[];
39
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/next/store/query.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAgB,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE/F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,uEAAuE;AACvE,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,OAAO,IAAI;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,IAAI,KAAK,CAGjB;CACD;AAED,uHAAuH;AACvH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,CAKhG;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAG,WAAW,EAAE,CAuBlH"}
@@ -0,0 +1,97 @@
1
+ // Queries (decision "Query runner"; slice 6a §6, rule 17): `query(Table).where(…).orderBy(…)` as immutable data
2
+ // (the condition compiled when given, the order with the key appended as the tie-break), and the opaque cursors that
3
+ // continue a page, bound to the table, the order columns and the direction.
4
+ import { invalid } from "../data/internal.js";
5
+ import { compileWhere } from "./expression.js";
6
+ import { checkScalar } from "./rows.js";
7
+ /** A query of `table`: its rows, in key order. */
8
+ export function query(table) {
9
+ return new Query(table, undefined, [], undefined);
10
+ }
11
+ /**
12
+ * An immutable query of one table: an optional condition (several `where`s are `and`ed) and an order (`orderBy`
13
+ * columns, one direction, the key appended unless already there).
14
+ */
15
+ export class Query {
16
+ table;
17
+ condition;
18
+ #orderBy;
19
+ #direction;
20
+ constructor(table, condition, orderBy, direction) {
21
+ this.table = table;
22
+ this.condition = condition;
23
+ this.#orderBy = orderBy;
24
+ this.#direction = direction;
25
+ }
26
+ /** This query with `fn`'s condition too. */
27
+ where(fn) {
28
+ // The refs are the table's columns, typed by `C`.
29
+ const compiled = compileWhere(this.table, fn(this.table.refs), "where");
30
+ const condition = this.condition === undefined ? compiled : { and: [this.condition, compiled] };
31
+ return new Query(this.table, condition, this.#orderBy, this.#direction);
32
+ }
33
+ /**
34
+ * This query ordered by `fn`'s column next (a non-`opt` `str` or `int` one), in `direction`: one direction per
35
+ * query, no column twice (`invalid/args`).
36
+ */
37
+ orderBy(fn, direction = "asc") {
38
+ const table = this.table;
39
+ // The refs are `C`'s columns; what the plugin's callback returns is checked below.
40
+ const ref = fn(table.refs);
41
+ const column = table.byName.get(ref?.column ?? "");
42
+ if (column === undefined || column.optional || (column.type !== "str" && column.type !== "int")) {
43
+ throw invalid("args", `${table.name}: orderBy: expected a non-opt str() or int() column`);
44
+ }
45
+ if (this.#orderBy.includes(column.name))
46
+ throw invalid("args", `${table.name}: orderBy: "${column.name}" twice`);
47
+ if (this.#direction !== undefined && this.#direction !== direction) {
48
+ throw invalid("args", `${table.name}: orderBy: one direction per query`);
49
+ }
50
+ return new Query(table, this.condition, [...this.#orderBy, column.name], direction);
51
+ }
52
+ /** The order of its rows: the `orderBy` columns, then the key columns not among them. */
53
+ get order() {
54
+ const columns = [...this.#orderBy, ...this.table.key.filter((column) => !this.#orderBy.includes(column))];
55
+ return { columns, direction: this.#direction ?? "asc" };
56
+ }
57
+ }
58
+ /** The cursor of the position after a row with the order values `values` in the table named `table` (its SQL name). */
59
+ export function encodeCursor(table, order, values) {
60
+ const json = JSON.stringify({ t: table, o: order.columns, d: order.direction, v: values });
61
+ let binary = "";
62
+ for (const byte of new TextEncoder().encode(json))
63
+ binary += String.fromCharCode(byte);
64
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
65
+ }
66
+ /**
67
+ * The order values of `cursor` (a trust boundary: an app hands it back): one made for `table`'s `order` (any
68
+ * condition) in the table named `sqlName` (another object's table of the same definition is another table), each value
69
+ * of its column's type; `invalid/args` otherwise.
70
+ */
71
+ export function decodeCursor(table, sqlName, order, cursor) {
72
+ const refuse = () => {
73
+ throw invalid("args", `${table.name}: the cursor is not one of this table's order`);
74
+ };
75
+ if (typeof cursor !== "string")
76
+ return refuse();
77
+ let decoded;
78
+ try {
79
+ const binary = atob(cursor.replaceAll("-", "+").replaceAll("_", "/"));
80
+ decoded = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(Uint8Array.from(binary, (c) => c.charCodeAt(0))));
81
+ }
82
+ catch {
83
+ return refuse();
84
+ }
85
+ // Wire input: every field is checked below.
86
+ const { t, o, d, v } = (decoded ?? {});
87
+ if (t !== sqlName || d !== order.direction || JSON.stringify(o) !== JSON.stringify(order.columns))
88
+ refuse();
89
+ if (!Array.isArray(v) || v.length !== order.columns.length)
90
+ return refuse();
91
+ return order.columns.map((name, index) => {
92
+ const column = table.byName.get(name);
93
+ // Order columns are non-opt `str` or `int` (checked when the query was built).
94
+ return checkScalar(column.type, v[index], `${table.name}: cursor`);
95
+ });
96
+ }
97
+ //# sourceMappingURL=query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/next/store/query.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,qHAAqH;AACrH,4EAA4E;AAG5E,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAkC,YAAY,EAAkB,MAAM,iBAAiB,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AASxC,kDAAkD;AAClD,MAAM,UAAU,KAAK,CAAiD,KAA4B;IACjG,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,KAAK;IACR,KAAK,CAAwB;IAC7B,SAAS,CAAwB;IACjC,QAAQ,CAAoB;IAC5B,UAAU,CAA6B;IAEhD,YACC,KAA4B,EAC5B,SAAgC,EAChC,OAA0B,EAC1B,SAAqC;QAErC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,4CAA4C;IAC5C,KAAK,CAAC,EAAqC;QAC1C,kDAAkD;QAClD,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,KAA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AAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACxC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;QACvC,+EAA+E;QAC/E,OAAO,WAAW,CAAC,MAAM,CAAC,IAAqB,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,UAAU,CAAoB,CAAC;IACxG,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Queries (decision \"Query runner\"; slice 6a §6, rule 17): `query(Table).where(…).orderBy(…)` as immutable data\n// (the condition compiled when given, the order with the key appended as the tie-break), and the opaque cursors that\n// continue a page, bound to the table, the order columns and the direction.\n\nimport type { SqliteValue } from \"../../sqlite/index.ts\";\nimport { invalid } from \"../data/internal.ts\";\nimport type { Columns, ColumnTypeOf, ValueOf } from \"./columns.ts\";\nimport { type ColumnRef, type Condition, compileWhere, type WhereNode } from \"./expression.ts\";\nimport { checkScalar } from \"./rows.ts\";\nimport type { Order } from \"./sql.ts\";\nimport type { TableDefinition } from \"./table.ts\";\n\n/** The column references a table's callbacks get: `e.path`, `e.at`. */\nexport type ColumnRefs<C extends Columns> = {\n\treadonly [K in keyof C & string]: ColumnRef<ValueOf<C[K]>, ColumnTypeOf<C[K]>>;\n};\n\n/** A query of `table`: its rows, in key order. */\nexport function query<C extends Columns, K extends readonly string[]>(table: TableDefinition<C, K>): Query<C, K> {\n\treturn new Query(table, undefined, [], undefined);\n}\n\n/**\n * An immutable query of one table: an optional condition (several `where`s are `and`ed) and an order (`orderBy`\n * columns, one direction, the key appended unless already there).\n */\nexport class Query<C extends Columns = Columns, K extends readonly string[] = readonly string[]> {\n\treadonly table: TableDefinition<C, K>;\n\treadonly condition: WhereNode | undefined;\n\treadonly #orderBy: readonly string[];\n\treadonly #direction: \"asc\" | \"desc\" | undefined;\n\n\tconstructor(\n\t\ttable: TableDefinition<C, K>,\n\t\tcondition: WhereNode | undefined,\n\t\torderBy: readonly string[],\n\t\tdirection: \"asc\" | \"desc\" | undefined,\n\t) {\n\t\tthis.table = table;\n\t\tthis.condition = condition;\n\t\tthis.#orderBy = orderBy;\n\t\tthis.#direction = direction;\n\t}\n\n\t/** This query with `fn`'s condition too. */\n\twhere(fn: (row: ColumnRefs<C>) => Condition): Query<C, K> {\n\t\t// The refs are the table's columns, typed by `C`.\n\t\tconst compiled = compileWhere(this.table, fn(this.table.refs as ColumnRefs<C>), \"where\");\n\t\tconst condition = this.condition === undefined ? compiled : { and: [this.condition, compiled] };\n\t\treturn new Query(this.table, condition, this.#orderBy, this.#direction);\n\t}\n\n\t/**\n\t * This query ordered by `fn`'s column next (a non-`opt` `str` or `int` one), in `direction`: one direction per\n\t * query, no column twice (`invalid/args`).\n\t */\n\torderBy(\n\t\tfn: (row: ColumnRefs<C>) => ColumnRef<unknown, \"str\" | \"int\">,\n\t\tdirection: \"asc\" | \"desc\" = \"asc\",\n\t): Query<C, K> {\n\t\tconst table = this.table;\n\t\t// The refs are `C`'s columns; what the plugin's callback returns is checked below.\n\t\tconst ref = fn(table.refs as ColumnRefs<C>) as ColumnRef | undefined;\n\t\tconst column = table.byName.get(ref?.column ?? \"\");\n\t\tif (column === undefined || column.optional || (column.type !== \"str\" && column.type !== \"int\")) {\n\t\t\tthrow invalid(\"args\", `${table.name}: orderBy: expected a non-opt str() or int() column`);\n\t\t}\n\t\tif (this.#orderBy.includes(column.name)) throw invalid(\"args\", `${table.name}: orderBy: \"${column.name}\" twice`);\n\t\tif (this.#direction !== undefined && this.#direction !== direction) {\n\t\t\tthrow invalid(\"args\", `${table.name}: orderBy: one direction per query`);\n\t\t}\n\t\treturn new Query(table, this.condition, [...this.#orderBy, column.name], direction);\n\t}\n\n\t/** The order of its rows: the `orderBy` columns, then the key columns not among them. */\n\tget order(): Order {\n\t\tconst columns = [...this.#orderBy, ...this.table.key.filter((column) => !this.#orderBy.includes(column))];\n\t\treturn { columns, direction: this.#direction ?? \"asc\" };\n\t}\n}\n\n/** The cursor of the position after a row with the order values `values` in the table named `table` (its SQL name). */\nexport function encodeCursor(table: string, order: Order, values: readonly SqliteValue[]): string {\n\tconst json = JSON.stringify({ t: table, o: order.columns, d: order.direction, v: values });\n\tlet binary = \"\";\n\tfor (const byte of new TextEncoder().encode(json)) binary += String.fromCharCode(byte);\n\treturn btoa(binary).replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\").replace(/=+$/, \"\");\n}\n\n/**\n * The order values of `cursor` (a trust boundary: an app hands it back): one made for `table`'s `order` (any\n * condition) in the table named `sqlName` (another object's table of the same definition is another table), each value\n * of its column's type; `invalid/args` otherwise.\n */\nexport function decodeCursor(table: TableDefinition, sqlName: string, order: Order, cursor: unknown): SqliteValue[] {\n\tconst refuse = (): never => {\n\t\tthrow invalid(\"args\", `${table.name}: the cursor is not one of this table's order`);\n\t};\n\tif (typeof cursor !== \"string\") return refuse();\n\tlet decoded: unknown;\n\ttry {\n\t\tconst binary = atob(cursor.replaceAll(\"-\", \"+\").replaceAll(\"_\", \"/\"));\n\t\tdecoded = JSON.parse(\n\t\t\tnew TextDecoder(\"utf-8\", { fatal: true }).decode(Uint8Array.from(binary, (c) => c.charCodeAt(0))),\n\t\t);\n\t} catch {\n\t\treturn refuse();\n\t}\n\t// Wire input: every field is checked below.\n\tconst { t, o, d, v } = (decoded ?? {}) as { t?: unknown; o?: unknown; d?: unknown; v?: unknown };\n\tif (t !== sqlName || d !== order.direction || JSON.stringify(o) !== JSON.stringify(order.columns)) refuse();\n\tif (!Array.isArray(v) || v.length !== order.columns.length) return refuse();\n\treturn order.columns.map((name, index) => {\n\t\tconst column = table.byName.get(name)!;\n\t\t// Order columns are non-opt `str` or `int` (checked when the query was built).\n\t\treturn checkScalar(column.type as \"str\" | \"int\", v[index], `${table.name}: cursor`) as string | number;\n\t});\n}\n"]}