@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,80 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/changelog-write.ts
|
|
3
|
+
/**
|
|
4
|
+
* changelog-write — shared runtime helpers for Task 2.4a atomic changelog writes.
|
|
5
|
+
*
|
|
6
|
+
* Both `D1TreeIndex` (Cloudflare Worker) and `MetadataDB` (desktop libsql) call
|
|
7
|
+
* into these helpers so the two runtimes stay byte-equivalent in SQL shape and
|
|
8
|
+
* deviceId validation. The DDL itself lives in `changelog-schema.ts` (parity-
|
|
9
|
+
* checked via CI); the INSERT statements live here.
|
|
10
|
+
*
|
|
11
|
+
* Design note: D1 and libsql have different prepared-statement builder APIs, so
|
|
12
|
+
* we cannot share a single "prepared statement" helper. Instead we export:
|
|
13
|
+
*
|
|
14
|
+
* 1. The canonical INSERT SQL string (identical across runtimes)
|
|
15
|
+
* 2. A deviceId validator (runtime-agnostic)
|
|
16
|
+
* 3. A small `buildChangelogBinds()` helper that returns the positional argument
|
|
17
|
+
* array both runtimes bind against
|
|
18
|
+
*
|
|
19
|
+
* This keeps the shared surface small and forces each call site to be explicit
|
|
20
|
+
* about which runtime it is writing to.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Canonical INSERT statement for `changelog`. Positional args:
|
|
24
|
+
* [scope, path, op, cid, old_cid, size, mtime, device_id]
|
|
25
|
+
*
|
|
26
|
+
* `seq` is omitted because the column is `INTEGER PRIMARY KEY AUTOINCREMENT` —
|
|
27
|
+
* SQLite/D1 assigns it automatically.
|
|
28
|
+
*
|
|
29
|
+
* This string is used VERBATIM in both `D1TreeIndex` (via `db.prepare(...)`) and
|
|
30
|
+
* `MetadataDB` (via `client.batch([{ sql, args }], 'write')`). Do not rewrite
|
|
31
|
+
* into multi-line form — the parity test compares byte-for-byte.
|
|
32
|
+
*/
|
|
33
|
+
const CHANGELOG_INSERT_SQL = "INSERT INTO ds_changelog (scope, path, op, cid, old_cid, size, mtime, device_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
34
|
+
/** Max allowed deviceId length in bytes (arbitrary cap to bound changelog row size). */
|
|
35
|
+
const MAX_DEVICE_ID_BYTES = 128;
|
|
36
|
+
/**
|
|
37
|
+
* Validate `opts.deviceId` at runtime.
|
|
38
|
+
*
|
|
39
|
+
* TypeScript's strict mode already blocks missing `opts` or missing `deviceId`
|
|
40
|
+
* at compile time (see `interface PutOpts`). This helper exists as a defense-
|
|
41
|
+
* in-depth check against:
|
|
42
|
+
* - empty string (fabricated at runtime by bypassing the type system)
|
|
43
|
+
* - oversized string (prevents DoS / unbounded changelog rows)
|
|
44
|
+
*
|
|
45
|
+
* Throws a plain `Error` prefixed with `InvalidDeviceId:` so callers can
|
|
46
|
+
* distinguish device-id failures from generic SQL errors.
|
|
47
|
+
*/
|
|
48
|
+
function validateDeviceId(deviceId) {
|
|
49
|
+
if (typeof deviceId !== "string" || deviceId.length === 0) throw new Error("InvalidDeviceId: deviceId must be a non-empty string");
|
|
50
|
+
const bytes = new TextEncoder().encode(deviceId).length;
|
|
51
|
+
if (bytes > MAX_DEVICE_ID_BYTES) throw new Error(`InvalidDeviceId: deviceId exceeds ${MAX_DEVICE_ID_BYTES} bytes (got ${bytes})`);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Build the positional bind arguments for a `changelog` INSERT row.
|
|
55
|
+
*
|
|
56
|
+
* Columns match `CHANGELOG_INSERT_SQL` exactly. Nulls are explicit so D1 and
|
|
57
|
+
* libsql do not accidentally coerce `undefined` → SQL default.
|
|
58
|
+
*
|
|
59
|
+
* Size semantics:
|
|
60
|
+
* - put : file size (bytes)
|
|
61
|
+
* - delete: null (the file is gone; its prior size lives in the old entries row)
|
|
62
|
+
*/
|
|
63
|
+
function buildChangelogBinds(args) {
|
|
64
|
+
return [
|
|
65
|
+
args.scope,
|
|
66
|
+
args.path,
|
|
67
|
+
args.op,
|
|
68
|
+
args.cid,
|
|
69
|
+
args.oldCid,
|
|
70
|
+
args.size,
|
|
71
|
+
args.mtime,
|
|
72
|
+
args.deviceId
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
exports.CHANGELOG_INSERT_SQL = CHANGELOG_INSERT_SQL;
|
|
78
|
+
exports.MAX_DEVICE_ID_BYTES = MAX_DEVICE_ID_BYTES;
|
|
79
|
+
exports.buildChangelogBinds = buildChangelogBinds;
|
|
80
|
+
exports.validateDeviceId = validateDeviceId;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//#region src/changelog-write.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* changelog-write — shared runtime helpers for Task 2.4a atomic changelog writes.
|
|
4
|
+
*
|
|
5
|
+
* Both `D1TreeIndex` (Cloudflare Worker) and `MetadataDB` (desktop libsql) call
|
|
6
|
+
* into these helpers so the two runtimes stay byte-equivalent in SQL shape and
|
|
7
|
+
* deviceId validation. The DDL itself lives in `changelog-schema.ts` (parity-
|
|
8
|
+
* checked via CI); the INSERT statements live here.
|
|
9
|
+
*
|
|
10
|
+
* Design note: D1 and libsql have different prepared-statement builder APIs, so
|
|
11
|
+
* we cannot share a single "prepared statement" helper. Instead we export:
|
|
12
|
+
*
|
|
13
|
+
* 1. The canonical INSERT SQL string (identical across runtimes)
|
|
14
|
+
* 2. A deviceId validator (runtime-agnostic)
|
|
15
|
+
* 3. A small `buildChangelogBinds()` helper that returns the positional argument
|
|
16
|
+
* array both runtimes bind against
|
|
17
|
+
*
|
|
18
|
+
* This keeps the shared surface small and forces each call site to be explicit
|
|
19
|
+
* about which runtime it is writing to.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Canonical INSERT statement for `changelog`. Positional args:
|
|
23
|
+
* [scope, path, op, cid, old_cid, size, mtime, device_id]
|
|
24
|
+
*
|
|
25
|
+
* `seq` is omitted because the column is `INTEGER PRIMARY KEY AUTOINCREMENT` —
|
|
26
|
+
* SQLite/D1 assigns it automatically.
|
|
27
|
+
*
|
|
28
|
+
* This string is used VERBATIM in both `D1TreeIndex` (via `db.prepare(...)`) and
|
|
29
|
+
* `MetadataDB` (via `client.batch([{ sql, args }], 'write')`). Do not rewrite
|
|
30
|
+
* into multi-line form — the parity test compares byte-for-byte.
|
|
31
|
+
*/
|
|
32
|
+
declare const CHANGELOG_INSERT_SQL = "INSERT INTO ds_changelog (scope, path, op, cid, old_cid, size, mtime, device_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
33
|
+
/** Max allowed deviceId length in bytes (arbitrary cap to bound changelog row size). */
|
|
34
|
+
declare const MAX_DEVICE_ID_BYTES = 128;
|
|
35
|
+
/**
|
|
36
|
+
* Validate `opts.deviceId` at runtime.
|
|
37
|
+
*
|
|
38
|
+
* TypeScript's strict mode already blocks missing `opts` or missing `deviceId`
|
|
39
|
+
* at compile time (see `interface PutOpts`). This helper exists as a defense-
|
|
40
|
+
* in-depth check against:
|
|
41
|
+
* - empty string (fabricated at runtime by bypassing the type system)
|
|
42
|
+
* - oversized string (prevents DoS / unbounded changelog rows)
|
|
43
|
+
*
|
|
44
|
+
* Throws a plain `Error` prefixed with `InvalidDeviceId:` so callers can
|
|
45
|
+
* distinguish device-id failures from generic SQL errors.
|
|
46
|
+
*/
|
|
47
|
+
declare function validateDeviceId(deviceId: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Build the positional bind arguments for a `changelog` INSERT row.
|
|
50
|
+
*
|
|
51
|
+
* Columns match `CHANGELOG_INSERT_SQL` exactly. Nulls are explicit so D1 and
|
|
52
|
+
* libsql do not accidentally coerce `undefined` → SQL default.
|
|
53
|
+
*
|
|
54
|
+
* Size semantics:
|
|
55
|
+
* - put : file size (bytes)
|
|
56
|
+
* - delete: null (the file is gone; its prior size lives in the old entries row)
|
|
57
|
+
*/
|
|
58
|
+
declare function buildChangelogBinds(args: {
|
|
59
|
+
scope: string;
|
|
60
|
+
path: string;
|
|
61
|
+
op: "put" | "delete";
|
|
62
|
+
cid: string | null;
|
|
63
|
+
oldCid: string | null;
|
|
64
|
+
size: number | null;
|
|
65
|
+
mtime: number;
|
|
66
|
+
deviceId: string;
|
|
67
|
+
}): [string, string, string, string | null, string | null, number | null, number, string];
|
|
68
|
+
//#endregion
|
|
69
|
+
export { CHANGELOG_INSERT_SQL, MAX_DEVICE_ID_BYTES, buildChangelogBinds, validateDeviceId };
|
|
70
|
+
//# sourceMappingURL=changelog-write.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changelog-write.d.cts","names":[],"sources":["../src/changelog-write.ts"],"mappings":";;AA+BA;;;;;AAIA;;;;;AAcA;;;;;AAwBA;;;;;;;;;;;;;;cA1Ca,oBAAA;;cAIA,mBAAA;;;;;;;;;;;;;iBAcG,gBAAA,CAAiB,QAAA;;;;;;;;;;;iBAwBjB,mBAAA,CAAoB,IAAA;EAClC,KAAA;EACA,IAAA;EACA,EAAA;EACA,GAAA;EACA,MAAA;EACA,IAAA;EACA,KAAA;EACA,QAAA;AAAA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//#region src/changelog-write.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* changelog-write — shared runtime helpers for Task 2.4a atomic changelog writes.
|
|
4
|
+
*
|
|
5
|
+
* Both `D1TreeIndex` (Cloudflare Worker) and `MetadataDB` (desktop libsql) call
|
|
6
|
+
* into these helpers so the two runtimes stay byte-equivalent in SQL shape and
|
|
7
|
+
* deviceId validation. The DDL itself lives in `changelog-schema.ts` (parity-
|
|
8
|
+
* checked via CI); the INSERT statements live here.
|
|
9
|
+
*
|
|
10
|
+
* Design note: D1 and libsql have different prepared-statement builder APIs, so
|
|
11
|
+
* we cannot share a single "prepared statement" helper. Instead we export:
|
|
12
|
+
*
|
|
13
|
+
* 1. The canonical INSERT SQL string (identical across runtimes)
|
|
14
|
+
* 2. A deviceId validator (runtime-agnostic)
|
|
15
|
+
* 3. A small `buildChangelogBinds()` helper that returns the positional argument
|
|
16
|
+
* array both runtimes bind against
|
|
17
|
+
*
|
|
18
|
+
* This keeps the shared surface small and forces each call site to be explicit
|
|
19
|
+
* about which runtime it is writing to.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Canonical INSERT statement for `changelog`. Positional args:
|
|
23
|
+
* [scope, path, op, cid, old_cid, size, mtime, device_id]
|
|
24
|
+
*
|
|
25
|
+
* `seq` is omitted because the column is `INTEGER PRIMARY KEY AUTOINCREMENT` —
|
|
26
|
+
* SQLite/D1 assigns it automatically.
|
|
27
|
+
*
|
|
28
|
+
* This string is used VERBATIM in both `D1TreeIndex` (via `db.prepare(...)`) and
|
|
29
|
+
* `MetadataDB` (via `client.batch([{ sql, args }], 'write')`). Do not rewrite
|
|
30
|
+
* into multi-line form — the parity test compares byte-for-byte.
|
|
31
|
+
*/
|
|
32
|
+
declare const CHANGELOG_INSERT_SQL = "INSERT INTO ds_changelog (scope, path, op, cid, old_cid, size, mtime, device_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
33
|
+
/** Max allowed deviceId length in bytes (arbitrary cap to bound changelog row size). */
|
|
34
|
+
declare const MAX_DEVICE_ID_BYTES = 128;
|
|
35
|
+
/**
|
|
36
|
+
* Validate `opts.deviceId` at runtime.
|
|
37
|
+
*
|
|
38
|
+
* TypeScript's strict mode already blocks missing `opts` or missing `deviceId`
|
|
39
|
+
* at compile time (see `interface PutOpts`). This helper exists as a defense-
|
|
40
|
+
* in-depth check against:
|
|
41
|
+
* - empty string (fabricated at runtime by bypassing the type system)
|
|
42
|
+
* - oversized string (prevents DoS / unbounded changelog rows)
|
|
43
|
+
*
|
|
44
|
+
* Throws a plain `Error` prefixed with `InvalidDeviceId:` so callers can
|
|
45
|
+
* distinguish device-id failures from generic SQL errors.
|
|
46
|
+
*/
|
|
47
|
+
declare function validateDeviceId(deviceId: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Build the positional bind arguments for a `changelog` INSERT row.
|
|
50
|
+
*
|
|
51
|
+
* Columns match `CHANGELOG_INSERT_SQL` exactly. Nulls are explicit so D1 and
|
|
52
|
+
* libsql do not accidentally coerce `undefined` → SQL default.
|
|
53
|
+
*
|
|
54
|
+
* Size semantics:
|
|
55
|
+
* - put : file size (bytes)
|
|
56
|
+
* - delete: null (the file is gone; its prior size lives in the old entries row)
|
|
57
|
+
*/
|
|
58
|
+
declare function buildChangelogBinds(args: {
|
|
59
|
+
scope: string;
|
|
60
|
+
path: string;
|
|
61
|
+
op: "put" | "delete";
|
|
62
|
+
cid: string | null;
|
|
63
|
+
oldCid: string | null;
|
|
64
|
+
size: number | null;
|
|
65
|
+
mtime: number;
|
|
66
|
+
deviceId: string;
|
|
67
|
+
}): [string, string, string, string | null, string | null, number | null, number, string];
|
|
68
|
+
//#endregion
|
|
69
|
+
export { CHANGELOG_INSERT_SQL, MAX_DEVICE_ID_BYTES, buildChangelogBinds, validateDeviceId };
|
|
70
|
+
//# sourceMappingURL=changelog-write.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changelog-write.d.mts","names":[],"sources":["../src/changelog-write.ts"],"mappings":";;AA+BA;;;;;AAIA;;;;;AAcA;;;;;AAwBA;;;;;;;;;;;;;;cA1Ca,oBAAA;;cAIA,mBAAA;;;;;;;;;;;;;iBAcG,gBAAA,CAAiB,QAAA;;;;;;;;;;;iBAwBjB,mBAAA,CAAoB,IAAA;EAClC,KAAA;EACA,IAAA;EACA,EAAA;EACA,GAAA;EACA,MAAA;EACA,IAAA;EACA,KAAA;EACA,QAAA;AAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region src/changelog-write.ts
|
|
2
|
+
/**
|
|
3
|
+
* changelog-write — shared runtime helpers for Task 2.4a atomic changelog writes.
|
|
4
|
+
*
|
|
5
|
+
* Both `D1TreeIndex` (Cloudflare Worker) and `MetadataDB` (desktop libsql) call
|
|
6
|
+
* into these helpers so the two runtimes stay byte-equivalent in SQL shape and
|
|
7
|
+
* deviceId validation. The DDL itself lives in `changelog-schema.ts` (parity-
|
|
8
|
+
* checked via CI); the INSERT statements live here.
|
|
9
|
+
*
|
|
10
|
+
* Design note: D1 and libsql have different prepared-statement builder APIs, so
|
|
11
|
+
* we cannot share a single "prepared statement" helper. Instead we export:
|
|
12
|
+
*
|
|
13
|
+
* 1. The canonical INSERT SQL string (identical across runtimes)
|
|
14
|
+
* 2. A deviceId validator (runtime-agnostic)
|
|
15
|
+
* 3. A small `buildChangelogBinds()` helper that returns the positional argument
|
|
16
|
+
* array both runtimes bind against
|
|
17
|
+
*
|
|
18
|
+
* This keeps the shared surface small and forces each call site to be explicit
|
|
19
|
+
* about which runtime it is writing to.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Canonical INSERT statement for `changelog`. Positional args:
|
|
23
|
+
* [scope, path, op, cid, old_cid, size, mtime, device_id]
|
|
24
|
+
*
|
|
25
|
+
* `seq` is omitted because the column is `INTEGER PRIMARY KEY AUTOINCREMENT` —
|
|
26
|
+
* SQLite/D1 assigns it automatically.
|
|
27
|
+
*
|
|
28
|
+
* This string is used VERBATIM in both `D1TreeIndex` (via `db.prepare(...)`) and
|
|
29
|
+
* `MetadataDB` (via `client.batch([{ sql, args }], 'write')`). Do not rewrite
|
|
30
|
+
* into multi-line form — the parity test compares byte-for-byte.
|
|
31
|
+
*/
|
|
32
|
+
const CHANGELOG_INSERT_SQL = "INSERT INTO ds_changelog (scope, path, op, cid, old_cid, size, mtime, device_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
33
|
+
/** Max allowed deviceId length in bytes (arbitrary cap to bound changelog row size). */
|
|
34
|
+
const MAX_DEVICE_ID_BYTES = 128;
|
|
35
|
+
/**
|
|
36
|
+
* Validate `opts.deviceId` at runtime.
|
|
37
|
+
*
|
|
38
|
+
* TypeScript's strict mode already blocks missing `opts` or missing `deviceId`
|
|
39
|
+
* at compile time (see `interface PutOpts`). This helper exists as a defense-
|
|
40
|
+
* in-depth check against:
|
|
41
|
+
* - empty string (fabricated at runtime by bypassing the type system)
|
|
42
|
+
* - oversized string (prevents DoS / unbounded changelog rows)
|
|
43
|
+
*
|
|
44
|
+
* Throws a plain `Error` prefixed with `InvalidDeviceId:` so callers can
|
|
45
|
+
* distinguish device-id failures from generic SQL errors.
|
|
46
|
+
*/
|
|
47
|
+
function validateDeviceId(deviceId) {
|
|
48
|
+
if (typeof deviceId !== "string" || deviceId.length === 0) throw new Error("InvalidDeviceId: deviceId must be a non-empty string");
|
|
49
|
+
const bytes = new TextEncoder().encode(deviceId).length;
|
|
50
|
+
if (bytes > MAX_DEVICE_ID_BYTES) throw new Error(`InvalidDeviceId: deviceId exceeds ${MAX_DEVICE_ID_BYTES} bytes (got ${bytes})`);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Build the positional bind arguments for a `changelog` INSERT row.
|
|
54
|
+
*
|
|
55
|
+
* Columns match `CHANGELOG_INSERT_SQL` exactly. Nulls are explicit so D1 and
|
|
56
|
+
* libsql do not accidentally coerce `undefined` → SQL default.
|
|
57
|
+
*
|
|
58
|
+
* Size semantics:
|
|
59
|
+
* - put : file size (bytes)
|
|
60
|
+
* - delete: null (the file is gone; its prior size lives in the old entries row)
|
|
61
|
+
*/
|
|
62
|
+
function buildChangelogBinds(args) {
|
|
63
|
+
return [
|
|
64
|
+
args.scope,
|
|
65
|
+
args.path,
|
|
66
|
+
args.op,
|
|
67
|
+
args.cid,
|
|
68
|
+
args.oldCid,
|
|
69
|
+
args.size,
|
|
70
|
+
args.mtime,
|
|
71
|
+
args.deviceId
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { CHANGELOG_INSERT_SQL, MAX_DEVICE_ID_BYTES, buildChangelogBinds, validateDeviceId };
|
|
77
|
+
//# sourceMappingURL=changelog-write.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changelog-write.mjs","names":[],"sources":["../src/changelog-write.ts"],"sourcesContent":["/**\n * changelog-write — shared runtime helpers for Task 2.4a atomic changelog writes.\n *\n * Both `D1TreeIndex` (Cloudflare Worker) and `MetadataDB` (desktop libsql) call\n * into these helpers so the two runtimes stay byte-equivalent in SQL shape and\n * deviceId validation. The DDL itself lives in `changelog-schema.ts` (parity-\n * checked via CI); the INSERT statements live here.\n *\n * Design note: D1 and libsql have different prepared-statement builder APIs, so\n * we cannot share a single \"prepared statement\" helper. Instead we export:\n *\n * 1. The canonical INSERT SQL string (identical across runtimes)\n * 2. A deviceId validator (runtime-agnostic)\n * 3. A small `buildChangelogBinds()` helper that returns the positional argument\n * array both runtimes bind against\n *\n * This keeps the shared surface small and forces each call site to be explicit\n * about which runtime it is writing to.\n */\n\n/**\n * Canonical INSERT statement for `changelog`. Positional args:\n * [scope, path, op, cid, old_cid, size, mtime, device_id]\n *\n * `seq` is omitted because the column is `INTEGER PRIMARY KEY AUTOINCREMENT` —\n * SQLite/D1 assigns it automatically.\n *\n * This string is used VERBATIM in both `D1TreeIndex` (via `db.prepare(...)`) and\n * `MetadataDB` (via `client.batch([{ sql, args }], 'write')`). Do not rewrite\n * into multi-line form — the parity test compares byte-for-byte.\n */\nexport const CHANGELOG_INSERT_SQL =\n \"INSERT INTO ds_changelog (scope, path, op, cid, old_cid, size, mtime, device_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)\";\n\n/** Max allowed deviceId length in bytes (arbitrary cap to bound changelog row size). */\nexport const MAX_DEVICE_ID_BYTES = 128;\n\n/**\n * Validate `opts.deviceId` at runtime.\n *\n * TypeScript's strict mode already blocks missing `opts` or missing `deviceId`\n * at compile time (see `interface PutOpts`). This helper exists as a defense-\n * in-depth check against:\n * - empty string (fabricated at runtime by bypassing the type system)\n * - oversized string (prevents DoS / unbounded changelog rows)\n *\n * Throws a plain `Error` prefixed with `InvalidDeviceId:` so callers can\n * distinguish device-id failures from generic SQL errors.\n */\nexport function validateDeviceId(deviceId: string): void {\n if (typeof deviceId !== \"string\" || deviceId.length === 0) {\n throw new Error(\"InvalidDeviceId: deviceId must be a non-empty string\");\n }\n // Byte length, not char length — a non-ASCII deviceId may overflow the cap\n // even when its char count looks small.\n const bytes = new TextEncoder().encode(deviceId).length;\n if (bytes > MAX_DEVICE_ID_BYTES) {\n throw new Error(\n `InvalidDeviceId: deviceId exceeds ${MAX_DEVICE_ID_BYTES} bytes (got ${bytes})`,\n );\n }\n}\n\n/**\n * Build the positional bind arguments for a `changelog` INSERT row.\n *\n * Columns match `CHANGELOG_INSERT_SQL` exactly. Nulls are explicit so D1 and\n * libsql do not accidentally coerce `undefined` → SQL default.\n *\n * Size semantics:\n * - put : file size (bytes)\n * - delete: null (the file is gone; its prior size lives in the old entries row)\n */\nexport function buildChangelogBinds(args: {\n scope: string;\n path: string;\n op: \"put\" | \"delete\";\n cid: string | null;\n oldCid: string | null;\n size: number | null;\n mtime: number;\n deviceId: string;\n}): [string, string, string, string | null, string | null, number | null, number, string] {\n return [\n args.scope,\n args.path,\n args.op,\n args.cid,\n args.oldCid,\n args.size,\n args.mtime,\n args.deviceId,\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,uBACX;;AAGF,MAAa,sBAAsB;;;;;;;;;;;;;AAcnC,SAAgB,iBAAiB,UAAwB;AACvD,KAAI,OAAO,aAAa,YAAY,SAAS,WAAW,EACtD,OAAM,IAAI,MAAM,uDAAuD;CAIzE,MAAM,QAAQ,IAAI,aAAa,CAAC,OAAO,SAAS,CAAC;AACjD,KAAI,QAAQ,oBACV,OAAM,IAAI,MACR,qCAAqC,oBAAoB,cAAc,MAAM,GAC9E;;;;;;;;;;;;AAcL,SAAgB,oBAAoB,MASsD;AACxF,QAAO;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACN"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/cid-byte-cache.ts
|
|
3
|
+
/** Canonical prefix under which content-addressed blobs live: `objects/{cid}`. */
|
|
4
|
+
const OBJECT_KEY_PREFIX = "objects/";
|
|
5
|
+
/** Total bytes the cache may hold before LRU eviction kicks in (per instance). */
|
|
6
|
+
const DEFAULT_MAX_TOTAL_BYTES = 64 * 1024 * 1024;
|
|
7
|
+
/**
|
|
8
|
+
* Largest single object we cache. Bigger blobs (large media / bundles) are left
|
|
9
|
+
* uncached: they'd evict many small hot files, and the ≳8 MiB range is
|
|
10
|
+
* download-plane territory (served R2-direct, never read through the Worker).
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_MAX_ENTRY_BYTES = 4 * 1024 * 1024;
|
|
13
|
+
const UTF8_DECODER = new TextDecoder();
|
|
14
|
+
/** Synthetic timestamp for cached objects — object-store metadata is never read
|
|
15
|
+
* from `get()` (the provider takes size/mtime from the tree index), so a fixed
|
|
16
|
+
* epoch is faithful and avoids a per-entry Date allocation. */
|
|
17
|
+
const SYNTHETIC_UPLOADED = /* @__PURE__ */ new Date(0);
|
|
18
|
+
/**
|
|
19
|
+
* Bounded LRU cache of `cid → bytes`. Insertion order in the backing Map is the
|
|
20
|
+
* LRU order; a `get` re-inserts (bumps to most-recently-used).
|
|
21
|
+
*/
|
|
22
|
+
var CidByteCache = class {
|
|
23
|
+
map = /* @__PURE__ */ new Map();
|
|
24
|
+
maxTotalBytes;
|
|
25
|
+
maxEntryBytes;
|
|
26
|
+
totalBytes = 0;
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.maxTotalBytes = options?.maxTotalBytes ?? DEFAULT_MAX_TOTAL_BYTES;
|
|
29
|
+
this.maxEntryBytes = options?.maxEntryBytes ?? DEFAULT_MAX_ENTRY_BYTES;
|
|
30
|
+
}
|
|
31
|
+
get(cid) {
|
|
32
|
+
const bytes = this.map.get(cid);
|
|
33
|
+
if (bytes === void 0) return void 0;
|
|
34
|
+
this.map.delete(cid);
|
|
35
|
+
this.map.set(cid, bytes);
|
|
36
|
+
return bytes;
|
|
37
|
+
}
|
|
38
|
+
set(cid, bytes) {
|
|
39
|
+
if (bytes.byteLength > this.maxEntryBytes) return;
|
|
40
|
+
const existing = this.map.get(cid);
|
|
41
|
+
if (existing !== void 0) {
|
|
42
|
+
this.totalBytes -= existing.byteLength;
|
|
43
|
+
this.map.delete(cid);
|
|
44
|
+
}
|
|
45
|
+
this.map.set(cid, bytes);
|
|
46
|
+
this.totalBytes += bytes.byteLength;
|
|
47
|
+
this.evictToBudget();
|
|
48
|
+
}
|
|
49
|
+
delete(cid) {
|
|
50
|
+
const existing = this.map.get(cid);
|
|
51
|
+
if (existing === void 0) return;
|
|
52
|
+
this.totalBytes -= existing.byteLength;
|
|
53
|
+
this.map.delete(cid);
|
|
54
|
+
}
|
|
55
|
+
/** Test/introspection helper. */
|
|
56
|
+
get size() {
|
|
57
|
+
return this.map.size;
|
|
58
|
+
}
|
|
59
|
+
evictToBudget() {
|
|
60
|
+
while (this.totalBytes > this.maxTotalBytes) {
|
|
61
|
+
const oldest = this.map.keys().next().value;
|
|
62
|
+
if (oldest === void 0) break;
|
|
63
|
+
const evicted = this.map.get(oldest);
|
|
64
|
+
if (evicted !== void 0) this.totalBytes -= evicted.byteLength;
|
|
65
|
+
this.map.delete(oldest);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
/** Build a minimal ObjectStoreObject that serves cached bytes. */
|
|
70
|
+
function objectFromBytes(key, bytes) {
|
|
71
|
+
return {
|
|
72
|
+
key,
|
|
73
|
+
size: bytes.byteLength,
|
|
74
|
+
uploaded: SYNTHETIC_UPLOADED,
|
|
75
|
+
async text() {
|
|
76
|
+
return UTF8_DECODER.decode(bytes);
|
|
77
|
+
},
|
|
78
|
+
async arrayBuffer() {
|
|
79
|
+
return bytes.slice().buffer;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* ObjectStore decorator that serves `objects/{cid}` reads from an in-memory
|
|
85
|
+
* {@link CidByteCache}. Non-`objects/` keys and all writes/lists pass straight
|
|
86
|
+
* through. `delete` drops the cid from the cache (belt-and-suspenders against GC
|
|
87
|
+
* — a still-referenced object is never GC'd, so this rarely matters).
|
|
88
|
+
*/
|
|
89
|
+
var CachingObjectStore = class {
|
|
90
|
+
constructor(inner, cache) {
|
|
91
|
+
this.inner = inner;
|
|
92
|
+
this.cache = cache;
|
|
93
|
+
}
|
|
94
|
+
cidOf(key) {
|
|
95
|
+
return key.startsWith(OBJECT_KEY_PREFIX) ? key.slice(8) : void 0;
|
|
96
|
+
}
|
|
97
|
+
async get(key) {
|
|
98
|
+
const cid = this.cidOf(key);
|
|
99
|
+
if (cid === void 0) return this.inner.get(key);
|
|
100
|
+
const cached = this.cache.get(cid);
|
|
101
|
+
if (cached !== void 0) return objectFromBytes(key, cached);
|
|
102
|
+
const obj = await this.inner.get(key);
|
|
103
|
+
if (!obj) return null;
|
|
104
|
+
const bytes = new Uint8Array(await obj.arrayBuffer());
|
|
105
|
+
this.cache.set(cid, bytes);
|
|
106
|
+
return objectFromBytes(key, bytes);
|
|
107
|
+
}
|
|
108
|
+
put(key, value) {
|
|
109
|
+
return this.inner.put(key, value);
|
|
110
|
+
}
|
|
111
|
+
async delete(key) {
|
|
112
|
+
const cid = this.cidOf(key);
|
|
113
|
+
if (cid !== void 0) this.cache.delete(cid);
|
|
114
|
+
return this.inner.delete(key);
|
|
115
|
+
}
|
|
116
|
+
list(options) {
|
|
117
|
+
return this.inner.list(options);
|
|
118
|
+
}
|
|
119
|
+
head(key) {
|
|
120
|
+
return this.inner.head(key);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
exports.CachingObjectStore = CachingObjectStore;
|
|
126
|
+
exports.CidByteCache = CidByteCache;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ObjectStore, ObjectStoreHeadResult, ObjectStoreListOptions, ObjectStoreListResult, ObjectStoreObject } from "./platform/r2/dist/types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/cid-byte-cache.d.ts
|
|
4
|
+
interface CidByteCacheOptions {
|
|
5
|
+
/** Total byte budget before LRU eviction. Default 64 MiB. */
|
|
6
|
+
maxTotalBytes?: number;
|
|
7
|
+
/** Per-object cap; larger objects are not cached. Default 4 MiB. */
|
|
8
|
+
maxEntryBytes?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Bounded LRU cache of `cid → bytes`. Insertion order in the backing Map is the
|
|
12
|
+
* LRU order; a `get` re-inserts (bumps to most-recently-used).
|
|
13
|
+
*/
|
|
14
|
+
declare class CidByteCache {
|
|
15
|
+
private readonly map;
|
|
16
|
+
private readonly maxTotalBytes;
|
|
17
|
+
private readonly maxEntryBytes;
|
|
18
|
+
private totalBytes;
|
|
19
|
+
constructor(options?: CidByteCacheOptions);
|
|
20
|
+
get(cid: string): Uint8Array | undefined;
|
|
21
|
+
set(cid: string, bytes: Uint8Array): void;
|
|
22
|
+
delete(cid: string): void;
|
|
23
|
+
/** Test/introspection helper. */
|
|
24
|
+
get size(): number;
|
|
25
|
+
private evictToBudget;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* ObjectStore decorator that serves `objects/{cid}` reads from an in-memory
|
|
29
|
+
* {@link CidByteCache}. Non-`objects/` keys and all writes/lists pass straight
|
|
30
|
+
* through. `delete` drops the cid from the cache (belt-and-suspenders against GC
|
|
31
|
+
* — a still-referenced object is never GC'd, so this rarely matters).
|
|
32
|
+
*/
|
|
33
|
+
declare class CachingObjectStore implements ObjectStore {
|
|
34
|
+
private readonly inner;
|
|
35
|
+
private readonly cache;
|
|
36
|
+
constructor(inner: ObjectStore, cache: CidByteCache);
|
|
37
|
+
private cidOf;
|
|
38
|
+
get(key: string): Promise<ObjectStoreObject | null>;
|
|
39
|
+
put(key: string, value: string | ArrayBuffer | ReadableStream): Promise<void>;
|
|
40
|
+
delete(key: string): Promise<void>;
|
|
41
|
+
list(options?: ObjectStoreListOptions): Promise<ObjectStoreListResult>;
|
|
42
|
+
head(key: string): Promise<ObjectStoreHeadResult | null>;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { CachingObjectStore, CidByteCache, CidByteCacheOptions };
|
|
46
|
+
//# sourceMappingURL=cid-byte-cache.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cid-byte-cache.d.cts","names":[],"sources":["../src/cid-byte-cache.ts"],"mappings":";;;UAiDiB,mBAAA;EAsBX;EApBJ,aAAA;EA6BA;EA3BA,aAAA;AAAA;;;;;cAOW,YAAA;EAAA,iBACM,GAAA;EAAA,iBACA,aAAA;EAAA,iBACA,aAAA;EAAA,QACT,UAAA;cAEI,OAAA,GAAU,mBAAA;EAKtB,GAAA,CAAI,GAAA,WAAc,UAAA;EASlB,GAAA,CAAI,GAAA,UAAa,KAAA,EAAO,UAAA;EAYxB,MAAA,CAAO,GAAA;EAuDiB;EAAA,IA/CpB,IAAA,CAAA;EAAA,QAII,aAAA;AAAA;;;;;;;cAiCG,kBAAA,YAA8B,WAAA;EAAA,iBAEtB,KAAA;EAAA,iBACA,KAAA;cADA,KAAA,EAAO,WAAA,EACP,KAAA,EAAO,YAAA;EAAA,QAGlB,KAAA;EAIF,GAAA,CAAI,GAAA,WAAc,OAAA,CAAQ,iBAAA;EAchC,GAAA,CAAI,GAAA,UAAa,KAAA,WAAgB,WAAA,GAAc,cAAA,GAAiB,OAAA;EAM1D,MAAA,CAAO,GAAA,WAAc,OAAA;EAM3B,IAAA,CAAK,OAAA,GAAU,sBAAA,GAAyB,OAAA,CAAQ,qBAAA;EAIhD,IAAA,CAAK,GAAA,WAAc,OAAA,CAAQ,qBAAA;AAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ObjectStore, ObjectStoreHeadResult, ObjectStoreListOptions, ObjectStoreListResult, ObjectStoreObject } from "./providers/platform/r2/dist/types.mjs";
|
|
2
|
+
import "./providers/platform/r2/dist/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/cid-byte-cache.d.ts
|
|
5
|
+
interface CidByteCacheOptions {
|
|
6
|
+
/** Total byte budget before LRU eviction. Default 64 MiB. */
|
|
7
|
+
maxTotalBytes?: number;
|
|
8
|
+
/** Per-object cap; larger objects are not cached. Default 4 MiB. */
|
|
9
|
+
maxEntryBytes?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Bounded LRU cache of `cid → bytes`. Insertion order in the backing Map is the
|
|
13
|
+
* LRU order; a `get` re-inserts (bumps to most-recently-used).
|
|
14
|
+
*/
|
|
15
|
+
declare class CidByteCache {
|
|
16
|
+
private readonly map;
|
|
17
|
+
private readonly maxTotalBytes;
|
|
18
|
+
private readonly maxEntryBytes;
|
|
19
|
+
private totalBytes;
|
|
20
|
+
constructor(options?: CidByteCacheOptions);
|
|
21
|
+
get(cid: string): Uint8Array | undefined;
|
|
22
|
+
set(cid: string, bytes: Uint8Array): void;
|
|
23
|
+
delete(cid: string): void;
|
|
24
|
+
/** Test/introspection helper. */
|
|
25
|
+
get size(): number;
|
|
26
|
+
private evictToBudget;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* ObjectStore decorator that serves `objects/{cid}` reads from an in-memory
|
|
30
|
+
* {@link CidByteCache}. Non-`objects/` keys and all writes/lists pass straight
|
|
31
|
+
* through. `delete` drops the cid from the cache (belt-and-suspenders against GC
|
|
32
|
+
* — a still-referenced object is never GC'd, so this rarely matters).
|
|
33
|
+
*/
|
|
34
|
+
declare class CachingObjectStore implements ObjectStore {
|
|
35
|
+
private readonly inner;
|
|
36
|
+
private readonly cache;
|
|
37
|
+
constructor(inner: ObjectStore, cache: CidByteCache);
|
|
38
|
+
private cidOf;
|
|
39
|
+
get(key: string): Promise<ObjectStoreObject | null>;
|
|
40
|
+
put(key: string, value: string | ArrayBuffer | ReadableStream): Promise<void>;
|
|
41
|
+
delete(key: string): Promise<void>;
|
|
42
|
+
list(options?: ObjectStoreListOptions): Promise<ObjectStoreListResult>;
|
|
43
|
+
head(key: string): Promise<ObjectStoreHeadResult | null>;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { CachingObjectStore, CidByteCache, CidByteCacheOptions };
|
|
47
|
+
//# sourceMappingURL=cid-byte-cache.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cid-byte-cache.d.mts","names":[],"sources":["../src/cid-byte-cache.ts"],"mappings":";;;;UAiDiB,mBAAA;EAsBf;EApBA,aAAA;EAoBkB;EAlBlB,aAAA;AAAA;;;;;cAOW,YAAA;EAAA,iBACM,GAAA;EAAA,iBACA,aAAA;EAAA,iBACA,aAAA;EAAA,QACT,UAAA;cAEI,OAAA,GAAU,mBAAA;EAKtB,GAAA,CAAI,GAAA,WAAc,UAAA;EASlB,GAAA,CAAI,GAAA,UAAa,KAAA,EAAO,UAAA;EAYxB,MAAA,CAAO,GAAA;EAuDyB;EAAA,IA/C5B,IAAA,CAAA;EAAA,QAII,aAAA;AAAA;;;;;;;cAiCG,kBAAA,YAA8B,WAAA;EAAA,iBAEtB,KAAA;EAAA,iBACA,KAAA;cADA,KAAA,EAAO,WAAA,EACP,KAAA,EAAO,YAAA;EAAA,QAGlB,KAAA;EAIF,GAAA,CAAI,GAAA,WAAc,OAAA,CAAQ,iBAAA;EAchC,GAAA,CAAI,GAAA,UAAa,KAAA,WAAgB,WAAA,GAAc,cAAA,GAAiB,OAAA;EAM1D,MAAA,CAAO,GAAA,WAAc,OAAA;EAM3B,IAAA,CAAK,OAAA,GAAU,sBAAA,GAAyB,OAAA,CAAQ,qBAAA;EAIhD,IAAA,CAAK,GAAA,WAAc,OAAA,CAAQ,qBAAA;AAAA"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
//#region src/cid-byte-cache.ts
|
|
2
|
+
/** Canonical prefix under which content-addressed blobs live: `objects/{cid}`. */
|
|
3
|
+
const OBJECT_KEY_PREFIX = "objects/";
|
|
4
|
+
/** Total bytes the cache may hold before LRU eviction kicks in (per instance). */
|
|
5
|
+
const DEFAULT_MAX_TOTAL_BYTES = 64 * 1024 * 1024;
|
|
6
|
+
/**
|
|
7
|
+
* Largest single object we cache. Bigger blobs (large media / bundles) are left
|
|
8
|
+
* uncached: they'd evict many small hot files, and the ≳8 MiB range is
|
|
9
|
+
* download-plane territory (served R2-direct, never read through the Worker).
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_MAX_ENTRY_BYTES = 4 * 1024 * 1024;
|
|
12
|
+
const UTF8_DECODER = new TextDecoder();
|
|
13
|
+
/** Synthetic timestamp for cached objects — object-store metadata is never read
|
|
14
|
+
* from `get()` (the provider takes size/mtime from the tree index), so a fixed
|
|
15
|
+
* epoch is faithful and avoids a per-entry Date allocation. */
|
|
16
|
+
const SYNTHETIC_UPLOADED = /* @__PURE__ */ new Date(0);
|
|
17
|
+
/**
|
|
18
|
+
* Bounded LRU cache of `cid → bytes`. Insertion order in the backing Map is the
|
|
19
|
+
* LRU order; a `get` re-inserts (bumps to most-recently-used).
|
|
20
|
+
*/
|
|
21
|
+
var CidByteCache = class {
|
|
22
|
+
map = /* @__PURE__ */ new Map();
|
|
23
|
+
maxTotalBytes;
|
|
24
|
+
maxEntryBytes;
|
|
25
|
+
totalBytes = 0;
|
|
26
|
+
constructor(options) {
|
|
27
|
+
this.maxTotalBytes = options?.maxTotalBytes ?? DEFAULT_MAX_TOTAL_BYTES;
|
|
28
|
+
this.maxEntryBytes = options?.maxEntryBytes ?? DEFAULT_MAX_ENTRY_BYTES;
|
|
29
|
+
}
|
|
30
|
+
get(cid) {
|
|
31
|
+
const bytes = this.map.get(cid);
|
|
32
|
+
if (bytes === void 0) return void 0;
|
|
33
|
+
this.map.delete(cid);
|
|
34
|
+
this.map.set(cid, bytes);
|
|
35
|
+
return bytes;
|
|
36
|
+
}
|
|
37
|
+
set(cid, bytes) {
|
|
38
|
+
if (bytes.byteLength > this.maxEntryBytes) return;
|
|
39
|
+
const existing = this.map.get(cid);
|
|
40
|
+
if (existing !== void 0) {
|
|
41
|
+
this.totalBytes -= existing.byteLength;
|
|
42
|
+
this.map.delete(cid);
|
|
43
|
+
}
|
|
44
|
+
this.map.set(cid, bytes);
|
|
45
|
+
this.totalBytes += bytes.byteLength;
|
|
46
|
+
this.evictToBudget();
|
|
47
|
+
}
|
|
48
|
+
delete(cid) {
|
|
49
|
+
const existing = this.map.get(cid);
|
|
50
|
+
if (existing === void 0) return;
|
|
51
|
+
this.totalBytes -= existing.byteLength;
|
|
52
|
+
this.map.delete(cid);
|
|
53
|
+
}
|
|
54
|
+
/** Test/introspection helper. */
|
|
55
|
+
get size() {
|
|
56
|
+
return this.map.size;
|
|
57
|
+
}
|
|
58
|
+
evictToBudget() {
|
|
59
|
+
while (this.totalBytes > this.maxTotalBytes) {
|
|
60
|
+
const oldest = this.map.keys().next().value;
|
|
61
|
+
if (oldest === void 0) break;
|
|
62
|
+
const evicted = this.map.get(oldest);
|
|
63
|
+
if (evicted !== void 0) this.totalBytes -= evicted.byteLength;
|
|
64
|
+
this.map.delete(oldest);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
/** Build a minimal ObjectStoreObject that serves cached bytes. */
|
|
69
|
+
function objectFromBytes(key, bytes) {
|
|
70
|
+
return {
|
|
71
|
+
key,
|
|
72
|
+
size: bytes.byteLength,
|
|
73
|
+
uploaded: SYNTHETIC_UPLOADED,
|
|
74
|
+
async text() {
|
|
75
|
+
return UTF8_DECODER.decode(bytes);
|
|
76
|
+
},
|
|
77
|
+
async arrayBuffer() {
|
|
78
|
+
return bytes.slice().buffer;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* ObjectStore decorator that serves `objects/{cid}` reads from an in-memory
|
|
84
|
+
* {@link CidByteCache}. Non-`objects/` keys and all writes/lists pass straight
|
|
85
|
+
* through. `delete` drops the cid from the cache (belt-and-suspenders against GC
|
|
86
|
+
* — a still-referenced object is never GC'd, so this rarely matters).
|
|
87
|
+
*/
|
|
88
|
+
var CachingObjectStore = class {
|
|
89
|
+
constructor(inner, cache) {
|
|
90
|
+
this.inner = inner;
|
|
91
|
+
this.cache = cache;
|
|
92
|
+
}
|
|
93
|
+
cidOf(key) {
|
|
94
|
+
return key.startsWith(OBJECT_KEY_PREFIX) ? key.slice(8) : void 0;
|
|
95
|
+
}
|
|
96
|
+
async get(key) {
|
|
97
|
+
const cid = this.cidOf(key);
|
|
98
|
+
if (cid === void 0) return this.inner.get(key);
|
|
99
|
+
const cached = this.cache.get(cid);
|
|
100
|
+
if (cached !== void 0) return objectFromBytes(key, cached);
|
|
101
|
+
const obj = await this.inner.get(key);
|
|
102
|
+
if (!obj) return null;
|
|
103
|
+
const bytes = new Uint8Array(await obj.arrayBuffer());
|
|
104
|
+
this.cache.set(cid, bytes);
|
|
105
|
+
return objectFromBytes(key, bytes);
|
|
106
|
+
}
|
|
107
|
+
put(key, value) {
|
|
108
|
+
return this.inner.put(key, value);
|
|
109
|
+
}
|
|
110
|
+
async delete(key) {
|
|
111
|
+
const cid = this.cidOf(key);
|
|
112
|
+
if (cid !== void 0) this.cache.delete(cid);
|
|
113
|
+
return this.inner.delete(key);
|
|
114
|
+
}
|
|
115
|
+
list(options) {
|
|
116
|
+
return this.inner.list(options);
|
|
117
|
+
}
|
|
118
|
+
head(key) {
|
|
119
|
+
return this.inner.head(key);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
export { CachingObjectStore, CidByteCache };
|
|
125
|
+
//# sourceMappingURL=cid-byte-cache.mjs.map
|