Initial work on the backend/next setup for the catalog
Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com> Co-authored-by: blam <ben@blam.sh> Co-authored-by: Johan Haals <johan.haals@gmail.com> Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
committed by
Patrik Oldsberg
parent
4ad817262c
commit
39b24c78fe
@@ -33,7 +33,9 @@
|
||||
"clean": "backstage-cli package clean",
|
||||
"start": "backstage-cli package start"
|
||||
},
|
||||
"dependencies": {},
|
||||
"dependencies": {
|
||||
"@backstage/config": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/cli": "^0.17.2-next.0"
|
||||
},
|
||||
|
||||
@@ -21,3 +21,5 @@
|
||||
*/
|
||||
|
||||
export * from './wiring';
|
||||
export * from './services/system/types';
|
||||
export * from './services/definitions';
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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 { Config } from '@backstage/config';
|
||||
import { createServiceRef } from '../system/types';
|
||||
|
||||
export const configApiRef = createServiceRef<Config>({
|
||||
id: 'core.config',
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 { createServiceRef } from '../system/types';
|
||||
|
||||
export interface HttpRouterApi {
|
||||
get(path: string): void;
|
||||
}
|
||||
|
||||
export const httpRouterApiRef = createServiceRef<HttpRouterApi>({
|
||||
id: 'core.httpRouter',
|
||||
});
|
||||
+6
-25
@@ -14,31 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
interface Logger {
|
||||
log(message: string): void;
|
||||
child(fields: { [name: string]: string }): Logger;
|
||||
}
|
||||
|
||||
interface ConfigApi {
|
||||
getString(key: string): string;
|
||||
}
|
||||
|
||||
interface HttpRouterApi {
|
||||
get(path: string): void;
|
||||
}
|
||||
|
||||
export const loggerApiRef = createServiceRef<Logger>({
|
||||
id: 'core.logger',
|
||||
});
|
||||
|
||||
export const configApiRef = createServiceRef<ConfigApi>({
|
||||
id: 'core.config',
|
||||
});
|
||||
|
||||
export const httpRouterApiRef = createServiceRef<HttpRouterApi>({
|
||||
id: 'core.apiRouter',
|
||||
});
|
||||
|
||||
// export type PluginEnvironment = {
|
||||
// logger: Logger;
|
||||
// cache: PluginCacheManager;
|
||||
@@ -50,3 +25,9 @@ export const httpRouterApiRef = createServiceRef<HttpRouterApi>({
|
||||
// permissions: PermissionEvaluator | PermissionAuthorizer;
|
||||
// scheduler: PluginTaskScheduler;
|
||||
// };
|
||||
|
||||
export { configApiRef } from './configApiRef';
|
||||
export { httpRouterApiRef } from './httpRouterApiRef';
|
||||
export type { HttpRouterApi } from './httpRouterApiRef';
|
||||
export { loggerApiRef } from './loggerApiRef';
|
||||
export type { Logger } from './loggerApiRef';
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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 { createServiceRef } from '../system/types';
|
||||
|
||||
export interface Logger {
|
||||
log(message: string): void;
|
||||
child(fields: { [name: string]: string }): Logger;
|
||||
}
|
||||
|
||||
export const loggerApiRef = createServiceRef<Logger>({
|
||||
id: 'core.logger',
|
||||
});
|
||||
@@ -14,17 +14,56 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface ServiceRef<T> {
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* Utility for getting the type of the service, using `typeof serviceRef.T`.
|
||||
* Attempting to actually read this value will result in an exception.
|
||||
*/
|
||||
T: T;
|
||||
|
||||
toString(): string;
|
||||
|
||||
$$ref: 'service';
|
||||
}
|
||||
|
||||
type TypesToServiceRef<T> = { [key in keyof T]: ServiceRef<T[key]> };
|
||||
type DepsToDepFactories<T> = {
|
||||
[key in keyof T]: (pluginId: string) => Promise<T[key]>;
|
||||
};
|
||||
|
||||
export type FactoryFunc<Impl> = (pluginId: string) => Promise<Impl>;
|
||||
|
||||
export type ServiceFactory<
|
||||
TApi,
|
||||
TImpl extends TApi,
|
||||
TDeps extends { [name in string]: unknown },
|
||||
> = {
|
||||
service: ServiceRef<TApi>;
|
||||
deps: TypesToServiceRef<TDeps>;
|
||||
factory(deps: DepsToDepFactories<TDeps>): Promise<FactoryFunc<TImpl>>;
|
||||
};
|
||||
|
||||
export type AnyServiceFactory = ServiceFactory<
|
||||
unknown,
|
||||
unknown,
|
||||
{ [key in string]: unknown }
|
||||
>;
|
||||
|
||||
export function createServiceRef<T>(options: { id: string }): ServiceRef<T> {
|
||||
return {
|
||||
id: options.id,
|
||||
get T(): T {
|
||||
throw Error('NO T');
|
||||
throw new Error(`tried to read ServiceRef.T of ${this}`);
|
||||
},
|
||||
toString() {
|
||||
return `serviceRef{${options.id}}`;
|
||||
},
|
||||
$$ref: 'service', // TODO: declare
|
||||
};
|
||||
|
||||
@@ -14,4 +14,5 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { BackendRegistrable } from './types';
|
||||
export type { BackendRegistrable } from './types';
|
||||
export * from './types';
|
||||
|
||||
@@ -14,9 +14,25 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ServiceRef } from '../services/system/types';
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface ExtensionPoint<T> {
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* Utility for getting the type of the extension point, using `typeof
|
||||
* extensionPoint.T`. Attempting to actually read this value will result in an
|
||||
* exception.
|
||||
*/
|
||||
T: T;
|
||||
|
||||
toString(): string;
|
||||
|
||||
$$ref: 'extension-point';
|
||||
}
|
||||
|
||||
@@ -26,7 +42,10 @@ export function createExtensionPoint<T>(options: {
|
||||
return {
|
||||
id: options.id,
|
||||
get T(): T {
|
||||
throw Error('NO T');
|
||||
throw new Error(`tried to read ExtensionPoint.T of ${this}`);
|
||||
},
|
||||
toString() {
|
||||
return `extensionPoint{${options.id}}`;
|
||||
},
|
||||
$$ref: 'extension-point', // TODO: declare
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user