@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,154 @@
1
+ import { SCOPE_META_FILE_COUNT_BACKFILL_SQL } from "./changelog-schema.mjs";
2
+ import { deriveScope, isPlainDidScope } from "./scope-id.mjs";
3
+
4
+ //#region src/scope-migration.ts
5
+ /**
6
+ * scope-migration — offline D1 scope de-identification migration (README §4.5).
7
+ *
8
+ * Migrates the existing PLAINTEXT DID scopes in a CF D1 database to derived
9
+ * HMAC scopes, in place. This is an OFFLINE ops tool (not a DDL migration, not
10
+ * on the request path): a local Node process holds the deployment secret,
11
+ * derives scopes with the SAME `deriveScope` the runtime uses, and rewrites the
12
+ * scope columns.
13
+ *
14
+ * Strict / fail-closed classification: only scopes for which
15
+ * `isPlainDidScope` (= `@arcblock/did#isValid`) is true are migrated. Versioned
16
+ * content scopes (`schema:pkg:1.2.3`), already-derived base32 hashes, bare names
17
+ * (`persona`) and junk are SKIPPED and logged — never silently HMAC'd. Because
18
+ * an already-derived hash is not a valid DID, a re-run sees it as non-DID and
19
+ * skips it: the migration is idempotent with no external "done" set.
20
+ *
21
+ * The thin CLI wrapper (runtimes/cloudflare/scripts/migrate-scope.mjs) handles
22
+ * argv + the D1 connection + the STOP GATE print; this module holds the
23
+ * testable logic so `test/migration.test.ts` can drive it against a mock D1.
24
+ */
25
+ /**
26
+ * Tables with a `scope` column that hold per-user DID-scoped data. `scope_meta`
27
+ * is intentionally absent — it is a derived count and is REBUILT after the
28
+ * scope columns move (UPDATE does not fire the file_count triggers, so a stale
29
+ * plaintext row would remain). `versioned_scopes` / `resolve_entries` /
30
+ * `gc_queue` are exempt by design (README §4.5 matrix).
31
+ */
32
+ const SCOPE_TABLES = [
33
+ "ds_entries",
34
+ "ds_changelog",
35
+ "ds_prefix_watermark",
36
+ "ds_device_sync_state",
37
+ "ds_dirty_path"
38
+ ];
39
+ async function tableExists(db, name) {
40
+ return await db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?").bind(name).first() != null;
41
+ }
42
+ async function distinctColumn(db, table, column) {
43
+ return ((await db.prepare(`SELECT DISTINCT ${column} AS v FROM ${table}`).all()).results ?? []).map((r) => r.v).filter((v) => v != null);
44
+ }
45
+ /**
46
+ * Migrate (or, with `dryRun`, classify) all plaintext DID scopes in `db`.
47
+ *
48
+ * @param db the D1 database (or a compatible mock) — the bound runtime D1
49
+ * @param key the deployment HMAC secret bytes (from `decodeScopeHmacSecret`)
50
+ * @param opts `{ dryRun }` to classify without writing
51
+ */
52
+ async function migrateD1Scopes(db, key, opts = {}) {
53
+ const tablesPresent = [];
54
+ for (const t of SCOPE_TABLES) if (await tableExists(db, t)) tablesPresent.push(t);
55
+ const hasShares = await tableExists(db, "ds_shares");
56
+ const hasScopeMeta = await tableExists(db, "ds_scope_meta");
57
+ const candidateSet = /* @__PURE__ */ new Set();
58
+ for (const t of tablesPresent) for (const s of await distinctColumn(db, t, "scope")) candidateSet.add(s);
59
+ if (hasShares) for (const s of await distinctColumn(db, "ds_shares", "owner_did")) candidateSet.add(s);
60
+ const migrate = [];
61
+ const skip = [];
62
+ for (const s of candidateSet) (isPlainDidScope(s) ? migrate : skip).push(s);
63
+ migrate.sort();
64
+ skip.sort();
65
+ const base = {
66
+ tablesPresent,
67
+ hasShares,
68
+ hasScopeMeta,
69
+ candidates: candidateSet.size,
70
+ migrate,
71
+ skip,
72
+ migrated: 0,
73
+ scopeMetaRebuilt: false
74
+ };
75
+ if (opts.dryRun) return base;
76
+ for (const s of migrate) {
77
+ const h = deriveScope(s, key);
78
+ const stmts = tablesPresent.map((t) => db.prepare(`UPDATE ${t} SET scope = ? WHERE scope = ?`).bind(h, s));
79
+ if (hasShares) stmts.push(db.prepare("UPDATE ds_shares SET owner_did = ? WHERE owner_did = ?").bind(h, s));
80
+ await db.batch(stmts);
81
+ }
82
+ let scopeMetaRebuilt = false;
83
+ if (hasScopeMeta && migrate.length > 0) {
84
+ const placeholders = migrate.map(() => "?").join(", ");
85
+ await db.prepare(`DELETE FROM ds_scope_meta WHERE scope IN (${placeholders})`).bind(...migrate).run();
86
+ await db.prepare(SCOPE_META_FILE_COUNT_BACKFILL_SQL).run();
87
+ scopeMetaRebuilt = true;
88
+ }
89
+ return {
90
+ ...base,
91
+ migrated: migrate.length,
92
+ scopeMetaRebuilt
93
+ };
94
+ }
95
+ /** Classify distinct scope strings into migrate (plaintext DID) vs skip. */
96
+ function classifyScopes(scopes) {
97
+ const migrate = [];
98
+ const skip = [];
99
+ for (const s of [...new Set(scopes)]) (isPlainDidScope(s) ? migrate : skip).push(s);
100
+ migrate.sort();
101
+ skip.sort();
102
+ return {
103
+ migrate,
104
+ skip
105
+ };
106
+ }
107
+ const SQL_SCOPE_COLUMN_TABLES = [
108
+ "ds_entries",
109
+ "ds_changelog",
110
+ "ds_prefix_watermark",
111
+ "ds_dirty_path"
112
+ ];
113
+ /**
114
+ * Generate the migration `.sql` for a REMOTE CF D1 (README §4.5 离线脚本形态).
115
+ *
116
+ * The HMAC is computed HERE (D1 SQL can't); the operator dumps the distinct
117
+ * scopes with `wrangler d1 execute --remote --json` and applies the emitted file
118
+ * with `wrangler d1 execute --remote --file`. Only plaintext DID scopes are
119
+ * rewritten — versioned `schema:…` / already-derived / junk are left out, so a
120
+ * re-apply is idempotent (their `WHERE scope = '<old DID>'` matches nothing).
121
+ *
122
+ * Statement order matters: all scope UPDATEs first, then the scope_meta rebuild
123
+ * (DELETE stale plaintext rows + BACKFILL derived counts from the now-moved
124
+ * entries). `entries` / `changelog` / `prefix_watermark` are CF's standard
125
+ * scope-bearing tables (migrations 0100–0107); `device_sync_state` is absent.
126
+ */
127
+ function buildD1MigrationSql(scopes, key, opts = {}) {
128
+ const { includeShares = true, includeScopeMeta = true } = opts;
129
+ const { migrate, skip } = classifyScopes(scopes);
130
+ const q = (v) => `'${v.replace(/'/g, "''")}'`;
131
+ const lines = [
132
+ "-- DID Space scope de-identification migration (generated).",
133
+ "-- Apply with: wrangler d1 execute <DB> --remote --file <this-file>",
134
+ `-- migrate ${migrate.length} DID scope(s); skip ${skip.length} non-DID scope(s).`
135
+ ];
136
+ for (const s of migrate) {
137
+ const h = deriveScope(s, key);
138
+ for (const t of SQL_SCOPE_COLUMN_TABLES) lines.push(`UPDATE ${t} SET scope = ${q(h)} WHERE scope = ${q(s)};`);
139
+ if (includeShares) lines.push(`UPDATE ds_shares SET owner_did = ${q(h)} WHERE owner_did = ${q(s)};`);
140
+ }
141
+ if (includeScopeMeta && migrate.length > 0) {
142
+ lines.push(`DELETE FROM ds_scope_meta WHERE scope IN (${migrate.map(q).join(", ")});`);
143
+ lines.push(`${SCOPE_META_FILE_COUNT_BACKFILL_SQL};`);
144
+ }
145
+ return {
146
+ sql: `${lines.join("\n")}\n`,
147
+ migrate,
148
+ skip
149
+ };
150
+ }
151
+
152
+ //#endregion
153
+ export { buildD1MigrationSql, classifyScopes, migrateD1Scopes };
154
+ //# sourceMappingURL=scope-migration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-migration.mjs","names":[],"sources":["../src/scope-migration.ts"],"sourcesContent":["/**\n * scope-migration — offline D1 scope de-identification migration (README §4.5).\n *\n * Migrates the existing PLAINTEXT DID scopes in a CF D1 database to derived\n * HMAC scopes, in place. This is an OFFLINE ops tool (not a DDL migration, not\n * on the request path): a local Node process holds the deployment secret,\n * derives scopes with the SAME `deriveScope` the runtime uses, and rewrites the\n * scope columns.\n *\n * Strict / fail-closed classification: only scopes for which\n * `isPlainDidScope` (= `@arcblock/did#isValid`) is true are migrated. Versioned\n * content scopes (`schema:pkg:1.2.3`), already-derived base32 hashes, bare names\n * (`persona`) and junk are SKIPPED and logged — never silently HMAC'd. Because\n * an already-derived hash is not a valid DID, a re-run sees it as non-DID and\n * skips it: the migration is idempotent with no external \"done\" set.\n *\n * The thin CLI wrapper (runtimes/cloudflare/scripts/migrate-scope.mjs) handles\n * argv + the D1 connection + the STOP GATE print; this module holds the\n * testable logic so `test/migration.test.ts` can drive it against a mock D1.\n */\nimport { SCOPE_META_FILE_COUNT_BACKFILL_SQL } from \"./changelog-schema.js\";\nimport { deriveScope, isPlainDidScope } from \"./scope-id.js\";\n\n/**\n * Tables with a `scope` column that hold per-user DID-scoped data. `scope_meta`\n * is intentionally absent — it is a derived count and is REBUILT after the\n * scope columns move (UPDATE does not fire the file_count triggers, so a stale\n * plaintext row would remain). `versioned_scopes` / `resolve_entries` /\n * `gc_queue` are exempt by design (README §4.5 matrix).\n */\nconst SCOPE_TABLES = [\n \"ds_entries\",\n \"ds_changelog\",\n \"ds_prefix_watermark\",\n \"ds_device_sync_state\",\n // index-follower-dirty-path §10.2: the dirty queue's PK includes `scope`, so a\n // de-id migration MUST rewrite it too — else a migrated user's dirty rows stay\n // on the old plaintext scope, the follower queries the new HMAC scope, finds\n // nothing, and silently stops indexing. (The trigger re-derives NEW rows on the\n // new scope going forward; this moves the pre-migration backlog.)\n \"ds_dirty_path\",\n] as const;\n\nexport interface ScopeMigrationOptions {\n /** Classify only — collect + classify candidates, write nothing (STOP GATE). */\n dryRun?: boolean;\n}\n\nexport interface ScopeMigrationReport {\n /** Which `SCOPE_TABLES` actually exist in this DB (CF lacks device_sync_state). */\n tablesPresent: string[];\n /** Whether the `shares` / `scope_meta` tables exist. */\n hasShares: boolean;\n hasScopeMeta: boolean;\n /** Distinct candidate scopes seen across all sources. */\n candidates: number;\n /** Plaintext DID scopes that WILL be / WERE migrated (sorted). */\n migrate: string[];\n /** Non-DID scopes skipped: versioned / already-derived hash / bare / junk (sorted). */\n skip: string[];\n /** Count actually migrated (0 when dryRun). */\n migrated: number;\n /** Whether scope_meta was rebuilt (only when something migrated + table present). */\n scopeMetaRebuilt: boolean;\n}\n\nasync function tableExists(db: D1Database, name: string): Promise<boolean> {\n const row = await db\n .prepare(\"SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?\")\n .bind(name)\n .first<{ name: string }>();\n return row != null;\n}\n\nasync function distinctColumn(db: D1Database, table: string, column: string): Promise<string[]> {\n const res = await db.prepare(`SELECT DISTINCT ${column} AS v FROM ${table}`).all<{ v: string }>();\n return (res.results ?? []).map((r) => r.v).filter((v): v is string => v != null);\n}\n\n/**\n * Migrate (or, with `dryRun`, classify) all plaintext DID scopes in `db`.\n *\n * @param db the D1 database (or a compatible mock) — the bound runtime D1\n * @param key the deployment HMAC secret bytes (from `decodeScopeHmacSecret`)\n * @param opts `{ dryRun }` to classify without writing\n */\nexport async function migrateD1Scopes(\n db: D1Database,\n key: Uint8Array,\n opts: ScopeMigrationOptions = {},\n): Promise<ScopeMigrationReport> {\n // 1. Probe which tables exist (CF has no device_sync_state; fresh DBs vary).\n const tablesPresent: string[] = [];\n for (const t of SCOPE_TABLES) {\n if (await tableExists(db, t)) tablesPresent.push(t);\n }\n const hasShares = await tableExists(db, \"ds_shares\");\n const hasScopeMeta = await tableExists(db, \"ds_scope_meta\");\n\n // 2. Collect distinct candidate scopes across every existing source.\n const candidateSet = new Set<string>();\n for (const t of tablesPresent) {\n for (const s of await distinctColumn(db, t, \"scope\")) candidateSet.add(s);\n }\n if (hasShares) {\n for (const s of await distinctColumn(db, \"ds_shares\", \"owner_did\")) candidateSet.add(s);\n }\n\n // 3. Classify: only true DIDs migrate; everything else is skipped + reported.\n const migrate: string[] = [];\n const skip: string[] = [];\n for (const s of candidateSet) (isPlainDidScope(s) ? migrate : skip).push(s);\n migrate.sort();\n skip.sort();\n\n const base: ScopeMigrationReport = {\n tablesPresent,\n hasShares,\n hasScopeMeta,\n candidates: candidateSet.size,\n migrate,\n skip,\n migrated: 0,\n scopeMetaRebuilt: false,\n };\n\n if (opts.dryRun) return base;\n\n // 4. Rewrite scopes — one ATOMIC batch per scope (all tables for a scope move\n // together). Per-scope batching is also the crash-safety boundary: an\n // interrupted run leaves untouched scopes plaintext, so a re-run completes\n // them; already-moved hashes are skipped (idempotent).\n for (const s of migrate) {\n const h = deriveScope(s, key);\n const stmts: D1PreparedStatement[] = tablesPresent.map((t) =>\n db.prepare(`UPDATE ${t} SET scope = ? WHERE scope = ?`).bind(h, s),\n );\n if (hasShares) {\n stmts.push(db.prepare(\"UPDATE ds_shares SET owner_did = ? WHERE owner_did = ?\").bind(h, s));\n }\n await db.batch(stmts);\n }\n\n // 5. Rebuild scope_meta from the (now-derived) entries. The triggers fire on\n // INSERT/DELETE, NOT the scope UPDATE above — so the old plaintext rows are\n // stale (entries moved away) and the new derived scopes have no row yet.\n // DELETE the stale plaintext rows, then BACKFILL re-seeds derived counts.\n let scopeMetaRebuilt = false;\n if (hasScopeMeta && migrate.length > 0) {\n const placeholders = migrate.map(() => \"?\").join(\", \");\n await db\n .prepare(`DELETE FROM ds_scope_meta WHERE scope IN (${placeholders})`)\n .bind(...migrate)\n .run();\n await db.prepare(SCOPE_META_FILE_COUNT_BACKFILL_SQL).run();\n scopeMetaRebuilt = true;\n }\n\n return { ...base, migrated: migrate.length, scopeMetaRebuilt };\n}\n\n/** Classify distinct scope strings into migrate (plaintext DID) vs skip. */\nexport function classifyScopes(scopes: string[]): { migrate: string[]; skip: string[] } {\n const migrate: string[] = [];\n const skip: string[] = [];\n for (const s of [...new Set(scopes)]) (isPlainDidScope(s) ? migrate : skip).push(s);\n migrate.sort();\n skip.sort();\n return { migrate, skip };\n}\n\nexport interface BuildD1MigrationSqlOptions {\n /** Emit `UPDATE shares SET owner_did = …` (CF has a shares table). Default true. */\n includeShares?: boolean;\n /** Emit the scope_meta DELETE-stale + BACKFILL rebuild. Default true. */\n includeScopeMeta?: boolean;\n}\n\nexport interface D1MigrationSql {\n /** The `.sql` text to apply via `wrangler d1 execute --remote --file`. */\n sql: string;\n migrate: string[];\n skip: string[];\n}\n\nconst SQL_SCOPE_COLUMN_TABLES = [\n \"ds_entries\",\n \"ds_changelog\",\n \"ds_prefix_watermark\",\n // index-follower-dirty-path §10.2 — same reason as SCOPE_TABLES above.\n \"ds_dirty_path\",\n] as const;\n\n/**\n * Generate the migration `.sql` for a REMOTE CF D1 (README §4.5 离线脚本形态).\n *\n * The HMAC is computed HERE (D1 SQL can't); the operator dumps the distinct\n * scopes with `wrangler d1 execute --remote --json` and applies the emitted file\n * with `wrangler d1 execute --remote --file`. Only plaintext DID scopes are\n * rewritten — versioned `schema:…` / already-derived / junk are left out, so a\n * re-apply is idempotent (their `WHERE scope = '<old DID>'` matches nothing).\n *\n * Statement order matters: all scope UPDATEs first, then the scope_meta rebuild\n * (DELETE stale plaintext rows + BACKFILL derived counts from the now-moved\n * entries). `entries` / `changelog` / `prefix_watermark` are CF's standard\n * scope-bearing tables (migrations 0100–0107); `device_sync_state` is absent.\n */\nexport function buildD1MigrationSql(\n scopes: string[],\n key: Uint8Array,\n opts: BuildD1MigrationSqlOptions = {},\n): D1MigrationSql {\n const { includeShares = true, includeScopeMeta = true } = opts;\n const { migrate, skip } = classifyScopes(scopes);\n // scope values are DIDs (base58) / hashes (base32) — no quotes; escape defensively.\n const q = (v: string) => `'${v.replace(/'/g, \"''\")}'`;\n\n const lines: string[] = [\n \"-- DID Space scope de-identification migration (generated).\",\n \"-- Apply with: wrangler d1 execute <DB> --remote --file <this-file>\",\n `-- migrate ${migrate.length} DID scope(s); skip ${skip.length} non-DID scope(s).`,\n ];\n for (const s of migrate) {\n const h = deriveScope(s, key);\n for (const t of SQL_SCOPE_COLUMN_TABLES) {\n lines.push(`UPDATE ${t} SET scope = ${q(h)} WHERE scope = ${q(s)};`);\n }\n if (includeShares) {\n lines.push(`UPDATE ds_shares SET owner_did = ${q(h)} WHERE owner_did = ${q(s)};`);\n }\n }\n if (includeScopeMeta && migrate.length > 0) {\n // DELETE the stale plaintext rows (UPDATE of entries.scope does NOT fire the\n // file_count triggers), then BACKFILL derived counts from the moved entries.\n lines.push(`DELETE FROM ds_scope_meta WHERE scope IN (${migrate.map(q).join(\", \")});`);\n lines.push(`${SCOPE_META_FILE_COUNT_BACKFILL_SQL};`);\n }\n return { sql: `${lines.join(\"\\n\")}\\n`, migrate, skip };\n}\n"],"mappings":"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"}
@@ -0,0 +1,225 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let _aigne_afs = require("@aigne/afs");
3
+ let js_yaml = require("js-yaml");
4
+
5
+ //#region src/share-declaration.ts
6
+ /**
7
+ * Phase 0.2 — ShareDeclaration: YAML schema parsing + path helpers.
8
+ *
9
+ * Exported functions used by Phase 0.3 (ShareResolver) and Phase 0.4 (writeHandler hook):
10
+ * - parseShareDeclaration
11
+ * - isShareDeclarationPath
12
+ * - isShareReservedPath
13
+ * - deriveSourcePath
14
+ * - mapShareErrorToAFSError
15
+ */
16
+ const KNOWN_FIELDS = new Set([
17
+ "slug",
18
+ "kind",
19
+ "status",
20
+ "expires_at",
21
+ "password",
22
+ "visibility",
23
+ "description",
24
+ "domain"
25
+ ]);
26
+ const SLUG_REGEX = /^[a-z0-9][a-z0-9-]{1,62}[a-z0-9]$/;
27
+ const MAX_CONTENT_BYTES = 4096;
28
+ const MAX_DESCRIPTION_LENGTH = 200;
29
+ /**
30
+ * Parse and validate a `.share` file's content.
31
+ *
32
+ * Validation order (strict, per spec):
33
+ * 1. Size check (> 4096 bytes) — before YAML parse
34
+ * 2. Empty content (0 bytes) → { ok: true, data: {} }
35
+ * 3. UTF-8 decode (fatal mode)
36
+ * 4. YAML parse with maxAliasCount: 0
37
+ * 5. Unknown field detection
38
+ * 6. slug format
39
+ * 7. kind enum
40
+ * 8. status enum
41
+ * 9. description length
42
+ * 10. expires_at format
43
+ * 11. password structure
44
+ */
45
+ function parseShareDeclaration(content) {
46
+ if (content.byteLength > MAX_CONTENT_BYTES) return {
47
+ ok: false,
48
+ code: "share-content-too-large",
49
+ message: `Content size ${content.byteLength} bytes exceeds ${MAX_CONTENT_BYTES} byte limit`,
50
+ detail: {
51
+ sizeBytes: content.byteLength,
52
+ limit: MAX_CONTENT_BYTES
53
+ }
54
+ };
55
+ if (content.byteLength === 0) return {
56
+ ok: true,
57
+ data: {}
58
+ };
59
+ let text;
60
+ try {
61
+ text = new TextDecoder("utf-8", { fatal: true }).decode(content);
62
+ } catch {
63
+ return {
64
+ ok: false,
65
+ code: "share-yaml-parse-error",
66
+ message: "Content is not valid UTF-8"
67
+ };
68
+ }
69
+ let parsed;
70
+ try {
71
+ parsed = (0, js_yaml.load)(text);
72
+ } catch (err) {
73
+ return {
74
+ ok: false,
75
+ code: "share-yaml-parse-error",
76
+ message: err instanceof Error ? err.message : String(err),
77
+ detail: err
78
+ };
79
+ }
80
+ if (parsed == null) return {
81
+ ok: true,
82
+ data: {}
83
+ };
84
+ if (typeof parsed !== "object" || Array.isArray(parsed)) return {
85
+ ok: false,
86
+ code: "share-yaml-parse-error",
87
+ message: "Expected a YAML mapping (object), got a different type"
88
+ };
89
+ const obj = parsed;
90
+ for (const key of Object.keys(obj)) if (!KNOWN_FIELDS.has(key)) return {
91
+ ok: false,
92
+ code: "share-field-unknown",
93
+ message: `Unknown field: ${key}`,
94
+ detail: { field: key }
95
+ };
96
+ if (obj.slug !== void 0) {
97
+ if (typeof obj.slug !== "string" || !SLUG_REGEX.test(obj.slug)) return {
98
+ ok: false,
99
+ code: "share-slug-invalid",
100
+ message: `slug must match /^[a-z0-9][a-z0-9-]{1,62}[a-z0-9]$/, got: ${JSON.stringify(obj.slug)}`,
101
+ detail: { slug: obj.slug }
102
+ };
103
+ }
104
+ if (obj.kind !== void 0) {
105
+ if (obj.kind !== "raw" && obj.kind !== "web") return {
106
+ ok: false,
107
+ code: "share-kind-invalid",
108
+ message: `kind must be "raw" or "web", got: ${JSON.stringify(obj.kind)}`,
109
+ detail: { kind: obj.kind }
110
+ };
111
+ }
112
+ if (obj.status !== void 0) {
113
+ if (obj.status !== "active" && obj.status !== "revoked") return {
114
+ ok: false,
115
+ code: "share-status-invalid",
116
+ message: `status must be "active" or "revoked", got: ${JSON.stringify(obj.status)}`,
117
+ detail: { status: obj.status }
118
+ };
119
+ }
120
+ if (obj.description !== void 0) {
121
+ if (typeof obj.description !== "string" || obj.description.length > MAX_DESCRIPTION_LENGTH) return {
122
+ ok: false,
123
+ code: "share-field-invalid",
124
+ message: `description must be a string with at most ${MAX_DESCRIPTION_LENGTH} characters`,
125
+ detail: { field: "description" }
126
+ };
127
+ }
128
+ if (obj.expires_at !== void 0) {
129
+ if (typeof obj.expires_at !== "string" || !isValidExpiresAt(obj.expires_at)) return {
130
+ ok: false,
131
+ code: "share-field-invalid",
132
+ message: `expires_at must be a valid ISO 8601 datetime or Unix milliseconds string`,
133
+ detail: { field: "expires_at" }
134
+ };
135
+ }
136
+ if (obj.password !== void 0) {
137
+ const pwd = obj.password;
138
+ if (typeof pwd !== "object" || pwd === null || Array.isArray(pwd) || pwd.algorithm !== "argon2id" || typeof pwd.hash !== "string") return {
139
+ ok: false,
140
+ code: "share-field-invalid",
141
+ message: "password must be {algorithm: \"argon2id\", hash: string}",
142
+ detail: { field: "password" }
143
+ };
144
+ }
145
+ return {
146
+ ok: true,
147
+ data: obj
148
+ };
149
+ }
150
+ function isValidExpiresAt(value) {
151
+ if (/^\d+$/.test(value)) return true;
152
+ const d = new Date(value);
153
+ return !Number.isNaN(d.getTime());
154
+ }
155
+ /**
156
+ * Returns true if `path` is a `.share` declaration file (in-tree or sidecar).
157
+ *
158
+ * Examples:
159
+ * `.share` → true (root in-tree)
160
+ * `/.share` → true (root in-tree with leading slash)
161
+ * `docs/.share` → true (subdirectory in-tree)
162
+ * `file.pdf.share` → true (sidecar)
163
+ * `.shares/foo` → false (reserved virtual view)
164
+ * `README.md` → false
165
+ */
166
+ function isShareDeclarationPath(path) {
167
+ return (path.startsWith("/") ? path.slice(1) : path).endsWith(".share");
168
+ }
169
+ /**
170
+ * Derives the source path from a declaration path.
171
+ *
172
+ * Examples:
173
+ * `.share` → `""` (root in-tree → source is root directory)
174
+ * `docs/.share` → `"docs"`
175
+ * `file.pdf.share` → `"file.pdf"`
176
+ */
177
+ function deriveSourcePath(declPath) {
178
+ const p = declPath.startsWith("/") ? declPath.slice(1) : declPath;
179
+ if (p.endsWith("/.share")) return p.slice(0, -7);
180
+ return p.slice(0, -6);
181
+ }
182
+ /**
183
+ * Returns true if `path` is a reserved share virtual path (read-only view, not writable).
184
+ *
185
+ * Reserved paths:
186
+ * `.shares` → the root virtual share listing
187
+ * `.shares/<anything>` → entries under the root listing
188
+ * `instances/<iid>/.shares` → per-instance listing
189
+ * `instances/<iid>/.shares/<…>` → per-instance listing entries
190
+ */
191
+ function isShareReservedPath(path) {
192
+ const norm = path.replace(/^\/+/, "");
193
+ if (norm === ".shares" || norm.startsWith(".shares/")) return true;
194
+ if (/^instances\/[^/]+\/\.shares(\/|$)/.test(norm)) return true;
195
+ return false;
196
+ }
197
+ /**
198
+ * Maps a ShareResolver / parser error code to the appropriate AFS error type
199
+ * so that writeHandler can throw with the correct HTTP status code.
200
+ */
201
+ function mapShareErrorToAFSError(code, message, path) {
202
+ switch (code) {
203
+ case "share-yaml-parse-error":
204
+ case "share-content-too-large":
205
+ case "share-field-unknown":
206
+ case "share-field-invalid":
207
+ case "share-slug-invalid":
208
+ case "share-kind-invalid":
209
+ case "share-status-invalid":
210
+ case "share-web-no-decl":
211
+ case "share-sidecar-target-missing":
212
+ case "share-nested": return new _aigne_afs.AFSValidationError(`[${path}] ${code}: ${message}`);
213
+ case "share-path-forbidden":
214
+ case "share-path-reserved": return new _aigne_afs.AFSForbiddenError(path, code);
215
+ case "share-slug-conflict": return new _aigne_afs.AFSAlreadyExistsError(path, message);
216
+ default: return new _aigne_afs.AFSError(`${code}: ${message}`, code);
217
+ }
218
+ }
219
+
220
+ //#endregion
221
+ exports.deriveSourcePath = deriveSourcePath;
222
+ exports.isShareDeclarationPath = isShareDeclarationPath;
223
+ exports.isShareReservedPath = isShareReservedPath;
224
+ exports.mapShareErrorToAFSError = mapShareErrorToAFSError;
225
+ exports.parseShareDeclaration = parseShareDeclaration;
@@ -0,0 +1,30 @@
1
+ //#region src/share-declaration.d.ts
2
+ /** All fields are optional; an empty file is equivalent to `{}`. */
3
+ interface ShareDeclaration {
4
+ slug?: string;
5
+ kind?: "raw" | "web";
6
+ status?: "active" | "revoked";
7
+ expires_at?: string;
8
+ password?: {
9
+ algorithm: "argon2id";
10
+ hash: string;
11
+ };
12
+ visibility?: "public" | "unlisted";
13
+ description?: string;
14
+ domain?: string;
15
+ }
16
+ /**
17
+ * Returns true if `path` is a `.share` declaration file (in-tree or sidecar).
18
+ *
19
+ * Examples:
20
+ * `.share` → true (root in-tree)
21
+ * `/.share` → true (root in-tree with leading slash)
22
+ * `docs/.share` → true (subdirectory in-tree)
23
+ * `file.pdf.share` → true (sidecar)
24
+ * `.shares/foo` → false (reserved virtual view)
25
+ * `README.md` → false
26
+ */
27
+ declare function isShareDeclarationPath(path: string): boolean;
28
+ //#endregion
29
+ export { ShareDeclaration, isShareDeclarationPath };
30
+ //# sourceMappingURL=share-declaration.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share-declaration.d.cts","names":[],"sources":["../src/share-declaration.ts"],"mappings":";;UAiBiB,gBAAA;EACf,IAAA;EACA,IAAA;EACA,MAAA;EACA,UAAA;EACA,QAAA;IAAa,SAAA;IAAuB,IAAA;EAAA;EACpC,UAAA;EACA,WAAA;EACA,MAAA;AAAA;;;;;;;;;;;;iBAwNc,sBAAA,CAAuB,IAAA"}
@@ -0,0 +1,32 @@
1
+ import { AFSAlreadyExistsError, AFSError, AFSForbiddenError, AFSValidationError } from "@aigne/afs";
2
+
3
+ //#region src/share-declaration.d.ts
4
+ /** All fields are optional; an empty file is equivalent to `{}`. */
5
+ interface ShareDeclaration {
6
+ slug?: string;
7
+ kind?: "raw" | "web";
8
+ status?: "active" | "revoked";
9
+ expires_at?: string;
10
+ password?: {
11
+ algorithm: "argon2id";
12
+ hash: string;
13
+ };
14
+ visibility?: "public" | "unlisted";
15
+ description?: string;
16
+ domain?: string;
17
+ }
18
+ /**
19
+ * Returns true if `path` is a `.share` declaration file (in-tree or sidecar).
20
+ *
21
+ * Examples:
22
+ * `.share` → true (root in-tree)
23
+ * `/.share` → true (root in-tree with leading slash)
24
+ * `docs/.share` → true (subdirectory in-tree)
25
+ * `file.pdf.share` → true (sidecar)
26
+ * `.shares/foo` → false (reserved virtual view)
27
+ * `README.md` → false
28
+ */
29
+ declare function isShareDeclarationPath(path: string): boolean;
30
+ //#endregion
31
+ export { ShareDeclaration, isShareDeclarationPath };
32
+ //# sourceMappingURL=share-declaration.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share-declaration.d.mts","names":[],"sources":["../src/share-declaration.ts"],"mappings":";;;;UAiBiB,gBAAA;EACf,IAAA;EACA,IAAA;EACA,MAAA;EACA,UAAA;EACA,QAAA;IAAa,SAAA;IAAuB,IAAA;EAAA;EACpC,UAAA;EACA,WAAA;EACA,MAAA;AAAA;;;;;;;;;;;;iBAwNc,sBAAA,CAAuB,IAAA"}