export const CACHE_FORMAT_VERSION = 2;
export const DEFAULT_CACHE_MAX_MB = 512;
export const DEFAULT_CACHE_TTL_DAYS = 30;
export const CACHE_KINDS = [
    "extract",
    "summary",
    "transcript",
    "chat",
    "slides",
];
export function createEmptyCacheCounts() {
    return {
        extract: 0,
        summary: 0,
        transcript: 0,
        chat: 0,
        slides: 0,
    };
}
export function isCacheKind(value) {
    return typeof value === "string" && CACHE_KINDS.includes(value);
}
export function measureCacheValueBytes(value) {
    const maybeBuffer = globalThis
        .Buffer;
    if (typeof maybeBuffer?.byteLength === "function") {
        return maybeBuffer.byteLength(value, "utf8");
    }
    return new TextEncoder().encode(value).byteLength;
}
export function buildPortableCacheRow({ kind, key, value, ttlMs, now = Date.now(), }) {
    return {
        kind,
        key,
        value,
        sizeBytes: measureCacheValueBytes(value),
        createdAt: now,
        lastAccessedAt: now,
        expiresAt: typeof ttlMs === "number" ? now + ttlMs : null,
    };
}
export function isPortableCacheRowExpired(row, now = Date.now()) {
    return typeof row.expiresAt === "number" && row.expiresAt <= now;
}
export function parseCacheJson(value) {
    if (!value)
        return null;
    try {
        return JSON.parse(value);
    }
    catch {
        return null;
    }
}
export function summarizePortableCacheRows(rows, path) {
    const counts = createEmptyCacheCounts();
    let sizeBytes = 0;
    let totalEntries = 0;
    for (const row of rows) {
        if (!isCacheKind(row.kind))
            continue;
        counts[row.kind] += 1;
        sizeBytes += Math.max(0, row.sizeBytes);
        totalEntries += 1;
    }
    return { path, sizeBytes, totalEntries, counts };
}
//# sourceMappingURL=cache-store.js.map