Giter VIP home page Giter VIP logo

restless's People

Contributors

dmaretskyi avatar marekkirejczyk avatar rzadp avatar sajma27 avatar sz-piotr avatar xitronix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

restless's Issues

What is "path" argument?

I just ran into this library, while looking for a library to do data sanitization for one of my apps. It looks very promising. I just have one question though. I noticed that each "as" function has a second "path" argument. What exactly is this argument? Or, what do I pass in to it? The docs in the README do not really go over the arguments.

Thanks.

Add asAnyOf

asAnyOf takes 2 or more sanitizers and returns a sanitizer that goes through them and returns the first that succeeds.

Add asLiteral

const asLiteral = <T extends string> (literal: T) =>
  asChecked(asString, value => value === literal) as Sanitizer<T>

Add asInteger

It's very common to expect integers in URL path, e.g. /users/123 to access user by Id.
With using asNumber sanitizer, request /users/3.14 would be still valid while not being a correct Id.

Restless wishlist

This is a list of all "nice-to-have" features for Restless:

  • Basic auth
  • Streaming responses
  • Support for rendering templates as in express
  • Integration with third-party middleware libraries

asyncHandler, second callback argument name 'b'- types of return value

In my personal project I have this usage of restless solutions:
my point of Route, method post:

route.post('/login', asyncHandler( sanitize({
    body: asObject({
      username: asString,
      password: asString,
    })
  }),
  (reqData) => {
  const {username, password} = reqData.body;
  findUser('user', username)
    .then((user: User) => {
      if(user.password === password) {
        responseOf(user, 200)
      }
      else {
        responseOf('user not found', 400)
      }
    })
    .catch(err => {
      responseOf('internal server error', 500)
    })
  }
));

TypeScript compiler error:
Type void is not assignable to type ResponseFunction | Promise<ResponseFunction>

When I change code to marked returns type like belowe
... function(reqData): ResponseFunction | Promise<ResponseFunction> { ...
I have another ts compiler warrning

Does anyone have any idea how to solve this issue?

Cast from an async sanitizer

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);

Short circuit responses

It would be nice to have short circuiting for responses. Current implementation idea is to throw a custom class.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.