import GRPCClient from "./GRPCClient"; import IClientActorBuilder from "../../../interfaces/Client/IClientActorBuilder"; import Class from "../../../types/Class"; /** * gRPC-based actor building block implementation. * * Provides actor proxy creation for virtual actor patterns. Actors are stateful, * re-entrant objects with built-in timers and reminders. This implementation * uses gRPC for efficient communication with actor instances on the Dapr sidecar. * * @implements {IClientActorBuilder} * @see {@link https://docs.dapr.io/reference/api/actors_api/} Dapr Actors API * @see {@link DaprClient.actor} for unified API * * @internal */ export default class GRPCClientActor implements IClientActorBuilder { /** * Reference to the underlying gRPC client. */ client: GRPCClient; /** * Creates a gRPC actor building block. * * @param client - The gRPC client instance */ constructor(client: GRPCClient); /** * Creates an actor proxy for invoking actor methods. * * Returns a proxy instance of the specified actor type with a randomly generated ID. * The proxy forwards method calls to the Dapr sidecar's actor runtime. * * **Note:** ActorTypeClass is required because JavaScript's type information is erased at runtime. * Unlike TypeScript's compile-time generics, we cannot instantiate T directly, so the class * must be passed explicitly. * * @typeParam T - The actor class type * @param actorTypeClass - The actor class (required for runtime instantiation) * * @returns A proxy instance of type T with a random actor ID * * @throws Throws if actor class is invalid or proxy builder fails * * @example * ```typescript * class MyActor { * async doSomething(value: string): Promise { * return `Processed: ${value}`; * } * } * * const actor = client.actor.create(MyActor); * const result = await actor.doSomething("test"); * ``` * * @see {@link ActorProxyBuilder} for proxy implementation details */ create(actorTypeClass: Class): T; }