Skip to content

Commit

Permalink
feat(nano-server): maybe promise type
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Dec 21, 2022
1 parent 94e181b commit d782761
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/nano-server/src/nano-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -149,7 +149,7 @@ export class AlwatrNanoServer {
route: 'all' | `/${string}`,
middleware: (
connection: AlwatrConnection
) => AlwatrServiceResponse<TData, TMeta> | Promise<AlwatrServiceResponse<TData, TMeta> | null> | null,
) => MaybePromise<AlwatrServiceResponse<TData, TMeta> | null>,
): void {
this._logger.logMethodArgs('route', {method, route});

Expand Down Expand Up @@ -288,7 +288,7 @@ export class AlwatrNanoServer {
// prettier-ignore
protected middlewareList: Record<string, Record<string,
(connection: AlwatrConnection) =>
AlwatrServiceResponse<unknown, unknown> | null | Promise<AlwatrServiceResponse<unknown, unknown> | null>
MaybePromise<AlwatrServiceResponse<unknown, unknown> | null>
>> = {
ALL: {},
};
Expand Down
2 changes: 2 additions & 0 deletions core/nano-server/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ export interface ConnectionConfig {

export type ParamKeyType = 'string' | 'number' | 'boolean';
export type ParamValueType = string | number | boolean | null;

export type MaybePromise<T> = T | Promise<T>

0 comments on commit d782761

Please sign in to comment.