diff --git a/packages/frontend-plugin-api/src/wiring/createExtension.test.ts b/packages/frontend-plugin-api/src/wiring/createExtension.test.ts index 8da3504434..7f27df4947 100644 --- a/packages/frontend-plugin-api/src/wiring/createExtension.test.ts +++ b/packages/frontend-plugin-api/src/wiring/createExtension.test.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { coreExtensionData } from './coreExtensionData'; import { createExtension } from './createExtension'; import { createExtensionDataRef } from './createExtensionDataRef'; import { createExtensionInput } from './createExtensionInput'; @@ -563,7 +564,7 @@ describe('createExtension', () => { }); describe('overrides', () => { - it('should allow overriding of the default factory', () => { + it('should allow overriding of config and merging', () => { const testExtension = createExtension({ namespace: 'test', attachTo: { id: 'root', input: 'blob' }, @@ -591,5 +592,54 @@ describe('createExtension', () => { expect(true).toBe(true); }); + + it('should allow overriding of outputs', () => { + const testExtension = createExtension({ + namespace: 'test', + attachTo: { id: 'root', input: 'blob' }, + output: [stringDataRef], + inputs: { + test: createExtensionInput([stringDataRef], { singleton: true }), + }, + config: { + schema: { + foo: z => z.string().optional(), + }, + }, + factory({ inputs }) { + return [stringDataRef(inputs.test.get(stringDataRef))]; + }, + }); + + const override = testExtension.override({ + output: [numberDataRef], + factory(_, { inputs }) { + return [ + numberDataRef(inputs.test.get(stringDataRef).length), + stringDataRef('default'), + ]; + }, + }); + + // @ts-expect-error - should fail as the string output from previous is not provided + const override2 = testExtension.override({ + output: [numberDataRef], + factory(_, { inputs }) { + return [numberDataRef(inputs.test.get(stringDataRef).length)]; + }, + }); + + // @ts-expect-error - this should fail because string output should be merged? + const override3 = testExtension.override({ + output: [numberDataRef], + factory(_, { inputs }) { + return [stringDataRef(inputs.test.get(stringDataRef))]; + }, + }); + + unused(override, override2, override3); + + 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 f1db16b4d2..3ec674f75f 100644 --- a/packages/frontend-plugin-api/src/wiring/createExtension.ts +++ b/packages/frontend-plugin-api/src/wiring/createExtension.ts @@ -246,11 +246,12 @@ export type OverrideExtensionOptions< TConfig, TConfigInput, TConfigSchema extends { [key: string]: (zImpl: typeof z) => z.ZodType }, - UFactoryOutput extends ExtensionDataValue, + UOriginalFactoryOutput extends ExtensionDataValue, TConfigSchemaOverrides extends { [key: string]: (zImpl: typeof z) => z.ZodType; }, - UOutputOverrides extends AnyExtensionDataRef = UOutput, + UOutputOverrides extends AnyExtensionDataRef, + UFactoryOverrideOutput extends ExtensionDataValue, > = { kind?: string; namespace?: string; @@ -262,7 +263,10 @@ export type OverrideExtensionOptions< /** @deprecated - use `config.schema` instead */ configSchema?: PortableSchema; config?: { - schema: TConfigSchemaOverrides; + schema: TConfigSchemaOverrides & { + [KName in keyof TConfig]?: `Error: Config key '${KName & + string}' is already defined in parent schema`; + }; }; factory?( originalFactory: (context?: { @@ -270,7 +274,7 @@ export type OverrideExtensionOptions< [key in keyof TConfigSchema]: z.infer>; }; inputs?: Expand>; - }) => Iterable>, + }) => Iterable, context: { node: AppNode; config: TConfig & @@ -287,8 +291,9 @@ export type OverrideExtensionOptions< }); inputs: Expand>; }, - ): Iterable; -} & VerifyExtensionFactoryOutput; + ): Iterable; + // todo(blam): need to verify that the outputs are meged properly. +} & VerifyExtensionFactoryOutput; /** @public */ export type OverridableExtension< @@ -308,6 +313,8 @@ export type OverridableExtension< TConfigSchemaOverrides extends { [key in string]: (zImpl: typeof z) => z.ZodType; }, + UOutputOverrides extends AnyExtensionDataRef, + UFactoryOverrideOutput extends ExtensionDataValue, >( options: OverrideExtensionOptions< UOutput, @@ -316,7 +323,9 @@ export type OverridableExtension< TConfigInput, TConfigSchema, UFactoryOutput, - TConfigSchemaOverrides + TConfigSchemaOverrides, + UOutputOverrides, + UFactoryOverrideOutput >, ): ExtensionDefinition; };