API Reference
Compiler API
Compile and inspect Matador policies programmatically from JavaScript or TypeScript.
@steerprotocol/matador-core exposes the same compiler pipeline used by the
Matador CLI.
Installation
npm install @steerprotocol/matador-coreThe package uses ES modules and requires Node.js 20 or newer.
Compile a policy
import { compile } from '@steerprotocol/matador-core';
const source = `
permission AllowAll -> v1 {
pub fn authorize() -> bool {
return true;
}
fn main() -> bool {
return true;
}
}
`;
const result = await compile(source);
if (!result.output) {
throw new Error(result.diagnostics.map(({ message }) => message).join('\n'));
}
console.log(result.output.hexData);
console.log(result.output.requiredModules);The successful output includes interpreter bytecode, canonical policy JSON, instruction metadata, parameter mappings, and the required interpreter modules.
Parse without compiling
Use parse when an editor or analysis tool needs the validated Langium AST
without lowering it to interpreter bytecode.
import { parse } from '@steerprotocol/matador-core';
const result = await parse(source, 'file:///policies/example.matador');For direct access to the parser, generated AST types, formatter, validator, and
language services, install @steerprotocol/matador-language.