chore: overriding of config seems to work in typescript
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -247,6 +247,10 @@ export type OverrideExtensionOptions<
|
||||
TConfigInput,
|
||||
TConfigSchema extends { [key: string]: (zImpl: typeof z) => z.ZodType },
|
||||
UFactoryOutput extends ExtensionDataValue<any, any>,
|
||||
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<UOutput>;
|
||||
output?: Array<UOutputOverrides>;
|
||||
/** @deprecated - use `config.schema` instead */
|
||||
configSchema?: PortableSchema<TConfig, TConfigInput>;
|
||||
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<TConfigSchemaOverrides[key]>
|
||||
>;
|
||||
} & {
|
||||
[key in keyof TConfigSchema]: z.infer<
|
||||
ReturnType<TConfigSchema[key]>
|
||||
>;
|
||||
@@ -280,7 +288,7 @@ export type OverrideExtensionOptions<
|
||||
inputs: Expand<ResolvedExtensionInputs<TInputs>>;
|
||||
},
|
||||
): Iterable<UFactoryOutput>;
|
||||
} & VerifyExtensionFactoryOutput<UOutput, UFactoryOutput>;
|
||||
} & VerifyExtensionFactoryOutput<UOutput & UOutputOverrides, UFactoryOutput>;
|
||||
|
||||
/** @public */
|
||||
export type OverridableExtension<
|
||||
@@ -296,14 +304,19 @@ export type OverridableExtension<
|
||||
TConfigSchema extends { [key: string]: (zImpl: typeof z) => z.ZodType },
|
||||
UFactoryOutput extends ExtensionDataValue<any, any>,
|
||||
> = {
|
||||
override(
|
||||
override<
|
||||
TConfigSchemaOverrides extends {
|
||||
[key in string]: (zImpl: typeof z) => z.ZodType;
|
||||
},
|
||||
>(
|
||||
options: OverrideExtensionOptions<
|
||||
UOutput,
|
||||
TInputs,
|
||||
TConfig,
|
||||
TConfigInput,
|
||||
TConfigSchema,
|
||||
UFactoryOutput
|
||||
UFactoryOutput,
|
||||
TConfigSchemaOverrides
|
||||
>,
|
||||
): ExtensionDefinition<TConfig, TConfigInput>;
|
||||
};
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user