import { isThemisSchema } from '~/data/helpers/is-themis-schema'; import { ValidationObjectSchema } from '~/domain/entities'; import { MakeSchema } from '~/domain/protocols'; import { IThemisMethods } from '~/domain/themis/themis-methods'; export class ThemisSchemaAdapter implements IThemisMethods.Schema { constructor(private readonly makeObjectSchema: MakeSchema<'object'>) {} /** * Creates a validation schema * * @param {ValidationObjectSchema|ValidationObjectSchema.Shape} shape */ schema = (shape: ValidationObjectSchema | ValidationObjectSchema.Shape): ValidationObjectSchema => { if (isThemisSchema(shape)) { return shape; } return this.makeObjectSchema.make({ required: true, shape, }); }; }