UNPKG

rpc_ts

Version:

Remote Procedure Calls in TypeScript made simple

41 lines 1.21 kB
"use strict"; /** * @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. */ Object.defineProperty(exports, "__esModule", { value: true }); /** */ const client_1 = require("../../client"); /** * 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); * ``` */ function getMockRpcClient(serviceDefinition, streamProducer) { return new client_1.ModuleRpcClient.Service(serviceDefinition, streamProducer); } exports.getMockRpcClient = getMockRpcClient; //# sourceMappingURL=mock.js.map