Skip to content

Commit

Permalink
Merge pull request #1055 from Ashikpaul/patch-1
Browse files Browse the repository at this point in the history
Fixed some minor typos
  • Loading branch information
icebob authored Jan 17, 2022
2 parents 93f0df3 + c89bd09 commit d88abb1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
30 changes: 15 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
_69 commits from 7 contributors._

## Custom error recreation feature [#1017](https://github.com/moleculerjs/moleculer/pull/1017)
You can create a custom `Regenerator` class which is able to serialize and deserialize your custom errors. It's necessary when the custom error is created on a remote node and must be serialized to be able to sent back to the caller.
You can create a custom `Regenerator` class that is able to serialize and deserialize your custom errors. It's necessary when the custom error is created on a remote node and must be serialized to be able to send it back to the caller.

**Create a custom Regenerator**
```js
Expand Down Expand Up @@ -49,7 +49,7 @@ module.exports = {
```

## Error events [#1048](https://github.com/moleculerjs/moleculer/pull/1048)
When an error occured inside ServiceBroker, it's printed to the console, but there was no option that you can process it programatically (e.g. transfer to an external monitoring service). This feature solves it. Every error inside ServiceBroker broadcasts a **local** (not transported) event (`$transporter.error`, `$broker.error`, `$transit.error`, `$cacher.error`, `$discoverer.error`) what you can listen in your dedicated service or in a middleware.
When an error occurred inside ServiceBroker, it's printed to the console, but there was no option that you can process it programmatically (e.g. transfer to an external monitoring service). This feature solves it. Every error inside ServiceBroker broadcasts a **local** (not transported) event (`$transporter.error`, `$broker.error`, `$transit.error`, `$cacher.error`, `$discoverer.error`) what you can listen in your dedicated service or in a middleware.

**Example to listen in an error-tracker service**
```js
Expand Down Expand Up @@ -230,7 +230,7 @@ _The transporter automatically detects the version of the library and uses the c
### Async custom validator functions and `ctx` as metadata
Since `fastest-validator@1.11.0`, the FastestValidator supports async custom validators and you can [pass metadata for custom validator functions](https://github.com/icebob/fastest-validator/blob/master/CHANGELOG.md#meta-information-for-custom-validators).
In Moleculer, the `FastestValidator` passes the `ctx` as metadata. It means you can access to the current context, service, broker and you can make async calls (e.g calling another service) in custom checker functions.
In Moleculer, the `FastestValidator` passes the `ctx` as metadata. It means you can access the current context, service, broker and you can make async calls (e.g calling another service) in custom checker functions.
**Example**
```js
Expand Down Expand Up @@ -303,7 +303,7 @@ _62 commits from 12 contributors._
# [0.14.11](https://github.com/moleculerjs/moleculer/compare/v0.14.10...v0.14.11) (2020-09-27)

