frontend-plugin-api: refactor to use LegacyExtensionInput type
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -15,7 +15,11 @@
|
||||
*/
|
||||
|
||||
import { createExtensionDataRef } from './createExtensionDataRef';
|
||||
import { ExtensionInput, createExtensionInput } from './createExtensionInput';
|
||||
import {
|
||||
ExtensionInput,
|
||||
LegacyExtensionInput,
|
||||
createExtensionInput,
|
||||
} from './createExtensionInput';
|
||||
|
||||
const stringDataRef = createExtensionDataRef<string>().with({ id: 'str' });
|
||||
const numberDataRef = createExtensionDataRef<number>().with({ id: 'num' });
|
||||
@@ -33,25 +37,21 @@ describe('createExtensionInput', () => {
|
||||
|
||||
const x1: ExtensionInput<
|
||||
typeof stringDataRef | typeof numberDataRef,
|
||||
never,
|
||||
{ singleton: false; optional: false }
|
||||
> = input;
|
||||
// @ts-expect-error
|
||||
const x2: ExtensionInput<
|
||||
typeof stringDataRef,
|
||||
never,
|
||||
{ singleton: false; optional: false }
|
||||
> = input;
|
||||
// @ts-expect-error
|
||||
const x3: ExtensionInput<
|
||||
typeof stringDataRef | typeof numberDataRef,
|
||||
never,
|
||||
{ singleton: true; optional: false }
|
||||
> = input;
|
||||
// @ts-expect-error
|
||||
const x4: ExtensionInput<
|
||||
typeof stringDataRef | typeof numberDataRef,
|
||||
never,
|
||||
{ singleton: false; optional: true }
|
||||
> = input;
|
||||
|
||||
@@ -70,25 +70,21 @@ describe('createExtensionInput', () => {
|
||||
|
||||
const x1: ExtensionInput<
|
||||
typeof stringDataRef | typeof numberDataRef,
|
||||
never,
|
||||
{ singleton: true; optional: false }
|
||||
> = input;
|
||||
// @ts-expect-error
|
||||
const x2: ExtensionInput<
|
||||
typeof stringDataRef,
|
||||
never,
|
||||
{ singleton: true; optional: false }
|
||||
> = input;
|
||||
// @ts-expect-error
|
||||
const x3: ExtensionInput<
|
||||
typeof stringDataRef | typeof numberDataRef,
|
||||
never,
|
||||
{ singleton: false; optional: false }
|
||||
> = input;
|
||||
// @ts-expect-error
|
||||
const x4: ExtensionInput<
|
||||
typeof stringDataRef | typeof numberDataRef,
|
||||
never,
|
||||
{ singleton: false; optional: true }
|
||||
> = input;
|
||||
|
||||
@@ -108,25 +104,21 @@ describe('createExtensionInput', () => {
|
||||
|
||||
const x1: ExtensionInput<
|
||||
typeof stringDataRef | typeof numberDataRef,
|
||||
never,
|
||||
{ singleton: true; optional: true }
|
||||
> = input;
|
||||
// @ts-expect-error
|
||||
const x2: ExtensionInput<
|
||||
typeof stringDataRef,
|
||||
never,
|
||||
{ singleton: true; optional: true }
|
||||
> = input;
|
||||
// @ts-expect-error
|
||||
const x3: ExtensionInput<
|
||||
typeof stringDataRef | typeof numberDataRef,
|
||||
never,
|
||||
{ singleton: false; optional: false }
|
||||
> = input;
|
||||
// @ts-expect-error
|
||||
const x4: ExtensionInput<
|
||||
typeof stringDataRef | typeof numberDataRef,
|
||||
never,
|
||||
{ singleton: false; optional: true }
|
||||
> = input;
|
||||
|
||||
@@ -151,26 +143,22 @@ describe('createExtensionInput', () => {
|
||||
config: { singleton: false, optional: false },
|
||||
});
|
||||
|
||||
const x1: ExtensionInput<
|
||||
never,
|
||||
const x1: LegacyExtensionInput<
|
||||
{ str: typeof stringDataRef; num: typeof numberDataRef },
|
||||
{ singleton: false; optional: false }
|
||||
> = input;
|
||||
// @ts-expect-error
|
||||
const x2: ExtensionInput<
|
||||
never,
|
||||
const x2: LegacyExtensionInput<
|
||||
{ str: typeof numberDataRef; num: typeof stringDataRef }, // switched
|
||||
{ singleton: false; optional: false }
|
||||
> = input;
|
||||
// @ts-expect-error
|
||||
const x3: ExtensionInput<
|
||||
never,
|
||||
const x3: LegacyExtensionInput<
|
||||
{ str: typeof stringDataRef; num: typeof numberDataRef },
|
||||
{ singleton: true; optional: false }
|
||||
> = input;
|
||||
// @ts-expect-error
|
||||
const x4: ExtensionInput<
|
||||
never,
|
||||
const x4: LegacyExtensionInput<
|
||||
{ str: typeof stringDataRef; num: typeof numberDataRef },
|
||||
{ singleton: false; optional: true }
|
||||
> = input;
|
||||
|
||||
@@ -20,11 +20,23 @@ import { ExtensionDataRef } from './createExtensionDataRef';
|
||||
/** @public */
|
||||
export interface ExtensionInput<
|
||||
TExtensionData extends ExtensionDataRef<unknown, string, { optional?: true }>,
|
||||
TConfig extends { singleton: boolean; optional: boolean },
|
||||
> {
|
||||
$$type: '@backstage/ExtensionInput';
|
||||
extensionData: TExtensionData;
|
||||
config: TConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @deprecated This type will be removed. Use `ExtensionInput` instead.
|
||||
*/
|
||||
export interface LegacyExtensionInput<
|
||||
TExtensionDataMap extends AnyExtensionDataMap,
|
||||
TConfig extends { singleton: boolean; optional: boolean },
|
||||
> {
|
||||
$$type: '@backstage/ExtensionInput';
|
||||
extensionData: TExtensionData | TExtensionDataMap;
|
||||
extensionData: TExtensionDataMap;
|
||||
config: TConfig;
|
||||
}
|
||||
|
||||
@@ -38,8 +50,7 @@ export function createExtensionInput<
|
||||
>(
|
||||
extensionData: TExtensionDataMap,
|
||||
config?: TConfig,
|
||||
): ExtensionInput<
|
||||
never,
|
||||
): LegacyExtensionInput<
|
||||
TExtensionDataMap,
|
||||
{
|
||||
singleton: TConfig['singleton'] extends true ? true : false;
|
||||
@@ -55,7 +66,6 @@ export function createExtensionInput<
|
||||
config?: TConfig,
|
||||
): ExtensionInput<
|
||||
UExtensionData,
|
||||
never,
|
||||
{
|
||||
singleton: TConfig['singleton'] extends true ? true : false;
|
||||
optional: TConfig['optional'] extends true ? true : false;
|
||||
@@ -68,14 +78,21 @@ export function createExtensionInput<
|
||||
>(
|
||||
extensionData: TExtensionData,
|
||||
config?: TConfig,
|
||||
): ExtensionInput<
|
||||
TExtensionData,
|
||||
TExtensionDataMap,
|
||||
{
|
||||
singleton: TConfig['singleton'] extends true ? true : false;
|
||||
optional: TConfig['optional'] extends true ? true : false;
|
||||
}
|
||||
> {
|
||||
):
|
||||
| LegacyExtensionInput<
|
||||
TExtensionDataMap,
|
||||
{
|
||||
singleton: TConfig['singleton'] extends true ? true : false;
|
||||
optional: TConfig['optional'] extends true ? true : false;
|
||||
}
|
||||
>
|
||||
| ExtensionInput<
|
||||
TExtensionData,
|
||||
{
|
||||
singleton: TConfig['singleton'] extends true ? true : false;
|
||||
optional: TConfig['optional'] extends true ? true : false;
|
||||
}
|
||||
> {
|
||||
if (Array.isArray(extensionData)) {
|
||||
const seen = new Set();
|
||||
const duplicates = [];
|
||||
|
||||
Reference in New Issue
Block a user