UNPKG

@openfga/syntax-transformer

Version:

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

191 lines (190 loc) 7.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ModuleTransformationError = exports.ModuleTransformationSingleError = exports.FGAModFileValidationError = exports.FGAModFileValidationSingleError = exports.UnsupportedModularModules = exports.ConditionNameDoesntMatchError = exports.UnsupportedDSLNestingError = exports.ConfigurationError = exports.ModelValidationError = exports.ModelValidationSingleError = exports.DSLSyntaxError = exports.DSLSyntaxSingleError = exports.BaseMultiError = exports.BaseError = exports.ValidationError = void 0; var ValidationError; (function (ValidationError) { ValidationError["SchemaVersionRequired"] = "schema-version-required"; ValidationError["SchemaVersionUnsupported"] = "schema-version-unsupported"; ValidationError["ReservedTypeKeywords"] = "reserved-type-keywords"; ValidationError["ReservedRelationKeywords"] = "reserved-relation-keywords"; ValidationError["SelfError"] = "self-error"; ValidationError["InvalidName"] = "invalid-name"; ValidationError["MissingDefinition"] = "missing-definition"; ValidationError["InvalidRelationType"] = "invalid-relation-type"; ValidationError["InvalidRelationOnTupleset"] = "invalid-relation-on-tupleset"; ValidationError["InvalidType"] = "invalid-type"; ValidationError["RelationNoEntrypoint"] = "relation-no-entry-point"; ValidationError["TuplesetNotDirect"] = "tupleuserset-not-direct"; ValidationError["DuplicatedError"] = "duplicated-error"; ValidationError["RequireSchema1_0"] = "allowed-type-schema-10"; ValidationError["AssignableRelationsMustHaveType"] = "assignable-relation-must-have-type"; ValidationError["AllowedTypesNotValidOnSchema1_0"] = "allowed-type-not-valid-on-schema-1_0"; ValidationError["InvalidSchema"] = "invalid-schema"; ValidationError["InvalidSyntax"] = "invalid-syntax"; ValidationError["TypeRestrictionCannotHaveWildcardAndRelation"] = "type-wildcard-relation"; ValidationError["ConditionNotDefined"] = "condition-not-defined"; ValidationError["ConditionNotUsed"] = "condition-not-used"; ValidationError["DifferentNestedConditionName"] = "different-nested-condition-name"; ValidationError["MultipleModulesInFile"] = "multiple-modules-in-file"; })(ValidationError || (exports.ValidationError = ValidationError = {})); /** * Abstract base class for syntax and validation exceptions. * Line and column numbers returned as part of this are zero based. */ class BaseError extends Error { constructor(properties, type) { super(`${type} error${properties.line !== undefined && properties.column !== undefined ? ` at line=${properties.line.start}, column=${properties.column.start}` : ""}: ${properties.msg}`); this.properties = properties; this.type = type; this.line = properties.line; this.column = properties.column; this.msg = properties.msg; this.file = properties.file; } toString() { return this.message; } } exports.BaseError = BaseError; /** * Abstract base class for errors that collate other errors. */ class BaseMultiError extends Error { constructor(errors) { super(`${errors.length} error${errors.length > 1 ? "s" : ""} occurred:\n\t* ${errors.join("\n\t* ")}\n\n`); this.errors = errors; this.errors = errors; } toString() { return this.message; } } exports.BaseMultiError = BaseMultiError; /** * Added to listener during syntax parsing, when syntax errors are encountered. * Line and column numbers returned as part of this are zero based. */ class DSLSyntaxSingleError extends BaseError { constructor(properties, metadata, e) { super(properties, "syntax"); this.properties = properties; this.metadata = metadata; if (e === null || e === void 0 ? void 0 : e.stack) { this.stack = e.stack; } this.metadata = metadata; } toString() { return this.message; } } exports.DSLSyntaxSingleError = DSLSyntaxSingleError; /** * Thrown at the end of syntax parsing, collecting all Syntax errors encountered during parsing */ class DSLSyntaxError extends BaseMultiError { } exports.DSLSyntaxError = DSLSyntaxError; /** * Added to reporter as the JSON transformation is being parsed and validated * Line and column numbers returned as part of this are zero based. */ class ModelValidationSingleError extends BaseError { constructor(properties, metadata) { super(properties, (metadata === null || metadata === void 0 ? void 0 : metadata.errorType) || "validation"); this.properties = properties; this.metadata = metadata; this.metadata = metadata; } toString() { return this.message; } } exports.ModelValidationSingleError = ModelValidationSingleError; /** * Thrown at end of checkDSL validation, collecting all encountered validation errors */ class ModelValidationError extends BaseMultiError { } exports.ModelValidationError = ModelValidationError; /** * Thrown when improper values are passed. */ class ConfigurationError extends Error { constructor(message, e) { super(message); this.message = message; this.e = e; if (e === null || e === void 0 ? void 0 : e.stack) { this.stack = e.stack; } } } exports.ConfigurationError = ConfigurationError; class UnsupportedDSLNestingError extends Error { constructor(typeName, relationName) { super(`the '${relationName}' relation definition under the '${typeName}' type is not supported by the OpenFGA DSL syntax yet`); this.typeName = typeName; this.relationName = relationName; } } exports.UnsupportedDSLNestingError = UnsupportedDSLNestingError; class ConditionNameDoesntMatchError extends Error { constructor(conditionName, conditionNestedName) { super(`the '${conditionName}' condition has a different nested condition name ('${conditionNestedName}')`); this.conditionName = conditionName; this.conditionNestedName = conditionNestedName; } } exports.ConditionNameDoesntMatchError = ConditionNameDoesntMatchError; class UnsupportedModularModules extends Error { constructor(schemaVersion) { super(`model schema version ${schemaVersion} does not support modules`); this.schemaVersion = schemaVersion; } } exports.UnsupportedModularModules = UnsupportedModularModules; /** * Represents an individual error returned during validation of `fga.mod`. * Line and column numbers returned as part of this are zero based. */ class FGAModFileValidationSingleError extends BaseError { constructor(properties) { super(properties, "validation"); this.properties = properties; } toString() { return this.message; } } exports.FGAModFileValidationSingleError = FGAModFileValidationSingleError; /** * Thrown when an `fga.mod` file is invalid. */ class FGAModFileValidationError extends BaseMultiError { } exports.FGAModFileValidationError = FGAModFileValidationError; /* * Represents an individual error returned during transformation of a module. * Line and column numbers returned as part of this are zero based. */ class ModuleTransformationSingleError extends BaseError { constructor(properties, metadata) { super(properties, "transformation-error"); this.properties = properties; this.metadata = metadata; this.metadata = metadata; } toString() { return this.message; } } exports.ModuleTransformationSingleError = ModuleTransformationSingleError; /** * Thrown when a module is invalid. */ class ModuleTransformationError extends BaseMultiError { } exports.ModuleTransformationError = ModuleTransformationError;