@zanzibar-ts/dsl
v0.1.1
Published
OpenFGA DSL → @zanzibar-ts/core model bridge — lower existing OpenFGA DSL text to a validated zanzibar-ts model (a build-time / migration tool, never in the core bundle)
Maintainers
Readme
@zanzibar-ts/dsl
Lower an existing OpenFGA DSL model (the model … schema 1.1 … text) to a validated
@zanzibar-ts/core model — migrate without
rewriting your model by hand. It wraps @openfga/syntax-transformer, so the parse is byte-faithful
to what OpenFGA itself ingests.
import { deepStrictEqual as assertEquals } from 'node:assert/strict';
import { modelFromDsl } from '@zanzibar-ts/dsl';
import { createEngine } from '@zanzibar-ts/core';
// paste your existing OpenFGA DSL verbatim
const model = modelFromDsl(`
model
schema 1.1
type user
type group
relations
define member: [user, group#member]
type document
relations
define editor: [user, group#member]
define viewer: [user, group#member] or editor
`);
const engine = createEngine(model);
await engine.write([
{ object: 'group:eng', relation: 'member', subject: 'user:anne' },
{ object: 'document:readme', relation: 'editor', subject: 'group:eng#member' },
]);
// editors are viewers (the `or editor` union), and the grant flows through the group:
assertEquals(
await engine.check({ object: 'document:readme', relation: 'viewer', subject: 'user:anne' }),
{ ok: true, value: true },
);modelFromDsl throws a DslError if the text doesn't parse (category: 'syntax') or is
semantically invalid (a dangling reference, a bad rewrite), so a broken model fails loudly at load.
Need just the JSON? dslToJson(dsl) returns the OpenFGA JSON model without validating.
Why a separate package
@zanzibar-ts/dsl is not part of @zanzibar-ts/core and is never in its bundle — the
syntax-transformer (and its OpenFGA SDK dependency) is large, and the edge bundle must stay small.
Use it at build time, or once to port a model. For models authored fresh, prefer the typed
defineModel builder — it's checked by tsc and
has no heavy dependency.
@zanzibar-ts/dslbundles@openfga/sdkinto its dependency closure to work around an upstream bug (@openfga/syntax-transformerrequire()s the SDK without declaring it), so the install is self-contained.
See the migration recipe for the full walkthrough.
License
MIT
