@aigne/afs-did-space 1.12.0-beta.5

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 (510) hide show
  1. package/LICENSE.md +26 -0
  2. package/README.md +129 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.108.0/helpers/decorate.cjs +11 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.108.0/helpers/decorate.mjs +10 -0
  5. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  6. package/dist/afs-metadata-context.cjs +20 -0
  7. package/dist/afs-metadata-context.d.cts +21 -0
  8. package/dist/afs-metadata-context.d.cts.map +1 -0
  9. package/dist/afs-metadata-context.d.mts +21 -0
  10. package/dist/afs-metadata-context.d.mts.map +1 -0
  11. package/dist/afs-metadata-context.mjs +18 -0
  12. package/dist/afs-metadata-context.mjs.map +1 -0
  13. package/dist/blocklet-hook.cjs +180 -0
  14. package/dist/blocklet-hook.d.cts +29 -0
  15. package/dist/blocklet-hook.d.cts.map +1 -0
  16. package/dist/blocklet-hook.d.mts +29 -0
  17. package/dist/blocklet-hook.d.mts.map +1 -0
  18. package/dist/blocklet-hook.mjs +178 -0
  19. package/dist/blocklet-hook.mjs.map +1 -0
  20. package/dist/changelog-schema.cjs +603 -0
  21. package/dist/changelog-schema.d.cts +395 -0
  22. package/dist/changelog-schema.d.cts.map +1 -0
  23. package/dist/changelog-schema.d.mts +395 -0
  24. package/dist/changelog-schema.d.mts.map +1 -0
  25. package/dist/changelog-schema.mjs +570 -0
  26. package/dist/changelog-schema.mjs.map +1 -0
  27. package/dist/changelog-write.cjs +80 -0
  28. package/dist/changelog-write.d.cts +70 -0
  29. package/dist/changelog-write.d.cts.map +1 -0
  30. package/dist/changelog-write.d.mts +70 -0
  31. package/dist/changelog-write.d.mts.map +1 -0
  32. package/dist/changelog-write.mjs +77 -0
  33. package/dist/changelog-write.mjs.map +1 -0
  34. package/dist/cid-byte-cache.cjs +126 -0
  35. package/dist/cid-byte-cache.d.cts +46 -0
  36. package/dist/cid-byte-cache.d.cts.map +1 -0
  37. package/dist/cid-byte-cache.d.mts +47 -0
  38. package/dist/cid-byte-cache.d.mts.map +1 -0
  39. package/dist/cid-byte-cache.mjs +125 -0
  40. package/dist/cid-byte-cache.mjs.map +1 -0
  41. package/dist/cid.cjs +68 -0
  42. package/dist/cid.d.cts +22 -0
  43. package/dist/cid.d.cts.map +1 -0
  44. package/dist/cid.d.mts +22 -0
  45. package/dist/cid.d.mts.map +1 -0
  46. package/dist/cid.mjs +65 -0
  47. package/dist/cid.mjs.map +1 -0
  48. package/dist/client.cjs +221 -0
  49. package/dist/client.d.cts +72 -0
  50. package/dist/client.d.cts.map +1 -0
  51. package/dist/client.d.mts +72 -0
  52. package/dist/client.d.mts.map +1 -0
  53. package/dist/client.mjs +220 -0
  54. package/dist/client.mjs.map +1 -0
  55. package/dist/cloudflare.cjs +510 -0
  56. package/dist/cloudflare.d.cts +307 -0
  57. package/dist/cloudflare.d.cts.map +1 -0
  58. package/dist/cloudflare.d.mts +308 -0
  59. package/dist/cloudflare.d.mts.map +1 -0
  60. package/dist/cloudflare.mjs +507 -0
  61. package/dist/cloudflare.mjs.map +1 -0
  62. package/dist/ctime-backfill.cjs +272 -0
  63. package/dist/ctime-backfill.d.cts +169 -0
  64. package/dist/ctime-backfill.d.cts.map +1 -0
  65. package/dist/ctime-backfill.d.mts +169 -0
  66. package/dist/ctime-backfill.d.mts.map +1 -0
  67. package/dist/ctime-backfill.mjs +267 -0
  68. package/dist/ctime-backfill.mjs.map +1 -0
  69. package/dist/d1-gc-queue.cjs +80 -0
  70. package/dist/d1-gc-queue.d.cts +59 -0
  71. package/dist/d1-gc-queue.d.cts.map +1 -0
  72. package/dist/d1-gc-queue.d.mts +59 -0
  73. package/dist/d1-gc-queue.d.mts.map +1 -0
  74. package/dist/d1-gc-queue.mjs +81 -0
  75. package/dist/d1-gc-queue.mjs.map +1 -0
  76. package/dist/d1-resolve-store.cjs +189 -0
  77. package/dist/d1-resolve-store.d.cts +93 -0
  78. package/dist/d1-resolve-store.d.cts.map +1 -0
  79. package/dist/d1-resolve-store.d.mts +93 -0
  80. package/dist/d1-resolve-store.d.mts.map +1 -0
  81. package/dist/d1-resolve-store.mjs +190 -0
  82. package/dist/d1-resolve-store.mjs.map +1 -0
  83. package/dist/d1-schema.cjs +361 -0
  84. package/dist/d1-schema.d.cts +237 -0
  85. package/dist/d1-schema.d.cts.map +1 -0
  86. package/dist/d1-schema.d.mts +237 -0
  87. package/dist/d1-schema.d.mts.map +1 -0
  88. package/dist/d1-schema.mjs +341 -0
  89. package/dist/d1-schema.mjs.map +1 -0
  90. package/dist/d1-share-store.cjs +0 -0
  91. package/dist/d1-share-store.d.cts +53 -0
  92. package/dist/d1-share-store.d.cts.map +1 -0
  93. package/dist/d1-share-store.d.mts +53 -0
  94. package/dist/d1-share-store.d.mts.map +1 -0
  95. package/dist/d1-share-store.mjs +0 -0
  96. package/dist/d1-share-store.mjs.map +1 -0
  97. package/dist/d1-tree-index.cjs +1098 -0
  98. package/dist/d1-tree-index.d.cts +203 -0
  99. package/dist/d1-tree-index.d.cts.map +1 -0
  100. package/dist/d1-tree-index.d.mts +203 -0
  101. package/dist/d1-tree-index.d.mts.map +1 -0
  102. package/dist/d1-tree-index.mjs +1094 -0
  103. package/dist/d1-tree-index.mjs.map +1 -0
  104. package/dist/data-backend.cjs +147 -0
  105. package/dist/data-backend.d.cts +30 -0
  106. package/dist/data-backend.d.cts.map +1 -0
  107. package/dist/data-backend.d.mts +30 -0
  108. package/dist/data-backend.d.mts.map +1 -0
  109. package/dist/data-backend.mjs +148 -0
  110. package/dist/data-backend.mjs.map +1 -0
  111. package/dist/dedup-backfill.cjs +278 -0
  112. package/dist/dedup-backfill.d.cts +165 -0
  113. package/dist/dedup-backfill.d.cts.map +1 -0
  114. package/dist/dedup-backfill.d.mts +165 -0
  115. package/dist/dedup-backfill.d.mts.map +1 -0
  116. package/dist/dedup-backfill.mjs +273 -0
  117. package/dist/dedup-backfill.mjs.map +1 -0
  118. package/dist/did-space-like.d.cts +2 -0
  119. package/dist/did-space-like.d.mts +2 -0
  120. package/dist/did-utils.cjs +44 -0
  121. package/dist/did-utils.d.cts +25 -0
  122. package/dist/did-utils.d.cts.map +1 -0
  123. package/dist/did-utils.d.mts +25 -0
  124. package/dist/did-utils.d.mts.map +1 -0
  125. package/dist/did-utils.mjs +43 -0
  126. package/dist/did-utils.mjs.map +1 -0
  127. package/dist/dirty-path-queue.cjs +31 -0
  128. package/dist/dirty-path-queue.d.cts +104 -0
  129. package/dist/dirty-path-queue.d.cts.map +1 -0
  130. package/dist/dirty-path-queue.d.mts +104 -0
  131. package/dist/dirty-path-queue.d.mts.map +1 -0
  132. package/dist/dirty-path-queue.mjs +31 -0
  133. package/dist/dirty-path-queue.mjs.map +1 -0
  134. package/dist/dirty-path-schema.cjs +142 -0
  135. package/dist/dirty-path-schema.d.cts +90 -0
  136. package/dist/dirty-path-schema.d.cts.map +1 -0
  137. package/dist/dirty-path-schema.d.mts +90 -0
  138. package/dist/dirty-path-schema.d.mts.map +1 -0
  139. package/dist/dirty-path-schema.mjs +136 -0
  140. package/dist/dirty-path-schema.mjs.map +1 -0
  141. package/dist/download-actions.cjs +43 -0
  142. package/dist/download-actions.mjs +40 -0
  143. package/dist/download-actions.mjs.map +1 -0
  144. package/dist/fs-object-store.cjs +153 -0
  145. package/dist/fs-object-store.d.cts +21 -0
  146. package/dist/fs-object-store.d.cts.map +1 -0
  147. package/dist/fs-object-store.d.mts +22 -0
  148. package/dist/fs-object-store.d.mts.map +1 -0
  149. package/dist/fs-object-store.mjs +153 -0
  150. package/dist/fs-object-store.mjs.map +1 -0
  151. package/dist/gc-queue.d.cts +43 -0
  152. package/dist/gc-queue.d.cts.map +1 -0
  153. package/dist/gc-queue.d.mts +43 -0
  154. package/dist/gc-queue.d.mts.map +1 -0
  155. package/dist/index.cjs +2712 -0
  156. package/dist/index.d.cts +504 -0
  157. package/dist/index.d.cts.map +1 -0
  158. package/dist/index.d.mts +505 -0
  159. package/dist/index.d.mts.map +1 -0
  160. package/dist/index.mjs +2537 -0
  161. package/dist/index.mjs.map +1 -0
  162. package/dist/inline-content-migration.cjs +212 -0
  163. package/dist/inline-content-migration.d.cts +110 -0
  164. package/dist/inline-content-migration.d.cts.map +1 -0
  165. package/dist/inline-content-migration.d.mts +111 -0
  166. package/dist/inline-content-migration.d.mts.map +1 -0
  167. package/dist/inline-content-migration.mjs +207 -0
  168. package/dist/inline-content-migration.mjs.map +1 -0
  169. package/dist/inline-content.cjs +145 -0
  170. package/dist/inline-content.d.cts +98 -0
  171. package/dist/inline-content.d.cts.map +1 -0
  172. package/dist/inline-content.d.mts +98 -0
  173. package/dist/inline-content.d.mts.map +1 -0
  174. package/dist/inline-content.mjs +137 -0
  175. package/dist/inline-content.mjs.map +1 -0
  176. package/dist/local-changelog.cjs +241 -0
  177. package/dist/local-changelog.d.cts +119 -0
  178. package/dist/local-changelog.d.cts.map +1 -0
  179. package/dist/local-changelog.d.mts +119 -0
  180. package/dist/local-changelog.d.mts.map +1 -0
  181. package/dist/local-changelog.mjs +240 -0
  182. package/dist/local-changelog.mjs.map +1 -0
  183. package/dist/local.cjs +435 -0
  184. package/dist/local.d.cts +254 -0
  185. package/dist/local.d.cts.map +1 -0
  186. package/dist/local.d.mts +254 -0
  187. package/dist/local.d.mts.map +1 -0
  188. package/dist/local.mjs +427 -0
  189. package/dist/local.mjs.map +1 -0
  190. package/dist/memory-gc-queue.cjs +36 -0
  191. package/dist/memory-gc-queue.d.cts +22 -0
  192. package/dist/memory-gc-queue.d.cts.map +1 -0
  193. package/dist/memory-gc-queue.d.mts +22 -0
  194. package/dist/memory-gc-queue.d.mts.map +1 -0
  195. package/dist/memory-gc-queue.mjs +36 -0
  196. package/dist/memory-gc-queue.mjs.map +1 -0
  197. package/dist/memory-tree-index.cjs +734 -0
  198. package/dist/memory-tree-index.d.cts +159 -0
  199. package/dist/memory-tree-index.d.cts.map +1 -0
  200. package/dist/memory-tree-index.d.mts +159 -0
  201. package/dist/memory-tree-index.d.mts.map +1 -0
  202. package/dist/memory-tree-index.mjs +735 -0
  203. package/dist/memory-tree-index.mjs.map +1 -0
  204. package/dist/metadata-db.cjs +562 -0
  205. package/dist/metadata-db.d.cts +102 -0
  206. package/dist/metadata-db.d.cts.map +1 -0
  207. package/dist/metadata-db.d.mts +102 -0
  208. package/dist/metadata-db.d.mts.map +1 -0
  209. package/dist/metadata-db.mjs +562 -0
  210. package/dist/metadata-db.mjs.map +1 -0
  211. package/dist/mime-utils.cjs +2 -0
  212. package/dist/mime-utils.d.cts +2 -0
  213. package/dist/mime-utils.d.mts +2 -0
  214. package/dist/mime-utils.mjs +3 -0
  215. package/dist/object-key.cjs +41 -0
  216. package/dist/object-key.d.cts +25 -0
  217. package/dist/object-key.d.cts.map +1 -0
  218. package/dist/object-key.d.mts +25 -0
  219. package/dist/object-key.d.mts.map +1 -0
  220. package/dist/object-key.mjs +40 -0
  221. package/dist/object-key.mjs.map +1 -0
  222. package/dist/packages/session/dist/index.cjs +788 -0
  223. package/dist/packages/session/dist/index.mjs +782 -0
  224. package/dist/packages/session/dist/index.mjs.map +1 -0
  225. package/dist/platform/r2/dist/types.d.cts +49 -0
  226. package/dist/platform/r2/dist/types.d.cts.map +1 -0
  227. package/dist/prefix-range.cjs +33 -0
  228. package/dist/prefix-range.d.cts +29 -0
  229. package/dist/prefix-range.d.cts.map +1 -0
  230. package/dist/prefix-range.d.mts +29 -0
  231. package/dist/prefix-range.d.mts.map +1 -0
  232. package/dist/prefix-range.mjs +33 -0
  233. package/dist/prefix-range.mjs.map +1 -0
  234. package/dist/prefixed-tree-index.cjs +238 -0
  235. package/dist/prefixed-tree-index.d.cts +85 -0
  236. package/dist/prefixed-tree-index.d.cts.map +1 -0
  237. package/dist/prefixed-tree-index.d.mts +85 -0
  238. package/dist/prefixed-tree-index.d.mts.map +1 -0
  239. package/dist/prefixed-tree-index.mjs +239 -0
  240. package/dist/prefixed-tree-index.mjs.map +1 -0
  241. package/dist/presign-signer.cjs +7 -0
  242. package/dist/presign-signer.d.cts +99 -0
  243. package/dist/presign-signer.d.cts.map +1 -0
  244. package/dist/presign-signer.d.mts +99 -0
  245. package/dist/presign-signer.d.mts.map +1 -0
  246. package/dist/presign-signer.mjs +7 -0
  247. package/dist/presign-signer.mjs.map +1 -0
  248. package/dist/providers/platform/r2/dist/index.d.mts +3 -0
  249. package/dist/providers/platform/r2/dist/types.d.mts +49 -0
  250. package/dist/providers/platform/r2/dist/types.d.mts.map +1 -0
  251. package/dist/reconcile.cjs +184 -0
  252. package/dist/reconcile.d.cts +26 -0
  253. package/dist/reconcile.d.cts.map +1 -0
  254. package/dist/reconcile.d.mts +26 -0
  255. package/dist/reconcile.d.mts.map +1 -0
  256. package/dist/reconcile.mjs +184 -0
  257. package/dist/reconcile.mjs.map +1 -0
  258. package/dist/reference-check.cjs +49 -0
  259. package/dist/reference-check.d.cts +10 -0
  260. package/dist/reference-check.d.cts.map +1 -0
  261. package/dist/reference-check.d.mts +10 -0
  262. package/dist/reference-check.d.mts.map +1 -0
  263. package/dist/reference-check.mjs +48 -0
  264. package/dist/reference-check.mjs.map +1 -0
  265. package/dist/remote-afs.cjs +681 -0
  266. package/dist/remote-afs.d.cts +236 -0
  267. package/dist/remote-afs.d.cts.map +1 -0
  268. package/dist/remote-afs.d.mts +236 -0
  269. package/dist/remote-afs.d.mts.map +1 -0
  270. package/dist/remote-afs.mjs +676 -0
  271. package/dist/remote-afs.mjs.map +1 -0
  272. package/dist/rename-guard.cjs +18 -0
  273. package/dist/rename-guard.mjs +18 -0
  274. package/dist/rename-guard.mjs.map +1 -0
  275. package/dist/resolve.cjs +260 -0
  276. package/dist/resolve.d.cts +113 -0
  277. package/dist/resolve.d.cts.map +1 -0
  278. package/dist/resolve.d.mts +113 -0
  279. package/dist/resolve.d.mts.map +1 -0
  280. package/dist/resolve.mjs +260 -0
  281. package/dist/resolve.mjs.map +1 -0
  282. package/dist/rsync-content.cjs +33 -0
  283. package/dist/rsync-content.mjs +33 -0
  284. package/dist/rsync-content.mjs.map +1 -0
  285. package/dist/rsync.cjs +400 -0
  286. package/dist/rsync.d.cts +157 -0
  287. package/dist/rsync.d.cts.map +1 -0
  288. package/dist/rsync.d.mts +157 -0
  289. package/dist/rsync.d.mts.map +1 -0
  290. package/dist/rsync.mjs +397 -0
  291. package/dist/rsync.mjs.map +1 -0
  292. package/dist/run-gc.cjs +57 -0
  293. package/dist/run-gc.d.cts +40 -0
  294. package/dist/run-gc.d.cts.map +1 -0
  295. package/dist/run-gc.d.mts +41 -0
  296. package/dist/run-gc.d.mts.map +1 -0
  297. package/dist/run-gc.mjs +57 -0
  298. package/dist/run-gc.mjs.map +1 -0
  299. package/dist/scope-id.cjs +70 -0
  300. package/dist/scope-id.d.cts +35 -0
  301. package/dist/scope-id.d.cts.map +1 -0
  302. package/dist/scope-id.d.mts +35 -0
  303. package/dist/scope-id.d.mts.map +1 -0
  304. package/dist/scope-id.mjs +68 -0
  305. package/dist/scope-id.mjs.map +1 -0
  306. package/dist/scope-migration-node.cjs +172 -0
  307. package/dist/scope-migration-node.d.cts +44 -0
  308. package/dist/scope-migration-node.d.cts.map +1 -0
  309. package/dist/scope-migration-node.d.mts +44 -0
  310. package/dist/scope-migration-node.d.mts.map +1 -0
  311. package/dist/scope-migration-node.mjs +171 -0
  312. package/dist/scope-migration-node.mjs.map +1 -0
  313. package/dist/scope-migration.cjs +155 -0
  314. package/dist/scope-migration.d.cts +65 -0
  315. package/dist/scope-migration.d.cts.map +1 -0
  316. package/dist/scope-migration.d.mts +65 -0
  317. package/dist/scope-migration.d.mts.map +1 -0
  318. package/dist/scope-migration.mjs +154 -0
  319. package/dist/scope-migration.mjs.map +1 -0
  320. package/dist/share-declaration.cjs +225 -0
  321. package/dist/share-declaration.d.cts +30 -0
  322. package/dist/share-declaration.d.cts.map +1 -0
  323. package/dist/share-declaration.d.mts +32 -0
  324. package/dist/share-declaration.d.mts.map +1 -0
  325. package/dist/share-declaration.mjs +221 -0
  326. package/dist/share-declaration.mjs.map +1 -0
  327. package/dist/share-hook.cjs +63 -0
  328. package/dist/share-hook.mjs +62 -0
  329. package/dist/share-hook.mjs.map +1 -0
  330. package/dist/share-resolve.cjs +176 -0
  331. package/dist/share-resolve.d.cts +36 -0
  332. package/dist/share-resolve.d.cts.map +1 -0
  333. package/dist/share-resolve.d.mts +36 -0
  334. package/dist/share-resolve.d.mts.map +1 -0
  335. package/dist/share-resolve.mjs +177 -0
  336. package/dist/share-resolve.mjs.map +1 -0
  337. package/dist/share-serve.cjs +145 -0
  338. package/dist/share-serve.d.cts +30 -0
  339. package/dist/share-serve.d.cts.map +1 -0
  340. package/dist/share-serve.d.mts +30 -0
  341. package/dist/share-serve.d.mts.map +1 -0
  342. package/dist/share-serve.mjs +144 -0
  343. package/dist/share-serve.mjs.map +1 -0
  344. package/dist/share-store.cjs +25 -0
  345. package/dist/share-store.d.cts +65 -0
  346. package/dist/share-store.d.cts.map +1 -0
  347. package/dist/share-store.d.mts +65 -0
  348. package/dist/share-store.d.mts.map +1 -0
  349. package/dist/share-store.mjs +25 -0
  350. package/dist/share-store.mjs.map +1 -0
  351. package/dist/share-virtual-path.cjs +102 -0
  352. package/dist/share-virtual-path.mjs +101 -0
  353. package/dist/share-virtual-path.mjs.map +1 -0
  354. package/dist/space-resolver.cjs +54 -0
  355. package/dist/space-resolver.d.cts +34 -0
  356. package/dist/space-resolver.d.cts.map +1 -0
  357. package/dist/space-resolver.d.mts +34 -0
  358. package/dist/space-resolver.d.mts.map +1 -0
  359. package/dist/space-resolver.mjs +55 -0
  360. package/dist/space-resolver.mjs.map +1 -0
  361. package/dist/sqlite-gc-queue.cjs +51 -0
  362. package/dist/sqlite-gc-queue.d.cts +22 -0
  363. package/dist/sqlite-gc-queue.d.cts.map +1 -0
  364. package/dist/sqlite-gc-queue.d.mts +22 -0
  365. package/dist/sqlite-gc-queue.d.mts.map +1 -0
  366. package/dist/sqlite-gc-queue.mjs +52 -0
  367. package/dist/sqlite-gc-queue.mjs.map +1 -0
  368. package/dist/sqlite-resolve-store.cjs +163 -0
  369. package/dist/sqlite-resolve-store.d.cts +50 -0
  370. package/dist/sqlite-resolve-store.d.cts.map +1 -0
  371. package/dist/sqlite-resolve-store.d.mts +50 -0
  372. package/dist/sqlite-resolve-store.d.mts.map +1 -0
  373. package/dist/sqlite-resolve-store.mjs +164 -0
  374. package/dist/sqlite-resolve-store.mjs.map +1 -0
  375. package/dist/sqlite-share-store.cjs +157 -0
  376. package/dist/sqlite-share-store.d.cts +31 -0
  377. package/dist/sqlite-share-store.d.cts.map +1 -0
  378. package/dist/sqlite-share-store.d.mts +31 -0
  379. package/dist/sqlite-share-store.d.mts.map +1 -0
  380. package/dist/sqlite-share-store.mjs +157 -0
  381. package/dist/sqlite-share-store.mjs.map +1 -0
  382. package/dist/sqlite-tree-index.cjs +901 -0
  383. package/dist/sqlite-tree-index.d.cts +107 -0
  384. package/dist/sqlite-tree-index.d.cts.map +1 -0
  385. package/dist/sqlite-tree-index.d.mts +107 -0
  386. package/dist/sqlite-tree-index.d.mts.map +1 -0
  387. package/dist/sqlite-tree-index.mjs +902 -0
  388. package/dist/sqlite-tree-index.mjs.map +1 -0
  389. package/dist/sync-engine.cjs +1324 -0
  390. package/dist/sync-engine.d.cts +473 -0
  391. package/dist/sync-engine.d.cts.map +1 -0
  392. package/dist/sync-engine.d.mts +473 -0
  393. package/dist/sync-engine.d.mts.map +1 -0
  394. package/dist/sync-engine.mjs +1315 -0
  395. package/dist/sync-engine.mjs.map +1 -0
  396. package/dist/sync-state.cjs +303 -0
  397. package/dist/sync-state.d.cts +224 -0
  398. package/dist/sync-state.d.cts.map +1 -0
  399. package/dist/sync-state.d.mts +224 -0
  400. package/dist/sync-state.d.mts.map +1 -0
  401. package/dist/sync-state.mjs +297 -0
  402. package/dist/sync-state.mjs.map +1 -0
  403. package/dist/timestamp.cjs +92 -0
  404. package/dist/timestamp.mjs +91 -0
  405. package/dist/timestamp.mjs.map +1 -0
  406. package/dist/transports/http.cjs +54 -0
  407. package/dist/transports/http.d.cts +26 -0
  408. package/dist/transports/http.d.cts.map +1 -0
  409. package/dist/transports/http.d.mts +26 -0
  410. package/dist/transports/http.d.mts.map +1 -0
  411. package/dist/transports/http.mjs +54 -0
  412. package/dist/transports/http.mjs.map +1 -0
  413. package/dist/transports/static.cjs +55 -0
  414. package/dist/transports/static.d.cts +28 -0
  415. package/dist/transports/static.d.cts.map +1 -0
  416. package/dist/transports/static.d.mts +28 -0
  417. package/dist/transports/static.d.mts.map +1 -0
  418. package/dist/transports/static.mjs +55 -0
  419. package/dist/transports/static.mjs.map +1 -0
  420. package/dist/transports/types.cjs +13 -0
  421. package/dist/transports/types.d.cts +72 -0
  422. package/dist/transports/types.d.cts.map +1 -0
  423. package/dist/transports/types.d.mts +72 -0
  424. package/dist/transports/types.d.mts.map +1 -0
  425. package/dist/transports/types.mjs +13 -0
  426. package/dist/transports/types.mjs.map +1 -0
  427. package/dist/transports/ws.cjs +207 -0
  428. package/dist/transports/ws.d.cts +47 -0
  429. package/dist/transports/ws.d.cts.map +1 -0
  430. package/dist/transports/ws.d.mts +47 -0
  431. package/dist/transports/ws.d.mts.map +1 -0
  432. package/dist/transports/ws.mjs +206 -0
  433. package/dist/transports/ws.mjs.map +1 -0
  434. package/dist/tree-index.cjs +333 -0
  435. package/dist/tree-index.d.cts +524 -0
  436. package/dist/tree-index.d.cts.map +1 -0
  437. package/dist/tree-index.d.mts +524 -0
  438. package/dist/tree-index.d.mts.map +1 -0
  439. package/dist/tree-index.mjs +322 -0
  440. package/dist/tree-index.mjs.map +1 -0
  441. package/dist/tree-query.cjs +655 -0
  442. package/dist/tree-query.d.cts +70 -0
  443. package/dist/tree-query.d.cts.map +1 -0
  444. package/dist/tree-query.d.mts +70 -0
  445. package/dist/tree-query.d.mts.map +1 -0
  446. package/dist/tree-query.mjs +648 -0
  447. package/dist/tree-query.mjs.map +1 -0
  448. package/dist/upload-actions.cjs +97 -0
  449. package/dist/upload-actions.d.cts +19 -0
  450. package/dist/upload-actions.d.cts.map +1 -0
  451. package/dist/upload-actions.d.mts +21 -0
  452. package/dist/upload-actions.d.mts.map +1 -0
  453. package/dist/upload-actions.mjs +90 -0
  454. package/dist/upload-actions.mjs.map +1 -0
  455. package/dist/upload-session-store.cjs +185 -0
  456. package/dist/upload-session-store.d.cts +99 -0
  457. package/dist/upload-session-store.d.cts.map +1 -0
  458. package/dist/upload-session-store.d.mts +99 -0
  459. package/dist/upload-session-store.d.mts.map +1 -0
  460. package/dist/upload-session-store.mjs +184 -0
  461. package/dist/upload-session-store.mjs.map +1 -0
  462. package/dist/url-normalize.cjs +61 -0
  463. package/dist/url-normalize.d.cts +33 -0
  464. package/dist/url-normalize.d.cts.map +1 -0
  465. package/dist/url-normalize.d.mts +33 -0
  466. package/dist/url-normalize.d.mts.map +1 -0
  467. package/dist/url-normalize.mjs +61 -0
  468. package/dist/url-normalize.mjs.map +1 -0
  469. package/dist/versioned-content-backends.cjs +155 -0
  470. package/dist/versioned-content-backends.d.cts +49 -0
  471. package/dist/versioned-content-backends.d.cts.map +1 -0
  472. package/dist/versioned-content-backends.d.mts +49 -0
  473. package/dist/versioned-content-backends.d.mts.map +1 -0
  474. package/dist/versioned-content-backends.mjs +154 -0
  475. package/dist/versioned-content-backends.mjs.map +1 -0
  476. package/dist/versioned-content-index.cjs +102 -0
  477. package/dist/versioned-content-index.d.cts +46 -0
  478. package/dist/versioned-content-index.d.cts.map +1 -0
  479. package/dist/versioned-content-index.d.mts +46 -0
  480. package/dist/versioned-content-index.d.mts.map +1 -0
  481. package/dist/versioned-content-index.mjs +103 -0
  482. package/dist/versioned-content-index.mjs.map +1 -0
  483. package/dist/versioned-content-store.cjs +121 -0
  484. package/dist/versioned-content-store.d.cts +90 -0
  485. package/dist/versioned-content-store.d.cts.map +1 -0
  486. package/dist/versioned-content-store.d.mts +90 -0
  487. package/dist/versioned-content-store.d.mts.map +1 -0
  488. package/dist/versioned-content-store.mjs +122 -0
  489. package/dist/versioned-content-store.mjs.map +1 -0
  490. package/dist/versioned-scope.cjs +39 -0
  491. package/dist/versioned-scope.d.cts +57 -0
  492. package/dist/versioned-scope.d.cts.map +1 -0
  493. package/dist/versioned-scope.d.mts +57 -0
  494. package/dist/versioned-scope.d.mts.map +1 -0
  495. package/dist/versioned-scope.mjs +37 -0
  496. package/dist/versioned-scope.mjs.map +1 -0
  497. package/migrations/0001_tree_entries.sql +17 -0
  498. package/migrations/0002_resolve_entries.sql +7 -0
  499. package/migrations/0003_entries_v2.sql +38 -0
  500. package/migrations/0004_gc_queue.sql +5 -0
  501. package/migrations/0006_resolve_enhance.sql +14 -0
  502. package/migrations/0007_resolve_created_at.sql +10 -0
  503. package/migrations/0008_changelog.sql +34 -0
  504. package/migrations/0009_device_sync_state.sql +29 -0
  505. package/migrations/0010_scope_meta.sql +33 -0
  506. package/migrations/0011_shares.sql +25 -0
  507. package/migrations/0012_scope_meta_file_count.sql +41 -0
  508. package/migrations/0013_scope_meta_total_bytes.sql +47 -0
  509. package/migrations/0014_rename_tables.sql +62 -0
  510. package/package.json +102 -0
