@opendatalabs/personal-server-ts-core 1.34.2 → 1.35.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 (414) hide show
  1. package/dist/additions/durable.d.ts +32 -2
  2. package/dist/additions/durable.d.ts.map +1 -1
  3. package/dist/additions/durable.js +237 -88
  4. package/dist/additions/durable.js.map +1 -1
  5. package/dist/additions/version-inventory.d.ts +4 -0
  6. package/dist/additions/version-inventory.d.ts.map +1 -1
  7. package/dist/additions/version-inventory.js +11 -1
  8. package/dist/additions/version-inventory.js.map +1 -1
  9. package/dist/api/index.d.ts +18 -1
  10. package/dist/api/index.d.ts.map +1 -1
  11. package/dist/api/index.js +172 -4
  12. package/dist/api/index.js.map +1 -1
  13. package/dist/api/oura-collection-requirements.d.ts +16 -0
  14. package/dist/api/oura-collection-requirements.d.ts.map +1 -0
  15. package/dist/api/oura-collection-requirements.js +70 -0
  16. package/dist/api/oura-collection-requirements.js.map +1 -0
  17. package/dist/api/scope-upload-batches.d.ts +18 -0
  18. package/dist/api/scope-upload-batches.d.ts.map +1 -0
  19. package/dist/api/scope-upload-batches.js +71 -0
  20. package/dist/api/scope-upload-batches.js.map +1 -0
  21. package/dist/api/scope-uploads.d.ts +112 -0
  22. package/dist/api/scope-uploads.d.ts.map +1 -0
  23. package/dist/api/scope-uploads.js +369 -0
  24. package/dist/api/scope-uploads.js.map +1 -0
  25. package/dist/client.d.ts +70 -0
  26. package/dist/client.d.ts.map +1 -1
  27. package/dist/client.js +1 -0
  28. package/dist/client.js.map +1 -1
  29. package/dist/contracts/data.d.ts +8 -0
  30. package/dist/contracts/data.d.ts.map +1 -1
  31. package/dist/contracts/data.js +31 -1
  32. package/dist/contracts/data.js.map +1 -1
  33. package/dist/contracts/grants.d.ts.map +1 -1
  34. package/dist/contracts/grants.js +3 -0
  35. package/dist/contracts/grants.js.map +1 -1
  36. package/dist/contracts/index.d.ts +3 -1
  37. package/dist/contracts/index.d.ts.map +1 -1
  38. package/dist/contracts/index.js +3 -1
  39. package/dist/contracts/index.js.map +1 -1
  40. package/dist/contracts/oura-collection-requirements.d.ts +17 -0
  41. package/dist/contracts/oura-collection-requirements.d.ts.map +1 -0
  42. package/dist/contracts/oura-collection-requirements.js +49 -0
  43. package/dist/contracts/oura-collection-requirements.js.map +1 -0
  44. package/dist/legacy-projection/bindings.d.ts +1 -7
  45. package/dist/legacy-projection/bindings.d.ts.map +1 -1
  46. package/dist/legacy-projection/bindings.js +162 -28
  47. package/dist/legacy-projection/bindings.js.map +1 -1
  48. package/dist/legacy-projection/index.d.ts +6 -5
  49. package/dist/legacy-projection/index.d.ts.map +1 -1
  50. package/dist/legacy-projection/index.js +9 -21
  51. package/dist/legacy-projection/index.js.map +1 -1
  52. package/dist/legacy-projection/oura-browser-bindings.d.ts +2 -0
  53. package/dist/legacy-projection/oura-browser-bindings.d.ts.map +1 -1
  54. package/dist/legacy-projection/oura-browser-bindings.js +2 -0
  55. package/dist/legacy-projection/oura-browser-bindings.js.map +1 -1
  56. package/dist/legacy-projection/strava-browser-bindings.d.ts +3 -0
  57. package/dist/legacy-projection/strava-browser-bindings.d.ts.map +1 -0
  58. package/dist/legacy-projection/strava-browser-bindings.js +32 -0
  59. package/dist/legacy-projection/strava-browser-bindings.js.map +1 -0
  60. package/dist/legacy-projection/types.d.ts +44 -12
  61. package/dist/legacy-projection/types.d.ts.map +1 -1
  62. package/dist/mcp/connection-api.d.ts +11 -1
  63. package/dist/mcp/connection-api.d.ts.map +1 -1
  64. package/dist/mcp/connection-api.js +94 -9
  65. package/dist/mcp/connection-api.js.map +1 -1
  66. package/dist/mcp/index.d.ts +1 -0
  67. package/dist/mcp/index.d.ts.map +1 -1
  68. package/dist/mcp/index.js +1 -0
  69. package/dist/mcp/index.js.map +1 -1
  70. package/dist/mcp/server.d.ts +9 -0
  71. package/dist/mcp/server.d.ts.map +1 -1
  72. package/dist/mcp/server.js +19 -6
  73. package/dist/mcp/server.js.map +1 -1
  74. package/dist/mcp/store.d.ts +10 -1
  75. package/dist/mcp/store.d.ts.map +1 -1
  76. package/dist/mcp/store.js +51 -0
  77. package/dist/mcp/store.js.map +1 -1
  78. package/dist/mcp/tools.d.ts +52 -2
  79. package/dist/mcp/tools.d.ts.map +1 -1
  80. package/dist/mcp/tools.js +395 -11
  81. package/dist/mcp/tools.js.map +1 -1
  82. package/dist/mcp/types.d.ts +36 -2
  83. package/dist/mcp/types.d.ts.map +1 -1
  84. package/dist/mcp/types.js +12 -0
  85. package/dist/mcp/types.js.map +1 -1
  86. package/dist/mcp/write-client.d.ts +81 -0
  87. package/dist/mcp/write-client.d.ts.map +1 -0
  88. package/dist/mcp/write-client.js +140 -0
  89. package/dist/mcp/write-client.js.map +1 -0
  90. package/dist/oura/history-policy.d.ts +12 -0
  91. package/dist/oura/history-policy.d.ts.map +1 -0
  92. package/dist/oura/history-policy.js +54 -0
  93. package/dist/oura/history-policy.js.map +1 -0
  94. package/dist/oura/index.d.ts +51 -0
  95. package/dist/oura/index.d.ts.map +1 -0
  96. package/dist/oura/index.js +315 -0
  97. package/dist/oura/index.js.map +1 -0
  98. package/dist/pdpp/approval.d.ts +1 -1
  99. package/dist/pdpp/approval.d.ts.map +1 -1
  100. package/dist/pdpp/approval.js +29 -10
  101. package/dist/pdpp/approval.js.map +1 -1
  102. package/dist/pdpp/declaration-limits.d.ts +7 -0
  103. package/dist/pdpp/declaration-limits.d.ts.map +1 -0
  104. package/dist/pdpp/declaration-limits.js +7 -0
  105. package/dist/pdpp/declaration-limits.js.map +1 -0
  106. package/dist/pdpp/declaration.d.ts +2 -1
  107. package/dist/pdpp/declaration.d.ts.map +1 -1
  108. package/dist/pdpp/declaration.js +2 -1
  109. package/dist/pdpp/declaration.js.map +1 -1
  110. package/dist/pdpp/index.d.ts +3 -2
  111. package/dist/pdpp/index.d.ts.map +1 -1
  112. package/dist/pdpp/index.js +3 -2
  113. package/dist/pdpp/index.js.map +1 -1
  114. package/dist/pdpp/issuance.d.ts.map +1 -1
  115. package/dist/pdpp/issuance.js +6 -2
  116. package/dist/pdpp/issuance.js.map +1 -1
  117. package/dist/pdpp/resolve.d.ts +12 -1
  118. package/dist/pdpp/resolve.d.ts.map +1 -1
  119. package/dist/pdpp/resolve.js +156 -58
  120. package/dist/pdpp/resolve.js.map +1 -1
  121. package/dist/pdpp/selection.d.ts +30 -1
  122. package/dist/pdpp/selection.d.ts.map +1 -1
  123. package/dist/pdpp/selection.js +77 -26
  124. package/dist/pdpp/selection.js.map +1 -1
  125. package/dist/pdpp/time.d.ts +39 -0
  126. package/dist/pdpp/time.d.ts.map +1 -0
  127. package/dist/pdpp/time.js +173 -0
  128. package/dist/pdpp/time.js.map +1 -0
  129. package/dist/pdpp/tokens.d.ts.map +1 -1
  130. package/dist/pdpp/tokens.js +4 -2
  131. package/dist/pdpp/tokens.js.map +1 -1
  132. package/dist/pdpp/types.d.ts +18 -2
  133. package/dist/pdpp/types.d.ts.map +1 -1
  134. package/dist/pdpp/types.js +7 -0
  135. package/dist/pdpp/types.js.map +1 -1
  136. package/dist/policy/reserved-scopes.d.ts +7 -0
  137. package/dist/policy/reserved-scopes.d.ts.map +1 -1
  138. package/dist/policy/reserved-scopes.js +12 -1
  139. package/dist/policy/reserved-scopes.js.map +1 -1
  140. package/dist/ports/index.d.ts +85 -1
  141. package/dist/ports/index.d.ts.map +1 -1
  142. package/dist/ports/index.js.map +1 -1
  143. package/dist/ports/pdpp-auth.d.ts +17 -27
  144. package/dist/ports/pdpp-auth.d.ts.map +1 -1
  145. package/dist/ports/pdpp-auth.js +14 -28
  146. package/dist/ports/pdpp-auth.js.map +1 -1
  147. package/dist/publication/publish.d.ts +96 -0
  148. package/dist/publication/publish.d.ts.map +1 -0
  149. package/dist/publication/publish.js +261 -0
  150. package/dist/publication/publish.js.map +1 -0
  151. package/dist/replication/completion.d.ts +20 -0
  152. package/dist/replication/completion.d.ts.map +1 -0
  153. package/dist/replication/completion.js +73 -0
  154. package/dist/replication/completion.js.map +1 -0
  155. package/dist/replication/coordinator-state.d.ts +29 -0
  156. package/dist/replication/coordinator-state.d.ts.map +1 -0
  157. package/dist/replication/coordinator-state.js +88 -0
  158. package/dist/replication/coordinator-state.js.map +1 -0
  159. package/dist/replication/coordinator-state.test-utils.d.ts +32 -0
  160. package/dist/replication/coordinator-state.test-utils.d.ts.map +1 -0
  161. package/dist/replication/coordinator-state.test-utils.js +113 -0
  162. package/dist/replication/coordinator-state.test-utils.js.map +1 -0
  163. package/dist/replication/coordinator.d.ts +264 -0
  164. package/dist/replication/coordinator.d.ts.map +1 -0
  165. package/dist/replication/coordinator.js +499 -0
  166. package/dist/replication/coordinator.js.map +1 -0
  167. package/dist/replication/copies.d.ts +126 -0
  168. package/dist/replication/copies.d.ts.map +1 -0
  169. package/dist/replication/copies.js +437 -0
  170. package/dist/replication/copies.js.map +1 -0
  171. package/dist/replication/copy-promotion.d.ts +132 -0
  172. package/dist/replication/copy-promotion.d.ts.map +1 -0
  173. package/dist/replication/copy-promotion.js +126 -0
  174. package/dist/replication/copy-promotion.js.map +1 -0
  175. package/dist/replication/door.d.ts +33 -0
  176. package/dist/replication/door.d.ts.map +1 -0
  177. package/dist/replication/door.js +10 -0
  178. package/dist/replication/door.js.map +1 -0
  179. package/dist/replication/dpv2.d.ts +141 -0
  180. package/dist/replication/dpv2.d.ts.map +1 -0
  181. package/dist/replication/dpv2.js +320 -0
  182. package/dist/replication/dpv2.js.map +1 -0
  183. package/dist/replication/effects.d.ts +68 -0
  184. package/dist/replication/effects.d.ts.map +1 -0
  185. package/dist/replication/effects.js +89 -0
  186. package/dist/replication/effects.js.map +1 -0
  187. package/dist/replication/engine.d.ts +378 -0
  188. package/dist/replication/engine.d.ts.map +1 -0
  189. package/dist/replication/engine.js +3197 -0
  190. package/dist/replication/engine.js.map +1 -0
  191. package/dist/replication/envelope.d.ts +481 -0
  192. package/dist/replication/envelope.d.ts.map +1 -0
  193. package/dist/replication/envelope.js +192 -0
  194. package/dist/replication/envelope.js.map +1 -0
  195. package/dist/replication/evidence.d.ts +118 -0
  196. package/dist/replication/evidence.d.ts.map +1 -0
  197. package/dist/replication/evidence.js +198 -0
  198. package/dist/replication/evidence.js.map +1 -0
  199. package/dist/replication/finality.d.ts +16 -0
  200. package/dist/replication/finality.d.ts.map +1 -0
  201. package/dist/replication/finality.js +11 -0
  202. package/dist/replication/finality.js.map +1 -0
  203. package/dist/replication/fixtures.d.ts +16 -0
  204. package/dist/replication/fixtures.d.ts.map +1 -0
  205. package/dist/replication/fixtures.js +47 -0
  206. package/dist/replication/fixtures.js.map +1 -0
  207. package/dist/replication/host-config.d.ts +52 -0
  208. package/dist/replication/host-config.d.ts.map +1 -0
  209. package/dist/replication/host-config.js +111 -0
  210. package/dist/replication/host-config.js.map +1 -0
  211. package/dist/replication/host-driver.d.ts +95 -0
  212. package/dist/replication/host-driver.d.ts.map +1 -0
  213. package/dist/replication/host-driver.js +202 -0
  214. package/dist/replication/host-driver.js.map +1 -0
  215. package/dist/replication/host-ports.d.ts +48 -0
  216. package/dist/replication/host-ports.d.ts.map +1 -0
  217. package/dist/replication/host-ports.js +69 -0
  218. package/dist/replication/host-ports.js.map +1 -0
  219. package/dist/replication/identity.d.ts +13 -0
  220. package/dist/replication/identity.d.ts.map +1 -0
  221. package/dist/replication/identity.js +22 -0
  222. package/dist/replication/identity.js.map +1 -0
  223. package/dist/replication/limits.d.ts +124 -0
  224. package/dist/replication/limits.d.ts.map +1 -0
  225. package/dist/replication/limits.js +182 -0
  226. package/dist/replication/limits.js.map +1 -0
  227. package/dist/replication/merge-plan.d.ts +92 -0
  228. package/dist/replication/merge-plan.d.ts.map +1 -0
  229. package/dist/replication/merge-plan.js +229 -0
  230. package/dist/replication/merge-plan.js.map +1 -0
  231. package/dist/replication/namespace.d.ts +4 -0
  232. package/dist/replication/namespace.d.ts.map +1 -0
  233. package/dist/replication/namespace.js +7 -0
  234. package/dist/replication/namespace.js.map +1 -0
  235. package/dist/replication/outcome.d.ts +178 -0
  236. package/dist/replication/outcome.d.ts.map +1 -0
  237. package/dist/replication/outcome.js +83 -0
  238. package/dist/replication/outcome.js.map +1 -0
  239. package/dist/replication/payload.d.ts +39 -0
  240. package/dist/replication/payload.d.ts.map +1 -0
  241. package/dist/replication/payload.js +137 -0
  242. package/dist/replication/payload.js.map +1 -0
  243. package/dist/replication/preparation.d.ts +42 -0
  244. package/dist/replication/preparation.d.ts.map +1 -0
  245. package/dist/replication/preparation.js +118 -0
  246. package/dist/replication/preparation.js.map +1 -0
  247. package/dist/replication/rebaseline.d.ts +33 -0
  248. package/dist/replication/rebaseline.d.ts.map +1 -0
  249. package/dist/replication/rebaseline.js +40 -0
  250. package/dist/replication/rebaseline.js.map +1 -0
  251. package/dist/replication/rebinding.d.ts +43 -0
  252. package/dist/replication/rebinding.d.ts.map +1 -0
  253. package/dist/replication/rebinding.js +52 -0
  254. package/dist/replication/rebinding.js.map +1 -0
  255. package/dist/replication/receive.d.ts +57 -0
  256. package/dist/replication/receive.d.ts.map +1 -0
  257. package/dist/replication/receive.js +114 -0
  258. package/dist/replication/receive.js.map +1 -0
  259. package/dist/replication/record-reducer.d.ts +16 -0
  260. package/dist/replication/record-reducer.d.ts.map +1 -0
  261. package/dist/replication/record-reducer.js +52 -0
  262. package/dist/replication/record-reducer.js.map +1 -0
  263. package/dist/replication/revision.d.ts +24 -0
  264. package/dist/replication/revision.d.ts.map +1 -0
  265. package/dist/replication/revision.js +35 -0
  266. package/dist/replication/revision.js.map +1 -0
  267. package/dist/replication/roster.d.ts +53 -0
  268. package/dist/replication/roster.d.ts.map +1 -0
  269. package/dist/replication/roster.js +115 -0
  270. package/dist/replication/roster.js.map +1 -0
  271. package/dist/replication/schedule.d.ts +73 -0
  272. package/dist/replication/schedule.d.ts.map +1 -0
  273. package/dist/replication/schedule.js +182 -0
  274. package/dist/replication/schedule.js.map +1 -0
  275. package/dist/replication/stream.d.ts +73 -0
  276. package/dist/replication/stream.d.ts.map +1 -0
  277. package/dist/replication/stream.js +542 -0
  278. package/dist/replication/stream.js.map +1 -0
  279. package/dist/replication/transport.d.ts +236 -0
  280. package/dist/replication/transport.d.ts.map +1 -0
  281. package/dist/replication/transport.js +440 -0
  282. package/dist/replication/transport.js.map +1 -0
  283. package/dist/replication/visibility-engine.d.ts +337 -0
  284. package/dist/replication/visibility-engine.d.ts.map +1 -0
  285. package/dist/replication/visibility-engine.js +602 -0
  286. package/dist/replication/visibility-engine.js.map +1 -0
  287. package/dist/replication/visibility-policy.d.ts +26 -0
  288. package/dist/replication/visibility-policy.d.ts.map +1 -0
  289. package/dist/replication/visibility-policy.js +33 -0
  290. package/dist/replication/visibility-policy.js.map +1 -0
  291. package/dist/replication/writer-identity-store.d.ts +100 -0
  292. package/dist/replication/writer-identity-store.d.ts.map +1 -0
  293. package/dist/replication/writer-identity-store.js +218 -0
  294. package/dist/replication/writer-identity-store.js.map +1 -0
  295. package/dist/replication/writer-identity.d.ts +252 -0
  296. package/dist/replication/writer-identity.d.ts.map +1 -0
  297. package/dist/replication/writer-identity.js +281 -0
  298. package/dist/replication/writer-identity.js.map +1 -0
  299. package/dist/replication/writer-identity.test-utils.d.ts +24 -0
  300. package/dist/replication/writer-identity.test-utils.d.ts.map +1 -0
  301. package/dist/replication/writer-identity.test-utils.js +86 -0
  302. package/dist/replication/writer-identity.test-utils.js.map +1 -0
  303. package/dist/schemas/server-config.d.ts +13 -0
  304. package/dist/schemas/server-config.d.ts.map +1 -1
  305. package/dist/schemas/server-config.js +24 -0
  306. package/dist/schemas/server-config.js.map +1 -1
  307. package/dist/storage/adapters/index.d.ts +3 -1
  308. package/dist/storage/adapters/index.d.ts.map +1 -1
  309. package/dist/storage/adapters/index.js +2 -0
  310. package/dist/storage/adapters/index.js.map +1 -1
  311. package/dist/storage/adapters/interface.d.ts +18 -1
  312. package/dist/storage/adapters/interface.d.ts.map +1 -1
  313. package/dist/storage/adapters/interface.js +13 -1
  314. package/dist/storage/adapters/interface.js.map +1 -1
  315. package/dist/storage/adapters/sdk.d.ts +2 -1
  316. package/dist/storage/adapters/sdk.d.ts.map +1 -1
  317. package/dist/storage/adapters/sdk.js +21 -3
  318. package/dist/storage/adapters/sdk.js.map +1 -1
  319. package/dist/storage/adapters/vana-audience.d.ts +17 -5
  320. package/dist/storage/adapters/vana-audience.d.ts.map +1 -1
  321. package/dist/storage/adapters/vana-audience.js +24 -9
  322. package/dist/storage/adapters/vana-audience.js.map +1 -1
  323. package/dist/storage/adapters/vana.d.ts +2 -2
  324. package/dist/storage/adapters/vana.d.ts.map +1 -1
  325. package/dist/storage/adapters/vana.js +30 -22
  326. package/dist/storage/adapters/vana.js.map +1 -1
  327. package/dist/storage/canonical-legacy-projection.d.ts +1 -1
  328. package/dist/storage/canonical-legacy-projection.d.ts.map +1 -1
  329. package/dist/storage/canonical-legacy-projection.js +13 -15
  330. package/dist/storage/canonical-legacy-projection.js.map +1 -1
  331. package/dist/storage/legacy-projection.d.ts.map +1 -1
  332. package/dist/storage/legacy-projection.js +16 -1
  333. package/dist/storage/legacy-projection.js.map +1 -1
  334. package/dist/storage/legacy-scope-coverage-exceptions.d.ts +5 -0
  335. package/dist/storage/legacy-scope-coverage-exceptions.d.ts.map +1 -1
  336. package/dist/storage/legacy-scope-coverage-exceptions.js +4 -0
  337. package/dist/storage/legacy-scope-coverage-exceptions.js.map +1 -1
  338. package/dist/storage/legacy-scope-coverage.d.ts.map +1 -1
  339. package/dist/storage/legacy-scope-coverage.js +14 -1
  340. package/dist/storage/legacy-scope-coverage.js.map +1 -1
  341. package/dist/storage/legacy-scope-entity-keys.d.ts +14 -1
  342. package/dist/storage/legacy-scope-entity-keys.d.ts.map +1 -1
  343. package/dist/storage/legacy-scope-entity-keys.js +18 -1
  344. package/dist/storage/legacy-scope-entity-keys.js.map +1 -1
  345. package/dist/storage/legacy-scope-view.d.ts +57 -5
  346. package/dist/storage/legacy-scope-view.d.ts.map +1 -1
  347. package/dist/storage/legacy-scope-view.js +644 -318
  348. package/dist/storage/legacy-scope-view.js.map +1 -1
  349. package/dist/storage/pdpp-records/cursor.d.ts +47 -2
  350. package/dist/storage/pdpp-records/cursor.d.ts.map +1 -1
  351. package/dist/storage/pdpp-records/cursor.js +7 -0
  352. package/dist/storage/pdpp-records/cursor.js.map +1 -1
  353. package/dist/storage/pdpp-records/enforcement.d.ts +3 -16
  354. package/dist/storage/pdpp-records/enforcement.d.ts.map +1 -1
  355. package/dist/storage/pdpp-records/enforcement.js +40 -13
  356. package/dist/storage/pdpp-records/enforcement.js.map +1 -1
  357. package/dist/storage/pdpp-records/index.d.ts +2 -0
  358. package/dist/storage/pdpp-records/index.d.ts.map +1 -1
  359. package/dist/storage/pdpp-records/index.js +1 -0
  360. package/dist/storage/pdpp-records/index.js.map +1 -1
  361. package/dist/storage/pdpp-records/interface.d.ts +8 -1
  362. package/dist/storage/pdpp-records/interface.d.ts.map +1 -1
  363. package/dist/storage/pdpp-records/list-page.d.ts +35 -0
  364. package/dist/storage/pdpp-records/list-page.d.ts.map +1 -0
  365. package/dist/storage/pdpp-records/list-page.js +106 -0
  366. package/dist/storage/pdpp-records/list-page.js.map +1 -0
  367. package/dist/storage/pdpp-records/memory-store.d.ts.map +1 -1
  368. package/dist/storage/pdpp-records/memory-store.js +95 -99
  369. package/dist/storage/pdpp-records/memory-store.js.map +1 -1
  370. package/dist/storage/pdpp-records/portable.d.ts +3 -0
  371. package/dist/storage/pdpp-records/portable.d.ts.map +1 -1
  372. package/dist/storage/pdpp-records/portable.js +3 -0
  373. package/dist/storage/pdpp-records/portable.js.map +1 -1
  374. package/dist/storage/pdpp-records/replication-journal.d.ts +20 -0
  375. package/dist/storage/pdpp-records/replication-journal.d.ts.map +1 -0
  376. package/dist/storage/pdpp-records/replication-journal.js +2 -0
  377. package/dist/storage/pdpp-records/replication-journal.js.map +1 -0
  378. package/dist/storage/pdpp-records/stream-declaration.d.ts +0 -2
  379. package/dist/storage/pdpp-records/stream-declaration.d.ts.map +1 -1
  380. package/dist/storage/pdpp-records/stream-declaration.js +0 -9
  381. package/dist/storage/pdpp-records/stream-declaration.js.map +1 -1
  382. package/dist/storage/pdpp-records/sync-selection.d.ts +4 -0
  383. package/dist/storage/pdpp-records/sync-selection.d.ts.map +1 -0
  384. package/dist/storage/pdpp-records/sync-selection.js +37 -0
  385. package/dist/storage/pdpp-records/sync-selection.js.map +1 -0
  386. package/dist/storage/pdpp-records/types.d.ts +64 -0
  387. package/dist/storage/pdpp-records/types.d.ts.map +1 -1
  388. package/dist/storage/pdpp-records/types.js.map +1 -1
  389. package/dist/sync/delete-data-port.d.ts +15 -0
  390. package/dist/sync/delete-data-port.d.ts.map +1 -1
  391. package/dist/sync/delete-data-port.js +19 -7
  392. package/dist/sync/delete-data-port.js.map +1 -1
  393. package/dist/sync/index.d.ts +2 -1
  394. package/dist/sync/index.d.ts.map +1 -1
  395. package/dist/sync/index.js +2 -1
  396. package/dist/sync/index.js.map +1 -1
  397. package/dist/sync/pending-blob-deletions.d.ts +18 -2
  398. package/dist/sync/pending-blob-deletions.d.ts.map +1 -1
  399. package/dist/sync/pending-blob-deletions.js +69 -23
  400. package/dist/sync/pending-blob-deletions.js.map +1 -1
  401. package/dist/sync/workers/delete.d.ts.map +1 -1
  402. package/dist/sync/workers/delete.js +332 -142
  403. package/dist/sync/workers/delete.js.map +1 -1
  404. package/dist/sync/workers/download.d.ts.map +1 -1
  405. package/dist/sync/workers/download.js +53 -5
  406. package/dist/sync/workers/download.js.map +1 -1
  407. package/dist/sync/workers/upload.d.ts +24 -5
  408. package/dist/sync/workers/upload.d.ts.map +1 -1
  409. package/dist/sync/workers/upload.js +160 -275
  410. package/dist/sync/workers/upload.js.map +1 -1
  411. package/dist/test-utils/memory-storage.d.ts.map +1 -1
  412. package/dist/test-utils/memory-storage.js +17 -2
  413. package/dist/test-utils/memory-storage.js.map +1 -1
  414. package/package.json +24 -2
