Introduce backend-defaults package
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
@@ -5,6 +5,18 @@
|
||||
```ts
|
||||
import { AnyServiceFactory } from '@backstage/backend-plugin-api';
|
||||
import { BackendRegistrable } from '@backstage/backend-plugin-api';
|
||||
import { Config } from '@backstage/config';
|
||||
import { HttpRouterService } from '@backstage/backend-plugin-api';
|
||||
import { Logger } from '@backstage/backend-plugin-api';
|
||||
import { PermissionAuthorizer } from '@backstage/plugin-permission-common';
|
||||
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
|
||||
import { PluginCacheManager } from '@backstage/backend-common';
|
||||
import { PluginDatabaseManager } from '@backstage/backend-common';
|
||||
import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import { PluginTaskScheduler } from '@backstage/backend-tasks';
|
||||
import { ServiceFactory } from '@backstage/backend-plugin-api';
|
||||
import { TokenManager } from '@backstage/backend-common';
|
||||
import { UrlReader } from '@backstage/backend-common';
|
||||
|
||||
// @public (undocumented)
|
||||
export interface Backend {
|
||||
@@ -15,11 +27,71 @@ export interface Backend {
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export function createBackend(options?: CreateBackendOptions): Backend;
|
||||
export const cacheFactory: ServiceFactory<
|
||||
PluginCacheManager,
|
||||
PluginCacheManager,
|
||||
{}
|
||||
>;
|
||||
|
||||
// @public (undocumented)
|
||||
export interface CreateBackendOptions {
|
||||
export const configFactory: ServiceFactory<Config, Config, {}>;
|
||||
|
||||
// @public (undocumented)
|
||||
export function createSpecializedBackend(
|
||||
options: CreateSpecializedBackendOptions,
|
||||
): Backend;
|
||||
|
||||
// @public (undocumented)
|
||||
export interface CreateSpecializedBackendOptions {
|
||||
// (undocumented)
|
||||
apis: AnyServiceFactory[];
|
||||
serviceFactories: AnyServiceFactory[];
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export const databaseFactory: ServiceFactory<
|
||||
PluginDatabaseManager,
|
||||
PluginDatabaseManager,
|
||||
{}
|
||||
>;
|
||||
|
||||
// @public (undocumented)
|
||||
export const discoveryFactory: ServiceFactory<
|
||||
PluginEndpointDiscovery,
|
||||
PluginEndpointDiscovery,
|
||||
{}
|
||||
>;
|
||||
|
||||
// @public (undocumented)
|
||||
export const httpRouterFactory: ServiceFactory<
|
||||
HttpRouterService,
|
||||
HttpRouterService,
|
||||
{}
|
||||
>;
|
||||
|
||||
// @public (undocumented)
|
||||
export const loggerFactory: ServiceFactory<Logger, Logger, {}>;
|
||||
|
||||
// @public (undocumented)
|
||||
export const permissionsFactory: ServiceFactory<
|
||||
PermissionAuthorizer | PermissionEvaluator,
|
||||
PermissionAuthorizer | PermissionEvaluator,
|
||||
{}
|
||||
>;
|
||||
|
||||
// @public (undocumented)
|
||||
export const schedulerFactory: ServiceFactory<
|
||||
PluginTaskScheduler,
|
||||
PluginTaskScheduler,
|
||||
{}
|
||||
>;
|
||||
|
||||
// @public (undocumented)
|
||||
export const tokenManagerFactory: ServiceFactory<
|
||||
TokenManager,
|
||||
TokenManager,
|
||||
{}
|
||||
>;
|
||||
|
||||
// @public (undocumented)
|
||||
export const urlReaderFactory: ServiceFactory<UrlReader, UrlReader, {}>;
|
||||
```
|
||||
|
||||
@@ -21,3 +21,4 @@
|
||||
*/
|
||||
|
||||
export * from './wiring';
|
||||
export * from './services/implementations';
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
cacheServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
|
||||
// TODO: Work out some naming and implementation patterns for these
|
||||
/** @public */
|
||||
export const cacheFactory = createServiceFactory({
|
||||
service: cacheServiceRef,
|
||||
deps: {
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
loggerServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
|
||||
/** @public */
|
||||
export const configFactory = createServiceFactory({
|
||||
service: configServiceRef,
|
||||
deps: {
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
databaseServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
|
||||
/** @public */
|
||||
export const databaseFactory = createServiceFactory({
|
||||
service: databaseServiceRef,
|
||||
deps: {
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
discoveryServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
|
||||
/** @public */
|
||||
export const discoveryFactory = createServiceFactory({
|
||||
service: discoveryServiceRef,
|
||||
deps: {
|
||||
|
||||
@@ -23,6 +23,7 @@ import Router from 'express-promise-router';
|
||||
import { Handler } from 'express';
|
||||
import { createServiceBuilder } from '@backstage/backend-common';
|
||||
|
||||
/** @public */
|
||||
export const httpRouterFactory = createServiceFactory({
|
||||
service: httpRouterServiceRef,
|
||||
deps: {
|
||||
|
||||
@@ -14,26 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { cacheFactory } from './cacheService';
|
||||
import { configFactory } from './configService';
|
||||
import { databaseFactory } from './databaseService';
|
||||
import { discoveryFactory } from './discoveryService';
|
||||
import { loggerFactory } from './loggerService';
|
||||
import { permissionsFactory } from './permissionsService';
|
||||
import { schedulerFactory } from './schedulerService';
|
||||
import { tokenManagerFactory } from './tokenManagerService';
|
||||
import { urlReaderFactory } from './urlReaderService';
|
||||
import { httpRouterFactory } from './httpRouterService';
|
||||
|
||||
export const defaultServiceFactories = [
|
||||
cacheFactory,
|
||||
configFactory,
|
||||
databaseFactory,
|
||||
discoveryFactory,
|
||||
loggerFactory,
|
||||
permissionsFactory,
|
||||
schedulerFactory,
|
||||
tokenManagerFactory,
|
||||
urlReaderFactory,
|
||||
httpRouterFactory,
|
||||
];
|
||||
export { cacheFactory } from './cacheService';
|
||||
export { configFactory } from './configService';
|
||||
export { databaseFactory } from './databaseService';
|
||||
export { discoveryFactory } from './discoveryService';
|
||||
export { loggerFactory } from './loggerService';
|
||||
export { permissionsFactory } from './permissionsService';
|
||||
export { schedulerFactory } from './schedulerService';
|
||||
export { tokenManagerFactory } from './tokenManagerService';
|
||||
export { urlReaderFactory } from './urlReaderService';
|
||||
export { httpRouterFactory } from './httpRouterService';
|
||||
|
||||
@@ -38,6 +38,7 @@ class BackstageLogger implements Logger {
|
||||
}
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export const loggerFactory = createServiceFactory({
|
||||
service: loggerServiceRef,
|
||||
deps: {},
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { ServerPermissionClient } from '@backstage/plugin-permission-node';
|
||||
|
||||
/** @public */
|
||||
export const permissionsFactory = createServiceFactory({
|
||||
service: permissionsServiceRef,
|
||||
deps: {
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { TaskScheduler } from '@backstage/backend-tasks';
|
||||
|
||||
/** @public */
|
||||
export const schedulerFactory = createServiceFactory({
|
||||
service: schedulerServiceRef,
|
||||
deps: {
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { ServerTokenManager } from '@backstage/backend-common';
|
||||
|
||||
/** @public */
|
||||
export const tokenManagerFactory = createServiceFactory({
|
||||
service: tokenManagerServiceRef,
|
||||
deps: {
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
urlReaderServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
|
||||
/** @public */
|
||||
export const urlReaderFactory = createServiceFactory({
|
||||
service: urlReaderServiceRef,
|
||||
deps: {
|
||||
|
||||
@@ -14,5 +14,5 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export type { Backend, CreateBackendOptions } from './types';
|
||||
export { createBackend } from './types';
|
||||
export type { Backend, CreateSpecializedBackendOptions } from './types';
|
||||
export { createSpecializedBackend } from './types';
|
||||
|
||||
@@ -20,7 +20,6 @@ import {
|
||||
FactoryFunc,
|
||||
ServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { defaultServiceFactories } from '../services/implementations';
|
||||
import { BackstageBackend } from './BackstageBackend';
|
||||
|
||||
/**
|
||||
@@ -42,8 +41,8 @@ export interface BackendRegisterInit {
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface CreateBackendOptions {
|
||||
apis: AnyServiceFactory[];
|
||||
export interface CreateSpecializedBackendOptions {
|
||||
serviceFactories: AnyServiceFactory[];
|
||||
}
|
||||
|
||||
export type ServiceHolder = {
|
||||
@@ -53,10 +52,8 @@ export type ServiceHolder = {
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export function createBackend(options?: CreateBackendOptions): Backend {
|
||||
// TODO: merge with provided APIs
|
||||
return new BackstageBackend([
|
||||
...defaultServiceFactories,
|
||||
...(options?.apis ?? []),
|
||||
]);
|
||||
export function createSpecializedBackend(
|
||||
options: CreateSpecializedBackendOptions,
|
||||
): Backend {
|
||||
return new BackstageBackend(options.serviceFactories);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user