backend-plugin-api: made defaultFactories internal

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 10:57:50 +02:00
parent c2b7cb1373
commit 2c57c0c499
4 changed files with 28 additions and 9 deletions
@@ -13,12 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
ServiceFactory,
FactoryFunc,
ServiceRef,
} from '@backstage/backend-plugin-api';
/**
* Keep in sync with `@backstage/backend-plugin-api/src/services/system/types.ts`
* @internal
*/
export type InternalServiceRef<T> = ServiceRef<T> & {
__defaultFactory?: (service: ServiceRef<T>) => Promise<ServiceFactory<T>>;
};
export class ServiceRegistry {
readonly #providedFactories: Map<string, ServiceFactory>;
readonly #loadedDefaultFactories: Map<Function, Promise<ServiceFactory>>;
@@ -38,7 +47,7 @@ export class ServiceRegistry {
get<T>(ref: ServiceRef<T>): FactoryFunc<T> | undefined {
let factory = this.#providedFactories.get(ref.id);
const { defaultFactory } = ref;
const { __defaultFactory: defaultFactory } = ref as InternalServiceRef<T>;
if (!factory && !defaultFactory) {
return undefined;
}