diff --git a/package-lock.json b/package-lock.json index 8218031..2e87d4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@matrixai/rpc", - "version": "0.1.2", + "version": "0.1.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@matrixai/rpc", - "version": "0.1.2", + "version": "0.1.5", "license": "Apache-2.0", "dependencies": { "@matrixai/async-init": "^1.9.4", diff --git a/package.json b/package.json index e34b1b4..c63d3c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@matrixai/rpc", - "version": "0.1.2", + "version": "0.1.5", "author": "Matrix AI", "contributors": [ { diff --git a/src/handlers/ClientHandler.ts b/src/handlers/ClientHandler.ts index 0aea354..6a3c93f 100644 --- a/src/handlers/ClientHandler.ts +++ b/src/handlers/ClientHandler.ts @@ -8,12 +8,12 @@ abstract class ClientHandler< Input extends JSONValue = JSONValue, Output extends JSONValue = JSONValue, > extends Handler { - public handle = async ( + public handle = async function* ( input: AsyncIterableIterator, cancel: (reason?: any) => void, meta: Record | undefined, ctx: ContextTimed, - ): Promise => { + ): AsyncIterableIterator { throw new ErrorRPCMethodNotImplemented(); }; } diff --git a/src/handlers/RawHandler.ts b/src/handlers/RawHandler.ts index 01fd1d7..500ce99 100644 --- a/src/handlers/RawHandler.ts +++ b/src/handlers/RawHandler.ts @@ -6,13 +6,16 @@ import { ErrorRPCMethodNotImplemented } from '../errors'; abstract class RawHandler< Container extends ContainerType = ContainerType, + Input extends JSONValue = JSONValue, // Define Input type if needed + Output extends JSONValue = JSONValue, // Define Output type if needed > extends Handler { - public handle = async ( - input: [JSONRPCRequest, ReadableStream], + public handle = async function* ( + input: AsyncIterableIterator, // Change this based on your specific needs cancel: (reason?: any) => void, meta: Record | undefined, ctx: ContextTimed, - ): Promise<[JSONValue, ReadableStream]> => { + ): AsyncIterableIterator { + // Change return type to AsyncIterableIterator throw new ErrorRPCMethodNotImplemented('This method must be overridden'); }; } diff --git a/src/handlers/UnaryHandler.ts b/src/handlers/UnaryHandler.ts index 0a1e37b..22ee1e2 100644 --- a/src/handlers/UnaryHandler.ts +++ b/src/handlers/UnaryHandler.ts @@ -8,12 +8,12 @@ abstract class UnaryHandler< Input extends JSONValue = JSONValue, Output extends JSONValue = JSONValue, > extends Handler { - public handle = async ( + public handle = async function* ( input: Input, cancel: (reason?: any) => void, meta: Record | undefined, ctx: ContextTimed, - ): Promise => { + ): AsyncIterableIterator { throw new ErrorRPCMethodNotImplemented('This method must be overridden'); }; } diff --git a/src/types.ts b/src/types.ts index 4cb941e..4ef00d7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -200,11 +200,8 @@ type ContainerType = Record; * mainly used as the return type for the `StreamFactory`. But the interface * can be propagated across the RPC system. */ -interface RPCStream< - R, - W, - M extends Record = Record, -> extends ReadableWritablePair { +interface RPCStream + extends ReadableWritablePair { cancel: (reason?: any) => void; meta?: M; }