"use strict";
/* Socket Lib - Built with esbuild */
"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);
var resolve_exports = {};
__export(resolve_exports, {
  cacheKey: () => cacheKey,
  doResolveOpengrep: () => doResolveOpengrep,
  resetOpengrepResolution: () => resetOpengrepResolution,
  resolveOpengrep: () => resolveOpengrep
});
module.exports = __toCommonJS(resolve_exports);
var import_from_download = require("./from-download");
var import_from_path = require("./from-path");
var import_from_vfs = require("./from-vfs");
const resolutionCache = /* @__PURE__ */ new Map();
function cacheKey(opts) {
  if (!opts?.downloadIfMissing) {
    return "local-only";
  }
  const { cacheDir, integrity, platformArch, version } = opts.downloadIfMissing;
  const integrityKey = typeof integrity === "string" ? integrity : integrity ? `${integrity.type}:${integrity.value}` : "";
  return `dl:${version}:${platformArch}:${integrityKey}:${cacheDir ?? ""}`;
}
async function doResolveOpengrep(opts) {
  const fromVfs = await (0, import_from_vfs.opengrepFromVfs)();
  if (fromVfs) {
    return fromVfs;
  }
  const fromPath = await (0, import_from_path.opengrepFromPath)();
  if (fromPath) {
    return fromPath;
  }
  if (opts?.downloadIfMissing) {
    return (0, import_from_download.opengrepFromDownload)(opts.downloadIfMissing);
  }
  return void 0;
}
function resetOpengrepResolution() {
  resolutionCache.clear();
}
function resolveOpengrep(opts) {
  const key = cacheKey(opts);
  let cached = resolutionCache.get(key);
  if (!cached) {
    cached = doResolveOpengrep(opts);
    resolutionCache.set(key, cached);
  }
  return cached;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  cacheKey,
  doResolveOpengrep,
  resetOpengrepResolution,
  resolveOpengrep
});
