Thanks for the ideas and feedback. I really appreciate it!
It looks like there’s some API overlap with zodern:relay
Yep, I took inspiration from zodern:relay
, Validated Method, my own experiences using basic Meteor.methods with check, and reading a bunch of old discussions on ways to make methods better.
I like writing isomorphically and taking advantage of Optimistic UI — one of Meteor’s best features imo. So jam:method
seeks to be a worthy Validated Method successor.
I think zodern does great work and like using the zodern:melte
package and Monti APM. I truly appreciate all of their contributions to Meteor core as well. I think zodern:relay
is a really nice package. When I tried it out, there were some things I wish it had which inspired jam:method
. I also wasn’t sure I wanted to be locked into zod and the other tradeoffs it makes.
Regarding jam:easy-schema, is it worth name-spacing the monkey patched method attachSchema a bit by calling it attachEasySchema to avoid a collision?
I think the only package that uses attachSchema
is aldeed:collection2
. If you switch to jam:easy-schema
, you won’t need aldeed:collection2
because it has that functionality built in. I wanted to have a familiar behavior for people who choose to switch. I suppose I’d be surprised if there would be a collision — seems like you’d either use jam:easy-schema
or something else entirely.
does the schema you pass into a jam:method constructor have to use <Collection>
.schema, or can you call it like this?
Currently, only a schema created with jam:easy-schema
can be passed into schema
using <Collection>.schema
. One thing that might not be obvious is that jam:easy-schema
smartly validates the data passed in so you don’t need to worry about passing in a subset of the schema. Just pass in the one schema you attach to the collection and it takes care of the rest.
My plan is to support other schemas. For example, I’ll likely add support for a zod
schema. It’d be great to hear what other schemas people would like to have supported.
You bring up an interesting idea that I hadn’t considered before. I could enable what you describe but the schema object would need to be compatible with Meteor’s check
. If you, or others reading this, like that idea, let me know. But at that point I wonder why not just use jam:easy-schema
which does that for you with a bunch of other benefits and a nicer syntax.
Currently, if you want to use Meteor’s check
, or any other validator function from a package of your choice, you can use the validate
function instead of schema
. Here’s an example with check
:
import { createMethod } from 'meteor/jam:method'; // can import { Methods } from 'meteor/jam:method' instead and use Methods.create if you prefer
import { check } from 'meteor/check'
export const create = createMethod({
name: 'todos.create',
validate(args) {
check(args, {text: String})
},
run({ text }) {
const todo = {
text,
done: false,
createdAt: new Date(),
authorId: Meteor.userId(), // can also use this.userId instead of Meteor.userId()
}
const todoId = Todos.insert(todo);
return todoId;
}
});
I like the idea of having a “standard” based on Meteor check for validation, separate from solutions like Zod, Typebox etc
. I like the simplicity of check which inspired jam:easy-schema
.
it does some processing each time you pass in a “raw” schema
Not exactly. The processing happens once when you use attachSchema
and then you retrieve it with <Collection>.schema
.
I wonder if it’s worth exposing shapeSchema somehow to let people “compile” the schemas e.g. as a module export.
Sounds interesting. How would you imagine using this? What would be the benefits?
(I have more thoughts regarding easy-schema than jam:method at the moment, apologies!)
All good! Thanks again for sharing your thoughts.