UNPKG

@rb2bv/cache-handler

Version:
69 lines (63 loc) 2.33 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/helpers/helpers.ts var helpers_exports = {}; __export(helpers_exports, { getTimeoutRedisCommandOptions: () => getTimeoutRedisCommandOptions, isImplicitTag: () => isImplicitTag, promiseWithTimeout: () => promiseWithTimeout }); module.exports = __toCommonJS(helpers_exports); // src/constants.ts var MAX_INT32 = 2 ** 31 - 1; // src/helpers/promise-with-timeout.ts function promiseWithTimeout(operation, timeoutMs) { if (typeof timeoutMs !== "number" || Number.isNaN(timeoutMs) || timeoutMs <= 0 || timeoutMs > MAX_INT32) { return operation; } return new Promise((resolve, reject) => { const timeoutId = setTimeout(reject, timeoutMs, new Error(`Operation timed out after ${timeoutMs} ms`)); operation.then((result) => { clearTimeout(timeoutId); resolve(result); }).catch((error) => { clearTimeout(timeoutId); reject(error); }); }); } // src/helpers/is-implicit-tag.ts var NEXT_CACHE_IMPLICIT_TAG_ID = "_N_T_"; function isImplicitTag(tag) { return tag.startsWith(NEXT_CACHE_IMPLICIT_TAG_ID); } // src/helpers/get-timeout-redis-command-options.ts var import_redis = require("redis"); function getTimeoutRedisCommandOptions(timeoutMs) { if (timeoutMs === 0) { return (0, import_redis.commandOptions)({}); } return (0, import_redis.commandOptions)({ signal: AbortSignal.timeout(timeoutMs) }); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getTimeoutRedisCommandOptions, isImplicitTag, promiseWithTimeout });