@@ -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`)];
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -274,6 +274,8 @@ export type OverrideExtensionOptions<
|
||||
[key in keyof TConfigSchema]: z.infer<ReturnType<TConfigSchema[key]>>;
|
||||
};
|
||||
inputs?: Expand<ResolvedExtensionInputs<TInputs>>;
|
||||
// todo(blam): Think this is better as a DataContainer instead
|
||||
// should probably update that everywhere.
|
||||
}) => Iterable<UOriginalFactoryOutput>,
|
||||
context: {
|
||||
node: AppNode;
|
||||
@@ -292,8 +294,11 @@ export type OverrideExtensionOptions<
|
||||
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
|
||||
},
|
||||
): Iterable<UFactoryOverrideOutput>;
|
||||
// todo(blam): need to verify that the outputs are meged properly.
|
||||
} & VerifyExtensionFactoryOutput<UOutput, UFactoryOverrideOutput>;
|
||||
// todo(blam): need to verify that the outputs are merged and verified properly.
|
||||
} & VerifyExtensionFactoryOutput<
|
||||
UOutput & UFactoryOverrideOutput,
|
||||
UFactoryOverrideOutput
|
||||
>;
|
||||
|
||||
/** @public */
|
||||
export type OverridableExtension<
|
||||
|
||||
Reference in New Issue
Block a user