Detalhes do pacote

feathers-hooks

feathersjs5.5kMITdepreciado2.1.2

Feathers v3 is out and this module has been integrated into Feathers core. See https://docs.feathersjs.com/migrating.html for more information.

Before and after service method call hooks for easy authorization and processing.

feathers-plugin, feathers

readme (leia-me)

Feathers Hooks

Important: feathers-hooks is included in Feathers (@feathersjs/feathers) v3 and later and does not have to be loaded and configured separately anymore.

Greenkeeper badge

Build Status Code Climate Test Coverage Dependency Status Download Status Slack Status

Middleware for Feathers service methods

Documentation

Please refer to the Feathers hooks documentation for more details on:

  • The philosophy behind hooks
  • How you can use hooks
  • How you can chain hooks using Promises
  • Params that are available in hooks
  • Hooks that are bundled with feathers and feathers plugins

Quick start

feathers-hooks allows to register composable middleware functions when a Feathers service method executes. This makes it easy to decouple things like authorization and pre- or post processing and error handling from your service logic.

To install from npm, run:

$ npm install feathers-hooks --save

Then, to use the plugin in your Feathers app:

const feathers = require('feathers');
const hooks = require('feathers-hooks');

const app = feathers().configure(hooks());

Then, you can register a hook for a service:

// User service
const service = require('feathers-memory');

module.exports = function(){
  const app = this;

  let myHook = function(options) {
    return 
  }

  // Initialize our service
  app.use('/users', service());

  // Get our initialize service to that we can bind hooks
  const userService = app.service('/users');

  // Set up our before hook
  userService.hooks({
    before(hook){
      console.log('My custom before hook ran!');
    }
  });
}

License

Copyright (c) 2016 Feathers contributors

Licensed under the MIT license.

changelog (log de mudanças)

Change Log

v2.1.1 (2017-10-22)

Full Changelog

Closed issues:

  • Angular 4 feathers hook build fails - "All declarations of 'Service' must have identical type parameters" #172

Merged pull requests:

v2.1.0 (2017-09-27)

Full Changelog

Merged pull requests:

v2.0.4 (2017-09-25)

Full Changelog

Merged pull requests:

  • [typings] Make Service generic types default to any #168 (j2L4e)

v2.0.3 (2017-09-25)

Full Changelog

Closed issues:

  • Hook typings #166
  • Error: 'chck' is not a valid hook method #165
  • [feature request] provide a way to swallow error in error hooks #151

Merged pull requests:

  • [typings] add service and id to hook context object #169 (j2L4e)
  • Update README to point at new documentation location #167 (tfussell)

v2.0.2 (2017-07-11)

Full Changelog

Fixed bugs:

  • TypeScript: HookProps.type: add 'error' #161 (tycho01)

Closed issues:

  • Params are not populated when called internally #160
  • [discussion] maybe change the name of the context parameter from 'hook' to 'context' or use 'this' in the future? #159
  • Add hook to the top of others hook #158
  • __hooks being overwritten #157
  • Using a hook.disable() on a service should remove that from the Allow header for REST services #107

Merged pull requests:

v2.0.1 (2017-04-28)

Full Changelog

Closed issues:

  • \_\_hooks of existing service should not be overwritten #154
  • An in-range update of mongoose is breaking the build 🚨 #153

Merged pull requests:

v2.0.0 (2017-04-17)

Full Changelog

Implemented enhancements:

  • Population fails on empty values #137

Closed issues:

  • feathers-hooks-common/lib/populate, feathers-hooks-common/lib/bundled not found. #149
  • Test Hooks #146
  • Gravatar example doesn't work?! #145
  • how to get service name(path) in hook functions? #143
  • V1.7.1: Module not found: Error: Can't resolve 'feathers-hooks-common/lib/populate' in '/app/node_modules/feathers-hooks/lib' @ ./~/feathers-hooks/lib/hooks.js 13:16-61 #142
  • Calling populate(target, options) is now DEPRECATED #141
  • Hooks with mutiple entries per request #95
  • Remove ref doc will broke the parent router #82

Merged pull requests:

v1.8.1 (2017-03-02)

Full Changelog

Merged pull requests:

v1.8.0 (2017-03-01)

Full Changelog

Closed issues:

  • Composing Hooks #133
  • Can I use populate without authentication? #132
  • Remove-hook breaks feathers-mongoose #91

Merged pull requests:

v1.7.1 (2016-12-16)

Full Changelog

Closed issues:

  • How to mix hooks together (pluck + populate) #68

Merged pull requests:

  • Use legacyPopulate from latest hooks-common #131 (daffl)

v1.7.0 (2016-11-25)

Full Changelog

Implemented enhancements:

  • Bundled hooks should support a scope #63

Closed issues:

  • Be able to access deeply nested attributes in bundled hooks #79

Merged pull requests:

v1.6.1 (2016-11-02)

Full Changelog

Closed issues:

  • app.hooks() does not pass hook.app #123
  • [Feature Request] Hook to disable multi-update/patch/remove #98

v1.6.0 (2016-10-31)

Full Changelog

Closed issues:

  • service.hooks() did not run as expected #119
  • Throw an error for unknown hook methods #118
  • no hook result when internal service call #106
  • remove hook should check if hook.result is not null #99
  • afterError hooks #83
  • Should remove hook.params.provider to act as an internal call #76

Merged pull requests:

v1.5.8 (2016-09-27)

Full Changelog

Closed issues:

  • Sanitation hooks for each db type #62

