Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove Proxy from json rpc client #10554

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,10 @@ export function createSafeJsonRpcClient<T extends object>(
return (schema as ApiSchema)[methodName].returnType().parse(res.result);
};

// Intercept any RPC methods with a proxy
const proxy = new Proxy(
{},
{
get: (target, method: string) => {
if (['then', 'catch'].includes(method)) {
return Reflect.get(target, method);
}
return (...params: any[]) => request(method, params);
},
},
) as T;
const proxy: any = {};
for (const method of Object.keys(schema)) {
proxy[method] = (...params: any[]) => request(method, params);
}

return proxy;
return proxy as T;
}
6 changes: 2 additions & 4 deletions yarn-project/foundation/src/json-rpc/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ describe('JsonRpc integration', () => {
await expect(() => client.fail()).rejects.toThrow('Test state failed');
});

it('fails if calls non-existing method in handler', async () => {
await expect(() => (client as TestState).forceClear()).rejects.toThrow(
'Unspecified method forceClear in client schema',
);
it('fails if calls non-existing method in handler', () => {
expect(() => (client as TestState).forceClear()).toThrow(/not a function/i);
});
});

Expand Down
Loading