-
Notifications
You must be signed in to change notification settings - Fork 12
Description
First of all, I want to say kudos for putting in the work to get a reactive layer on top of mongo (server-side) to handle declarative updates. Both collection2 and simpleschema solve specific issues, same as peerdb. I personally see peerdb more of a better package to replace collection-hooks but I wonder if peerdb api can be made to work with collection2 and simpleschema. I really see 3 concerns here:
Data schema integrity and validation -> SimpleSchema
Collection data schema validation on insert, upsert and update -> Collection2
Provide Collection data hooks on insert, upsert, update and delete -> Collection-hooks || Peerdb
I will personally like to use Peerdb over collection-hooks because of its reactive nature and the ability to handle hooks even if the changes are made by another client. For me peerdb is a clear winner but I cant seem to feel like it will even be much better if it can work in tandem with SimpleSchema and Collection2.
My question is - how do I get the benefit of simpleschema + collection2 + peerdb. Is it be possible to integrate all 3 to work together. Will it be better to integrate peerdb definitions into simpleschema since both of them are in a way defining metadata information. Example, If would be great if we could do something like
//data validation provided by simpleschema
PostSchema = new SimpleSchema({
content: {
type: String,
optional: false,
},
author: {
type:Object,
optional: false
},
"author.username": {
type: String
},
"author.displayName": {
type: String
},
hits: {
type: Number
}
//etc
});
//peerdb hook through SimpleSchema
PostSchema.References({
fields: function() {
return {
author: Post.ReferenceField(Person, ['username', 'displayName']),
};
}
});
PostSchema.Triggers({
//trigger definition here ....
});
Post = new Meteor.Collection('posts');
Post.attachSchema(PostSchema); //provided by collection2In the approve sample code, simpleschema handles validation (i.e. make sure author's username and displayname is a string), collection2 handle running validation and peerdb extension to simpleschema + collection2 maintains data references and hooks. This is just a thought but I think something along these lines will provide the community with 80% of what its needed for data manipulation. I want to use peerdb now but I also don't want to loose my schema validation checks on my collection (as well as on the client through autoform)