Where's Match.And?

No, I didn’t. That would be sad as I really like Match and check! I dropped aldeed:collection2 in favor of writing my own simple Schema class that simply applies the given object composed with Match/check to a collection’s documents on insert/update/etc. I really like the Match/check syntax much better than the syntax in aldeed:collection2.

export default
class Schema {
    constructor(spec) {
        this.spec = spec || {}
    }

    applyTo(collection) {
        collection.before.insert((userId, doc) => {
            _checkDocument(this, doc, collection, 'insert')
        })
        collection.before.update((userId, doc, fieldNames, modifier, options) => {
            _checkDocument(this, doc, collection, 'updat')
        })
        collection.before.upsert(function(userId, doc, fieldNames, modifier, options) {
            // TODO
        })
    }
}

function _checkDocument(self, document, collection, action) {
    try {
        check(document, Object.assign({
            _id: String, // TODO: make a MeteorIDString Match type.
        }, self.spec))
    }
    catch(error) {
        throw new Error(`${error.message} while ${action}ing item ${action == 'insert' ? 'into' : 'in'} '${collection._name}' collection.`)
    }
}