From d7827616ea71b7e6328c6a85b80c2daec0b6f512 Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Wed, 21 Dec 2022 16:24:38 +0330 Subject: [PATCH] feat(nano-server): maybe promise type --- core/nano-server/src/nano-server.ts | 6 +++--- core/nano-server/src/type.ts | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/nano-server/src/nano-server.ts b/core/nano-server/src/nano-server.ts index fe212b9db..ab8834706 100644 --- a/core/nano-server/src/nano-server.ts +++ b/core/nano-server/src/nano-server.ts @@ -3,7 +3,7 @@ import {createServer} from 'node:http'; import {alwatrRegisteredList, createLogger} from '@alwatr/logger'; import {isNumber} from '@alwatr/math'; -import type {NanoServerConfig, ConnectionConfig, ParamKeyType, ParamValueType} from './type.js'; +import type {NanoServerConfig, ConnectionConfig, ParamKeyType, ParamValueType, MaybePromise} from './type.js'; import type { AlwatrServiceResponse, AlwatrServiceResponseFailed, @@ -149,7 +149,7 @@ export class AlwatrNanoServer { route: 'all' | `/${string}`, middleware: ( connection: AlwatrConnection - ) => AlwatrServiceResponse | Promise | null> | null, + ) => MaybePromise | null>, ): void { this._logger.logMethodArgs('route', {method, route}); @@ -288,7 +288,7 @@ export class AlwatrNanoServer { // prettier-ignore protected middlewareList: Record - AlwatrServiceResponse | null | Promise | null> + MaybePromise | null> >> = { ALL: {}, }; diff --git a/core/nano-server/src/type.ts b/core/nano-server/src/type.ts index 6b98f7384..f3f3f45ac 100644 --- a/core/nano-server/src/type.ts +++ b/core/nano-server/src/type.ts @@ -62,3 +62,5 @@ export interface ConnectionConfig { export type ParamKeyType = 'string' | 'number' | 'boolean'; export type ParamValueType = string | number | boolean | null; + +export type MaybePromise = T | Promise