@@ -0,0 +1,307 @@
1
+ import { ObjectStore } from "./platform/r2/dist/types.cjs";
2
+ import { D1GCQueue } from "./d1-gc-queue.cjs";
3
+ import { DIDSpaceLike as DIDSpaceLike$1, InstanceSpaceOptions } from "./did-space-like.cjs";
4
+ import { PresignSigner } from "./presign-signer.cjs";
5
+ import { DIDSpaceResolver } from "./resolve.cjs";
6
+ import { PutOpts } from "./tree-index.cjs";
7
+ import { ShareResolver } from "./share-resolve.cjs";
8
+ import { normalizeId, validateId } from "./did-utils.cjs";
9
+ import { AFS, AFSAccessMode } from "@aigne/afs";
10
+
11
+ //#region src/cloudflare.d.ts
12
+ interface CloudflareDIDSpaceOptions {
13
+ /** Owner DID of this space */
14
+ userDid: string;
15
+ /** Shared R2 object store (content-addressed, shared across all apps) */
16
+ objectStore: ObjectStore;
17
+ /** D1 database for tree index + resolve entries */
18
+ indexDb: D1Database;
19
+ /**
20
+ * Optional per-deployment HMAC secret for scope de-identification (README §4.4).
21
+ * When set, all D1 storage keys (`entries.scope` / `changelog.scope` /
22
+ * `shares.owner_did`) become `deriveScope(userDid, secret)` — an opaque HMAC —
23
+ * instead of the plaintext DID. When absent, scope stays plaintext (de-id off,
24
+ * back-compat). Injected along `objectStore` / `indexDb` by the resolver.
25
+ */
26
+ scopeHmacSecret?: Uint8Array;
27
+ /** Optional: ShareResolver for .share reconcile hook (Phase 0.4) */
28
+ shareResolver?: ShareResolver;
29
+ /**
30
+ * Route READ-serving D1 queries through a D1 Session
31
+ * (`withSession("first-unconstrained")`) so they can be served by the
32
+ * nearest read replica. Requires `read_replication: { mode: "auto" }` on the
33
+ * D1 database (a DB-level setting, NOT wrangler.toml) — otherwise every query
34
+ * stays on primary regardless of this flag.
35
+ *
36
+ * Only the read paths honor this (getInstanceSpace / getConfigSpace /
37
+ * getUserSpace / listApps / resolver). The write + GC paths (internalWrite /
38
+ * internalDelete / gcQueue) ALWAYS use the primary: they read the old entry to
39
+ * drive GC, and a stale replica read there would compute the wrong `oldCid`.
40
+ *
41
+ * Consistency note: each tree-index opens its own session with no bookmark
42
+ * threading, so this is "first-unconstrained" (potentially-stale) reads.
43
+ * Read-your-write holds WITHIN a single mounted AFS (same session) but NOT
44
+ * across requests. Default false (last-write-wins on primary, back-compat).
45
+ */
46
+ useReplica?: boolean;
47
+ /**
48
+ * Object-store presigned-PUT signer (DID Space upload plane, §15 decision 7).
49
+ * Injected by the CF runtime when R2 signer credentials are configured;
50
+ * `prepare-upload` (P2) mints exact-key checksum-pinned grants through it.
51
+ * Absent → no grant capability (clients fall back to batchWrite). Node never
52
+ * injects one (decision 8, fallback-only).
53
+ */
54
+ signer?: PresignSigner;
55
+ /**
56
+ * upload-limits Phase 5 per-scope byte quota (bytes). 0 / unset = OFF (the
57
+ * opt-in default). Injected by the CF runtime from `resolveUploadLimits`'s
58
+ * `maxBytesPerScope`; enforced on every write through this space's tree index.
59
+ */
60
+ maxBytesPerScope?: number;
61
+ }
62
+ declare class CloudflareDIDSpace implements DIDSpaceLike$1 {
63
+ /** Real normalizeId(DID) — identity, returned to callers (NOT a storage key). */
64
+ private readonly userDid;
65
+ /**
66
+ * Storage scope — `deriveScope(userDid, secret)` when de-id is on, else the
67
+ * plaintext `userDid`. Every D1 storage/query key uses this, never `userDid`.
68
+ * Named `_scope` to avoid colliding with the `get scope()` accessor (README §4.1).
69
+ */
70
+ private readonly _scope;
71
+ private readonly objectStore;
72
+ private readonly indexDb;
73
+ private _resolver?;
74
+ /** Optional ShareResolver for .share reconcile hook (Phase 0.4) */
75
+ private readonly shareResolver?;
76
+ /** Read replica opt-in for read-serving paths only — see options doc. */
77
+ private readonly useReplica;
78
+ /** upload-limits Phase 5 per-scope byte quota (0 = off, the opt-in default). */
79
+ private readonly maxBytesPerScope;
80
+ /**
81
+ * Instance space cache keyed by (role, useReplica) — same shape as `local.ts`
82
+ * `instanceSpaces`. Without it, `getInstanceSpace` returns a fresh `AFS`
83
+ * (and fresh `EventBus`) every call, so propBind subscribe (registered on
84
+ * AFS_A at session start) and the agent's subsequent write (executing on
85
+ * AFS_B for that exec) cross different buses — the write's `afs:write`
86
+ * event never reaches the subscriber, so the live patch silently drops and
87
+ * the user only sees the new value after a manual page reload (Layer 2
88
+ * staleness on staging). Bounded by the lifetime of this DID-Space (per
89
+ * caller in the resolver), the same memory budget the resolver already
90
+ * spends on `spaces`.
91
+ */
92
+ private readonly instanceSpaces;
93
+ /**
94
+ * User-space cache keyed by (accessMode, useReplica) — the getUserSpace
95
+ * counterpart of {@link instanceSpaces}. Without it, every `getUserSpace()`
96
+ * builds a fresh `AFS` and re-runs `AFS.mount()`'s async provider health check
97
+ * (a root `stat` → `countChildren` + list). Blocklet serve calls getUserSpace
98
+ * once PER stage (reader / afsRoot), so a cold page paid that root enumeration
99
+ * 3× (issue #808 #4). Caching the handle reuses the mounted provider; data
100
+ * reads stay fresh (path→cid D1 lookups are never cached), so zero staleness.
101
+ */
102
+ private readonly userSpaces;
103
+ /** Shared GC queue instance — created once per CloudflareDIDSpace instance */
104
+ readonly gcQueue: D1GCQueue;
105
+ /** Injected presigned-PUT signer (upload plane). Undefined → no grant capability. */
106
+ private readonly signer?;
107
+ constructor(options: CloudflareDIDSpaceOptions);
108
+ /**
109
+ * Construct a D1TreeIndex for this scope with the per-scope byte quota
110
+ * (upload-limits Phase 5) always injected — so every write path enforces it
111
+ * uniformly without each call site remembering to thread it. 0 = quota off.
112
+ */
113
+ private makeTreeIndex;
114
+ /**
115
+ * The injected presigned-PUT signer, or undefined when no R2 signer
116
+ * credentials are configured. The seam through which `prepare-upload` (P2)
117
+ * mints upload grants; also the capability signal clients use to decide
118
+ * grant-path vs batchWrite fallback (§15 decision 7/8).
119
+ */
120
+ get presignSigner(): PresignSigner | undefined;
121
+ /**
122
+ * Upload-plane deps for the user-facing `DIDSpaceProvider` (design §7): the
123
+ * injected signer (CF mints grants; absent → fallback), a D1-backed session
124
+ * store, and the de-identified storage scope written into `upload_sessions`.
125
+ * Only the user space gets these — `/instance` (installer) + config don't.
126
+ */
127
+ private uploadDeps;
128
+ /**
129
+ * Get an isolated AFS instance for a blocklet instance under this DID Space,
130
+ * scoped by role (system = installer-side data, user = caller-side data).
131
+ *
132
+ * Layout (PrefixedTreeIndex prefix relative to `entries.scope = userDid`):
133
+ * role:"system" → blocklets/{instanceDid}/system/ (content tree, mounted at `/`)
134
+ * role:"user" → blocklets/{instanceDid}/user/ (content tree, mounted at `/`)
135
+ * config → blocklets/{instanceDid}/config/ (sibling fragment, getConfigSpace)
136
+ *
137
+ * /files-prefix-removal: content tree is the role root (no `files/` wrapper);
138
+ * config is a sibling fragment (invisible to `/instance`); vault removed.
139
+ *
140
+ * did-space-composition Phase 2 (symmetric with the local backend): the user
141
+ * fragment is a SINGLE `user` subtree. Per-user isolation comes from scope =
142
+ * caller's userDid (the resolver hands back a CloudflareDIDSpace scoped to the
143
+ * caller), so a `users/{userDid}` path segment would be redundant. `userDid`
144
+ * is @deprecated for this call and ignored for the path.
145
+ *
146
+ * Cached per (instanceDid, role, useReplica) — first caller's accessMode
147
+ * wins for that triple (mirrors local.ts). See `instanceSpaces` for the
148
+ * live-update rationale.
149
+ */
150
+ getInstanceSpace(opts: InstanceSpaceOptions): Promise<AFS>;
151
+ /**
152
+ * Runtime-internal config fragment (`blocklets/<i>/config/`, mounted at
153
+ * `/`). Mirrors local `getConfigSpace`. Invisible to `/instance`; holds
154
+ * per-instance machine state like `mounts.toml`.
155
+ */
156
+ getConfigSpace(instanceDid: string): Promise<AFS>;
157
+ /**
158
+ * List all instance DIDs that have storage in this user's space.
159
+ *
160
+ * Enumerates entries under the `blocklets/<instanceDid>/...` prefix and
161
+ * returns the distinct instance-DID segment. This mirrors the local
162
+ * backend's `listApps`, which enumerates `{userDir}/blocklets/*`. Legacy
163
+ * top-level `getAppSpace` segments are NOT enumerated — that layout is
164
+ * deprecated and removed in P4.
165
+ */
166
+ listApps(): Promise<string[]>;
167
+ /**
168
+ * Contract alias (分叉 A, observability Phase 2) for the whole-space root.
169
+ * Delegates to {@link getUserSpace}; satisfies `DIDSpaceLike.getSpaceRoot`
170
+ * without renaming the existing CF method. Defaults readonly via getUserSpace.
171
+ */
172
+ getSpaceRoot(options?: {
173
+ accessMode?: AFSAccessMode;
174
+ }): Promise<AFS>;
175
+ /**
176
+ * Get an AFS instance scoped to the user's entire DID Space.
177
+ * No appDid sub-partitioning.
178
+ */
179
+ getUserSpace(options?: {
180
+ accessMode?: AFSAccessMode;
181
+ }): Promise<AFS>;
182
+ get resolver(): DIDSpaceResolver;
183
+ /**
184
+ * Expose the underlying storage scope — used by worker handlers for
185
+ * cid-permission queries. MUST return the derived scope (not the plaintext
186
+ * DID) so the worker's `entries.scope` lookups match what was written.
187
+ */
188
+ get scope(): string;
189
+ /**
190
+ * Direct write path for the Worker HTTP handler (Task 2.4b).
191
+ *
192
+ * Bypasses the generic `afs.write()` path because `AFSWriteEntryPayload` has
193
+ * no `deviceId`/`skipChangelog` field — the `PutOpts` cannot be smuggled
194
+ * through the public AFS API. The Worker handler therefore constructs a
195
+ * `CloudflareDIDSpace` and calls this method directly, passing the per-
196
+ * request `deviceId` read from the `X-Device-Id` header.
197
+ *
198
+ * Semantics mirror `DIDSpaceProvider.writeHandler`:
199
+ * 1. Compute the content-addressed CID from the payload bytes.
200
+ * 2. R2 put `objects/{cid}` if not already stored (head-check for dedup).
201
+ * 3. `treeIndex.put` — atomic `entries` + `changelog` write (Task 2.4a).
202
+ * 4. Enqueue the previous CID (if any) onto the GC queue for deferred
203
+ * cleanup. Enqueuing an overwritten CID is a no-op if the CID is still
204
+ * referenced by another row (the GC job's reference check handles it).
205
+ *
206
+ * Path conventions:
207
+ * - `afsPath` is an AFS-style path WITH leading slash (e.g. `/foo.json`
208
+ * or `/blocklets/z1abc/index.html`).
209
+ * - The leading slash is stripped before `treeIndex.put`; the remainder is
210
+ * stored verbatim under `entries.scope = this._scope` (the derived storage
211
+ * scope when de-id is on, else the plaintext DID). This matches the
212
+ * `getUserSpace()` layout (no appDid sub-partition) that blocklet publish
213
+ * and general user-space CRUD share.
214
+ *
215
+ * Returns `{ cid, oldCid }`. `oldCid` is present only when an existing row
216
+ * was overwritten; the caller can treat its presence as "something was
217
+ * replaced" for change-tracking. `seq` is not returned — Task 2.4a's
218
+ * `treeIndex.put` does not expose the changelog's AUTOINCREMENT `seq`, and
219
+ * adding a separate SELECT round trip here is wasted work for the current
220
+ * sync path (which only cares about cid + oldCid).
221
+ *
222
+ * No event dispatch is performed (Decision 3A round 5): CloudflareDIDSpace
223
+ * has no event bus reference, the Worker runtime is request/response with
224
+ * no long-lived subscriber, and the sync protocol polls `changelog` rows
225
+ * by `seq` rather than reacting to transient event fan-out.
226
+ */
227
+ internalWrite(afsPath: string, content: string | Uint8Array | ArrayBuffer, opts: PutOpts): Promise<{
228
+ cid: string;
229
+ oldCid?: string;
230
+ }>;
231
+ /**
232
+ * Read the current entry's cid + mtime + last-write deviceId for an
233
+ * If-Match precondition check (Task 3.3).
234
+ *
235
+ * Used by `_createSpaceHandler` BEFORE issuing a write when the client
236
+ * sends `If-Match: <cid>` for optimistic concurrency control. The
237
+ * handler compares the returned `cid` to the header value and returns
238
+ * 409 (with the full snapshot below) on mismatch, or 412 if the row
239
+ * doesn't exist (first-create with If-Match).
240
+ *
241
+ * The query joins `entries` (cid + mtime authoritative) with the most
242
+ * recent put row in `changelog` (device_id of last writer). Both
243
+ * indices used (`PRIMARY KEY (scope, path)` on entries +
244
+ * `idx_changelog_scope_seq` on changelog) keep this O(log n).
245
+ *
246
+ * `deviceId` is `null` when the entry was written via the blocklet
247
+ * exemption path (skipChangelog = true) — there's no changelog row to
248
+ * read the device id from. The handler exposes `null` to clients in
249
+ * the 409 body.
250
+ *
251
+ * Returns `null` when no entry exists at this path.
252
+ */
253
+ getCurrentEntry(afsPath: string): Promise<{
254
+ cid: string;
255
+ mtime: number;
256
+ deviceId: string | null;
257
+ } | null>;
258
+ /**
259
+ * Read the changelog `seq` of the most recent write by `(scope, path,
260
+ * deviceId)` (Task 3.3).
261
+ *
262
+ * The Worker handler calls this AFTER `internalWrite/internalDelete`
263
+ * to recover the seq of the row just inserted, so the PUT/DELETE
264
+ * response can echo `{cid, seq}` for the client.
265
+ *
266
+ * The triple WHERE clause (scope + path + device_id) is the safety
267
+ * mechanism for concurrent writers: each writer is guaranteed to have
268
+ * a unique `device_id` (validated by the Worker handler's strict
269
+ * format regex BEFORE we get here), so even if two PUTs on the same
270
+ * path race, each call's getLastSeq sees ONLY its own write — never
271
+ * the other writer's.
272
+ *
273
+ * Returns `0` when no row matches (impossible if called immediately
274
+ * after a successful internalWrite, but defensive against
275
+ * skipChangelog = true callers — blocklet exempt PUTs have no
276
+ * changelog row at all and the handler should NOT call this for them).
277
+ */
278
+ getLastSeq(afsPath: string, deviceId: string): Promise<number>;
279
+ /**
280
+ * Direct delete path for the Worker HTTP handler (Task 2.4b).
281
+ *
282
+ * Semantics mirror `DIDSpaceProvider.deleteHandler`:
283
+ * 1. Read the current entry (for GC enqueue of the soon-to-be-orphaned CID).
284
+ * 2. `treeIndex.delete` — atomic `entries` delete + `changelog` delete row
285
+ * (Task 2.4a's `INSERT INTO ds_changelog SELECT ... FROM ds_entries` pattern
286
+ * captures the old CID in-batch).
287
+ * 3. Enqueue the old CID for GC. Enqueueing is safe even under races —
288
+ * the GC job's `isReferenced` check skips CIDs still referenced by
289
+ * other rows.
290
+ *
291
+ * Returns an empty object (no `seq` for the same reason as `internalWrite`).
292
+ * Callers that need to know whether anything was actually deleted can rely
293
+ * on the absence of an `AFSNotFoundError` — Task 2.4b's handler converts
294
+ * that to a 404 response.
295
+ */
296
+ internalDelete(afsPath: string, opts: PutOpts): Promise<{
297
+ deleted: boolean;
298
+ }>;
299
+ /**
300
+ * Clean up resources. Drops the cached instance-space map so retained AFS
301
+ * instances are GC-eligible alongside this DID-Space.
302
+ */
303
+ close(): void;
304
+ }
305
+ //#endregion
306
+ export { CloudflareDIDSpace, CloudflareDIDSpaceOptions, type InstanceSpaceOptions, normalizeId, validateId };
307
+ //# sourceMappingURL=cloudflare.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare.d.cts","names":[],"sources":["../src/cloudflare.ts"],"mappings":";;;;;;;;;;;UA2CiB,yBAAA;EAIF;EAFb,OAAA;EAIS;EAFT,WAAA,EAAa,WAAA;EAUK;EARlB,OAAA,EAAS,UAAA;EAUO;;;;;;;EAFhB,eAAA,GAAkB,UAAA;EAuCY;EArC9B,aAAA,GAAgB,aAAA;EA+EE;;;;;;;;;;;;;;;;;EA7DlB,UAAA;EA0ZQ;;;;;;;EAlZR,MAAA,GAAS,aAAA;EAW4C;;;;;EALrD,gBAAA;AAAA;AAAA,cAKW,kBAAA,YAA8B,cAAA;EAiBxB;EAAA,iBAfA,OAAA;EAsCA;;;;;EAAA,iBAhCA,MAAA;EAAA,iBACA,WAAA;EAAA,iBACA,OAAA;EAAA,QACT,SAAA;EAqFa;EAAA,iBAnFJ,aAAA;EA2HX;EAAA,iBAzHW,UAAA;EAyHM;EAAA,iBAvHN,gBAAA;EAuH2C;;;;;;;;;;;;EAAA,iBA1G3C,cAAA;EAiRX;;;;;;;;;EAAA,iBAvQW,UAAA;EA6Vf;EAAA,SA3VO,OAAA,EAAS,SAAA;EA4Ve;EAAA,iBA1VhB,MAAA;cAEL,OAAA,EAAS,yBAAA;EAyVnB;;;;;EAAA,QApTM,aAAA;EA4bgC;;;;;;EAAA,IA/apC,aAAA,CAAA,GAAiB,aAAA;EA0dgC;;;;;;EAAA,QAhd7C,UAAA;EA6hBR;;;;;;;;;;;;;;;;;;;;;;EA/fM,gBAAA,CAAiB,IAAA,EAAM,oBAAA,GAAuB,OAAA,CAAQ,GAAA;;;;;;EAiHtD,cAAA,CAAe,WAAA,WAAsB,OAAA,CAAQ,GAAA;;;;;;;;;;EA0B7C,QAAA,CAAA,GAAY,OAAA;;;;;;EAoBZ,YAAA,CAAa,OAAA;IAAY,UAAA,GAAa,aAAA;EAAA,IAAkB,OAAA,CAAQ,GAAA;;;;;EAQhE,YAAA,CAAa,OAAA;IAAY,UAAA,GAAa,aAAA;EAAA,IAAkB,OAAA,CAAQ,GAAA;EAAA,IA6BlE,QAAA,CAAA,GAAY,gBAAA;;;;;;MAcZ,KAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0CE,aAAA,CACJ,OAAA,UACA,OAAA,WAAkB,UAAA,GAAa,WAAA,EAC/B,IAAA,EAAM,OAAA,GACL,OAAA;IAAU,GAAA;IAAa,MAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;EAuIpB,eAAA,CAAgB,OAAA,WAAkB,OAAA;IACtC,GAAA;IACA,KAAA;IACA,QAAA;EAAA;;;;;;;;;;;;;;;;;;;;;EAwCI,UAAA,CAAW,OAAA,UAAiB,QAAA,WAAmB,OAAA;;;;;;;;;;;;;;;;;;EA6B/C,cAAA,CAAe,OAAA,UAAiB,IAAA,EAAM,OAAA,GAAU,OAAA;IAAU,OAAA;EAAA;;;;;EAgDhE,KAAA,CAAA;AAAA"}
@@ -0,0 +1,308 @@
1
+ import { ObjectStore } from "./providers/platform/r2/dist/types.mjs";
2
+ import "./providers/platform/r2/dist/index.mjs";
3
+ import { D1GCQueue } from "./d1-gc-queue.mjs";
4
+ import { DIDSpaceLike as DIDSpaceLike$1, InstanceSpaceOptions } from "./did-space-like.mjs";
5
+ import { PresignSigner } from "./presign-signer.mjs";
6
+ import { DIDSpaceResolver } from "./resolve.mjs";
7
+ import { PutOpts } from "./tree-index.mjs";
8
+ import { ShareResolver } from "./share-resolve.mjs";
9
+ import { normalizeId, validateId } from "./did-utils.mjs";
10
+ import { AFS, AFSAccessMode } from "@aigne/afs";
11
+
12
+ //#region src/cloudflare.d.ts
13
+ interface CloudflareDIDSpaceOptions {
14
+ /** Owner DID of this space */
15
+ userDid: string;
16
+ /** Shared R2 object store (content-addressed, shared across all apps) */
17
+ objectStore: ObjectStore;
18
+ /** D1 database for tree index + resolve entries */
19
+ indexDb: D1Database;
20
+ /**
21
+ * Optional per-deployment HMAC secret for scope de-identification (README §4.4).
22
+ * When set, all D1 storage keys (`entries.scope` / `changelog.scope` /
23
+ * `shares.owner_did`) become `deriveScope(userDid, secret)` — an opaque HMAC —
24
+ * instead of the plaintext DID. When absent, scope stays plaintext (de-id off,
25
+ * back-compat). Injected along `objectStore` / `indexDb` by the resolver.
26
+ */
27
+ scopeHmacSecret?: Uint8Array;
28
+ /** Optional: ShareResolver for .share reconcile hook (Phase 0.4) */
29
+ shareResolver?: ShareResolver;
30
+ /**
31
+ * Route READ-serving D1 queries through a D1 Session
32
+ * (`withSession("first-unconstrained")`) so they can be served by the
33
+ * nearest read replica. Requires `read_replication: { mode: "auto" }` on the
34
+ * D1 database (a DB-level setting, NOT wrangler.toml) — otherwise every query
35
+ * stays on primary regardless of this flag.
36
+ *
37
+ * Only the read paths honor this (getInstanceSpace / getConfigSpace /
38
+ * getUserSpace / listApps / resolver). The write + GC paths (internalWrite /
39
+ * internalDelete / gcQueue) ALWAYS use the primary: they read the old entry to
40
+ * drive GC, and a stale replica read there would compute the wrong `oldCid`.
41
+ *
42
+ * Consistency note: each tree-index opens its own session with no bookmark
43
+ * threading, so this is "first-unconstrained" (potentially-stale) reads.
44
+ * Read-your-write holds WITHIN a single mounted AFS (same session) but NOT
45
+ * across requests. Default false (last-write-wins on primary, back-compat).
46
+ */
47
+ useReplica?: boolean;
48
+ /**
49
+ * Object-store presigned-PUT signer (DID Space upload plane, §15 decision 7).
50
+ * Injected by the CF runtime when R2 signer credentials are configured;
51
+ * `prepare-upload` (P2) mints exact-key checksum-pinned grants through it.
52
+ * Absent → no grant capability (clients fall back to batchWrite). Node never
53
+ * injects one (decision 8, fallback-only).
54
+ */
55
+ signer?: PresignSigner;
56
+ /**
57
+ * upload-limits Phase 5 per-scope byte quota (bytes). 0 / unset = OFF (the
58
+ * opt-in default). Injected by the CF runtime from `resolveUploadLimits`'s
59
+ * `maxBytesPerScope`; enforced on every write through this space's tree index.
60
+ */
61
+ maxBytesPerScope?: number;
62
+ }
63
+ declare class CloudflareDIDSpace implements DIDSpaceLike$1 {
64
+ /** Real normalizeId(DID) — identity, returned to callers (NOT a storage key). */
65
+ private readonly userDid;
66
+ /**
67
+ * Storage scope — `deriveScope(userDid, secret)` when de-id is on, else the
68
+ * plaintext `userDid`. Every D1 storage/query key uses this, never `userDid`.
69
+ * Named `_scope` to avoid colliding with the `get scope()` accessor (README §4.1).
70
+ */
71
+ private readonly _scope;
72
+ private readonly objectStore;
73
+ private readonly indexDb;
74
+ private _resolver?;
75
+ /** Optional ShareResolver for .share reconcile hook (Phase 0.4) */
76
+ private readonly shareResolver?;
77
+ /** Read replica opt-in for read-serving paths only — see options doc. */
78
+ private readonly useReplica;
79
+ /** upload-limits Phase 5 per-scope byte quota (0 = off, the opt-in default). */
80
+ private readonly maxBytesPerScope;
81
+ /**
82
+ * Instance space cache keyed by (role, useReplica) — same shape as `local.ts`
83
+ * `instanceSpaces`. Without it, `getInstanceSpace` returns a fresh `AFS`
84
+ * (and fresh `EventBus`) every call, so propBind subscribe (registered on
85
+ * AFS_A at session start) and the agent's subsequent write (executing on
86
+ * AFS_B for that exec) cross different buses — the write's `afs:write`
87
+ * event never reaches the subscriber, so the live patch silently drops and
88
+ * the user only sees the new value after a manual page reload (Layer 2
89
+ * staleness on staging). Bounded by the lifetime of this DID-Space (per
90
+ * caller in the resolver), the same memory budget the resolver already
91
+ * spends on `spaces`.
92
+ */
93
+ private readonly instanceSpaces;
94
+ /**
95
+ * User-space cache keyed by (accessMode, useReplica) — the getUserSpace
96
+ * counterpart of {@link instanceSpaces}. Without it, every `getUserSpace()`
97
+ * builds a fresh `AFS` and re-runs `AFS.mount()`'s async provider health check
98
+ * (a root `stat` → `countChildren` + list). Blocklet serve calls getUserSpace
99
+ * once PER stage (reader / afsRoot), so a cold page paid that root enumeration
100
+ * 3× (issue #808 #4). Caching the handle reuses the mounted provider; data
101
+ * reads stay fresh (path→cid D1 lookups are never cached), so zero staleness.
102
+ */
103
+ private readonly userSpaces;
104
+ /** Shared GC queue instance — created once per CloudflareDIDSpace instance */
105
+ readonly gcQueue: D1GCQueue;
106
+ /** Injected presigned-PUT signer (upload plane). Undefined → no grant capability. */
107
+ private readonly signer?;
108
+ constructor(options: CloudflareDIDSpaceOptions);
109
+ /**
110
+ * Construct a D1TreeIndex for this scope with the per-scope byte quota
111
+ * (upload-limits Phase 5) always injected — so every write path enforces it
112
+ * uniformly without each call site remembering to thread it. 0 = quota off.
113
+ */
114
+ private makeTreeIndex;
115
+ /**
116
+ * The injected presigned-PUT signer, or undefined when no R2 signer
117
+ * credentials are configured. The seam through which `prepare-upload` (P2)
118
+ * mints upload grants; also the capability signal clients use to decide
119
+ * grant-path vs batchWrite fallback (§15 decision 7/8).
120
+ */
121
+ get presignSigner(): PresignSigner | undefined;
122
+ /**
123
+ * Upload-plane deps for the user-facing `DIDSpaceProvider` (design §7): the
124
+ * injected signer (CF mints grants; absent → fallback), a D1-backed session
125
+ * store, and the de-identified storage scope written into `upload_sessions`.
126
+ * Only the user space gets these — `/instance` (installer) + config don't.
127
+ */
128
+ private uploadDeps;
129
+ /**
130
+ * Get an isolated AFS instance for a blocklet instance under this DID Space,
131
+ * scoped by role (system = installer-side data, user = caller-side data).
132
+ *
133
+ * Layout (PrefixedTreeIndex prefix relative to `entries.scope = userDid`):
134
+ * role:"system" → blocklets/{instanceDid}/system/ (content tree, mounted at `/`)
135
+ * role:"user" → blocklets/{instanceDid}/user/ (content tree, mounted at `/`)
136
+ * config → blocklets/{instanceDid}/config/ (sibling fragment, getConfigSpace)
137
+ *
138
+ * /files-prefix-removal: content tree is the role root (no `files/` wrapper);
139
+ * config is a sibling fragment (invisible to `/instance`); vault removed.
140
+ *
141
+ * did-space-composition Phase 2 (symmetric with the local backend): the user
142
+ * fragment is a SINGLE `user` subtree. Per-user isolation comes from scope =
143
+ * caller's userDid (the resolver hands back a CloudflareDIDSpace scoped to the
144
+ * caller), so a `users/{userDid}` path segment would be redundant. `userDid`
145
+ * is @deprecated for this call and ignored for the path.
146
+ *
147
+ * Cached per (instanceDid, role, useReplica) — first caller's accessMode
148
+ * wins for that triple (mirrors local.ts). See `instanceSpaces` for the
149
+ * live-update rationale.
150
+ */
151
+ getInstanceSpace(opts: InstanceSpaceOptions): Promise<AFS>;
152
+ /**
153
+ * Runtime-internal config fragment (`blocklets/<i>/config/`, mounted at
154
+ * `/`). Mirrors local `getConfigSpace`. Invisible to `/instance`; holds
155
+ * per-instance machine state like `mounts.toml`.
156
+ */
157
+ getConfigSpace(instanceDid: string): Promise<AFS>;
158
+ /**
159
+ * List all instance DIDs that have storage in this user's space.
160
+ *
161
+ * Enumerates entries under the `blocklets/<instanceDid>/...` prefix and
162
+ * returns the distinct instance-DID segment. This mirrors the local
163
+ * backend's `listApps`, which enumerates `{userDir}/blocklets/*`. Legacy
164
+ * top-level `getAppSpace` segments are NOT enumerated — that layout is
165
+ * deprecated and removed in P4.
166
+ */
167
+ listApps(): Promise<string[]>;
168
+ /**
169
+ * Contract alias (分叉 A, observability Phase 2) for the whole-space root.
170
+ * Delegates to {@link getUserSpace}; satisfies `DIDSpaceLike.getSpaceRoot`
171
+ * without renaming the existing CF method. Defaults readonly via getUserSpace.
172
+ */
173
+ getSpaceRoot(options?: {
174
+ accessMode?: AFSAccessMode;
175
+ }): Promise<AFS>;
176
+ /**
177
+ * Get an AFS instance scoped to the user's entire DID Space.
178
+ * No appDid sub-partitioning.
179
+ */
180
+ getUserSpace(options?: {
181
+ accessMode?: AFSAccessMode;
182
+ }): Promise<AFS>;
183
+ get resolver(): DIDSpaceResolver;
184
+ /**
185
+ * Expose the underlying storage scope — used by worker handlers for
186
+ * cid-permission queries. MUST return the derived scope (not the plaintext
187
+ * DID) so the worker's `entries.scope` lookups match what was written.
188
+ */
189
+ get scope(): string;
190
+ /**
191
+ * Direct write path for the Worker HTTP handler (Task 2.4b).
192
+ *
193
+ * Bypasses the generic `afs.write()` path because `AFSWriteEntryPayload` has
194
+ * no `deviceId`/`skipChangelog` field — the `PutOpts` cannot be smuggled
195
+ * through the public AFS API. The Worker handler therefore constructs a
196
+ * `CloudflareDIDSpace` and calls this method directly, passing the per-
197
+ * request `deviceId` read from the `X-Device-Id` header.
198
+ *
199
+ * Semantics mirror `DIDSpaceProvider.writeHandler`:
200
+ * 1. Compute the content-addressed CID from the payload bytes.
201
+ * 2. R2 put `objects/{cid}` if not already stored (head-check for dedup).
202
+ * 3. `treeIndex.put` — atomic `entries` + `changelog` write (Task 2.4a).
203
+ * 4. Enqueue the previous CID (if any) onto the GC queue for deferred
204
+ * cleanup. Enqueuing an overwritten CID is a no-op if the CID is still
205
+ * referenced by another row (the GC job's reference check handles it).
206
+ *
207
+ * Path conventions:
208
+ * - `afsPath` is an AFS-style path WITH leading slash (e.g. `/foo.json`
209
+ * or `/blocklets/z1abc/index.html`).
210
+ * - The leading slash is stripped before `treeIndex.put`; the remainder is
211
+ * stored verbatim under `entries.scope = this._scope` (the derived storage
212
+ * scope when de-id is on, else the plaintext DID). This matches the
213
+ * `getUserSpace()` layout (no appDid sub-partition) that blocklet publish
214
+ * and general user-space CRUD share.
215
+ *
216
+ * Returns `{ cid, oldCid }`. `oldCid` is present only when an existing row
217
+ * was overwritten; the caller can treat its presence as "something was
218
+ * replaced" for change-tracking. `seq` is not returned — Task 2.4a's
219
+ * `treeIndex.put` does not expose the changelog's AUTOINCREMENT `seq`, and
220
+ * adding a separate SELECT round trip here is wasted work for the current
221
+ * sync path (which only cares about cid + oldCid).
222
+ *
223
+ * No event dispatch is performed (Decision 3A round 5): CloudflareDIDSpace
224
+ * has no event bus reference, the Worker runtime is request/response with
225
+ * no long-lived subscriber, and the sync protocol polls `changelog` rows
226
+ * by `seq` rather than reacting to transient event fan-out.
227
+ */
228
+ internalWrite(afsPath: string, content: string | Uint8Array | ArrayBuffer, opts: PutOpts): Promise<{
229
+ cid: string;
230
+ oldCid?: string;
231
+ }>;
232
+ /**
233
+ * Read the current entry's cid + mtime + last-write deviceId for an
234
+ * If-Match precondition check (Task 3.3).
235
+ *
236
+ * Used by `_createSpaceHandler` BEFORE issuing a write when the client
237
+ * sends `If-Match: <cid>` for optimistic concurrency control. The
238
+ * handler compares the returned `cid` to the header value and returns
239
+ * 409 (with the full snapshot below) on mismatch, or 412 if the row
240
+ * doesn't exist (first-create with If-Match).
241
+ *
242
+ * The query joins `entries` (cid + mtime authoritative) with the most
243
+ * recent put row in `changelog` (device_id of last writer). Both
244
+ * indices used (`PRIMARY KEY (scope, path)` on entries +
245
+ * `idx_changelog_scope_seq` on changelog) keep this O(log n).
246
+ *
247
+ * `deviceId` is `null` when the entry was written via the blocklet
248
+ * exemption path (skipChangelog = true) — there's no changelog row to
249
+ * read the device id from. The handler exposes `null` to clients in
250
+ * the 409 body.
251
+ *
252
+ * Returns `null` when no entry exists at this path.
253
+ */
254
+ getCurrentEntry(afsPath: string): Promise<{
255
+ cid: string;
256
+ mtime: number;
257
+ deviceId: string | null;
258
+ } | null>;
259
+ /**
260
+ * Read the changelog `seq` of the most recent write by `(scope, path,
261
+ * deviceId)` (Task 3.3).
262
+ *
263
+ * The Worker handler calls this AFTER `internalWrite/internalDelete`
264
+ * to recover the seq of the row just inserted, so the PUT/DELETE
265
+ * response can echo `{cid, seq}` for the client.
266
+ *
267
+ * The triple WHERE clause (scope + path + device_id) is the safety
268
+ * mechanism for concurrent writers: each writer is guaranteed to have
269
+ * a unique `device_id` (validated by the Worker handler's strict
270
+ * format regex BEFORE we get here), so even if two PUTs on the same
271
+ * path race, each call's getLastSeq sees ONLY its own write — never
272
+ * the other writer's.
273
+ *
274
+ * Returns `0` when no row matches (impossible if called immediately
275
+ * after a successful internalWrite, but defensive against
276
+ * skipChangelog = true callers — blocklet exempt PUTs have no
277
+ * changelog row at all and the handler should NOT call this for them).
278
+ */
279
+ getLastSeq(afsPath: string, deviceId: string): Promise<number>;
280
+ /**
281
+ * Direct delete path for the Worker HTTP handler (Task 2.4b).
282
+ *
283
+ * Semantics mirror `DIDSpaceProvider.deleteHandler`:
284
+ * 1. Read the current entry (for GC enqueue of the soon-to-be-orphaned CID).
285
+ * 2. `treeIndex.delete` — atomic `entries` delete + `changelog` delete row
286
+ * (Task 2.4a's `INSERT INTO ds_changelog SELECT ... FROM ds_entries` pattern
287
+ * captures the old CID in-batch).
288
+ * 3. Enqueue the old CID for GC. Enqueueing is safe even under races —
289
+ * the GC job's `isReferenced` check skips CIDs still referenced by
290
+ * other rows.
291
+ *
292
+ * Returns an empty object (no `seq` for the same reason as `internalWrite`).
293
+ * Callers that need to know whether anything was actually deleted can rely
294
+ * on the absence of an `AFSNotFoundError` — Task 2.4b's handler converts
295
+ * that to a 404 response.
296
+ */
297
+ internalDelete(afsPath: string, opts: PutOpts): Promise<{
298
+ deleted: boolean;
299
+ }>;
300
+ /**
301
+ * Clean up resources. Drops the cached instance-space map so retained AFS
302
+ * instances are GC-eligible alongside this DID-Space.
303
+ */
304
+ close(): void;
305
+ }
306
+ //#endregion
307
+ export { CloudflareDIDSpace, CloudflareDIDSpaceOptions, type InstanceSpaceOptions, normalizeId, validateId };
308
+ //# sourceMappingURL=cloudflare.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare.d.mts","names":[],"sources":["../src/cloudflare.ts"],"mappings":";;;;;;;;;;;;UA2CiB,yBAAA;EAIf;EAFA,OAAA;EAIA;EAFA,WAAA,EAAa,WAAA;EAUb;EARA,OAAA,EAAS,UAAA;EAUT;;;;;;;EAFA,eAAA,GAAkB,UAAA;EAuCP;EArCX,aAAA,GAAgB,aAAA;;;;;;;;;;;;;;;;;;EAkBhB,UAAA;EAyZiC;;;;;;;EAjZjC,MAAA,GAAS,aAAA;EAW4C;;;;;EALrD,gBAAA;AAAA;AAAA,cAKW,kBAAA,YAA8B,cAAA;EAexB;EAAA,iBAbA,OAAA;EA4BA;;;;;EAAA,iBAtBA,MAAA;EAAA,iBACA,WAAA;EAAA,iBACA,OAAA;EAAA,QACT,SAAA;EAqFJ;EAAA,iBAnFa,aAAA;EA6FT;EAAA,iBA3FS,UAAA;EAyHY;EAAA,iBAvHZ,gBAAA;EAuHmC;;;;;;;;;;;;EAAA,iBA1GnC,cAAA;EAyQqD;;;;;;;;;EAAA,iBA/PrD,UAAA;EA4VX;EAAA,SA1VG,OAAA,EAAS,SAAA;EA4VE;EAAA,iBA1VH,MAAA;cAEL,OAAA,EAAS,yBAAA;EAyVb;;;;;EAAA,QApTA,aAAA;EA4bc;;;;;;EAAA,IA/alB,aAAA,CAAA,GAAiB,aAAA;EA0da;;;;;;EAAA,QAhd1B,UAAA;EA6ewD;;;;;;;;;;;;;;;;;;;;;;EA/c1D,gBAAA,CAAiB,IAAA,EAAM,oBAAA,GAAuB,OAAA,CAAQ,GAAA;;;;;;EAiHtD,cAAA,CAAe,WAAA,WAAsB,OAAA,CAAQ,GAAA;;;;;;;;;;EA0B7C,QAAA,CAAA,GAAY,OAAA;;;;;;EAoBZ,YAAA,CAAa,OAAA;IAAY,UAAA,GAAa,aAAA;EAAA,IAAkB,OAAA,CAAQ,GAAA;;;;;EAQhE,YAAA,CAAa,OAAA;IAAY,UAAA,GAAa,aAAA;EAAA,IAAkB,OAAA,CAAQ,GAAA;EAAA,IA6BlE,QAAA,CAAA,GAAY,gBAAA;;;;;;MAcZ,KAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0CE,aAAA,CACJ,OAAA,UACA,OAAA,WAAkB,UAAA,GAAa,WAAA,EAC/B,IAAA,EAAM,OAAA,GACL,OAAA;IAAU,GAAA;IAAa,MAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;EAuIpB,eAAA,CAAgB,OAAA,WAAkB,OAAA;IACtC,GAAA;IACA,KAAA;IACA,QAAA;EAAA;;;;;;;;;;;;;;;;;;;;;EAwCI,UAAA,CAAW,OAAA,UAAiB,QAAA,WAAmB,OAAA;;;;;;;;;;;;;;;;;;EA6B/C,cAAA,CAAe,OAAA,UAAiB,IAAA,EAAM,OAAA,GAAU,OAAA;IAAU,OAAA;EAAA;;;;;EAgDhE,KAAA,CAAA;AAAA"}