@@ -0,0 +1,26 @@
1
+ /** One policy for every replica read surface. Reader identity is supplied by the trusted host. */
2
+ export type ReplicaReader = "owner" | "grant";
3
+ export type ReplicaVisibilityState = "confirmed" | "pending" | "quarantined" | "conflicted";
4
+ export type ReplicaRecordOrigin = "local" | "received";
5
+ export interface ReplicaVisibilityPolicy {
6
+ owner: "confirmed-only" | "include-pending";
7
+ grant: "confirmed-only";
8
+ }
9
+ export declare const DEFAULT_REPLICA_VISIBILITY_POLICY: Readonly<ReplicaVisibilityPolicy>;
10
+ export declare function replicaStateVisible(state: ReplicaVisibilityState, reader?: ReplicaReader, policy?: ReplicaVisibilityPolicy, origin?: ReplicaRecordOrigin): boolean;
11
+ /** The marker describes every pending effect, including a removal. */
12
+ export declare function replicaPendingMetadata(): {
13
+ confirmation: "not yet confirmed";
14
+ visibility: "pending";
15
+ };
16
+ /** Identity ambiguity is visible to the owner without declaring received data authoritative. */
17
+ export declare function replicaConflictMetadata(): {
18
+ visibility: "conflicted";
19
+ status: "account conflict";
20
+ };
21
+ /** The host supplies the durable identity-ambiguity fact, never a request parameter. */
22
+ export declare function replicaConnectionVisibility(bindingConflict: boolean): {
23
+ state: "conflicted";
24
+ reason: "source_binding";
25
+ } | undefined;
26
+ //# sourceMappingURL=visibility-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visibility-policy.d.ts","sourceRoot":"","sources":["../../src/replication/visibility-policy.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,OAAO,CAAC;AAC9C,MAAM,MAAM,sBAAsB,GAChC,WAAW,GAAG,SAAS,GAAG,aAAa,GAAG,YAAY,CAAC;AACzD,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,UAAU,CAAC;AACvD,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB,CAAC;IAC5C,KAAK,EAAE,gBAAgB,CAAC;CACzB;AACD,eAAO,MAAM,iCAAiC,EAAE,QAAQ,CAAC,uBAAuB,CAI7E,CAAC;AACJ,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,sBAAsB,EAC7B,MAAM,GAAE,aAAuB,EAC/B,MAAM,GAAE,uBAA2D,EACnE,MAAM,GAAE,mBAAgC,GACvC,OAAO,CAQT;AAED,sEAAsE;AACtE,wBAAgB,sBAAsB;;;EAKrC;AAED,gGAAgG;AAChG,wBAAgB,uBAAuB;;;EAKtC;AAED,wFAAwF;AACxF,wBAAgB,2BAA2B,CAAC,eAAe,EAAE,OAAO;;;cAInE"}
@@ -0,0 +1,33 @@
1
+ export const DEFAULT_REPLICA_VISIBILITY_POLICY = {
2
+ owner: "include-pending",
3
+ grant: "confirmed-only",
4
+ };
5
+ export function replicaStateVisible(state, reader = "grant", policy = DEFAULT_REPLICA_VISIBILITY_POLICY, origin = "received") {
6
+ if (state === "conflicted")
7
+ return reader === "owner" && origin === "local";
8
+ return (state === "confirmed" ||
9
+ (state === "pending" &&
10
+ reader === "owner" &&
11
+ policy.owner === "include-pending"));
12
+ }
13
+ /** The marker describes every pending effect, including a removal. */
14
+ export function replicaPendingMetadata() {
15
+ return {
16
+ confirmation: "not yet confirmed",
17
+ visibility: "pending",
18
+ };
19
+ }
20
+ /** Identity ambiguity is visible to the owner without declaring received data authoritative. */
21
+ export function replicaConflictMetadata() {
22
+ return {
23
+ visibility: "conflicted",
24
+ status: "account conflict",
25
+ };
26
+ }
27
+ /** The host supplies the durable identity-ambiguity fact, never a request parameter. */
28
+ export function replicaConnectionVisibility(bindingConflict) {
29
+ return bindingConflict
30
+ ? { state: "conflicted", reason: "source_binding" }
31
+ : undefined;
32
+ }
33
+ //# sourceMappingURL=visibility-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visibility-policy.js","sourceRoot":"","sources":["../../src/replication/visibility-policy.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,iCAAiC,GAC5C;IACE,KAAK,EAAE,iBAAiB;IACxB,KAAK,EAAE,gBAAgB;CACxB,CAAC;AACJ,MAAM,UAAU,mBAAmB,CACjC,KAA6B,EAC7B,SAAwB,OAAO,EAC/B,SAAkC,iCAAiC,EACnE,SAA8B,UAAU;IAExC,IAAI,KAAK,KAAK,YAAY;QAAE,OAAO,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,OAAO,CAAC;IAC5E,OAAO,CACL,KAAK,KAAK,WAAW;QACrB,CAAC,KAAK,KAAK,SAAS;YAClB,MAAM,KAAK,OAAO;YAClB,MAAM,CAAC,KAAK,KAAK,iBAAiB,CAAC,CACtC,CAAC;AACJ,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,sBAAsB;IACpC,OAAO;QACL,YAAY,EAAE,mBAA4B;QAC1C,UAAU,EAAE,SAAkB;KAC/B,CAAC;AACJ,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,uBAAuB;IACrC,OAAO;QACL,UAAU,EAAE,YAAqB;QACjC,MAAM,EAAE,kBAA2B;KACpC,CAAC;AACJ,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,2BAA2B,CAAC,eAAwB;IAClE,OAAO,eAAe;QACpB,CAAC,CAAC,EAAE,KAAK,EAAE,YAAqB,EAAE,MAAM,EAAE,gBAAyB,EAAE;QACrE,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * This server's replica writer identity (host contract §3.2), as storage
3
+ * effects Node (`server/src/storage/pdpp-replica-writer-identity.ts`) and
4
+ * PS-Lite (`lite/src/replication-engine.ts`) both run. Each row is one
5
+ * incarnation: the gateway registration and writer nonce it was derived
6
+ * from, and the two writer ids. The current identity is the highest
7
+ * incarnation. Rows are never changed, so an older writer id can never be
8
+ * derived again on this database.
9
+ */
10
+ import { type ReplicaRosterPort, type ReplicaRosterRecord } from "./roster.js";
11
+ import { type ReplicaWriterSeed } from "./writer-identity.js";
12
+ import { type ReplicationRefusal } from "./door.js";
13
+ import { type ReplicaEffect } from "./effects.js";
14
+ import type { ReplicationTimers } from "./host-driver.js";
15
+ export declare const REPLICA_WRITER_IDENTITY_MIGRATION = "\nCREATE TABLE IF NOT EXISTS pdpp_replica_writer_identity (\n incarnation INTEGER PRIMARY KEY AUTOINCREMENT,\n owner TEXT NOT NULL,\n server TEXT NOT NULL,\n server_id TEXT NOT NULL,\n writer_nonce TEXT NOT NULL UNIQUE,\n transport_writer TEXT NOT NULL UNIQUE,\n operation_writer TEXT NOT NULL UNIQUE\n);\nCREATE TRIGGER IF NOT EXISTS pdpp_replica_writer_identity_no_update BEFORE UPDATE ON pdpp_replica_writer_identity\nBEGIN SELECT RAISE(ABORT, 'replica writer identity is append-only'); END;\nCREATE TRIGGER IF NOT EXISTS pdpp_replica_writer_identity_no_delete BEFORE DELETE ON pdpp_replica_writer_identity\nBEGIN SELECT RAISE(ABORT, 'replica writer identity is append-only'); END;\n";
16
+ export interface ReplicaWriterIdentity {
17
+ incarnation: number;
18
+ seed: ReplicaWriterSeed;
19
+ transportWriter: string;
20
+ operationWriter: string;
21
+ }
22
+ /** Writer identity cannot be created or changed for this database. */
23
+ export declare class ReplicaWriterIdentityError extends Error {
24
+ readonly code: "replica_identity_requires_fresh_journal" | "replica_identity_owner_mismatch" | "replica_identity_not_registered";
25
+ constructor(code: "replica_identity_requires_fresh_journal" | "replica_identity_owner_mismatch" | "replica_identity_not_registered");
26
+ }
27
+ /**
28
+ * What a boot rotation that threw means (host contract §3.2): a database
29
+ * without an identity yet (`no_identity`; its first identity draws a new
30
+ * nonce anyway) or a closed door (`replication_off`). `undefined` for a real
31
+ * failure, which the host rethrows.
32
+ */
33
+ export declare function replicaWriterRotationOutcome(error: unknown): "no_identity" | "replication_off" | undefined;
34
+ /** The current identity, or undefined before the first enable. */
35
+ export declare function currentReplicaWriterIdentity(): ReplicaEffect<ReplicaWriterIdentity | undefined>;
36
+ /** What the identity writes need from their host, in its transaction. */
37
+ export interface ReplicaWriterIdentityHost {
38
+ /** The replication door is open. */
39
+ admitted(): ReplicaEffect<boolean>;
40
+ /** No operation was captured locally yet (the first identity needs this). */
41
+ journalEmpty(): ReplicaEffect<boolean>;
42
+ }
43
+ /**
44
+ * Create or update the identity from this server's own gateway record, in
45
+ * the caller's write transaction. Idempotent for the current registration.
46
+ * A new registration id (the address registered again) starts a new
47
+ * incarnation with a new nonce.
48
+ *
49
+ * The first identity requires an empty replica journal: operations captured
50
+ * before it carry another writer id, which receivers refuse. Throws
51
+ * `ReplicationRefusedError` instead of writing once the door is closed.
52
+ */
53
+ export declare function establishReplicaWriterIdentity(host: ReplicaWriterIdentityHost, input: {
54
+ owner: string;
55
+ server: string;
56
+ record: ReplicaRosterRecord | null;
57
+ nonce?: string;
58
+ }): ReplicaEffect<ReplicaWriterIdentity>;
59
+ /**
60
+ * A new nonce under the same registration, before new writes, in the
61
+ * caller's write transaction. See the Node host for when to call it.
62
+ */
63
+ export declare function rotateReplicaWriterIdentity(host: Pick<ReplicaWriterIdentityHost, "admitted">, input?: {
64
+ nonce?: string;
65
+ }): ReplicaEffect<ReplicaWriterIdentity>;
66
+ export type ReplicaWriterIdentityState = {
67
+ tag: "ready";
68
+ identity: ReplicaWriterIdentity;
69
+ } | {
70
+ tag: "waiting";
71
+ reason: "server_not_registered" | "roster_unavailable";
72
+ }
73
+ /** The replication door closed; it stays closed. */
74
+ | {
75
+ tag: "refused";
76
+ reason: ReplicationRefusal;
77
+ };
78
+ /**
79
+ * Enable step: read this server's own roster record and establish or
80
+ * update the identity from it. Waits while the server is not registered,
81
+ * revoked, or registered under another owner. While the roster is
82
+ * unavailable an existing identity stays usable; a missing one waits. A read
83
+ * that outlasts `deadlineMs` (default: the coordinator's attempt deadline)
84
+ * counts as unavailable. The roster read writes nothing; if the door closes
85
+ * during it, the identity write refuses.
86
+ *
87
+ * `current` reads the identity; `establish` runs
88
+ * `establishReplicaWriterIdentity` in one write transaction.
89
+ */
90
+ export declare function enableReplicaWriterIdentity(input: {
91
+ owner: string;
92
+ server: string;
93
+ roster: ReplicaRosterPort;
94
+ signal?: AbortSignal;
95
+ deadlineMs?: number;
96
+ timers?: Pick<ReplicationTimers, "setTimeout" | "clearTimeout">;
97
+ current(): ReplicaWriterIdentity | undefined | Promise<ReplicaWriterIdentity | undefined>;
98
+ establish(record: ReplicaRosterRecord | null): ReplicaWriterIdentity | Promise<ReplicaWriterIdentity>;
99
+ }): Promise<ReplicaWriterIdentityState>;
100
+ //# sourceMappingURL=writer-identity-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer-identity-store.d.ts","sourceRoot":"","sources":["../../src/replication/writer-identity-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAA2B,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EAAO,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,eAAO,MAAM,iCAAiC,0rBAc7C,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,iBAAiB,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB;AAYD,sEAAsE;AACtE,qBAAa,0BAA2B,SAAQ,KAAK;IAEjD,QAAQ,CAAC,IAAI,EACT,yCAAyC,GACzC,iCAAiC,GACjC,iCAAiC;gBAH5B,IAAI,EACT,yCAAyC,GACzC,iCAAiC,GACjC,iCAAiC;CAKxC;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,OAAO,GACb,aAAa,GAAG,iBAAiB,GAAG,SAAS,CAQ/C;AAED,kEAAkE;AAClE,wBAAiB,4BAA4B,IAAI,aAAa,CAC5D,qBAAqB,GAAG,SAAS,CAClC,CAiBA;AAED,yEAAyE;AACzE,MAAM,WAAW,yBAAyB;I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,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAAC;IAC/C,SAAS,CACP,MAAM,EAAE,mBAAmB,GAAG,IAAI,GACjC,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAC3D,GAAG,OAAO,CAAC,0BAA0B,CAAC,CA+BtC"}
@@ -0,0 +1,218 @@
1
+ /**
2
+ * This server's replica writer identity (host contract §3.2), as storage
3
+ * effects Node (`server/src/storage/pdpp-replica-writer-identity.ts`) and
4
+ * PS-Lite (`lite/src/replication-engine.ts`) both run. Each row is one
5
+ * incarnation: the gateway registration and writer nonce it was derived
6
+ * from, and the two writer ids. The current identity is the highest
7
+ * incarnation. Rows are never changed, so an older writer id can never be
8
+ * derived again on this database.
9
+ */
10
+ import { ReplicaRosterUnavailableError, } from "./roster.js";
11
+ import { deriveReplicaWriters, randomReplicaWriterNonce, replicaWriterSeedSchema, } from "./writer-identity.js";
12
+ import { ReplicationRefusedError } from "./door.js";
13
+ import { sql } from "./effects.js";
14
+ import { REPLICA_ATTEMPT_TIMEOUT_MS } from "./coordinator.js";
15
+ export const REPLICA_WRITER_IDENTITY_MIGRATION = `
16
+ CREATE TABLE IF NOT EXISTS pdpp_replica_writer_identity (
17
+ incarnation INTEGER PRIMARY KEY AUTOINCREMENT,
18
+ owner TEXT NOT NULL,
19
+ server TEXT NOT NULL,
20
+ server_id TEXT NOT NULL,
21
+ writer_nonce TEXT NOT NULL UNIQUE,
22
+ transport_writer TEXT NOT NULL UNIQUE,
23
+ operation_writer TEXT NOT NULL UNIQUE
24
+ );
25
+ CREATE TRIGGER IF NOT EXISTS pdpp_replica_writer_identity_no_update BEFORE UPDATE ON pdpp_replica_writer_identity
26
+ BEGIN SELECT RAISE(ABORT, 'replica writer identity is append-only'); END;
27
+ CREATE TRIGGER IF NOT EXISTS pdpp_replica_writer_identity_no_delete BEFORE DELETE ON pdpp_replica_writer_identity
28
+ BEGIN SELECT RAISE(ABORT, 'replica writer identity is append-only'); END;
29
+ `;
30
+ /** Writer identity cannot be created or changed for this database. */
31
+ export class ReplicaWriterIdentityError extends Error {
32
+ code;
33
+ constructor(code) {
34
+ super(code);
35
+ this.code = code;
36
+ this.name = "ReplicaWriterIdentityError";
37
+ }
38
+ }
39
+ /**
40
+ * What a boot rotation that threw means (host contract §3.2): a database
41
+ * without an identity yet (`no_identity`; its first identity draws a new
42
+ * nonce anyway) or a closed door (`replication_off`). `undefined` for a real
43
+ * failure, which the host rethrows.
44
+ */
45
+ export function replicaWriterRotationOutcome(error) {
46
+ if (error instanceof ReplicaWriterIdentityError &&
47
+ error.code === "replica_identity_not_registered")
48
+ return "no_identity";
49
+ if (error instanceof ReplicationRefusedError)
50
+ return "replication_off";
51
+ return undefined;
52
+ }
53
+ /** The current identity, or undefined before the first enable. */
54
+ export function* currentReplicaWriterIdentity() {
55
+ const row = yield* sql.get("SELECT * FROM pdpp_replica_writer_identity ORDER BY incarnation DESC LIMIT 1");
56
+ return row
57
+ ? {
58
+ incarnation: row.incarnation,
59
+ seed: {
60
+ owner: row.owner,
61
+ server: row.server,
62
+ serverId: row.server_id,
63
+ writerNonce: row.writer_nonce,
64
+ },
65
+ transportWriter: row.transport_writer,
66
+ operationWriter: row.operation_writer,
67
+ }
68
+ : undefined;
69
+ }
70
+ /**
71
+ * The only identity write. Run inside the caller's transaction, so the door
72
+ * check and the insert are atomic: once the door is closed, no identity is
73
+ * established or rotated.
74
+ */
75
+ function* insert(host, seed) {
76
+ if (!(yield* host.admitted()))
77
+ throw new ReplicationRefusedError("reenable_refused");
78
+ const s = replicaWriterSeedSchema.parse(seed);
79
+ const writers = deriveReplicaWriters(s);
80
+ yield* sql.run("INSERT INTO pdpp_replica_writer_identity (owner,server,server_id,writer_nonce,transport_writer,operation_writer) VALUES (?,?,?,?,?,?)", s.owner, s.server, s.serverId, s.writerNonce, writers.transport, writers.operation);
81
+ return (yield* currentReplicaWriterIdentity());
82
+ }
83
+ /** Registered now, under this owner. Anything else is not registered for it. */
84
+ function registeredId(record, owner) {
85
+ if (!record ||
86
+ record.revokedAt !== null ||
87
+ record.owner.toLowerCase() !== owner)
88
+ throw new ReplicaWriterIdentityError("replica_identity_not_registered");
89
+ return record.id.toLowerCase();
90
+ }
91
+ /**
92
+ * Create or update the identity from this server's own gateway record, in
93
+ * the caller's write transaction. Idempotent for the current registration.
94
+ * A new registration id (the address registered again) starts a new
95
+ * incarnation with a new nonce.
96
+ *
97
+ * The first identity requires an empty replica journal: operations captured
98
+ * before it carry another writer id, which receivers refuse. Throws
99
+ * `ReplicationRefusedError` instead of writing once the door is closed.
100
+ */
101
+ export function* establishReplicaWriterIdentity(host, input) {
102
+ const owner = input.owner.toLowerCase();
103
+ const server = input.server.toLowerCase();
104
+ const serverId = registeredId(input.record, owner);
105
+ const current = yield* currentReplicaWriterIdentity();
106
+ if (current && current.seed.owner !== owner)
107
+ throw new ReplicaWriterIdentityError("replica_identity_owner_mismatch");
108
+ if (current &&
109
+ current.seed.server === server &&
110
+ current.seed.serverId === serverId)
111
+ return current;
112
+ if (!current && !(yield* host.journalEmpty()))
113
+ throw new ReplicaWriterIdentityError("replica_identity_requires_fresh_journal");
114
+ return yield* insert(host, {
115
+ owner,
116
+ server,
117
+ serverId,
118
+ writerNonce: input.nonce ?? randomReplicaWriterNonce(),
119
+ });
120
+ }
121
+ /**
122
+ * A new nonce under the same registration, before new writes, in the
123
+ * caller's write transaction. See the Node host for when to call it.
124
+ */
125
+ export function* rotateReplicaWriterIdentity(host, input = {}) {
126
+ const current = yield* currentReplicaWriterIdentity();
127
+ if (!current)
128
+ throw new ReplicaWriterIdentityError("replica_identity_not_registered");
129
+ return yield* insert(host, {
130
+ ...current.seed,
131
+ writerNonce: input.nonce ?? randomReplicaWriterNonce(),
132
+ });
133
+ }
134
+ /**
135
+ * One bounded roster read. A gateway that never answers must not hold the
136
+ * single-flight step, so the read races a deadline: on it the lookup's signal
137
+ * aborts, the late answer is dropped and the read counts as unavailable,
138
+ * which `enableReplicaWriterIdentity` already settles as a Wait. The host's
139
+ * own abort is forwarded to the lookup.
140
+ */
141
+ async function readRoster(input) {
142
+ const lookup = new AbortController();
143
+ const forward = () => lookup.abort(input.signal.reason);
144
+ if (input.signal?.aborted)
145
+ forward();
146
+ else
147
+ input.signal?.addEventListener("abort", forward, { once: true });
148
+ let timer;
149
+ const deadline = new Promise((_resolve, reject) => {
150
+ timer = input.timers.setTimeout(() => {
151
+ const error = new DOMException("replica roster deadline", "TimeoutError");
152
+ lookup.abort(error);
153
+ reject(new ReplicaRosterUnavailableError({ cause: error }));
154
+ }, input.deadlineMs);
155
+ });
156
+ try {
157
+ return await Promise.race([
158
+ input.roster.server(input.server.toLowerCase(), {
159
+ signal: lookup.signal,
160
+ }),
161
+ deadline,
162
+ ]);
163
+ }
164
+ finally {
165
+ input.timers.clearTimeout(timer);
166
+ input.signal?.removeEventListener("abort", forward);
167
+ }
168
+ }
169
+ const defaultTimers = {
170
+ setTimeout: (run, ms) => globalThis.setTimeout(run, ms),
171
+ clearTimeout: (handle) => globalThis.clearTimeout(handle),
172
+ };
173
+ /**
174
+ * Enable step: read this server's own roster record and establish or
175
+ * update the identity from it. Waits while the server is not registered,
176
+ * revoked, or registered under another owner. While the roster is
177
+ * unavailable an existing identity stays usable; a missing one waits. A read
178
+ * that outlasts `deadlineMs` (default: the coordinator's attempt deadline)
179
+ * counts as unavailable. The roster read writes nothing; if the door closes
180
+ * during it, the identity write refuses.
181
+ *
182
+ * `current` reads the identity; `establish` runs
183
+ * `establishReplicaWriterIdentity` in one write transaction.
184
+ */
185
+ export async function enableReplicaWriterIdentity(input) {
186
+ let record;
187
+ try {
188
+ record = await readRoster({
189
+ roster: input.roster,
190
+ server: input.server,
191
+ signal: input.signal,
192
+ deadlineMs: input.deadlineMs ?? REPLICA_ATTEMPT_TIMEOUT_MS,
193
+ timers: input.timers ?? defaultTimers,
194
+ });
195
+ }
196
+ catch (error) {
197
+ if (!(error instanceof ReplicaRosterUnavailableError))
198
+ throw error;
199
+ const current = await input.current();
200
+ return current &&
201
+ current.seed.server === input.server.toLowerCase() &&
202
+ current.seed.owner === input.owner.toLowerCase()
203
+ ? { tag: "ready", identity: current }
204
+ : { tag: "waiting", reason: "roster_unavailable" };
205
+ }
206
+ try {
207
+ return { tag: "ready", identity: await input.establish(record) };
208
+ }
209
+ catch (error) {
210
+ if (error instanceof ReplicaWriterIdentityError &&
211
+ error.code === "replica_identity_not_registered")
212
+ return { tag: "waiting", reason: "server_not_registered" };
213
+ if (error instanceof ReplicationRefusedError)
214
+ return { tag: "refused", reason: error.reason };
215
+ throw error;
216
+ }
217
+ }
218
+ //# sourceMappingURL=writer-identity-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer-identity-store.js","sourceRoot":"","sources":["../../src/replication/writer-identity-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,6BAA6B,GAG9B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,uBAAuB,GAExB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,uBAAuB,EAA2B,MAAM,WAAW,CAAC;AAC7E,OAAO,EAAE,GAAG,EAAsB,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAG9D,MAAM,CAAC,MAAM,iCAAiC,GAAG;;;;;;;;;;;;;;CAchD,CAAC;AAmBF,sEAAsE;AACtE,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAExC;IADX,YACW,IAG4B;QAErC,KAAK,CAAC,IAAI,CAAC,CAAC;QALH,SAAI,GAAJ,IAAI,CAGwB;QAGrC,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAC1C,KAAc;IAEd,IACE,KAAK,YAAY,0BAA0B;QAC3C,KAAK,CAAC,IAAI,KAAK,iCAAiC;QAEhD,OAAO,aAAa,CAAC;I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AAC,MAAM,CAAC,WAAW,EAAE;YAClD,OAAO,CAAC,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE;YAChD,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE;YACrC,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAC;IACvD,CAAC;IACD,IAAI,CAAC;QACH,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;IACnE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IACE,KAAK,YAAY,0BAA0B;YAC3C,KAAK,CAAC,IAAI,KAAK,iCAAiC;YAEhD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC;QAC7D,IAAI,KAAK,YAAY,uBAAuB;YAC1C,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;QAClD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,252 @@
1
+ /**
2
+ * Who may write (host contract §3). A device signs each batch with its
3
+ * registered PS server key. Writer ids are derived from that signer, so a
4
+ * receiver checks them from the signature and the roster alone. Nothing is
5
+ * bound on first contact.
6
+ */
7
+ import { z } from "zod";
8
+ import { type Hex } from "viem";
9
+ import { type ReplicaRosterRecord } from "./roster.js";
10
+ export declare const REPLICA_WRITER_DOMAIN = "vana-pdpp-replica-writer-v1";
11
+ export type ReplicaWriterRole = "transport" | "operation";
12
+ export type ReplicaEnvironment = "dev" | "prod";
13
+ /**
14
+ * Declared by a runtime that rotates the writer identity at boot when the
15
+ * host asks (host contract §3.2). A host checks it before it relies on the
16
+ * rotation.
17
+ */
18
+ export declare const REPLICA_WRITER_ROTATION_CONTRACT = "replica-writer-rotation-v1";
19
+ /**
20
+ * What a boot did with the host's rotation request. `rotated`: a new nonce
21
+ * before any write of this boot. `no_identity`: this database has no writer
22
+ * identity yet, so its first one gets a new nonce anyway. `replication_off`:
23
+ * replication does not run in this boot (flag off or a closed door), so
24
+ * there is no writer to rotate. `not_requested`: the host did not ask.
25
+ */
26
+ export type ReplicaWriterRotation = "rotated" | "no_identity" | "replication_off" | "not_requested";
27
+ /** Everything a writer id is derived from. Hex values are lowercase. */
28
+ export declare const replicaWriterSeedSchema: z.ZodObject<{
29
+ owner: z.ZodString;
30
+ server: z.ZodString;
31
+ serverId: z.ZodString;
32
+ writerNonce: z.ZodString;
33
+ }, z.core.$strict>;
34
+ export type ReplicaWriterSeed = z.infer<typeof replicaWriterSeedSchema>;
35
+ export interface ReplicaWriters {
36
+ transport: string;
37
+ operation: string;
38
+ }
39
+ /**
40
+ * writerId(role) = first 16 bytes of SHA-256 over the length-prefixed domain
41
+ * tag, owner, server, serverId, role and writer nonce. Each field is its byte
42
+ * length (4 bytes, big-endian) then its bytes. 32 lowercase hex characters.
43
+ */
44
+ export declare function deriveReplicaWriterId(seed: ReplicaWriterSeed, role: ReplicaWriterRole): string;
45
+ /** The transport and operation writers of one seed. They always come as a pair. */
46
+ export declare function deriveReplicaWriters(seed: ReplicaWriterSeed): ReplicaWriters;
47
+ /** A fresh 16-byte writer nonce. */
48
+ export declare function randomReplicaWriterNonce(): string;
49
+ /**
50
+ * The signed batch statement (EIP-712 `PdppReplicaBatch`). With the writer
51
+ * scope, which the seed derives, it covers every field a receiver reads from
52
+ * a manifest and the registration slot the manifest is valid at.
53
+ */
54
+ export declare const replicaBatchStatementSchema: z.ZodObject<{
55
+ owner: z.ZodString;
56
+ server: z.ZodString;
57
+ serverId: z.ZodString;
58
+ environment: z.ZodEnum<{
59
+ dev: "dev";
60
+ prod: "prod";
61
+ }>;
62
+ writerNonce: z.ZodString;
63
+ version: z.ZodNumber;
64
+ batch: z.ZodString;
65
+ sequence: z.ZodNumber;
66
+ previous: z.ZodString;
67
+ previousBatch: z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"">]>;
68
+ collectedAt: z.ZodString;
69
+ digest: z.ZodString;
70
+ totalBytes: z.ZodNumber;
71
+ count: z.ZodNumber;
72
+ fragments: z.ZodString;
73
+ }, z.core.$strict>;
74
+ export type ReplicaBatchStatement = z.infer<typeof replicaBatchStatementSchema>;
75
+ /** The statement, its signature and the EIP-712 domain chain it was signed for. */
76
+ export declare const replicaBatchAuthoritySchema: z.ZodObject<{
77
+ chainId: z.ZodNumber;
78
+ statement: z.ZodObject<{
79
+ owner: z.ZodString;
80
+ server: z.ZodString;
81
+ serverId: z.ZodString;
82
+ environment: z.ZodEnum<{
83
+ dev: "dev";
84
+ prod: "prod";
85
+ }>;
86
+ writerNonce: z.ZodString;
87
+ version: z.ZodNumber;
88
+ batch: z.ZodString;
89
+ sequence: z.ZodNumber;
90
+ previous: z.ZodString;
91
+ previousBatch: z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"">]>;
92
+ collectedAt: z.ZodString;
93
+ digest: z.ZodString;
94
+ totalBytes: z.ZodNumber;
95
+ count: z.ZodNumber;
96
+ fragments: z.ZodString;
97
+ }, z.core.$strict>;
98
+ signature: z.ZodString;
99
+ }, z.core.$strict>;
100
+ export type ReplicaBatchAuthority = z.infer<typeof replicaBatchAuthoritySchema>;
101
+ /** EIP-712 typed data for one statement: domain "Vana PDPP Replica", version "1". */
102
+ export declare function replicaBatchTypedData(chainId: number, statement: ReplicaBatchStatement): {
103
+ domain: {
104
+ name: string;
105
+ version: string;
106
+ chainId: number;
107
+ };
108
+ types: {
109
+ readonly PdppReplicaBatch: readonly [{
110
+ readonly name: "owner";
111
+ readonly type: "address";
112
+ }, {
113
+ readonly name: "server";
114
+ readonly type: "address";
115
+ }, {
116
+ readonly name: "serverId";
117
+ readonly type: "bytes32";
118
+ }, {
119
+ readonly name: "environment";
120
+ readonly type: "string";
121
+ }, {
122
+ readonly name: "writerNonce";
123
+ readonly type: "bytes16";
124
+ }, {
125
+ readonly name: "version";
126
+ readonly type: "uint64";
127
+ }, {
128
+ readonly name: "batch";
129
+ readonly type: "string";
130
+ }, {
131
+ readonly name: "sequence";
132
+ readonly type: "uint64";
133
+ }, {
134
+ readonly name: "previous";
135
+ readonly type: "bytes32";
136
+ }, {
137
+ readonly name: "previousBatch";
138
+ readonly type: "string";
139
+ }, {
140
+ readonly name: "collectedAt";
141
+ readonly type: "string";
142
+ }, {
143
+ readonly name: "digest";
144
+ readonly type: "bytes32";
145
+ }, {
146
+ readonly name: "totalBytes";
147
+ readonly type: "uint64";
148
+ }, {
149
+ readonly name: "count";
150
+ readonly type: "uint32";
151
+ }, {
152
+ readonly name: "fragments";
153
+ readonly type: "bytes32";
154
+ }];
155
+ };
156
+ primaryType: "PdppReplicaBatch";
157
+ message: {
158
+ owner: Hex;
159
+ server: Hex;
160
+ serverId: Hex;
161
+ writerNonce: Hex;
162
+ previous: Hex;
163
+ digest: Hex;
164
+ fragments: Hex;
165
+ version: bigint;
166
+ sequence: bigint;
167
+ totalBytes: bigint;
168
+ count: number;
169
+ environment: "dev" | "prod";
170
+ batch: string;
171
+ previousBatch: string;
172
+ collectedAt: string;
173
+ };
174
+ };
175
+ /** The registered PS server key: Node `key.json` or the Lite server identity. */
176
+ export interface ReplicaBatchSigner {
177
+ address: string;
178
+ signTypedData(params: ReturnType<typeof replicaBatchTypedData>): Promise<`0x${string}`>;
179
+ }
180
+ /** What one receiver accepts: its own owner, chain and environment. */
181
+ export interface ReplicaPartition {
182
+ owner: string;
183
+ chainId: number;
184
+ environment: ReplicaEnvironment;
185
+ }
186
+ /** What the carrier claims about a batch; the statement must sign exactly this. */
187
+ export interface ReplicaBatchFacts {
188
+ /** The DPv2 version of the writer scope that registers the batch. */
189
+ version: number;
190
+ batch: string;
191
+ sequence: number;
192
+ previous: {
193
+ batch: string;
194
+ digest: string;
195
+ } | null;
196
+ collectedAt: string;
197
+ /** `sha256:<hex>` of the assembled batch. */
198
+ digest: string;
199
+ totalBytes: number;
200
+ /** Every fragment in index order: sha256 of its exact stored bytes and their length. */
201
+ fragments: readonly {
202
+ digest: string;
203
+ bytes: number;
204
+ }[];
205
+ }
206
+ /**
207
+ * SHA-256 over the ordered fragment list: for each entry its 32-byte digest,
208
+ * then its length as 8 bytes, big-endian.
209
+ */
210
+ export declare function replicaFragmentListDigest(fragments: ReplicaBatchFacts["fragments"]): string;
211
+ /** Sign one batch with the server key. The signer must be the seed's server. */
212
+ export declare function signReplicaBatch(input: {
213
+ signer: ReplicaBatchSigner;
214
+ partition: ReplicaPartition;
215
+ seed: ReplicaWriterSeed;
216
+ facts: ReplicaBatchFacts;
217
+ }): Promise<ReplicaBatchAuthority>;
218
+ /** Typed refusals; each one quarantines only the item that failed. */
219
+ export type ReplicaAuthorityRefusal = "signature_invalid" | "partition_mismatch" | "server_not_registered" | "roster_owner_mismatch" | "writer_mismatch";
220
+ export type ReplicaAuthorityVerdict = {
221
+ tag: "authorized";
222
+ seed: ReplicaWriterSeed;
223
+ writers: ReplicaWriters;
224
+ } | {
225
+ tag: "refused";
226
+ reason: ReplicaAuthorityRefusal;
227
+ }
228
+ /** The roster could not be read and no fresh answer is cached. */
229
+ | {
230
+ tag: "wait";
231
+ server: string;
232
+ };
233
+ /**
234
+ * Receiver checks 2-5 of host contract §3.4, in order. The carrier supplies
235
+ * its claimed facts and the transport writer of the scope it was registered
236
+ * in, so this does not depend on how the carrier names objects.
237
+ * `roster` throws when it cannot answer; that is a Wait, never acceptance.
238
+ */
239
+ export declare function authorizeReplicaBatch(input: {
240
+ authority: unknown;
241
+ facts: ReplicaBatchFacts;
242
+ transportWriter: string;
243
+ receiver: ReplicaPartition;
244
+ roster: (server: `0x${string}`) => Promise<ReplicaRosterRecord | null>;
245
+ }): Promise<ReplicaAuthorityVerdict>;
246
+ /** Check 7: every operation of an authorized batch names its operation writer. */
247
+ export declare function replicaOperationWriterRefusal(operations: readonly {
248
+ revision: {
249
+ writerId: string;
250
+ };
251
+ }[], writers: ReplicaWriters): "writer_mismatch" | undefined;
252
+ //# sourceMappingURL=writer-identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer-identity.d.ts","sourceRoot":"","sources":["../../src/replication/writer-identity.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAOL,KAAK,GAAG,EACT,MAAM,MAAM,CAAC;AACd,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,qBAAqB,gCAAgC,CAAC;AACnE,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,WAAW,CAAC;AAC1D,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,MAAM,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,+BAA+B,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAC/B,SAAS,GAAG,aAAa,GAAG,iBAAiB,GAAG,eAAe,CAAC;AASlE,wEAAwE;AACxE,eAAO,MAAM,uBAAuB;;;;;kBASlC,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,iBAAiB,EACvB,IAAI,EAAE,iBAAiB,GACtB,MAAM,CAkBR;AAED,mFAAmF;AACnF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,iBAAiB,GAAG,cAAc,CAK5E;AAED,oCAAoC;AACpC,wBAAgB,wBAAwB,IAAI,MAAM,CAEjD;AAED;;;;GAIG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;kBAqBtC,CAAC;AACH,MAAM,MA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