Moonlight-io / asteroid-sdk-js

5 stars 3 forks source link

Feature/validators #47

Closed rockacola closed 4 years ago

rockacola commented 4 years ago

To solve https://github.com/Moonlight-io/asteroid-sdk-js/issues/46

@lllwvlvwlll would like to get your feedback on the proposed validator mechanism. This is designed to replace vega's attribute validation logic, as well as provide self-documented, cross-language rules in JSON format.

The focus of this PR is to review its "mechanic" and not completion of its "validation rules" (as it will follow once the mechanic is finalized).


The validation rules are stored in /data/attribute-validation-rules.json. Originally considered to use YAML (for readability) but decided to go with JSON to minimize hurdles to parse its content on the client-side.

TypeScript interface (interfaces/validation.ts) is available to showcase available rule choices.

The TypeScript implementation response with standard Error object. Leaving it as it is for now, but later I would like to explore the option of throwing error with even more context.

EDIT: ValidationError is now implemented, extends from standard Error and providing extra propertyKey parameter. More custom parameters can be added in the near future if deemed useful.

lllwvlvwlll commented 4 years ago

I think this works well in the SDK for now. So you are aware, the back-end using type validation instead of field validation (in most cases). I think we can move forward with this approach though and work to align the two. The format makes sense to me and there is nothing I see that would inhibit use in the backend in the future.