github moleculerjs/moleculer v0.14.5

latest releases: v0.14.35, v0.14.34, v0.15.0-beta1...
4 years ago

Wrapping service methods with middlewares

New localMethod hook in middlewares which wraps the service methods.

Example

// my.middleware.js
module.exports = {
    name: "MyMiddleware",

    localMethod(next, method) {
        return (...args) => {
            console.log(`The '${method.name}' method is called in '${method.service.fullName}' service.`, args);
            return handler(...args);
        }
    }
}

Schema for service methods

Similar for action schema, you can define service methods with schema. It can be useful when middleware wraps service methods.

Example for new method schema

// posts.service.js
module.exports = {
    name: "posts",

    methods: {
        list: {
            async handler(count) {
                // Do something
                return posts;
            }
        }
    }
};

Changes

  • add chunk limit for streams in message transporting. #683
  • add baseUrl option to Datadog metric reporter. #694
  • fix open handles in unit tests. #695
  • update d.ts #699 #700 #703

Don't miss a new moleculer release

NewReleases is sending notifications on new releases.