UNPKG

waterline

Version:

An ORM for Node.js and the Sails framework

57 lines (50 loc) 3.64 kB
// ██████╗ ██╗ ██╗██╗██╗ ██████╗ // ██╔══██╗██║ ██║██║██║ ██╔══██╗ // ██████╔╝██║ ██║██║██║ ██║ ██║ // ██╔══██╗██║ ██║██║██║ ██║ ██║ // ██████╔╝╚██████╔╝██║███████╗██████╔╝ // ╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ // // ██╗ ██╗███████╗███████╗ ██████╗██╗ ██╗ ██████╗██╗ ███████╗ // ██║ ██║██╔════╝██╔════╝██╔════╝╚██╗ ██╔╝██╔════╝██║ ██╔════╝ // ██║ ██║█████╗ █████╗ ██║ ╚████╔╝ ██║ ██║ █████╗ // ██║ ██║██╔══╝ ██╔══╝ ██║ ╚██╔╝ ██║ ██║ ██╔══╝ // ███████╗██║██║ ███████╗╚██████╗ ██║ ╚██████╗███████╗███████╗ // ╚══════╝╚═╝╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═════╝╚══════╝╚══════╝ // // ██████╗ █████╗ ██╗ ██╗ ██████╗ █████╗ ██████╗██╗ ██╗███████╗ // ██╔════╝██╔══██╗██║ ██║ ██╔══██╗██╔══██╗██╔════╝██║ ██╔╝██╔════╝ // ██║ ███████║██║ ██║ ██████╔╝███████║██║ █████╔╝ ███████╗ // ██║ ██╔══██║██║ ██║ ██╔══██╗██╔══██║██║ ██╔═██╗ ╚════██║ // ╚██████╗██║ ██║███████╗███████╗██████╔╝██║ ██║╚██████╗██║ ██╗███████║ // ╚═════╝╚═╝ ╚═╝╚══════╝╚══════╝╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝ // var _ = require('@sailshq/lodash'); module.exports = function LifecycleCallbackBuilder(context) { // Build a list of accepted lifecycle callbacks var validCallbacks = [ 'beforeValidate', 'afterValidate', 'beforeUpdate', 'afterUpdate', 'beforeCreate', 'afterCreate', 'beforeDestroy', 'afterDestroy', 'beforeFind', 'afterFind', 'beforeFindOne', 'afterFindOne' ]; // Hold a mapping of functions to run at various times in the query lifecycle var callbacks = {}; // Look for each type of callback in the collection _.each(validCallbacks, function(callbackName) { // If the callback isn't defined on the model there is nothing to do if (_.isUndefined(context[callbackName])) { return; } callbacks[callbackName] = context[callbackName]; }); return callbacks; };