@opendatalabs/personal-server-ts-core 1.37.0 → 1.38.1

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 (793) hide show
  1. package/contracts/host-contract.json +115 -0
  2. package/contracts/raw-end.json +2360 -0
  3. package/contracts/replace-conformance.json +729 -0
  4. package/contracts/routes.json +349 -0
  5. package/contracts/run-finish-plan.json +3238 -0
  6. package/contracts/run-saved.json +1308 -0
  7. package/contracts/scope-delete-receipt.json +616 -0
  8. package/dist/api/account-storage-mode.d.ts +77 -0
  9. package/dist/api/account-storage-mode.d.ts.map +1 -0
  10. package/dist/api/account-storage-mode.js +72 -0
  11. package/dist/api/account-storage-mode.js.map +1 -0
  12. package/dist/api/index.d.ts +139 -3
  13. package/dist/api/index.d.ts.map +1 -1
  14. package/dist/api/index.js +973 -191
  15. package/dist/api/index.js.map +1 -1
  16. package/dist/api/legacy-write-gate.d.ts +51 -0
  17. package/dist/api/legacy-write-gate.d.ts.map +1 -0
  18. package/dist/api/legacy-write-gate.js +88 -0
  19. package/dist/api/legacy-write-gate.js.map +1 -0
  20. package/dist/api/owner-connector-delete.d.ts +103 -0
  21. package/dist/api/owner-connector-delete.d.ts.map +1 -0
  22. package/dist/api/owner-connector-delete.js +158 -0
  23. package/dist/api/owner-connector-delete.js.map +1 -0
  24. package/dist/api/pdpp-record-query.d.ts +25 -0
  25. package/dist/api/pdpp-record-query.d.ts.map +1 -0
  26. package/dist/api/pdpp-record-query.js +72 -0
  27. package/dist/api/pdpp-record-query.js.map +1 -0
  28. package/dist/api/pdpp-records-list.d.ts +133 -0
  29. package/dist/api/pdpp-records-list.d.ts.map +1 -0
  30. package/dist/api/pdpp-records-list.js +380 -0
  31. package/dist/api/pdpp-records-list.js.map +1 -0
  32. package/dist/api/scope-delete-verdict.d.ts +107 -0
  33. package/dist/api/scope-delete-verdict.d.ts.map +1 -0
  34. package/dist/api/scope-delete-verdict.js +92 -0
  35. package/dist/api/scope-delete-verdict.js.map +1 -0
  36. package/dist/api/switched-delete-refusal.d.ts +16 -0
  37. package/dist/api/switched-delete-refusal.d.ts.map +1 -0
  38. package/dist/api/switched-delete-refusal.js +30 -0
  39. package/dist/api/switched-delete-refusal.js.map +1 -0
  40. package/dist/client.d.ts +29 -0
  41. package/dist/client.d.ts.map +1 -1
  42. package/dist/client.js +34 -2
  43. package/dist/client.js.map +1 -1
  44. package/dist/contracts/access-logs.d.ts +1 -0
  45. package/dist/contracts/access-logs.d.ts.map +1 -1
  46. package/dist/contracts/access-logs.js +7 -1
  47. package/dist/contracts/access-logs.js.map +1 -1
  48. package/dist/contracts/data.d.ts +12 -0
  49. package/dist/contracts/data.d.ts.map +1 -1
  50. package/dist/contracts/data.js +30 -1
  51. package/dist/contracts/data.js.map +1 -1
  52. package/dist/contracts/grants.d.ts.map +1 -1
  53. package/dist/contracts/grants.js +9 -0
  54. package/dist/contracts/grants.js.map +1 -1
  55. package/dist/contracts/index.d.ts +1 -1
  56. package/dist/contracts/index.d.ts.map +1 -1
  57. package/dist/contracts/index.js +1 -1
  58. package/dist/contracts/index.js.map +1 -1
  59. package/dist/contracts/sync.d.ts +9 -1
  60. package/dist/contracts/sync.d.ts.map +1 -1
  61. package/dist/contracts/sync.js +6 -2
  62. package/dist/contracts/sync.js.map +1 -1
  63. package/dist/derivatives/compute.d.ts.map +1 -1
  64. package/dist/derivatives/compute.js +19 -0
  65. package/dist/derivatives/compute.js.map +1 -1
  66. package/dist/encoding/base64url.d.ts +6 -0
  67. package/dist/encoding/base64url.d.ts.map +1 -0
  68. package/dist/encoding/base64url.js +29 -0
  69. package/dist/encoding/base64url.js.map +1 -0
  70. package/dist/errors/pdpp-catalog.d.ts +1 -1
  71. package/dist/errors/pdpp-catalog.d.ts.map +1 -1
  72. package/dist/errors/pdpp-catalog.js +6 -0
  73. package/dist/errors/pdpp-catalog.js.map +1 -1
  74. package/dist/keys/index.d.ts +1 -0
  75. package/dist/keys/index.d.ts.map +1 -1
  76. package/dist/keys/index.js +1 -0
  77. package/dist/keys/index.js.map +1 -1
  78. package/dist/keys/owner-master-key.d.ts +37 -0
  79. package/dist/keys/owner-master-key.d.ts.map +1 -0
  80. package/dist/keys/owner-master-key.js +45 -0
  81. package/dist/keys/owner-master-key.js.map +1 -0
  82. package/dist/legacy-projection/bindings.d.ts.map +1 -1
  83. package/dist/legacy-projection/bindings.js +10 -4
  84. package/dist/legacy-projection/bindings.js.map +1 -1
  85. package/dist/legacy-projection/erase-connector.d.ts +18 -0
  86. package/dist/legacy-projection/erase-connector.d.ts.map +1 -0
  87. package/dist/legacy-projection/erase-connector.js +29 -0
  88. package/dist/legacy-projection/erase-connector.js.map +1 -0
  89. package/dist/legacy-projection/index.d.ts +17 -0
  90. package/dist/legacy-projection/index.d.ts.map +1 -1
  91. package/dist/legacy-projection/index.js +41 -0
  92. package/dist/legacy-projection/index.js.map +1 -1
  93. package/dist/legacy-projection/types.d.ts +12 -2
  94. package/dist/legacy-projection/types.d.ts.map +1 -1
  95. package/dist/lineage/gateway.d.ts +3 -1
  96. package/dist/lineage/gateway.d.ts.map +1 -1
  97. package/dist/lineage/gateway.js +2 -1
  98. package/dist/lineage/gateway.js.map +1 -1
  99. package/dist/localdb/admit.d.ts +138 -0
  100. package/dist/localdb/admit.d.ts.map +1 -0
  101. package/dist/localdb/admit.js +344 -0
  102. package/dist/localdb/admit.js.map +1 -0
  103. package/dist/localdb/apply-meter.d.ts +14 -0
  104. package/dist/localdb/apply-meter.d.ts.map +1 -0
  105. package/dist/localdb/apply-meter.js +31 -0
  106. package/dist/localdb/apply-meter.js.map +1 -0
  107. package/dist/localdb/apply-progress.d.ts +10 -0
  108. package/dist/localdb/apply-progress.d.ts.map +1 -0
  109. package/dist/localdb/apply-progress.js +39 -0
  110. package/dist/localdb/apply-progress.js.map +1 -0
  111. package/dist/localdb/apply.d.ts +17 -0
  112. package/dist/localdb/apply.d.ts.map +1 -0
  113. package/dist/localdb/apply.js +291 -0
  114. package/dist/localdb/apply.js.map +1 -0
  115. package/dist/localdb/batch-commit.d.ts +70 -0
  116. package/dist/localdb/batch-commit.d.ts.map +1 -0
  117. package/dist/localdb/batch-commit.js +91 -0
  118. package/dist/localdb/batch-commit.js.map +1 -0
  119. package/dist/localdb/batch-contract.d.ts +19 -0
  120. package/dist/localdb/batch-contract.d.ts.map +1 -0
  121. package/dist/localdb/batch-contract.js +24 -0
  122. package/dist/localdb/batch-contract.js.map +1 -0
  123. package/dist/localdb/blobs.d.ts +71 -0
  124. package/dist/localdb/blobs.d.ts.map +1 -0
  125. package/dist/localdb/blobs.js +306 -0
  126. package/dist/localdb/blobs.js.map +1 -0
  127. package/dist/localdb/bootstrap-copy.d.ts +6 -0
  128. package/dist/localdb/bootstrap-copy.d.ts.map +1 -0
  129. package/dist/localdb/bootstrap-copy.js +79 -0
  130. package/dist/localdb/bootstrap-copy.js.map +1 -0
  131. package/dist/localdb/bootstrap-keys.d.ts +33 -0
  132. package/dist/localdb/bootstrap-keys.d.ts.map +1 -0
  133. package/dist/localdb/bootstrap-keys.js +89 -0
  134. package/dist/localdb/bootstrap-keys.js.map +1 -0
  135. package/dist/localdb/bootstrap-swap.d.ts +17 -0
  136. package/dist/localdb/bootstrap-swap.d.ts.map +1 -0
  137. package/dist/localdb/bootstrap-swap.js +78 -0
  138. package/dist/localdb/bootstrap-swap.js.map +1 -0
  139. package/dist/localdb/bootstrap.d.ts +55 -0
  140. package/dist/localdb/bootstrap.d.ts.map +1 -0
  141. package/dist/localdb/bootstrap.js +195 -0
  142. package/dist/localdb/bootstrap.js.map +1 -0
  143. package/dist/localdb/complete-read.d.ts +77 -0
  144. package/dist/localdb/complete-read.d.ts.map +1 -0
  145. package/dist/localdb/complete-read.js +136 -0
  146. package/dist/localdb/complete-read.js.map +1 -0
  147. package/dist/localdb/connection-link.d.ts +12 -0
  148. package/dist/localdb/connection-link.d.ts.map +1 -0
  149. package/dist/localdb/connection-link.js +79 -0
  150. package/dist/localdb/connection-link.js.map +1 -0
  151. package/dist/localdb/cursor.d.ts +61 -0
  152. package/dist/localdb/cursor.d.ts.map +1 -0
  153. package/dist/localdb/cursor.js +178 -0
  154. package/dist/localdb/cursor.js.map +1 -0
  155. package/dist/localdb/cycle.d.ts +69 -0
  156. package/dist/localdb/cycle.d.ts.map +1 -0
  157. package/dist/localdb/cycle.js +189 -0
  158. package/dist/localdb/cycle.js.map +1 -0
  159. package/dist/localdb/delete-batch.d.ts +29 -0
  160. package/dist/localdb/delete-batch.d.ts.map +1 -0
  161. package/dist/localdb/delete-batch.js +84 -0
  162. package/dist/localdb/delete-batch.js.map +1 -0
  163. package/dist/localdb/delete-lifetime.d.ts +24 -0
  164. package/dist/localdb/delete-lifetime.d.ts.map +1 -0
  165. package/dist/localdb/delete-lifetime.js +83 -0
  166. package/dist/localdb/delete-lifetime.js.map +1 -0
  167. package/dist/localdb/delete.d.ts +88 -0
  168. package/dist/localdb/delete.d.ts.map +1 -0
  169. package/dist/localdb/delete.js +521 -0
  170. package/dist/localdb/delete.js.map +1 -0
  171. package/dist/localdb/delta-apply.d.ts +4 -0
  172. package/dist/localdb/delta-apply.d.ts.map +1 -0
  173. package/dist/localdb/delta-apply.js +253 -0
  174. package/dist/localdb/delta-apply.js.map +1 -0
  175. package/dist/localdb/deps.d.ts +87 -0
  176. package/dist/localdb/deps.d.ts.map +1 -0
  177. package/dist/localdb/deps.js +10 -0
  178. package/dist/localdb/deps.js.map +1 -0
  179. package/dist/localdb/driver.d.ts +51 -0
  180. package/dist/localdb/driver.d.ts.map +1 -0
  181. package/dist/localdb/driver.js +3 -0
  182. package/dist/localdb/driver.js.map +1 -0
  183. package/dist/localdb/fence.d.ts +31 -0
  184. package/dist/localdb/fence.d.ts.map +1 -0
  185. package/dist/localdb/fence.js +69 -0
  186. package/dist/localdb/fence.js.map +1 -0
  187. package/dist/localdb/history.d.ts +76 -0
  188. package/dist/localdb/history.d.ts.map +1 -0
  189. package/dist/localdb/history.js +256 -0
  190. package/dist/localdb/history.js.map +1 -0
  191. package/dist/localdb/import-fingerprint.d.ts +8 -0
  192. package/dist/localdb/import-fingerprint.d.ts.map +1 -0
  193. package/dist/localdb/import-fingerprint.js +35 -0
  194. package/dist/localdb/import-fingerprint.js.map +1 -0
  195. package/dist/localdb/import-ledger.d.ts +27 -0
  196. package/dist/localdb/import-ledger.d.ts.map +1 -0
  197. package/dist/localdb/import-ledger.js +197 -0
  198. package/dist/localdb/import-ledger.js.map +1 -0
  199. package/dist/localdb/import-readback.d.ts +8 -0
  200. package/dist/localdb/import-readback.d.ts.map +1 -0
  201. package/dist/localdb/import-readback.js +69 -0
  202. package/dist/localdb/import-readback.js.map +1 -0
  203. package/dist/localdb/import-snapshot.d.ts +21 -0
  204. package/dist/localdb/import-snapshot.d.ts.map +1 -0
  205. package/dist/localdb/import-snapshot.js +94 -0
  206. package/dist/localdb/import-snapshot.js.map +1 -0
  207. package/dist/localdb/index.d.ts +42 -0
  208. package/dist/localdb/index.d.ts.map +1 -0
  209. package/dist/localdb/index.js +40 -0
  210. package/dist/localdb/index.js.map +1 -0
  211. package/dist/localdb/legacy-import-types.d.ts +112 -0
  212. package/dist/localdb/legacy-import-types.d.ts.map +1 -0
  213. package/dist/localdb/legacy-import-types.js +2 -0
  214. package/dist/localdb/legacy-import-types.js.map +1 -0
  215. package/dist/localdb/legacy-import.d.ts +67 -0
  216. package/dist/localdb/legacy-import.d.ts.map +1 -0
  217. package/dist/localdb/legacy-import.js +320 -0
  218. package/dist/localdb/legacy-import.js.map +1 -0
  219. package/dist/localdb/legacy-retire.d.ts +26 -0
  220. package/dist/localdb/legacy-retire.d.ts.map +1 -0
  221. package/dist/localdb/legacy-retire.js +93 -0
  222. package/dist/localdb/legacy-retire.js.map +1 -0
  223. package/dist/localdb/lifetime.d.ts +29 -0
  224. package/dist/localdb/lifetime.d.ts.map +1 -0
  225. package/dist/localdb/lifetime.js +64 -0
  226. package/dist/localdb/lifetime.js.map +1 -0
  227. package/dist/localdb/listing.d.ts +70 -0
  228. package/dist/localdb/listing.d.ts.map +1 -0
  229. package/dist/localdb/listing.js +345 -0
  230. package/dist/localdb/listing.js.map +1 -0
  231. package/dist/localdb/log-apply.d.ts +46 -0
  232. package/dist/localdb/log-apply.d.ts.map +1 -0
  233. package/dist/localdb/log-apply.js +827 -0
  234. package/dist/localdb/log-apply.js.map +1 -0
  235. package/dist/localdb/log-batch.d.ts +204 -0
  236. package/dist/localdb/log-batch.d.ts.map +1 -0
  237. package/dist/localdb/log-batch.js +418 -0
  238. package/dist/localdb/log-batch.js.map +1 -0
  239. package/dist/localdb/log-bodies.d.ts +27 -0
  240. package/dist/localdb/log-bodies.d.ts.map +1 -0
  241. package/dist/localdb/log-bodies.js +142 -0
  242. package/dist/localdb/log-bodies.js.map +1 -0
  243. package/dist/localdb/log-bootstrap-stage.d.ts +5 -0
  244. package/dist/localdb/log-bootstrap-stage.d.ts.map +1 -0
  245. package/dist/localdb/log-bootstrap-stage.js +60 -0
  246. package/dist/localdb/log-bootstrap-stage.js.map +1 -0
  247. package/dist/localdb/log-bootstrap.d.ts +23 -0
  248. package/dist/localdb/log-bootstrap.d.ts.map +1 -0
  249. package/dist/localdb/log-bootstrap.js +399 -0
  250. package/dist/localdb/log-bootstrap.js.map +1 -0
  251. package/dist/localdb/log-compact.d.ts +28 -0
  252. package/dist/localdb/log-compact.d.ts.map +1 -0
  253. package/dist/localdb/log-compact.js +83 -0
  254. package/dist/localdb/log-compact.js.map +1 -0
  255. package/dist/localdb/log-keyed.d.ts +118 -0
  256. package/dist/localdb/log-keyed.d.ts.map +1 -0
  257. package/dist/localdb/log-keyed.js +640 -0
  258. package/dist/localdb/log-keyed.js.map +1 -0
  259. package/dist/localdb/log-progressive.d.ts +18 -0
  260. package/dist/localdb/log-progressive.d.ts.map +1 -0
  261. package/dist/localdb/log-progressive.js +58 -0
  262. package/dist/localdb/log-progressive.js.map +1 -0
  263. package/dist/localdb/log-publish-phases.d.ts +31 -0
  264. package/dist/localdb/log-publish-phases.d.ts.map +1 -0
  265. package/dist/localdb/log-publish-phases.js +40 -0
  266. package/dist/localdb/log-publish-phases.js.map +1 -0
  267. package/dist/localdb/log-publish.d.ts +16 -0
  268. package/dist/localdb/log-publish.d.ts.map +1 -0
  269. package/dist/localdb/log-publish.js +1745 -0
  270. package/dist/localdb/log-publish.js.map +1 -0
  271. package/dist/localdb/log-rebase.d.ts +12 -0
  272. package/dist/localdb/log-rebase.d.ts.map +1 -0
  273. package/dist/localdb/log-rebase.js +74 -0
  274. package/dist/localdb/log-rebase.js.map +1 -0
  275. package/dist/localdb/log-recommit.d.ts +15 -0
  276. package/dist/localdb/log-recommit.d.ts.map +1 -0
  277. package/dist/localdb/log-recommit.js +88 -0
  278. package/dist/localdb/log-recommit.js.map +1 -0
  279. package/dist/localdb/log-seed.d.ts +25 -0
  280. package/dist/localdb/log-seed.d.ts.map +1 -0
  281. package/dist/localdb/log-seed.js +129 -0
  282. package/dist/localdb/log-seed.js.map +1 -0
  283. package/dist/localdb/log-state.d.ts +34 -0
  284. package/dist/localdb/log-state.d.ts.map +1 -0
  285. package/dist/localdb/log-state.js +79 -0
  286. package/dist/localdb/log-state.js.map +1 -0
  287. package/dist/localdb/merge.d.ts +122 -0
  288. package/dist/localdb/merge.d.ts.map +1 -0
  289. package/dist/localdb/merge.js +339 -0
  290. package/dist/localdb/merge.js.map +1 -0
  291. package/dist/localdb/migrate.d.ts +10 -0
  292. package/dist/localdb/migrate.d.ts.map +1 -0
  293. package/dist/localdb/migrate.js +27 -0
  294. package/dist/localdb/migrate.js.map +1 -0
  295. package/dist/localdb/name.d.ts +10 -0
  296. package/dist/localdb/name.d.ts.map +1 -0
  297. package/dist/localdb/name.js +15 -0
  298. package/dist/localdb/name.js.map +1 -0
  299. package/dist/localdb/open.d.ts +33 -0
  300. package/dist/localdb/open.d.ts.map +1 -0
  301. package/dist/localdb/open.js +46 -0
  302. package/dist/localdb/open.js.map +1 -0
  303. package/dist/localdb/part-layout.d.ts +6 -0
  304. package/dist/localdb/part-layout.d.ts.map +1 -0
  305. package/dist/localdb/part-layout.js +6 -0
  306. package/dist/localdb/part-layout.js.map +1 -0
  307. package/dist/localdb/part-readahead.d.ts +87 -0
  308. package/dist/localdb/part-readahead.d.ts.map +1 -0
  309. package/dist/localdb/part-readahead.js +130 -0
  310. package/dist/localdb/part-readahead.js.map +1 -0
  311. package/dist/localdb/partial-load.d.ts +42 -0
  312. package/dist/localdb/partial-load.d.ts.map +1 -0
  313. package/dist/localdb/partial-load.js +120 -0
  314. package/dist/localdb/partial-load.js.map +1 -0
  315. package/dist/localdb/partial-read.d.ts +64 -0
  316. package/dist/localdb/partial-read.d.ts.map +1 -0
  317. package/dist/localdb/partial-read.js +110 -0
  318. package/dist/localdb/partial-read.js.map +1 -0
  319. package/dist/localdb/plan-inputs.d.ts +31 -0
  320. package/dist/localdb/plan-inputs.d.ts.map +1 -0
  321. package/dist/localdb/plan-inputs.js +26 -0
  322. package/dist/localdb/plan-inputs.js.map +1 -0
  323. package/dist/localdb/publication-work.d.ts +20 -0
  324. package/dist/localdb/publication-work.d.ts.map +1 -0
  325. package/dist/localdb/publication-work.js +60 -0
  326. package/dist/localdb/publication-work.js.map +1 -0
  327. package/dist/localdb/publish-meter.d.ts +32 -0
  328. package/dist/localdb/publish-meter.d.ts.map +1 -0
  329. package/dist/localdb/publish-meter.js +36 -0
  330. package/dist/localdb/publish-meter.js.map +1 -0
  331. package/dist/localdb/publish.d.ts +153 -0
  332. package/dist/localdb/publish.d.ts.map +1 -0
  333. package/dist/localdb/publish.js +329 -0
  334. package/dist/localdb/publish.js.map +1 -0
  335. package/dist/localdb/purge.d.ts +40 -0
  336. package/dist/localdb/purge.d.ts.map +1 -0
  337. package/dist/localdb/purge.js +159 -0
  338. package/dist/localdb/purge.js.map +1 -0
  339. package/dist/localdb/query.d.ts +77 -0
  340. package/dist/localdb/query.d.ts.map +1 -0
  341. package/dist/localdb/query.js +330 -0
  342. package/dist/localdb/query.js.map +1 -0
  343. package/dist/localdb/queue.d.ts +10 -0
  344. package/dist/localdb/queue.d.ts.map +1 -0
  345. package/dist/localdb/queue.js +31 -0
  346. package/dist/localdb/queue.js.map +1 -0
  347. package/dist/localdb/raw-end-evidence.d.ts +16 -0
  348. package/dist/localdb/raw-end-evidence.d.ts.map +1 -0
  349. package/dist/localdb/raw-end-evidence.js +27 -0
  350. package/dist/localdb/raw-end-evidence.js.map +1 -0
  351. package/dist/localdb/read-selection.d.ts +182 -0
  352. package/dist/localdb/read-selection.d.ts.map +1 -0
  353. package/dist/localdb/read-selection.js +290 -0
  354. package/dist/localdb/read-selection.js.map +1 -0
  355. package/dist/localdb/registered-read.d.ts +15 -0
  356. package/dist/localdb/registered-read.d.ts.map +1 -0
  357. package/dist/localdb/registered-read.js +62 -0
  358. package/dist/localdb/registered-read.js.map +1 -0
  359. package/dist/localdb/replace.d.ts +33 -0
  360. package/dist/localdb/replace.d.ts.map +1 -0
  361. package/dist/localdb/replace.js +22 -0
  362. package/dist/localdb/replace.js.map +1 -0
  363. package/dist/localdb/requirements.d.ts +35 -0
  364. package/dist/localdb/requirements.d.ts.map +1 -0
  365. package/dist/localdb/requirements.js +66 -0
  366. package/dist/localdb/requirements.js.map +1 -0
  367. package/dist/localdb/resolve.d.ts +69 -0
  368. package/dist/localdb/resolve.d.ts.map +1 -0
  369. package/dist/localdb/resolve.js +436 -0
  370. package/dist/localdb/resolve.js.map +1 -0
  371. package/dist/localdb/run-end.d.ts +35 -0
  372. package/dist/localdb/run-end.d.ts.map +1 -0
  373. package/dist/localdb/run-end.js +520 -0
  374. package/dist/localdb/run-end.js.map +1 -0
  375. package/dist/localdb/run-intake.d.ts +17 -0
  376. package/dist/localdb/run-intake.d.ts.map +1 -0
  377. package/dist/localdb/run-intake.js +662 -0
  378. package/dist/localdb/run-intake.js.map +1 -0
  379. package/dist/localdb/run-receipts.d.ts +19 -0
  380. package/dist/localdb/run-receipts.d.ts.map +1 -0
  381. package/dist/localdb/run-receipts.js +151 -0
  382. package/dist/localdb/run-receipts.js.map +1 -0
  383. package/dist/localdb/schema.d.ts +7 -0
  384. package/dist/localdb/schema.d.ts.map +1 -0
  385. package/dist/localdb/schema.js +686 -0
  386. package/dist/localdb/schema.js.map +1 -0
  387. package/dist/localdb/seed.d.ts +39 -0
  388. package/dist/localdb/seed.d.ts.map +1 -0
  389. package/dist/localdb/seed.js +188 -0
  390. package/dist/localdb/seed.js.map +1 -0
  391. package/dist/localdb/slot.d.ts +9 -0
  392. package/dist/localdb/slot.d.ts.map +1 -0
  393. package/dist/localdb/slot.js +15 -0
  394. package/dist/localdb/slot.js.map +1 -0
  395. package/dist/localdb/stream-digest.d.ts +35 -0
  396. package/dist/localdb/stream-digest.d.ts.map +1 -0
  397. package/dist/localdb/stream-digest.js +50 -0
  398. package/dist/localdb/stream-digest.js.map +1 -0
  399. package/dist/localdb/sync.d.ts +75 -0
  400. package/dist/localdb/sync.d.ts.map +1 -0
  401. package/dist/localdb/sync.js +339 -0
  402. package/dist/localdb/sync.js.map +1 -0
  403. package/dist/localdb/system-stream-descriptor.d.ts +22 -0
  404. package/dist/localdb/system-stream-descriptor.d.ts.map +1 -0
  405. package/dist/localdb/system-stream-descriptor.js +24 -0
  406. package/dist/localdb/system-stream-descriptor.js.map +1 -0
  407. package/dist/localdb/system-stream-page.d.ts +15 -0
  408. package/dist/localdb/system-stream-page.d.ts.map +1 -0
  409. package/dist/localdb/system-stream-page.js +98 -0
  410. package/dist/localdb/system-stream-page.js.map +1 -0
  411. package/dist/localdb/system-streams.d.ts +35 -0
  412. package/dist/localdb/system-streams.d.ts.map +1 -0
  413. package/dist/localdb/system-streams.js +350 -0
  414. package/dist/localdb/system-streams.js.map +1 -0
  415. package/dist/localdb/transfer-memory.d.ts +17 -0
  416. package/dist/localdb/transfer-memory.d.ts.map +1 -0
  417. package/dist/localdb/transfer-memory.js +17 -0
  418. package/dist/localdb/transfer-memory.js.map +1 -0
  419. package/dist/localdb/unwrite.d.ts +28 -0
  420. package/dist/localdb/unwrite.d.ts.map +1 -0
  421. package/dist/localdb/unwrite.js +62 -0
  422. package/dist/localdb/unwrite.js.map +1 -0
  423. package/dist/localdb/update-required.d.ts +10 -0
  424. package/dist/localdb/update-required.d.ts.map +1 -0
  425. package/dist/localdb/update-required.js +27 -0
  426. package/dist/localdb/update-required.js.map +1 -0
  427. package/dist/localdb/view-changes.d.ts +58 -0
  428. package/dist/localdb/view-changes.d.ts.map +1 -0
  429. package/dist/localdb/view-changes.js +174 -0
  430. package/dist/localdb/view-changes.js.map +1 -0
  431. package/dist/logging/access-log.d.ts +2 -2
  432. package/dist/logging/access-log.d.ts.map +1 -1
  433. package/dist/logging/access-reader.d.ts +4 -1
  434. package/dist/logging/access-reader.d.ts.map +1 -1
  435. package/dist/logging/activity-stream.d.ts +37 -0
  436. package/dist/logging/activity-stream.d.ts.map +1 -0
  437. package/dist/logging/activity-stream.js +86 -0
  438. package/dist/logging/activity-stream.js.map +1 -0
  439. package/dist/mcp/approval-url.d.ts +32 -0
  440. package/dist/mcp/approval-url.d.ts.map +1 -1
  441. package/dist/mcp/approval-url.js +76 -0
  442. package/dist/mcp/approval-url.js.map +1 -1
  443. package/dist/mcp/connection-api.d.ts +54 -27
  444. package/dist/mcp/connection-api.d.ts.map +1 -1
  445. package/dist/mcp/connection-api.js +267 -77
  446. package/dist/mcp/connection-api.js.map +1 -1
  447. package/dist/mcp/grant-registration.d.ts +15 -0
  448. package/dist/mcp/grant-registration.d.ts.map +1 -0
  449. package/dist/mcp/grant-registration.js +44 -0
  450. package/dist/mcp/grant-registration.js.map +1 -0
  451. package/dist/mcp/index.d.ts +1 -0
  452. package/dist/mcp/index.d.ts.map +1 -1
  453. package/dist/mcp/index.js +1 -0
  454. package/dist/mcp/index.js.map +1 -1
  455. package/dist/mcp/read-client.d.ts +32 -10
  456. package/dist/mcp/read-client.d.ts.map +1 -1
  457. package/dist/mcp/read-client.js +299 -15
  458. package/dist/mcp/read-client.js.map +1 -1
  459. package/dist/mcp/resources.d.ts +3 -1
  460. package/dist/mcp/resources.d.ts.map +1 -1
  461. package/dist/mcp/resources.js +11 -2
  462. package/dist/mcp/resources.js.map +1 -1
  463. package/dist/mcp/server.d.ts +17 -0
  464. package/dist/mcp/server.d.ts.map +1 -1
  465. package/dist/mcp/server.js +54 -7
  466. package/dist/mcp/server.js.map +1 -1
  467. package/dist/mcp/session.d.ts +2 -0
  468. package/dist/mcp/session.d.ts.map +1 -1
  469. package/dist/mcp/session.js +41 -8
  470. package/dist/mcp/session.js.map +1 -1
  471. package/dist/mcp/store.d.ts +14 -1
  472. package/dist/mcp/store.d.ts.map +1 -1
  473. package/dist/mcp/store.js +31 -2
  474. package/dist/mcp/store.js.map +1 -1
  475. package/dist/mcp/tools.d.ts +62 -0
  476. package/dist/mcp/tools.d.ts.map +1 -1
  477. package/dist/mcp/tools.js +186 -64
  478. package/dist/mcp/tools.js.map +1 -1
  479. package/dist/mcp/types.d.ts +3 -1
  480. package/dist/mcp/types.d.ts.map +1 -1
  481. package/dist/oura/index.d.ts +1 -1
  482. package/dist/oura/index.d.ts.map +1 -1
  483. package/dist/oura/index.js +15 -0
  484. package/dist/oura/index.js.map +1 -1
  485. package/dist/payment/x402.d.ts +6 -3
  486. package/dist/payment/x402.d.ts.map +1 -1
  487. package/dist/payment/x402.js +35 -0
  488. package/dist/payment/x402.js.map +1 -1
  489. package/dist/pdpp/pkce.d.ts +1 -22
  490. package/dist/pdpp/pkce.d.ts.map +1 -1
  491. package/dist/pdpp/pkce.js +3 -2
  492. package/dist/pdpp/pkce.js.map +1 -1
  493. package/dist/policy/reserved-scopes.d.ts +3 -0
  494. package/dist/policy/reserved-scopes.d.ts.map +1 -1
  495. package/dist/policy/reserved-scopes.js +12 -1
  496. package/dist/policy/reserved-scopes.js.map +1 -1
  497. package/dist/ports/index.d.ts +61 -9
  498. package/dist/ports/index.d.ts.map +1 -1
  499. package/dist/ports/index.js.map +1 -1
  500. package/dist/publication/publish.d.ts +31 -1
  501. package/dist/publication/publish.d.ts.map +1 -1
  502. package/dist/publication/publish.js +30 -14
  503. package/dist/publication/publish.js.map +1 -1
  504. package/dist/replication/copies.d.ts +1 -1
  505. package/dist/replication/dpv2.d.ts.map +1 -1
  506. package/dist/replication/dpv2.js +33 -0
  507. package/dist/replication/dpv2.js.map +1 -1
  508. package/dist/schemas/server-config.d.ts +16 -0
  509. package/dist/schemas/server-config.d.ts.map +1 -1
  510. package/dist/schemas/server-config.js +49 -0
  511. package/dist/schemas/server-config.js.map +1 -1
  512. package/dist/storage/adapters/interface.d.ts +12 -2
  513. package/dist/storage/adapters/interface.d.ts.map +1 -1
  514. package/dist/storage/adapters/interface.js.map +1 -1
  515. package/dist/storage/adapters/rate-limit-policy.d.ts +71 -0
  516. package/dist/storage/adapters/rate-limit-policy.d.ts.map +1 -0
  517. package/dist/storage/adapters/rate-limit-policy.js +107 -0
  518. package/dist/storage/adapters/rate-limit-policy.js.map +1 -0
  519. package/dist/storage/adapters/sdk.d.ts +7 -0
  520. package/dist/storage/adapters/sdk.d.ts.map +1 -1
  521. package/dist/storage/adapters/sdk.js +12 -6
  522. package/dist/storage/adapters/sdk.js.map +1 -1
  523. package/dist/storage/adapters/throttle.d.ts +30 -0
  524. package/dist/storage/adapters/throttle.d.ts.map +1 -0
  525. package/dist/storage/adapters/throttle.js +94 -0
  526. package/dist/storage/adapters/throttle.js.map +1 -0
  527. package/dist/storage/adapters/vana-audience.d.ts +4 -1
  528. package/dist/storage/adapters/vana-audience.d.ts.map +1 -1
  529. package/dist/storage/adapters/vana-audience.js +23 -11
  530. package/dist/storage/adapters/vana-audience.js.map +1 -1
  531. package/dist/storage/adapters/vana.d.ts +5 -0
  532. package/dist/storage/adapters/vana.d.ts.map +1 -1
  533. package/dist/storage/adapters/vana.js +82 -18
  534. package/dist/storage/adapters/vana.js.map +1 -1
  535. package/dist/storage/blocks/cursor.d.ts.map +1 -1
  536. package/dist/storage/blocks/cursor.js +3 -13
  537. package/dist/storage/blocks/cursor.js.map +1 -1
  538. package/dist/storage/canonical-legacy-projection.d.ts +13 -1
  539. package/dist/storage/canonical-legacy-projection.d.ts.map +1 -1
  540. package/dist/storage/canonical-legacy-projection.js +92 -24
  541. package/dist/storage/canonical-legacy-projection.js.map +1 -1
  542. package/dist/storage/hierarchy/paths.d.ts.map +1 -1
  543. package/dist/storage/hierarchy/paths.js +9 -2
  544. package/dist/storage/hierarchy/paths.js.map +1 -1
  545. package/dist/storage/index/manager.d.ts +19 -5
  546. package/dist/storage/index/manager.d.ts.map +1 -1
  547. package/dist/storage/legacy-scope-view.d.ts +4 -6
  548. package/dist/storage/legacy-scope-view.d.ts.map +1 -1
  549. package/dist/storage/legacy-scope-view.js +50 -57
  550. package/dist/storage/legacy-scope-view.js.map +1 -1
  551. package/dist/storage/legacy-write-seal.d.ts +73 -0
  552. package/dist/storage/legacy-write-seal.d.ts.map +1 -0
  553. package/dist/storage/legacy-write-seal.js +74 -0
  554. package/dist/storage/legacy-write-seal.js.map +1 -0
  555. package/dist/storage/pdpp-records/cursor.d.ts.map +1 -1
  556. package/dist/storage/pdpp-records/cursor.js +3 -29
  557. package/dist/storage/pdpp-records/cursor.js.map +1 -1
  558. package/dist/storage/pdpp-records/declaration-witness.d.ts.map +1 -1
  559. package/dist/storage/pdpp-records/declaration-witness.js +4 -3
  560. package/dist/storage/pdpp-records/declaration-witness.js.map +1 -1
  561. package/dist/storage/pdpp-records/types.d.ts +2 -0
  562. package/dist/storage/pdpp-records/types.d.ts.map +1 -1
  563. package/dist/storage/pdpp-records/types.js.map +1 -1
  564. package/dist/stream-sync/artifacts.d.ts +38 -0
  565. package/dist/stream-sync/artifacts.d.ts.map +1 -0
  566. package/dist/stream-sync/artifacts.js +179 -0
  567. package/dist/stream-sync/artifacts.js.map +1 -0
  568. package/dist/stream-sync/blobs.d.ts +18 -0
  569. package/dist/stream-sync/blobs.d.ts.map +1 -0
  570. package/dist/stream-sync/blobs.js +83 -0
  571. package/dist/stream-sync/blobs.js.map +1 -0
  572. package/dist/stream-sync/crypto-port.d.ts +30 -0
  573. package/dist/stream-sync/crypto-port.d.ts.map +1 -0
  574. package/dist/stream-sync/crypto-port.js +29 -0
  575. package/dist/stream-sync/crypto-port.js.map +1 -0
  576. package/dist/stream-sync/crypto.d.ts +27 -0
  577. package/dist/stream-sync/crypto.d.ts.map +1 -0
  578. package/dist/stream-sync/crypto.js +67 -0
  579. package/dist/stream-sync/crypto.js.map +1 -0
  580. package/dist/stream-sync/delete-metadata.d.ts +23 -0
  581. package/dist/stream-sync/delete-metadata.d.ts.map +1 -0
  582. package/dist/stream-sync/delete-metadata.js +40 -0
  583. package/dist/stream-sync/delete-metadata.js.map +1 -0
  584. package/dist/stream-sync/design-flags.d.ts +31 -0
  585. package/dist/stream-sync/design-flags.d.ts.map +1 -0
  586. package/dist/stream-sync/design-flags.js +44 -0
  587. package/dist/stream-sync/design-flags.js.map +1 -0
  588. package/dist/stream-sync/host-contract.d.ts +50 -0
  589. package/dist/stream-sync/host-contract.d.ts.map +1 -0
  590. package/dist/stream-sync/host-contract.js +80 -0
  591. package/dist/stream-sync/host-contract.js.map +1 -0
  592. package/dist/stream-sync/index.d.ts +19 -0
  593. package/dist/stream-sync/index.d.ts.map +1 -0
  594. package/dist/stream-sync/index.js +19 -0
  595. package/dist/stream-sync/index.js.map +1 -0
  596. package/dist/stream-sync/intake.d.ts +319 -0
  597. package/dist/stream-sync/intake.d.ts.map +1 -0
  598. package/dist/stream-sync/intake.js +62 -0
  599. package/dist/stream-sync/intake.js.map +1 -0
  600. package/dist/stream-sync/memory-registry.d.ts +85 -0
  601. package/dist/stream-sync/memory-registry.d.ts.map +1 -0
  602. package/dist/stream-sync/memory-registry.js +293 -0
  603. package/dist/stream-sync/memory-registry.js.map +1 -0
  604. package/dist/stream-sync/normalize-raw-end.d.ts +25 -0
  605. package/dist/stream-sync/normalize-raw-end.d.ts.map +1 -0
  606. package/dist/stream-sync/normalize-raw-end.js +177 -0
  607. package/dist/stream-sync/normalize-raw-end.js.map +1 -0
  608. package/dist/stream-sync/ports.d.ts +486 -0
  609. package/dist/stream-sync/ports.d.ts.map +1 -0
  610. package/dist/stream-sync/ports.js +91 -0
  611. package/dist/stream-sync/ports.js.map +1 -0
  612. package/dist/stream-sync/publish-plan.d.ts +129 -0
  613. package/dist/stream-sync/publish-plan.d.ts.map +1 -0
  614. package/dist/stream-sync/publish-plan.js +134 -0
  615. package/dist/stream-sync/publish-plan.js.map +1 -0
  616. package/dist/stream-sync/raw-end.d.ts +59 -0
  617. package/dist/stream-sync/raw-end.d.ts.map +1 -0
  618. package/dist/stream-sync/raw-end.js +113 -0
  619. package/dist/stream-sync/raw-end.js.map +1 -0
  620. package/dist/stream-sync/registry.d.ts +31 -0
  621. package/dist/stream-sync/registry.d.ts.map +1 -0
  622. package/dist/stream-sync/registry.js +645 -0
  623. package/dist/stream-sync/registry.js.map +1 -0
  624. package/dist/stream-sync/run-finish-plan.d.ts +61 -0
  625. package/dist/stream-sync/run-finish-plan.d.ts.map +1 -0
  626. package/dist/stream-sync/run-finish-plan.js +373 -0
  627. package/dist/stream-sync/run-finish-plan.js.map +1 -0
  628. package/dist/stream-sync/run-saved.d.ts +51 -0
  629. package/dist/stream-sync/run-saved.d.ts.map +1 -0
  630. package/dist/stream-sync/run-saved.js +83 -0
  631. package/dist/stream-sync/run-saved.js.map +1 -0
  632. package/dist/stream-sync/scope-routing.d.ts +17 -0
  633. package/dist/stream-sync/scope-routing.d.ts.map +1 -0
  634. package/dist/stream-sync/scope-routing.js +24 -0
  635. package/dist/stream-sync/scope-routing.js.map +1 -0
  636. package/dist/stream-sync/seed-staging.d.ts +85 -0
  637. package/dist/stream-sync/seed-staging.d.ts.map +1 -0
  638. package/dist/stream-sync/seed-staging.js +325 -0
  639. package/dist/stream-sync/seed-staging.js.map +1 -0
  640. package/dist/stream-sync/semver.d.ts +3 -0
  641. package/dist/stream-sync/semver.d.ts.map +1 -0
  642. package/dist/stream-sync/semver.js +49 -0
  643. package/dist/stream-sync/semver.js.map +1 -0
  644. package/dist/stream-sync/send-gate.d.ts +149 -0
  645. package/dist/stream-sync/send-gate.d.ts.map +1 -0
  646. package/dist/stream-sync/send-gate.js +382 -0
  647. package/dist/stream-sync/send-gate.js.map +1 -0
  648. package/dist/stream-sync/storage-retry.d.ts +216 -0
  649. package/dist/stream-sync/storage-retry.d.ts.map +1 -0
  650. package/dist/stream-sync/storage-retry.js +315 -0
  651. package/dist/stream-sync/storage-retry.js.map +1 -0
  652. package/dist/stream-sync/stream-aead.d.ts +33 -0
  653. package/dist/stream-sync/stream-aead.d.ts.map +1 -0
  654. package/dist/stream-sync/stream-aead.js +183 -0
  655. package/dist/stream-sync/stream-aead.js.map +1 -0
  656. package/dist/stream-sync/timer.d.ts +3 -0
  657. package/dist/stream-sync/timer.d.ts.map +1 -0
  658. package/dist/stream-sync/timer.js +3 -0
  659. package/dist/stream-sync/timer.js.map +1 -0
  660. package/dist/stream-sync-read/index.d.ts +4 -0
  661. package/dist/stream-sync-read/index.d.ts.map +1 -0
  662. package/dist/stream-sync-read/index.js +3 -0
  663. package/dist/stream-sync-read/index.js.map +1 -0
  664. package/dist/stream-sync-read/routing.d.ts +27 -0
  665. package/dist/stream-sync-read/routing.d.ts.map +1 -0
  666. package/dist/stream-sync-read/routing.js +49 -0
  667. package/dist/stream-sync-read/routing.js.map +1 -0
  668. package/dist/stream-sync-read/service.d.ts +281 -0
  669. package/dist/stream-sync-read/service.d.ts.map +1 -0
  670. package/dist/stream-sync-read/service.js +18 -0
  671. package/dist/stream-sync-read/service.js.map +1 -0
  672. package/dist/sync/account-mode/authority.d.ts +121 -0
  673. package/dist/sync/account-mode/authority.d.ts.map +1 -0
  674. package/dist/sync/account-mode/authority.js +446 -0
  675. package/dist/sync/account-mode/authority.js.map +1 -0
  676. package/dist/sync/account-mode/evidence-wire.d.ts +42 -0
  677. package/dist/sync/account-mode/evidence-wire.d.ts.map +1 -0
  678. package/dist/sync/account-mode/evidence-wire.js +76 -0
  679. package/dist/sync/account-mode/evidence-wire.js.map +1 -0
  680. package/dist/sync/account-mode/import-waker.d.ts +36 -0
  681. package/dist/sync/account-mode/import-waker.d.ts.map +1 -0
  682. package/dist/sync/account-mode/import-waker.js +55 -0
  683. package/dist/sync/account-mode/import-waker.js.map +1 -0
  684. package/dist/sync/account-mode/index.d.ts +10 -0
  685. package/dist/sync/account-mode/index.d.ts.map +1 -0
  686. package/dist/sync/account-mode/index.js +10 -0
  687. package/dist/sync/account-mode/index.js.map +1 -0
  688. package/dist/sync/account-mode/port.d.ts +11 -0
  689. package/dist/sync/account-mode/port.d.ts.map +1 -0
  690. package/dist/sync/account-mode/port.js +21 -0
  691. package/dist/sync/account-mode/port.js.map +1 -0
  692. package/dist/sync/account-mode/record.d.ts +54 -0
  693. package/dist/sync/account-mode/record.d.ts.map +1 -0
  694. package/dist/sync/account-mode/record.js +62 -0
  695. package/dist/sync/account-mode/record.js.map +1 -0
  696. package/dist/sync/account-mode/rw-lock.d.ts +14 -0
  697. package/dist/sync/account-mode/rw-lock.d.ts.map +1 -0
  698. package/dist/sync/account-mode/rw-lock.js +59 -0
  699. package/dist/sync/account-mode/rw-lock.js.map +1 -0
  700. package/dist/sync/cancellable-gateway.d.ts +25 -0
  701. package/dist/sync/cancellable-gateway.d.ts.map +1 -0
  702. package/dist/sync/cancellable-gateway.js +64 -0
  703. package/dist/sync/cancellable-gateway.js.map +1 -0
  704. package/dist/sync/engine/change-probe.d.ts +49 -0
  705. package/dist/sync/engine/change-probe.d.ts.map +1 -0
  706. package/dist/sync/engine/change-probe.js +84 -0
  707. package/dist/sync/engine/change-probe.js.map +1 -0
  708. package/dist/sync/engine/change-push.d.ts +56 -0
  709. package/dist/sync/engine/change-push.d.ts.map +1 -0
  710. package/dist/sync/engine/change-push.js +176 -0
  711. package/dist/sync/engine/change-push.js.map +1 -0
  712. package/dist/sync/engine/sync-manager.d.ts +208 -1
  713. package/dist/sync/engine/sync-manager.d.ts.map +1 -1
  714. package/dist/sync/engine/sync-manager.js +1005 -34
  715. package/dist/sync/engine/sync-manager.js.map +1 -1
  716. package/dist/sync/index.d.ts +6 -2
  717. package/dist/sync/index.d.ts.map +1 -1
  718. package/dist/sync/index.js +5 -1
  719. package/dist/sync/index.js.map +1 -1
  720. package/dist/sync/pdpp-import.d.ts +12 -2
  721. package/dist/sync/pdpp-import.d.ts.map +1 -1
  722. package/dist/sync/pdpp-import.js +32 -7
  723. package/dist/sync/pdpp-import.js.map +1 -1
  724. package/dist/sync/tombstone-resubmits.d.ts +7 -4
  725. package/dist/sync/tombstone-resubmits.d.ts.map +1 -1
  726. package/dist/sync/tombstone-resubmits.js.map +1 -1
  727. package/dist/sync/types.d.ts +29 -0
  728. package/dist/sync/types.d.ts.map +1 -1
  729. package/dist/sync/upload-attempts.d.ts +244 -0
  730. package/dist/sync/upload-attempts.d.ts.map +1 -0
  731. package/dist/sync/upload-attempts.js +548 -0
  732. package/dist/sync/upload-attempts.js.map +1 -0
  733. package/dist/sync/upload-state.d.ts +163 -0
  734. package/dist/sync/upload-state.d.ts.map +1 -0
  735. package/dist/sync/upload-state.js +239 -0
  736. package/dist/sync/upload-state.js.map +1 -0
  737. package/dist/sync/workers/delete.d.ts +33 -1
  738. package/dist/sync/workers/delete.d.ts.map +1 -1
  739. package/dist/sync/workers/delete.js +83 -11
  740. package/dist/sync/workers/delete.js.map +1 -1
  741. package/dist/sync/workers/download.d.ts +3 -0
  742. package/dist/sync/workers/download.d.ts.map +1 -1
  743. package/dist/sync/workers/download.js +67 -12
  744. package/dist/sync/workers/download.js.map +1 -1
  745. package/dist/sync/workers/upload.d.ts +70 -2
  746. package/dist/sync/workers/upload.d.ts.map +1 -1
  747. package/dist/sync/workers/upload.js +354 -23
  748. package/dist/sync/workers/upload.js.map +1 -1
  749. package/dist/test-support/memory-oracle.calibration.d.ts +16 -0
  750. package/dist/test-support/memory-oracle.calibration.d.ts.map +1 -0
  751. package/dist/test-support/memory-oracle.calibration.js +43 -0
  752. package/dist/test-support/memory-oracle.calibration.js.map +1 -0
  753. package/dist/test-support/memory-oracle.d.ts +82 -0
  754. package/dist/test-support/memory-oracle.d.ts.map +1 -0
  755. package/dist/test-support/memory-oracle.js +104 -0
  756. package/dist/test-support/memory-oracle.js.map +1 -0
  757. package/dist/test-utils/account-mode.d.ts +36 -0
  758. package/dist/test-utils/account-mode.d.ts.map +1 -0
  759. package/dist/test-utils/account-mode.js +78 -0
  760. package/dist/test-utils/account-mode.js.map +1 -0
  761. package/dist/test-utils/index.d.ts +3 -0
  762. package/dist/test-utils/index.d.ts.map +1 -1
  763. package/dist/test-utils/index.js +3 -0
  764. package/dist/test-utils/index.js.map +1 -1
  765. package/dist/test-utils/legacy-write-seal.d.ts +16 -0
  766. package/dist/test-utils/legacy-write-seal.d.ts.map +1 -0
  767. package/dist/test-utils/legacy-write-seal.js +20 -0
  768. package/dist/test-utils/legacy-write-seal.js.map +1 -0
  769. package/dist/test-utils/live-grants.d.ts +24 -0
  770. package/dist/test-utils/live-grants.d.ts.map +1 -0
  771. package/dist/test-utils/live-grants.js +6 -0
  772. package/dist/test-utils/live-grants.js.map +1 -0
  773. package/dist/test-utils/memory-storage.d.ts +17 -1
  774. package/dist/test-utils/memory-storage.d.ts.map +1 -1
  775. package/dist/test-utils/memory-storage.js +94 -46
  776. package/dist/test-utils/memory-storage.js.map +1 -1
  777. package/dist/test-utils/run-end.d.ts +27 -0
  778. package/dist/test-utils/run-end.d.ts.map +1 -0
  779. package/dist/test-utils/run-end.js +44 -0
  780. package/dist/test-utils/run-end.js.map +1 -0
  781. package/dist/test-utils/wallet.d.ts +0 -4
  782. package/dist/test-utils/wallet.d.ts.map +1 -1
  783. package/dist/test-utils/wallet.js +3 -12
  784. package/dist/test-utils/wallet.js.map +1 -1
  785. package/dist/write/attribution.d.ts.map +1 -1
  786. package/dist/write/attribution.js +2 -4
  787. package/dist/write/attribution.js.map +1 -1
  788. package/dist-test/localdb/conformance.d.ts +13 -0
  789. package/dist-test/localdb/conformance.d.ts.map +1 -0
  790. package/dist-test/localdb/conformance.js +372 -0
  791. package/dist-test/localdb/conformance.js.map +1 -0
  792. package/dist-test/tsconfig.tsbuildinfo +1 -0
  793. package/package.json +60 -5
