Skip to content

Commit

Permalink
fix(nano-server): update docs and return type
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Dec 20, 2022
1 parent 53f4d95 commit df949c1
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions core/nano-server/src/nano-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ export class AlwatrNanoServer {
* const nanoServer = new AlwatrNanoServer();
*
* nanoServer.route('GET', '/', async (connection) => {
* connection.reply({
* return {
* ok: true,
* data: {
* app: 'Alwatr Nanoservice Starter Kit',
* message: 'Hello ;)',
* },
* });
* };
* });
* ```
*/
Expand Down Expand Up @@ -134,20 +134,22 @@ export class AlwatrNanoServer {
*
* ```ts
* nanoServer.route('GET', '/', async (connection) => {
* connection.reply({
* return {
* ok: true,
* data: {
* app: 'Alwatr Nanoservice Starter Kit',
* message: 'Hello ;)',
* },
* });
* });
* };
* ```
*/
route<TMeta = Record<string, unknown>, TData = Record<string, unknown>>(
method: 'ALL' | Methods,
route: 'all' | `/${string}`,
middleware: (connection: AlwatrConnection) => AlwatrServiceResponse<TData, TMeta> | null,
middleware: (
connection: AlwatrConnection
) => AlwatrServiceResponse<TData, TMeta> | Promise<AlwatrServiceResponse<TData, TMeta> | null> | null,
): void {
this._logger.logMethodArgs('route', {method, route});

Expand All @@ -170,13 +172,13 @@ export class AlwatrNanoServer {
* Example:
* ```ts
* nanoServer.route('GET', '/', async (connection) => {
* connection.reply({
* return {
* ok: true,
* data: {
* app: 'Alwatr Nanoservice Starter Kit',
* message: 'Hello ;)',
* },
* });
* };
* });
* ```
*/
Expand Down Expand Up @@ -334,7 +336,7 @@ export class AlwatrNanoServer {
method: connection.method,
route,
});
connection.reply({
this.reply(serverResponse, {
ok: false,
statusCode: 500,
errorCode: 'http_server_middleware_error',
Expand All @@ -348,7 +350,7 @@ export class AlwatrNanoServer {
}

protected _notFoundListener = (connection: AlwatrConnection): void => {
connection.reply({
this.reply(connection.serverResponse, {
ok: false,
statusCode: 404,
errorCode: 'not_found',
Expand Down Expand Up @@ -430,10 +432,9 @@ export class AlwatrConnection {
* Example:
* ```ts
* const bodyData = await connection.requireJsonBody();
* if (bodyData == null) return;
* ```
*/
async requireJsonBody<T>(): Promise<T | null> {
async requireJsonBody<T>(): Promise<T> {
// if request content type is json
if (this.incomingMessage.headers['content-type'] !== 'application/json') {
throw new Error('require_body_json');
Expand Down Expand Up @@ -526,11 +527,10 @@ export class AlwatrConnection {
* Example:
* ```ts
* const params = connection.requireQueryParams<{id: string}>({id: 'string'});
* if (params == null) return;
* console.log(params.id);
* ```
*/
requireQueryParams<T extends QueryParameters = QueryParameters>(params: Record<string, ParamKeyType>): T | null {
requireQueryParams<T extends QueryParameters = QueryParameters>(params: Record<string, ParamKeyType>): T {
const parsedParams: Record<string, ParamValueType> = {};

for (const paramName in params) {
Expand Down

0 comments on commit df949c1

Please sign in to comment.