Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move over most trivial services to backend-defaults #24724

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion .changeset/lucky-taxis-rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
'@backstage/backend-defaults': patch
---

Added the `schedulerServiceFactory` and its implementation, migrated over from `@backstage/backend-app-api`
Added core service factories and implementations from
`@backstage/backend-app-api`. They are now available as subpath exports, e.g.
`@backstage/backend-defaults/scheduler` is where the service factory and default
implementation of `coreServices.scheduler` now lives. They have been marked as
deprecated in their old locations.
5 changes: 4 additions & 1 deletion .changeset/rude-kings-press.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
'@backstage/backend-app-api': patch
---

Deprecated `schedulerServiceFactory`, which should now instead be imported from `@backstage/backend-defaults/scheduler` instead
Deprecated core service factories and implementations and moved them over to
subpath exports on `@backstage/backend-defaults` instead. E.g.
`@backstage/backend-defaults/scheduler` is where the service factory and default
implementation of `coreServices.scheduler` now lives.
26 changes: 13 additions & 13 deletions packages/backend-app-api/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export interface Backend {
stop(): Promise<void>;
}

// @public (undocumented)
// @public @deprecated (undocumented)
export const cacheServiceFactory: () => ServiceFactory<CacheClient, 'plugin'>;

// @public (undocumented)
Expand Down Expand Up @@ -100,7 +100,7 @@ export interface CreateSpecializedBackendOptions {
defaultServiceFactories: ServiceFactoryOrFunction[];
}

// @public (undocumented)
// @public @deprecated (undocumented)
export const databaseServiceFactory: () => ServiceFactory<
PluginDatabaseManager,
'plugin'
Expand All @@ -121,7 +121,7 @@ export interface DefaultRootHttpRouterOptions {
indexPath?: string | false;
}

// @public (undocumented)
// @public @deprecated (undocumented)
export const discoveryServiceFactory: () => ServiceFactory<
DiscoveryService,
'plugin'
Expand All @@ -137,7 +137,7 @@ export interface ExtendedHttpServer extends http.Server {
stop(): Promise<void>;
}

// @public
// @public @deprecated
export class HostDiscovery implements DiscoveryService {
static fromConfig(
config: Config,
Expand Down Expand Up @@ -190,13 +190,13 @@ export type HttpServerOptions = {
};
};

// @public
// @public @deprecated
export type IdentityFactoryOptions = {
issuer?: string;
algorithms?: string[];
};

// @public (undocumented)
// @public @deprecated (undocumented)
export const identityServiceFactory: (
options?: IdentityFactoryOptions | undefined,
) => ServiceFactory<IdentityService, 'plugin'>;
Expand All @@ -208,7 +208,7 @@ export interface LifecycleMiddlewareOptions {
startupRequestPauseTimeout?: HumanDuration;
}

// @public
// @public @deprecated
export const lifecycleServiceFactory: () => ServiceFactory<
LifecycleService,
'plugin'
Expand Down Expand Up @@ -255,7 +255,7 @@ export interface MiddlewareFactoryOptions {
logger: LoggerService;
}

// @public (undocumented)
// @public @deprecated (undocumented)
export const permissionsServiceFactory: () => ServiceFactory<
PermissionsService,
'plugin'
Expand All @@ -270,15 +270,15 @@ export function readHelmetOptions(config?: Config): HelmetOptions;
// @public
export function readHttpServerOptions(config?: Config): HttpServerOptions;

// @public (undocumented)
// @public @deprecated (undocumented)
export interface RootConfigFactoryOptions {
argv?: string[];
remote?: Pick<RemoteConfigSourceOptions, 'reloadInterval'>;
// (undocumented)
watch?: boolean;
}

// @public (undocumented)
// @public @deprecated (undocumented)
export const rootConfigServiceFactory: (
options?: RootConfigFactoryOptions | undefined,
) => ServiceFactory<RootConfigService, 'root'>;
Expand Down Expand Up @@ -314,7 +314,7 @@ export const rootHttpRouterServiceFactory: (
options?: RootHttpRouterFactoryOptions | undefined,
) => ServiceFactory<RootHttpRouterService, 'root'>;

// @public
// @public @deprecated
export const rootLifecycleServiceFactory: () => ServiceFactory<
RootLifecycleService,
'root'
Expand All @@ -332,13 +332,13 @@ export const schedulerServiceFactory: () => ServiceFactory<
'plugin'
>;

// @public (undocumented)
// @public @deprecated (undocumented)
export const tokenManagerServiceFactory: () => ServiceFactory<
TokenManagerService,
'plugin'
>;

// @public (undocumented)
// @public @deprecated (undocumented)
export const urlReaderServiceFactory: () => ServiceFactory<UrlReader, 'plugin'>;

// @public (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {
createServiceFactory,
} from '@backstage/backend-plugin-api';

