diff --git a/packages/agent/src/prototyping/clients/dwn-rpc-types.ts b/packages/agent/src/prototyping/clients/dwn-rpc-types.ts index 1371a8f98..4eff6fb9b 100644 --- a/packages/agent/src/prototyping/clients/dwn-rpc-types.ts +++ b/packages/agent/src/prototyping/clients/dwn-rpc-types.ts @@ -7,34 +7,49 @@ export interface SerializableDwnMessage { export type DwnEventSubscriptionHandler = (event: MessageEvent) => void; /** - * Interface that can be implemented to communicate with - * {@link https://github.com/TBD54566975/dwn-server | DWN Servers} via JSON-RPC. + * Interface for communicating with {@link https://github.com/TBD54566975/dwn-server | DWN Servers} + * via JSON-RPC, supporting operations like sending DWN requests. */ export interface DwnRpc { /** - * TODO: add jsdoc + * Lists the transport protocols supported by the DWN RPC client, such as HTTP or HTTPS. + * @returns An array of strings representing the supported transport protocols. */ get transportProtocols(): string[] /** - * TODO: add jsdoc - * @param request + * Sends a request to a DWN Server using the specified DWN RPC request parameters. + * + * @param request - The DWN RPC request containing the URL, target DID, message, and optional data. + * @returns A promise that resolves to the response from the DWN server. */ sendDwnRequest(request: DwnRpcRequest): Promise } + /** - * TODO: add jsdoc + * Represents a JSON RPC request to a DWN server, including the URL, target DID, the message to be + * processed, and optional data. */ export type DwnRpcRequest = { + /** Optional data to be sent with the request. */ data?: any; - subscriptionHandler?: DwnEventSubscriptionHandler; + + /** The URL of the DWN server to which the request is sent. */ dwnUrl: string; + + /** The message to be processed by the DWN server, which can be a serializable DWN message. */ message: SerializableDwnMessage | any; + + /** The DID of the target to which the message is addressed. */ targetDid: string; + + /** Optional subscription handler for DWN events. */ + subscriptionHandler?: DwnEventSubscriptionHandler; } /** - * TODO: add jsdoc + * Represents the JSON RPC response from a DWN server to a request, combining the results of various + * DWN operations. */ export type DwnRpcResponse = UnionMessageReply & RecordsReadReply; \ No newline at end of file diff --git a/packages/agent/src/rpc-client.ts b/packages/agent/src/rpc-client.ts index 34efb0d65..25c479c1c 100644 --- a/packages/agent/src/rpc-client.ts +++ b/packages/agent/src/rpc-client.ts @@ -1,10 +1,12 @@ import { utils as cryptoUtils } from '@web5/crypto'; -import { RecordsReadReply, UnionMessageReply } from '@tbd54566975/dwn-sdk-js'; +import type { DwnRpc, DwnRpcRequest, DwnRpcResponse } from './prototyping/clients/dwn-rpc-types.js'; +import type { JsonRpcResponse } from './prototyping/clients/json-rpc.js'; + +import { createJsonRpcRequest } from './prototyping/clients/json-rpc.js'; import { HttpDwnRpcClient } from './prototyping/clients/http-dwn-rpc-client.js'; import { WebSocketDwnRpcClient } from './prototyping/clients/web-socket-clients.js'; -import { JsonRpcResponse, createJsonRpcRequest } from './prototyping/clients/json-rpc.js'; /** * Interface that can be implemented to communicate with {@link Web5Agent | Web5 Agent} @@ -32,60 +34,11 @@ export type DidRpcResponse = { status: RpcStatus; } -/** - * Interface for communicating with {@link https://github.com/TBD54566975/dwn-server | DWN Servers} - * via JSON-RPC, supporting operations like sending DWN requests. - */ -export interface DwnRpc { - /** - * Lists the transport protocols supported by the DWN RPC client, such as HTTP or HTTPS. - * @returns An array of strings representing the supported transport protocols. - */ - get transportProtocols(): string[] - - /** - * Sends a request to a DWN Server using the specified DWN RPC request parameters. - * - * @param request - The DWN RPC request containing the URL, target DID, message, and optional data. - * @returns A promise that resolves to the response from the DWN server. - */ - sendDwnRequest(request: DwnRpcRequest): Promise -} - - -/** - * Represents a JSON RPC request to a DWN server, including the URL, target DID, the message to be - * processed, and optional data. - */ -export type DwnRpcRequest = { - /** Optional data to be sent with the request. */ - data?: any; - - /** The URL of the DWN server to which the request is sent. */ - dwnUrl: string; - - /** The message to be processed by the DWN server, which can be a serializable DWN message. */ - message: SerializableDwnMessage | any; - - /** The DID of the target to which the message is addressed. */ - targetDid: string; -} - -/** - * Represents the JSON RPC response from a DWN server to a request, combining the results of various - * DWN operations. - */ -export type DwnRpcResponse = UnionMessageReply & RecordsReadReply; - export type RpcStatus = { code: number; message: string; }; -export interface SerializableDwnMessage { - toJSON(): string; -} - export interface Web5Rpc extends DwnRpc, DidRpc {} /**