## New `merged` service lifecycle hook
Service has a new `merged` lifecycle hook which is called after the service schemas (including mixins) has been merged but before service is registered. It means you can manipulate the merged service schema before it's processed.
Service has a new `merged` lifecycle hook which is called after the service schemas (including mixins) have been merged but before service is registered. It means you can manipulate the merged service schema before it's processed.
**Example**
```js
Expand Down Expand Up @@ -351,7 +351,7 @@ module.exports = {
# [0.14.9](https://github.com/moleculerjs/moleculer/compare/v0.14.8...v0.14.9) (2020-08-06)
## Register method in module resolver
If you create a custom module (e.g. serializer), you can register it into the built-in modules with the `register` method. This method is also available in all other built-in module resolver.
If you create a custom module (e.g. serializer), you can register it into the built-in modules with the `register` method. This method is also available in all other built-in module resolvers.
**Example**
```js
Expand Down Expand Up @@ -441,11 +441,11 @@ module.exports = {
# [0.14.8](https://github.com/moleculerjs/moleculer/compare/v0.14.7...v0.14.8) (2020-06-27)

## Github Sponsoring is available for Moleculer :tada:
We have been approved in Github Sponsors program, so you can sponsor the Moleculer project via [Github Sponsors](https://github.com/sponsors/moleculerjs).
We have been approved in the Github Sponsors program, so you can sponsor the Moleculer project via [Github Sponsors](https://github.com/sponsors/moleculerjs).
_If you have taxing problem with Patreon, change to Github Sponsors._

## New Validator configuration
The `validator` has the same module configuration in broker options like other modules. It means you can configure the validation constructor options via broker options (moleculer.config.js).
The `validator` has the same module configuration in broker options as other modules. It means you can configure the validation constructor options via broker options (moleculer.config.js).

**Default usage:**
```js
Expand Down Expand Up @@ -516,7 +516,7 @@ Added the following new metrics:
# [0.14.7](https://github.com/moleculerjs/moleculer/compare/v0.14.6...v0.14.7) (2020-05-22)
## New Discoverer module
The Discoverer is a new built-in module in Moleculer framework. It's responsible for that all Moleculer nodes can discover each other and check them with heartbeats. In previous versions, it was an integrated module inside `ServiceRegistry` & `Transit` modules. In this version, the discovery logic has been extracted to a separated built-in module. It means you can replace it to other built-in implementations or a custom one. The current discovery & heartbeat logic is moved to the `Local` Discoverer.
The Discoverer is a new built-in module in Moleculer framework. It's responsible for that all Moleculer nodes can discover each other and check them with heartbeats. In previous versions, it was an integrated module inside `ServiceRegistry` & `Transit` modules. In this version, the discovery logic has been extracted to a separated built-in module. It means you can replace it with other built-in implementations or a custom one. The current discovery & heartbeat logic is moved to the `Local` Discoverer.
Nevertheless, this version also contains other discoverers, like Redis & etcd3 discoverers. Both of them require an external server to make them work.
One of the main advantages of the external discoverers, the node discovery & heartbeat packets don't overload the communication on the transporter. The transporter transfers only the request, response, event packets.
Expand Down Expand Up @@ -730,8 +730,8 @@ You can create your custom Discoverer. We recommend to copy the source of Redis
- fixed multiple heartbeat sending issue at transporter reconnecting.
- the `heartbeatInterval` default value has been changed to `10` seconds.
- the `heartbeatTimeout` default value has been changed to `30` seconds.
- the heartbeat check logics use process uptime instead of timestamps in order to avoid issues with time synchronization or daylight saving.
- Notepack serializer initialization issue fixed. It caused problem when Redis cacher uses Notepack serializer.
- the heartbeat check logics uses process uptime instead of timestamps in order to avoid issues with time synchronization or daylight saving.
- Notepack serializer initialization issue fixed. It caused a problem when Redis cacher uses Notepack serializer.
- new `removeFromArray` function in Utils.
- `mcall` method definition fixed in Typescript definition.
- dependencies updated.
Expand Down Expand Up @@ -764,7 +764,7 @@ Thanks for [@jalerg](https://github.com/jalerg), there is a NewRelic tracing exp
// Set `shared` property in payload.
shared: false,
},
// Default tags. They will be added into all span tags.
// Default tags. They will be added to all span tags.
defaultTags: null,
},
},
Expand Down Expand Up @@ -803,7 +803,7 @@ module.exports = {
```
## Schema for service methods
Similar for action schema, you can define service methods with schema. It can be useful when middleware wraps service methods.
Similar to action schema, you can define service methods with schema. It can be useful when middleware wraps service methods.
**Example for new method schema**
```js
Expand Down Expand Up @@ -911,11 +911,11 @@ Fastest-validator, the default validation has been upgraded to the 1.0.0 version
If you use custom rules, you should upgrade your codes. [Check the changes here.](https://github.com/icebob/fastest-validator/releases/tag/v1.0.0-beta1)
## Logger settings changed
The whole logging function has been rewritten in this version. It means, it has a lot of new features, but the configuration of loggers has contains breaking changes. You can't use some old custom logger configuration form. The new configuration same as the other Moleculer module configurations. This new version supports all famous loggers like [Pino](https://github.com/pinojs/pino), [Winston](https://github.com/winstonjs/winston), [Bunyan](https://github.com/trentm/node-bunyan), [Debug](https://github.com/visionmedia/debug) & [Log4js](https://github.com/log4js-node/log4js-node).
The whole logging function has been rewritten in this version. It means, it has a lot of new features, but the configuration of loggers has contains breaking changes. You can't use some old custom logger configuration form. The new configuration is same as the other Moleculer module configurations. This new version supports all famous loggers like [Pino](https://github.com/pinojs/pino), [Winston](https://github.com/winstonjs/winston), [Bunyan](https://github.com/trentm/node-bunyan), [Debug](https://github.com/visionmedia/debug) & [Log4js](https://github.com/log4js-node/log4js-node).
_If you are using the built-in default console logger, this breaking change doesn't affect you._
The `logFormatter` and `logObjectPrinter` broker options has been removed and moved into the `Console` and `File` logger options.
The `logFormatter` and `logObjectPrinter` broker options have been removed and moved into the `Console` and `File` logger options.
**Not changed usable configurations**
```js
Expand Down Expand Up @@ -947,7 +947,7 @@ module.exports = {
```
### Console logger
This logger prints all log messags to the `console`. It supports several built-in formatters or you can use your custom formatter, as well.
This logger prints all log messages to the `console`. It supports several built-in formatters or you can use your custom formatter, as well.
**Shorthand configuration with default options**
```js
Expand Down
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
education, socio-economic status, nationality, personal appearance, race,
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ Use the Moleculer CLI tool to create a new Moleculer based microservices project
$ npx moleculer-cli -c moleculer init project moleculer-demo
```

2. Open project folder
2. Open the project folder
```bash
$ cd moleculer-demo
```

3. Start project
3. Start the project
```bash
$ npm run dev
```

4. Open the [http://localhost:3000/](http://localhost:3000/) link in your browser. It shows a welcome page which contains many information about your project & you can test the generated services.
4. Open the [http://localhost:3000/](http://localhost:3000/) link in your browser. It shows a welcome page that contains more information about your project & you can test the generated services.

:tada: **Congratulations! Your first Moleculer-based microservices project is created. Read our [documentation](https://moleculer.services/docs) to learn more about Moleculer.**

Expand Down Expand Up @@ -143,7 +143,7 @@ To report a security vulnerability, please use the [Tidelift security contact](h
Tidelift will coordinate the fix and disclosure.

# Contributions
We welcome you to join to the development of Moleculer. Please read our [contribution guide](http://moleculer.services/docs/contributing.html).
We welcome you to join in the development of Moleculer. Please read our [contribution guide](http://moleculer.services/docs/contributing.html).
<a href="https://github.com/moleculerjs/moleculer/graphs/contributors"><img src="https://opencollective.com/moleculer/contributors.svg?width=882&button=false" /></a>

## Project activity
Expand Down
14 changes: 7 additions & 7 deletions docs/MIGRATION_GUIDE_0.14.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const MyMiddleware = function(broker) {
```

## 4. Use the new context-based event handler signature
Moleculer detects the signature if your event handler. If it finds that the signature is `"user.created(ctx) { ... }`, it will call it with Event Context. If not, it will call with old arguments & the 4th argument will be the Event Context, like `"user.created"(payload, sender, eventName, ctx) {...}`
Moleculer detects the signature of your event handler. If it finds that the signature is `"user.created(ctx) { ... }`, it will call it with Event Context. If not, it will call with old arguments & the 4th argument will be the Event Context, like `"user.created"(payload, sender, eventName, ctx) {...}`

**Legacy event handler signature**
```js
Expand Down Expand Up @@ -311,7 +311,7 @@ module.exports = {
};
```
>[Read more about new logging feature and all supported loggers.](https://moleculer.services/docs/0.14/logging.html)
>[Read more about the new logging feature and all supported loggers.](https://moleculer.services/docs/0.14/logging.html)
## 7. Bluebird is dropped
The Bluebird Promise library has been dropped from the project because as of Node 10, the native `Promise` implementation is [faster (2x)](https://github.com/icebob/js-perf-benchmark/blob/95803284dcb46c403eb71f2f114b76bf669189ce/suites/promise.js#L123-L133) than Bluebird.
Expand All @@ -338,7 +338,7 @@ declare module "moleculer" {
Additionally, if you were using `PromiseLike<T>` as a type for anything being returned by moleculer, this will need to be converted to `Promise<T>`, regardless of whether you are using native promises or third-party promises.
## 8. Typescript definitions more strict
## 8. Typescript definitions are more strict
The 0.13 release was very loose on the typings for `params` and `meta` for the `Context` class and the `call`, `emit`, and `broadcast` methods from the `Context` and `ServiceBroker` classes. If Generics were not provided to these types, the default behavior would return `any`:
```ts
type GenericObject = { [name: string]: any };
Expand Down Expand Up @@ -382,17 +382,17 @@ class Context<P = unknown, M extends object = {}> {
broadcast(eventName: string): PromiseLike<void>;
```
Effectively, if generics are not provided then `params` will be typed as `unknown` and `meta` will be typed as an empty object. The `return` value of `call` will be `unknown`. You could pass any payload to `emit` and `broadcast` without any validation. Since moleculer is calling services and passing parameters over the wire, it cannot discern what the type of params and called action return values is without guidance. The generics provide that guidance and allow for type safety in your application.
Effectively, if generics are not provided then `params` will be typed as `unknown` and `meta` will be typed as an empty object. The `return` value of `call` will be `unknown`. You could pass any payload to `emit` and `broadcast` without any validation. Since moleculer is calling services and passing parameters over the wire, it cannot discern what the type of params and called action return values are without guidance. The generics provide that guidance and allow for type safety in your application.
If you've already been providing generics to these types then congratulations(!), there is nothing you need to do. If you have not been providing generics to these types then you are likely to find that you will be getting type errors because values that were previously typed as `any` will now be `unknown`. You will need to update your types to provide types for these generics to avoid the type errors.
There are a couple approaches to remedying these type issues:
There are a couple of approaches to remedying these type issues:
1. (**recommended**) Provided proper types for these generics in `Context`, `call`, `emit`, and `broadcast`. You will now have type safety for your `ctx.params`, `ctx.meta`, return values from `call`, `params` passed to `call`, and payloads passed to `emit` and `broadcast`.
2. (not recommended) Augment the moleculer module with your own local TS definitions that revert these types to their previous behavior. This will make your code work exactly as it was previously, with no type safety afforded.
2. (not recommended) Augment the moleculer module with your own local TS definitions that revert these types to their previous behavior. This will make your code work exactly as it was previously, with no type of safety afforded.
3. (not recommended) Replace all uses of the `Context` type in your application with `Context<GenericObject, GenericObject>`, `call` with `call<any, GenericObject>`, `emit` with `emit<any>` and `broadcast` with `broadcast<any>`. As with #2, you will still not have type safety, but it may represent a quick and dirty approach.
**NOTE:** The examples above show the changes to the `Context` class but similar changes were made to the `ServiceBroker` class as well. Any changes that you need to make for `Context` will be needed for `ServiceBroker` as well.
**:tada: Well, you are done! :clap:**
Happy coding in your up-to-date Moleculer project. If you need help, join to [Discord chat](https://discord.gg/j5cJYdu) and don't hesitate to ask Moleculer community.
Happy coding in your up-to-date Moleculer project. If you need help, join [Discord chat](https://discord.gg/j5cJYdu) and don't hesitate to ask Moleculer community.

0 comments on commit d88abb1

Please sign in to comment.