backend-*-api: refactor for more explicit internal feature types

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-08-05 12:16:19 +02:00
parent dc0d284419
commit d4d048b3ff
5 changed files with 96 additions and 47 deletions
@@ -15,7 +15,7 @@
*/
import { createBackendModule } from './createBackendModule';
import { InternalBackendFeature } from './types';
import { InternalBackendRegistrations } from './types';
describe('createBackendModule', () => {
it('should create a BackendModule', () => {
@@ -28,13 +28,13 @@ describe('createBackendModule', () => {
});
// legacy form
const legacy = result() as unknown as InternalBackendFeature;
const legacy = result() as unknown as InternalBackendRegistrations;
expect(legacy.$$type).toEqual('@backstage/BackendFeature');
expect(legacy.version).toEqual('v1');
expect(legacy.getRegistrations).toEqual(expect.any(Function));
// new form
const module = result as unknown as InternalBackendFeature;
const module = result as unknown as InternalBackendRegistrations;
expect(module.$$type).toEqual('@backstage/BackendFeature');
expect(module.version).toEqual('v1');
expect(module.getRegistrations).toEqual(expect.any(Function));
@@ -15,7 +15,7 @@
*/
import { createBackendPlugin } from './createBackendPlugin';
import { InternalBackendFeature } from './types';
import { InternalBackendRegistrations } from './types';
describe('createBackendPlugin', () => {
it('should create a BackendPlugin', () => {
@@ -27,13 +27,13 @@ describe('createBackendPlugin', () => {
});
// legacy form
const legacy = result() as unknown as InternalBackendFeature;
const legacy = result() as unknown as InternalBackendRegistrations;
expect(legacy.$$type).toEqual('@backstage/BackendFeature');
expect(legacy.version).toEqual('v1');
expect(legacy.getRegistrations).toEqual(expect.any(Function));
// new form
const plugin = result as unknown as InternalBackendFeature;
const plugin = result as unknown as InternalBackendRegistrations;
expect(plugin.$$type).toEqual('@backstage/BackendFeature');
expect(plugin.version).toEqual('v1');
expect(plugin.getRegistrations).toEqual(expect.any(Function));
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { ServiceRef } from '../services/system/types';
import { InternalServiceFactory, ServiceRef } from '../services/system/types';
import { BackendFeature } from '../types';
/**
@@ -73,7 +73,7 @@ export interface BackendModuleRegistrationPoints {
}
/** @internal */
export interface InternalBackendFeature extends BackendFeature {
export interface InternalBackendRegistrations extends BackendFeature {
version: 'v1';
featureType: 'registrations';
getRegistrations(): Array<
@@ -114,3 +114,9 @@ export interface InternalBackendFeatureLoader extends BackendFeature {
deps: Record<string, ServiceRef<unknown>>;
loader(deps: Record<string, unknown>): Promise<BackendFeature[]>;
}
/** @internal */
export type InternalBackendFeature =
| InternalBackendRegistrations
| InternalBackendFeatureLoader
| InternalServiceFactory;