| 37 | } |
| 38 | |
| 39 | static proxyPluginAPI(opts: { |
| 40 | pluginAPI: PluginAPi; |
| 41 | service: Core; |
| 42 | serviceProps: string[]; |
| 43 | staticProps: Record<string, any>; |
| 44 | }) { |
| 45 | return new Proxy(opts.pluginAPI, { |
| 46 | get: (target, prop: string) => { |
| 47 | if (opts.service.pluginMethods[prop]) { |
| 48 | return opts.service.pluginMethods[prop].fn; |
| 49 | } |
| 50 | if (opts.serviceProps.includes(prop)) { |
| 51 | // @ts-ignore |
| 52 | const serviceProp = opts.service[prop]; |
| 53 | return typeof serviceProp === 'function' |
| 54 | ? serviceProp.bind(opts.service) |
| 55 | : serviceProp; |
| 56 | } |
| 57 | if (prop in opts.staticProps) { |
| 58 | return opts.staticProps[prop]; |
| 59 | } |
| 60 | // @ts-ignore |
| 61 | return target[prop]; |
| 62 | }, |
| 63 | }); |
| 64 | } |
| 65 | } |