"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCachedValue = getCachedValue;
exports.setCachedValue = setCachedValue;
exports.hasCachedValue = hasCachedValue;
exports.clearCachedValue = clearCachedValue;
exports.getOrCacheValue = getOrCacheValue;
const ObjectStoreSymbol = Symbol.for('@zyno-io/ts-server-foundation:http-request-object-store');
function getCachedValue(request, key) {
    if (typeof key === 'object')
        return getObjectStore(request).get(key);
    return request.store[key];
}
function setCachedValue(request, key, value) {
    if (typeof key === 'object') {
        getObjectStore(request).set(key, value);
        return value;
    }
    request.store[key] = value;
    return value;
}
function hasCachedValue(request, key) {
    if (typeof key === 'object')
        return getObjectStore(request).has(key);
    return Object.hasOwn(request.store, key);
}
function clearCachedValue(request, key) {
    if (typeof key === 'object') {
        getObjectStore(request).delete(key);
        return;
    }
    delete request.store[key];
}
async function getOrCacheValue(request, key, factory) {
    if (hasCachedValue(request, key))
        return getCachedValue(request, key);
    return setCachedValue(request, key, await factory());
}
function getObjectStore(request) {
    const existing = request.store[ObjectStoreSymbol];
    if (existing instanceof Map)
        return existing;
    const store = new Map();
    request.store[ObjectStoreSymbol] = store;
    return store;
}
//# sourceMappingURL=store.js.map