diff --git a/packages/frontend-plugin-api/src/wiring/createExtension.test.ts b/packages/frontend-plugin-api/src/wiring/createExtension.test.ts index ab6a6c19a5..8da3504434 100644 --- a/packages/frontend-plugin-api/src/wiring/createExtension.test.ts +++ b/packages/frontend-plugin-api/src/wiring/createExtension.test.ts @@ -561,4 +561,35 @@ describe('createExtension', () => { }), ).toMatchObject({ version: 'v2' }); }); + + describe('overrides', () => { + it('should allow overriding of the default factory', () => { + const testExtension = createExtension({ + namespace: 'test', + attachTo: { id: 'root', input: 'blob' }, + output: [stringDataRef], + config: { + schema: { + foo: z => z.string().optional(), + }, + }, + factory() { + return [stringDataRef('default')]; + }, + }); + + testExtension.override({ + config: { + schema: { + bar: z => z.string().optional(), + }, + }, + factory(_, { config }) { + return [stringDataRef(config.foo ?? config.bar ?? 'default')]; + }, + }); + + expect(true).toBe(true); + }); + }); }); diff --git a/packages/frontend-plugin-api/src/wiring/createExtension.ts b/packages/frontend-plugin-api/src/wiring/createExtension.ts index 6684323b51..f1db16b4d2 100644 --- a/packages/frontend-plugin-api/src/wiring/createExtension.ts +++ b/packages/frontend-plugin-api/src/wiring/createExtension.ts @@ -247,6 +247,10 @@ export type OverrideExtensionOptions< TConfigInput, TConfigSchema extends { [key: string]: (zImpl: typeof z) => z.ZodType }, UFactoryOutput extends ExtensionDataValue, + TConfigSchemaOverrides extends { + [key: string]: (zImpl: typeof z) => z.ZodType; + }, + UOutputOverrides extends AnyExtensionDataRef = UOutput, > = { kind?: string; namespace?: string; @@ -254,11 +258,11 @@ export type OverrideExtensionOptions< attachTo?: { id: string; input: string }; disabled?: boolean; inputs?: TInputs; - output: Array; + output?: Array; /** @deprecated - use `config.schema` instead */ configSchema?: PortableSchema; config?: { - schema: TConfigSchema; + schema: TConfigSchemaOverrides; }; factory?( originalFactory: (context?: { @@ -273,6 +277,10 @@ export type OverrideExtensionOptions< (string extends keyof TConfigSchema ? {} : { + [key in keyof TConfigSchemaOverrides]: z.infer< + ReturnType + >; + } & { [key in keyof TConfigSchema]: z.infer< ReturnType >; @@ -280,7 +288,7 @@ export type OverrideExtensionOptions< inputs: Expand>; }, ): Iterable; -} & VerifyExtensionFactoryOutput; +} & VerifyExtensionFactoryOutput; /** @public */ export type OverridableExtension< @@ -296,14 +304,19 @@ export type OverridableExtension< TConfigSchema extends { [key: string]: (zImpl: typeof z) => z.ZodType }, UFactoryOutput extends ExtensionDataValue, > = { - override( + override< + TConfigSchemaOverrides extends { + [key in string]: (zImpl: typeof z) => z.ZodType; + }, + >( options: OverrideExtensionOptions< UOutput, TInputs, TConfig, TConfigInput, TConfigSchema, - UFactoryOutput + UFactoryOutput, + TConfigSchemaOverrides >, ): ExtensionDefinition; }; @@ -540,6 +553,9 @@ export function createExtension< parts.push(`attachTo=${options.attachTo.id}@${options.attachTo.input}`); return `ExtensionDefinition{${parts.join(',')}}`; }, + override() { + // todo(blam): implement. + }, } as InternalExtensionDefinition< TConfig & (string extends keyof TConfigSchema