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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
|
||||
@@ -0,0 +1,19 @@
|
||||
# @backstage/backend-defaults
|
||||
|
||||
**This package is HIGHLY EXPERIMENTAL, do not use this for production**
|
||||
|
||||
This package provides the core API used by Backstage backend apps.
|
||||
|
||||
## Installation
|
||||
|
||||
Add the library to your backend app package:
|
||||
|
||||
```bash
|
||||
# From your Backstage root directory
|
||||
yarn add --cwd packages/backend @backstage/backend-defaults
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
- [Backstage Readme](https://github.com/backstage/backstage/blob/master/README.md)
|
||||
- [Backstage Documentation](https://github.com/backstage/backstage/blob/master/docs/README.md)
|
||||
@@ -0,0 +1,19 @@
|
||||
## 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 { AnyServiceFactory } from '@backstage/backend-plugin-api';
|
||||
import { Backend } from '@backstage/backend-app-api';
|
||||
|
||||
// @public (undocumented)
|
||||
export function createBackend(options?: CreateBackendOptions): Backend;
|
||||
|
||||
// @public (undocumented)
|
||||
export interface CreateBackendOptions {
|
||||
// (undocumented)
|
||||
serviceFactories?: AnyServiceFactory[];
|
||||
}
|
||||
|
||||
// (No @packageDocumentation comment for this package)
|
||||
```
|
||||
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "@backstage/backend-defaults",
|
||||
"description": "Backend defaults used by Backstage backend apps",
|
||||
"version": "0.0.0",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"private": false,
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"main": "dist/index.cjs.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"alphaTypes": "dist/index.alpha.d.ts"
|
||||
},
|
||||
"backstage": {
|
||||
"role": "node-library"
|
||||
},
|
||||
"homepage": "https://backstage.io",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/backstage/backstage",
|
||||
"directory": "packages/backend-defaults"
|
||||
},
|
||||
"keywords": [
|
||||
"backstage"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"build": "backstage-cli package build --experimental-type-build",
|
||||
"lint": "backstage-cli package lint",
|
||||
"test": "backstage-cli package test",
|
||||
"prepack": "backstage-cli package prepack",
|
||||
"postpack": "backstage-cli package postpack",
|
||||
"clean": "backstage-cli package clean",
|
||||
"start": "backstage-cli package start"
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/backend-app-api": "^0.1.1-next.0",
|
||||
"@backstage/backend-plugin-api": "^0.1.1-next.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/cli": "^0.18.1-next.0"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"alpha"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2022 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 {
|
||||
Backend,
|
||||
cacheFactory,
|
||||
configFactory,
|
||||
createSpecializedBackend,
|
||||
databaseFactory,
|
||||
discoveryFactory,
|
||||
httpRouterFactory,
|
||||
loggerFactory,
|
||||
permissionsFactory,
|
||||
schedulerFactory,
|
||||
tokenManagerFactory,
|
||||
urlReaderFactory,
|
||||
} from '@backstage/backend-app-api';
|
||||
import { CreateBackendOptions } from './types';
|
||||
|
||||
export const defaultServiceFactories = [
|
||||
cacheFactory,
|
||||
configFactory,
|
||||
databaseFactory,
|
||||
discoveryFactory,
|
||||
loggerFactory,
|
||||
permissionsFactory,
|
||||
schedulerFactory,
|
||||
tokenManagerFactory,
|
||||
urlReaderFactory,
|
||||
httpRouterFactory,
|
||||
];
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export function createBackend(options?: CreateBackendOptions): Backend {
|
||||
// TODO: merge with provided APIs
|
||||
return createSpecializedBackend({
|
||||
serviceFactories: [
|
||||
...defaultServiceFactories,
|
||||
...(options?.serviceFactories || []),
|
||||
],
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2022 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.
|
||||
*/
|
||||
|
||||
export type { CreateBackendOptions } from './types';
|
||||
export { createBackend } from './CreateBackend';
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2022 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 { AnyServiceFactory } from '@backstage/backend-plugin-api';
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface CreateBackendOptions {
|
||||
serviceFactories?: AnyServiceFactory[];
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
"clean": "backstage-cli package clean"
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/backend-app-api": "^0.1.1-next.0",
|
||||
"@backstage/backend-defaults": "^0.0.0",
|
||||
"@backstage/plugin-catalog-backend": "^1.3.1-next.0",
|
||||
"@backstage/plugin-scaffolder-backend": "^1.5.0-next.0"
|
||||
},
|
||||
@@ -35,4 +35,4 @@
|
||||
"files": [
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createBackend } from '@backstage/backend-app-api';
|
||||
import { catalogPlugin } from '@backstage/plugin-catalog-backend';
|
||||
import { scaffolderCatalogModule } from '@backstage/plugin-scaffolder-backend';
|
||||
import { createBackend } from '@backstage/backend-defaults';
|
||||
|
||||
const backend = createBackend({
|
||||
apis: [],
|
||||
});
|
||||
const backend = createBackend();
|
||||
|
||||
backend.add(catalogPlugin({}));
|
||||
backend.add(scaffolderCatalogModule({}));
|
||||
|
||||
Reference in New Issue
Block a user