diff --git a/packages/frontend-plugin-api/src/wiring/createExtension.test.ts b/packages/frontend-plugin-api/src/wiring/createExtension.test.ts index 7f27df4947..e38a24cebe 100644 --- a/packages/frontend-plugin-api/src/wiring/createExtension.test.ts +++ b/packages/frontend-plugin-api/src/wiring/createExtension.test.ts @@ -599,7 +599,9 @@ describe('createExtension', () => { attachTo: { id: 'root', input: 'blob' }, output: [stringDataRef], inputs: { - test: createExtensionInput([stringDataRef], { singleton: true }), + test: createExtensionInput([stringDataRef], { + singleton: true, + }), }, config: { schema: { @@ -641,5 +643,31 @@ describe('createExtension', () => { expect(true).toBe(true); }); + + it('should allow overriding the factory function and calling the original 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({ + factory(originalFactory) { + const response = originalFactory(); + + const foo: string = response.get(stringDataRef); + + return [stringDataRef(`foo-${foo}-override`)]; + }, + }); + }); }); }); diff --git a/packages/frontend-plugin-api/src/wiring/createExtension.ts b/packages/frontend-plugin-api/src/wiring/createExtension.ts index 3ec674f75f..678ce4e042 100644 --- a/packages/frontend-plugin-api/src/wiring/createExtension.ts +++ b/packages/frontend-plugin-api/src/wiring/createExtension.ts @@ -274,6 +274,8 @@ export type OverrideExtensionOptions< [key in keyof TConfigSchema]: z.infer>; }; inputs?: Expand>; + // todo(blam): Think this is better as a DataContainer instead + // should probably update that everywhere. }) => Iterable, context: { node: AppNode; @@ -292,8 +294,11 @@ export type OverrideExtensionOptions< inputs: Expand>; }, ): Iterable; - // todo(blam): need to verify that the outputs are meged properly. -} & VerifyExtensionFactoryOutput; + // todo(blam): need to verify that the outputs are merged and verified properly. +} & VerifyExtensionFactoryOutput< + UOutput & UFactoryOverrideOutput, + UFactoryOverrideOutput +>; /** @public */ export type OverridableExtension<