export function validateSchema()

in src/client/src/schema/validation/validate_schema.ts [18:30]


export function validateSchema<Payload>(sourceName: string, validator: Type<Payload>, payload: Payload): void {
  // Run io-ts validation to the event
  const result = validator.decode(payload);

  either.mapLeft(result, (validationErrors) => {
    const humanFriendlyErrors = validationErrors
      .map((err) => `[${getFullPathKey(err.context)}]: ${err.message ?? readableContext(err.context)}`)
      .filter((errMsg, idx, listOfErrMsgs) => listOfErrMsgs.indexOf(errMsg, idx + 1) === -1);
    throw new Error(
      `Failed to validate payload coming from "${sourceName}":\n\t- ${humanFriendlyErrors.join('\n\t- ')}`
    );
  });
}