frontend-plugin-api: store extension ID parts in an object type parameter

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-08-15 22:44:38 +02:00
parent 4490d733b5
commit d52ed1a562
21 changed files with 622 additions and 376 deletions
@@ -218,14 +218,20 @@ export interface ExtensionDefinition<
{ optional: boolean; singleton: boolean }
>;
} = {},
TKind extends string | undefined = string | undefined,
TNamespace extends string | undefined = string | undefined,
TName extends string | undefined = string | undefined,
TIdParts extends {
kind?: string;
namespace?: string;
name?: string;
} = {
kind?: string;
namespace?: string;
name?: string;
},
> {
$$type: '@backstage/ExtensionDefinition';
readonly kind?: TKind;
readonly namespace?: TNamespace;
readonly name?: TName;
readonly kind?: TIdParts['kind'];
readonly namespace?: TIdParts['namespace'];
readonly name?: TIdParts['name'];
readonly attachTo: { id: string; input: string };
readonly disabled: boolean;
readonly configSchema?: PortableSchema<TConfig, TConfigInput>;
@@ -292,9 +298,7 @@ export interface ExtensionDefinition<
TConfigInput,
AnyExtensionDataRef extends UNewOutput ? UOutput : UNewOutput,
TInputs & TExtraInputs,
TKind,
TNamespace,
TName
TIdParts
>;
}
@@ -309,18 +313,16 @@ export type InternalExtensionDefinition<
{ optional: boolean; singleton: boolean }
>;
} = {},
TKind extends string | undefined = string | undefined,
TNamespace extends string | undefined = string | undefined,
TName extends string | undefined = string | undefined,
> = ExtensionDefinition<
TConfig,
TConfigInput,
UOutput,
TInputs,
TKind,
TNamespace,
TName
> &
TIdParts extends {
kind?: string;
namespace?: string;
name?: string;
} = {
kind?: string;
namespace?: string;
name?: string;
},
> = ExtensionDefinition<TConfig, TConfigInput, UOutput, TInputs, TIdParts> &
(
| {
readonly version: 'v1';
@@ -411,9 +413,11 @@ export function createExtension<
>,
UOutput,
TInputs,
string | undefined extends TKind ? undefined : TKind,
string | undefined extends TNamespace ? undefined : TNamespace,
string | undefined extends TName ? undefined : TName
{
kind: string | undefined extends TKind ? undefined : TKind;
namespace: string | undefined extends TNamespace ? undefined : TNamespace;
name: string | undefined extends TName ? undefined : TName;
}
>;
/**
* @public
@@ -482,9 +486,11 @@ export function createExtension<
>),
UOutput,
TInputs,
TKind,
TNamespace,
TName
{
kind: TKind;
namespace: TNamespace;
name: TName;
}
> {
if ('configSchema' in options && 'config' in options) {
throw new Error(`Cannot provide both configSchema and config.schema`);
@@ -596,9 +602,11 @@ export function createExtension<
>,
AnyExtensionDataRef extends UNewOutput ? UOutput : UNewOutput,
TInputs & TExtraInputs,
TKind,
TNamespace,
TName
{
kind: TKind;
namespace: TNamespace;
name: TName;
}
> => {
if (!Array.isArray(options.output)) {
throw new Error(
@@ -697,8 +705,10 @@ export function createExtension<
>),
UOutput,
TInputs,
TKind,
TNamespace,
TName
{
kind: TKind;
namespace: TNamespace;
name: TName;
}
>;
}
@@ -85,9 +85,11 @@ export type CreateExtensionBlueprintOptions<
* @public
*/
export interface ExtensionBlueprint<
TKind extends string,
TNamespace extends string | undefined,
TName extends string | undefined,
TIdParts extends {
kind: string;
namespace?: string;
name?: string;
},
TParams,
UOutput extends AnyExtensionDataRef,
TInputs extends {
@@ -116,9 +118,13 @@ export interface ExtensionBlueprint<
TConfigInput,
UOutput,
TInputs,
TKind,
string | undefined extends TNewNamespace ? TNamespace : TNewNamespace,
string | undefined extends TNewName ? TName : TNewName
{
kind: TIdParts['kind'];
namespace: string | undefined extends TNewNamespace
? TIdParts['namespace']
: TNewNamespace;
name: string | undefined extends TNewName ? TIdParts['name'] : TNewName;
}
>;
/**
@@ -195,9 +201,13 @@ export interface ExtensionBlueprint<
TConfigInput,
AnyExtensionDataRef extends UNewOutput ? UOutput : UNewOutput,
TInputs & TExtraInputs,
TKind,
string | undefined extends TNewNamespace ? TNamespace : TNewNamespace,
string | undefined extends TNewName ? TName : TNewName
{
kind: TIdParts['kind'];
namespace: string | undefined extends TNewNamespace
? TIdParts['namespace']
: TNewNamespace;
name: string | undefined extends TNewName ? TIdParts['name'] : TNewName;
}
>;
}
@@ -422,9 +432,11 @@ export function createExtensionBlueprint<
TDataRefs
>,
): ExtensionBlueprint<
TKind,
TNamespace,
TName,
{
kind: TKind;
namespace: TNamespace;
name: TName;
},
TParams,
UOutput,
string extends keyof TInputs ? {} : TInputs,
@@ -441,9 +453,11 @@ export function createExtensionBlueprint<
TDataRefs
> {
return new ExtensionBlueprintImpl(options) as ExtensionBlueprint<
TKind,
TNamespace,
TName,
{
kind: TKind;
namespace: TNamespace;
name: TName;
},
TParams,
UOutput,
string extends keyof TInputs ? {} : TInputs,
@@ -108,7 +108,13 @@ describe('ResolveExtensionId', () => {
TKind extends string | undefined,
TNamespace extends string | undefined,
TName extends string | undefined,
> = ExtensionDefinition<any, any, any, any, TKind, TNamespace, TName>;
> = ExtensionDefinition<
any,
any,
any,
any,
{ kind: TKind; namespace: TNamespace; name: TName }
>;
const id1: 'k:ns' = {} as ResolveExtensionId<
NamedExtension<'k', 'ns', undefined>,
@@ -103,9 +103,11 @@ export type ResolveExtensionId<
any,
any,
any,
infer IKind,
infer INamespace,
infer IName
{
kind: infer IKind extends string | undefined;
namespace: infer INamespace extends string | undefined;
name: infer IName extends string | undefined;
}
>
? [string | undefined] extends [IKind | INamespace | IName]
? never