import { extractCsvEntities } from './csv.js';
import { extractJsonEntities, isJsonStructureComplete } from './json.js';
import { extractMarkdownEntities } from './markdown.js';
import { extractTomlEntities } from './toml.js';
import { extractYamlEntities } from './yaml.js';
export { FormatEntityKindSchema } from './types.js';
export { extractCsvEntities } from './csv.js';
export { extractJsonEntities } from './json.js';
export { extractMarkdownEntities, scanMarkdownLines } from './markdown.js';
export { extractTomlEntities } from './toml.js';
export { extractYamlEntities } from './yaml.js';
/** Format name by file extension. Deliberately not part of `LANGUAGE_SPECS`. */
const FORMAT_BY_EXTENSION = new Map([
    ['.json', 'json'],
    ['.jsonc', 'json'],
    ['.json5', 'json'],
    ['.yaml', 'yaml'],
    ['.yml', 'yaml'],
    ['.toml', 'toml'],
    ['.md', 'markdown'],
    ['.mdx', 'markdown'],
    ['.markdown', 'markdown'],
    ['.csv', 'csv'],
    ['.tsv', 'csv'],
]);
export const FORMAT_EXTENSIONS = [...FORMAT_BY_EXTENSION.keys()].sort();
export function formatForPath(relativePath) {
    const lower = relativePath.toLowerCase();
    const dot = lower.lastIndexOf('.');
    if (dot === -1)
        return undefined;
    return FORMAT_BY_EXTENSION.get(lower.slice(dot));
}
/**
 * Extract entities from a data-format file, or nothing if the extension is not
 * one OCC models.
 *
 * These extractors are not registered as languages, so `occ code map`,
 * `dirtree`, and the code graph behave exactly as before; only the entity layer
 * consults them. Format entities get honest diff, blame, and history, and no
 * impact at all — they have no edges, and that is reported rather than
 * presented as "nothing depends on this".
 */
export function extractFormatEntities(relativePath, content) {
    const format = formatForPath(relativePath);
    if (!format)
        return undefined;
    try {
        switch (format) {
            case 'json':
                return { entities: extractJsonEntities(content), parseFailed: !isJsonStructureComplete(content) };
            case 'yaml':
                return { entities: extractYamlEntities(content), parseFailed: false };
            case 'toml':
                return { entities: extractTomlEntities(content), parseFailed: false };
            case 'markdown':
                return { entities: extractMarkdownEntities(content), parseFailed: false };
            case 'csv':
                return { entities: extractCsvEntities(content, relativePath), parseFailed: false };
            default:
                return undefined;
        }
    }
    catch {
        // Keep the query alive, but preserve the distinction between a proved empty
        // document and one whose structure could not be read.
        return { entities: [], parseFailed: true };
    }
}
/** Format kinds, for callers that need to enumerate what a format can produce. */
export const FORMAT_ENTITY_KINDS = [
    'object',
    'array',
    'array-item',
    'property',
    'section',
    'table',
    'array-table',
    'heading',
    'row',
    'document',
];
//# sourceMappingURL=index.js.map