Revert back to context in createLocalClient

This commit is contained in:
Jerko Steiner 2019-08-30 17:51:14 +07:00
parent 0222455cd7
commit d2a5a35543
2 changed files with 3 additions and 4 deletions

View File

@ -25,7 +25,7 @@ describe('local', () => {
const service = new Service()
const proxy = createLocalClient(service, () => ({userId: 1000}))
const proxy = createLocalClient(service, {userId: 1000})
describe('add', () => {
it('should add two numbers', async () => {

View File

@ -7,13 +7,12 @@ import {TGetContext} from './express'
* will be invoked as if it would be remotely. This helps keep the API similar
* on the client- and server-side.
*/
export function createLocalClient<T, Context>(
export function createLocalClient<T extends {}, Context>(
service: T,
getContext: () => Context,
context: Context,
): TAsyncified<ReverseContextual<T>> {
const proxy = new Proxy({}, {
get(obj, prop) {
const context = getContext()
return async function makeRequest(...args: any[]) {
const result = (service as any)[prop](context, ...args)
return result