@feathersjs/feathers
Advanced tools
Comparing version 3.0.0-pre.2 to 3.0.0-pre.3
# Change Log | ||
## [v3.0.0-pre.2](https://github.com/feathersjs/feathers/tree/v3.0.0-pre.2) (2017-10-20) | ||
[Full Changelog](https://github.com/feathersjs/feathers/compare/v2.2.3...v3.0.0-pre.2) | ||
**Merged pull requests:** | ||
- Move to @feathersjs npm scope [\#699](https://github.com/feathersjs/feathers/pull/699) ([daffl](https://github.com/daffl)) | ||
- Also pass app object as parameter to configure callbacks [\#698](https://github.com/feathersjs/feathers/pull/698) ([daffl](https://github.com/daffl)) | ||
## [v2.2.3](https://github.com/feathersjs/feathers/tree/v2.2.3) (2017-10-20) | ||
@@ -4,0 +12,0 @@ [Full Changelog](https://github.com/feathersjs/feathers/compare/v2.2.2...v2.2.3) |
const { EventEmitter } = require('events'); | ||
const Proto = require('uberproto'); | ||
// Returns a hook that emits service events. Should always be | ||
// used as the very last hook in the chain | ||
const eventHook = exports.eventHook = function eventHook () { | ||
@@ -17,2 +19,3 @@ return function (hook) { | ||
// Mixin that turns a service into a Node event emitter | ||
const eventMixin = exports.eventMixin = function eventMixin (service) { | ||
@@ -61,5 +64,3 @@ if (service._serviceEvents) { | ||
module.exports = function () { | ||
return function () { | ||
const app = this; | ||
return function (app) { | ||
// Mappings from service method to event name | ||
@@ -66,0 +67,0 @@ Object.assign(app, { |
@@ -11,2 +11,3 @@ const { | ||
// A service mixin that adds `service.hooks()` method and functionality | ||
const hookMixin = exports.hookMixin = function hookMixin (service) { | ||
@@ -32,4 +33,10 @@ if (typeof service.hooks === 'function') { | ||
const service = this; | ||
const args = arguments; | ||
const args = Array.from(arguments); | ||
// If the last argument is `true` we want to return | ||
// the actual hook object instead of the result | ||
const returnHook = args[args.length - 1] === true | ||
? args.pop() : false; | ||
// We have to try/catch this so that argument validation | ||
// returns a rejected promise | ||
try { | ||
@@ -46,2 +53,3 @@ validateArguments(method, args); | ||
type: 'before', // initial hook object type | ||
returnHook, | ||
service, | ||
@@ -74,8 +82,7 @@ app | ||
}) | ||
// Make a copy of hookObject from `before` hooks and update type | ||
.then(hookObject => | ||
Object.assign({}, hookObject, { type: 'after' }) | ||
) | ||
// Make a (shallow) copy of hookObject from `before` hooks and update type | ||
.then(hookObject => Object.assign({}, hookObject, { type: 'after' })) | ||
// Run through all `after` hooks | ||
.then(hookObject => { | ||
// Combine all app and service `after` and `finally` hooks and process | ||
const afterHooks = getHooks(app, service, 'after', method, true); | ||
@@ -87,8 +94,10 @@ const finallyHooks = getHooks(app, service, 'finally', method, true); | ||
}) | ||
// Finally, return the result (or the hook object if a hidden flag is set) | ||
.then(hookObject => | ||
hookObject.params.__returnHook ? hookObject : hookObject.result | ||
// Finally, return the result | ||
// Or the hook object if the `__returnHook` flag is set | ||
hookObject.returnHook ? hookObject : hookObject.result | ||
) | ||
// Handle errors | ||
.catch(error => { | ||
// Combine all app and service `error` and `finally` hooks and process | ||
const errorHooks = getHooks(app, service, 'error', method, true); | ||
@@ -98,2 +107,3 @@ const finallyHooks = getHooks(app, service, 'finally', method, true); | ||
// A shallow copy of the hook object | ||
const errorHookObject = Object.assign({}, error.hook || hookObject, { | ||
@@ -109,8 +119,11 @@ type: 'error', | ||
.then(hook => { | ||
if (errorHookObject.params.__returnHook) { | ||
if (errorHookObject.returnHook) { | ||
// Return either the complete hook if the `__returnHook` flag is set | ||
return Promise.reject(hook); | ||
} else if (hook.result) { | ||
// Return the result if it is set so you can swallow errors | ||
return Promise.resolve(hook.result); | ||
} | ||
// If none of the above, return the error | ||
return Promise.reject(hook.error); | ||
@@ -126,5 +139,3 @@ }); | ||
module.exports = function () { | ||
return function () { | ||
const app = this; | ||
return function (app) { | ||
// We store a reference of all supported hook types on the app | ||
@@ -131,0 +142,0 @@ // in case someone needs it |
@@ -1,1 +0,1 @@ | ||
module.exports = '3.0.0-pre.2'; | ||
module.exports = '3.0.0-pre.3'; |
{ | ||
"name": "@feathersjs/feathers", | ||
"description": "A REST and realtime API layer for modern applications.", | ||
"version": "3.0.0-pre.2", | ||
"version": "3.0.0-pre.3", | ||
"homepage": "http://feathersjs.com", | ||
@@ -6,0 +6,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44491
13
318