Skip to content

Commit 94fbe45

Browse files
committed
rewrite to TS
1 parent 514bcf9 commit 94fbe45

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

template/moleculer.config.js renamed to template/moleculer.config.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
"use strict";
1+
import type { BrokerOptions, MetricRegistry, ServiceBroker } from "moleculer";
2+
import { Errors } from "moleculer";
23

34
{{#needChannels}}
4-
const ChannelMiddleware = require("@moleculer/channels").Middleware;
5-
{{#tracing}}const ChannelTracing = require("@moleculer/channels").Tracing;{{/tracing}}
5+
import { Middleware as ChannelMiddleware } from "@moleculer/channels");
6+
{{#tracing}}import { Tracing as ChannelTracing } from "@moleculer/channels";{{/tracing}}
67
{{/needChannels}}
78

89
{{#needWorkflows}}
9-
const WorkflowsMiddleware = require("@moleculer/workflows").Middleware;
10+
import { Middleware as WorkflowsMiddleware } = require("@moleculer/workflows");
1011
{{/needWorkflows}}
1112

1213
/**
@@ -36,7 +37,7 @@ const WorkflowsMiddleware = require("@moleculer/workflows").Middleware;
3637
*
3738
* @type {import('moleculer').BrokerOptions}
3839
*/
39-
module.exports = {
40+
const brokerConfig: BrokerOptions = {
4041
// Namespace of nodes to segment your nodes on the same network.
4142
namespace: "",
4243
// Unique node identifier. Must be unique in a namespace.
@@ -96,7 +97,8 @@ module.exports = {
9697
// Backoff factor for delay. 2 means exponential backoff.
9798
factor: 2,
9899
// A function to check failed requests.
99-
check: err => err && !!err.retryable
100+
check: (err: Error) =>
101+
err && err instanceof Errors.MoleculerRetryableError && !!err.retryable,
100102
},
101103

102104
// Limit of calling level. If it reaches the limit, broker will throw an MaxCallLevelError error. (Infinite loop protection)
@@ -143,7 +145,7 @@ module.exports = {
143145
// Number of milliseconds to switch from open to half-open state
144146
halfOpenTime: 10 * 1000,
145147
// A function to check failed requests.
146-
check: err => err && err.code >= 500
148+
check: (err: Error) => err && err instanceof Errors.MoleculerError && err.code >= 500,
147149
},
148150

149151
// Settings of bulkhead feature. More info: https://moleculer.services/docs/0.15/fault-tolerance.html#Bulkhead
@@ -245,3 +247,5 @@ module.exports = {
245247

246248
}
247249
};
250+
251+
export = brokerConfig;

0 commit comments

Comments
 (0)