@arifwidianto/rpc-agent
Version:
RPC Agent for both client and server, extends more methods easily
52 lines (51 loc) • 1.35 kB
TypeScript
import { ErrorCode, ErrorDetails } from "./error.interface";
export interface RpcMessageBase {
jsonrpc: "2.0";
id: string | number | null;
}
export interface RpcRequest extends RpcMessageBase {
method: string;
params?: Record<string, unknown>;
}
export interface RpcResponse extends RpcMessageBase {
result?: unknown;
error?: {
code: ErrorCode;
message: string;
data?: unknown;
};
}
export type RpcMethod = (param?: any) => Promise<any> | Promise<any[]> | Promise<Map<string, any>> | Promise<void> | any | any[] | Map<string, any> | void | undefined;
export interface RpcMethodSchema {
name: string;
description: string;
parameters: Record<string, {
type: string;
description: string;
required: boolean;
}>;
returns: {
type: string;
description: string;
};
}
export interface RpcMethodDefinition {
method: RpcMethod;
name: string;
schema?: RpcMethodSchema;
validate?: (params: unknown) => Promise<{
valid: boolean;
message?: string;
}>;
}
export interface RpcMethodRegistry {
[key: string]: RpcMethodDefinition;
}
export interface ValidationResult {
isValid: boolean;
errors?: Array<ErrorDetails>;
}
export interface Config {
enabled: boolean;
options?: Record<string, unknown>;
}