@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.
- package/LICENSE.md +26 -0
- package/README.md +129 -0
- package/dist/_virtual/_@oxc-project_runtime@0.108.0/helpers/decorate.cjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.108.0/helpers/decorate.mjs +10 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/afs-metadata-context.cjs +20 -0
- package/dist/afs-metadata-context.d.cts +21 -0
- package/dist/afs-metadata-context.d.cts.map +1 -0
- package/dist/afs-metadata-context.d.mts +21 -0
- package/dist/afs-metadata-context.d.mts.map +1 -0
- package/dist/afs-metadata-context.mjs +18 -0
- package/dist/afs-metadata-context.mjs.map +1 -0
- package/dist/blocklet-hook.cjs +180 -0
- package/dist/blocklet-hook.d.cts +29 -0
- package/dist/blocklet-hook.d.cts.map +1 -0
- package/dist/blocklet-hook.d.mts +29 -0
- package/dist/blocklet-hook.d.mts.map +1 -0
- package/dist/blocklet-hook.mjs +178 -0
- package/dist/blocklet-hook.mjs.map +1 -0
- package/dist/changelog-schema.cjs +603 -0
- package/dist/changelog-schema.d.cts +395 -0
- package/dist/changelog-schema.d.cts.map +1 -0
- package/dist/changelog-schema.d.mts +395 -0
- package/dist/changelog-schema.d.mts.map +1 -0
- package/dist/changelog-schema.mjs +570 -0
- package/dist/changelog-schema.mjs.map +1 -0
- package/dist/changelog-write.cjs +80 -0
- package/dist/changelog-write.d.cts +70 -0
- package/dist/changelog-write.d.cts.map +1 -0
- package/dist/changelog-write.d.mts +70 -0
- package/dist/changelog-write.d.mts.map +1 -0
- package/dist/changelog-write.mjs +77 -0
- package/dist/changelog-write.mjs.map +1 -0
- package/dist/cid-byte-cache.cjs +126 -0
- package/dist/cid-byte-cache.d.cts +46 -0
- package/dist/cid-byte-cache.d.cts.map +1 -0
- package/dist/cid-byte-cache.d.mts +47 -0
- package/dist/cid-byte-cache.d.mts.map +1 -0
- package/dist/cid-byte-cache.mjs +125 -0
- package/dist/cid-byte-cache.mjs.map +1 -0
- package/dist/cid.cjs +68 -0
- package/dist/cid.d.cts +22 -0
- package/dist/cid.d.cts.map +1 -0
- package/dist/cid.d.mts +22 -0
- package/dist/cid.d.mts.map +1 -0
- package/dist/cid.mjs +65 -0
- package/dist/cid.mjs.map +1 -0
- package/dist/client.cjs +221 -0
- package/dist/client.d.cts +72 -0
- package/dist/client.d.cts.map +1 -0
- package/dist/client.d.mts +72 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +220 -0
- package/dist/client.mjs.map +1 -0
- package/dist/cloudflare.cjs +510 -0
- package/dist/cloudflare.d.cts +307 -0
- package/dist/cloudflare.d.cts.map +1 -0
- package/dist/cloudflare.d.mts +308 -0
- package/dist/cloudflare.d.mts.map +1 -0
- package/dist/cloudflare.mjs +507 -0
- package/dist/cloudflare.mjs.map +1 -0
- package/dist/ctime-backfill.cjs +272 -0
- package/dist/ctime-backfill.d.cts +169 -0
- package/dist/ctime-backfill.d.cts.map +1 -0
- package/dist/ctime-backfill.d.mts +169 -0
- package/dist/ctime-backfill.d.mts.map +1 -0
- package/dist/ctime-backfill.mjs +267 -0
- package/dist/ctime-backfill.mjs.map +1 -0
- package/dist/d1-gc-queue.cjs +80 -0
- package/dist/d1-gc-queue.d.cts +59 -0
- package/dist/d1-gc-queue.d.cts.map +1 -0
- package/dist/d1-gc-queue.d.mts +59 -0
- package/dist/d1-gc-queue.d.mts.map +1 -0
- package/dist/d1-gc-queue.mjs +81 -0
- package/dist/d1-gc-queue.mjs.map +1 -0
- package/dist/d1-resolve-store.cjs +189 -0
- package/dist/d1-resolve-store.d.cts +93 -0
- package/dist/d1-resolve-store.d.cts.map +1 -0
- package/dist/d1-resolve-store.d.mts +93 -0
- package/dist/d1-resolve-store.d.mts.map +1 -0
- package/dist/d1-resolve-store.mjs +190 -0
- package/dist/d1-resolve-store.mjs.map +1 -0
- package/dist/d1-schema.cjs +361 -0
- package/dist/d1-schema.d.cts +237 -0
- package/dist/d1-schema.d.cts.map +1 -0
- package/dist/d1-schema.d.mts +237 -0
- package/dist/d1-schema.d.mts.map +1 -0
- package/dist/d1-schema.mjs +341 -0
- package/dist/d1-schema.mjs.map +1 -0
- package/dist/d1-share-store.cjs +0 -0
- package/dist/d1-share-store.d.cts +53 -0
- package/dist/d1-share-store.d.cts.map +1 -0
- package/dist/d1-share-store.d.mts +53 -0
- package/dist/d1-share-store.d.mts.map +1 -0
- package/dist/d1-share-store.mjs +0 -0
- package/dist/d1-share-store.mjs.map +1 -0
- package/dist/d1-tree-index.cjs +1098 -0
- package/dist/d1-tree-index.d.cts +203 -0
- package/dist/d1-tree-index.d.cts.map +1 -0
- package/dist/d1-tree-index.d.mts +203 -0
- package/dist/d1-tree-index.d.mts.map +1 -0
- package/dist/d1-tree-index.mjs +1094 -0
- package/dist/d1-tree-index.mjs.map +1 -0
- package/dist/data-backend.cjs +147 -0
- package/dist/data-backend.d.cts +30 -0
- package/dist/data-backend.d.cts.map +1 -0
- package/dist/data-backend.d.mts +30 -0
- package/dist/data-backend.d.mts.map +1 -0
- package/dist/data-backend.mjs +148 -0
- package/dist/data-backend.mjs.map +1 -0
- package/dist/dedup-backfill.cjs +278 -0
- package/dist/dedup-backfill.d.cts +165 -0
- package/dist/dedup-backfill.d.cts.map +1 -0
- package/dist/dedup-backfill.d.mts +165 -0
- package/dist/dedup-backfill.d.mts.map +1 -0
- package/dist/dedup-backfill.mjs +273 -0
- package/dist/dedup-backfill.mjs.map +1 -0
- package/dist/did-space-like.d.cts +2 -0
- package/dist/did-space-like.d.mts +2 -0
- package/dist/did-utils.cjs +44 -0
- package/dist/did-utils.d.cts +25 -0
- package/dist/did-utils.d.cts.map +1 -0
- package/dist/did-utils.d.mts +25 -0
- package/dist/did-utils.d.mts.map +1 -0
- package/dist/did-utils.mjs +43 -0
- package/dist/did-utils.mjs.map +1 -0
- package/dist/dirty-path-queue.cjs +31 -0
- package/dist/dirty-path-queue.d.cts +104 -0
- package/dist/dirty-path-queue.d.cts.map +1 -0
- package/dist/dirty-path-queue.d.mts +104 -0
- package/dist/dirty-path-queue.d.mts.map +1 -0
- package/dist/dirty-path-queue.mjs +31 -0
- package/dist/dirty-path-queue.mjs.map +1 -0
- package/dist/dirty-path-schema.cjs +142 -0
- package/dist/dirty-path-schema.d.cts +90 -0
- package/dist/dirty-path-schema.d.cts.map +1 -0
- package/dist/dirty-path-schema.d.mts +90 -0
- package/dist/dirty-path-schema.d.mts.map +1 -0
- package/dist/dirty-path-schema.mjs +136 -0
- package/dist/dirty-path-schema.mjs.map +1 -0
- package/dist/download-actions.cjs +43 -0
- package/dist/download-actions.mjs +40 -0
- package/dist/download-actions.mjs.map +1 -0
- package/dist/fs-object-store.cjs +153 -0
- package/dist/fs-object-store.d.cts +21 -0
- package/dist/fs-object-store.d.cts.map +1 -0
- package/dist/fs-object-store.d.mts +22 -0
- package/dist/fs-object-store.d.mts.map +1 -0
- package/dist/fs-object-store.mjs +153 -0
- package/dist/fs-object-store.mjs.map +1 -0
- package/dist/gc-queue.d.cts +43 -0
- package/dist/gc-queue.d.cts.map +1 -0
- package/dist/gc-queue.d.mts +43 -0
- package/dist/gc-queue.d.mts.map +1 -0
- package/dist/index.cjs +2712 -0
- package/dist/index.d.cts +504 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +505 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2537 -0
- package/dist/index.mjs.map +1 -0
- package/dist/inline-content-migration.cjs +212 -0
- package/dist/inline-content-migration.d.cts +110 -0
- package/dist/inline-content-migration.d.cts.map +1 -0
- package/dist/inline-content-migration.d.mts +111 -0
- package/dist/inline-content-migration.d.mts.map +1 -0
- package/dist/inline-content-migration.mjs +207 -0
- package/dist/inline-content-migration.mjs.map +1 -0
- package/dist/inline-content.cjs +145 -0
- package/dist/inline-content.d.cts +98 -0
- package/dist/inline-content.d.cts.map +1 -0
- package/dist/inline-content.d.mts +98 -0
- package/dist/inline-content.d.mts.map +1 -0
- package/dist/inline-content.mjs +137 -0
- package/dist/inline-content.mjs.map +1 -0
- package/dist/local-changelog.cjs +241 -0
- package/dist/local-changelog.d.cts +119 -0
- package/dist/local-changelog.d.cts.map +1 -0
- package/dist/local-changelog.d.mts +119 -0
- package/dist/local-changelog.d.mts.map +1 -0
- package/dist/local-changelog.mjs +240 -0
- package/dist/local-changelog.mjs.map +1 -0
- package/dist/local.cjs +435 -0
- package/dist/local.d.cts +254 -0
- package/dist/local.d.cts.map +1 -0
- package/dist/local.d.mts +254 -0
- package/dist/local.d.mts.map +1 -0
- package/dist/local.mjs +427 -0
- package/dist/local.mjs.map +1 -0
- package/dist/memory-gc-queue.cjs +36 -0
- package/dist/memory-gc-queue.d.cts +22 -0
- package/dist/memory-gc-queue.d.cts.map +1 -0
- package/dist/memory-gc-queue.d.mts +22 -0
- package/dist/memory-gc-queue.d.mts.map +1 -0
- package/dist/memory-gc-queue.mjs +36 -0
- package/dist/memory-gc-queue.mjs.map +1 -0
- package/dist/memory-tree-index.cjs +734 -0
- package/dist/memory-tree-index.d.cts +159 -0
- package/dist/memory-tree-index.d.cts.map +1 -0
- package/dist/memory-tree-index.d.mts +159 -0
- package/dist/memory-tree-index.d.mts.map +1 -0
- package/dist/memory-tree-index.mjs +735 -0
- package/dist/memory-tree-index.mjs.map +1 -0
- package/dist/metadata-db.cjs +562 -0
- package/dist/metadata-db.d.cts +102 -0
- package/dist/metadata-db.d.cts.map +1 -0
- package/dist/metadata-db.d.mts +102 -0
- package/dist/metadata-db.d.mts.map +1 -0
- package/dist/metadata-db.mjs +562 -0
- package/dist/metadata-db.mjs.map +1 -0
- package/dist/mime-utils.cjs +2 -0
- package/dist/mime-utils.d.cts +2 -0
- package/dist/mime-utils.d.mts +2 -0
- package/dist/mime-utils.mjs +3 -0
- package/dist/object-key.cjs +41 -0
- package/dist/object-key.d.cts +25 -0
- package/dist/object-key.d.cts.map +1 -0
- package/dist/object-key.d.mts +25 -0
- package/dist/object-key.d.mts.map +1 -0
- package/dist/object-key.mjs +40 -0
- package/dist/object-key.mjs.map +1 -0
- package/dist/packages/session/dist/index.cjs +788 -0
- package/dist/packages/session/dist/index.mjs +782 -0
- package/dist/packages/session/dist/index.mjs.map +1 -0
- package/dist/platform/r2/dist/types.d.cts +49 -0
- package/dist/platform/r2/dist/types.d.cts.map +1 -0
- package/dist/prefix-range.cjs +33 -0
- package/dist/prefix-range.d.cts +29 -0
- package/dist/prefix-range.d.cts.map +1 -0
- package/dist/prefix-range.d.mts +29 -0
- package/dist/prefix-range.d.mts.map +1 -0
- package/dist/prefix-range.mjs +33 -0
- package/dist/prefix-range.mjs.map +1 -0
- package/dist/prefixed-tree-index.cjs +238 -0
- package/dist/prefixed-tree-index.d.cts +85 -0
- package/dist/prefixed-tree-index.d.cts.map +1 -0
- package/dist/prefixed-tree-index.d.mts +85 -0
- package/dist/prefixed-tree-index.d.mts.map +1 -0
- package/dist/prefixed-tree-index.mjs +239 -0
- package/dist/prefixed-tree-index.mjs.map +1 -0
- package/dist/presign-signer.cjs +7 -0
- package/dist/presign-signer.d.cts +99 -0
- package/dist/presign-signer.d.cts.map +1 -0
- package/dist/presign-signer.d.mts +99 -0
- package/dist/presign-signer.d.mts.map +1 -0
- package/dist/presign-signer.mjs +7 -0
- package/dist/presign-signer.mjs.map +1 -0
- package/dist/providers/platform/r2/dist/index.d.mts +3 -0
- package/dist/providers/platform/r2/dist/types.d.mts +49 -0
- package/dist/providers/platform/r2/dist/types.d.mts.map +1 -0
- package/dist/reconcile.cjs +184 -0
- package/dist/reconcile.d.cts +26 -0
- package/dist/reconcile.d.cts.map +1 -0
- package/dist/reconcile.d.mts +26 -0
- package/dist/reconcile.d.mts.map +1 -0
- package/dist/reconcile.mjs +184 -0
- package/dist/reconcile.mjs.map +1 -0
- package/dist/reference-check.cjs +49 -0
- package/dist/reference-check.d.cts +10 -0
- package/dist/reference-check.d.cts.map +1 -0
- package/dist/reference-check.d.mts +10 -0
- package/dist/reference-check.d.mts.map +1 -0
- package/dist/reference-check.mjs +48 -0
- package/dist/reference-check.mjs.map +1 -0
- package/dist/remote-afs.cjs +681 -0
- package/dist/remote-afs.d.cts +236 -0
- package/dist/remote-afs.d.cts.map +1 -0
- package/dist/remote-afs.d.mts +236 -0
- package/dist/remote-afs.d.mts.map +1 -0
- package/dist/remote-afs.mjs +676 -0
- package/dist/remote-afs.mjs.map +1 -0
- package/dist/rename-guard.cjs +18 -0
- package/dist/rename-guard.mjs +18 -0
- package/dist/rename-guard.mjs.map +1 -0
- package/dist/resolve.cjs +260 -0
- package/dist/resolve.d.cts +113 -0
- package/dist/resolve.d.cts.map +1 -0
- package/dist/resolve.d.mts +113 -0
- package/dist/resolve.d.mts.map +1 -0
- package/dist/resolve.mjs +260 -0
- package/dist/resolve.mjs.map +1 -0
- package/dist/rsync-content.cjs +33 -0
- package/dist/rsync-content.mjs +33 -0
- package/dist/rsync-content.mjs.map +1 -0
- package/dist/rsync.cjs +400 -0
- package/dist/rsync.d.cts +157 -0
- package/dist/rsync.d.cts.map +1 -0
- package/dist/rsync.d.mts +157 -0
- package/dist/rsync.d.mts.map +1 -0
- package/dist/rsync.mjs +397 -0
- package/dist/rsync.mjs.map +1 -0
- package/dist/run-gc.cjs +57 -0
- package/dist/run-gc.d.cts +40 -0
- package/dist/run-gc.d.cts.map +1 -0
- package/dist/run-gc.d.mts +41 -0
- package/dist/run-gc.d.mts.map +1 -0
- package/dist/run-gc.mjs +57 -0
- package/dist/run-gc.mjs.map +1 -0
- package/dist/scope-id.cjs +70 -0
- package/dist/scope-id.d.cts +35 -0
- package/dist/scope-id.d.cts.map +1 -0
- package/dist/scope-id.d.mts +35 -0
- package/dist/scope-id.d.mts.map +1 -0
- package/dist/scope-id.mjs +68 -0
- package/dist/scope-id.mjs.map +1 -0
- package/dist/scope-migration-node.cjs +172 -0
- package/dist/scope-migration-node.d.cts +44 -0
- package/dist/scope-migration-node.d.cts.map +1 -0
- package/dist/scope-migration-node.d.mts +44 -0
- package/dist/scope-migration-node.d.mts.map +1 -0
- package/dist/scope-migration-node.mjs +171 -0
- package/dist/scope-migration-node.mjs.map +1 -0
- package/dist/scope-migration.cjs +155 -0
- package/dist/scope-migration.d.cts +65 -0
- package/dist/scope-migration.d.cts.map +1 -0
- package/dist/scope-migration.d.mts +65 -0
- package/dist/scope-migration.d.mts.map +1 -0
- package/dist/scope-migration.mjs +154 -0
- package/dist/scope-migration.mjs.map +1 -0
- package/dist/share-declaration.cjs +225 -0
- package/dist/share-declaration.d.cts +30 -0
- package/dist/share-declaration.d.cts.map +1 -0
- package/dist/share-declaration.d.mts +32 -0
- package/dist/share-declaration.d.mts.map +1 -0
- package/dist/share-declaration.mjs +221 -0
- package/dist/share-declaration.mjs.map +1 -0
- package/dist/share-hook.cjs +63 -0
- package/dist/share-hook.mjs +62 -0
- package/dist/share-hook.mjs.map +1 -0
- package/dist/share-resolve.cjs +176 -0
- package/dist/share-resolve.d.cts +36 -0
- package/dist/share-resolve.d.cts.map +1 -0
- package/dist/share-resolve.d.mts +36 -0
- package/dist/share-resolve.d.mts.map +1 -0
- package/dist/share-resolve.mjs +177 -0
- package/dist/share-resolve.mjs.map +1 -0
- package/dist/share-serve.cjs +145 -0
- package/dist/share-serve.d.cts +30 -0
- package/dist/share-serve.d.cts.map +1 -0
- package/dist/share-serve.d.mts +30 -0
- package/dist/share-serve.d.mts.map +1 -0
- package/dist/share-serve.mjs +144 -0
- package/dist/share-serve.mjs.map +1 -0
- package/dist/share-store.cjs +25 -0
- package/dist/share-store.d.cts +65 -0
- package/dist/share-store.d.cts.map +1 -0
- package/dist/share-store.d.mts +65 -0
- package/dist/share-store.d.mts.map +1 -0
- package/dist/share-store.mjs +25 -0
- package/dist/share-store.mjs.map +1 -0
- package/dist/share-virtual-path.cjs +102 -0
- package/dist/share-virtual-path.mjs +101 -0
- package/dist/share-virtual-path.mjs.map +1 -0
- package/dist/space-resolver.cjs +54 -0
- package/dist/space-resolver.d.cts +34 -0
- package/dist/space-resolver.d.cts.map +1 -0
- package/dist/space-resolver.d.mts +34 -0
- package/dist/space-resolver.d.mts.map +1 -0
- package/dist/space-resolver.mjs +55 -0
- package/dist/space-resolver.mjs.map +1 -0
- package/dist/sqlite-gc-queue.cjs +51 -0
- package/dist/sqlite-gc-queue.d.cts +22 -0
- package/dist/sqlite-gc-queue.d.cts.map +1 -0
- package/dist/sqlite-gc-queue.d.mts +22 -0
- package/dist/sqlite-gc-queue.d.mts.map +1 -0
- package/dist/sqlite-gc-queue.mjs +52 -0
- package/dist/sqlite-gc-queue.mjs.map +1 -0
- package/dist/sqlite-resolve-store.cjs +163 -0
- package/dist/sqlite-resolve-store.d.cts +50 -0
- package/dist/sqlite-resolve-store.d.cts.map +1 -0
- package/dist/sqlite-resolve-store.d.mts +50 -0
- package/dist/sqlite-resolve-store.d.mts.map +1 -0
- package/dist/sqlite-resolve-store.mjs +164 -0
- package/dist/sqlite-resolve-store.mjs.map +1 -0
- package/dist/sqlite-share-store.cjs +157 -0
- package/dist/sqlite-share-store.d.cts +31 -0
- package/dist/sqlite-share-store.d.cts.map +1 -0
- package/dist/sqlite-share-store.d.mts +31 -0
- package/dist/sqlite-share-store.d.mts.map +1 -0
- package/dist/sqlite-share-store.mjs +157 -0
- package/dist/sqlite-share-store.mjs.map +1 -0
- package/dist/sqlite-tree-index.cjs +901 -0
- package/dist/sqlite-tree-index.d.cts +107 -0
- package/dist/sqlite-tree-index.d.cts.map +1 -0
- package/dist/sqlite-tree-index.d.mts +107 -0
- package/dist/sqlite-tree-index.d.mts.map +1 -0
- package/dist/sqlite-tree-index.mjs +902 -0
- package/dist/sqlite-tree-index.mjs.map +1 -0
- package/dist/sync-engine.cjs +1324 -0
- package/dist/sync-engine.d.cts +473 -0
- package/dist/sync-engine.d.cts.map +1 -0
- package/dist/sync-engine.d.mts +473 -0
- package/dist/sync-engine.d.mts.map +1 -0
- package/dist/sync-engine.mjs +1315 -0
- package/dist/sync-engine.mjs.map +1 -0
- package/dist/sync-state.cjs +303 -0
- package/dist/sync-state.d.cts +224 -0
- package/dist/sync-state.d.cts.map +1 -0
- package/dist/sync-state.d.mts +224 -0
- package/dist/sync-state.d.mts.map +1 -0
- package/dist/sync-state.mjs +297 -0
- package/dist/sync-state.mjs.map +1 -0
- package/dist/timestamp.cjs +92 -0
- package/dist/timestamp.mjs +91 -0
- package/dist/timestamp.mjs.map +1 -0
- package/dist/transports/http.cjs +54 -0
- package/dist/transports/http.d.cts +26 -0
- package/dist/transports/http.d.cts.map +1 -0
- package/dist/transports/http.d.mts +26 -0
- package/dist/transports/http.d.mts.map +1 -0
- package/dist/transports/http.mjs +54 -0
- package/dist/transports/http.mjs.map +1 -0
- package/dist/transports/static.cjs +55 -0
- package/dist/transports/static.d.cts +28 -0
- package/dist/transports/static.d.cts.map +1 -0
- package/dist/transports/static.d.mts +28 -0
- package/dist/transports/static.d.mts.map +1 -0
- package/dist/transports/static.mjs +55 -0
- package/dist/transports/static.mjs.map +1 -0
- package/dist/transports/types.cjs +13 -0
- package/dist/transports/types.d.cts +72 -0
- package/dist/transports/types.d.cts.map +1 -0
- package/dist/transports/types.d.mts +72 -0
- package/dist/transports/types.d.mts.map +1 -0
- package/dist/transports/types.mjs +13 -0
- package/dist/transports/types.mjs.map +1 -0
- package/dist/transports/ws.cjs +207 -0
- package/dist/transports/ws.d.cts +47 -0
- package/dist/transports/ws.d.cts.map +1 -0
- package/dist/transports/ws.d.mts +47 -0
- package/dist/transports/ws.d.mts.map +1 -0
- package/dist/transports/ws.mjs +206 -0
- package/dist/transports/ws.mjs.map +1 -0
- package/dist/tree-index.cjs +333 -0
- package/dist/tree-index.d.cts +524 -0
- package/dist/tree-index.d.cts.map +1 -0
- package/dist/tree-index.d.mts +524 -0
- package/dist/tree-index.d.mts.map +1 -0
- package/dist/tree-index.mjs +322 -0
- package/dist/tree-index.mjs.map +1 -0
- package/dist/tree-query.cjs +655 -0
- package/dist/tree-query.d.cts +70 -0
- package/dist/tree-query.d.cts.map +1 -0
- package/dist/tree-query.d.mts +70 -0
- package/dist/tree-query.d.mts.map +1 -0
- package/dist/tree-query.mjs +648 -0
- package/dist/tree-query.mjs.map +1 -0
- package/dist/upload-actions.cjs +97 -0
- package/dist/upload-actions.d.cts +19 -0
- package/dist/upload-actions.d.cts.map +1 -0
- package/dist/upload-actions.d.mts +21 -0
- package/dist/upload-actions.d.mts.map +1 -0
- package/dist/upload-actions.mjs +90 -0
- package/dist/upload-actions.mjs.map +1 -0
- package/dist/upload-session-store.cjs +185 -0
- package/dist/upload-session-store.d.cts +99 -0
- package/dist/upload-session-store.d.cts.map +1 -0
- package/dist/upload-session-store.d.mts +99 -0
- package/dist/upload-session-store.d.mts.map +1 -0
- package/dist/upload-session-store.mjs +184 -0
- package/dist/upload-session-store.mjs.map +1 -0
- package/dist/url-normalize.cjs +61 -0
- package/dist/url-normalize.d.cts +33 -0
- package/dist/url-normalize.d.cts.map +1 -0
- package/dist/url-normalize.d.mts +33 -0
- package/dist/url-normalize.d.mts.map +1 -0
- package/dist/url-normalize.mjs +61 -0
- package/dist/url-normalize.mjs.map +1 -0
- package/dist/versioned-content-backends.cjs +155 -0
- package/dist/versioned-content-backends.d.cts +49 -0
- package/dist/versioned-content-backends.d.cts.map +1 -0
- package/dist/versioned-content-backends.d.mts +49 -0
- package/dist/versioned-content-backends.d.mts.map +1 -0
- package/dist/versioned-content-backends.mjs +154 -0
- package/dist/versioned-content-backends.mjs.map +1 -0
- package/dist/versioned-content-index.cjs +102 -0
- package/dist/versioned-content-index.d.cts +46 -0
- package/dist/versioned-content-index.d.cts.map +1 -0
- package/dist/versioned-content-index.d.mts +46 -0
- package/dist/versioned-content-index.d.mts.map +1 -0
- package/dist/versioned-content-index.mjs +103 -0
- package/dist/versioned-content-index.mjs.map +1 -0
- package/dist/versioned-content-store.cjs +121 -0
- package/dist/versioned-content-store.d.cts +90 -0
- package/dist/versioned-content-store.d.cts.map +1 -0
- package/dist/versioned-content-store.d.mts +90 -0
- package/dist/versioned-content-store.d.mts.map +1 -0
- package/dist/versioned-content-store.mjs +122 -0
- package/dist/versioned-content-store.mjs.map +1 -0
- package/dist/versioned-scope.cjs +39 -0
- package/dist/versioned-scope.d.cts +57 -0
- package/dist/versioned-scope.d.cts.map +1 -0
- package/dist/versioned-scope.d.mts +57 -0
- package/dist/versioned-scope.d.mts.map +1 -0
- package/dist/versioned-scope.mjs +37 -0
- package/dist/versioned-scope.mjs.map +1 -0
- package/migrations/0001_tree_entries.sql +17 -0
- package/migrations/0002_resolve_entries.sql +7 -0
- package/migrations/0003_entries_v2.sql +38 -0
- package/migrations/0004_gc_queue.sql +5 -0
- package/migrations/0006_resolve_enhance.sql +14 -0
- package/migrations/0007_resolve_created_at.sql +10 -0
- package/migrations/0008_changelog.sql +34 -0
- package/migrations/0009_device_sync_state.sql +29 -0
- package/migrations/0010_scope_meta.sql +33 -0
- package/migrations/0011_shares.sql +25 -0
- package/migrations/0012_scope_meta_file_count.sql +41 -0
- package/migrations/0013_scope_meta_total_bytes.sql +47 -0
- package/migrations/0014_rename_tables.sql +62 -0
- package/package.json +102 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-migration-node.d.cts","names":[],"sources":["../src/scope-migration-node.ts"],"mappings":";;;UAiCiB,yBAAA;;EAEf,MAAA;AAAA;AAAA,UAGe,wBAAA;EAHf;EAKA,OAAA;EAFe;EAIf,IAAA;;EAEA,OAAA;EAJA;EAMA,MAAA;IAAU,QAAA;IAAkB,OAAA;EAAA;AAAA;;;AAwB9B;;;;;;;;;iBAAsB,qBAAA,CACpB,MAAA,EAAQ,MAAA,EACR,CAAA,UACA,GAAA,EAAK,UAAA,GACJ,OAAA;;;;;iBA+EmB,iBAAA,CAAkB,IAAA;EACtC,QAAA;EACA,GAAA,EAAK,UAAA;EACL,MAAA;AAAA,IACE,OAAA,CAAQ,wBAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Client } from "@libsql/client";
|
|
2
|
+
|
|
3
|
+
//#region src/scope-migration-node.d.ts
|
|
4
|
+
interface NodeScopeMigrationOptions {
|
|
5
|
+
/** Classify only — list migrate/skip, rewrite + rename nothing. */
|
|
6
|
+
dryRun?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface NodeScopeMigrationReport {
|
|
9
|
+
/** Plaintext DID directory names that WILL be / WERE migrated (sorted). */
|
|
10
|
+
migrate: string[];
|
|
11
|
+
/** Non-DID directory names skipped: already-derived hash / versioned / junk (sorted). */
|
|
12
|
+
skip: string[];
|
|
13
|
+
/** Count of directories actually renamed (0 when dryRun). */
|
|
14
|
+
renamed: number;
|
|
15
|
+
/** `_shares.db` owner_did migration outcome. */
|
|
16
|
+
shares: {
|
|
17
|
+
migrated: number;
|
|
18
|
+
skipped: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Rewrite a single per-user `_metadata.db` for the DID scope `s` → derived.
|
|
23
|
+
* Atomic (one write batch). The caller MUST close the client before renaming
|
|
24
|
+
* the directory.
|
|
25
|
+
*
|
|
26
|
+
* Probes table existence first: older `_metadata.db` files predate
|
|
27
|
+
* `prefix_watermark` / `sync_state` / `cid_cache` (added by later phases), so
|
|
28
|
+
* each statement is included ONLY when its table exists — otherwise libsql
|
|
29
|
+
* throws "no such table" and the whole batch aborts. `entries` / `changelog`
|
|
30
|
+
* are the core tables (always present in a real space db).
|
|
31
|
+
*/
|
|
32
|
+
declare function migrateNodeMetadataDb(client: Client, s: string, key: Uint8Array): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Migrate (or, with `dryRun`, classify) every plaintext-DID space under
|
|
35
|
+
* `rootPath`, plus the daemon-global `_shares.db`.
|
|
36
|
+
*/
|
|
37
|
+
declare function migrateNodeSpaces(opts: {
|
|
38
|
+
rootPath: string;
|
|
39
|
+
key: Uint8Array;
|
|
40
|
+
dryRun?: boolean;
|
|
41
|
+
}): Promise<NodeScopeMigrationReport>;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { NodeScopeMigrationOptions, NodeScopeMigrationReport, migrateNodeMetadataDb, migrateNodeSpaces };
|
|
44
|
+
//# sourceMappingURL=scope-migration-node.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-migration-node.d.mts","names":[],"sources":["../src/scope-migration-node.ts"],"mappings":";;;UAiCiB,yBAAA;;EAEf,MAAA;AAAA;AAAA,UAGe,wBAAA;EAHf;EAKA,OAAA;EAFe;EAIf,IAAA;;EAEA,OAAA;EAJA;EAMA,MAAA;IAAU,QAAA;IAAkB,OAAA;EAAA;AAAA;;;AAwB9B;;;;;;;;;iBAAsB,qBAAA,CACpB,MAAA,EAAQ,MAAA,EACR,CAAA,UACA,GAAA,EAAK,UAAA,GACJ,OAAA;;;;;iBA+EmB,iBAAA,CAAkB,IAAA;EACtC,QAAA;EACA,GAAA,EAAK,UAAA;EACL,MAAA;AAAA,IACE,OAAA,CAAQ,wBAAA"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { deriveScope, isPlainDidScope } from "./scope-id.mjs";
|
|
2
|
+
import { existsSync, readdirSync, renameSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { createClient } from "@libsql/client";
|
|
5
|
+
|
|
6
|
+
//#region src/scope-migration-node.ts
|
|
7
|
+
/**
|
|
8
|
+
* scope-migration-node — offline Node scope de-identification migration (README §5.4).
|
|
9
|
+
*
|
|
10
|
+
* Migrates the existing PLAINTEXT DID-scoped per-user spaces on a local disk to
|
|
11
|
+
* derived HMAC scopes. Unlike the CF migration (one shared D1), Node stores each
|
|
12
|
+
* user under `{rootPath}/{scope}/_metadata.db` + a daemon-global
|
|
13
|
+
* `{rootPath}/_shares.db`, so this is a per-DIRECTORY rename plus a per-db
|
|
14
|
+
* rewrite. OFFLINE tool: the daemon MUST be stopped first (README §5.4).
|
|
15
|
+
*
|
|
16
|
+
* Per directory `{rootPath}/{s}` whose basename `s` is a plaintext DID:
|
|
17
|
+
* 1. Rewrite `_metadata.db` scope columns (entries / changelog /
|
|
18
|
+
* prefix_watermark) where `scope = s` → `deriveScope(s)`, rewrite the
|
|
19
|
+
* `sync_state` `{s}:` key prefix (INSERT+DELETE — can't UPDATE a PK; the
|
|
20
|
+
* bare `device_id` key has no `{s}:` prefix so it is preserved), and clear
|
|
21
|
+
* `cid_cache` (no scope column, rebuildable). `sync_checkpoint` (transient)
|
|
22
|
+
* and `gc_queue` (cid-keyed) are untouched. ALL in one atomic batch.
|
|
23
|
+
* 2. `fs.rename` the directory to `{rootPath}/{deriveScope(s)}` — done LAST so
|
|
24
|
+
* the directory name is the idempotency marker: an interrupted run leaves a
|
|
25
|
+
* plaintext dir (re-run completes it), and a finished dir is a hash
|
|
26
|
+
* (`isPlainDidScope` false → skipped). The per-db batch is itself
|
|
27
|
+
* idempotent (keyed on the old plaintext `s`, a no-op once moved).
|
|
28
|
+
*
|
|
29
|
+
* Then the daemon-global `_shares.db.owner_did` is migrated once (same DID
|
|
30
|
+
* classification). Strict: only true DIDs migrate; versioned / already-derived /
|
|
31
|
+
* junk are skipped + reported, never silently HMAC'd.
|
|
32
|
+
*/
|
|
33
|
+
/** Which of `names` exist as tables in this db. */
|
|
34
|
+
async function existingTables(client, names) {
|
|
35
|
+
const placeholders = names.map(() => "?").join(", ");
|
|
36
|
+
const res = await client.execute({
|
|
37
|
+
sql: `SELECT name FROM sqlite_master WHERE type = 'table' AND name IN (${placeholders})`,
|
|
38
|
+
args: names
|
|
39
|
+
});
|
|
40
|
+
return new Set((res.rows ?? []).map((r) => r.name));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Rewrite a single per-user `_metadata.db` for the DID scope `s` → derived.
|
|
44
|
+
* Atomic (one write batch). The caller MUST close the client before renaming
|
|
45
|
+
* the directory.
|
|
46
|
+
*
|
|
47
|
+
* Probes table existence first: older `_metadata.db` files predate
|
|
48
|
+
* `prefix_watermark` / `sync_state` / `cid_cache` (added by later phases), so
|
|
49
|
+
* each statement is included ONLY when its table exists — otherwise libsql
|
|
50
|
+
* throws "no such table" and the whole batch aborts. `entries` / `changelog`
|
|
51
|
+
* are the core tables (always present in a real space db).
|
|
52
|
+
*/
|
|
53
|
+
async function migrateNodeMetadataDb(client, s, key) {
|
|
54
|
+
const h = deriveScope(s, key);
|
|
55
|
+
const scopedPrefix = `${s}:`;
|
|
56
|
+
const derivedPrefix = `${h}:`;
|
|
57
|
+
const likeOld = `${s}:%`;
|
|
58
|
+
const present = await existingTables(client, [
|
|
59
|
+
"ds_entries",
|
|
60
|
+
"ds_changelog",
|
|
61
|
+
"ds_prefix_watermark",
|
|
62
|
+
"ds_dirty_path",
|
|
63
|
+
"ds_sync_state",
|
|
64
|
+
"cid_cache"
|
|
65
|
+
]);
|
|
66
|
+
const stmts = [];
|
|
67
|
+
if (present.has("ds_entries")) stmts.push({
|
|
68
|
+
sql: "UPDATE ds_entries SET scope = ? WHERE scope = ?",
|
|
69
|
+
args: [h, s]
|
|
70
|
+
});
|
|
71
|
+
if (present.has("ds_changelog")) stmts.push({
|
|
72
|
+
sql: "UPDATE ds_changelog SET scope = ? WHERE scope = ?",
|
|
73
|
+
args: [h, s]
|
|
74
|
+
});
|
|
75
|
+
if (present.has("ds_prefix_watermark")) stmts.push({
|
|
76
|
+
sql: "UPDATE ds_prefix_watermark SET scope = ? WHERE scope = ?",
|
|
77
|
+
args: [h, s]
|
|
78
|
+
});
|
|
79
|
+
if (present.has("ds_dirty_path")) stmts.push({
|
|
80
|
+
sql: "UPDATE ds_dirty_path SET scope = ? WHERE scope = ?",
|
|
81
|
+
args: [h, s]
|
|
82
|
+
});
|
|
83
|
+
if (present.has("ds_sync_state")) {
|
|
84
|
+
stmts.push({
|
|
85
|
+
sql: "INSERT OR IGNORE INTO ds_sync_state(key, value) SELECT replace(key, ?, ?), value FROM ds_sync_state WHERE key LIKE ?",
|
|
86
|
+
args: [
|
|
87
|
+
scopedPrefix,
|
|
88
|
+
derivedPrefix,
|
|
89
|
+
likeOld
|
|
90
|
+
]
|
|
91
|
+
});
|
|
92
|
+
stmts.push({
|
|
93
|
+
sql: "DELETE FROM ds_sync_state WHERE key LIKE ?",
|
|
94
|
+
args: [likeOld]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (present.has("cid_cache")) stmts.push({
|
|
98
|
+
sql: "DELETE FROM cid_cache",
|
|
99
|
+
args: []
|
|
100
|
+
});
|
|
101
|
+
if (stmts.length > 0) await client.batch(stmts, "write");
|
|
102
|
+
}
|
|
103
|
+
/** Migrate `_shares.db.owner_did` for every plaintext-DID owner (one batch). */
|
|
104
|
+
async function migrateNodeShares(sharesPath, key, dryRun) {
|
|
105
|
+
const client = createClient({ url: `file:${sharesPath}` });
|
|
106
|
+
try {
|
|
107
|
+
const owners = ((await client.execute("SELECT DISTINCT owner_did AS v FROM ds_shares")).rows ?? []).map((r) => r.v).filter((v) => v != null);
|
|
108
|
+
const migrate = owners.filter((o) => isPlainDidScope(o));
|
|
109
|
+
const skipped = owners.length - migrate.length;
|
|
110
|
+
if (dryRun || migrate.length === 0) return {
|
|
111
|
+
migrated: 0,
|
|
112
|
+
skipped
|
|
113
|
+
};
|
|
114
|
+
await client.batch(migrate.map((o) => ({
|
|
115
|
+
sql: "UPDATE ds_shares SET owner_did = ? WHERE owner_did = ?",
|
|
116
|
+
args: [deriveScope(o, key), o]
|
|
117
|
+
})), "write");
|
|
118
|
+
return {
|
|
119
|
+
migrated: migrate.length,
|
|
120
|
+
skipped
|
|
121
|
+
};
|
|
122
|
+
} finally {
|
|
123
|
+
client.close();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Migrate (or, with `dryRun`, classify) every plaintext-DID space under
|
|
128
|
+
* `rootPath`, plus the daemon-global `_shares.db`.
|
|
129
|
+
*/
|
|
130
|
+
async function migrateNodeSpaces(opts) {
|
|
131
|
+
const { rootPath, key, dryRun = false } = opts;
|
|
132
|
+
const migrate = [];
|
|
133
|
+
const skip = [];
|
|
134
|
+
const entries = existsSync(rootPath) ? readdirSync(rootPath, { withFileTypes: true }) : [];
|
|
135
|
+
for (const entry of entries) {
|
|
136
|
+
if (!entry.isDirectory()) continue;
|
|
137
|
+
(isPlainDidScope(entry.name) ? migrate : skip).push(entry.name);
|
|
138
|
+
}
|
|
139
|
+
migrate.sort();
|
|
140
|
+
skip.sort();
|
|
141
|
+
let renamed = 0;
|
|
142
|
+
if (!dryRun) for (const s of migrate) {
|
|
143
|
+
const dir = join(rootPath, s);
|
|
144
|
+
const dbPath = join(dir, "_metadata.db");
|
|
145
|
+
if (existsSync(dbPath)) {
|
|
146
|
+
const client = createClient({ url: `file:${dbPath}` });
|
|
147
|
+
try {
|
|
148
|
+
await migrateNodeMetadataDb(client, s, key);
|
|
149
|
+
} finally {
|
|
150
|
+
client.close();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
renameSync(dir, join(rootPath, deriveScope(s, key)));
|
|
154
|
+
renamed++;
|
|
155
|
+
}
|
|
156
|
+
const sharesPath = join(rootPath, "_shares.db");
|
|
157
|
+
const shares = existsSync(sharesPath) ? await migrateNodeShares(sharesPath, key, dryRun) : {
|
|
158
|
+
migrated: 0,
|
|
159
|
+
skipped: 0
|
|
160
|
+
};
|
|
161
|
+
return {
|
|
162
|
+
migrate,
|
|
163
|
+
skip,
|
|
164
|
+
renamed,
|
|
165
|
+
shares
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
//#endregion
|
|
170
|
+
export { migrateNodeMetadataDb, migrateNodeSpaces };
|
|
171
|
+
//# sourceMappingURL=scope-migration-node.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-migration-node.mjs","names":[],"sources":["../src/scope-migration-node.ts"],"sourcesContent":["/**\n * scope-migration-node — offline Node scope de-identification migration (README §5.4).\n *\n * Migrates the existing PLAINTEXT DID-scoped per-user spaces on a local disk to\n * derived HMAC scopes. Unlike the CF migration (one shared D1), Node stores each\n * user under `{rootPath}/{scope}/_metadata.db` + a daemon-global\n * `{rootPath}/_shares.db`, so this is a per-DIRECTORY rename plus a per-db\n * rewrite. OFFLINE tool: the daemon MUST be stopped first (README §5.4).\n *\n * Per directory `{rootPath}/{s}` whose basename `s` is a plaintext DID:\n * 1. Rewrite `_metadata.db` scope columns (entries / changelog /\n * prefix_watermark) where `scope = s` → `deriveScope(s)`, rewrite the\n * `sync_state` `{s}:` key prefix (INSERT+DELETE — can't UPDATE a PK; the\n * bare `device_id` key has no `{s}:` prefix so it is preserved), and clear\n * `cid_cache` (no scope column, rebuildable). `sync_checkpoint` (transient)\n * and `gc_queue` (cid-keyed) are untouched. ALL in one atomic batch.\n * 2. `fs.rename` the directory to `{rootPath}/{deriveScope(s)}` — done LAST so\n * the directory name is the idempotency marker: an interrupted run leaves a\n * plaintext dir (re-run completes it), and a finished dir is a hash\n * (`isPlainDidScope` false → skipped). The per-db batch is itself\n * idempotent (keyed on the old plaintext `s`, a no-op once moved).\n *\n * Then the daemon-global `_shares.db.owner_did` is migrated once (same DID\n * classification). Strict: only true DIDs migrate; versioned / already-derived /\n * junk are skipped + reported, never silently HMAC'd.\n */\n// biome-ignore lint/style/noRestrictedImports: offline migration manages physical DID-space directories\nimport { existsSync, readdirSync, renameSync } from \"node:fs\";\n// biome-ignore lint/style/noRestrictedImports: filesystem path joins for the on-disk directory layout\nimport { join } from \"node:path\";\nimport { type Client, createClient } from \"@libsql/client\";\nimport { deriveScope, isPlainDidScope } from \"./scope-id.js\";\n\nexport interface NodeScopeMigrationOptions {\n /** Classify only — list migrate/skip, rewrite + rename nothing. */\n dryRun?: boolean;\n}\n\nexport interface NodeScopeMigrationReport {\n /** Plaintext DID directory names that WILL be / WERE migrated (sorted). */\n migrate: string[];\n /** Non-DID directory names skipped: already-derived hash / versioned / junk (sorted). */\n skip: string[];\n /** Count of directories actually renamed (0 when dryRun). */\n renamed: number;\n /** `_shares.db` owner_did migration outcome. */\n shares: { migrated: number; skipped: number };\n}\n\n/** Which of `names` exist as tables in this db. */\nasync function existingTables(client: Client, names: string[]): Promise<Set<string>> {\n const placeholders = names.map(() => \"?\").join(\", \");\n const res = await client.execute({\n sql: `SELECT name FROM sqlite_master WHERE type = 'table' AND name IN (${placeholders})`,\n args: names,\n });\n return new Set((res.rows ?? []).map((r) => r.name as string));\n}\n\n/**\n * Rewrite a single per-user `_metadata.db` for the DID scope `s` → derived.\n * Atomic (one write batch). The caller MUST close the client before renaming\n * the directory.\n *\n * Probes table existence first: older `_metadata.db` files predate\n * `prefix_watermark` / `sync_state` / `cid_cache` (added by later phases), so\n * each statement is included ONLY when its table exists — otherwise libsql\n * throws \"no such table\" and the whole batch aborts. `entries` / `changelog`\n * are the core tables (always present in a real space db).\n */\nexport async function migrateNodeMetadataDb(\n client: Client,\n s: string,\n key: Uint8Array,\n): Promise<void> {\n const h = deriveScope(s, key);\n const scopedPrefix = `${s}:`;\n const derivedPrefix = `${h}:`;\n const likeOld = `${s}:%`;\n const present = await existingTables(client, [\n \"ds_entries\",\n \"ds_changelog\",\n \"ds_prefix_watermark\",\n \"ds_dirty_path\",\n \"ds_sync_state\",\n \"cid_cache\",\n ]);\n\n const stmts: Parameters<Client[\"batch\"]>[0] = [];\n if (present.has(\"ds_entries\")) {\n stmts.push({ sql: \"UPDATE ds_entries SET scope = ? WHERE scope = ?\", args: [h, s] });\n }\n if (present.has(\"ds_changelog\")) {\n stmts.push({ sql: \"UPDATE ds_changelog SET scope = ? WHERE scope = ?\", args: [h, s] });\n }\n if (present.has(\"ds_prefix_watermark\")) {\n stmts.push({ sql: \"UPDATE ds_prefix_watermark SET scope = ? WHERE scope = ?\", args: [h, s] });\n }\n if (present.has(\"ds_dirty_path\")) {\n // index-follower-dirty-path §10.2: move the dirty backlog to the HMAC scope\n // so the migrated user's follower keeps finding its pending rows.\n stmts.push({ sql: \"UPDATE ds_dirty_path SET scope = ? WHERE scope = ?\", args: [h, s] });\n }\n if (present.has(\"ds_sync_state\")) {\n // Rewrite the `{s}:` key prefix. INSERT the derived-prefixed rows first, then\n // DELETE the plaintext-prefixed ones — the bare `device_id` key (no `{s}:`\n // prefix) is never matched, so it survives.\n stmts.push({\n sql: \"INSERT OR IGNORE INTO ds_sync_state(key, value) SELECT replace(key, ?, ?), value FROM ds_sync_state WHERE key LIKE ?\",\n args: [scopedPrefix, derivedPrefix, likeOld],\n });\n stmts.push({ sql: \"DELETE FROM ds_sync_state WHERE key LIKE ?\", args: [likeOld] });\n }\n if (present.has(\"cid_cache\")) {\n // Clear (no scope column; path→cid cache is rebuildable and the dir rename\n // invalidates absolute paths anyway). sync_checkpoint (transient session\n // state) + gc_queue (cid-keyed) are intentionally left untouched.\n stmts.push({ sql: \"DELETE FROM cid_cache\", args: [] });\n }\n\n if (stmts.length > 0) await client.batch(stmts, \"write\");\n}\n\n/** Migrate `_shares.db.owner_did` for every plaintext-DID owner (one batch). */\nasync function migrateNodeShares(\n sharesPath: string,\n key: Uint8Array,\n dryRun: boolean,\n): Promise<{ migrated: number; skipped: number }> {\n const client = createClient({ url: `file:${sharesPath}` });\n try {\n const res = await client.execute(\"SELECT DISTINCT owner_did AS v FROM ds_shares\");\n const owners = (res.rows ?? []).map((r) => r.v as string).filter((v): v is string => v != null);\n const migrate = owners.filter((o) => isPlainDidScope(o));\n const skipped = owners.length - migrate.length;\n if (dryRun || migrate.length === 0) return { migrated: 0, skipped };\n await client.batch(\n migrate.map((o) => ({\n sql: \"UPDATE ds_shares SET owner_did = ? WHERE owner_did = ?\",\n args: [deriveScope(o, key), o],\n })),\n \"write\",\n );\n return { migrated: migrate.length, skipped };\n } finally {\n client.close();\n }\n}\n\n/**\n * Migrate (or, with `dryRun`, classify) every plaintext-DID space under\n * `rootPath`, plus the daemon-global `_shares.db`.\n */\nexport async function migrateNodeSpaces(opts: {\n rootPath: string;\n key: Uint8Array;\n dryRun?: boolean;\n}): Promise<NodeScopeMigrationReport> {\n const { rootPath, key, dryRun = false } = opts;\n const migrate: string[] = [];\n const skip: string[] = [];\n\n const entries = existsSync(rootPath) ? readdirSync(rootPath, { withFileTypes: true }) : [];\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n (isPlainDidScope(entry.name) ? migrate : skip).push(entry.name);\n }\n migrate.sort();\n skip.sort();\n\n let renamed = 0;\n if (!dryRun) {\n for (const s of migrate) {\n const dir = join(rootPath, s);\n const dbPath = join(dir, \"_metadata.db\");\n if (existsSync(dbPath)) {\n const client = createClient({ url: `file:${dbPath}` });\n try {\n await migrateNodeMetadataDb(client, s, key);\n } finally {\n // MUST close before renaming the directory (the file handle is held).\n client.close();\n }\n }\n // Rename LAST — the directory name is the idempotency marker.\n renameSync(dir, join(rootPath, deriveScope(s, key)));\n renamed++;\n }\n }\n\n const sharesPath = join(rootPath, \"_shares.db\");\n const shares = existsSync(sharesPath)\n ? await migrateNodeShares(sharesPath, key, dryRun)\n : { migrated: 0, skipped: 0 };\n\n return { migrate, skip, renamed, shares };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,eAAe,eAAe,QAAgB,OAAuC;CACnF,MAAM,eAAe,MAAM,UAAU,IAAI,CAAC,KAAK,KAAK;CACpD,MAAM,MAAM,MAAM,OAAO,QAAQ;EAC/B,KAAK,oEAAoE,aAAa;EACtF,MAAM;EACP,CAAC;AACF,QAAO,IAAI,KAAK,IAAI,QAAQ,EAAE,EAAE,KAAK,MAAM,EAAE,KAAe,CAAC;;;;;;;;;;;;;AAc/D,eAAsB,sBACpB,QACA,GACA,KACe;CACf,MAAM,IAAI,YAAY,GAAG,IAAI;CAC7B,MAAM,eAAe,GAAG,EAAE;CAC1B,MAAM,gBAAgB,GAAG,EAAE;CAC3B,MAAM,UAAU,GAAG,EAAE;CACrB,MAAM,UAAU,MAAM,eAAe,QAAQ;EAC3C;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;CAEF,MAAM,QAAwC,EAAE;AAChD,KAAI,QAAQ,IAAI,aAAa,CAC3B,OAAM,KAAK;EAAE,KAAK;EAAmD,MAAM,CAAC,GAAG,EAAE;EAAE,CAAC;AAEtF,KAAI,QAAQ,IAAI,eAAe,CAC7B,OAAM,KAAK;EAAE,KAAK;EAAqD,MAAM,CAAC,GAAG,EAAE;EAAE,CAAC;AAExF,KAAI,QAAQ,IAAI,sBAAsB,CACpC,OAAM,KAAK;EAAE,KAAK;EAA4D,MAAM,CAAC,GAAG,EAAE;EAAE,CAAC;AAE/F,KAAI,QAAQ,IAAI,gBAAgB,CAG9B,OAAM,KAAK;EAAE,KAAK;EAAsD,MAAM,CAAC,GAAG,EAAE;EAAE,CAAC;AAEzF,KAAI,QAAQ,IAAI,gBAAgB,EAAE;AAIhC,QAAM,KAAK;GACT,KAAK;GACL,MAAM;IAAC;IAAc;IAAe;IAAQ;GAC7C,CAAC;AACF,QAAM,KAAK;GAAE,KAAK;GAA8C,MAAM,CAAC,QAAQ;GAAE,CAAC;;AAEpF,KAAI,QAAQ,IAAI,YAAY,CAI1B,OAAM,KAAK;EAAE,KAAK;EAAyB,MAAM,EAAE;EAAE,CAAC;AAGxD,KAAI,MAAM,SAAS,EAAG,OAAM,OAAO,MAAM,OAAO,QAAQ;;;AAI1D,eAAe,kBACb,YACA,KACA,QACgD;CAChD,MAAM,SAAS,aAAa,EAAE,KAAK,QAAQ,cAAc,CAAC;AAC1D,KAAI;EAEF,MAAM,WADM,MAAM,OAAO,QAAQ,gDAAgD,EAC7D,QAAQ,EAAE,EAAE,KAAK,MAAM,EAAE,EAAY,CAAC,QAAQ,MAAmB,KAAK,KAAK;EAC/F,MAAM,UAAU,OAAO,QAAQ,MAAM,gBAAgB,EAAE,CAAC;EACxD,MAAM,UAAU,OAAO,SAAS,QAAQ;AACxC,MAAI,UAAU,QAAQ,WAAW,EAAG,QAAO;GAAE,UAAU;GAAG;GAAS;AACnE,QAAM,OAAO,MACX,QAAQ,KAAK,OAAO;GAClB,KAAK;GACL,MAAM,CAAC,YAAY,GAAG,IAAI,EAAE,EAAE;GAC/B,EAAE,EACH,QACD;AACD,SAAO;GAAE,UAAU,QAAQ;GAAQ;GAAS;WACpC;AACR,SAAO,OAAO;;;;;;;AAQlB,eAAsB,kBAAkB,MAIF;CACpC,MAAM,EAAE,UAAU,KAAK,SAAS,UAAU;CAC1C,MAAM,UAAoB,EAAE;CAC5B,MAAM,OAAiB,EAAE;CAEzB,MAAM,UAAU,WAAW,SAAS,GAAG,YAAY,UAAU,EAAE,eAAe,MAAM,CAAC,GAAG,EAAE;AAC1F,MAAK,MAAM,SAAS,SAAS;AAC3B,MAAI,CAAC,MAAM,aAAa,CAAE;AAC1B,GAAC,gBAAgB,MAAM,KAAK,GAAG,UAAU,MAAM,KAAK,MAAM,KAAK;;AAEjE,SAAQ,MAAM;AACd,MAAK,MAAM;CAEX,IAAI,UAAU;AACd,KAAI,CAAC,OACH,MAAK,MAAM,KAAK,SAAS;EACvB,MAAM,MAAM,KAAK,UAAU,EAAE;EAC7B,MAAM,SAAS,KAAK,KAAK,eAAe;AACxC,MAAI,WAAW,OAAO,EAAE;GACtB,MAAM,SAAS,aAAa,EAAE,KAAK,QAAQ,UAAU,CAAC;AACtD,OAAI;AACF,UAAM,sBAAsB,QAAQ,GAAG,IAAI;aACnC;AAER,WAAO,OAAO;;;AAIlB,aAAW,KAAK,KAAK,UAAU,YAAY,GAAG,IAAI,CAAC,CAAC;AACpD;;CAIJ,MAAM,aAAa,KAAK,UAAU,aAAa;CAC/C,MAAM,SAAS,WAAW,WAAW,GACjC,MAAM,kBAAkB,YAAY,KAAK,OAAO,GAChD;EAAE,UAAU;EAAG,SAAS;EAAG;AAE/B,QAAO;EAAE;EAAS;EAAM;EAAS;EAAQ"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
const require_changelog_schema = require('./changelog-schema.cjs');
|
|
2
|
+
const require_scope_id = require('./scope-id.cjs');
|
|
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) (require_scope_id.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 = require_scope_id.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(require_changelog_schema.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)]) (require_scope_id.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 = require_scope_id.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(`${require_changelog_schema.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
|
+
exports.buildD1MigrationSql = buildD1MigrationSql;
|
|
154
|
+
exports.classifyScopes = classifyScopes;
|
|
155
|
+
exports.migrateD1Scopes = migrateD1Scopes;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
//#region src/scope-migration.d.ts
|
|
2
|
+
interface ScopeMigrationOptions {
|
|
3
|
+
/** Classify only — collect + classify candidates, write nothing (STOP GATE). */
|
|
4
|
+
dryRun?: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface ScopeMigrationReport {
|
|
7
|
+
/** Which `SCOPE_TABLES` actually exist in this DB (CF lacks device_sync_state). */
|
|
8
|
+
tablesPresent: string[];
|
|
9
|
+
/** Whether the `shares` / `scope_meta` tables exist. */
|
|
10
|
+
hasShares: boolean;
|
|
11
|
+
hasScopeMeta: boolean;
|
|
12
|
+
/** Distinct candidate scopes seen across all sources. */
|
|
13
|
+
candidates: number;
|
|
14
|
+
/** Plaintext DID scopes that WILL be / WERE migrated (sorted). */
|
|
15
|
+
migrate: string[];
|
|
16
|
+
/** Non-DID scopes skipped: versioned / already-derived hash / bare / junk (sorted). */
|
|
17
|
+
skip: string[];
|
|
18
|
+
/** Count actually migrated (0 when dryRun). */
|
|
19
|
+
migrated: number;
|
|
20
|
+
/** Whether scope_meta was rebuilt (only when something migrated + table present). */
|
|
21
|
+
scopeMetaRebuilt: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Migrate (or, with `dryRun`, classify) all plaintext DID scopes in `db`.
|
|
25
|
+
*
|
|
26
|
+
* @param db the D1 database (or a compatible mock) — the bound runtime D1
|
|
27
|
+
* @param key the deployment HMAC secret bytes (from `decodeScopeHmacSecret`)
|
|
28
|
+
* @param opts `{ dryRun }` to classify without writing
|
|
29
|
+
*/
|
|
30
|
+
declare function migrateD1Scopes(db: D1Database, key: Uint8Array, opts?: ScopeMigrationOptions): Promise<ScopeMigrationReport>;
|
|
31
|
+
/** Classify distinct scope strings into migrate (plaintext DID) vs skip. */
|
|
32
|
+
declare function classifyScopes(scopes: string[]): {
|
|
33
|
+
migrate: string[];
|
|
34
|
+
skip: string[];
|
|
35
|
+
};
|
|
36
|
+
interface BuildD1MigrationSqlOptions {
|
|
37
|
+
/** Emit `UPDATE shares SET owner_did = …` (CF has a shares table). Default true. */
|
|
38
|
+
includeShares?: boolean;
|
|
39
|
+
/** Emit the scope_meta DELETE-stale + BACKFILL rebuild. Default true. */
|
|
40
|
+
includeScopeMeta?: boolean;
|
|
41
|
+
}
|
|
42
|
+
interface D1MigrationSql {
|
|
43
|
+
/** The `.sql` text to apply via `wrangler d1 execute --remote --file`. */
|
|
44
|
+
sql: string;
|
|
45
|
+
migrate: string[];
|
|
46
|
+
skip: string[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Generate the migration `.sql` for a REMOTE CF D1 (README §4.5 离线脚本形态).
|
|
50
|
+
*
|
|
51
|
+
* The HMAC is computed HERE (D1 SQL can't); the operator dumps the distinct
|
|
52
|
+
* scopes with `wrangler d1 execute --remote --json` and applies the emitted file
|
|
53
|
+
* with `wrangler d1 execute --remote --file`. Only plaintext DID scopes are
|
|
54
|
+
* rewritten — versioned `schema:…` / already-derived / junk are left out, so a
|
|
55
|
+
* re-apply is idempotent (their `WHERE scope = '<old DID>'` matches nothing).
|
|
56
|
+
*
|
|
57
|
+
* Statement order matters: all scope UPDATEs first, then the scope_meta rebuild
|
|
58
|
+
* (DELETE stale plaintext rows + BACKFILL derived counts from the now-moved
|
|
59
|
+
* entries). `entries` / `changelog` / `prefix_watermark` are CF's standard
|
|
60
|
+
* scope-bearing tables (migrations 0100–0107); `device_sync_state` is absent.
|
|
61
|
+
*/
|
|
62
|
+
declare function buildD1MigrationSql(scopes: string[], key: Uint8Array, opts?: BuildD1MigrationSqlOptions): D1MigrationSql;
|
|
63
|
+
//#endregion
|
|
64
|
+
export { BuildD1MigrationSqlOptions, D1MigrationSql, ScopeMigrationOptions, ScopeMigrationReport, buildD1MigrationSql, classifyScopes, migrateD1Scopes };
|
|
65
|
+
//# sourceMappingURL=scope-migration.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-migration.d.cts","names":[],"sources":["../src/scope-migration.ts"],"mappings":";UA2CiB,qBAAA;EAAA;EAEf,MAAA;AAAA;AAAA,UAGe,oBAAA;EAHT;EAKN,aAAA;EAFmC;EAInC,SAAA;EACA,YAAA;EAHA;EAKA,UAAA;EAFA;EAIA,OAAA;EAAA;EAEA,IAAA;EAEA;EAAA,QAAA;EAEgB;EAAhB,gBAAA;AAAA;;;;;;;;iBAuBoB,eAAA,CACpB,EAAA,EAAI,UAAA,EACJ,GAAA,EAAK,UAAA,EACL,IAAA,GAAM,qBAAA,GACL,OAAA,CAAQ,oBAAA;;iBAwEK,cAAA,CAAe,MAAA;EAAqB,OAAA;EAAmB,IAAA;AAAA;AAAA,UAStD,0BAAA;EAlFf;EAoFA,aAAA;EAnFS;EAqFT,gBAAA;AAAA;AAAA,UAGe,cAAA;EAhBa;EAkB5B,GAAA;EACA,OAAA;EACA,IAAA;AAAA;;;;AAXF;;;;;AAOA;;;;;;iBA6BgB,mBAAA,CACd,MAAA,YACA,GAAA,EAAK,UAAA,EACL,IAAA,GAAM,0BAAA,GACL,cAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
//#region src/scope-migration.d.ts
|
|
2
|
+
interface ScopeMigrationOptions {
|
|
3
|
+
/** Classify only — collect + classify candidates, write nothing (STOP GATE). */
|
|
4
|
+
dryRun?: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface ScopeMigrationReport {
|
|
7
|
+
/** Which `SCOPE_TABLES` actually exist in this DB (CF lacks device_sync_state). */
|
|
8
|
+
tablesPresent: string[];
|
|
9
|
+
/** Whether the `shares` / `scope_meta` tables exist. */
|
|
10
|
+
hasShares: boolean;
|
|
11
|
+
hasScopeMeta: boolean;
|
|
12
|
+
/** Distinct candidate scopes seen across all sources. */
|
|
13
|
+
candidates: number;
|
|
14
|
+
/** Plaintext DID scopes that WILL be / WERE migrated (sorted). */
|
|
15
|
+
migrate: string[];
|
|
16
|
+
/** Non-DID scopes skipped: versioned / already-derived hash / bare / junk (sorted). */
|
|
17
|
+
skip: string[];
|
|
18
|
+
/** Count actually migrated (0 when dryRun). */
|
|
19
|
+
migrated: number;
|
|
20
|
+
/** Whether scope_meta was rebuilt (only when something migrated + table present). */
|
|
21
|
+
scopeMetaRebuilt: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Migrate (or, with `dryRun`, classify) all plaintext DID scopes in `db`.
|
|
25
|
+
*
|
|
26
|
+
* @param db the D1 database (or a compatible mock) — the bound runtime D1
|
|
27
|
+
* @param key the deployment HMAC secret bytes (from `decodeScopeHmacSecret`)
|
|
28
|
+
* @param opts `{ dryRun }` to classify without writing
|
|
29
|
+
*/
|
|
30
|
+
declare function migrateD1Scopes(db: D1Database, key: Uint8Array, opts?: ScopeMigrationOptions): Promise<ScopeMigrationReport>;
|
|
31
|
+
/** Classify distinct scope strings into migrate (plaintext DID) vs skip. */
|
|
32
|
+
declare function classifyScopes(scopes: string[]): {
|
|
33
|
+
migrate: string[];
|
|
34
|
+
skip: string[];
|
|
35
|
+
};
|
|
36
|
+
interface BuildD1MigrationSqlOptions {
|
|
37
|
+
/** Emit `UPDATE shares SET owner_did = …` (CF has a shares table). Default true. */
|
|
38
|
+
includeShares?: boolean;
|
|
39
|
+
/** Emit the scope_meta DELETE-stale + BACKFILL rebuild. Default true. */
|
|
40
|
+
includeScopeMeta?: boolean;
|
|
41
|
+
}
|
|
42
|
+
interface D1MigrationSql {
|
|
43
|
+
/** The `.sql` text to apply via `wrangler d1 execute --remote --file`. */
|
|
44
|
+
sql: string;
|
|
45
|
+
migrate: string[];
|
|
46
|
+
skip: string[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Generate the migration `.sql` for a REMOTE CF D1 (README §4.5 离线脚本形态).
|
|
50
|
+
*
|
|
51
|
+
* The HMAC is computed HERE (D1 SQL can't); the operator dumps the distinct
|
|
52
|
+
* scopes with `wrangler d1 execute --remote --json` and applies the emitted file
|
|
53
|
+
* with `wrangler d1 execute --remote --file`. Only plaintext DID scopes are
|
|
54
|
+
* rewritten — versioned `schema:…` / already-derived / junk are left out, so a
|
|
55
|
+
* re-apply is idempotent (their `WHERE scope = '<old DID>'` matches nothing).
|
|
56
|
+
*
|
|
57
|
+
* Statement order matters: all scope UPDATEs first, then the scope_meta rebuild
|
|
58
|
+
* (DELETE stale plaintext rows + BACKFILL derived counts from the now-moved
|
|
59
|
+
* entries). `entries` / `changelog` / `prefix_watermark` are CF's standard
|
|
60
|
+
* scope-bearing tables (migrations 0100–0107); `device_sync_state` is absent.
|
|
61
|
+
*/
|
|
62
|
+
declare function buildD1MigrationSql(scopes: string[], key: Uint8Array, opts?: BuildD1MigrationSqlOptions): D1MigrationSql;
|
|
63
|
+
//#endregion
|
|
64
|
+
export { BuildD1MigrationSqlOptions, D1MigrationSql, ScopeMigrationOptions, ScopeMigrationReport, buildD1MigrationSql, classifyScopes, migrateD1Scopes };
|
|
65
|
+
//# sourceMappingURL=scope-migration.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-migration.d.mts","names":[],"sources":["../src/scope-migration.ts"],"mappings":";UA2CiB,qBAAA;EAAA;EAEf,MAAA;AAAA;AAAA,UAGe,oBAAA;EAHT;EAKN,aAAA;EAFmC;EAInC,SAAA;EACA,YAAA;EAHA;EAKA,UAAA;EAFA;EAIA,OAAA;EAAA;EAEA,IAAA;EAEA;EAAA,QAAA;EAEgB;EAAhB,gBAAA;AAAA;;;;;;;;iBAuBoB,eAAA,CACpB,EAAA,EAAI,UAAA,EACJ,GAAA,EAAK,UAAA,EACL,IAAA,GAAM,qBAAA,GACL,OAAA,CAAQ,oBAAA;;iBAwEK,cAAA,CAAe,MAAA;EAAqB,OAAA;EAAmB,IAAA;AAAA;AAAA,UAStD,0BAAA;EAlFf;EAoFA,aAAA;EAnFS;EAqFT,gBAAA;AAAA;AAAA,UAGe,cAAA;EAhBa;EAkB5B,GAAA;EACA,OAAA;EACA,IAAA;AAAA;;;;AAXF;;;;;AAOA;;;;;;iBA6BgB,mBAAA,CACd,MAAA,YACA,GAAA,EAAK,UAAA,EACL,IAAA,GAAM,0BAAA,GACL,cAAA"}
|