From 760d99b138c916bcb20f1bb372390ff2c4fdd7d5 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 26 Jul 2024 17:03:13 +0200 Subject: [PATCH] frontend-plugin-api: refactor to use LegacyExtensionInput type Signed-off-by: Patrik Oldsberg --- .../src/wiring/createExtensionInput.test.ts | 30 ++++---------- .../src/wiring/createExtensionInput.ts | 41 +++++++++++++------ 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/packages/frontend-plugin-api/src/wiring/createExtensionInput.test.ts b/packages/frontend-plugin-api/src/wiring/createExtensionInput.test.ts index 0025789c73..e401adc675 100644 --- a/packages/frontend-plugin-api/src/wiring/createExtensionInput.test.ts +++ b/packages/frontend-plugin-api/src/wiring/createExtensionInput.test.ts @@ -15,7 +15,11 @@ */ import { createExtensionDataRef } from './createExtensionDataRef'; -import { ExtensionInput, createExtensionInput } from './createExtensionInput'; +import { + ExtensionInput, + LegacyExtensionInput, + createExtensionInput, +} from './createExtensionInput'; const stringDataRef = createExtensionDataRef().with({ id: 'str' }); const numberDataRef = createExtensionDataRef().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; diff --git a/packages/frontend-plugin-api/src/wiring/createExtensionInput.ts b/packages/frontend-plugin-api/src/wiring/createExtensionInput.ts index 3c09fcdaeb..5627bdecc2 100644 --- a/packages/frontend-plugin-api/src/wiring/createExtensionInput.ts +++ b/packages/frontend-plugin-api/src/wiring/createExtensionInput.ts @@ -20,11 +20,23 @@ import { ExtensionDataRef } from './createExtensionDataRef'; /** @public */ export interface ExtensionInput< TExtensionData extends ExtensionDataRef, + 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 = [];