Deprecation warning when declaring custom actions for internal services
DenisFerrero opened this issue · 1 comments
Prerequisites
Please answer the following questions for yourself before submitting an issue.
- I am running the latest version
- I checked the documentation and found no answer
- I checked to make sure that this issue has not already been filed
- I'm reporting the issue to the correct repository
Current Behavior
Since I updated moleculer to the newer version (0.14.26) on project startup keeps to being logged this message DeprecationWarning: Using 'schemaMods' parameter in 'broker.createService' is deprecated. Use 'mixins' instead..
Expected Behavior
No deprecation warning showed
Failure Information
I analyzed a little the code and at this point of the service-broker is being still used the schemaMods. The fact is that I cannot directly handle the situation as the only log is caused by the internal service $node because I declared some custom actions directly inside the moleculer.config like explained in the documentation.
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
- Declare the broker with a configuration to declare/overwrite internalServices actions
Reproduce code snippet
const { ServiceBroker } = require("moleculer");
const broker = new ServiceBroker({
internalServices: {
$node: {
actions: {
demo (ctx) {
return "Hello!";
}
}
}
}
});
broker.start();
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
- Moleculer version: v0.14.26
- NodeJS version: v16.15.0
- Operating System: Windows 10 PRO
Failure Logs
[2022-12-08T09:26:00.011Z] INFO pc-sandbox-1676/BROKER: Moleculer v0.14.26 is starting...
[2022-12-08T09:26:00.014Z] INFO pc-sanbox-1676/BROKER: Namespace: <not defined>
[2022-12-08T09:26:00.014Z] INFO pc-sanbox-1676/BROKER: Node ID: pc-sandbox-1676
[2022-12-08T09:26:00.016Z] INFO pc-sanbox-1676/REGISTRY: Strategy: RoundRobinStrategy
[2022-12-08T09:26:00.017Z] INFO pc-sanbox-1676/REGISTRY: Discoverer: LocalDiscoverer
[2022-12-08T09:26:00.032Z] INFO pc-sanbox-1676/BROKER: Serializer: JSONSerializer
[2022-12-08T09:26:00.201Z] INFO pc-sanbox-1676/BROKER: Validator: FastestValidator
[2022-12-08T09:26:00.204Z] INFO pc-sanbox-1676/BROKER: Registered 13 middleware(s).
DeprecationWarning: Using 'schemaMods' parameter in 'broker.createService' is deprecated. Use 'mixins' instead.
[2022-12-08T09:26:00.228Z] INFO pc-sanbox-1676/REGISTRY: '$node' service is registered.
[2022-12-08T09:26:00.230Z] INFO pc-sanbox-1676/$NODE: Service '$node' started.
[2022-12-08T09:26:00.230Z] INFO pc-sanbox-1676/BROKER: ✔ ServiceBroker with 1 service(s) started successfully in 6ms.
[2022-12-08T09:26:00.334Z] INFO pc-sanbox-1676/$NODE: Service '$node' stopped.
[2022-12-08T09:26:00.335Z] INFO pc-sanbox-1676/BROKER: ServiceBroker is stopped. Good bye.
Suggested solution
This code should be replaced to the current registerInternalServices
, here the default schema is injected as a mixin if an eventual custom schema is provided
registerInternalServices(opts) {
opts = utils.isObject(opts) ? opts : {};
const interalsSchema = require("./internals")(this);
let definitiveSchema = {};
if (opts["$node"]) {
definitiveSchema = opts["$node"];
if (!definitiveSchema.mixins) definitiveSchema.mixins = [];
definitiveSchema.mixins.push(interalsSchema);
} else {
definitiveSchema = interalsSchema;
}
this.createService(definitiveSchema);
}
Closing issue as it has been merged