rpc_ts
Version:
Remote Procedure Calls in TypeScript made simple
37 lines (36 loc) • 1.23 kB
TypeScript
/**
* @module ModuleRpcProtocolMock
* @preferred
*
* @license
* Copyright (c) Aiden.ai
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** */
import { ModuleRpcClient } from '../../client';
import { ModuleRpcCommon } from '../../common';
/**
* Mocks an RPC client, calling a stream producer that can be used to mock
* server responses.
*
* @example ```Typescript
* const serviceDefinition = {
* foo: { request: {}, response: {} as { bar: number } },
* };
* const client = getMockRpcClient(serviceDefinition, (method, request) => {
* console.log(
* 'RPC:',
* method,
* request instanceof Function ? request() : request,
* );
* return ModuleRpcClient.streamFromArray([
* { response: { bar: 1 } },
* ]) as ModuleRpcClient.Stream<any>;
* });
* const { bar } = await client.methodMap().foo({});
* expect(bar).to.equal(1);
* ```
*/
export declare function getMockRpcClient<serviceDefinition extends ModuleRpcCommon.ServiceDefinition, ResponseContext>(serviceDefinition: serviceDefinition, streamProducer: ModuleRpcClient.StreamProducer): ModuleRpcClient.Service<serviceDefinition, ResponseContext>;