Skip to content

Commit 6232ac3

Browse files
committed
biome update
1 parent 0598a21 commit 6232ac3

9 files changed

Lines changed: 46 additions & 27 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ Main feature of that release is full TypeScript support insluding mongoose model
5151
- **[BREAKING]** Mongoose v9. <https://mongoosejs.com/docs/migrating_to_9.html>.
5252
- **[BREAKING]** Vitest v4 <https://vitest.dev/guide/migration.html#vitest-4>
5353

54+
---
55+
## [5.0.0-beta.45]
56+
- **[BREAKING]** rate-limiter-flexible v9->v10
57+
- **[BREAKING]** typecript v5->v6
5458

5559
---
5660
## [5.0.0-beta.44]
5761

5862
- **[NEW]** Logout method
5963
- **[Update]** set model typing
60-
- **[BREAKING]** rate-limiter-flexible v9->v10
61-
- **[BREAKING]** typecript v5->v6
64+
6265

6366

6467
---

src/modules/AbstractController.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ type MiddlewareWithParamsTuple = [
1616
export type TMiddleware = Array<
1717
typeof AbstractMiddleware | MiddlewareWithParamsTuple
1818
>;
19+
// biome-ignore lint/complexity/noBannedTypes: Route handlers are generic callable values from user controllers
20+
type RouteHandler = Function;
1921
type RouteObject = {
20-
handler: Function;
22+
handler: RouteHandler;
2123
description?: string;
2224
middleware?: TMiddleware | null;
2325
request?: (unknown & { fields: unknown }) | null; // fields part of you magic
@@ -26,7 +28,7 @@ type RouteObject = {
2628

2729
export type RouteParams = {
2830
[method: string]: {
29-
[path: string]: RouteObject | Function;
31+
[path: string]: RouteObject | RouteHandler;
3032
};
3133
};
3234

@@ -92,7 +94,7 @@ class AbstractController extends Base {
9294
* Register controller middleware
9395
*/
9496
for (const middleware of middlewaresInfo) {
95-
(this.router[middleware.method as keyof IRouter] as Function)(
97+
(this.router[middleware.method as keyof IRouter] as RouteHandler)(
9698
middleware.path,
9799
new middleware.MiddlewareFunction(
98100
this.app,
@@ -121,7 +123,7 @@ class AbstractController extends Base {
121123
if (Object.prototype.toString.call(routeObject) !== '[object Object]') {
122124
// for support firect pass function instead of object
123125
routeObject = {
124-
handler: routeObject as unknown as Function,
126+
handler: routeObject as unknown as RouteHandler,
125127
request: null,
126128
query: null,
127129
middleware: null,
@@ -164,7 +166,9 @@ class AbstractController extends Base {
164166
// `Controller '${this.getConstructorName()}' register function '${fnName}' for method '${verb}' and path '${path}' Full path '${fullPath}'`,
165167
// );
166168

167-
let additionalMiddlewares: any;
169+
let additionalMiddlewares:
170+
| ReturnType<AbstractMiddleware['getMiddleware']>[]
171+
| undefined;
168172

169173
if (routeAdditionalMiddlewares.length > 0) {
170174
additionalMiddlewares = Array.from(
@@ -174,7 +178,7 @@ class AbstractController extends Base {
174178
);
175179
}
176180

177-
(this.router[verb as keyof IRouter] as Function)(
181+
(this.router[verb as keyof IRouter] as RouteHandler)(
178182
path,
179183
additionalMiddlewares || [],
180184
async (req: FrameworkRequest, res: Response, next: NextFunction) => {

src/modules/BaseCli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class Cli extends Base {
189189

190190
const result = await c.run().catch((e: { stack: unknown }) => {
191191
this.logger?.error(e.stack);
192+
return undefined;
192193
});
193194

194195
return result;

src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface IApp {
3030
getModel(
3131
modelName: string,
3232
): AbstractModel['mongooseModel'] | false | TBaseModel;
33-
runCliCommand(commandName: string): Promise<boolean | void>;
33+
runCliCommand(commandName: string): Promise<boolean | undefined>;
3434
updateConfig(
3535
configName: string,
3636
config: Record<string, unknown>,
@@ -473,7 +473,7 @@ class Server {
473473
),
474474
);
475475
const { transports } = this.app.getConfig('log') as TLogConfig;
476-
function IsConstructor(f: Function) {
476+
function IsConstructor(f: (...args: never) => unknown) {
477477
try {
478478
Reflect.construct(String, [], f);
479479
} catch {

src/services/cache/Cache.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class Cache extends Base {
4444
* @param onNotFound callback that will be executed if value not found on cahce
4545
* @param storeTime how long we should store value on cache
4646
*/
47-
async getSetValue(
47+
async getSetValue<T = unknown>(
4848
keyValue: string,
49-
onNotFound: () => Promise<any>,
49+
onNotFound: () => Promise<T>,
5050
storeTime = 60 * 5,
5151
) {
5252
await this.whenReady;
@@ -69,11 +69,12 @@ class Cache extends Base {
6969
}),
7070
);
7171

72-
let result = await this.redisClient.get(key);
73-
if (!result) {
72+
let parsedResult: T | undefined;
73+
const cached = await this.redisClient.get(key);
74+
if (!cached) {
7475
this.logger?.verbose(`getSetValueFromCache not found for key ${key}`);
7576
try {
76-
result = await onNotFound();
77+
parsedResult = await onNotFound();
7778
} catch (e) {
7879
this.logger?.error(`Cache onNotFound for key '${key}' error: ${e}`);
7980
this.promiseMapping.delete(key);
@@ -83,7 +84,7 @@ class Cache extends Base {
8384

8485
this.redisClient.set(
8586
key,
86-
JSON.stringify(result, (_jsonkey, value) =>
87+
JSON.stringify(parsedResult, (_jsonkey, value) =>
8788
typeof value === 'bigint' ? `${value}n` : value,
8889
),
8990
{
@@ -92,13 +93,13 @@ class Cache extends Base {
9293
);
9394
} else {
9495
this.logger?.verbose(
95-
`getSetValueFromCache FROM CACHE key ${key}, value ${result.substring(
96+
`getSetValueFromCache FROM CACHE key ${key}, value ${cached.substring(
9697
0,
9798
100,
9899
)}`,
99100
);
100101
try {
101-
result = JSON.parse(result, (_jsonkey, value) => {
102+
parsedResult = JSON.parse(cached, (_jsonkey, value) => {
102103
if (typeof value === 'string' && /^\d+n$/.test(value)) {
103104
return BigInt(value.slice(0, value.length - 1));
104105
}
@@ -111,9 +112,9 @@ class Cache extends Base {
111112
}
112113
}
113114

114-
resolve(result);
115+
resolve(parsedResult);
115116
this.promiseMapping.delete(key);
116-
return result;
117+
return parsedResult;
117118
}
118119

119120
/**

src/services/http/middleware/AbstractMiddleware.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class AbstractMiddleware extends Base {
4747
_req: FrameworkRequest,
4848
_res: Response,
4949
next: NextFunction,
50-
): Promise<void | Response> {
50+
): // biome-ignore lint/suspicious/noConfusingVoidType: Express middleware legitimately returns void or Response
51+
Promise<void | Response> {
5152
this.logger?.warn('Middleware is not implemented');
5253
return next();
5354
}

src/services/http/middleware/Auth.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import type { Response } from 'express';
12
import { beforeAll, describe, expect, it } from 'vitest';
23
import { appInstance } from '../../../helpers/appInstance.ts';
4+
import type { FrameworkRequest } from '../HttpServer.ts';
35
import Auth from './Auth.ts';
6+
import type { GetUserByTokenAppInfo } from './GetUserByToken.ts';
7+
8+
type AuthRequest = FrameworkRequest & GetUserByTokenAppInfo;
49

510
describe('atuh middleware methods', () => {
611
let middleware: Auth;
@@ -26,7 +31,11 @@ describe('atuh middleware methods', () => {
2631
user: true,
2732
},
2833
};
29-
await middleware.middleware(req as any, {} as any, nextFunction);
34+
await middleware.middleware(
35+
req as unknown as AuthRequest,
36+
{} as unknown as Response,
37+
nextFunction,
38+
);
3039

3140
expect(isCalled).toBeTruthy();
3241
});
@@ -44,7 +53,7 @@ describe('atuh middleware methods', () => {
4453
appInfo: {}, // no user
4554
};
4655
await middleware.middleware(
47-
req as any,
56+
req as unknown as AuthRequest,
4857
{
4958
status(statusCode: number) {
5059
status = statusCode;
@@ -54,7 +63,7 @@ describe('atuh middleware methods', () => {
5463
isSend = true;
5564
return this;
5665
},
57-
} as any,
66+
} as unknown as Response,
5867
nextFunction,
5968
);
6069

src/services/http/middleware/I18n.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { appInstance } from '../../../helpers/appInstance.ts';
33
import I18n from './I18n.ts';
44

55
describe('i18n middleware methods', () => {
6-
let middleware: any;
6+
let middleware: I18n;
77

88
beforeAll(() => {
99
middleware = new I18n(appInstance);

src/services/logging/SentryTransport.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SentryTransport extends Transport {
3939
this.loadSentryTransport(opts);
4040
}
4141

42-
private async loadSentryTransport(opts: Transport.TransportStreamOptions) {
42+
private async loadSentryTransport(_opts: Transport.TransportStreamOptions) {
4343
if (this.#initializationAttempted) {
4444
return;
4545
}
@@ -54,7 +54,7 @@ class SentryTransport extends Transport {
5454
this.#sentry = sentry;
5555

5656
console.log('[Framework] Sentry Winston transport loaded successfully');
57-
} catch (error) {
57+
} catch (_error) {
5858
// Sentry is not installed - this is fine for a framework
5959
console.log(
6060
'[Framework] Sentry Winston transport not available (package not installed)',

0 commit comments

Comments
 (0)