frontend-plugin-api: refactor to use symbol to pass param overrides
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -33,6 +33,12 @@ import { z } from 'zod';
|
||||
import { createSchemaFromZod } from '../schema/createSchemaFromZod';
|
||||
import { OpaqueExtensionDefinition } from '@internal/frontend';
|
||||
|
||||
/**
|
||||
* This symbol is used to pass parameter overrides from the extension override to the blueprint factory
|
||||
* @internal
|
||||
*/
|
||||
export const ctxParamsSymbol = Symbol('params');
|
||||
|
||||
/**
|
||||
* Convert a single extension input into a matching resolved input.
|
||||
* @public
|
||||
@@ -484,11 +490,8 @@ export function createExtension<
|
||||
apis,
|
||||
config: config as any,
|
||||
inputs: inputs as any,
|
||||
params: overrideOptions.params,
|
||||
// TODO(Rugvip): This is a bit of a hack to send the params
|
||||
// through to the blueprint factory, might be that there's a
|
||||
// better way to do this
|
||||
} as Parameters<typeof options.factory>[0]);
|
||||
[ctxParamsSymbol as any]: overrideOptions.params,
|
||||
});
|
||||
}
|
||||
const parentResult = overrideOptions.factory(
|
||||
(innerContext): ExtensionDataContainer<UOutput> => {
|
||||
@@ -502,9 +505,8 @@ export function createExtension<
|
||||
inputs,
|
||||
innerContext?.inputs,
|
||||
) as any,
|
||||
params: innerContext?.params,
|
||||
// TODO(Rugvip): Same as above
|
||||
} as Parameters<typeof options.factory>[0]) as Iterable<any>,
|
||||
[ctxParamsSymbol as any]: innerContext?.params,
|
||||
}) as Iterable<any>,
|
||||
options.output,
|
||||
);
|
||||
},
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
ResolvedExtensionInputs,
|
||||
VerifyExtensionFactoryOutput,
|
||||
createExtension,
|
||||
ctxParamsSymbol,
|
||||
} from './createExtension';
|
||||
import { z } from 'zod';
|
||||
import { ExtensionInput } from './createExtensionInput';
|
||||
@@ -482,10 +483,7 @@ export function createExtensionBlueprint<
|
||||
config: options.config,
|
||||
factory: ctx =>
|
||||
options.factory(
|
||||
// TODO(Rugvip): The `ctx` here might actually have a `params` key
|
||||
// when the extension has been overridden. It's currently hidden in
|
||||
// the types and there might be a better way to do this.
|
||||
{ ...args.params, ...(ctx as any).params },
|
||||
{ ...args.params, ...(ctx as any)[ctxParamsSymbol] },
|
||||
ctx,
|
||||
) as Iterable<ExtensionDataValue<any, any>>,
|
||||
}) as ExtensionDefinition;
|
||||
@@ -514,8 +512,7 @@ export function createExtensionBlueprint<
|
||||
(innerParams, innerContext) => {
|
||||
return createExtensionDataContainer<UOutput>(
|
||||
options.factory(
|
||||
// TODO(Rugvip): Same as ctx.params from .make
|
||||
{ ...innerParams, ...(ctx as any).params },
|
||||
{ ...innerParams, ...(ctx as any)[ctxParamsSymbol] },
|
||||
{
|
||||
apis,
|
||||
node,
|
||||
|
||||
Reference in New Issue
Block a user