npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@linode/validation

v0.56.0

Published

Yup validation schemas for use with the Linode APIv4

Downloads

1,178

Readme

Linode API Validation Schemas

Usage

This library consists of Yup schemas corresponding to the endpoints of the Linode API, intended to be used for client-side validation. They closely (though not exactly) match the validation that is run by the API back-end when a request is received. They can be used to validate API request payloads manually or to validate forms (for example through Formik’s validationSchema). They also work well with the @linode/api-v4 package.

Manual Validation

import { CreateLinodeSchema } from '@linode/validation';

const payload = { label: 'My Linode', type: 'g6-standard-1' };
CreateLinodeSchema.validateSync(payload);
// Uncaught: u [ValidationError]: Region is required.

With the @linode/api-v4 package

NOTE: This feature is in development.

import { createLinode } from '@linode/api-v4';
import { CreateLinodeSchema } from '@linode/validation';

const payload = { label: 'My Linode', type: 'g6-standard-1' };
createLinode(payload, { schema: CreateLinodeSchema }).catch((error) => {
  console.log(error);
});

// { field: 'region', reason: 'Region is required.' }

Why is it a separate library?

These schemas were originally included in the @linode/api-v4 package by default, and automatically applied before any network request was made. This worked well in the early days of Cloud Manager, especially before @linode/api-v4 was published as a separate package. However, as the project grew, this setup caused a few problems:

  1. Coupling the request handlers and validation schemas meant that it wasn't possible to turn client-side validation off, which isn't a good fit for a public package.
  2. The validation doesn't match the API’s exactly. There are some things, such as uniqueness, that are difficult to validate on the client. There are some additional cases where the validation is too complex, and we made a decision to fall back on the backend validation. This was acceptable when the schemas were only used internally by the Cloud Manager, but can lead to confusion for external users (in fact it's unlikely that most external users were even aware that validation was happening on the client side).
  3. The auto-validation meant that we were double-validating in many cases; when using Formik, for example, the same schema is run on form submit, then run again in the JS client.
  4. The api-v4 bundle was too big, and the schemas were a big part of it. This is unfortunate especially since not everyone necessarily wants to run client validation.