"use strict";
// Copyright 2018-2024 the Deno authors. MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCache = exports.FileFetcher = exports.DenoDir = exports.FetchCacher = void 0;
/**
 * A module which provides a TypeScript implementation of the Deno CLI's cache
 * directory logic (`DENO_DIR`). This can be used in combination with other
 * modules to provide user loadable APIs that are like the Deno CLI's
 * functionality.
 *
 * This also can provide user read access in Deploy to a Deno CLI's cache when
 * the cache is checked into the repository.
 *
 * ### Example
 *
 * ```ts
 * import { createCache } from "@deno/cache-dir";
 * import { createGraph } from "@deno/graph";
 *
 * // create a cache where the location will be determined environmentally
 * const cache = createCache();
 * // destructuring the two functions we need to pass to the graph
 * const { cacheInfo, load } = cache;
 * // create a graph that will use the cache above to load and cache dependencies
 * const graph = await createGraph("https://deno.land/x/oak@v9.0.1/mod.ts", {
 *   cacheInfo,
 *   load,
 * });
 *
 * // log out the console a similar output to `deno info` on the command line.
 * console.log(graph.toString());
 * ```
 *
 * @module
 */
const cache_js_1 = require("./cache.js");
const deno_dir_js_1 = require("./deno_dir.js");
const file_fetcher_js_1 = require("./file_fetcher.js");
var cache_js_2 = require("./cache.js");
Object.defineProperty(exports, "FetchCacher", { enumerable: true, get: function () { return cache_js_2.FetchCacher; } });
var deno_dir_js_2 = require("./deno_dir.js");
Object.defineProperty(exports, "DenoDir", { enumerable: true, get: function () { return deno_dir_js_2.DenoDir; } });
var file_fetcher_js_2 = require("./file_fetcher.js");
Object.defineProperty(exports, "FileFetcher", { enumerable: true, get: function () { return file_fetcher_js_2.FileFetcher; } });
/**
 * Creates a cache object that allows access to the internal `DENO_DIR` cache
 * structure for remote dependencies and cached output of emitted modules.
 */
function createCache({ root, cacheSetting = "use", allowRemote = true, readOnly, vendorRoot, } = {}) {
    const denoDir = new deno_dir_js_1.DenoDir(root);
    const fileFetcher = new file_fetcher_js_1.FileFetcher(() => {
        return denoDir.createHttpCache({
            readOnly,
            vendorRoot,
        });
    }, cacheSetting, allowRemote);
    return new cache_js_1.FetchCacher(fileFetcher);
}
exports.createCache = createCache;
