backend-plugin-api: remove factory function helper types

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-01-12 14:42:18 +01:00
parent d1e86013ef
commit 635287ead1
25 changed files with 76 additions and 202 deletions
+10 -9
View File
@@ -113,13 +113,13 @@ export namespace coreServices {
// @public
export function createBackendModule<TOptions extends [options?: object] = []>(
config: FactoryFunctionConfig<BackendModuleConfig, TOptions>,
): FactoryFunction<BackendFeature, TOptions>;
config: BackendModuleConfig | ((...params: TOptions) => BackendModuleConfig),
): (...params: TOptions) => BackendFeature;
// @public (undocumented)
export function createBackendPlugin<TOptions extends [options?: object] = []>(
config: FactoryFunctionConfig<BackendPluginConfig, TOptions>,
): FactoryFunction<BackendFeature, TOptions>;
config: BackendPluginConfig | ((...params: TOptions) => BackendPluginConfig),
): (...params: TOptions) => BackendFeature;
// @public (undocumented)
export function createExtensionPoint<T>(
@@ -136,11 +136,12 @@ export function createServiceFactory<
},
TOpts extends [options?: object] = [],
>(
config: FactoryFunctionConfig<
ServiceFactoryConfig<TService, TScope, TImpl, TDeps>,
TOpts
>,
): FactoryFunction<ServiceFactory<TService>, TOpts>;
config:
| ServiceFactoryConfig<TService, TScope, TImpl, TDeps>
| ((
...options: TOpts
) => ServiceFactoryConfig<TService, TScope, TImpl, TDeps>),
): (...params: TOpts) => ServiceFactory<TService>;
// @public
export function createServiceRef<TService>(
@@ -14,8 +14,6 @@
* limitations under the License.
*/
import { FactoryFunctionConfig, FactoryFunction } from '../../types';
/**
* TODO
*
@@ -162,11 +160,12 @@ export function createServiceFactory<
TDeps extends { [name in string]: ServiceRef<unknown> },
TOpts extends [options?: object] = [],
>(
config: FactoryFunctionConfig<
ServiceFactoryConfig<TService, TScope, TImpl, TDeps>,
TOpts
>,
): FactoryFunction<ServiceFactory<TService>, TOpts> {
config:
| ServiceFactoryConfig<TService, TScope, TImpl, TDeps>
| ((
...options: TOpts
) => ServiceFactoryConfig<TService, TScope, TImpl, TDeps>),
): (...params: TOpts) => ServiceFactory<TService> {
if (typeof config === 'function') {
return (...opts: TOpts) => {
const c = config(...opts);
-31
View File
@@ -1,31 +0,0 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @ignore
*/
export type FactoryFunctionConfig<TConfig, TParams extends unknown[]> =
| TConfig
| ((...params: TParams) => TConfig);
/**
* Helper type that makes the options argument optional if options are not required.
*
* @ignore
*/
export type FactoryFunction<TResult, TParams extends unknown[]> = (
...params: TParams
) => TResult;
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import { FactoryFunction, FactoryFunctionConfig } from '../types';
import {
BackendRegistrationPoints,
BackendFeature,
@@ -50,10 +49,10 @@ export interface BackendPluginConfig {
/** @public */
export function createBackendPlugin<TOptions extends [options?: object] = []>(
config: FactoryFunctionConfig<BackendPluginConfig, TOptions>,
): FactoryFunction<BackendFeature, TOptions> {
config: BackendPluginConfig | ((...params: TOptions) => BackendPluginConfig),
): (...params: TOptions) => BackendFeature {
if (typeof config === 'function') {
return config as FactoryFunction<BackendFeature, TOptions>;
return config;
}
return () => config;
@@ -83,8 +82,8 @@ export interface BackendModuleConfig {
* The `pluginId` should exactly match the `id` of the plugin that the module extends.
*/
export function createBackendModule<TOptions extends [options?: object] = []>(
config: FactoryFunctionConfig<BackendModuleConfig, TOptions>,
): FactoryFunction<BackendFeature, TOptions> {
config: BackendModuleConfig | ((...params: TOptions) => BackendModuleConfig),
): (...params: TOptions) => BackendFeature {
if (typeof config === 'function') {
return (...options: TOptions) => {
const c = config(...options);