"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseDirectives = exports.directiveRegex = void 0;
exports.directiveRegex = new RegExp(/^\s*(--|\/\*)\s*ts-sql-plugin:(?<directive>[\w\d\-]+)(?:\((?<arg>.*)\))?\s*(\*\/)?\s*$/);
const takeUntil = (source, predicate) => {
    const takeUntil = source.findIndex(predicate);
    return source.slice(0, takeUntil);
};
exports.parseDirectives = (query) => {
    return takeUntil(query.split("\n"), line => !line.match(/^\s*(?:(--|\/\*).*)?$/)).reduce((accum, line) => {
        const match = line.trimLeft().match(exports.directiveRegex);
        if (match) {
            const { directive, arg } = match.groups;
            return [...accum, { directive, arg: arg && JSON.parse(arg) }];
        }
        else {
            return accum;
        }
    }, []);
};
//# sourceMappingURL=directiveParser.js.map