Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add input validation for use as a JS library #58

Merged
merged 1 commit into from
Apr 28, 2021

Conversation

bengourley
Copy link
Contributor

Goal

When used via TypeScript, as we do in our commands, the uploader libraries have type information that prevent certain kinds of input. However, when used via JS – as is one of the use cases of this package – no such safety is in place. The goal is to add input checking at runtime to ensure early and helpful feedback to the user when invalid input is provided.

Design

I've implemented a set of reusable input checking functions. Each uploader has slightly different parameters that it supports so the exact validation method is composed of multiple calls to the input checkers specifying the kind of input allowed.

It also checks for unknown options, since this can (and has been) as source of confusion – for instance, passing bundleUrl into the Node uploader.

Changeset

  • New lib/InputValidators.ts file
  • Updated all of the node/browser/reactnative upload*() methods to first validate the provided input. If invalid input is detected, these functions will reject a promise with the validation error.

Testing

  • Added test cases for all functions where the input validation was added.

@bengourley bengourley merged commit fd7e9fd into next Apr 28, 2021
@bengourley bengourley deleted the bengourley/js-runtime-checks branch April 28, 2021 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants