chore: added some more overrides part
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -246,11 +246,12 @@ export type OverrideExtensionOptions<
|
||||
TConfig,
|
||||
TConfigInput,
|
||||
TConfigSchema extends { [key: string]: (zImpl: typeof z) => z.ZodType },
|
||||
UFactoryOutput extends ExtensionDataValue<any, any>,
|
||||
UOriginalFactoryOutput extends ExtensionDataValue<any, any>,
|
||||
TConfigSchemaOverrides extends {
|
||||
[key: string]: (zImpl: typeof z) => z.ZodType;
|
||||
},
|
||||
UOutputOverrides extends AnyExtensionDataRef = UOutput,
|
||||
UOutputOverrides extends AnyExtensionDataRef,
|
||||
UFactoryOverrideOutput extends ExtensionDataValue<any, any>,
|
||||
> = {
|
||||
kind?: string;
|
||||
namespace?: string;
|
||||
@@ -262,7 +263,10 @@ export type OverrideExtensionOptions<
|
||||
/** @deprecated - use `config.schema` instead */
|
||||
configSchema?: PortableSchema<TConfig, TConfigInput>;
|
||||
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<ReturnType<TConfigSchema[key]>>;
|
||||
};
|
||||
inputs?: Expand<ResolvedExtensionInputs<TInputs>>;
|
||||
}) => Iterable<ExtensionDataRefToValue<UOutput>>,
|
||||
}) => Iterable<UOriginalFactoryOutput>,
|
||||
context: {
|
||||
node: AppNode;
|
||||
config: TConfig &
|
||||
@@ -287,8 +291,9 @@ export type OverrideExtensionOptions<
|
||||
});
|
||||
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
|
||||
},
|
||||
): Iterable<UFactoryOutput>;
|
||||
} & VerifyExtensionFactoryOutput<UOutput & UOutputOverrides, UFactoryOutput>;
|
||||
): Iterable<UFactoryOverrideOutput>;
|
||||
// todo(blam): need to verify that the outputs are meged properly.
|
||||
} & VerifyExtensionFactoryOutput<UOutput, UFactoryOverrideOutput>;
|
||||
|
||||
/** @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<any, any>,
|
||||
>(
|
||||
options: OverrideExtensionOptions<
|
||||
UOutput,
|
||||
@@ -316,7 +323,9 @@ export type OverridableExtension<
|
||||
TConfigInput,
|
||||
TConfigSchema,
|
||||
UFactoryOutput,
|
||||
TConfigSchemaOverrides
|
||||
TConfigSchemaOverrides,
|
||||
UOutputOverrides,
|
||||
UFactoryOverrideOutput
|
||||
>,
|
||||
): ExtensionDefinition<TConfig, TConfigInput>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user