(name: string, serviceName: string, credential: APICredential, options?: Partial<WebServiceOptions>)
| 87 | } |
| 88 | |
| 89 | createService(name: string, serviceName: string, credential: APICredential, options?: Partial<WebServiceOptions>): WebService { |
| 90 | if (!(serviceName in this.#services)) |
| 91 | throw new Error(`Service with name "${serviceName}" does not exist.`); |
| 92 | // Do runtime check of API type compatibility. |
| 93 | const {icon, apiClass} = apiManager.getAPIRecord(credential.type); |
| 94 | const {apiClasses, serviceClass} = this.#services[serviceName]; |
| 95 | if (!apiClasses.find(A => matchClass(A, apiClass))) |
| 96 | throw new Error(`Service "${serviceName}" does not support API type "${credential.type}".`); |
| 97 | // Create service. |
| 98 | const serviceOptions = deepAssign({name, api: new apiClass(credential), icon}, options); |
| 99 | return new serviceClass(serviceOptions); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | export default new ServiceManager; |
no test coverage detected