catalog-node: Export experimental catalogServiceRef
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-node': patch
|
||||
---
|
||||
|
||||
Adds experimental catalogServiceRef for optaining a `catalogClient` in the new backend system
|
||||
@@ -5,10 +5,12 @@
|
||||
```ts
|
||||
/// <reference types="node" />
|
||||
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import { CompoundEntityRef } from '@backstage/catalog-model';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { JsonValue } from '@backstage/types';
|
||||
import { ServiceRef } from '@backstage/backend-plugin-api';
|
||||
|
||||
// @alpha (undocumented)
|
||||
export interface CatalogProcessingExtensionPoint {
|
||||
@@ -106,6 +108,9 @@ export type CatalogProcessorResult =
|
||||
| CatalogProcessorErrorResult
|
||||
| CatalogProcessorRefreshKeysResult;
|
||||
|
||||
// @alpha
|
||||
export const catalogServiceRef: ServiceRef<CatalogApi>;
|
||||
|
||||
// @public
|
||||
export type DeferredEntity = {
|
||||
entity: Entity;
|
||||
|
||||
@@ -26,16 +26,18 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/backend-plugin-api": "^0.1.2-next.0",
|
||||
"@backstage/catalog-client": "^1.0.5-next.0",
|
||||
"@backstage/catalog-model": "^1.1.0",
|
||||
"@backstage/errors": "1.1.0",
|
||||
"@backstage/types": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/backend-common": "^0.15.1-next.1",
|
||||
"@backstage/cli": "^0.19.0-next.1"
|
||||
"@backstage/cli": "^0.19.0-next.1",
|
||||
"@backstage/backend-test-utils": "^0.1.28-next.1"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"alpha"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import {
|
||||
createBackendModule,
|
||||
createServiceFactory,
|
||||
createServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { startTestBackend } from '@backstage/backend-test-utils';
|
||||
import { CatalogClient } from '@backstage/catalog-client';
|
||||
import { catalogServiceRef } from './catalogService';
|
||||
|
||||
describe('catalogServiceRef', () => {
|
||||
it('should return a catalogClient', async () => {
|
||||
const mockDiscoveryFactory = createServiceFactory({
|
||||
service: createServiceRef<PluginEndpointDiscovery>({
|
||||
id: 'core.discovery',
|
||||
}),
|
||||
deps: {},
|
||||
factory: async ({}) => {
|
||||
return async () => jest.fn() as unknown as PluginEndpointDiscovery;
|
||||
},
|
||||
});
|
||||
|
||||
const testModule = createBackendModule({
|
||||
moduleId: 'test.module',
|
||||
pluginId: 'test',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
catalog: catalogServiceRef,
|
||||
},
|
||||
async init({ catalog }) {
|
||||
expect(catalog).toBeInstanceOf(CatalogClient);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
await startTestBackend({
|
||||
services: [mockDiscoveryFactory],
|
||||
features: [testModule({})],
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 {
|
||||
createServiceFactory,
|
||||
createServiceRef,
|
||||
discoveryServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { CatalogApi, CatalogClient } from '@backstage/catalog-client';
|
||||
|
||||
/**
|
||||
* The catalogService provides the catalog API.
|
||||
* @alpha
|
||||
*/
|
||||
export const catalogServiceRef = createServiceRef<CatalogApi>({
|
||||
id: 'catalog-client',
|
||||
defaultFactory: async service =>
|
||||
createServiceFactory({
|
||||
service,
|
||||
deps: {
|
||||
discoveryFactory: discoveryServiceRef,
|
||||
},
|
||||
factory: async ({ discoveryFactory }) => {
|
||||
const discoveryApi = await discoveryFactory('root');
|
||||
const catalogClient = new CatalogClient({ discoveryApi });
|
||||
return async _pluginId => {
|
||||
return catalogClient;
|
||||
};
|
||||
},
|
||||
}),
|
||||
});
|
||||
@@ -22,5 +22,6 @@
|
||||
|
||||
export type { CatalogProcessingExtensionPoint } from './extensions';
|
||||
export { catalogProcessingExtensionPoint } from './extensions';
|
||||
export { catalogServiceRef } from './catalogService';
|
||||
export * from './api';
|
||||
export * from './processing';
|
||||
|
||||
Reference in New Issue
Block a user