"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SANDBOX_RUN_DIRECTORY_PREFIX = exports.SANDBOX_PARENT_DIRECTORY = void 0;
exports.isSandboxRunDirectoryName = isSandboxRunDirectoryName;
exports.composeSandboxRunDirectoryName = composeSandboxRunDirectoryName;
exports.composeSandboxRunDirectoryPath = composeSandboxRunDirectoryPath;
const node_path_1 = __importDefault(require("node:path"));
exports.SANDBOX_PARENT_DIRECTORY = "sandbox";
exports.SANDBOX_RUN_DIRECTORY_PREFIX = "run-";
const SANDBOX_RUN_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
const SANDBOX_RUN_DIRECTORY_NAME_PATTERN = /^run-[A-Za-z0-9][A-Za-z0-9._-]*$/;
function isSandboxRunDirectoryName(value) {
    return SANDBOX_RUN_DIRECTORY_NAME_PATTERN.test(value);
}
function composeSandboxRunDirectoryName(runId) {
    if (runId === "") {
        throw new RangeError("Sandbox run IDs must not be empty.");
    }
    if (!SANDBOX_RUN_ID_PATTERN.test(runId)) {
        throw new RangeError(`Sandbox run IDs must be filesystem-safe: ${runId}`);
    }
    return `${exports.SANDBOX_RUN_DIRECTORY_PREFIX}${runId}`;
}
function composeSandboxRunDirectoryPath(runId) {
    return node_path_1.default.posix.join(exports.SANDBOX_PARENT_DIRECTORY, composeSandboxRunDirectoryName(runId));
}
