UNPKG

@openfga/syntax-transformer

Version:

Javascript implementation of ANTLR Grammar for the OpenFGA DSL and parser from and to the OpenFGA JSON Syntax

38 lines (37 loc) 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRelationLineNumber = exports.getTypeLineNumber = exports.getConditionLineNumber = void 0; const getConditionLineNumber = (conditionName, lines, skipIndex) => { if (!skipIndex) { skipIndex = 0; } if (!lines) { return undefined; } return (lines.slice(skipIndex).findIndex((line) => line.trim().startsWith(`condition ${conditionName}`)) + skipIndex); }; exports.getConditionLineNumber = getConditionLineNumber; const getTypeLineNumber = (typeName, lines, skipIndex, extension = false) => { if (!skipIndex) { skipIndex = 0; } if (!lines) { return undefined; } return (lines .slice(skipIndex) .findIndex((line) => line.trim().match(`^${extension ? "extend " : ""}type ${typeName}$`)) + skipIndex); }; exports.getTypeLineNumber = getTypeLineNumber; const getRelationLineNumber = (relation, lines, skipIndex) => { if (!skipIndex) { skipIndex = 0; } if (!lines) { return undefined; } return (lines .slice(skipIndex) .findIndex((line) => line.trim().replace(/ {2,}/g, " ").match(`^define ${relation}\\s*:`)) + skipIndex); }; exports.getRelationLineNumber = getRelationLineNumber;