(obj: T)
| 70 | } |
| 71 | |
| 72 | function bindAllFunctions<T extends Record<string, any>>(obj: T): T { |
| 73 | const bound: Record<string, unknown> = {}; |
| 74 | let current: object | null = obj; |
| 75 | |
| 76 | while (current !== null && current !== Object.prototype) { |
| 77 | for (const key of Object.getOwnPropertyNames(current)) { |
| 78 | if (key === 'constructor' || Object.hasOwn(bound, key)) { |
| 79 | continue; |
| 80 | } |
| 81 | |
| 82 | const descriptor = Object.getOwnPropertyDescriptor(current, key); |
| 83 | if (typeof descriptor?.value === 'function') { |
| 84 | bound[key] = descriptor.value.bind(obj); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | current = Object.getPrototypeOf(current); |
| 89 | } |
| 90 | |
| 91 | return bound as T; |
| 92 | } |
| 93 | |
| 94 | async function leftClient(self: PromisableMethods<Left>): Promise<RPCMethods<Right>> { |
| 95 | left.resolve(bindAllFunctions(self)); |
no test coverage detected