Merged pull requests:

v1.5.7 (2016-08-20)

Full Changelog

Closed issues:

  • Customize existing hook - 'this' undefined - TypeError #94
  • c #93

Merged pull requests:

  • Fix removing fields from feathers-mongoose #92 (supasate)

v1.5.6 (2016-08-16)

Full Changelog

Closed issues:

  • Hooks cannot remove inherited properties #89
  • Pop wrong hooks in bundled.test #87

Merged pull requests:

  • Fix #89 Hooks cannot remove inherited properties #90 (supasate)
  • Fix #87 pop wrong hooks in bundled test #88 (supasate)

v1.5.5 (2016-08-11)

Full Changelog

Closed issues:

  • Multi populate with client control of which fields to populate #85

Merged pull requests:

v1.5.4 (2016-05-30)

Full Changelog

Closed issues:

  • Throw or log an error for catch block in populate method. #80

Merged pull requests:

v1.5.3 (2016-05-09)

Full Changelog

Closed issues:

  • Populate hook doesn't work with populating arrays #74
  • hashPassword validation error #70
  • Remove field hook not working. #69
  • Remove field and haspassword hooks are not working properly. #67

Merged pull requests:

v1.5.2 (2016-04-11)

Full Changelog

Fixed bugs:

  • Do not throw an error when a field that is supposed to be lowercased is undefined #66 (gurisko)

Merged pull requests:

v1.5.1 (2016-03-30)

Full Changelog

Closed issues:

  • Header or request information in hooks #61
  • Create a populate hook #56

Merged pull requests:

  • adding ability to remove from result.data object #64 (ekryski)

v1.5.0 (2016-03-15)

Full Changelog

Closed issues:

  • Create a "select" or "pluck" hook for serialization #50

Merged pull requests:

  • Adding functionality and tests for the populate hook #60 (daffl)
  • Add "pluck" bundled hook #58 (harangue)

v1.4.0 (2016-03-06)

Full Changelog

Closed issues:

  • The idea for a new hook #42
  • Make sure hook promises propagate their errors #30
  • Defining a service hook without an app/before app initialization? #25

Merged pull requests:

  • Refactoring hooks to run before event dispatching #57 (daffl)

v1.3.0 (2016-02-26)

Full Changelog

Closed issues:

  • Add toLowerCase hook #49

Merged pull requests:

v1.2.0 (2016-02-26)

Full Changelog

Fixed bugs:

  • should be able to bypass remove hook #48

Merged pull requests:

  • Alllow to conditionally remove fields #51 (daffl)

v1.1.2 (2016-02-24)

Full Changelog

Merged pull requests:

v1.1.1 (2016-02-23)

Full Changelog

Closed issues:

  • Ability to call the same service from a hook? #43
  • more request param in hook? #40
  • hook on non-service apps? #39

Merged pull requests:

v1.1.0 (2016-02-14)

Full Changelog

Merged pull requests:

  • Allow before hooks to set the result which will skip service method #38 (daffl)

v1.0.0 (2016-02-13)

Full Changelog

Closed issues:

  • Provide a collection of common hooks #31

Merged pull requests:

v1.0.0-pre.4 (2016-01-23)

Full Changelog

v1.0.0-pre.3 (2016-01-23)

Full Changelog

Merged pull requests:

v1.0.0-pre.2 (2016-01-12)

Full Changelog

v1.0.0-pre.1 (2016-01-12)

Full Changelog

Closed issues:

  • Should support promises returned from service methods #28

Merged pull requests:

  • Refactoring for hooks to use promises and promise chains #29 (daffl)

v0.6.0 (2016-01-10)

Full Changelog

Fixed bugs:

  • After hooks fail if params was missing on the original service method #19

Closed issues:

  • examples not working #24
  • Unable to modify result object in after hook #23

Merged pull requests:

  • Prevent next from being called multiple times #27 (daffl)
  • Migrate to ES6 and new plugin infrastructure #26 (daffl)

v0.5.1 (2015-10-06)

Full Changelog

Implemented enhancements:

  • Be able to apply hooks to custom service methods #9

Merged pull requests:

  • Use feathers-commons hook functionality #22 (daffl)

0.5.0 (2015-02-05)

Full Changelog

Closed issues:

  • feathers-hooks is changing the scope of makeWrapper() #17
  • Arrays of Hooks are running in reverse order. #13
  • Remove peer dependency #12
  • Before all and after all hooks #11
  • Hooks are always called even if you don't want them to be #8

Merged pull requests:

  • Make sure hooks and service methods keep their context #18 (daffl)
  • Refactoring to fix hook execution order and all-hooks #16 (daffl)
  • Better check for .makeArguments id #15 (daffl)

0.4.0 (2014-07-20)

Full Changelog

Closed issues:

  • multiple hooks / array of hooks #2

Merged pull requests:

  • Adding the ability to define multiple hooks in an array. #7 (ekryski)

0.3.2 (2014-06-18)

Full Changelog

Closed issues:

  • Update repository link on npm #5

0.3.1 (2014-06-05)

Full Changelog

0.3.0 (2014-06-05)

Full Changelog

Closed issues:

  • Allow hooks to return a promise #3
  • normalize parameters #1

Merged pull requests:

  • Allow hooks to return a promise #4 (daffl)

0.2.0 (2014-06-02)

Full Changelog

0.1.1 (2014-05-29)

Full Changelog

0.1.0 (2014-05-28)

* This Change Log was automatically generated by github_changelog_generator