/** @public */
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move the deprecated files to a deprecated folder? Just for making it easy to cleanup later?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah that could really help!

* @public
* @deprecated Please import from `@backstage/backend-defaults/cache` instead.
*/
export const cacheServiceFactory = createServiceFactory({
service: coreServices.cache,
deps: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import {
RemoteConfigSourceOptions,
} from '@backstage/config-loader';

/** @public */
/**
* @public
* @deprecated Please import from `@backstage/backend-defaults/rootConfig` instead.
*/
export interface RootConfigFactoryOptions {
/**
* Process arguments to use instead of the default `process.argv()`.
Expand All @@ -37,7 +40,10 @@ export interface RootConfigFactoryOptions {
watch?: boolean;
}

/** @public */
/**
* @public
* @deprecated Please import from `@backstage/backend-defaults/rootConfig` instead.
*/
export const rootConfigServiceFactory = createServiceFactory(
(options?: RootConfigFactoryOptions) => ({
service: coreServices.rootConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
} from '@backstage/backend-plugin-api';
import { ConfigReader } from '@backstage/config';

/** @public */
/**
* @public
* @deprecated Please import from `@backstage/backend-defaults/database` instead.
*/
export const databaseServiceFactory = createServiceFactory({
service: coreServices.database,
deps: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Target = string | { internal: string; external: string };
* resolved to the same host, so there won't be any balancing of internal traffic.
*
* @public
* @deprecated Please import from `@backstage/backend-defaults/discovery` instead.
*/
export class HostDiscovery implements DiscoveryService {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {
} from '@backstage/backend-plugin-api';
import { HostDiscovery } from './HostDiscovery';

/** @public */
/**
* @public
* @deprecated Please import from `@backstage/backend-defaults/discovery` instead.
*/
export const discoveryServiceFactory = createServiceFactory({
service: coreServices.discovery,
deps: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@ 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 */
/**
* 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 */
/**
* @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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import {
createServiceFactory,
} from '@backstage/backend-plugin-api';

/** @internal */
/**
* @internal
* @deprecated
*/
export class BackendPluginLifecycleImpl implements LifecycleService {
constructor(
private readonly logger: LoggerService,
Expand Down Expand Up @@ -85,7 +88,9 @@ export class BackendPluginLifecycleImpl implements LifecycleService {

/**
* Allows plugins to register shutdown hooks that are run when the process is about to exit.
*
* @public
* @deprecated Please import from `@backstage/backend-defaults/lifecycle` instead.
*/
export const lifecycleServiceFactory = createServiceFactory({
service: coreServices.lifecycle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {
} from '@backstage/backend-plugin-api';
import { ServerPermissionClient } from '@backstage/plugin-permission-node';

/** @public */
/**
* @public
* @deprecated Please import from `@backstage/backend-defaults/permissions` instead.
*/
export const permissionsServiceFactory = createServiceFactory({
service: coreServices.permissions,
deps: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import {
LoggerService,
} from '@backstage/backend-plugin-api';

/** @internal */
/**
* @internal
* @deprecated
*/
export class BackendLifecycleImpl implements RootLifecycleService {
constructor(private readonly logger: LoggerService) {}

Expand Down Expand Up @@ -108,6 +111,7 @@ export class BackendLifecycleImpl implements RootLifecycleService {
* Allows plugins to register shutdown hooks that are run when the process is about to exit.
*
* @public
* @deprecated Please import from `@backstage/backend-defaults/rootLifecycle` instead.
*/
export const rootLifecycleServiceFactory = createServiceFactory({
service: coreServices.rootLifecycle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {
} from '@backstage/backend-plugin-api';
import { ServerTokenManager } from '@backstage/backend-common';

/** @public */
/**
* @public
* @deprecated Please migrate to the new `coreServices.auth`, `coreServices.httpAuth`, and `coreServices.userInfo` services as needed instead
*/
export const tokenManagerServiceFactory = createServiceFactory({
service: coreServices.tokenManager,
deps: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {
createServiceFactory,
} from '@backstage/backend-plugin-api';

/** @public */
/**
* @public
* @deprecated Please import from `@backstage/backend-defaults/urlReader` instead.
*/
export const urlReaderServiceFactory = createServiceFactory({
service: coreServices.urlReader,
deps: {
Expand Down
31 changes: 23 additions & 8 deletions packages/backend-app-api/src/wiring/BackendInitializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
coreServices,
ServiceRef,
ServiceFactory,
LifecycleService,
RootLifecycleService,
} from '@backstage/backend-plugin-api';
import { BackendLifecycleImpl } from '../services/implementations/rootLifecycle/rootLifecycleServiceFactory';
camilaibs marked this conversation as resolved.
Show resolved Hide resolved
import { BackendPluginLifecycleImpl } from '../services/implementations/lifecycle/lifecycleServiceFactory';
import { ServiceOrExtensionPoint } from './types';
// Direct internal import to avoid duplication
// eslint-disable-next-line @backstage/no-forbidden-package-imports
Expand Down Expand Up @@ -345,27 +345,42 @@ export class BackendInitializer {
}

// Bit of a hacky way to grab the lifecycle services, potentially find a nicer way to do this
async #getRootLifecycleImpl(): Promise<BackendLifecycleImpl> {
async #getRootLifecycleImpl(): Promise<
RootLifecycleService & {
startup(): Promise<void>;
shutdown(): Promise<void>;
}
> {
const lifecycleService = await this.#serviceRegistry.get(
coreServices.rootLifecycle,
'root',
);
if (lifecycleService instanceof BackendLifecycleImpl) {
return lifecycleService;

const service = lifecycleService as any;
if (
service &&
typeof service.startup === 'function' &&
typeof service.shutdown === 'function'
) {
return service;
}

throw new Error('Unexpected root lifecycle service implementation');
}

async #getPluginLifecycleImpl(
pluginId: string,
): Promise<BackendPluginLifecycleImpl> {
): Promise<LifecycleService & { startup(): Promise<void> }> {
const lifecycleService = await this.#serviceRegistry.get(
coreServices.lifecycle,
pluginId,
);
if (lifecycleService instanceof BackendPluginLifecycleImpl) {
return lifecycleService;

const service = lifecycleService as any;
if (service && typeof service.startup === 'function') {
return service;
}
Comment on lines +379 to 382
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


throw new Error('Unexpected plugin lifecycle service implementation');
}
}
Expand Down
13 changes: 13 additions & 0 deletions packages/backend-defaults/api-report-cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## API Report File for "@backstage/backend-defaults"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts
import { CacheClient } from '@backstage/backend-common';
import { ServiceFactory } from '@backstage/backend-plugin-api';

// @public (undocumented)
export const cacheServiceFactory: () => ServiceFactory<CacheClient, 'plugin'>;

// (No @packageDocumentation comment for this package)
```
16 changes: 16 additions & 0 deletions packages/backend-defaults/api-report-database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## API Report File for "@backstage/backend-defaults"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts
import { PluginDatabaseManager } from '@backstage/backend-common';
import { ServiceFactory } from '@backstage/backend-plugin-api';

// @public (undocumented)
export const databaseServiceFactory: () => ServiceFactory<
PluginDatabaseManager,
'plugin'
>;

// (No @packageDocumentation comment for this package)
```