@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,681 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_cid = require('./cid.cjs');
|
|
3
|
+
require('./mime-utils.cjs');
|
|
4
|
+
let _aigne_afs = require("@aigne/afs");
|
|
5
|
+
let ufo = require("ufo");
|
|
6
|
+
let _aigne_afs_provider_utils = require("@aigne/afs-provider-utils");
|
|
7
|
+
|
|
8
|
+
//#region src/remote-afs.ts
|
|
9
|
+
/**
|
|
10
|
+
* Loopback hosts that may be served over plain http (no HTTPS requirement).
|
|
11
|
+
* Covers `localhost`, the reserved `*.localhost` subdomains (RFC 6761 — always
|
|
12
|
+
* loopback, e.g. `aside.localhost:8787` for local multi-app dev where the
|
|
13
|
+
* subdomain selects the blocklet), and the IPv4/IPv6 loopback literals.
|
|
14
|
+
*/
|
|
15
|
+
function isLoopbackHost(hostname) {
|
|
16
|
+
const h = hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
17
|
+
return h === "localhost" || h.endsWith(".localhost") || h === "127.0.0.1" || h === "::1";
|
|
18
|
+
}
|
|
19
|
+
var RemoteUserSpaceAFS = class {
|
|
20
|
+
name = "remote-user-space";
|
|
21
|
+
baseUrl;
|
|
22
|
+
token;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
const url = new URL(options.baseUrl);
|
|
25
|
+
if (url.protocol !== "https:" && !isLoopbackHost(url.hostname)) throw new Error(`HTTPS required for remote connections (got ${url.protocol}//${url.hostname})`);
|
|
26
|
+
this.baseUrl = options.baseUrl;
|
|
27
|
+
this.token = options.token;
|
|
28
|
+
}
|
|
29
|
+
apiUrl(path, params) {
|
|
30
|
+
const url = (0, ufo.joinURL)(this.baseUrl, "/api/space/", (0, ufo.encodePath)(path));
|
|
31
|
+
if (!params) return url;
|
|
32
|
+
return `${url}?${new URLSearchParams(params).toString()}`;
|
|
33
|
+
}
|
|
34
|
+
headers() {
|
|
35
|
+
return { Authorization: `Bearer ${this.token}` };
|
|
36
|
+
}
|
|
37
|
+
async handleResponse(res, path) {
|
|
38
|
+
if (res.ok) return res.json();
|
|
39
|
+
if (res.status === 404) throw new _aigne_afs.AFSNotFoundError(path);
|
|
40
|
+
if (res.status === 401) throw new Error("Authentication failed: check your access token");
|
|
41
|
+
if (res.status === 409) await this.handle409(res, path);
|
|
42
|
+
const errorMsg = await this.parseErrorBody(res);
|
|
43
|
+
throw new Error(`Remote AFS error at ${path}: ${errorMsg}`);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parse a 409 response body and throw the appropriate AFS error:
|
|
47
|
+
* - `{ error: "if_match_failed", currentCid, currentMtime, currentDeviceId }` → AFSConflictError
|
|
48
|
+
* - `{ requireFullResync: true, compactedBelowSeq }` → AFSCompactedError
|
|
49
|
+
* - Otherwise → generic error
|
|
50
|
+
*/
|
|
51
|
+
async handle409(res, path) {
|
|
52
|
+
let body;
|
|
53
|
+
try {
|
|
54
|
+
body = await res.json();
|
|
55
|
+
} catch {
|
|
56
|
+
throw new Error(`Remote AFS 409 at ${path}`);
|
|
57
|
+
}
|
|
58
|
+
if (body.requireFullResync === true) {
|
|
59
|
+
const seq = typeof body.compactedBelowSeq === "number" ? body.compactedBelowSeq : 0;
|
|
60
|
+
throw new _aigne_afs.AFSCompactedError(path, String(seq));
|
|
61
|
+
}
|
|
62
|
+
if (body.code === "AFS_CONFLICT" || body.error === "if_match_failed" || "currentCid" in body) throw new _aigne_afs.AFSConflictError(path, {
|
|
63
|
+
cid: typeof body.currentCid === "string" ? body.currentCid : null,
|
|
64
|
+
mtime: typeof body.currentMtime === "number" ? body.currentMtime : null,
|
|
65
|
+
deviceId: typeof body.currentDeviceId === "string" ? body.currentDeviceId : null
|
|
66
|
+
});
|
|
67
|
+
throw new Error(`Remote AFS 409 at ${path}: ${JSON.stringify(body)}`);
|
|
68
|
+
}
|
|
69
|
+
async parseErrorBody(res) {
|
|
70
|
+
try {
|
|
71
|
+
return (await res.json()).error || `HTTP ${res.status}`;
|
|
72
|
+
} catch {
|
|
73
|
+
return `HTTP ${res.status}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async list(path, options) {
|
|
77
|
+
const params = { op: "list" };
|
|
78
|
+
const normPath = path.startsWith("/") ? path.slice(1) : path;
|
|
79
|
+
const isChangelog = normPath === ".changelog" || normPath.startsWith(".changelog/");
|
|
80
|
+
if (options?.maxDepth === -1) {
|
|
81
|
+
if (isChangelog) throw new _aigne_afs.AFSValidationError(".changelog path does not support maxDepth=-1 (changelog uses cursor-based incremental access)");
|
|
82
|
+
if (options.limit !== void 0 && Number.isFinite(options.limit) || options.offset !== void 0 && Number.isFinite(options.offset) || options.cursor !== void 0) throw new _aigne_afs.AFSValidationError("list with maxDepth=-1 cannot be combined with cursor, limit, or offset");
|
|
83
|
+
}
|
|
84
|
+
if (options?.maxDepth !== void 0) params.maxDepth = String(options.maxDepth);
|
|
85
|
+
if (isChangelog && options?.cursor !== void 0) params.cursor = String(options.cursor);
|
|
86
|
+
if (!isChangelog) {
|
|
87
|
+
if (options?.limit !== void 0 && Number.isFinite(options.limit)) params.limit = String(options.limit);
|
|
88
|
+
if (options?.offset !== void 0 && Number.isFinite(options.offset)) params.offset = String(options.offset);
|
|
89
|
+
}
|
|
90
|
+
const res = await fetch(this.apiUrl(path, params), { headers: this.headers() });
|
|
91
|
+
return this.handleResponse(res, path);
|
|
92
|
+
}
|
|
93
|
+
async read(path) {
|
|
94
|
+
const normPath = path.startsWith("/") ? path.slice(1) : path;
|
|
95
|
+
if (normPath.startsWith(".objects/")) return this.readObject(path, normPath);
|
|
96
|
+
const res = await fetch(this.apiUrl(path), { headers: this.headers() });
|
|
97
|
+
if (!res.ok) return this.handleResponse(res, path);
|
|
98
|
+
const contentType = res.headers.get("Content-Type") || "";
|
|
99
|
+
if (!res.headers.has("X-AFS-Kind") && contentType.includes("application/json")) return res.json();
|
|
100
|
+
const meta = {};
|
|
101
|
+
const kind = res.headers.get("X-AFS-Kind");
|
|
102
|
+
const cid = res.headers.get("X-AFS-CID");
|
|
103
|
+
const size = res.headers.get("X-AFS-Size");
|
|
104
|
+
const mimeType = res.headers.get("X-AFS-MimeType");
|
|
105
|
+
const childrenCount = res.headers.get("X-AFS-ChildrenCount");
|
|
106
|
+
meta.kind = kind || "did-space:file";
|
|
107
|
+
if (cid) meta.cid = cid;
|
|
108
|
+
if (size) meta.size = Number(size);
|
|
109
|
+
if (mimeType) meta.mimeType = mimeType;
|
|
110
|
+
if (childrenCount != null) meta.childrenCount = Number(childrenCount);
|
|
111
|
+
const content = (0, _aigne_afs_provider_utils.isTextMime)(mimeType || (contentType.split(";")[0] ?? "").trim() || void 0) ? await res.text() : await res.arrayBuffer();
|
|
112
|
+
const createdAt = res.headers.get("X-AFS-CreatedAt");
|
|
113
|
+
const updatedAt = res.headers.get("X-AFS-UpdatedAt");
|
|
114
|
+
return { data: {
|
|
115
|
+
id: path,
|
|
116
|
+
path,
|
|
117
|
+
content,
|
|
118
|
+
meta,
|
|
119
|
+
createdAt: createdAt ? new Date(createdAt) : void 0,
|
|
120
|
+
updatedAt: updatedAt ? new Date(updatedAt) : void 0
|
|
121
|
+
} };
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Task 1.3: read a content-addressed object by path `.objects/{cid}`.
|
|
125
|
+
* Calls `GET /api/space/.objects/{cid}`, reads raw bytes, then recomputes
|
|
126
|
+
* the CID to verify integrity before returning.
|
|
127
|
+
*/
|
|
128
|
+
async readObject(path, normPath) {
|
|
129
|
+
const requestedCid = normPath.slice(9);
|
|
130
|
+
const res = await fetch(this.apiUrl(path), { headers: this.headers() });
|
|
131
|
+
if (!res.ok) return this.handleResponse(res, path);
|
|
132
|
+
const ab = await res.arrayBuffer();
|
|
133
|
+
const bytes = new Uint8Array(ab);
|
|
134
|
+
const actualCid = await require_cid.computeCID(bytes);
|
|
135
|
+
if (actualCid !== requestedCid) throw new Error(`read .objects: CID mismatch (requested ${requestedCid}, got ${actualCid})`);
|
|
136
|
+
return { data: {
|
|
137
|
+
id: path,
|
|
138
|
+
path,
|
|
139
|
+
content: bytes,
|
|
140
|
+
meta: {
|
|
141
|
+
kind: "did-space:object",
|
|
142
|
+
cid: requestedCid,
|
|
143
|
+
size: bytes.length
|
|
144
|
+
}
|
|
145
|
+
} };
|
|
146
|
+
}
|
|
147
|
+
async write(path, payload) {
|
|
148
|
+
const content = payload.content;
|
|
149
|
+
const extra = payload.meta?.extra;
|
|
150
|
+
const extraHeaders = {};
|
|
151
|
+
if (extra) {
|
|
152
|
+
if (typeof extra.contentCid === "string") extraHeaders["X-Content-CID"] = extra.contentCid;
|
|
153
|
+
if (typeof extra.deviceId === "string") extraHeaders["X-Device-Id"] = extra.deviceId;
|
|
154
|
+
if (typeof extra.mtime === "number") extraHeaders["X-Mtime"] = String(extra.mtime);
|
|
155
|
+
if (typeof extra.ifMatch === "string") extraHeaders["If-Match"] = extra.ifMatch;
|
|
156
|
+
}
|
|
157
|
+
if (content instanceof ArrayBuffer || content instanceof Uint8Array) {
|
|
158
|
+
const body$1 = content instanceof Uint8Array ? content.buffer.slice(content.byteOffset, content.byteOffset + content.byteLength) : content;
|
|
159
|
+
const res$1 = await fetch(this.apiUrl(path), {
|
|
160
|
+
method: "PUT",
|
|
161
|
+
headers: {
|
|
162
|
+
...this.headers(),
|
|
163
|
+
"Content-Type": "application/octet-stream",
|
|
164
|
+
...extraHeaders
|
|
165
|
+
},
|
|
166
|
+
body: body$1
|
|
167
|
+
});
|
|
168
|
+
return this.handleResponse(res$1, path);
|
|
169
|
+
}
|
|
170
|
+
const isString = typeof content === "string";
|
|
171
|
+
const body = isString ? content : JSON.stringify(content);
|
|
172
|
+
const mimeType = isString ? "text/plain" : "application/json";
|
|
173
|
+
const res = await fetch(this.apiUrl(path), {
|
|
174
|
+
method: "PUT",
|
|
175
|
+
headers: {
|
|
176
|
+
...this.headers(),
|
|
177
|
+
"Content-Type": mimeType,
|
|
178
|
+
...extraHeaders
|
|
179
|
+
},
|
|
180
|
+
body
|
|
181
|
+
});
|
|
182
|
+
return this.handleResponse(res, path);
|
|
183
|
+
}
|
|
184
|
+
async delete(path, opts) {
|
|
185
|
+
const meta = opts?.meta;
|
|
186
|
+
const extraHeaders = {};
|
|
187
|
+
if (meta) {
|
|
188
|
+
if (typeof meta.deviceId === "string") extraHeaders["X-Device-Id"] = meta.deviceId;
|
|
189
|
+
if (typeof meta.mtime === "number") extraHeaders["X-Mtime"] = String(meta.mtime);
|
|
190
|
+
if (typeof meta.ifMatch === "string") extraHeaders["If-Match"] = meta.ifMatch;
|
|
191
|
+
}
|
|
192
|
+
const res = await fetch(this.apiUrl(path), {
|
|
193
|
+
method: "DELETE",
|
|
194
|
+
headers: {
|
|
195
|
+
...this.headers(),
|
|
196
|
+
...extraHeaders
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
return this.handleResponse(res, path);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
/** Thrown when the server does not support the batch wire ops (old daemon). */
|
|
203
|
+
var BatchUnsupportedError = class extends Error {
|
|
204
|
+
constructor() {
|
|
205
|
+
super("server does not support batch wire ops");
|
|
206
|
+
this.name = "BatchUnsupportedError";
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Envelope-level BATCH_OVER_BUDGET / PAYLOAD_TOO_LARGE — zero entries
|
|
211
|
+
* executed; the engine halves the chunk and retries (design §7.3). MUST NOT
|
|
212
|
+
* trip the capability-fallback memory.
|
|
213
|
+
*/
|
|
214
|
+
var BatchOverBudgetError = class extends Error {
|
|
215
|
+
constructor(message) {
|
|
216
|
+
super(message);
|
|
217
|
+
this.name = "BatchOverBudgetError";
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* SyncCloudAFS over the afs-rpc wire (`POST /api/afs/rpc`) — the transport
|
|
222
|
+
* the production daemon/worker actually serve (the legacy `/api/space` REST
|
|
223
|
+
* server is gone; `RemoteUserSpaceAFS` above survives only for the
|
|
224
|
+
* export/import CLI against legacy hosts).
|
|
225
|
+
*
|
|
226
|
+
* Sync paths are fragment-root-relative; the wire allowlist admits only
|
|
227
|
+
* `/user/**` mutations, so every path is mapped through `/user` on the way
|
|
228
|
+
* out and stripped on the way back.
|
|
229
|
+
*
|
|
230
|
+
* Batch (P4): `batchWrite`/`batchDelete`/`batchRead` send one wire envelope
|
|
231
|
+
* each (wire-contract §9) and restore per-entry results to the single-op
|
|
232
|
+
* error types (`AFSConflictError` with the triple, `BATCH_TAIL_SKIPPED`
|
|
233
|
+
* passthrough). Capability fallback: the FIRST envelope answered with the
|
|
234
|
+
* old server's exact `Unsupported op 'batch…'` 400 marks this INSTANCE as
|
|
235
|
+
* batch-unsupported (`supportsBatch === false`) and throws
|
|
236
|
+
* {@link BatchUnsupportedError}; the engine then stays on the single-op
|
|
237
|
+
* path for the rest of the instance's life. Any other 400 (e.g.
|
|
238
|
+
* BATCH_OVER_BUDGET) does NOT trip the memory.
|
|
239
|
+
*/
|
|
240
|
+
var RpcUserSpaceAFS = class {
|
|
241
|
+
name = "rpc-user-space";
|
|
242
|
+
baseUrl;
|
|
243
|
+
token;
|
|
244
|
+
blocklet;
|
|
245
|
+
sessionId;
|
|
246
|
+
extraHeaders;
|
|
247
|
+
/** null = unknown (no batch envelope sent yet); set on first evidence. */
|
|
248
|
+
batchSupported = null;
|
|
249
|
+
constructor(options) {
|
|
250
|
+
const url = new URL(options.baseUrl);
|
|
251
|
+
if (url.protocol !== "https:" && !isLoopbackHost(url.hostname)) throw new Error(`HTTPS required for remote connections (got ${url.protocol}//${url.hostname})`);
|
|
252
|
+
this.baseUrl = options.baseUrl;
|
|
253
|
+
this.token = options.token;
|
|
254
|
+
this.blocklet = options.blocklet;
|
|
255
|
+
this.sessionId = options.sessionId;
|
|
256
|
+
this.extraHeaders = options.extraHeaders ?? {};
|
|
257
|
+
}
|
|
258
|
+
/** Instance-scoped capability memory (per-server, design §7.1). */
|
|
259
|
+
get supportsBatch() {
|
|
260
|
+
return this.batchSupported;
|
|
261
|
+
}
|
|
262
|
+
wirePath(path) {
|
|
263
|
+
const p = path.startsWith("/") ? path : `/${path}`;
|
|
264
|
+
return `/user${p === "/" ? "" : p}`;
|
|
265
|
+
}
|
|
266
|
+
stripUser(path) {
|
|
267
|
+
return path.startsWith("/user/") ? path.slice(5) : path;
|
|
268
|
+
}
|
|
269
|
+
async rpc(body) {
|
|
270
|
+
const res = await fetch((0, ufo.joinURL)(this.baseUrl, "/api/afs/rpc"), {
|
|
271
|
+
method: "POST",
|
|
272
|
+
headers: {
|
|
273
|
+
"content-type": "application/json",
|
|
274
|
+
Authorization: `Bearer ${this.token}`,
|
|
275
|
+
...this.extraHeaders
|
|
276
|
+
},
|
|
277
|
+
body: JSON.stringify({
|
|
278
|
+
blocklet: this.blocklet,
|
|
279
|
+
...this.sessionId ? { sessionId: this.sessionId } : {},
|
|
280
|
+
...body
|
|
281
|
+
})
|
|
282
|
+
});
|
|
283
|
+
let json;
|
|
284
|
+
try {
|
|
285
|
+
json = await res.json();
|
|
286
|
+
} catch {
|
|
287
|
+
json = {
|
|
288
|
+
ok: false,
|
|
289
|
+
error: `non-JSON response (HTTP ${res.status})`
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
status: res.status,
|
|
294
|
+
json
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
/** Map a non-OK single-op wire response onto the AFS error types. */
|
|
298
|
+
throwWireError(status, json, path) {
|
|
299
|
+
if (status === 404) throw new _aigne_afs.AFSNotFoundError(path);
|
|
300
|
+
if (status === 401) throw new Error("Authentication failed: check your access token");
|
|
301
|
+
if (status === 409) this.throwConflict(json, path);
|
|
302
|
+
if (json.requireFullResync === true) throw new _aigne_afs.AFSCompactedError(path, String(json.compactedBelowSeq ?? 0));
|
|
303
|
+
throw new Error(`afs-rpc error at ${path}: ${String(json.error ?? `HTTP ${status}`)}`);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* 409 → AFSConflictError with the triple. Keyed on `code: "AFS_CONFLICT"`
|
|
307
|
+
* OR triple-field presence — NEVER the legacy `error === "if_match_failed"`
|
|
308
|
+
* string (the T4.1 存量 bug: the wire sends the stable code, see
|
|
309
|
+
* afs-rpc-wire.ts WIRE_ERROR_CODES.conflict; Swift's throwConflict already
|
|
310
|
+
* keys on the code).
|
|
311
|
+
*/
|
|
312
|
+
throwConflict(json, path) {
|
|
313
|
+
if (json.code === "AFS_CONFLICT" || "currentCid" in json) throw new _aigne_afs.AFSConflictError(path, {
|
|
314
|
+
cid: typeof json.currentCid === "string" ? json.currentCid : null,
|
|
315
|
+
mtime: typeof json.currentMtime === "number" ? json.currentMtime : null,
|
|
316
|
+
deviceId: typeof json.currentDeviceId === "string" ? json.currentDeviceId : null
|
|
317
|
+
});
|
|
318
|
+
if (json.requireFullResync === true) throw new _aigne_afs.AFSCompactedError(path, String(json.compactedBelowSeq ?? 0));
|
|
319
|
+
throw new Error(`afs-rpc 409 at ${path}: ${JSON.stringify(json)}`);
|
|
320
|
+
}
|
|
321
|
+
async list(path, options) {
|
|
322
|
+
const opts = {};
|
|
323
|
+
if (options?.cursor !== void 0) opts.cursor = options.cursor;
|
|
324
|
+
if (options?.limit !== void 0 && Number.isFinite(options.limit)) opts.limit = options.limit;
|
|
325
|
+
if (options?.maxDepth !== void 0) opts.maxDepth = options.maxDepth;
|
|
326
|
+
const { status, json } = await this.rpc({
|
|
327
|
+
type: "list",
|
|
328
|
+
path: this.wirePath(path),
|
|
329
|
+
...Object.keys(opts).length ? { options: opts } : {}
|
|
330
|
+
});
|
|
331
|
+
if (status !== 200 || json.ok !== true) this.throwWireError(status, json, path);
|
|
332
|
+
const data = json.data ?? [];
|
|
333
|
+
return {
|
|
334
|
+
data: data.map((e) => ({
|
|
335
|
+
...e,
|
|
336
|
+
path: this.stripUser(String(e.path ?? ""))
|
|
337
|
+
})),
|
|
338
|
+
total: typeof json.total === "number" ? json.total : data.length,
|
|
339
|
+
meta: json.meta,
|
|
340
|
+
liveSeq: json.liveSeq
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
async read(path) {
|
|
344
|
+
const normPath = path.startsWith("/") ? path.slice(1) : path;
|
|
345
|
+
const isObject = normPath.startsWith(".objects/");
|
|
346
|
+
const { status, json } = await this.rpc({
|
|
347
|
+
type: "read",
|
|
348
|
+
path: this.wirePath(path)
|
|
349
|
+
});
|
|
350
|
+
if (status !== 200 || json.ok !== true) this.throwWireError(status, json, path);
|
|
351
|
+
const data = json.data ?? {};
|
|
352
|
+
let content = data.content;
|
|
353
|
+
if (data.encoding === "base64" && typeof content === "string") content = decodeBase64ToBytes(content);
|
|
354
|
+
if (isObject) {
|
|
355
|
+
const requestedCid = normPath.slice(9);
|
|
356
|
+
const bytes = content instanceof Uint8Array ? content : new TextEncoder().encode(String(content ?? ""));
|
|
357
|
+
const actualCid = await require_cid.computeCID(bytes);
|
|
358
|
+
if (actualCid !== requestedCid) throw new Error(`read .objects: CID mismatch (requested ${requestedCid}, got ${actualCid})`);
|
|
359
|
+
content = bytes;
|
|
360
|
+
}
|
|
361
|
+
return { data: {
|
|
362
|
+
...data,
|
|
363
|
+
path: this.stripUser(String(data.path ?? path)),
|
|
364
|
+
content
|
|
365
|
+
} };
|
|
366
|
+
}
|
|
367
|
+
async write(path, payload) {
|
|
368
|
+
const extra = payload.meta?.extra;
|
|
369
|
+
const content = payload.content;
|
|
370
|
+
const bytes = content instanceof Uint8Array ? content : content instanceof ArrayBuffer ? new Uint8Array(content) : new TextEncoder().encode(typeof content === "string" ? content : JSON.stringify(content));
|
|
371
|
+
const options = {};
|
|
372
|
+
const meta = {};
|
|
373
|
+
if (typeof extra?.deviceId === "string") meta.deviceId = extra.deviceId;
|
|
374
|
+
if (typeof extra?.mtime === "number") meta.mtime = extra.mtime;
|
|
375
|
+
if (Object.keys(meta).length) options.meta = meta;
|
|
376
|
+
if (typeof extra?.ifMatch === "string") options.ifMatch = extra.ifMatch;
|
|
377
|
+
const { extra: _extra, ...appMeta } = payload.meta ?? {};
|
|
378
|
+
const { status, json } = await this.rpc({
|
|
379
|
+
type: "write",
|
|
380
|
+
path: this.wirePath(path),
|
|
381
|
+
content: encodeBytesToBase64(bytes),
|
|
382
|
+
encoding: "base64",
|
|
383
|
+
...appMeta && Object.keys(appMeta).length ? { meta: appMeta } : {},
|
|
384
|
+
...Object.keys(options).length ? { options } : {}
|
|
385
|
+
});
|
|
386
|
+
if (status !== 200 || json.ok !== true) this.throwWireError(status, json, path);
|
|
387
|
+
return { data: json.data };
|
|
388
|
+
}
|
|
389
|
+
async delete(path, opts) {
|
|
390
|
+
const meta = opts?.meta;
|
|
391
|
+
const wireMeta = {};
|
|
392
|
+
if (typeof meta?.deviceId === "string") wireMeta.deviceId = meta.deviceId;
|
|
393
|
+
if (typeof meta?.mtime === "number") wireMeta.mtime = meta.mtime;
|
|
394
|
+
if (typeof meta?.ifMatch === "string") wireMeta.ifMatch = meta.ifMatch;
|
|
395
|
+
const { status, json } = await this.rpc({
|
|
396
|
+
type: "delete",
|
|
397
|
+
path: this.wirePath(path),
|
|
398
|
+
...Object.keys(wireMeta).length ? { options: { meta: wireMeta } } : {}
|
|
399
|
+
});
|
|
400
|
+
if (status !== 200 || json.ok !== true) this.throwWireError(status, json, path);
|
|
401
|
+
return json.data;
|
|
402
|
+
}
|
|
403
|
+
/** Detect the old server's exact "unsupported batch op" 400 (design T4.2):
|
|
404
|
+
* ONLY this text trips the per-instance fallback memory. */
|
|
405
|
+
checkBatchUnsupported(status, json) {
|
|
406
|
+
if (status === 400 && typeof json.error === "string" && /Unsupported op 'batch/.test(json.error)) {
|
|
407
|
+
this.batchSupported = false;
|
|
408
|
+
throw new BatchUnsupportedError();
|
|
409
|
+
}
|
|
410
|
+
if (json.code === "BATCH_OVER_BUDGET" || json.code === "PAYLOAD_TOO_LARGE") throw new BatchOverBudgetError(String(json.error ?? json.code));
|
|
411
|
+
}
|
|
412
|
+
restoreBatchResults(rawResults, entryPaths) {
|
|
413
|
+
if (!Array.isArray(rawResults) || rawResults.length !== entryPaths.length) throw new Error(`afs-rpc batch: results length ${Array.isArray(rawResults) ? rawResults.length : "?"} != entries length ${entryPaths.length}`);
|
|
414
|
+
return rawResults.map((raw, i) => {
|
|
415
|
+
const r = raw ?? {};
|
|
416
|
+
const status = typeof r.status === "number" ? r.status : 500;
|
|
417
|
+
const ok = r.ok === true;
|
|
418
|
+
const out = {
|
|
419
|
+
path: entryPaths[i],
|
|
420
|
+
success: ok,
|
|
421
|
+
status
|
|
422
|
+
};
|
|
423
|
+
if (ok) {
|
|
424
|
+
out.data = r.data;
|
|
425
|
+
return out;
|
|
426
|
+
}
|
|
427
|
+
out.error = typeof r.error === "string" ? r.error : void 0;
|
|
428
|
+
out.code = typeof r.code === "string" ? r.code : void 0;
|
|
429
|
+
if (r.missing === true) out.missing = true;
|
|
430
|
+
if (status === 409 || out.code === "AFS_CONFLICT") out.conflict = {
|
|
431
|
+
currentCid: typeof r.currentCid === "string" ? r.currentCid : null,
|
|
432
|
+
currentMtime: typeof r.currentMtime === "number" ? r.currentMtime : null,
|
|
433
|
+
currentDeviceId: typeof r.currentDeviceId === "string" ? r.currentDeviceId : null
|
|
434
|
+
};
|
|
435
|
+
return out;
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* One wire envelope per call — entries in the CORE batch shape
|
|
440
|
+
* (`AFSBatchWriteEntry`: `content.content` bytes + `options.ifMatch` /
|
|
441
|
+
* `options.meta` provenance), paths fragment-relative.
|
|
442
|
+
*/
|
|
443
|
+
async batchWrite(entries) {
|
|
444
|
+
const wireEntries = entries.map((e) => {
|
|
445
|
+
const payload = e.content?.content;
|
|
446
|
+
const bytes = payload instanceof Uint8Array ? payload : payload instanceof ArrayBuffer ? new Uint8Array(payload) : new TextEncoder().encode(typeof payload === "string" ? payload : JSON.stringify(payload ?? ""));
|
|
447
|
+
const options = e.options;
|
|
448
|
+
const meta = {};
|
|
449
|
+
if (typeof options?.meta?.deviceId === "string") meta.deviceId = options.meta.deviceId;
|
|
450
|
+
if (typeof options?.meta?.mtime === "number") meta.mtime = options.meta.mtime;
|
|
451
|
+
const wireOptions = {};
|
|
452
|
+
if (Object.keys(meta).length) wireOptions.meta = meta;
|
|
453
|
+
if (typeof options?.ifMatch === "string") wireOptions.ifMatch = options.ifMatch;
|
|
454
|
+
const appMeta = e.content?.meta;
|
|
455
|
+
return {
|
|
456
|
+
path: this.wirePath(e.path),
|
|
457
|
+
content: encodeBytesToBase64(bytes),
|
|
458
|
+
encoding: "base64",
|
|
459
|
+
...appMeta && Object.keys(appMeta).length ? { meta: appMeta } : {},
|
|
460
|
+
...Object.keys(wireOptions).length ? { options: wireOptions } : {}
|
|
461
|
+
};
|
|
462
|
+
});
|
|
463
|
+
const { status, json } = await this.rpc({
|
|
464
|
+
type: "batchWrite",
|
|
465
|
+
entries: wireEntries
|
|
466
|
+
});
|
|
467
|
+
this.checkBatchUnsupported(status, json);
|
|
468
|
+
if (status !== 200 || json.ok !== true) this.throwWireError(status, json, "batchWrite");
|
|
469
|
+
this.batchSupported = true;
|
|
470
|
+
return {
|
|
471
|
+
results: this.restoreBatchResults(json.results, entries.map((e) => e.path)),
|
|
472
|
+
succeeded: Number(json.succeeded ?? 0),
|
|
473
|
+
failed: Number(json.failed ?? 0)
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
/** Core-shaped delete entries (`options.meta.{ifMatch,deviceId,mtime}`). */
|
|
477
|
+
async batchDelete(entries) {
|
|
478
|
+
const wireEntries = entries.map((e) => {
|
|
479
|
+
const m = e.options?.meta;
|
|
480
|
+
const meta = {};
|
|
481
|
+
if (typeof m?.deviceId === "string") meta.deviceId = m.deviceId;
|
|
482
|
+
if (typeof m?.mtime === "number") meta.mtime = m.mtime;
|
|
483
|
+
if (typeof m?.ifMatch === "string") meta.ifMatch = m.ifMatch;
|
|
484
|
+
return {
|
|
485
|
+
path: this.wirePath(e.path),
|
|
486
|
+
...Object.keys(meta).length ? { options: { meta } } : {}
|
|
487
|
+
};
|
|
488
|
+
});
|
|
489
|
+
const { status, json } = await this.rpc({
|
|
490
|
+
type: "batchDelete",
|
|
491
|
+
entries: wireEntries
|
|
492
|
+
});
|
|
493
|
+
this.checkBatchUnsupported(status, json);
|
|
494
|
+
if (status !== 200 || json.ok !== true) this.throwWireError(status, json, "batchDelete");
|
|
495
|
+
this.batchSupported = true;
|
|
496
|
+
return {
|
|
497
|
+
results: this.restoreBatchResults(json.results, entries.map((e) => e.path)),
|
|
498
|
+
succeeded: Number(json.succeeded ?? 0),
|
|
499
|
+
failed: Number(json.failed ?? 0)
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
/** Entries are absolute wire paths already (e.g. "/.objects/{cid}" reads). */
|
|
503
|
+
async batchRead(entries) {
|
|
504
|
+
const wireEntries = entries.map((e) => ({
|
|
505
|
+
path: this.wirePath(e.path),
|
|
506
|
+
...e.optional ? { optional: true } : {}
|
|
507
|
+
}));
|
|
508
|
+
const { status, json } = await this.rpc({
|
|
509
|
+
type: "batchRead",
|
|
510
|
+
entries: wireEntries
|
|
511
|
+
});
|
|
512
|
+
this.checkBatchUnsupported(status, json);
|
|
513
|
+
if (status !== 200 || json.ok !== true) this.throwWireError(status, json, "batchRead");
|
|
514
|
+
this.batchSupported = true;
|
|
515
|
+
const results = this.restoreBatchResults(json.results, entries.map((e) => e.path));
|
|
516
|
+
for (const r of results) {
|
|
517
|
+
const content = r.data?.content;
|
|
518
|
+
if (r.data?.encoding === "base64" && typeof content === "string") r.data.content = decodeBase64ToBytes(content);
|
|
519
|
+
}
|
|
520
|
+
return {
|
|
521
|
+
results,
|
|
522
|
+
succeeded: Number(json.succeeded ?? 0),
|
|
523
|
+
failed: Number(json.failed ?? 0)
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Probe whether the server's `/user` space advertises grant capability
|
|
528
|
+
* (P2 T2.5). Reads the `.actions` catalogue and checks the prepare-upload
|
|
529
|
+
* entry's `meta.grantCapability`. `false` on Node (fallback-only) or an old
|
|
530
|
+
* server with no upload actions → the engine stays on batchWrite.
|
|
531
|
+
*/
|
|
532
|
+
async uploadGrantCapability() {
|
|
533
|
+
const { status, json } = await this.rpc({
|
|
534
|
+
type: "list",
|
|
535
|
+
path: this.wirePath("/.actions")
|
|
536
|
+
});
|
|
537
|
+
if (status !== 200 || json.ok !== true) return false;
|
|
538
|
+
return (json.data ?? []).find((e) => e.id === "prepare-upload")?.meta?.grantCapability === true;
|
|
539
|
+
}
|
|
540
|
+
/** Run a `/user/.actions/<name>` exec. Throws `BatchUnsupportedError` when the
|
|
541
|
+
* server lacks the action (old server) so the engine falls back. */
|
|
542
|
+
async execAction(name, args) {
|
|
543
|
+
const { status, json } = await this.rpc({
|
|
544
|
+
type: "exec",
|
|
545
|
+
path: this.wirePath(`/.actions/${name}`),
|
|
546
|
+
args
|
|
547
|
+
});
|
|
548
|
+
if (status === 404 || status === 501) throw new BatchUnsupportedError();
|
|
549
|
+
if (status !== 200 || json.ok !== true) throw new Error(`afs-rpc exec ${name} failed: ${String(json.error ?? json.message ?? status)}`);
|
|
550
|
+
return json.data ?? {};
|
|
551
|
+
}
|
|
552
|
+
async prepareUpload(entries) {
|
|
553
|
+
return await this.execAction("prepare-upload", {
|
|
554
|
+
entries,
|
|
555
|
+
strategy: "auto"
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
async commitUpload(sessionId, entries) {
|
|
559
|
+
const data = await this.execAction("commit-upload", {
|
|
560
|
+
sessionId,
|
|
561
|
+
entries
|
|
562
|
+
});
|
|
563
|
+
const results = (data.results ?? []).map((r) => commitResultToBatchEntry(r));
|
|
564
|
+
let okCount = 0;
|
|
565
|
+
for (const r of results) if (r.success) okCount++;
|
|
566
|
+
return {
|
|
567
|
+
results,
|
|
568
|
+
succeeded: Number(data.succeeded ?? okCount),
|
|
569
|
+
failed: Number(data.failed ?? results.length - okCount)
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
/** Abort a prepared session (staged objects → GC). No TS engine call site yet
|
|
573
|
+
* — the engine bails via BatchUnsupportedError on grant loss; exposed for
|
|
574
|
+
* protocol parity (Swift mirror) + a future P4 abort-on-timeout path. */
|
|
575
|
+
async abortUpload(sessionId) {
|
|
576
|
+
await this.execAction("abort-upload", { sessionId });
|
|
577
|
+
}
|
|
578
|
+
/** Out-of-band PUT of object bytes via a presigned grant. Returns the HTTP
|
|
579
|
+
* status (commit-after-200: the engine only commits entries that got 200). */
|
|
580
|
+
async uploadObject(grant, bytes) {
|
|
581
|
+
const res = await fetch(grant.url, {
|
|
582
|
+
method: grant.method,
|
|
583
|
+
headers: grant.signedHeaders,
|
|
584
|
+
body: bytes
|
|
585
|
+
});
|
|
586
|
+
if (!res.ok) await res.text().catch(() => void 0);
|
|
587
|
+
return res.status;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Probe whether the server's `/user` space advertises GET-grant capability
|
|
591
|
+
* (P2 T2.4). Reads the `.actions` catalogue and checks the prepare-download
|
|
592
|
+
* entry's INDEPENDENT `meta.downloadGrantCapability` (NOT the upload
|
|
593
|
+
* `grantCapability`). `false` on Node (fallback-only) or an old server → the
|
|
594
|
+
* engine stays on batchRead.
|
|
595
|
+
*/
|
|
596
|
+
async downloadGrantCapability() {
|
|
597
|
+
const { status, json } = await this.rpc({
|
|
598
|
+
type: "list",
|
|
599
|
+
path: this.wirePath("/.actions")
|
|
600
|
+
});
|
|
601
|
+
if (status !== 200 || json.ok !== true) return false;
|
|
602
|
+
return (json.data ?? []).find((e) => e.id === "prepare-download")?.meta?.downloadGrantCapability === true;
|
|
603
|
+
}
|
|
604
|
+
/** Run `prepare-download` — mints GET grants for the referenced cids. Throws
|
|
605
|
+
* `BatchUnsupportedError` when the server lacks the action (old server). */
|
|
606
|
+
async prepareDownload(entries) {
|
|
607
|
+
return await this.execAction("prepare-download", { entries });
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Out-of-band GET of object bytes via a presigned grant (content leaves R2
|
|
611
|
+
* directly — never through the Worker / base64). Returns the raw bytes on
|
|
612
|
+
* 200. A 401/403 means the grant was rejected (token lacks GetObject / bad
|
|
613
|
+
* signature) → throws {@link DownloadForbiddenError} so the engine flips the
|
|
614
|
+
* whole session to batchRead (runtime fallback-on-403, §7.3). Any other
|
|
615
|
+
* non-2xx (404 dangling / 5xx) throws a generic Error — the engine leaves the
|
|
616
|
+
* cid unfilled so the existing missing-object path handles it.
|
|
617
|
+
*/
|
|
618
|
+
async downloadObject(grant) {
|
|
619
|
+
const res = await fetch(grant.url, { method: grant.method });
|
|
620
|
+
if (res.status === 401 || res.status === 403) {
|
|
621
|
+
await res.body?.cancel().catch(() => void 0);
|
|
622
|
+
throw new DownloadForbiddenError(res.status);
|
|
623
|
+
}
|
|
624
|
+
if (!res.ok) {
|
|
625
|
+
await res.body?.cancel().catch(() => void 0);
|
|
626
|
+
throw new Error(`downloadObject ${grant.method} failed: ${res.status}`);
|
|
627
|
+
}
|
|
628
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
/**
|
|
632
|
+
* A presigned GET directly rejected the bearer (401/403) — the R2 token likely
|
|
633
|
+
* lacks GetObject or the signature is bad. Signals the engine to flip the whole
|
|
634
|
+
* sync session to batchRead and not keep hitting the same wall (§7.3).
|
|
635
|
+
*/
|
|
636
|
+
var DownloadForbiddenError = class extends Error {
|
|
637
|
+
constructor(status) {
|
|
638
|
+
super(`download grant rejected by object store: ${status}`);
|
|
639
|
+
this.status = status;
|
|
640
|
+
this.name = "DownloadForbiddenError";
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
/** Map a commit-upload per-entry result (P2 shape) → the engine's RpcBatchEntryResult. */
|
|
644
|
+
function commitResultToBatchEntry(r) {
|
|
645
|
+
if (r.ok === true || typeof r.status === "number" && r.status === 200 && !r.code) {
|
|
646
|
+
const data = r.data;
|
|
647
|
+
return {
|
|
648
|
+
path: String(data?.path ?? ""),
|
|
649
|
+
success: true,
|
|
650
|
+
status: 200,
|
|
651
|
+
data: r.data
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
return {
|
|
655
|
+
path: String(r.path ?? ""),
|
|
656
|
+
success: false,
|
|
657
|
+
status: typeof r.status === "number" ? r.status : r.code === "AFS_CONFLICT" ? 409 : 500,
|
|
658
|
+
code: typeof r.code === "string" ? r.code : void 0,
|
|
659
|
+
error: typeof r.error === "string" ? r.error : void 0,
|
|
660
|
+
conflict: r.conflict
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
function encodeBytesToBase64(bytes) {
|
|
664
|
+
let binary = "";
|
|
665
|
+
const CHUNK = 32768;
|
|
666
|
+
for (let i = 0; i < bytes.length; i += CHUNK) binary += String.fromCharCode(...bytes.subarray(i, i + CHUNK));
|
|
667
|
+
return btoa(binary);
|
|
668
|
+
}
|
|
669
|
+
function decodeBase64ToBytes(b64) {
|
|
670
|
+
const binary = atob(b64);
|
|
671
|
+
const bytes = new Uint8Array(binary.length);
|
|
672
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
673
|
+
return bytes;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
//#endregion
|
|
677
|
+
exports.BatchOverBudgetError = BatchOverBudgetError;
|
|
678
|
+
exports.BatchUnsupportedError = BatchUnsupportedError;
|
|
679
|
+
exports.DownloadForbiddenError = DownloadForbiddenError;
|
|
680
|
+
exports.RemoteUserSpaceAFS = RemoteUserSpaceAFS;
|
|
681
|
+
exports.RpcUserSpaceAFS = RpcUserSpaceAFS;
|