@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,827 @@
1
+ import { loadBootstrap, discardBootstrap, FalseRemovalFact, } from "./log-bootstrap.js";
2
+ // The reader of the stream-sync log (stream-sync/src/log.ts).
3
+ //
4
+ // One registry read says the log's position. A device at position n fetches
5
+ // the newest segment (the head: it lists the older ones) and then only the
6
+ // segments after n, and applies them in position order, one batch each. A
7
+ // segment's operations are order- and duplicate-insensitive: an upsert merges
8
+ // by greatest observation stamp, and every delete and omission leaves a
9
+ // tombstone `(stream, pk_hash, stamp, rank)` that an upsert below it cannot
10
+ // pass (see `OMISSION_RANK`: an observation at an omission's cutoff passes, one
11
+ // at an explicit delete's stamp does not). So the order of delivery matters only for gap detection: position n+1
12
+ // is never applied before n, and a segment that cannot be fetched stops the
13
+ // pass there (the position stays; the next pass tries again).
14
+ //
15
+ // A device that is behind the log's `base` installs the snapshot the head
16
+ // names, then applies the tail. A registry that is BEHIND this device (a
17
+ // rollback or restore) whose row is one this device applied lost only rows:
18
+ // this device commits the segments it applied above it again, in order
19
+ // (`log-recommit.ts`). A registry that names another segment at a position
20
+ // this device applied is not a continuation: the rows, tombstones and
21
+ // checkpoints this device holds came from segments the log no longer has.
22
+ // This device queues what only those segments held as changes of its own and
23
+ // reads the registry's log from the last position both agree on
24
+ // (`log-rebase.ts`).
25
+ import { classifyStreamRow, digestSegment, digestSnapshotPart, encodeSegment, encodeSnapshotPart, logScope, planOpsSince, segmentBlobName, segmentRemoves, snapshotPartBlobName, verifySegment, verifySnapshotPart, } from "@opendatalabs/personal-server-ts-stream-sync";
26
+ import { keccakOf } from "../stream-sync/crypto-port.js";
27
+ import { resolveBodies } from "./log-bodies.js";
28
+ import { rebaseOnLog } from "./log-rebase.js";
29
+ import { seedFromRecords } from "./log-seed.js";
30
+ import { announceApplied } from "./apply-progress.js";
31
+ import { cursorApplied } from "./cursor.js";
32
+ import { applyBatch, applyInGroups, stageBatch, streamHeadStatements, streamStateStatement, } from "./log-batch.js";
33
+ import { loadKeyed, keyedLoadBlocked, planKeyedLoad, rebaselineKeyedLoad, unfinishedKeyedLoad, } from "./log-keyed.js";
34
+ import { heldKeys, removalsOf } from "./log-progressive.js";
35
+ import { LogDivergedError, readKeyedPending, readLogState, writeLogState, } from "./log-state.js";
36
+ import { recommitApplied } from "./log-recommit.js";
37
+ import { UpdateRequiredError } from "./update-required.js";
38
+ import { failedRowStatement, failureCode, hideStoredRows, partialRowStatement, } from "./partial-load.js";
39
+ export { recordKeyOfKey } from "./log-batch.js";
40
+ export { LogDivergedError, readLogState, writeLogState, } from "./log-state.js";
41
+ /**
42
+ * Apply one segment's operations to local state, in one batch (origin
43
+ * `remote`). Safe to repeat and to run in any order against other segments:
44
+ * see the file comment. With `state`, the log position is written in the same
45
+ * batch, so a position never runs ahead of the rows it stands for.
46
+ */
47
+ export async function applySegmentOperations(deps, connectionId, segment, state) {
48
+ const { dataHash, blobName } = await digestSegment(keccakOf(deps.streamCrypto), encodeSegment(segment));
49
+ await applyBatch(deps, connectionId, segment, { dataHash, blobName }, state);
50
+ }
51
+ /**
52
+ * Apply one snapshot part: its entries are upserts and deletes, applied as the
53
+ * operations of a segment are (in any order, any number of times).
54
+ */
55
+ export async function applySnapshotPart(deps, connectionId, part, state) {
56
+ const bytes = encodeSnapshotPart(part);
57
+ const { dataHash, blobName } = await digestSnapshotPart(keccakOf(deps.streamCrypto), bytes);
58
+ await applyBatch(deps, connectionId, {
59
+ generation: part.generation,
60
+ observedAt: 0,
61
+ streams: part.streams,
62
+ operations: part.entries,
63
+ }, { dataHash, blobName }, state);
64
+ }
65
+ /**
66
+ * Bring this device to the log's position. One registry read (or the one the
67
+ * caller holds), one GET for the newest segment, one GET for each older segment
68
+ * this device lacks.
69
+ */
70
+ export async function applyLog(deps, connectionId, context, rebased = false) {
71
+ const scope = logScope(context.connector, context.ns);
72
+ const local = await readLogState(deps, connectionId);
73
+ // A log that does not continue this device's history: put back what only
74
+ // that history held, then read the log from where both agree. Once per
75
+ // pass: a log that diverges again under the second read is refused.
76
+ const rebase = async (registry, why) => {
77
+ if (rebased)
78
+ throw new LogDivergedError(why);
79
+ await rebaseOnLog(deps, connectionId, context, local, registry);
80
+ return applyLog(deps, connectionId, context, true);
81
+ };
82
+ // A listed row is a hint taken before this apply. One behind this device can
83
+ // be a listing taken before this device's own later commit, so it is read
84
+ // again before it is believed.
85
+ const listed = context.read;
86
+ const read = listed === undefined || (listed.found && listed.version < local.position)
87
+ ? await deps.registry.read(scope)
88
+ : listed;
89
+ const classification = classifyStreamRow(read, context.hashes);
90
+ const [bootstrap] = await deps.db.query("SELECT generation,base FROM bootstrap_load WHERE connection_id=?", [connectionId]);
91
+ if (bootstrap &&
92
+ (classification !== "present" ||
93
+ bootstrap.generation !== context.generation ||
94
+ deps.bootstrapFirstLoad === false ||
95
+ deps.progressiveFirstLoad !== true))
96
+ await discardBootstrap(deps, connectionId);
97
+ if (!read.found || classification === "absent")
98
+ return { applied: 0 };
99
+ // Rows an unfinished key-ordered load left (see `log-keyed.ts`) lie beyond
100
+ // this device's position, and only a key-ordered load that covers them may
101
+ // move it. So while the marker stands, no branch below may write a cursor:
102
+ // not the lifetime branches, which write `log_state` without applying
103
+ // anything, and not a device that somehow holds both a cursor and the marker.
104
+ // A log that cannot finish that load (`keyedLoadBlocked`) ends it instead:
105
+ // the marker and its rows go, and the first load starts again from the log.
106
+ let pending = await readKeyedPending(deps, connectionId);
107
+ if (pending !== null && local.position !== 0)
108
+ throw unfinishedKeyedLoad(pending, "this device holds a cursor above 0");
109
+ if (classification === "tombstoned") {
110
+ if (pending !== null)
111
+ throw unfinishedKeyedLoad(pending, "the log is of an ended lifetime");
112
+ // The log of an ended lifetime. A new one begins after its version.
113
+ if (read.version > local.position)
114
+ await deps.db.batch([
115
+ writeLogState(connectionId, {
116
+ position: read.version,
117
+ base: read.version,
118
+ refs: [],
119
+ snapshot: null,
120
+ }),
121
+ ]);
122
+ return { applied: 0 };
123
+ }
124
+ // A registry behind this device is a rollback or a restore. The segments
125
+ // above its position are still in storage, and this device applied them: it
126
+ // commits them again, in order (`recommitApplied`), so the log is the one
127
+ // this device's rows are the fold of. A registry row this device did not
128
+ // apply is another history, which this device rebases onto.
129
+ if (local.position > read.version) {
130
+ try {
131
+ await recommitApplied(deps, connectionId, context, local, read);
132
+ return { applied: 0 };
133
+ }
134
+ catch (error) {
135
+ if (!(error instanceof LogDivergedError))
136
+ throw error;
137
+ const named = await fetchSegment(deps, scope, context, read.dataHash, read.version);
138
+ return rebase([
139
+ ...named.segment.refs,
140
+ {
141
+ position: read.version,
142
+ dataHash: read.dataHash.toLowerCase(),
143
+ bytes: named.bytes,
144
+ },
145
+ ], error.message);
146
+ }
147
+ }
148
+ const lastRef = local.refs.at(-1);
149
+ if (read.version === local.position &&
150
+ lastRef?.dataHash.toLowerCase() === read.dataHash.toLowerCase())
151
+ return { applied: 0 };
152
+ const newest = await fetchSegment(deps, scope, context, read.dataHash, read.version);
153
+ const head = newest.segment;
154
+ if (head.generation < context.generation) {
155
+ if (pending !== null)
156
+ throw unfinishedKeyedLoad(pending, "the log is of an earlier lifetime");
157
+ // A log of an earlier lifetime holds none of this one.
158
+ await deps.db.batch([
159
+ writeLogState(connectionId, {
160
+ position: read.version,
161
+ base: read.version,
162
+ refs: [],
163
+ snapshot: null,
164
+ }),
165
+ ]);
166
+ return { applied: 0 };
167
+ }
168
+ if (head.generation > context.generation)
169
+ return { applied: 0 };
170
+ // This device's first install of the connection's log. What it holds from
171
+ // before goes into the log with its next publish (`log-seed.ts`). An
172
+ // unfinished key-ordered load already passed here at its start.
173
+ if (local.position === 0 && pending === null)
174
+ await seedFromRecords(deps, connectionId);
175
+ const headRef = {
176
+ position: head.position,
177
+ dataHash: read.dataHash.toLowerCase(),
178
+ bytes: newest.bytes,
179
+ removes: segmentRemoves(head.operations),
180
+ };
181
+ const allRefs = [...head.refs, headRef];
182
+ // The segment this device applied last must be the one the log names at that
183
+ // position. Another history that reuses the position (a rolled-back log that
184
+ // grew again) is not a tail to apply on top of what this device holds.
185
+ if (lastRef && lastRef.position === local.position) {
186
+ const named = allRefs.find((ref) => ref.position === lastRef.position);
187
+ if (named &&
188
+ named.dataHash.toLowerCase() !== lastRef.dataHash.toLowerCase())
189
+ return rebase(allRefs, `apply: the log names a different segment at position ${lastRef.position} than this device applied`);
190
+ }
191
+ let since = local.position;
192
+ let plan = planOpsSince(head, headRef, since);
193
+ let snapshot = null;
194
+ let gap = false;
195
+ if (plan.kind === "gap") {
196
+ if (plan.reason === "ahead_of_head")
197
+ return rebase(allRefs, `apply: the log's newest position ${head.position} is behind this device at ${since}`);
198
+ // A full check. Behind `base` the log no longer holds the prefix: a
199
+ // snapshot does, and it is installed first. Without one the log holds
200
+ // nothing below `base`, and the pass applies the tail alone.
201
+ gap = true;
202
+ since = head.base;
203
+ plan = planOpsSince(head, headRef, since);
204
+ // Behind `base` the snapshot is installed first, then the tail: one pass.
205
+ snapshot = head.snapshot ?? null;
206
+ }
207
+ const tail = plan.kind === "segments" ? plan.refs : [];
208
+ if (pending !== null) {
209
+ const last = tail.at(-1);
210
+ const blocked = keyedLoadBlocked(deps, pending, {
211
+ snapshotPresent: snapshot !== null,
212
+ target: last
213
+ ? {
214
+ position: last.position,
215
+ base: head.base,
216
+ refs: allRefs.filter((ref) => ref.position <= last.position),
217
+ snapshot: head.snapshot,
218
+ }
219
+ : null,
220
+ });
221
+ if (blocked !== null) {
222
+ await rebaselineKeyedLoad(deps, connectionId, blocked);
223
+ pending = null;
224
+ }
225
+ }
226
+ // A first load of a log too big for one commit loads key by key (see
227
+ // `log-keyed.ts`), whether or not the host shows streams while they load. On a
228
+ // log whose keys arrive in no key order, a segment-by-segment load rewrites a
229
+ // table's random-hash indexes in every commit: on a 198k-row source it writes
230
+ // 1.6x the pages the key ranges do and keeps the Web worker busy about twice
231
+ // as long. The segment-by-segment load takes the logs that fit one commit's budget, and
232
+ // what a key-ordered load cannot take (a snapshot, a device that holds
233
+ // streams). The key-ordered load lists the source at the head all the same.
234
+ if (bootstrap) {
235
+ const staged = await deps.db.query("SELECT position,data_hash FROM bootstrap_segments");
236
+ if (snapshot !== null ||
237
+ bootstrap.base !== head.base ||
238
+ staged.some((row) => !allRefs.some((ref) => ref.position === row.position &&
239
+ ref.dataHash.toLowerCase() === row.data_hash)))
240
+ await discardBootstrap(deps, connectionId);
241
+ }
242
+ if (deps.bootstrapFirstLoad !== false &&
243
+ deps.progressiveFirstLoad === true &&
244
+ local.position === 0 &&
245
+ snapshot === null &&
246
+ pending === null &&
247
+ tail.length) {
248
+ const applied = await loadBootstrap({
249
+ deps,
250
+ connectionId,
251
+ generation: context.generation,
252
+ base: head.base,
253
+ head,
254
+ refs: tail,
255
+ fetch: async (ref) => (await fetchSegment(deps, scope, context, ref.dataHash, ref.position))
256
+ .segment,
257
+ state: {
258
+ position: head.position,
259
+ base: head.base,
260
+ refs: allRefs,
261
+ snapshot: head.snapshot,
262
+ },
263
+ });
264
+ if (applied !== null)
265
+ return { applied };
266
+ }
267
+ const buckets = await planKeyedLoad(deps, connectionId, local, snapshot !== null, tail, pending);
268
+ const progressive = deps.progressiveFirstLoad === true && pending === null && buckets === null;
269
+ if (gap && progressive) {
270
+ const after = planOpsSince(head, headRef, head.base);
271
+ return {
272
+ applied: await loadProgressively(deps, connectionId, scope, context, head, allRefs, head.snapshot ?? null, after.kind === "segments" ? after.refs : []),
273
+ };
274
+ }
275
+ if (tail.length === 0 && snapshot === null && pending === null)
276
+ return { applied: 0 };
277
+ if (progressive)
278
+ return {
279
+ applied: await loadProgressively(deps, connectionId, scope, context, head, allRefs, snapshot, tail),
280
+ };
281
+ if (buckets !== null) {
282
+ const listing = deps.progressiveFirstLoad === true
283
+ ? await listKeyedLoad(deps, connectionId, context, head, tail)
284
+ : null;
285
+ try {
286
+ await loadKeyed(deps, connectionId, tail.map((ref) => segmentSource(deps, scope, context, head, allRefs, ref)), buckets);
287
+ }
288
+ catch (error) {
289
+ await listing?.failed(error);
290
+ throw error;
291
+ }
292
+ return { applied: tail.length };
293
+ }
294
+ const items = [
295
+ ...snapshotItems(deps, connectionId, scope, context, head, allRefs, snapshot),
296
+ ...tail.map((ref) => segmentItem(deps, connectionId, scope, context, head, allRefs, ref)),
297
+ ];
298
+ await applyInGroups(deps, items, { firstAlone: false });
299
+ return { applied: items.length };
300
+ }
301
+ /**
302
+ * One segment of the tail as a batch of the pass: fetched (the newest is
303
+ * already in hand), verified, staged, with the position it carries.
304
+ */
305
+ function segmentItem(deps, connectionId, scope, context, head, allRefs, ref) {
306
+ return {
307
+ bytes: ref.bytes,
308
+ stage: async () => {
309
+ const segment = ref.position === head.position
310
+ ? head
311
+ : (await fetchSegment(deps, scope, context, ref.dataHash, ref.position)).segment;
312
+ return stageBatch(deps, connectionId, segment, {
313
+ dataHash: ref.dataHash.toLowerCase(),
314
+ blobName: segmentBlobName(ref.dataHash),
315
+ }, {
316
+ position: ref.position,
317
+ base: head.base,
318
+ refs: allRefs.filter((r) => r.position <= ref.position),
319
+ snapshot: head.snapshot,
320
+ });
321
+ },
322
+ };
323
+ }
324
+ /** One segment of the tail as a source of the keyed load. */
325
+ function segmentSource(deps, scope, context, head, allRefs, ref) {
326
+ return {
327
+ bytes: ref.bytes,
328
+ load: async () => ({
329
+ batch: ref.position === head.position
330
+ ? head
331
+ : (await fetchSegment(deps, scope, context, ref.dataHash, ref.position)).segment,
332
+ identity: {
333
+ dataHash: ref.dataHash.toLowerCase(),
334
+ blobName: segmentBlobName(ref.dataHash),
335
+ },
336
+ }),
337
+ state: {
338
+ position: ref.position,
339
+ base: head.base,
340
+ refs: allRefs.filter((r) => r.position <= ref.position),
341
+ snapshot: head.snapshot,
342
+ },
343
+ };
344
+ }
345
+ /**
346
+ * The parts of the snapshot a reader behind `head.base` installs, as batches
347
+ * of the pass. The position moves to the snapshot's only with the last part,
348
+ * in the same batch, so an interrupted install is repeated, never half
349
+ * believed. Idempotent.
350
+ */
351
+ function snapshotItems(deps, connectionId, scope, context, head, allRefs, snapshot) {
352
+ if (snapshot === null)
353
+ return [];
354
+ return snapshot.parts.map((ref, index) => ({
355
+ bytes: ref.bytes,
356
+ stage: async () => {
357
+ const part = await fetchSnapshotPart(deps, scope, context, ref.dataHash, snapshot.position);
358
+ if (part.index !== index)
359
+ throw new Error("apply: invalid log snapshot part (inconsistent)");
360
+ return stageBatch(deps, connectionId, {
361
+ generation: part.generation,
362
+ observedAt: 0,
363
+ streams: part.streams,
364
+ operations: part.entries,
365
+ }, {
366
+ dataHash: ref.dataHash.toLowerCase(),
367
+ blobName: snapshotPartBlobName(ref.dataHash),
368
+ }, index === snapshot.parts.length - 1
369
+ ? {
370
+ position: snapshot.position,
371
+ base: head.base,
372
+ refs: allRefs.filter((r) => r.position <= snapshot.position),
373
+ snapshot,
374
+ }
375
+ : undefined);
376
+ },
377
+ }));
378
+ }
379
+ /** One segment, fetched, decrypted and verified against the hash and position. */
380
+ export async function fetchSegment(deps, scope, context, dataHash, position) {
381
+ const cipher = await deps.blobs.get(`${scope}/${segmentBlobName(dataHash)}`);
382
+ if (cipher === null)
383
+ throw new Error(`apply: missing log segment ${position}`);
384
+ const verified = await verifySegment(keccakOf(deps.streamCrypto), await deps.keys.decrypt(scope, cipher), {
385
+ dataHash,
386
+ connector: context.connector,
387
+ ns: context.ns,
388
+ keyCheck: context.keyCheck,
389
+ position,
390
+ });
391
+ if (verified.kind === "unsupported_format")
392
+ throw new UpdateRequiredError(`apply: invalid log segment ${position} (unsupported_format)`, verified.format);
393
+ if (verified.kind !== "ok")
394
+ throw new Error(`apply: invalid log segment ${position} (${verified.kind})`);
395
+ const segment = {
396
+ ...verified.segment,
397
+ operations: await resolveBodies(deps, scope, verified.segment.operations),
398
+ };
399
+ return { segment, bytes: verified.bytes, cipherBytes: cipher.length };
400
+ }
401
+ /** One snapshot part, fetched, decrypted and verified. */
402
+ export async function fetchSnapshotPart(deps, scope, context, dataHash, position) {
403
+ const cipher = await deps.blobs.get(`${scope}/${snapshotPartBlobName(dataHash)}`);
404
+ if (cipher === null)
405
+ throw new Error("apply: missing log snapshot part");
406
+ const verified = await verifySnapshotPart(keccakOf(deps.streamCrypto), await deps.keys.decrypt(scope, cipher), {
407
+ dataHash,
408
+ connector: context.connector,
409
+ ns: context.ns,
410
+ keyCheck: context.keyCheck,
411
+ position,
412
+ });
413
+ if (verified.kind === "unsupported_format")
414
+ throw new UpdateRequiredError("apply: invalid log snapshot part (unsupported_format)", verified.format);
415
+ if (verified.kind !== "ok")
416
+ throw new Error(`apply: invalid log snapshot part (${verified.kind})`);
417
+ return {
418
+ ...verified.part,
419
+ entries: await resolveBodies(deps, scope, verified.part.entries),
420
+ };
421
+ }
422
+ /**
423
+ * List the streams a key-ordered first load will publish, before it fetches a
424
+ * segment: each is a stream state with a partial row at 0 of the segments, so a
425
+ * host that lists loading sources shows the source from the head on. The rows
426
+ * the key ranges merge are final rows (a range merges every segment's
427
+ * operations on its keys), so a reader that shows partial rows shows only keys
428
+ * the finished log keeps. The last range's commit writes the heads, which ends
429
+ * these rows (`partial_complete_au`). A load that stops marks them failed.
430
+ */
431
+ async function listKeyedLoad(deps, connectionId, context, head, tail) {
432
+ const last = tail.at(-1);
433
+ if (!last)
434
+ return { failed: async () => undefined };
435
+ const stored = await deps.db.query("SELECT stream, head_version, last_delete_version FROM stream_state WHERE connection_id = ?", [connectionId]);
436
+ const versions = new Map(stored.map((row) => [
437
+ row.stream,
438
+ Math.max(row.head_version, row.last_delete_version) + 1,
439
+ ]));
440
+ const identities = head.streams.map((meta) => ({
441
+ connectionId,
442
+ stream: meta.stream,
443
+ version: versions.get(meta.stream) ?? 1,
444
+ generation: context.generation,
445
+ dataHash: last.dataHash.toLowerCase(),
446
+ headBlob: segmentBlobName(last.dataHash),
447
+ observedAt: head.observedAt,
448
+ }));
449
+ await deps.db.batch(head.streams.flatMap((meta, index) => [
450
+ streamStateStatement(connectionId, meta),
451
+ partialRowStatement(identities[index], 0, tail.length, 0),
452
+ ]));
453
+ announceApplied(deps, connectionId);
454
+ return {
455
+ failed: async (error) => {
456
+ const code = failureCode(error);
457
+ await deps.db
458
+ .batch(identities.map((identity) => failedRowStatement(identity, code)))
459
+ .then(() => announceApplied(deps, connectionId), () => undefined);
460
+ },
461
+ };
462
+ }
463
+ /**
464
+ * The pass of `applyLog` for a device that serves a first load while it
465
+ * applies (`progressiveFirstLoad`): the same batches in the same order, with
466
+ * `stream_partial` rows between them. See `log-progressive.ts` for why a row
467
+ * of a key a later batch removes stays hidden.
468
+ *
469
+ * The pass lists the streams the head names, with no rows, as soon as it has
470
+ * read the head; reads the segments that remove a key (the head's refs say
471
+ * which) and the first snapshot part; and then applies every batch as the
472
+ * read-ahead delivers it, the first alone. A segment that removes nothing is
473
+ * fetched when its batch is next, not before: the first rows show after the
474
+ * first segment, and the download and the apply overlap.
475
+ *
476
+ * Every stream finishes with the last batch: that commit writes the heads of
477
+ * all the streams the pass named, whichever batch named them last.
478
+ */
479
+ async function loadProgressively(deps, connectionId, scope, context, head, allRefs, snapshot, tail) {
480
+ const partRefs = snapshot?.parts ?? [];
481
+ // A part is fetched once, whoever asks first: the plan asks for the first,
482
+ // the pass for the others as read-ahead reaches them.
483
+ const parts = [];
484
+ const partAt = (index) => {
485
+ if (!parts[index]) {
486
+ const fetching = fetchSnapshotPart(deps, scope, context, partRefs[index].dataHash, snapshot.position);
487
+ fetching.catch(() => undefined);
488
+ parts[index] = fetching;
489
+ }
490
+ return parts[index];
491
+ };
492
+ if (partRefs.length > 0)
493
+ void partAt(0);
494
+ // A segment is fetched once, whoever asks first. The head is in hand.
495
+ const segments = new Map([
496
+ [head.position, Promise.resolve(head)],
497
+ ]);
498
+ const segmentAt = (ref) => {
499
+ let fetching = segments.get(ref.position);
500
+ if (!fetching) {
501
+ fetching = fetchSegment(deps, scope, context, ref.dataHash, ref.position).then((fetched) => fetched.segment);
502
+ fetching.catch(() => undefined);
503
+ segments.set(ref.position, fetching);
504
+ }
505
+ return fetching;
506
+ };
507
+ // The segments the head does not say remove nothing: those are read first.
508
+ const removing = tail.filter((ref) => ref.position !== head.position && ref.removes !== false);
509
+ for (const ref of removing)
510
+ void segmentAt(ref);
511
+ // Every batch's identity: the hash and blob its stream head will name.
512
+ const identities = [
513
+ ...partRefs.map((ref) => ({
514
+ dataHash: ref.dataHash.toLowerCase(),
515
+ blobName: snapshotPartBlobName(ref.dataHash),
516
+ })),
517
+ ...tail.map((ref) => ({
518
+ dataHash: ref.dataHash.toLowerCase(),
519
+ blobName: segmentBlobName(ref.dataHash),
520
+ })),
521
+ ];
522
+ const total = identities.length;
523
+ const lastIndex = total - 1;
524
+ const stored = await deps.db.query(`SELECT stream, complete, head_generation, head_version, last_delete_version
525
+ FROM stream_state WHERE connection_id = ?`, [connectionId]);
526
+ const skip = new Set(stored
527
+ .filter((row) => row.complete === 1 &&
528
+ row.head_generation === context.generation &&
529
+ row.head_version > row.last_delete_version)
530
+ .map((row) => row.stream));
531
+ const versionOf = new Map(stored.map((row) => [
532
+ row.stream,
533
+ Math.max(row.head_version, row.last_delete_version) + 1,
534
+ ]));
535
+ // The row a stream's load shows is the head the pass ends as: the version
536
+ // its last batch writes, and the hash and blob of the pass's last batch.
537
+ const identityOf = new Map();
538
+ const headOf = (stream) => {
539
+ let identity = identityOf.get(stream);
540
+ if (!identity) {
541
+ identity = {
542
+ connectionId,
543
+ stream,
544
+ version: versionOf.get(stream) ?? 1,
545
+ generation: context.generation,
546
+ dataHash: identities[lastIndex].dataHash,
547
+ headBlob: identities[lastIndex].blobName,
548
+ observedAt: head.observedAt,
549
+ };
550
+ identityOf.set(stream, identity);
551
+ }
552
+ return identity;
553
+ };
554
+ // A load of the same head that stopped continues: its rows keep showing.
555
+ const markers = await deps.db.query(`SELECT stream, version, generation, data_hash
556
+ FROM stream_partial WHERE connection_id = ?`, [connectionId]);
557
+ const resumed = new Set();
558
+ const stale = [];
559
+ for (const marker of markers) {
560
+ const mine = headOf(marker.stream);
561
+ if (marker.version === mine.version &&
562
+ marker.generation === mine.generation) {
563
+ resumed.add(marker.stream);
564
+ if (marker.data_hash !== mine.dataHash)
565
+ stale.push({
566
+ sql: "UPDATE stream_partial SET data_hash=?,head_blob=?,observed_at=?,failed=0,last_error=NULL WHERE connection_id=? AND stream=? AND version=? AND generation=? AND data_hash=?",
567
+ params: [
568
+ mine.dataHash,
569
+ mine.headBlob,
570
+ mine.observedAt,
571
+ connectionId,
572
+ marker.stream,
573
+ marker.version,
574
+ marker.generation,
575
+ marker.data_hash,
576
+ ],
577
+ });
578
+ }
579
+ else if (skip.has(marker.stream))
580
+ // A load this pass does not continue, of a stream that reads complete.
581
+ stale.push({
582
+ sql: "DELETE FROM stream_partial WHERE connection_id = ? AND stream = ?",
583
+ params: [connectionId, marker.stream],
584
+ });
585
+ }
586
+ // The streams the head names are listed now, with no rows: the stream's
587
+ // row, its rows hidden, and a partial row at 0 of `total` batches. A reader
588
+ // that lists with progressive on sees the source here, with the others
589
+ // loading. Streams a segment names that the head does not are listed with
590
+ // the first batch that names them.
591
+ const begun = new Set();
592
+ const listed = [...stale];
593
+ for (const meta of head.streams) {
594
+ if (skip.has(meta.stream) || resumed.has(meta.stream))
595
+ continue;
596
+ begun.add(meta.stream);
597
+ listed.push(streamStateStatement(connectionId, meta), ...hideStoredRows(connectionId, meta.stream), partialRowStatement(headOf(meta.stream), 0, total, 0));
598
+ }
599
+ if (listed.length > 0) {
600
+ await deps.db.batch(listed);
601
+ if (begun.size > 0 || stale.length > 0)
602
+ announceApplied(deps, connectionId);
603
+ }
604
+ // What a later batch removes: read from the segments that say they remove,
605
+ // which are in hand (or on their way) before the first batch applies.
606
+ const [firstPart] = await Promise.all([
607
+ partRefs.length > 0 ? partAt(0) : Promise.resolve(undefined),
608
+ ...removing.map(segmentAt),
609
+ ]).catch(async (error) => {
610
+ const stopped = [...new Set([...begun, ...resumed])].map(headOf);
611
+ if (stopped.length)
612
+ await deps.db
613
+ .batch(stopped.map((identity) => failedRowStatement(identity, failureCode(error))))
614
+ .then(() => announceApplied(deps, connectionId), () => undefined);
615
+ throw error;
616
+ });
617
+ const removed = removalsOf(await Promise.all(tail
618
+ .filter((ref) => ref.position === head.position || ref.removes !== false)
619
+ .map(async (ref) => ({
620
+ index: partRefs.length + tail.indexOf(ref),
621
+ operations: (await segmentAt(ref)).operations,
622
+ }))));
623
+ // What each batch does for the streams that load progressively: a function
624
+ // of its place in the pass and its own operations, so the batches can be
625
+ // staged in any order and are committed in this one.
626
+ const stepsOf = [];
627
+ const lastNaming = new Map();
628
+ // The newest cursor each stream's batches carry: a later batch that names
629
+ // the stream without one leaves it (`followMeta`).
630
+ const lastCursor = new Map();
631
+ const stepsFor = (index, batch) => {
632
+ const steps = new Map();
633
+ const final = index === lastIndex;
634
+ for (const meta of batch.streams) {
635
+ if (skip.has(meta.stream))
636
+ continue;
637
+ const seen = lastNaming.get(meta.stream);
638
+ if (!seen || seen.index < index)
639
+ lastNaming.set(meta.stream, { index, meta, batch });
640
+ const carried = lastCursor.get(meta.stream);
641
+ if (meta.cursor && (!carried || carried.index < index))
642
+ lastCursor.set(meta.stream, { index, cursor: meta.cursor });
643
+ steps.set(meta.stream, {
644
+ begin: !resumed.has(meta.stream),
645
+ final,
646
+ held: final
647
+ ? []
648
+ : heldKeys(removed, meta.stream, index, batch.operations),
649
+ row: final
650
+ ? undefined
651
+ : {
652
+ head: headOf(meta.stream),
653
+ applied: Math.min(index + 1, total - 1),
654
+ total,
655
+ },
656
+ });
657
+ }
658
+ stepsOf[index] = steps;
659
+ return steps;
660
+ };
661
+ const stateOf = (index) => {
662
+ const lastPart = index === partRefs.length - 1;
663
+ const position = index - partRefs.length;
664
+ return index < partRefs.length
665
+ ? lastPart
666
+ ? {
667
+ position: snapshot.position,
668
+ base: head.base,
669
+ refs: allRefs.filter((r) => r.position <= snapshot.position),
670
+ snapshot,
671
+ }
672
+ : undefined
673
+ : {
674
+ position: tail[position].position,
675
+ base: head.base,
676
+ refs: allRefs.filter((r) => r.position <= tail[position].position),
677
+ snapshot: head.snapshot,
678
+ };
679
+ };
680
+ const earlierNaming = async (streams) => {
681
+ const found = new Map();
682
+ const inTail = new Set(tail.map((ref) => ref.position));
683
+ const earlier = allRefs
684
+ .filter((ref) => !inTail.has(ref.position))
685
+ .sort((a, b) => b.position - a.position);
686
+ for (const ref of earlier) {
687
+ if (found.size === streams.length)
688
+ break;
689
+ const segment = await segmentAt(ref);
690
+ for (const meta of segment.streams)
691
+ if (streams.includes(meta.stream) && !found.has(meta.stream))
692
+ found.set(meta.stream, {
693
+ meta,
694
+ batch: segment,
695
+ identity: {
696
+ dataHash: ref.dataHash.toLowerCase(),
697
+ blobName: segmentBlobName(ref.dataHash),
698
+ },
699
+ });
700
+ }
701
+ const pointer = snapshot ?? head.snapshot ?? null;
702
+ if (found.size < streams.length && pointer && pointer.parts.length > 0) {
703
+ const part = await fetchSnapshotPart(deps, scope, context, pointer.parts[0].dataHash, pointer.position);
704
+ for (const meta of part.streams)
705
+ if (streams.includes(meta.stream) && !found.has(meta.stream))
706
+ found.set(meta.stream, {
707
+ meta,
708
+ batch: { generation: part.generation, observedAt: 0 },
709
+ identity: {
710
+ dataHash: pointer.parts[0].dataHash.toLowerCase(),
711
+ blobName: snapshotPartBlobName(pointer.parts[0].dataHash),
712
+ },
713
+ });
714
+ }
715
+ return found;
716
+ };
717
+ const ending = async () => {
718
+ const out = [];
719
+ const named = new Map();
720
+ for (const [stream, { index, meta, batch }] of lastNaming)
721
+ named.set(stream, {
722
+ meta,
723
+ batch,
724
+ identity: identities[index],
725
+ final: index === lastIndex,
726
+ });
727
+ const orphans = [...resumed].filter((stream) => !lastNaming.has(stream) && !skip.has(stream));
728
+ if (orphans.length > 0) {
729
+ const found = await earlierNaming(orphans);
730
+ for (const stream of orphans) {
731
+ const hit = found.get(stream);
732
+ if (!hit)
733
+ throw new Error(`apply: no batch of the log names stream ${stream}, which an earlier load began`);
734
+ named.set(stream, { ...hit, final: false });
735
+ }
736
+ }
737
+ for (const [stream, { meta, batch, identity, final }] of named) {
738
+ if (!final)
739
+ out.push(...streamHeadStatements(connectionId, [meta], batch, identity));
740
+ if (!meta.complete)
741
+ out.push({
742
+ sql: "DELETE FROM stream_partial WHERE connection_id = ? AND stream = ?",
743
+ params: [connectionId, stream],
744
+ });
745
+ }
746
+ // Every row of the pass is in: each stream takes the newest cursor its
747
+ // batches carried, after any head above staged an older one.
748
+ for (const [stream, { cursor }] of lastCursor)
749
+ if (named.has(stream))
750
+ out.push(cursorApplied(connectionId, stream, cursor));
751
+ return out;
752
+ };
753
+ const items = identities.map((_, index) => ({
754
+ bytes: index < partRefs.length
755
+ ? partRefs[index].bytes
756
+ : tail[index - partRefs.length].bytes,
757
+ stage: async () => {
758
+ let batch;
759
+ if (index < partRefs.length) {
760
+ const part = await partAt(index);
761
+ if (part.index !== index ||
762
+ JSON.stringify(part.streams) !== JSON.stringify(firstPart.streams))
763
+ throw new Error("apply: invalid log snapshot part (inconsistent)");
764
+ batch = {
765
+ generation: part.generation,
766
+ observedAt: 0,
767
+ streams: part.streams,
768
+ operations: part.entries,
769
+ };
770
+ }
771
+ else {
772
+ const ref = tail[index - partRefs.length];
773
+ const segment = await segmentAt(ref);
774
+ // A segment the head says removes nothing was not read first. If it
775
+ // removes a key, rows of the keys it removes may be showing.
776
+ if (ref.removes === false && segmentRemoves(segment.operations))
777
+ throw new FalseRemovalFact();
778
+ batch = segment;
779
+ }
780
+ const staged = await stageBatch(deps, connectionId, batch, identities[index], stateOf(index), stepsFor(index, batch));
781
+ return index === lastIndex ? { ...staged, after: ending } : staged;
782
+ },
783
+ }));
784
+ const showing = new Map();
785
+ const finished = new Set();
786
+ try {
787
+ await applyInGroups(deps, items, {
788
+ // The first batch commits alone: it is the first screen.
789
+ firstAlone: true,
790
+ begun,
791
+ onCommit: (first, last) => {
792
+ let shown = false;
793
+ for (let index = first; index <= last; index++)
794
+ for (const [stream, step] of stepsOf[index]) {
795
+ shown = true;
796
+ if (step.final)
797
+ finished.add(stream);
798
+ else
799
+ showing.set(stream, headOf(stream));
800
+ }
801
+ if (shown)
802
+ announceApplied(deps, connectionId);
803
+ },
804
+ });
805
+ }
806
+ catch (error) {
807
+ // The load stopped short of its last batch: say so on its rows, for a
808
+ // reader to tell this from a load that is still going. The next batch
809
+ // clears it. A failure here must not hide the one being thrown.
810
+ const code = failureCode(error);
811
+ const stopped = [...new Set([...begun, ...showing.keys()])]
812
+ .filter((stream) => !finished.has(stream))
813
+ .map(headOf);
814
+ if (stopped.length > 0)
815
+ await deps.db
816
+ .batch(stopped.flatMap((identity) => [
817
+ ...(error instanceof FalseRemovalFact
818
+ ? hideStoredRows(connectionId, identity.stream)
819
+ : []),
820
+ failedRowStatement(identity, code),
821
+ ]))
822
+ .then(() => announceApplied(deps, connectionId), () => undefined);
823
+ throw error;
824
+ }
825
+ return total;
826
+ }
827
+ //# sourceMappingURL=log-apply.js.map