Merge pull request #26023 from backstage/freben/nocompat2
remove the backend feature and service compat callback patterns
This commit is contained in:
@@ -4,14 +4,13 @@
|
||||
|
||||
```ts
|
||||
import { FeatureDiscoveryService } from '@backstage/backend-plugin-api/alpha';
|
||||
import { ServiceFactoryCompat } from '@backstage/backend-plugin-api';
|
||||
import { ServiceFactory } from '@backstage/backend-plugin-api';
|
||||
|
||||
// @alpha (undocumented)
|
||||
export const featureDiscoveryServiceFactory: ServiceFactoryCompat<
|
||||
export const featureDiscoveryServiceFactory: ServiceFactory<
|
||||
FeatureDiscoveryService,
|
||||
'root',
|
||||
'singleton',
|
||||
undefined
|
||||
'singleton'
|
||||
>;
|
||||
|
||||
// (No @packageDocumentation comment for this package)
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
import { BackendFeature } from '@backstage/backend-plugin-api';
|
||||
import { IdentityService } from '@backstage/backend-plugin-api';
|
||||
import { ServiceFactory } from '@backstage/backend-plugin-api';
|
||||
import { ServiceFactoryCompat } from '@backstage/backend-plugin-api';
|
||||
import { TokenManagerService } from '@backstage/backend-plugin-api';
|
||||
|
||||
// @public (undocumented)
|
||||
@@ -36,25 +35,17 @@ export interface CreateSpecializedBackendOptions {
|
||||
defaultServiceFactories: ServiceFactory[];
|
||||
}
|
||||
|
||||
// @public @deprecated
|
||||
export type IdentityFactoryOptions = {
|
||||
issuer?: string;
|
||||
algorithms?: string[];
|
||||
};
|
||||
|
||||
// @public @deprecated (undocumented)
|
||||
export const identityServiceFactory: ServiceFactoryCompat<
|
||||
export const identityServiceFactory: ServiceFactory<
|
||||
IdentityService,
|
||||
'plugin',
|
||||
'singleton',
|
||||
IdentityFactoryOptions
|
||||
'singleton'
|
||||
>;
|
||||
|
||||
// @public @deprecated (undocumented)
|
||||
export const tokenManagerServiceFactory: ServiceFactoryCompat<
|
||||
export const tokenManagerServiceFactory: ServiceFactory<
|
||||
TokenManagerService,
|
||||
'plugin',
|
||||
'singleton',
|
||||
undefined
|
||||
'singleton'
|
||||
>;
|
||||
```
|
||||
|
||||
@@ -147,7 +147,7 @@ describe('featureDiscoveryServiceFactory', () => {
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory(),
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: { backend: { packages: 'all' } },
|
||||
}),
|
||||
@@ -166,7 +166,7 @@ describe('featureDiscoveryServiceFactory', () => {
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory(),
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: {
|
||||
backend: {
|
||||
@@ -195,7 +195,7 @@ describe('featureDiscoveryServiceFactory', () => {
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory(),
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: {
|
||||
backend: {
|
||||
@@ -220,7 +220,7 @@ describe('featureDiscoveryServiceFactory', () => {
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory(),
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: {
|
||||
backend: {
|
||||
@@ -245,7 +245,7 @@ describe('featureDiscoveryServiceFactory', () => {
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory(),
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: {
|
||||
backend: {
|
||||
@@ -270,7 +270,7 @@ describe('featureDiscoveryServiceFactory', () => {
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory(),
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: {
|
||||
backend: {
|
||||
@@ -300,7 +300,7 @@ describe('featureDiscoveryServiceFactory', () => {
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory(),
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: { backend: { packages: {} } },
|
||||
}),
|
||||
@@ -316,7 +316,7 @@ describe('featureDiscoveryServiceFactory', () => {
|
||||
await startTestBackend({
|
||||
features: [
|
||||
mock.factory,
|
||||
featureDiscoveryServiceFactory(),
|
||||
featureDiscoveryServiceFactory,
|
||||
mockServices.rootConfig.factory({
|
||||
data: { backend: {} },
|
||||
}),
|
||||
|
||||
+9
-27
@@ -21,33 +21,15 @@ import {
|
||||
import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
|
||||
|
||||
/**
|
||||
* An identity client options object which allows extra configurations
|
||||
*
|
||||
* @public
|
||||
* @deprecated Please migrate to the new `coreServices.auth`, `coreServices.httpAuth`, and `coreServices.userInfo` services as needed instead
|
||||
*/
|
||||
export type IdentityFactoryOptions = {
|
||||
issuer?: string;
|
||||
|
||||
/**
|
||||
* JWS "alg" (Algorithm) Header Parameter values. Defaults to an array containing just ES256.
|
||||
* More info on supported algorithms: https://github.com/panva/jose
|
||||
*/
|
||||
algorithms?: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated Please migrate to the new `coreServices.auth`, `coreServices.httpAuth`, and `coreServices.userInfo` services as needed instead
|
||||
*/
|
||||
export const identityServiceFactory = createServiceFactory(
|
||||
(options?: IdentityFactoryOptions) => ({
|
||||
service: coreServices.identity,
|
||||
deps: {
|
||||
discovery: coreServices.discovery,
|
||||
},
|
||||
async factory({ discovery }) {
|
||||
return DefaultIdentityClient.create({ discovery, ...options });
|
||||
},
|
||||
}),
|
||||
);
|
||||
export const identityServiceFactory = createServiceFactory({
|
||||
service: coreServices.identity,
|
||||
deps: {
|
||||
discovery: coreServices.discovery,
|
||||
},
|
||||
async factory({ discovery }) {
|
||||
return DefaultIdentityClient.create({ discovery });
|
||||
},
|
||||
});
|
||||
|
||||
@@ -15,4 +15,3 @@
|
||||
*/
|
||||
|
||||
export { identityServiceFactory } from './identityServiceFactory';
|
||||
export type { IdentityFactoryOptions } from './identityServiceFactory';
|
||||
|
||||
@@ -39,14 +39,14 @@ class MockLogger {
|
||||
}
|
||||
|
||||
const baseFactories = [
|
||||
lifecycleServiceFactory(),
|
||||
rootLifecycleServiceFactory(),
|
||||
lifecycleServiceFactory,
|
||||
rootLifecycleServiceFactory,
|
||||
createServiceFactory({
|
||||
service: coreServices.rootLogger,
|
||||
deps: {},
|
||||
factory: () => new MockLogger(),
|
||||
})(),
|
||||
loggerServiceFactory(),
|
||||
}),
|
||||
loggerServiceFactory,
|
||||
];
|
||||
|
||||
const testPlugin = createBackendPlugin({
|
||||
@@ -57,7 +57,7 @@ const testPlugin = createBackendPlugin({
|
||||
async init() {},
|
||||
});
|
||||
},
|
||||
})();
|
||||
});
|
||||
|
||||
describe('BackendInitializer', () => {
|
||||
it('should initialize root scoped services', async () => {
|
||||
@@ -84,18 +84,18 @@ describe('BackendInitializer', () => {
|
||||
initialization: 'always',
|
||||
deps: {},
|
||||
factory: factory1,
|
||||
})(),
|
||||
}),
|
||||
createServiceFactory({
|
||||
service: ref2,
|
||||
deps: {},
|
||||
factory: factory2,
|
||||
})(),
|
||||
}),
|
||||
createServiceFactory({
|
||||
service: ref3,
|
||||
initialization: 'lazy',
|
||||
deps: {},
|
||||
factory: factory3,
|
||||
})(),
|
||||
}),
|
||||
];
|
||||
|
||||
const init = new BackendInitializer(services);
|
||||
@@ -249,18 +249,18 @@ describe('BackendInitializer', () => {
|
||||
initialization: 'always',
|
||||
deps: {},
|
||||
factory: factory1,
|
||||
})(),
|
||||
}),
|
||||
createServiceFactory({
|
||||
service: ref2,
|
||||
deps: {},
|
||||
factory: factory2,
|
||||
})(),
|
||||
}),
|
||||
createServiceFactory({
|
||||
service: ref3,
|
||||
initialization: 'lazy',
|
||||
deps: {},
|
||||
factory: factory3,
|
||||
})(),
|
||||
}),
|
||||
];
|
||||
|
||||
const init = new BackendInitializer(services);
|
||||
@@ -505,12 +505,12 @@ describe('BackendInitializer', () => {
|
||||
const extA = createExtensionPoint<string>({ id: 'a' });
|
||||
const extB = createExtensionPoint<string>({ id: 'b' });
|
||||
const init = new BackendInitializer([
|
||||
rootLifecycleServiceFactory(),
|
||||
rootLifecycleServiceFactory,
|
||||
createServiceFactory({
|
||||
service: coreServices.rootLogger,
|
||||
deps: {},
|
||||
factory: () => new MockLogger(),
|
||||
})(),
|
||||
}),
|
||||
]);
|
||||
init.add(testPlugin);
|
||||
init.add(
|
||||
|
||||
@@ -95,7 +95,7 @@ describe('ServiceRegistry', () => {
|
||||
});
|
||||
|
||||
it('should return an implementation for a registered ref', async () => {
|
||||
const registry = ServiceRegistry.create([sf1()]);
|
||||
const registry = ServiceRegistry.create([sf1]);
|
||||
await expect(registry.get(ref1, 'catalog')).resolves.toEqual({ x: 1 });
|
||||
await expect(registry.get(ref1, 'scaffolder')).resolves.toEqual({ x: 1 });
|
||||
expect(await registry.get(ref1, 'catalog')).toBe(
|
||||
@@ -110,7 +110,7 @@ describe('ServiceRegistry', () => {
|
||||
});
|
||||
|
||||
it('should handle multiple factories with different serviceRefs', async () => {
|
||||
const registry = ServiceRegistry.create([sf1(), sf2()]);
|
||||
const registry = ServiceRegistry.create([sf1, sf2]);
|
||||
|
||||
await expect(registry.get(ref1, 'catalog')).resolves.toEqual({
|
||||
x: 1,
|
||||
@@ -124,15 +124,15 @@ describe('ServiceRegistry', () => {
|
||||
});
|
||||
|
||||
it('should not be possible for root scoped services to depend on plugin scoped services', async () => {
|
||||
// @ts-expect-error
|
||||
const factory = createServiceFactory({
|
||||
// @ts-expect-error
|
||||
service: ref2,
|
||||
deps: { pluginDep: ref1 },
|
||||
async factory() {
|
||||
return { x: 2 };
|
||||
},
|
||||
});
|
||||
const registry = ServiceRegistry.create([factory(), sf1()]);
|
||||
const registry = ServiceRegistry.create([factory, sf1]);
|
||||
await expect(registry.get(ref2, 'catalog')).rejects.toThrow(
|
||||
"Failed to instantiate 'root' scoped service '2' because it depends on 'plugin' scoped service '1'.",
|
||||
);
|
||||
@@ -146,7 +146,7 @@ describe('ServiceRegistry', () => {
|
||||
return { x: rootDep.x };
|
||||
},
|
||||
});
|
||||
const registry = ServiceRegistry.create([factory(), sf2()]);
|
||||
const registry = ServiceRegistry.create([factory, sf2]);
|
||||
await expect(registry.get(ref1, 'catalog')).resolves.toEqual({
|
||||
x: 2,
|
||||
});
|
||||
@@ -161,7 +161,7 @@ describe('ServiceRegistry', () => {
|
||||
return { x: rootDep.x };
|
||||
},
|
||||
});
|
||||
const registry = ServiceRegistry.create([factory(), sf2()]);
|
||||
const registry = ServiceRegistry.create([factory, sf2]);
|
||||
await expect(registry.get(ref, 'catalog')).resolves.toEqual({
|
||||
x: 2,
|
||||
});
|
||||
@@ -176,41 +176,41 @@ describe('ServiceRegistry', () => {
|
||||
return { pluginId: meta.getId() };
|
||||
},
|
||||
});
|
||||
const registry = ServiceRegistry.create([factory()]);
|
||||
const registry = ServiceRegistry.create([factory]);
|
||||
await expect(registry.get(ref, 'catalog')).resolves.toEqual({
|
||||
pluginId: 'catalog',
|
||||
});
|
||||
});
|
||||
|
||||
it('should use the last factory for each ref', async () => {
|
||||
const registry = ServiceRegistry.create([sf2(), sf2b()]);
|
||||
const registry = ServiceRegistry.create([sf2, sf2b]);
|
||||
await expect(registry.get(ref2, 'catalog')).resolves.toEqual({
|
||||
x: 22,
|
||||
});
|
||||
});
|
||||
|
||||
it('should use added service factories for each ref', async () => {
|
||||
const registry = ServiceRegistry.create([sf2()]);
|
||||
registry.add(sf2b());
|
||||
const registry = ServiceRegistry.create([sf2]);
|
||||
registry.add(sf2b);
|
||||
await expect(registry.get(ref2, 'catalog')).resolves.toEqual({
|
||||
x: 22,
|
||||
});
|
||||
});
|
||||
|
||||
it('should not allow factories to be added after instantiation', async () => {
|
||||
const registry = ServiceRegistry.create([sf2()]);
|
||||
const registry = ServiceRegistry.create([sf2]);
|
||||
await expect(registry.get(ref2, 'catalog')).resolves.toEqual({
|
||||
x: 2,
|
||||
});
|
||||
expect(() => registry.add(sf2b())).toThrow(
|
||||
expect(() => registry.add(sf2b)).toThrow(
|
||||
'Unable to set service factory with id 2, service has already been instantiated',
|
||||
);
|
||||
});
|
||||
|
||||
it('should not allow the same factory to be added twice', async () => {
|
||||
const registry = ServiceRegistry.create([sf2()]);
|
||||
registry.add(sf2b());
|
||||
expect(() => registry.add(sf2b())).toThrow(
|
||||
const registry = ServiceRegistry.create([sf2]);
|
||||
registry.add(sf2b);
|
||||
expect(() => registry.add(sf2b)).toThrow(
|
||||
'Duplicate service implementations provided for 2',
|
||||
);
|
||||
});
|
||||
@@ -223,7 +223,7 @@ describe('ServiceRegistry', () => {
|
||||
});
|
||||
|
||||
it('should not use the defaultFactory from the ref if provided to the registry', async () => {
|
||||
const registry = ServiceRegistry.create([sf1()]);
|
||||
const registry = ServiceRegistry.create([sf1]);
|
||||
await expect(registry.get(refDefault1, 'catalog')).resolves.toEqual({
|
||||
x: 1,
|
||||
});
|
||||
@@ -279,7 +279,7 @@ describe('ServiceRegistry', () => {
|
||||
factory,
|
||||
});
|
||||
|
||||
const registry = ServiceRegistry.create([myFactory()]);
|
||||
const registry = ServiceRegistry.create([myFactory]);
|
||||
|
||||
await Promise.all([
|
||||
registry.get(ref1, 'catalog')!,
|
||||
@@ -301,7 +301,7 @@ describe('ServiceRegistry', () => {
|
||||
factory,
|
||||
});
|
||||
|
||||
const registry = ServiceRegistry.create([myFactory()]);
|
||||
const registry = ServiceRegistry.create([myFactory]);
|
||||
|
||||
await Promise.all([
|
||||
registry.get(ref1, 'catalog')!,
|
||||
@@ -323,7 +323,7 @@ describe('ServiceRegistry', () => {
|
||||
},
|
||||
});
|
||||
|
||||
const registry = ServiceRegistry.create([myFactory()]);
|
||||
const registry = ServiceRegistry.create([myFactory]);
|
||||
|
||||
await expect(registry.get(ref1, 'catalog')).rejects.toThrow(
|
||||
"Failed to instantiate service '1' for 'catalog' because the following dependent services are missing: '2'",
|
||||
@@ -350,7 +350,7 @@ describe('ServiceRegistry', () => {
|
||||
},
|
||||
});
|
||||
|
||||
const registry = ServiceRegistry.create([factoryA(), factoryB()]);
|
||||
const registry = ServiceRegistry.create([factoryA, factoryB]);
|
||||
|
||||
await expect(registry.get(refA, 'catalog')).rejects.toThrow(
|
||||
"Failed to instantiate service 'a' for 'catalog' because the factory function threw an error, Error: Failed to instantiate service 'b' for 'catalog' because the following dependent services are missing: 'c', 'd'",
|
||||
@@ -374,7 +374,7 @@ describe('ServiceRegistry', () => {
|
||||
factory: async ({ a }) => a,
|
||||
});
|
||||
|
||||
expect(() => ServiceRegistry.create([factoryA(), factoryB()])).toThrow(
|
||||
expect(() => ServiceRegistry.create([factoryA, factoryB])).toThrow(
|
||||
`Circular dependencies detected:
|
||||
'a' -> 'b' -> 'a'`,
|
||||
);
|
||||
@@ -411,12 +411,7 @@ describe('ServiceRegistry', () => {
|
||||
});
|
||||
|
||||
expect(() =>
|
||||
ServiceRegistry.create([
|
||||
factoryA(),
|
||||
factoryB(),
|
||||
factoryC(),
|
||||
factoryD(),
|
||||
]),
|
||||
ServiceRegistry.create([factoryA, factoryB, factoryC, factoryD]),
|
||||
).toThrow(
|
||||
`Circular dependencies detected:
|
||||
'a' -> 'b' -> 'a'
|
||||
@@ -448,7 +443,7 @@ describe('ServiceRegistry', () => {
|
||||
});
|
||||
|
||||
expect(() =>
|
||||
ServiceRegistry.create([factoryA(), factoryB(), factoryC()]),
|
||||
ServiceRegistry.create([factoryA, factoryB, factoryC]),
|
||||
).toThrow(
|
||||
`Circular dependencies detected:
|
||||
'a' -> 'b' -> 'c' -> 'a'`,
|
||||
@@ -486,12 +481,7 @@ describe('ServiceRegistry', () => {
|
||||
});
|
||||
|
||||
expect(() =>
|
||||
ServiceRegistry.create([
|
||||
factoryA(),
|
||||
factoryB(),
|
||||
factoryC(),
|
||||
factoryD(),
|
||||
]),
|
||||
ServiceRegistry.create([factoryA, factoryB, factoryC, factoryD]),
|
||||
).toThrow(
|
||||
`Circular dependencies detected:
|
||||
'a' -> 'b' -> 'c' -> 'a'`,
|
||||
@@ -522,7 +512,7 @@ describe('ServiceRegistry', () => {
|
||||
});
|
||||
|
||||
expect(() =>
|
||||
ServiceRegistry.create([factoryA(), factoryB(), factoryC()]),
|
||||
ServiceRegistry.create([factoryA, factoryB, factoryC]),
|
||||
).toThrow(
|
||||
`Circular dependencies detected:
|
||||
'a' -> 'c' -> 'a'`,
|
||||
@@ -553,7 +543,7 @@ describe('ServiceRegistry', () => {
|
||||
});
|
||||
|
||||
expect(() =>
|
||||
ServiceRegistry.create([factoryA(), factoryB(), factoryC()]),
|
||||
ServiceRegistry.create([factoryA, factoryB, factoryC]),
|
||||
).toThrow(
|
||||
`Circular dependencies detected:
|
||||
'b' -> 'c' -> 'b'`,
|
||||
@@ -573,7 +563,7 @@ describe('ServiceRegistry', () => {
|
||||
},
|
||||
});
|
||||
|
||||
const registry = ServiceRegistry.create([myFactory()]);
|
||||
const registry = ServiceRegistry.create([myFactory]);
|
||||
|
||||
await expect(registry.get(ref1, 'catalog')).rejects.toThrow(
|
||||
"Failed to instantiate service '1' because createRootContext threw an error, Error: top-level error",
|
||||
@@ -589,7 +579,7 @@ describe('ServiceRegistry', () => {
|
||||
},
|
||||
});
|
||||
|
||||
const registry = ServiceRegistry.create([myFactory()]);
|
||||
const registry = ServiceRegistry.create([myFactory]);
|
||||
|
||||
await expect(registry.get(ref1, 'catalog')).rejects.toThrow(
|
||||
"Failed to instantiate service '1' for 'catalog' because the factory function threw an error, Error: error in plugin",
|
||||
|
||||
Reference in New Issue
Block a user