Skip to content

Commit 3ef5dd4

Browse files
committed
fixing types
1 parent 96fcf13 commit 3ef5dd4

File tree

14 files changed

+37
-54
lines changed

14 files changed

+37
-54
lines changed

meta.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
module.exports = function(values) {
44
return {
5-
/** @type {Array<import('inquirer').Question>} */
65
questions: [
76
{
87
type: "confirm",
@@ -126,25 +125,6 @@ module.exports = function(values) {
126125

127126
metalsmith: {
128127
before(metalsmith) {
129-
/**
130-
* @typedef Metadata
131-
* @property {Boolean} apiGW
132-
* @property {Boolean} apiGQL
133-
* @property {Boolean} apiIO
134-
* @property {Boolean} needTransporter
135-
* @property {String} transporter
136-
* @property {Boolean} needCacher
137-
* @property {Boolean} dbService
138-
* @property {Boolean} needChannels
139-
* @property {Boolean} needWorkflows
140-
* @property {String} channels
141-
* @property {Boolean} metrics
142-
* @property {Boolean} tracing
143-
* @property {Boolean} docker
144-
* @property {Boolean} lint
145-
*/
146-
147-
/** @type {Metadata} */
148128
const data = metalsmith.metadata();
149129

150130
data.redis = data.cacher == "Redis" || data.transporter == "Redis" || data.channels == "Redis" || data.needWorkflows;

template/mixins/db.mixin.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export type DbServiceThis = Service & DbServiceMethods;
1313
export default function (collection: string): DbServiceSchema {
1414
const cacheCleanEventName = `cache.clean.${collection}`;
1515

16-
/** @type {MoleculerDB & ServiceSchema} */
1716
const schema: DbServiceSchema = {
1817
/**
1918
* Mixins. More info: https://moleculer.services/docs/0.15/services.html#Mixins
@@ -75,7 +74,13 @@ export default function (collection: string): DbServiceSchema {
7574
* @param {Context} ctx
7675
* @param {object} opts
7776
*/
78-
async entityChanged(type: string, data: object, oldData: object, ctx: Context, opts: object) {
77+
async entityChanged(
78+
type: string,
79+
data: object,
80+
oldData: object,
81+
ctx: Context,
82+
opts: object
83+
) {
7984
ctx.broadcast(cacheCleanEventName);
8085
}
8186
},

template/moleculer.config.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { BrokerOptions, MetricRegistry, ServiceBroker } from "moleculer";
1+
import type { BrokerOptions } from "moleculer";
22
import { Errors } from "moleculer";
33

44
{{#needChannels}}
@@ -7,7 +7,7 @@ import { Middleware as ChannelMiddleware } from "@moleculer/channels";
77
{{/needChannels}}
88

99
{{#needWorkflows}}
10-
import { Middleware as WorkflowsMiddleware } = require("@moleculer/workflows");
10+
import { Middleware as WorkflowsMiddleware } from "@moleculer/workflows";
1111
{{/needWorkflows}}
1212

1313
/**
@@ -34,8 +34,6 @@ import { Middleware as WorkflowsMiddleware } = require("@moleculer/workflows");
3434
* }
3535
* }
3636
* }
37-
*
38-
* @type {import('moleculer').BrokerOptions}
3937
*/
4038
const brokerConfig: BrokerOptions = {
4139
// Namespace of nodes to segment your nodes on the same network.
@@ -248,4 +246,4 @@ const brokerConfig: BrokerOptions = {
248246
}
249247
};
250248

251-
export = brokerConfig;
249+
export default brokerConfig;

template/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "{{projectName}}",
33
"version": "1.0.0",
44
"description": "My Moleculer-based microservices project",
5+
"type": "module",
56
"scripts": {
67
"build": "tsc --project tsconfig.build.json",
78
"dev": "tsx ./node_modules/moleculer/bin/moleculer-runner.js --config moleculer.config.ts --hot --repl services/**/*.service.ts",

template/services/api.service.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Context, ServiceSchema } from "moleculer";
2-
import type { IncomingRequest, ServerResponse } from "http";
2+
import type { IncomingMessage, ServerResponse } from "http";
33

44
import ApiGateway from "moleculer-web";
55
import type { ApiSettingsSchema } from "moleculer-web";
@@ -47,7 +47,7 @@ const ApiService: ServiceSchema<ApiSettingsSchema> = {
4747
{{/apiGQL}}
4848
],
4949

50-
/** @type {ApiSettingsSchema} More info: https://moleculer.services/docs/0.15/moleculer-web.html */
50+
/** More info: https://moleculer.services/docs/0.15/moleculer-web.html */
5151
settings: {
5252
// Exposed port
5353
port: process.env.PORT || 3000,
@@ -88,7 +88,7 @@ const ApiService: ServiceSchema<ApiSettingsSchema> = {
8888
onBeforeCall(
8989
ctx: Context<unknown, Meta>,
9090
route: Route,
91-
req: IncomingRequest,
91+
req: IncomingMessage,
9292
res: GatewayResponse,
9393
): void {
9494
// Set request headers to context meta
@@ -101,7 +101,7 @@ const ApiService: ServiceSchema<ApiSettingsSchema> = {
101101
onAfterCall(
102102
ctx: Context,
103103
route: Route,
104-
req: IncomingRequest,
104+
req: IncomingMessage,
105105
res: GatewayResponse,
106106
data: unknown,
107107
): unknown {
@@ -146,7 +146,6 @@ const ApiService: ServiceSchema<ApiSettingsSchema> = {
146146
options: {}
147147
}
148148

149-
/** @type {import('moleculer-io').IOSetting} */
150149
// io: {},
151150
},
152151

@@ -164,7 +163,7 @@ const ApiService: ServiceSchema<ApiSettingsSchema> = {
164163
authenticate(
165164
ctx: Context,
166165
route: Route,
167-
req: IncomingRequest,
166+
req: IncomingMessage,
168167
): Record<string, unknown> | null {
169168
// Read the token from header
170169
const auth = req.headers["authorization"];
@@ -194,7 +193,7 @@ const ApiService: ServiceSchema<ApiSettingsSchema> = {
194193
*
195194
* PLEASE NOTE, IT'S JUST AN EXAMPLE IMPLEMENTATION. DO NOT USE IN PRODUCTION!
196195
*/
197-
authorize(ctx: Context<null, Meta>, route: Route, req: IncomingRequest) {
196+
authorize(ctx: Context<null, Meta>, route: Route, req: IncomingMessage) {
198197
// Get the authenticated user.
199198
const user = ctx.meta.user;
200199

template/services/greeter.service.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const GreeterService: ServiceSchema<GreeterSettings> = {
2525
* Settings. More info: https://moleculer.services/docs/0.15/services.html#Settings
2626
*/
2727
settings: {
28-
defaultName: "Moleculer",
28+
defaultName: "Moleculer"
2929
},
3030

3131
/**
@@ -50,7 +50,7 @@ const GreeterService: ServiceSchema<GreeterSettings> = {
5050
{{#apiGQL}}graphql: {
5151
query: "hello: String"
5252
},{{/apiGQL}}
53-
async handler(this: GreeterThis/* , ctx: Context */): string {
53+
async handler(this: GreeterThis /* , ctx: Context */): Promise<string> {
5454
return "Hello Moleculer";
5555
}
5656
},
@@ -68,8 +68,7 @@ const GreeterService: ServiceSchema<GreeterSettings> = {
6868
{{#apiGQL}}graphql: {
6969
mutation: "welcome(name: String!): String"
7070
},{{/apiGQL}}
71-
/** @param {import('moleculer').Context<{name: String}>} ctx */
72-
async handler(this: GreeterThis, ctx: Context<ActionHelloParams>): string {
71+
async handler(this: GreeterThis, ctx: Context<ActionHelloParams>): Promise<string> {
7372
return `Welcome, ${ctx.params.name}`;
7473
}
7574
}

template/services/products.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ const ProductsService: ServiceSchema<ProductSettings> & { methods: DbServiceMeth
196196
{{#apiGQL}}graphql: {
197197
mutation: "decreaseQuantity(id: String!, value: Int!): Product"
198198
},{{/apiGQL}}
199-
/** @param {Context<{id: String, value: Number}>} ctx */
200199
async handler(this: ProductsThis, ctx: Context<ActionQuantityParams>): Promise<object> {
201200
// Get current quantity
202201
const adapter = await this.getAdapter(ctx);

template/test/integration/api.spec.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { afterAll, beforeAll, describe, it, expect, vi } from "vitest";
22

3-
43
process.env.PORT = 0; // Use random ports during tests
54

65
import HTTPrequest from "supertest";
@@ -13,20 +12,20 @@ import { request, gql } from "graphql-request";
1312

1413
import { Context, ServiceBroker } from "moleculer";
1514
// Load service schemas
16-
import APISchema from "../../../services/api.service";
17-
import GreeterSchema from "../../../services/greeter.service";
15+
import APISchema from "../../services/api.service.js";
16+
import GreeterSchema from "../../services/greeter.service.js";
1817
{{#dbService}}
19-
import ProductsSchema from "../../../services/products.service";
18+
import ProductsSchema from "../../services/products.service.js";
2019
{{/dbService}}
2120

2221
describe("Test HTTP API gateway", () => {
23-
let broker = new ServiceBroker({ logger: false });
22+
const broker = new ServiceBroker({ logger: false });
2423
broker.sendToChannel = vi.fn();
2524

26-
let greeterService = broker.createService(GreeterSchema);
27-
let apiService = broker.createService(APISchema);
25+
const greeterService = broker.createService(GreeterSchema);
26+
const apiService = broker.createService(APISchema);
2827
{{#dbService}}
29-
let productsService = broker.createService(ProductsSchema);
28+
const productsService = broker.createService(ProductsSchema);
3029
productsService.seedDB = null; // Disable seeding
3130
{{/dbService}}
3231

template/test/integration/products.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { afterAll, beforeAll, describe, it, expect, vi } from "vitest";
22
import { ServiceBroker } from "moleculer";
33
import type { ServiceSchema } from "moleculer";
44
import type { ProductEntity } from "../../services/products.service";
5-
import TestService from "../../services/products.service";
5+
import TestService from "../../services/products.service.js";
66

77
describe("Test 'products' service", () => {
88
describe("Test actions", () => {

template/test/unit/mixins/db.mixin.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { afterAll, beforeAll, describe, it, expect, vi } from "vitest";
22

33
import { Context, ServiceBroker } from "moleculer";
4-
import type { Service, ServiceAsyncLifecycleHandler, ServiceEventHandler } from "moleculer";
5-
import DbMixin from "../../../mixins/db.mixin";
4+
import DbMixin from "../../../mixins/db.mixin.js";
65

76
describe("Test DB mixin", () => {
87
describe("Test schema generator", () => {

0 commit comments

Comments
 (0)