/
schema-shim.ts
31 lines (28 loc) · 1.01 KB
/
schema-shim.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { Context, LegacyProcessor, ValidatedJobConfig } from '../../interfaces';
import ConvictSchema from '../convict-schema';
import { SchemaModule } from '../interfaces';
export default function schemaShim<S extends Record<string, any>>(
legacy: LegacyProcessor
): SchemaModule {
return {
Schema: class LegacySchemaShim extends ConvictSchema<S> {
// @ts-expect-error
validate(inputConfig: any) {
const opConfig = super.validate(inputConfig);
if (legacy.selfValidation) {
// @ts-expect-error
legacy.selfValidation(opConfig);
}
return opConfig;
}
validateJob(job: ValidatedJobConfig): void {
if (legacy.crossValidation) {
legacy.crossValidation(job, this.context.sysconfig);
}
}
build(context?: Context) {
return legacy.schema(context);
}
}
};
}