Merge pull request #13498 from backstage/rugvip/internalfactory
backend-plugin-api: made defaultFactories internal
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/backend-app-api': patch
|
||||
'@backstage/backend-plugin-api': patch
|
||||
---
|
||||
|
||||
Made `ApiRef.defaultFactory` internal.
|
||||
@@ -108,9 +108,7 @@ export class BackendInitializer {
|
||||
id: feature.id,
|
||||
provides,
|
||||
consumes: new Set(Object.values(registerOptions.deps)),
|
||||
deps: registerOptions.deps as {
|
||||
[name: string]: ServiceOrExtensionPoint;
|
||||
},
|
||||
deps: registerOptions.deps,
|
||||
init: registerOptions.init as BackendRegisterInit['init'],
|
||||
};
|
||||
},
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
ServiceFactory,
|
||||
FactoryFunc,
|
||||
@@ -20,6 +21,14 @@ import {
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { stringifyError } from '@backstage/errors';
|
||||
|
||||
/**
|
||||
* 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>>;
|
||||
@@ -39,7 +48,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;
|
||||
}
|
||||
|
||||
@@ -192,7 +192,6 @@ export type ServiceFactory<TService = unknown> = {
|
||||
export type ServiceRef<T> = {
|
||||
id: string;
|
||||
T: T;
|
||||
defaultFactory?: (service: ServiceRef<T>) => Promise<ServiceFactory<T>>;
|
||||
toString(): string;
|
||||
$$ref: 'service';
|
||||
};
|
||||
|
||||
@@ -28,15 +28,20 @@ export type ServiceRef<T> = {
|
||||
*/
|
||||
T: T;
|
||||
|
||||
toString(): string;
|
||||
|
||||
$$ref: 'service';
|
||||
};
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type InternalServiceRef<T> = ServiceRef<T> & {
|
||||
/**
|
||||
* The default factory that will be used to create service
|
||||
* instances if no other factory is provided.
|
||||
*/
|
||||
defaultFactory?: (service: ServiceRef<T>) => Promise<ServiceFactory<T>>;
|
||||
|
||||
toString(): string;
|
||||
|
||||
$$ref: 'service';
|
||||
__defaultFactory?: (service: ServiceRef<T>) => Promise<ServiceFactory<T>>;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
@@ -70,12 +75,12 @@ export function createServiceRef<T>(options: {
|
||||
get T(): T {
|
||||
throw new Error(`tried to read ServiceRef.T of ${this}`);
|
||||
},
|
||||
defaultFactory,
|
||||
toString() {
|
||||
return `serviceRef{${options.id}}`;
|
||||
},
|
||||
$$ref: 'service', // TODO: declare
|
||||
};
|
||||
__defaultFactory: defaultFactory,
|
||||
} as InternalServiceRef<T>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user