backend-next: widen accepted ServiceFactory types to include meta method

Co-authored-by: Fredrik Adelöw <freben@gmail.com>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-09-02 16:27:29 +02:00
parent 5f388ca501
commit 5263e9449d
5 changed files with 33 additions and 22 deletions
+2 -12
View File
@@ -47,24 +47,14 @@ export const defaultServiceFactories = [
* @public
*/
export interface CreateBackendOptions {
services?: ServiceFactory[];
services?: (ServiceFactory | (() => ServiceFactory))[];
}
/**
* @public
*/
export function createBackend(options?: CreateBackendOptions): Backend {
const services = new Map<string, ServiceFactory>(
defaultServiceFactories.map(sf => [sf.service.id, sf as ServiceFactory]),
);
if (options?.services) {
for (const sf of options.services) {
services.set(sf.service.id, sf);
}
}
return createSpecializedBackend({
services: Array.from(services.values()),
services: [...defaultServiceFactories, ...(options?.services ?? [])],
});
}