frontend-internal: switch opaqueType.createInstance to decorate + select version

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-09-11 14:04:39 +02:00
parent 4cfacd936b
commit bb0ea523b9
3 changed files with 102 additions and 150 deletions
@@ -366,6 +366,26 @@ export function createExtension<
namespace: string | undefined extends TNamespace ? undefined : TNamespace;
name: string | undefined extends TName ? undefined : TName;
}> {
type T = {
config: string extends keyof TConfigSchema
? {}
: {
[key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>>;
};
configInput: string extends keyof TConfigSchema
? {}
: z.input<
z.ZodObject<{
[key in keyof TConfigSchema]: ReturnType<TConfigSchema[key]>;
}>
>;
output: UOutput;
inputs: TInputs;
kind: string | undefined extends TKind ? undefined : TKind;
namespace: string | undefined extends TNamespace ? undefined : TNamespace;
name: string | undefined extends TName ? undefined : TName;
};
const schemaDeclaration = options.config?.schema;
const configSchema =
schemaDeclaration &&
@@ -377,30 +397,8 @@ export function createExtension<
),
);
return OpaqueExtensionDefinition.createInstance({
$$type: '@backstage/ExtensionDefinition',
version: 'v2',
T: undefined as unknown as {
config: string extends keyof TConfigSchema
? {}
: {
[key in keyof TConfigSchema]: z.infer<
ReturnType<TConfigSchema[key]>
>;
};
configInput: string extends keyof TConfigSchema
? {}
: z.input<
z.ZodObject<{
[key in keyof TConfigSchema]: ReturnType<TConfigSchema[key]>;
}>
>;
output: UOutput;
inputs: TInputs;
kind: string | undefined extends TKind ? undefined : TKind;
namespace: string | undefined extends TNamespace ? undefined : TNamespace;
name: string | undefined extends TName ? undefined : TName;
},
return OpaqueExtensionDefinition.createInstance('v2', {
T: undefined as unknown as T,
kind: options.kind,
namespace: options.namespace,
name: options.name,
@@ -512,5 +510,5 @@ export function createExtension<
},
}) as ExtensionDefinition<any>;
},
});
}) as ExtensionDefinition<T>;
}