#json-parser #dsl #json #parser #transformer #openfga

openfga-dsl-parser

Parsing and JSON transformer for the OpenFGA authorization DSL

1 stable release

1.0.0 Jul 31, 2022

#2889 in Parser implementations

Download history 71/week @ 2024-02-16 33/week @ 2024-02-23 9/week @ 2024-03-01

113 downloads per month

Apache-2.0

33KB
849 lines

OpenFGA DSL Parser

The OpenFGA DSL Parser provides utilities for parsing DSL file string inputs into an AST representation, as well as transforming them into a JSON representation.

This library is meant to be a utility for services using OpenFGA for their authorization solution, but need a way to translate from their DSL to the JSON format the HTTP API expects. A Typescript library is available that does something similar, however this library aims to target Rust as well as be a base for other potential languages to bind to.

Usage

use openfga_dsl_parser::{json, Parser};

let input = "type group
  relations
    define member as self
type resource
  relations
    define writer as self
    define reader as self but not writer";

let mut parser = Parser::new(input);
let doc = parser.parse_document()?;

let json = json::JsonTransformer::new(&doc).serialize();

lib.rs:

OpenFGA DSL Parser

The OpenFGA DSL Parser provides utilities for parsing DSL file string inputs into an AST representation, as well as transforming them into a JSON representation.

This library is meant to be a utility for services using OpenFGA for their authorization solution, but need a way to translate from their DSL to the JSON format the HTTP API expects. A Typescript library is available that does something similar, however this aims to target Rust, as well as be a base for other potential languages to bind to.

Usage

use openfga_dsl_parser::{json, Parser};

let input = "type group
  relations
    define member as self
type resource
  relations
    define writer as self
    define reader as self but not writer";

let mut parser = Parser::new(input);
let doc = parser.parse_document()?;

let json = json::JsonTransformer::new(&doc).serialize();

Dependencies

~360–760KB
~17K SLoC