Nodal 0.10: New Core, Asynchronous Validations, and More

Hey! It's May and that means it's about time for another Nodal release. :)

This time around we've taken a few important steps for the future and added some functionality developers have been requesting. Let's go over the basics.

New Core

Nodal's core (controller and routing) logic has been offloaded to a project called fxn. Nodal still inherits all of these classes and methods, we just needed to modularize it for future projects. Not much to say here besides everything you know and love about Nodal still exists, but if you need to debug or expand upon error handling check out fxn instead.

Asynchronous Validations: Verifications

Nodal Models have a new type of validation in town --- the verification. Verifications work much like validations except they're run asynchronously after the beforeSave() method but before your model is saved. They're always run in the order in which they're defined. The errors don't stack - a single error here prevents anything else from executing.

As you recall, validations work like this:

User.validates('email', 'Must exist', (email) => email);

Whereas verifications work like this...

User.verifies('Must not have duplicate email', (email, callback) => { User.findBy('email', email, (err, user) => { callback(!user); // true if user isn't found, false otherwise }); });

Model.findBy, Model.findOrCreateBy

Models now have a findBy and findOrCreateBy method. They work as follows;

User.findBy('email', '[email protected]', (err, user) => { // do something, found first match by email });

And...

User.findOrCreateBy('email', {email: '[email protected]'}, (err, user) => { // found me or created a new user with that email and other properties... });

Have fun with these shortcuts. :) Should save some time.

Form Data and File Uploads

Nodal now natively supports multipart form data! Hooray. This includes uploads from a form. You can access uploads with this.params.body.NAME where NAME is the name of the form file upload element. The return will be a Buffer that has .filename and .contentType properties for easy inspection.

Other Misc. Fixes

On top of these changes, we've made some fixes to Nodal generally. Mostly controller template changes and more explicit error messages.

Thanks!

Thanks! Please keep up with the most recent changes to Nodal by following me on Twitter, @keithwhor and keep up to date with all open source related to Nodal via Polybit. :)