@ic-reactor/codegen
v0.12.0
Published
Shared code generation utilities for IC Reactor
Downloads
541
Maintainers
Readme
@ic-reactor/codegen
shared code generation pipeline and utilities for IC Reactor.
This package contains the core machinery for generating TypeScript declarations, reactor instances, and client managers from Candid files. It is primarily used by:
@ic-reactor/cli: For manual/CLI-based generation@ic-reactor/vite-plugin: For automatic build-time generation
API
The main entry point is the runCanisterPipeline function, which orchestrates the generation process.
import { runCanisterPipeline } from "@ic-reactor/codegen"
await runCanisterPipeline({
canisterConfig: {
name: "backend",
mode: "DisplayReactor",
didFile: "./backend.did",
},
projectRoot: process.cwd(),
globalConfig: {
outDir: "src/declarations",
clientManagerPath: "../../clients",
target: "react",
},
generateReactor: true,
})Reactor Class Configuration
Set canisterConfig.mode to choose the generated reactor class:
DisplayReactor(default)ReactorCandidReactorCandidDisplayReactorMetadataDisplayReactor
Set target to control whether generated files include React hooks:
react(default): generates the reactor plus boundcreateActorHooksexportscore: generates only the typed reactor exports with no@ic-reactor/reactdependency
Codegen now writes two files per canister: a managed index.generated.ts implementation that is regenerated on every run, and an index.ts entry wrapper. The wrapper is created once, then preserved unless it still matches the default generated wrapper or an older generated scaffold that can be migrated automatically.
Set generateReactor: false if you only want the bindgen/declaration output and
need to skip index.generated.ts and index.ts.
Generators
You can also use individual generators if you need more granular control:
generateDeclarations: Writesdeclarations/<did-basename>.js(factory),.d.ts(types), and a.didcopy. Thedeclarations/directory is wiped and recreated on every run.generateReactorFile: Generates the managedindex.generated.tsimplementation using anyReactorClassName—Reactor,DisplayReactor(default),CandidReactor,CandidDisplayReactor, orMetadataDisplayReactor. Withtarget: "react"it also emits the sixcreateActorHooksexports (use<Canister>Query,use<Canister>SuspenseQuery,use<Canister>InfiniteQuery,use<Canister>SuspenseInfiniteQuery,use<Canister>Mutation,use<Canister>Method). NocreateQuery/createMutationobjects are generated.generateReactorEntryFile: Generates the stableindex.tswrapper that re-exports fromindex.generated.ts.generateClientFile: Generates aClientManagerboilerplate file that importsClientManagerfrom@ic-reactor/react.
Utilities
parseDIDFile/extractMethods: Parse a.didfile and extract method signatures.toPascalCase/getReactorName/getServiceTypeName: Naming helpers.generateCodecDeclarations: Renders a@ic-reactor/codcodec module from Candid (also available on the./renderersubpath).
License
MIT
