import type { CandidDisplayReactorParameters, DynamicMethodOptions } from "./types.js";
import { CandidAdapter } from "./adapter.js";
import { BaseActor, TransformKey, DisplayReactor } from "@ic-reactor/core";
/**
* CandidDisplayReactor combines the display transformation capabilities of
* DisplayReactor with dynamic Candid parsing from CandidReactor.
*
* This class provides:
* - **Display transformations**: Automatic type conversion between Candid and
* display-friendly types (bigint ↔ string, Principal ↔ string, etc.)
* - **Validation**: Optional argument validation with display types
* - **Dynamic Candid parsing**: Initialize from Candid source or fetch from network
* - **Dynamic method registration**: Register methods at runtime with Candid signatures
*
* @typeParam A - The actor service type
*
* @example
* ```typescript
* import { CandidDisplayReactor } from "@ic-reactor/candid"
*
* const reactor = new CandidDisplayReactor({
* clientManager,
* canisterId: "ryjl3-tyaaa-aaaaa-aaaba-cai",
* })
*
* // Initialize from network (fetches Candid from canister)
* await reactor.initialize()
*
* // Or provide Candid source directly
* const reactor2 = new CandidDisplayReactor({
* clientManager,
* canisterId: "...",
* candid: `service : { greet : (text) -> (text) query }`
* })
* await reactor2.initialize()
*
* // Call methods with display types (strings instead of bigint/Principal)
* const result = await reactor.callMethod({
* functionName: "transfer",
* args: [{ to: "aaaaa-aa", amount: "1000000" }] // strings!
* })
*
* // Add validation
* reactor.registerValidator("transfer", ([input]) => {
* if (!input.to) {
* return { success: false, issues: [{ path: ["to"], message: "Required" }] }
* }
* return { success: true }
* })
* ```
*/
export declare class CandidDisplayReactor extends DisplayReactor {
readonly transform: T;
adapter: CandidAdapter;
private candidSource?;
constructor(config: CandidDisplayReactorParameters);
/**
* Initializes the reactor by parsing the provided Candid string or fetching it from the network.
* This updates the internal service definition with the actual canister interface.
*
* After initialization, all DisplayReactor methods work with display type transformations.
*
* @example
* ```typescript
* const reactor = new CandidDisplayReactor({
* clientManager,
* canisterId: "ryjl3-tyaaa-aaaaa-aaaba-cai",
* })
*
* // Fetches Candid from the canister and initializes
* await reactor.initialize()
*
* // Now you can call methods with display types
* const balance = await reactor.callMethod({
* functionName: "icrc1_balance_of",
* args: [{ owner: "aaaaa-aa" }] // Principal as string!
* })
* ```
*/
initialize(): Promise;
/**
* Re-initialize the display codecs after the service has been updated.
* This is called automatically after initialize() or registerMethod().
*/
private reinitializeCodecs;
/**
* Register a dynamic method by its Candid signature.
* After registration, all DisplayReactor methods work with display type transformations.
*
* @example
* ```typescript
* // Register a method
* await reactor.registerMethod({
* functionName: "icrc1_balance_of",
* candid: "(record { owner : principal }) -> (nat) query"
* })
*
* // Now use with display types!
* const balance = await reactor.callMethod({
* functionName: "icrc1_balance_of",
* args: [{ owner: "aaaaa-aa" }] // Principal as string
* })
* // balance is string (not bigint) due to display transformation
* ```
*/
registerMethod(options: DynamicMethodOptions): Promise;
/**
* Register multiple methods at once.
*
* @example
* ```typescript
* await reactor.registerMethods([
* { functionName: "icrc1_balance_of", candid: "(record { owner : principal }) -> (nat) query" },
* { functionName: "icrc1_transfer", candid: "(record { to : principal; amount : nat }) -> (variant { Ok : nat; Err : text })" }
* ])
* ```
*/
registerMethods(methods: DynamicMethodOptions[]): Promise;
/**
* Check if a method is registered (either from initialize or registerMethod).
*/
hasMethod(functionName: string): boolean;
/**
* Get all registered method names.
*/
getMethodNames(): string[];
/**
* Perform a dynamic update call in one step with display type transformations.
* Registers the method if not already registered, then calls it.
*
* @example
* ```typescript
* const result = await reactor.callDynamic({
* functionName: "transfer",
* candid: "(record { to : principal; amount : nat }) -> (variant { Ok : nat; Err : text })",
* args: [{ to: "aaaaa-aa", amount: "100" }] // Display types!
* })
* ```
*/
callDynamic(options: DynamicMethodOptions & {
args?: unknown[];
}): Promise;
/**
* Perform a dynamic query call in one step with display type transformations.
* Registers the method if not already registered, then calls it.
*
* @example
* ```typescript
* const balance = await reactor.queryDynamic({
* functionName: "icrc1_balance_of",
* candid: "(record { owner : principal }) -> (nat) query",
* args: [{ owner: "aaaaa-aa" }] // Display types!
* })
* // balance is string (not BigInt)
* ```
*/
queryDynamic(options: DynamicMethodOptions & {
args?: unknown[];
}): Promise;
/**
* Fetch with dynamic Candid and TanStack Query caching.
* Registers the method if not already registered, then fetches with caching.
* Results are transformed to display types.
*
* @example
* ```typescript
* const balance = await reactor.fetchQueryDynamic({
* functionName: "icrc1_balance_of",
* candid: "(record { owner : principal }) -> (nat) query",
* args: [{ owner: "aaaaa-aa" }]
* })
* // Subsequent calls with same args return cached result
* ```
*/
fetchQueryDynamic(options: DynamicMethodOptions & {
args?: unknown[];
}): Promise;
}
//# sourceMappingURL=display-reactor.d.ts.map