Improving Meteor’s check package. Feedback needed

Hey y’all,

I’ve been exploring validation recently and think adding Match.AllOf (AND) and Match.OnlyOneOf (XOR) to compliment the existing Match.OneOf (OR) could be useful. I’d be willing to submit a PR if others think they’d be helpful.

If you‘d prefer not to have them, that’d be good to know too.

If you have other ideas on what would be useful, please post them below. Thanks!

1 Like

I don’t know how you use them. Could you give some examples?

Sure. Here are some examples to spur ideas:

Match.AllOf
Matches on all of the provided patterns. From an older forum post, instead of doing this:

something: Match.Where(function(value) {
  check(value, condition1)
  check(value, condition2)
})

You could write

something: Match.AllOf(condition1, condition2)

Match.OnlyOneOf
Matches on one and only one of the provided patterns. For example, let’s say you needed to match numbers but not integers:

num: Match.OnlyOneOf(Number, Match.Integer)

A number like 14 or 14.0 would fail on the above because it would match both number and integer

I’d honestly look at Zod. In my experience you’re probably going to be using check to validate method and publication parameters. In which case you should check out zodern:relay which uses Zod and has nice API for setting up and working with publications, subscriptions and methods.

3 Likes

Zod looks nice. Curious, are you using it for client-side validation? If so, what’s the bundle-size impact?

Still like check for its simplicity. It’s also nice to not have to carry another dependency.

zod is gzipped to 11.7k according to the vscode import cost extension

would definitely reiterate what @copleykj said.

zodern:relay + zod is a significant improvement to Meteor.

1 Like

to answer your other question, yes… I have it validating methods, forms in the browser (using react-hook-forms), publications, subscriptions, and i have it wired up to simple schema to validate database writes. Define the schema in zod, and get runtime checks + type safety enforced consistently across the entire app. Very cool.

Once I get some time, I am going to make a sample app showing the setup.