@toolkit-p2p/mesh-cache
Version:
Content-addressed mesh cache for toolkit-p2p
81 lines • 1.73 kB
TypeScript
/**
* Mesh cache types
*/
/**
* Content Identifier (CID) - SHA-256 hash of content
* Format: base58(sha256(data))
*/
export type CID = string;
/**
* Content block with metadata
*/
export interface Block {
/** Content identifier */
cid: CID;
/** Raw block data */
data: Uint8Array;
/** Block size in bytes */
size: number;
/** Timestamp when block was added */
addedAt: number;
/** Last access timestamp */
lastAccessedAt: number;
/** Whether block is pinned (won't be garbage collected) */
pinned: boolean;
/** Optional TTL in seconds (0 = no expiration) */
ttl: number;
}
/**
* Block metadata (without data)
*/
export interface BlockMetadata {
cid: CID;
size: number;
addedAt: number;
lastAccessedAt: number;
pinned: boolean;
ttl: number;
}
/**
* Cache statistics
*/
export interface CacheStats {
/** Total number of blocks */
blockCount: number;
/** Total size in bytes */
totalSize: number;
/** Number of pinned blocks */
pinnedBlocks: number;
/** Size of pinned blocks */
pinnedSize: number;
}
/**
* Block request message
*/
export interface BlockRequest {
type: 'block-request';
cid: CID;
requestId: string;
}
/**
* Block response message
*/
export interface BlockResponse {
type: 'block-response';
cid: CID;
requestId: string;
data: Uint8Array | null;
}
/**
* Block announcement message (for propagation)
*/
export interface BlockAnnouncement {
type: 'block-announcement';
cid: CID;
size: number;
}
/**
* Mesh cache protocol messages
*/
export type CacheMessage = BlockRequest | BlockResponse | BlockAnnouncement;
//# sourceMappingURL=types.d.ts.map