@@ -0,0 +1,640 @@
1
+ // The keyed first load: a device with no rows loads a log it has never read key
2
+ // by key, not segment by segment.
3
+ //
4
+ // Why. The keys of a log are in publish order and `records` is in key order, so
5
+ // a segment's rows land across the whole table and its secondary indexes, and a
6
+ // commit rewrites about as many pages as the table has leaves (the log's keys
7
+ // are hashes; see `pk_hash`). A host whose every page write costs a call (the
8
+ // Web's OPFS) pays for each. Committing segments together (`applyInGroups`)
9
+ // divides the commits, but each one still rewrites most of the table: the cost
10
+ // is the number of commits times the table, and the memory budget sets the
11
+ // number of commits. Loading in key order writes each page once.
12
+ //
13
+ // How. Two phases; the cursor (`log_state`) and the streams' heads move only in
14
+ // the last commit, so no reader sees a state between them.
15
+ //
16
+ // 1. Stage. The segments are fetched, checked and hashed as `applyInGroups`
17
+ // does it (read-ahead against the memory budget), and each operation is
18
+ // appended to the stage table of its key range ("bucket": a range of the
19
+ // first digits of the key's hash). Appending to P tables is sequential
20
+ // writing; nothing touches `records`.
21
+ // 2. Apply. One bucket at a time, in one transaction: the keys that have one
22
+ // operation, an upsert (nearly all of a first import), merge in one batch
23
+ // that the merge reads in key order; the keys that have several or a
24
+ // deletion go through the same statements a segment-by-segment load uses,
25
+ // one position at a time, so what the merge does for them is not
26
+ // re-derived here. The bucket's stage table is dropped in the same
27
+ // transaction.
28
+ //
29
+ // Why it is the same fold: an operation changes only its own key's row and
30
+ // tombstone, so keys are independent and a key's operations apply in position
31
+ // order in both. What differs is the order in which two keys are written, so
32
+ // `record_changes` holds the same changes per key in another order across keys.
33
+ // The model: `KeyedLoad` and `KeyedPublish` in docs/formal/log-protocol.
34
+ //
35
+ // How many buckets is not a number here: the rows of a bucket are in the stage
36
+ // table and in `temp.incoming` while it applies, so a bucket is half the
37
+ // memory budget, and the buckets are the log's bytes over that (`keyedBuckets`).
38
+ // A log that fits in the budget has one commit's worth of rows and gains
39
+ // nothing from this: it takes the pass of `applyInGroups`.
40
+ //
41
+ // What a stopped load leaves. Each bucket's commit makes its rows and
42
+ // tombstones durable in `records` and `log_tombstones`, but the streams have no
43
+ // version row, so no reader serves them, and the cursor is where it was. Those
44
+ // rows are bound to the position the load meant to publish: bucket 0's commit
45
+ // also writes `log_keyed_pending` (that position, the base and the segment
46
+ // refs), and the commit that publishes deletes it. A retry may publish only a
47
+ // target that `pendingAdmits` accepts (same base, no shorter, same data hashes
48
+ // at the pending refs): a retry that can fetch fewer segments than the stopped
49
+ // load wrote would otherwise publish rows from beyond its cursor. A refused
50
+ // retry writes nothing and raises. While the marker exists and the log can
51
+ // still finish it, `applyLog` takes this path whatever the flags say. A log
52
+ // that cannot (a snapshot, a compaction, a different log) has no key-ordered
53
+ // load that could finish what was written, and the rows left cannot be told
54
+ // apart from rows of the live log: `applyLog` rebaselines (below). The marker holds back every other way to move the
55
+ // position, not only the load plan: the lifetime branches of `applyLog` (a log
56
+ // read as ended, a log of an earlier lifetime) write a cursor without applying
57
+ // anything, and a device that holds a cursor above 0 beside the marker is not
58
+ // one this load made, so each of them raises with the marker kept. The model:
59
+ // `KeyedBucket`, `KeyedPage`, `PendingAdmits`, `NoPending`.
60
+ //
61
+ // The way out. A log that compacted, or was rewritten, after a stopped load has
62
+ // nothing a key-ordered load can finish, and the rows the stopped load left are
63
+ // not told apart from rows of the live log (no per-key record says which
64
+ // position wrote a row). `keyedLoadBlocked` names that case (a snapshot, no
65
+ // segment past the marker, the flag off, another base, another segment at a
66
+ // position the marker names) and `rebaselineKeyedLoad` ends it: in one batch it
67
+ // drops the rows the load wrote, the log's tombstones and the marker, and the
68
+ // first load restarts from the log as it is now. A device that holds nothing
69
+ // of the log's streams (no cursor, no stream version) loses nothing the log
70
+ // does not hold; what is kept is the rows of a local write the device has not
71
+ // published (below). A log that only reads short (a segment that cannot be
72
+ // fetched now, a registry that lags) is not this case: the marker stands and
73
+ // the retry is refused until the log is whole, as `pendingAdmits` says. The
74
+ // model: `Rebaseline`, `Unfinishable`, and `EventuallyConverged` in
75
+ // docs/formal/log-protocol.
76
+ //
77
+ // A segment that cannot be fetched ends staging there: if no bucket has
78
+ // committed yet, the segments before it load, the cursor stands at the last of
79
+ // them, and the error is raised, as it is when they apply one by one.
80
+ //
81
+ // What a bucket holds. Its simple keys (one upsert) merge from the stage table
82
+ // in SQL, so they hold nothing in memory. Its complex keys (several operations,
83
+ // deletes, omissions) are read into memory to build statements. `STAGE_ROW_BYTES`
84
+ // counts every row by what it holds (key, hash and body in UTF-8 bytes, NULL
85
+ // bodies and tombstone rows included), and a bucket whose complex rows exceed
86
+ // the room is applied a page at a time (`complexPages`: a hash range, or a
87
+ // position slice of one key), each page in its own commit. This is weighted
88
+ // in-flight accounting against the governor's budget, not a hard memory bound:
89
+ // the SQLite driver and the statements a page builds are not counted, and a
90
+ // page is held at twice its row bytes to cover them.
91
+ import { sha256 } from "@noble/hashes/sha2";
92
+ import { followMeta, toHex, } from "@opendatalabs/personal-server-ts-stream-sync";
93
+ import { withOrigin } from "./merge.js";
94
+ import { applyInGroups, rowsPerStatement, commitStaged, mergeStaged, operationStatements, prepareOperations, streamHeadStatements, streamStateStatement, } from "./log-batch.js";
95
+ import { clearKeyedPending, LogDivergedError, readKeyedPending, writeKeyedPending, writeLogState, } from "./log-state.js";
96
+ import { holdMemory } from "./transfer-memory.js";
97
+ /**
98
+ * Hex digits of a key's hash that place it in a bucket. The count of buckets
99
+ * is the log's bytes over half the memory budget (`keyedBuckets`) and is capped
100
+ * by the key space, 16^PLACING_DIGITS, which is also the most stage tables a
101
+ * load can create. With 4 digits the cap is 65,536 tables, reached only by a
102
+ * log of `32,768 x budget` bytes, so the cap never decides the plan for a log
103
+ * a device can hold; a fifth digit would only raise a table-count ceiling that
104
+ * no log reaches, while 3 (4,096) would cap a log of `2,048 x budget`. A key's
105
+ * hash is uniform, so a range holds its share of the bytes within the variance
106
+ * of that many keys, not by construction.
107
+ */
108
+ const PLACING_DIGITS = 4;
109
+ const KEY_SPACE = 16 ** PLACING_DIGITS;
110
+ /**
111
+ * How many key ranges a log of `totalBytes` splits into so that one range
112
+ * (twice: its stage rows and the rows being merged) fits in the memory budget.
113
+ */
114
+ export function keyedBuckets(segmentBytes, budgetBytes) {
115
+ const total = segmentBytes.reduce((sum, bytes) => sum + bytes, 0);
116
+ // A budget under two segments (the read-ahead holds a segment as plain and
117
+ // as encrypted bytes) still admits one alone, so a range holds one at least.
118
+ const room = Math.max(budgetBytes, 2 * Math.max(0, ...segmentBytes));
119
+ return Math.min(KEY_SPACE, Math.max(1, Math.ceil((2 * total) / room)));
120
+ }
121
+ /**
122
+ * Whether this pass loads key by key, and into how many ranges. It does when
123
+ * the device holds nothing of the log's streams (no stream version, so no
124
+ * reader serves a row, and no position) and the log is more than the memory
125
+ * budget can apply in one commit. Not with a snapshot: its parts are
126
+ * key-ordered already and load as they are.
127
+ *
128
+ * A host that shows a stream while it loads (`progressiveFirstLoad`) loads
129
+ * key by key too. Segment by segment, each commit rewrites most of the table
130
+ * (see the top of this file): on the Web's OPFS a 198,001-row log took 378 s
131
+ * that way and 26 s key by key, and the rows the progressive load would show
132
+ * meanwhile reach no listing, which serves a stream only once its head is
133
+ * complete. The key-ordered load shows the streams when its last range
134
+ * commits.
135
+ */
136
+ export async function planKeyedLoad(deps, connectionId, local, snapshotPresent, tail, pending = null) {
137
+ const buckets = keyedBuckets(tail.map((ref) => ref.bytes), deps.blobs.governor.limitBytes);
138
+ if (pending !== null) {
139
+ // An unfinished key-ordered load left rows in `records` that only a
140
+ // key-ordered load that covers them may publish over. The rest of the
141
+ // gate (a flag, the size of the log) decided how the first attempt began;
142
+ // it does not decide how to end it. `applyLog` rebaselines a connection
143
+ // whose log cannot finish it (`keyedLoadBlocked`) before it gets here, so
144
+ // this refusal holds the line for any other caller.
145
+ if (snapshotPresent || tail.length === 0 || deps.keyedFirstLoad === false)
146
+ throw unfinishedKeyedLoad(pending, snapshotPresent
147
+ ? "the log has a snapshot now"
148
+ : tail.length === 0
149
+ ? "the log holds no segment past it"
150
+ : "the key-ordered first load is off");
151
+ return buckets;
152
+ }
153
+ if (deps.keyedFirstLoad === false ||
154
+ snapshotPresent ||
155
+ local.position !== 0 ||
156
+ tail.length < 2)
157
+ return null;
158
+ if (buckets < 2)
159
+ return null;
160
+ const [held] = await deps.db.query("SELECT COUNT(*) AS n FROM (SELECT 1 FROM stream_versions WHERE connection_id = ? LIMIT 1)", [connectionId]);
161
+ return held?.n === 0 ? buckets : null;
162
+ }
163
+ /**
164
+ * The refusal of every path that cannot finish an unfinished key-ordered load
165
+ * of this connection and may not drop it. Its rows are in `records` and
166
+ * `log_tombstones` and belong to no published position; the way out is a
167
+ * key-ordered load of the same log, or `rebaselineKeyedLoad` when the log can
168
+ * no longer be one.
169
+ */
170
+ export function unfinishedKeyedLoad(pending, why) {
171
+ return new LogDivergedError(`apply: an earlier key-ordered load of this connection wrote rows up to position ${pending.position} and did not finish; only a key-ordered load of the same log can finish it, or a rebaseline (${why})`);
172
+ }
173
+ /**
174
+ * Whether the rows an unfinished key-ordered load left (`pending`) lie inside
175
+ * the prefix that a load ending at `target` publishes: the same log (the same
176
+ * segment at every position they name) and no shorter. A load that holds less
177
+ * (a segment it cannot fetch now) must leave the cursor where it is, because
178
+ * the rows beyond it would become visible, or hide a row of the prefix, under
179
+ * a cursor that does not cover them.
180
+ */
181
+ export function pendingAdmits(pending, target) {
182
+ if (pending === null)
183
+ return true;
184
+ if (pending.base !== target.base || pending.position > target.position)
185
+ return false;
186
+ const hashes = new Map(target.refs.map((ref) => [ref.position, ref.dataHash.toLowerCase()]));
187
+ return pending.refs.every((ref) => hashes.get(ref.position) === ref.dataHash.toLowerCase());
188
+ }
189
+ /**
190
+ * Why no key-ordered load of this log can finish the one that stopped (the
191
+ * marker `pending`), or `null` when one still can. `target` is the state the
192
+ * load would publish: the last segment of the plan, or `null` when the plan
193
+ * holds none.
194
+ *
195
+ * Blocked: the load is off, the plan starts from a snapshot, the plan holds no
196
+ * segment, the log's base is not the one the rows were written under, or the
197
+ * log names another segment at a position the marker names. A log that holds
198
+ * the marker's prefix and is only shorter (a lagging registry) is not blocked:
199
+ * the load that cannot fetch the whole prefix is refused by `pendingAdmits`
200
+ * with the marker kept, and ends when the log is whole.
201
+ */
202
+ export function keyedLoadBlocked(deps, pending, plan) {
203
+ if (deps.keyedFirstLoad === false)
204
+ return "the key-ordered first load is off";
205
+ if (plan.snapshotPresent)
206
+ return "the log has a snapshot now";
207
+ const { target } = plan;
208
+ if (target === null)
209
+ return "the log holds no segment past the marker";
210
+ if (pending.base !== target.base)
211
+ return "the log's base moved";
212
+ const named = new Map(target.refs.map((ref) => [ref.position, ref.dataHash.toLowerCase()]));
213
+ for (const ref of pending.refs) {
214
+ const hash = named.get(ref.position);
215
+ if (hash === undefined
216
+ ? target.position >= ref.position
217
+ : hash !== ref.dataHash.toLowerCase())
218
+ return "the log names another segment than the rows were written from";
219
+ }
220
+ return null;
221
+ }
222
+ /**
223
+ * End an unfinished key-ordered load that no load can finish (`keyedLoadBlocked`):
224
+ * in ONE batch (a failing statement rolls all back, so the marker never
225
+ * outlives the decision to drop its rows), delete the rows the load wrote, the
226
+ * log's tombstones and the marker, as `purgeConnection` does for the rows of a
227
+ * lifetime. The cursor is at 0 by the marker's invariant (the commit that
228
+ * writes it also clears the marker), so its row is deleted as well.
229
+ *
230
+ * What stays is every row that is the newest local write of its key the
231
+ * device has not published (a `record_changes` upsert of origin `local`,
232
+ * `import` or `refresh` past the stream's `publish_watermark`, at the row's own
233
+ * stamp: the test `mergeIncoming` uses to keep a key an omission names). Those
234
+ * writes exist nowhere else. The retry loads the log's rows under them, and
235
+ * the merge is order-insensitive per key, so the result is the one a device
236
+ * that held the write before the log would have. Streams' rows (`stream_state`,
237
+ * with the watermarks), `record_tombstones` and `record_changes` are not touched.
238
+ */
239
+ export async function rebaselineKeyedLoad(deps, connectionId, why) {
240
+ const { changes } = await deps.db.batch(withOrigin("purge", [
241
+ {
242
+ sql: `DELETE FROM records
243
+ WHERE connection_id = ?
244
+ AND NOT EXISTS (
245
+ SELECT 1 FROM record_changes ch
246
+ WHERE ch.connection_id = records.connection_id
247
+ AND ch.stream = records.stream
248
+ AND ch.pk_hash = records.pk_hash
249
+ AND ch.origin IN ('local','import','refresh')
250
+ AND ch.op = 'upsert'
251
+ AND ch.stamp_o = records.stamp_o
252
+ AND ch.stamp_r = records.stamp_r
253
+ AND ch.seq > COALESCE(
254
+ (SELECT s.publish_watermark FROM stream_state s
255
+ WHERE s.connection_id = ch.connection_id AND s.stream = ch.stream), 0))`,
256
+ params: [connectionId],
257
+ },
258
+ {
259
+ sql: "DELETE FROM log_tombstones WHERE connection_id = ?",
260
+ params: [connectionId],
261
+ },
262
+ clearKeyedPending(connectionId),
263
+ {
264
+ sql: "DELETE FROM log_state WHERE connection_id = ?",
265
+ params: [connectionId],
266
+ },
267
+ ]));
268
+ deps.logger.info({ connectionId, why, rowsDropped: changes[1] }, "rebaseline unfinished key-ordered load");
269
+ }
270
+ /** The stage tables of one connection: its id hashed, so any id is a name. */
271
+ const tagOf = (connectionId) => toHex(sha256(new TextEncoder().encode(connectionId)));
272
+ const stageTable = (tag, bucket) => `log_stage_${tag}_${bucket}`;
273
+ const bucketOf = (pkHash, buckets) => Math.floor((Number.parseInt(pkHash.slice(0, PLACING_DIGITS), 16) * buckets) /
274
+ KEY_SPACE);
275
+ const STAGE_COLUMNS = "position, kind, stream, pk_hash, record_key, stamp_o, stamp_r, body, body_sha256, first_o, stamp_n";
276
+ /**
277
+ * The keys of a stage table that are not one upsert: written more than once, or
278
+ * deleted or omitted. Those apply through the statements of a segment, one
279
+ * position at a time.
280
+ */
281
+ const complexKeys = (table) => `SELECT stream, pk_hash FROM ${table} GROUP BY stream, pk_hash
282
+ HAVING COUNT(*) > 1 OR MAX(kind <> 'u')`;
283
+ async function dropStages(deps, tag) {
284
+ const stale = await deps.db.query("SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE ? ESCAPE '\\'", [`log\\_stage\\_${tag}\\_%`]);
285
+ if (stale.length > 0)
286
+ await deps.db.batch(stale.map(({ name }) => ({
287
+ sql: `DROP TABLE IF EXISTS ${name}`,
288
+ params: [],
289
+ })));
290
+ }
291
+ /** Variables a stage row binds. */
292
+ const STAGE_FIELDS = STAGE_COLUMNS.split(",").length;
293
+ /**
294
+ * The rows a batch's operations add to the stage tables, each in its key's
295
+ * bucket. A bucket's rows go in multi-row inserts, in the order they came: a
296
+ * statement costs the host a call, a row is a few variables.
297
+ */
298
+ function stageStatements(tag, buckets, position, operations) {
299
+ const rowsOf = new Map();
300
+ const add = (kind, stream, pkHash, recordKey, stampO, stampR, upsert) => {
301
+ const bucket = bucketOf(pkHash, buckets);
302
+ const row = [
303
+ position,
304
+ kind,
305
+ stream,
306
+ pkHash,
307
+ recordKey,
308
+ stampO,
309
+ stampR,
310
+ upsert?.body ?? null,
311
+ upsert?.bodySha256 ?? null,
312
+ upsert?.firstO ?? null,
313
+ upsert?.ordinal ?? 0,
314
+ ];
315
+ const rows = rowsOf.get(bucket);
316
+ if (rows)
317
+ rows.push(row);
318
+ else
319
+ rowsOf.set(bucket, [row]);
320
+ };
321
+ for (const operation of operations) {
322
+ if (operation.kind === "upsert")
323
+ add("u", operation.stream, operation.pkHash, operation.recordKey, operation.stampO, operation.stampR, operation);
324
+ else if (operation.kind === "complete")
325
+ for (const omission of operation.omitted)
326
+ add("o", operation.stream, omission.pkHash, omission.recordKey, operation.stampO, operation.stampR);
327
+ else
328
+ add(operation.kind === "delete" ? "d" : "o", operation.stream, operation.pkHash, operation.recordKey, operation.stampO, operation.stampR);
329
+ }
330
+ const perStatement = rowsPerStatement(STAGE_FIELDS);
331
+ const statements = [];
332
+ for (const [bucket, rows] of rowsOf)
333
+ for (let i = 0; i < rows.length; i += perStatement) {
334
+ const group = rows.slice(i, i + perStatement);
335
+ statements.push({
336
+ sql: `INSERT INTO ${stageTable(tag, bucket)} (${STAGE_COLUMNS}) VALUES ${group
337
+ .map(() => `(${"?, ".repeat(STAGE_FIELDS - 1)}?)`)
338
+ .join(", ")}`,
339
+ params: group.flat(),
340
+ });
341
+ }
342
+ return statements;
343
+ }
344
+ /** A stage row as the operation it stands for. */
345
+ function operationOf(row) {
346
+ if (row.kind === "u")
347
+ return {
348
+ kind: "upsert",
349
+ stream: row.stream,
350
+ pkHash: row.pk_hash,
351
+ recordKey: row.record_key,
352
+ stampO: row.stamp_o,
353
+ stampR: row.stamp_r,
354
+ body: row.body,
355
+ bodySha256: row.body_sha256,
356
+ firstO: row.first_o,
357
+ ordinal: row.stamp_n,
358
+ };
359
+ return {
360
+ kind: row.kind === "d" ? "delete" : "omitted",
361
+ stream: row.stream,
362
+ pkHash: row.pk_hash,
363
+ recordKey: row.record_key,
364
+ stampO: row.stamp_o,
365
+ stampR: row.stamp_r,
366
+ };
367
+ }
368
+ /**
369
+ * Load `sources` (the segments after the device's position, in order) key by
370
+ * key into `buckets` key ranges, and move the cursor to the last one loaded.
371
+ * Throws the error that ended the staging, after loading what came before it.
372
+ */
373
+ export async function loadKeyed(deps, connectionId, sources, buckets) {
374
+ const tag = tagOf(connectionId);
375
+ await dropStages(deps, tag);
376
+ try {
377
+ await deps.db.batch([
378
+ {
379
+ sql: `CREATE TEMP TABLE IF NOT EXISTS log_complex (stream TEXT NOT NULL, pk_hash TEXT NOT NULL,
380
+ PRIMARY KEY (stream, pk_hash)) WITHOUT ROWID`,
381
+ params: [],
382
+ },
383
+ ...Array.from({ length: buckets }, (_, bucket) => ({
384
+ sql: `CREATE TABLE ${stageTable(tag, bucket)} (position INTEGER NOT NULL, kind TEXT NOT NULL,
385
+ stream TEXT NOT NULL, pk_hash TEXT NOT NULL, record_key TEXT NOT NULL,
386
+ stamp_o INTEGER NOT NULL, stamp_r TEXT NOT NULL, body TEXT, body_sha256 TEXT, first_o INTEGER,
387
+ stamp_n INTEGER NOT NULL DEFAULT 0)`,
388
+ params: [],
389
+ })),
390
+ ]);
391
+ // Phase 1: stage.
392
+ const infos = [];
393
+ const items = sources.map((source, position) => ({
394
+ bytes: source.bytes,
395
+ stage: async () => {
396
+ const { batch, identity } = await source.load();
397
+ const operations = await prepareOperations(batch.streams, batch.operations);
398
+ // Only what the heads need: the operations are not kept.
399
+ infos[position] = {
400
+ streams: batch.streams,
401
+ generation: batch.generation,
402
+ observedAt: batch.observedAt,
403
+ identity,
404
+ };
405
+ return {
406
+ op: deps.newOp(),
407
+ statements: stageStatements(tag, buckets, position, operations),
408
+ };
409
+ },
410
+ }));
411
+ let staged = 0;
412
+ let stopped;
413
+ try {
414
+ await applyInGroups(deps, items, {
415
+ firstAlone: false,
416
+ onCommit: (_first, last) => {
417
+ staged = last + 1;
418
+ },
419
+ });
420
+ }
421
+ catch (error) {
422
+ stopped = { error };
423
+ }
424
+ if (staged === 0)
425
+ throw stopped?.error;
426
+ // Phase 2: apply, one bucket per transaction.
427
+ const heads = new Map();
428
+ const primaryKeys = new Map();
429
+ for (const info of infos.slice(0, staged))
430
+ for (const meta of info.streams) {
431
+ if (!primaryKeys.has(meta.stream))
432
+ primaryKeys.set(meta.stream, meta);
433
+ heads.set(meta.stream, {
434
+ ...info,
435
+ meta: followMeta(heads.get(meta.stream)?.meta, meta),
436
+ });
437
+ }
438
+ const last = sources[staged - 1].state;
439
+ // What an unfinished load of this connection wrote must lie inside the
440
+ // prefix this one publishes; if it does not, write nothing.
441
+ if (!pendingAdmits(await readKeyedPending(deps, connectionId), last)) {
442
+ if (stopped)
443
+ throw stopped.error;
444
+ throw new LogDivergedError("apply: the log is not the one an earlier key-ordered load of this connection wrote rows from");
445
+ }
446
+ for (let bucket = 0; bucket < buckets; bucket++)
447
+ await applyBucket(deps, connectionId, tag, bucket, {
448
+ // The first range creates the streams' rows and names the position
449
+ // the rows it and the later ranges write belong to.
450
+ first: bucket === 0
451
+ ? { primaryKeys: [...primaryKeys.values()], target: last }
452
+ : undefined,
453
+ last: bucket === buckets - 1
454
+ ? { heads: [...heads.values()], state: last }
455
+ : undefined,
456
+ });
457
+ if (stopped)
458
+ throw stopped.error;
459
+ }
460
+ finally {
461
+ await dropStages(deps, tag).catch(() => undefined);
462
+ }
463
+ }
464
+ /**
465
+ * What a stage row holds in memory, in bytes: every text field as UTF-8 (a
466
+ * body or a key of non-ASCII text is more bytes than characters) and each
467
+ * number as 8. A deletion or an omission has no body and still holds its keys.
468
+ */
469
+ const STAGE_ROW_BYTES = `(
470
+ LENGTH(CAST(kind AS BLOB)) + LENGTH(CAST(stream AS BLOB)) + LENGTH(CAST(pk_hash AS BLOB))
471
+ + LENGTH(CAST(record_key AS BLOB)) + LENGTH(CAST(stamp_r AS BLOB))
472
+ + COALESCE(LENGTH(CAST(body AS BLOB)), 0) + COALESCE(LENGTH(CAST(body_sha256 AS BLOB)), 0)
473
+ + 4 * 8)`;
474
+ const PAGE_FILTER = "pk_hash >= ? AND pk_hash < ? AND position BETWEEN ? AND ?";
475
+ const pageParams = (page) => [
476
+ page.from,
477
+ page.to,
478
+ page.firstPosition,
479
+ page.lastPosition,
480
+ ];
481
+ async function weighPage(deps, table, page) {
482
+ const [weight] = await deps.db.query(`SELECT COUNT(*) AS n, COALESCE(SUM(${STAGE_ROW_BYTES}), 0) AS bytes
483
+ FROM ${table} WHERE ${PAGE_FILTER}
484
+ AND (stream, pk_hash) IN (${complexKeys(table)})`, pageParams(page));
485
+ return weight;
486
+ }
487
+ /**
488
+ * The slices the complex rows of a bucket are applied in, each holding at most
489
+ * `room` bytes (as `weighPage` counts them, twice: the rows and the statements
490
+ * made from them). One slice for a bucket that fits, which is nearly always: the
491
+ * bucket count already divides the log's bytes by the budget. A bucket whose
492
+ * keys cluster (their hashes share a prefix) splits by the next hex digit of
493
+ * the hash until each piece fits. A single key whose operations are over the
494
+ * room splits by position: its operations apply in position order, and a slice
495
+ * is a run of them.
496
+ */
497
+ export async function complexPages(deps, table, room) {
498
+ const all = {
499
+ from: "",
500
+ to: "g",
501
+ firstPosition: 0,
502
+ lastPosition: Number.MAX_SAFE_INTEGER,
503
+ bytes: 0,
504
+ };
505
+ const split = async (prefix) => {
506
+ const page = { ...all, from: prefix, to: `${prefix}g` };
507
+ const weight = await weighPage(deps, table, page);
508
+ if (weight.n === 0)
509
+ return [];
510
+ if (2 * weight.bytes <= room)
511
+ return [{ ...page, bytes: weight.bytes }];
512
+ if (prefix.length < 64) {
513
+ const pieces = [];
514
+ for (const digit of "0123456789abcdef")
515
+ pieces.push(...(await split(prefix + digit)));
516
+ return pieces;
517
+ }
518
+ // One key: slice its positions.
519
+ const byPosition = await deps.db.query(`SELECT position, SUM(${STAGE_ROW_BYTES}) AS bytes FROM ${table}
520
+ WHERE pk_hash = ? AND (stream, pk_hash) IN (${complexKeys(table)})
521
+ GROUP BY position ORDER BY position`, [prefix]);
522
+ const slices = [];
523
+ let start = byPosition[0].position;
524
+ let held = 0;
525
+ for (const { position, bytes } of byPosition) {
526
+ if (held > 0 && 2 * (held + bytes) > room) {
527
+ slices.push({
528
+ ...page,
529
+ firstPosition: start,
530
+ lastPosition: position - 1,
531
+ bytes: held,
532
+ });
533
+ start = position;
534
+ held = 0;
535
+ }
536
+ held += bytes;
537
+ }
538
+ slices.push({
539
+ ...page,
540
+ firstPosition: start,
541
+ lastPosition: Number.MAX_SAFE_INTEGER,
542
+ bytes: held,
543
+ });
544
+ return slices;
545
+ };
546
+ return split("");
547
+ }
548
+ /**
549
+ * One key range. A bucket whose complex rows fit the memory budget commits in
550
+ * one transaction. The single-upsert keys merge in one batch from the stage
551
+ * table; the others (see `complexKeys`) apply as the segments they came from,
552
+ * in position order, restricted to these keys. A bucket whose complex rows do
553
+ * not fit commits the single-upsert keys first, then the complex rows a page
554
+ * at a time (`complexPages`), then the clean-up: the rows are held in memory
555
+ * for a page, not for the bucket.
556
+ */
557
+ async function applyBucket(deps, connectionId, tag, bucket, edges) {
558
+ const table = stageTable(tag, bucket);
559
+ const pages = await complexPages(deps, table, deps.blobs.governor.limitBytes);
560
+ const simpleOp = deps.newOp();
561
+ const simple = [
562
+ ...(edges.first
563
+ ? [
564
+ // In the commit of the first rows the load writes, or before it: the
565
+ // position those rows lie within. A load that is one commit has no
566
+ // rows to fence.
567
+ ...(edges.last && pages.length <= 1
568
+ ? []
569
+ : [writeKeyedPending(connectionId, edges.first.target)]),
570
+ ...edges.first.primaryKeys.map((meta) => streamStateStatement(connectionId, meta)),
571
+ ]
572
+ : []),
573
+ { sql: `INSERT INTO temp.log_complex ${complexKeys(table)}`, params: [] },
574
+ {
575
+ sql: `INSERT INTO temp.incoming (op, stream, pk_hash, record_key, stamp_o, stamp_r, body, body_sha256, first_o, stamp_n)
576
+ SELECT ?, stream, pk_hash, record_key, stamp_o, stamp_r, body, body_sha256, first_o, stamp_n
577
+ FROM ${table} s
578
+ WHERE s.kind = 'u' AND NOT EXISTS (
579
+ SELECT 1 FROM temp.log_complex c WHERE c.stream = s.stream AND c.pk_hash = s.pk_hash)`,
580
+ params: [simpleOp],
581
+ },
582
+ ...mergeStaged(connectionId, simpleOp),
583
+ { sql: "DELETE FROM temp.log_complex", params: [] },
584
+ ];
585
+ const closing = [{ sql: `DROP TABLE ${table}`, params: [] }];
586
+ if (edges.last) {
587
+ for (const head of edges.last.heads)
588
+ closing.push(...streamHeadStatements(connectionId, [head.meta], head, head.identity));
589
+ closing.push(writeLogState(connectionId, edges.last.state), clearKeyedPending(connectionId));
590
+ }
591
+ // The complex rows of a page, as the batches that apply them: one per
592
+ // position, in position order (the rows came out in the order they were staged).
593
+ const batchesOf = async (page) => {
594
+ const rows = await deps.db.query(`SELECT ${STAGE_COLUMNS} FROM ${table}
595
+ WHERE ${PAGE_FILTER} AND (stream, pk_hash) IN (${complexKeys(table)}) ORDER BY rowid`, pageParams(page));
596
+ const byPosition = new Map();
597
+ for (const row of rows) {
598
+ const operations = byPosition.get(row.position);
599
+ if (operations)
600
+ operations.push(operationOf(row));
601
+ else
602
+ byPosition.set(row.position, [operationOf(row)]);
603
+ }
604
+ return [...byPosition.values()].map((operations) => {
605
+ const op = deps.newOp();
606
+ return {
607
+ op,
608
+ statements: operationStatements(connectionId, op, operations),
609
+ };
610
+ });
611
+ };
612
+ // The rows of a page and the statements made from them: twice its bytes.
613
+ const hold = (page) => holdMemory(deps.blobs, 2 * page.bytes, 0);
614
+ if (pages.length <= 1) {
615
+ const release = pages[0] ? await hold(pages[0]) : undefined;
616
+ try {
617
+ await commitStaged(deps, [
618
+ { op: simpleOp, statements: simple },
619
+ ...(pages[0] ? await batchesOf(pages[0]) : []),
620
+ { op: deps.newOp(), statements: closing },
621
+ ]);
622
+ }
623
+ finally {
624
+ release?.();
625
+ }
626
+ return;
627
+ }
628
+ await commitStaged(deps, [{ op: simpleOp, statements: simple }]);
629
+ for (const page of pages) {
630
+ const release = await hold(page);
631
+ try {
632
+ await commitStaged(deps, await batchesOf(page));
633
+ }
634
+ finally {
635
+ release();
636
+ }
637
+ }
638
+ await commitStaged(deps, [{ op: deps.newOp(), statements: closing }]);
639
+ }
640
+ //# sourceMappingURL=log-keyed.js.map