"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTestDatabasePrefix = createTestDatabasePrefix;
exports.formatTestDatabaseName = formatTestDatabaseName;
const node_crypto_1 = require("node:crypto");
const node_path_1 = require("node:path");
const DIRECTORY_HASH_LENGTH = 4;
const DATABASE_NAME_HASH_LENGTH = 8;
const MAX_DATABASE_NAME_LENGTH = 63;
const MAX_DATABASE_PREFIX_LENGTH = 40;
function createTestDatabasePrefix(prefix = 'test', directory = process.cwd()) {
    const safePrefix = shortenValue(prefix.replace(/[^a-zA-Z0-9_]/g, '_') || 'test', MAX_DATABASE_PREFIX_LENGTH - DIRECTORY_HASH_LENGTH - 1);
    const directoryHash = (0, node_crypto_1.createHash)('sha1').update((0, node_path_1.resolve)(directory)).digest('hex').slice(0, DIRECTORY_HASH_LENGTH);
    return `${safePrefix}_${directoryHash}`;
}
function formatTestDatabaseName(prefix, parts) {
    const name = `${createTestDatabasePrefix(prefix)}_${parts.join('_')}`;
    return shortenValue(name, MAX_DATABASE_NAME_LENGTH);
}
function shortenValue(value, maxLength) {
    if (value.length <= maxLength)
        return value;
    const hash = (0, node_crypto_1.createHash)('sha1').update(value).digest('hex').slice(0, DATABASE_NAME_HASH_LENGTH);
    return `${value.slice(0, maxLength - DATABASE_NAME_HASH_LENGTH - 1)}_${hash}`;
}
//# sourceMappingURL=database-name.js.map