Conjure
Conjure is the builder an output uses to write TypeScript. It is a small set of functions over recast's AST builders. An AST (abstract syntax tree) is the tree a compiler reads instead of text.
Conjure has three rules:
- Every builder returns an
ast-typesnode type:Exprfor expressions,Stmtfor statements andTyfor types. Builders compose without casts. - The functions are pure. They hold no state and import nothing from
node:, so Conjure runs in a browser. printis the only printer. It gives every generated file the same layout.
import * as c from "pg-sourcerer/conjure"
const schema = c.id("Schema").method(
"Struct",
c.obj().prop("id", c.id("Schema").member("String").build()).build(),
).build()
console.log(c.print([c.exportConst("User", schema)]))
// export const User = Schema.Struct({
// id: Schema.String
// });
Pages
- Expressions: names, member chains, calls, objects, arrays, functions and templates.
- Types and statements: the
c.tstype builders and the statements an output exports. - Symbols: how an output declares what it exports and how the generator links the imports between files.
The source is packages/pg-sourcerer/src/conjure/index.ts and types.ts.