import GRPCClient from "./GRPCClient"; import IClientBinding from "../../../interfaces/Client/IClientBinding"; import { KeyValueType } from "../../../types/KeyValue.type"; /** * gRPC-based output bindings building block implementation. * * Output bindings invoke external systems through the Dapr sidecar. * This implementation uses gRPC for efficient communication with binding connectors. * * Supported binding types include databases, message queues, webhooks, and more. * Bindings allow sending data to external systems without maintaining direct connections. * * @implements {IClientBinding} * @see {@link https://docs.dapr.io/reference/api/bindings_api/} Dapr Bindings API * @see {@link DaprClient.binding} for unified API * * @internal */ export default class GRPCClientBinding implements IClientBinding { /** * Reference to the underlying gRPC client. */ client: GRPCClient; /** * Creates a gRPC output binding building block. * * @param client - The gRPC client instance */ constructor(client: GRPCClient); /** * Sends a request to an output binding. * * Invokes the named binding with the specified operation and data. * The binding connector determines how the operation is interpreted * (e.g., "create" for databases, "send" for message queues). * * @param bindingName - Name of the binding to invoke * @param operation - Binding-specific operation identifier * @param data - Data to send (automatically serialized) * @param metadata - Optional metadata key-value pairs (default: {}) * * @returns Promise resolving to response object with data and metadata * * @throws Rejects if binding does not exist, operation fails, or gRPC call fails * * @example * ```typescript * // Send data to a database binding * const response = await client.binding.send( * "mydb", * "create", * { id: 1, name: "Alice", city: "San Francisco" }, * { table: "users" } * ); * // response: { data: ..., metadata: { table: "users" }, operation: "create" } * * // Send message to a message queue binding * await client.binding.send( * "mqbinding", * "send", * { message: "Hello World" } * ); * ``` * * @see {@link https://docs.dapr.io/reference/api/bindings_api/#invoking-output-bindings} */ send(bindingName: string, operation: string, data: any, metadata?: KeyValueType): Promise; }