# @openfga/syntax-transformer

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

Latest version **0.2.2** (published 2026-07-07) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @openfga/syntax-transformer
pnpm add @openfga/syntax-transformer
yarn add @openfga/syntax-transformer
bun add @openfga/syntax-transformer
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2026-07-07 |
| First published | 2022-06-15 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=20.19.0 |
| Dependencies | 3 |
| Unpacked size | 392 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 35 |
| Author | OpenFGA |
| Maintainers | aaguiarz, rhamzeh_auth0, openfgateam |
| Keywords | openfga, authorization, fga, fine-grained-authorization, rebac, zanzibar |

## Links

- npm: https://www.npmjs.com/package/@openfga/syntax-transformer
- Repository: https://github.com/openfga/language
- Homepage: https://github.com/openfga/language#readme
- Issues: https://github.com/openfga/language/issues
- npm.io page: https://npm.io/package/@openfga/syntax-transformer

## Dependencies (3)

- [ajv](https://npm.io/package/ajv.md) ^8.18.0
- [yaml](https://npm.io/package/yaml.md) ^2.8.2
- [antlr4](https://npm.io/package/antlr4.md) ^4.13.2

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 0.2.2 (latest) — 2026-07-07
- 0.2.0 (beta) — 2025-07-22
- 0.2.1 — 2026-02-11
- 0.2.0-beta.22 — 2024-09-30
- 0.2.0-beta.21 — 2024-09-09
- 0.2.0-beta.20 — 2024-09-06
- 0.2.0-beta.19 — 2024-07-25
- 0.2.0-beta.18 — 2024-06-12
- 0.2.0-beta.17 — 2024-04-12
- 0.2.0-beta.16 — 2024-04-04
- 0.2.0-beta.15 — 2024-04-01
- 0.2.0-beta.14 — 2024-03-27
- 0.2.0-beta.13 — 2024-03-22
- 0.2.0-beta.12 — 2024-03-19
- 0.2.0-beta.11 — 2024-02-22
- … 30 more at https://npm.io/package/@openfga/syntax-transformer/versions

## README

# OpenFGA Language - JS

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

[![@openfga/syntax-transformer](https://img.shields.io/npm/v/%40openfga%2Fsyntax-transformer/beta?label=%40openfga%2Fsyntax-transformer&style=flat-square)](https://www.npmjs.com/package/@openfga/syntax-transformer)

## Installation

```bash
npm install @openfga/syntax-transformer
```

### Supported Node.js Versions

For details on the supported Node.js versions and our support policy, see [SUPPORTED_RUNTIMES.md](./SUPPORTED_RUNTIMES.md).

## Usage

### Transformer

Example transform DSL model to JSON, and from JSON to DSL.

```typescript
import { transformer } from "@openfga/syntax-transformer";

let dslString = `model
  schema 1.1
type user
type folder
  relations
    define viewer: [user]`;

// Transform from DSL model to a JSON object
const generatedJsonObject = transformer.transformDSLToJSONObject(dslString);

// Transform from DSL to a JSON string
const generatedJsonString = transformer.transformDSLToJSONString(dslString);

// Transform from a JSON string to DSL
const generatedDsl = transformer.transformJSONStringToDSL(generatedJsonString);
```

### Transform Mod File to JSON

```typescript
import { transformer } from "@openfga/syntax-transformer";

...

const modFileContents = `schema: "1.2"
contents:
  - core.fga
  - board.fga
  - wiki.fga`

// Transform from fga.mod to an object
const jsonModFile = transformer.TransformModFile(modFileContents)
```

### Transform set of Modules To Model

```typescript
import { transformer } from "@openfga/syntax-transformer";

...

const files: transformer.ModuleFile[] = [];
files.push({
    name: "core.fga",
    contents: `module core
    type user`
  },
  {
    name: "board.fga",
    contents: `module core
    type board`
  },
  {
    name: "wiki.fga",
		contents: `module core
    type wiki`
  }
);

// Compile module files into a complete model
const jsonModel = transformer.transformModuleFilesToModel(files, "1.2");

/*
{
  "schema_version": "1.2",
  "type_definitions": [
    {
      "type": "user",
      "metadata": {
        "module": "core",
        "source_info": {
          "file": "core.fga"
        }
      }
    },
    {
      "type": "board",
      "metadata": {
        "module": "core",
        "source_info": {
          "file": "board.fga"
        }
      }
    },
    {
      "type": "wiki",
      "metadata": {
        "module": "core",
        "source_info": {
          "file": "wiki.fga"
        }
      }
    }
  ]
}
*/

```

### Validation

```typescript
import { errors, validator } from "@openfga/syntax-transformer";

...

let dslString = `model
  schema 1.2
type user
type folder
  relations
    define viewer: [user]`;

// Attempt validation of model
try {
  validator.validateDSL(dslString);
} catch (err) {
  if (err instanceof errors.BaseMultiError) {
    // Handle generated errors
  } else {
    console.error("Unhandled Exception: " + err);
  }
}

```

## License

This project is licensed under the Apache-2.0 license. See the [LICENSE](https://github.com/openfga/language/blob/main/LICENSE) file for more info.

---
_Source: https://npm.io/package/@openfga/syntax-transformer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
