import { C as ContentAddressedBlobStore, M as MemoryBlobStore } from './content-addressed-blob-store-CRUU_iCe.js'; import { BlobRef } from '@korajs/core'; /** * The server-side blob callbacks a `KoraSyncServer` accepts: read a chunk by * hash (to serve it) and persist an uploaded chunk by hash (to store it). */ interface ServerBlobCallbacks { resolveBlobChunk: (hash: string) => Promise; persistBlobChunk: (hash: string, bytes: Uint8Array) => Promise; } /** * Adapt a {@link ContentAddressedBlobStore} into the read/persist callbacks a * `KoraSyncServer` needs for central blob storage. The server package depends * only on these plain function signatures, so a self-hosted server can back its * blob storage with any store (for example a `FilesystemBlobStore`) without the * server package taking a dependency on `@korajs/store`. * * @example * ```typescript * const server = new KoraSyncServer({ * store, * ...toServerBlobCallbacks(new FilesystemBlobStore('/var/kora/blobs')), * }) * ``` */ declare function toServerBlobCallbacks(store: ContentAddressedBlobStore): ServerBlobCallbacks; /** * Convenience: an in-memory central blob store plus its server callbacks. For * tests and single-process deployments. Persistent deployments should back * {@link toServerBlobCallbacks} with a durable store instead. */ declare function createMemoryServerBlobStore(): { store: MemoryBlobStore; callbacks: ServerBlobCallbacks; }; /** Outcome of a blob garbage-collection sweep. */ interface BlobGcResult { /** Total distinct blobs held before the sweep. */ scanned: number; /** Distinct hashes kept because a live reference points to them (blob, manifest, or chunk). */ live: number; /** Number of blobs deleted (or, with `dryRun`, that would be deleted). */ collected: number; /** The hashes deleted (or, with `dryRun`, that would be deleted). */ collectedHashes: string[]; } /** Options for {@link collectBlobGarbage}. */ interface BlobGcOptions { /** Compute what would be collected without deleting anything. */ dryRun?: boolean; /** * Unreferenced blobs written within this long are kept (default 24 hours). A device * uploads a blob's bytes before the record that points at it, and the record can * arrive much later (the device went offline in between), so a blob is only garbage * once it has had time to be claimed. Applies to stores that report write times * (`FilesystemBlobStore`, `ObjectBlobStore`); others are swept as before. * * It applies to `dryRun` too: a dry run lists what a real sweep would delete. To list * every unreferenced blob however recent (to apply a grace of your own, per uploader * say), pass `graceMs: 0`. */ graceMs?: number; /** The current time, for tests. */ now?: number; } /** The default {@link BlobGcOptions.graceMs}: a day. */ declare const DEFAULT_BLOB_GC_GRACE_MS: number; /** * Extract the {@link BlobRef}s referenced by a materialized record. Scans the * record's top-level field values, so it works without the schema; a `blob` * field simply holds a `BlobRef`. */ declare function extractBlobRefs(record: Record): BlobRef[]; /** * Garbage-collect a content-addressed blob store by mark-and-sweep: keep every * blob reachable from a live reference, delete the rest. * * The live set is closed over the reference graph — for each live {@link BlobRef} * it retains the blob hash, the manifest hash, and every chunk hash named in that * manifest. Because chunks (and blobs) are shared by content address, a chunk * referenced by any surviving blob is retained even if another blob that used it * was collected. This makes GC safe under deduplication. * * Mark-and-sweep (rather than reference counting) is deliberate: counts are * fragile under concurrent edits and CRDT merges, whereas a sweep against the * current live set is always correct for the state it observes. Run it * periodically or on demand. * * A manifest that cannot be read or parsed (corruption) contributes no chunk * hashes; its own hash still counts as live. The blob it describes is already * unusable, so its chunks becoming collectable is acceptable, and GC never * throws on a single bad manifest. * * @param store - The blob store to sweep * @param liveRefs - Every reference still reachable from live records * @param options - `dryRun` to report without deleting */ declare function collectBlobGarbage(store: ContentAddressedBlobStore, liveRefs: Iterable, options?: BlobGcOptions): Promise; export { type BlobGcOptions as B, DEFAULT_BLOB_GC_GRACE_MS as D, type ServerBlobCallbacks as S, type BlobGcResult as a, createMemoryServerBlobStore as b, collectBlobGarbage as c, extractBlobRefs as e, toServerBlobCallbacks as t };