Skip to content

Commit c9877b3

Browse files
committed
refactor(utils): fix export issues and add logger types
1 parent 7f1de19 commit c9877b3

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from "./utils/async.utils";
33
export * from "./utils/cache.utils";
44
export * from "./utils/context-store.utils";
55
export * from "./utils/crypto.utils";
6+
export * from "./utils/decorators.utils";
67
export * from "./utils/dir.utils";
78
export * from "./utils/env.utils";
89
export * from "./utils/exception.utils";

src/utils/decorators.utils.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@
33
import "reflect-metadata";
44

55
// --- Sample Express interfaces for type safety ---
6-
export interface Request {
6+
interface Request {
77
query: any;
88
params: any;
99
body?: any;
1010
[key: string]: any;
1111
}
12-
export interface Response {
12+
interface Response {
1313
json: (body: any) => void;
1414
headersSent: boolean;
1515
[key: string]: any;
1616
}
17-
export type NextFunction = (err?: any) => void;
18-
export type RequestHandler = (
19-
req: Request,
20-
res: Response,
21-
next: NextFunction,
22-
) => any;
23-
export interface Router {
17+
type NextFunction = (err?: any) => void;
18+
type RequestHandler = (req: Request, res: Response, next: NextFunction) => any;
19+
interface Router {
2420
[method: string]: (path: string, ...handlers: RequestHandler[]) => void;
2521
}
2622
// --- End sample Express interfaces ---
@@ -29,7 +25,7 @@ const ROUTES_KEY = Symbol("routes");
2925
const MIDDLEWARE_KEY = Symbol("middlewares");
3026
const PARAMS_KEY = Symbol("params");
3127

32-
export type HttpMethod =
28+
type HttpMethod =
3329
| "get"
3430
| "post"
3531
| "put"

src/utils/logger.utils.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pino, { LoggerOptions, stdTimeFunctions } from "pino";
2-
import type { Logger } from "pino"; // Type-only import
2+
import type { Logger as PinoLogger } from "pino"; // Type-only import
33
import { Config } from "../config";
44
import { ContextStore, StoreKeys } from "./context-store.utils";
55

@@ -8,11 +8,21 @@ import { ContextStore, StoreKeys } from "./context-store.utils";
88
*/
99
const GLOBAL_LOGGER_KEY = Symbol.for("logger");
1010

11+
/**
12+
* Logger type for application-wide logging.
13+
*/
14+
export type Logger = pino.Logger;
15+
16+
/**
17+
* Logger levels for application-wide logging.
18+
*/
19+
export type LoggerLevels = pino.Level;
20+
1121
/**
1222
* Use an object compatible with either modern or legacy global scopes.
1323
*/
1424
export const _globalThis = typeof globalThis === "object" ? globalThis : global;
15-
const _global = _globalThis as unknown as { [GLOBAL_LOGGER_KEY]: Logger };
25+
const _global = _globalThis as unknown as { [GLOBAL_LOGGER_KEY]: PinoLogger };
1626

1727
/**
1828
* Initializes the global root logger according to app configuration.
@@ -56,8 +66,8 @@ function setupLogger(): void {
5666
*
5767
* @returns {Logger} The logger instance (request-bound or global root logger)
5868
*/
59-
export function getLogger(): Logger {
60-
const logger = ContextStore.get<Logger>(StoreKeys.LOGGER);
69+
export function getLogger(): PinoLogger {
70+
const logger = ContextStore.get<PinoLogger>(StoreKeys.LOGGER);
6171
if (logger) return logger;
6272

6373
if (!_global[GLOBAL_LOGGER_KEY]) {
@@ -76,8 +86,8 @@ export function getLogger(): Logger {
7686
*/
7787
export function createChildLogger(
7888
bindings: Record<string, any>,
79-
parentLogger?: Logger,
80-
): Logger {
89+
parentLogger?: PinoLogger,
90+
): PinoLogger {
8191
const logger = parentLogger || getLogger();
8292
return logger.child(bindings);
8393
}
@@ -92,7 +102,7 @@ export function createChildLogger(
92102
export function createRequestLogger(
93103
requestId: string,
94104
additionalContext: Record<string, any> = {},
95-
): Logger {
105+
): PinoLogger {
96106
const logger = createChildLogger({
97107
requestId,
98108
...additionalContext,

src/utils/middleware.utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { getLogger } from "./logger.utils";
99
/**
1010
* Type definitions for Express-compatible middleware
1111
*/
12-
export type Request = {
12+
type Request = {
1313
headers: Record<string, string | string[] | undefined>;
1414
method: string;
1515
url: string;
@@ -20,7 +20,7 @@ export type Request = {
2020
[key: string]: any;
2121
};
2222

23-
export type Response = {
23+
type Response = {
2424
status: (code: number) => Response;
2525
json: (data: any) => void;
2626
send: (data: any) => void;
@@ -30,9 +30,9 @@ export type Response = {
3030
[key: string]: any;
3131
};
3232

33-
export type NextFunction = (err?: Error | any) => void;
33+
type NextFunction = (err?: Error | any) => void;
3434

35-
export type Middleware = (
35+
type Middleware = (
3636
req: Request,
3737
res: Response,
3838
next: NextFunction,

0 commit comments

Comments
 (0)