Giter Site home page Giter Site logo

dataffy / themis Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 0.0 565 KB

Themis is a validation and processing library that helps you always make sure your data is correct.

License: ISC License

TypeScript 99.92% Shell 0.08%
validation validator decorators schema typescript validate sanitise sanitize assert sanitization

themis's People

Contributors

dariusmb avatar radumolnar99 avatar

Stargazers

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

Watchers

 avatar  avatar

themis's Issues

Make the Validator constructor public, so we don't need to override it in the child class

Make the Validator constructor public instead of protected.

Current implementation

The validator constructor is protected, and we always need to override it in the child validator

class MyValidator extends Validator<string> {
  constructor() {
    super();
  }
}
.
class MySchema extends Schema {
  @StringField({ validators: [new TimeZoneValidator()]})
  myField: string
}

We are forced by typescript to override the constructor, because we cannot use new TimeZoneValidator(), if the constructor is protected

Proposed solution

Make the constructor public, so we don't need to override it.

Improve error throwing

The package has 3 levels of validations:

  • Validator level - throws ValidateError which has a message
  • Processor level - validates the field by applying all the validators. At this level, an array with all the ValidateError messages must be constructed and an ProcessorValidateError is thrown with the array
  • Schema validate - validates all the fields and constructs an object containing as keys the properties and as value the array of errors. The thrown error must be ValidateError

Add EnumField & EnumProccessor

Description
Add the EnumField decorator and create the processor for the field.

The field's toInternalValue will transform the input string into the the Enum type and check if it is a valid value for the enum.

Configuration:
enum - The enum that you want the string to be checked against.

Add Polymorphic Schema

We should have a class PolymorphicSchema which should have the following:

  • a lookup field which by default should have the value type
  • an object field which will store a key value. The value will be a schema and the key should be used to determine which schema we are using.

Inherit fields from parent classes

Description

Inherit the fields from all parent classes.

e.g:

class BaseSchema extends Schema<BasePayload> {
  @StringField()
  parentField: string;
}

class ChildSchema extends Schema<ChildPayload> {
  @IntegerField()
  extraField: string;
}

When the ChildSchema is validated, it should also validate the parentField

Replace Nested Field any with type

The nested fields configuration should stop using any.

export type NestedFieldConfiguration<T> = {
  validator: any; //TODO: Update type
};

Add fromField config for the decorator config

The field decorators need to allow the possibility to specify from where that field gets the value from the input data.

Example usage:

@StringField({fromField: 'last_name'})
lastName: string;

Add ArrayField & ArrayProcessor

Description
Add the ArrayField decorator and create the processor for the field.

The field should allow specifying what is the child value that is going to be validated. It is either a primitive value (another field) or another schema.

Add ability input custom validators for the fields

Add the ability to input custom validators for fields that will not override the default preset validators but will be both applied.

const isValidString = (value: string) => !value.isEmpty()
@StringField({validators: [isValidString]})

Add DateField & DateProcessor

Description

Add the DateField decorator and create the processor for the field.

The field's toInternalValue will transform the input string to a date format and check the formats allowed. If the value is a date, it doesn't need transforming anymore.

For working with date functions, add date-fns package

Configuration:

  • formats - An array of allowed formats (e.g: MM/dd/yyyy)

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.