frontend-plugin-api: naming refactor for createApiExtension
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -26,13 +26,38 @@ describe('createApiExtension', () => {
|
||||
factory: () => ({ foo: 'bar' }),
|
||||
});
|
||||
|
||||
const extension = createApiExtension({
|
||||
factory,
|
||||
expect(
|
||||
createApiExtension({
|
||||
factory,
|
||||
}),
|
||||
).toEqual({
|
||||
$$type: '@backstage/ExtensionDefinition',
|
||||
kind: 'api',
|
||||
attachTo: { id: 'core', input: 'apis' },
|
||||
disabled: false,
|
||||
configSchema: undefined,
|
||||
inputs: {},
|
||||
output: {
|
||||
api: expect.objectContaining({
|
||||
$$type: '@backstage/ExtensionDataRef',
|
||||
id: 'core.api.factory',
|
||||
config: {},
|
||||
}),
|
||||
},
|
||||
factory: expect.any(Function),
|
||||
});
|
||||
|
||||
expect(extension).toEqual({
|
||||
$$type: '@backstage/Extension',
|
||||
id: 'apis.test',
|
||||
expect(
|
||||
createApiExtension({
|
||||
factory,
|
||||
namespace: 'ns',
|
||||
name: 'n',
|
||||
}),
|
||||
).toEqual({
|
||||
$$type: '@backstage/ExtensionDefinition',
|
||||
kind: 'api',
|
||||
namespace: 'ns',
|
||||
name: 'n',
|
||||
attachTo: { id: 'core', input: 'apis' },
|
||||
disabled: false,
|
||||
configSchema: undefined,
|
||||
@@ -53,7 +78,6 @@ describe('createApiExtension', () => {
|
||||
const factory = jest.fn(() => ({ foo: 'bar' }));
|
||||
|
||||
const extension = createApiExtension({
|
||||
api,
|
||||
inputs: {},
|
||||
factory({ config: _config, inputs: _inputs }) {
|
||||
return createApiFactory({
|
||||
@@ -65,8 +89,8 @@ describe('createApiExtension', () => {
|
||||
});
|
||||
// boo
|
||||
expect(extension).toEqual({
|
||||
$$type: '@backstage/Extension',
|
||||
id: 'apis.test',
|
||||
$$type: '@backstage/ExtensionDefinition',
|
||||
kind: 'api',
|
||||
attachTo: { id: 'core', input: 'apis' },
|
||||
disabled: false,
|
||||
configSchema: undefined,
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AnyApiFactory, AnyApiRef } from '@backstage/core-plugin-api';
|
||||
import { AnyApiFactory } from '@backstage/core-plugin-api';
|
||||
import { PortableSchema } from '../schema';
|
||||
import {
|
||||
ExtensionInputValues,
|
||||
@@ -28,30 +28,24 @@ import { Expand } from '../types';
|
||||
export function createApiExtension<
|
||||
TConfig extends {},
|
||||
TInputs extends AnyExtensionInputMap,
|
||||
>(
|
||||
options: (
|
||||
| {
|
||||
api: AnyApiRef;
|
||||
factory: (options: {
|
||||
config: TConfig;
|
||||
inputs: Expand<ExtensionInputValues<TInputs>>;
|
||||
}) => AnyApiFactory;
|
||||
}
|
||||
| {
|
||||
factory: AnyApiFactory;
|
||||
}
|
||||
) & {
|
||||
configSchema?: PortableSchema<TConfig>;
|
||||
inputs?: TInputs;
|
||||
},
|
||||
) {
|
||||
>(options: {
|
||||
factory:
|
||||
| AnyApiFactory
|
||||
| ((options: {
|
||||
config: TConfig;
|
||||
inputs: Expand<ExtensionInputValues<TInputs>>;
|
||||
}) => AnyApiFactory);
|
||||
namespace?: string;
|
||||
name?: string;
|
||||
configSchema?: PortableSchema<TConfig>;
|
||||
inputs?: TInputs;
|
||||
}) {
|
||||
const { factory, configSchema, inputs: extensionInputs } = options;
|
||||
|
||||
const apiRef =
|
||||
'api' in options ? options.api : (factory as { api: AnyApiRef }).api;
|
||||
|
||||
return createExtension({
|
||||
id: `apis.${apiRef.id}`,
|
||||
kind: 'api',
|
||||
namespace: options.namespace,
|
||||
name: options.name,
|
||||
attachTo: { id: 'core', input: 'apis' },
|
||||
inputs: extensionInputs,
|
||||
configSchema,
|
||||
|
||||
Reference in New Issue
Block a user