Skip to content

Cast from an async sanitizer #42

Description

@getlarge

It seems it is not yet possible to use an async sanitizer function inside cast, do i mistake ?

If not, would it be possible to add support for this ?

Example

Sanitizer

import { Result } from '@restless/sanitizers';

export const asCertificate = async (value, path: string) => {
  const errors = (await validate(value)) as any[];
  
  if (Object.keys(errors).length) {
    const resultError = flatten(
      Object.values(errors).map((error) => {
        return error.map((error) => ({
          path: `${path}${error.path}`,
          expected: error.expected || '',
        }));
      })
    );

    console.log(resultError);
    return Result.error(resultError);
  }
  return Result.ok(value as Certificate);
};

Cast

import {cast} from '@restless/sanitizers';
import {asCertificate} from './somewhere';

const certificate = {};
const value = cast(certificate, asCertificate);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions