move to a top level service

Signed-off-by: aramissennyeydd <aramis.sennyey@doordash.com>
This commit is contained in:
aramissennyeydd
2024-11-29 09:44:09 -05:00
parent 51ae068e10
commit af86ae9e57
7 changed files with 48 additions and 38 deletions
@@ -27,7 +27,7 @@ import {
createBackendFeatureLoader,
} from '@backstage/backend-plugin-api';
import { BackendInitializer } from './BackendInitializer';
import { experimentalServices } from '@backstage/backend-plugin-api/alpha';
import { EXPERIMENTAL_instanceMetadataServiceRef } from '@backstage/backend-plugin-api/alpha';
class MockLogger {
debug() {}
@@ -743,8 +743,7 @@ describe('BackendInitializer', () => {
register(reg) {
reg.registerInit({
deps: {
instanceMetadata:
experimentalServices.EXPERIMENTAL_instanceMetadata,
instanceMetadata: EXPERIMENTAL_instanceMetadataServiceRef,
},
async init({ instanceMetadata }) {
expect(instanceMetadata.getInstalledFeatures()).toEqual([
@@ -36,7 +36,7 @@ import type {
import type { InternalServiceFactory } from '../../../backend-plugin-api/src/services/system/types';
import { ForwardedError, ConflictError } from '@backstage/errors';
import {
experimentalServices,
EXPERIMENTAL_instanceMetadataServiceRef,
featureDiscoveryServiceRef,
BackendFeatureMeta,
} from '@backstage/backend-plugin-api/alpha';
@@ -128,7 +128,7 @@ function createInstanceMetadataServiceFactory(
})
.flat();
return createServiceFactory({
service: experimentalServices.EXPERIMENTAL_instanceMetadata,
service: EXPERIMENTAL_instanceMetadataServiceRef,
deps: {},
factory: async () => ({ getInstalledFeatures: () => installedFeatures }),
});
@@ -6,6 +6,25 @@
import { BackendFeature } from '@backstage/backend-plugin-api';
import { ServiceRef } from '@backstage/backend-plugin-api';
// @alpha (undocumented)
export type BackendFeatureMeta =
| {
type: 'plugin';
pluginId: string;
}
| {
type: 'module';
pluginId: string;
moduleId: string;
};
// @alpha
export const EXPERIMENTAL_instanceMetadataServiceRef: ServiceRef<
InstanceMetadataService,
'plugin',
'singleton'
>;
// @alpha (undocumented)
export interface FeatureDiscoveryService {
// (undocumented)
@@ -21,5 +40,11 @@ export const featureDiscoveryServiceRef: ServiceRef<
'singleton'
>;
// @alpha (undocumented)
export interface InstanceMetadataService {
// (undocumented)
getInstalledFeatures: () => BackendFeatureMeta[];
}
// (No @packageDocumentation comment for this package)
```
+15 -2
View File
@@ -35,5 +35,18 @@ export const featureDiscoveryServiceRef =
scope: 'root',
});
export { experimentalServices } from './services/definitions/experimentalServices';
export type { BackendFeatureMeta } from './services/definitions/InstanceMetadataService';
/**
* EXPERIMENTAL: Instance metadata service.
*
* @alpha
*/
export const EXPERIMENTAL_instanceMetadataServiceRef = createServiceRef<
import('./services/definitions/InstanceMetadataService').InstanceMetadataService
>({
id: 'experimental.instanceMetadata',
});
export type {
BackendFeatureMeta,
InstanceMetadataService,
} from './services/definitions/InstanceMetadataService';
@@ -14,6 +14,7 @@
* limitations under the License.
*/
/** @alpha */
export type BackendFeatureMeta =
| {
type: 'plugin';
@@ -25,6 +26,7 @@ export type BackendFeatureMeta =
moduleId: string;
};
/** @alpha */
export interface InstanceMetadataService {
getInstalledFeatures: () => BackendFeatureMeta[];
}
@@ -1,29 +0,0 @@
/*
* Copyright 2024 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.
*/
import { createServiceRef } from '../system';
export namespace experimentalServices {
/**
* EXPERIMENTAL: Instance metadata service.
*
* @public
*/
export const EXPERIMENTAL_instanceMetadata = createServiceRef<
import('./InstanceMetadataService').InstanceMetadataService
>({
id: 'core.instanceMetadata',
});
}
+2 -2
View File
@@ -17,7 +17,7 @@ import {
coreServices,
createBackendPlugin,
} from '@backstage/backend-plugin-api';
import { experimentalServices } from '@backstage/backend-plugin-api/alpha';
import { EXPERIMENTAL_instanceMetadataServiceRef } from '@backstage/backend-plugin-api/alpha';
// Example usage of the instance metadata service to log the installed features.
export default createBackendPlugin({
@@ -25,7 +25,7 @@ export default createBackendPlugin({
register(env) {
env.registerInit({
deps: {
instanceMetadata: experimentalServices.EXPERIMENTAL_instanceMetadata,
instanceMetadata: EXPERIMENTAL_instanceMetadataServiceRef,
logger: coreServices.logger,
},
async init({ instanceMetadata, logger }) {