@nomyx/canton-codegen
v0.1.0
Published
Generate TypeScript interfaces and template ID constants from Daml source files
Maintainers
Readme
@nomyx/canton-codegen
Generate TypeScript interfaces and template ID constants from Daml source files.
Installation
npm install @nomyx/canton-codegenCLI Usage
canton-codegen --input ./daml --output ./src/generated.tsThis scans all .daml files under the input directory and writes a single TypeScript
module containing typed interfaces and template ID constants for every template found.
Programmatic Usage
import { generate, parseDamlSource, emit } from '@nomyx/canton-codegen';
// One-shot: read Daml files and write the output
await generate({
input: './daml',
output: './src/generated.ts',
});
// Step-by-step: parse then emit
const templates = parseDamlSource('daml/Main.daml');
const tsSource = emit(templates);Output Example
For a Daml template Main:Asset with fields owner: Party and quantity: Int,
the codegen produces:
export interface Asset {
owner: string;
quantity: string;
}
export const Asset = {
templateId: 'Main:Asset' as const,
};License
Apache-2.0 -- see LICENSE for details.
