From b7b032cc5b30fb100f29ba7899c03f72ae3650fe Mon Sep 17 00:00:00 2001 From: Thomas Cruveilher <38007824+Sorikairox@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:56:17 +0000 Subject: [PATCH] docs: fix JSDoc formatting --- .github/workflows/main.yml | 2 +- README.md | 9 +- deno.json | 2 +- spec/queue.test.ts | 9 +- src/app.ts | 72 ++-- src/events/events.ts | 13 +- src/exception/filter/decorator.ts | 4 +- src/exception/filter/executor.ts | 6 +- src/exception/filter/interface.ts | 4 +- src/exception/http/exceptions.ts | 414 ++++++++++----------- src/guard/decorator.ts | 4 +- src/guard/executor.ts | 6 +- src/hook/executor.ts | 7 +- src/hook/interfaces.ts | 2 +- src/hook/mod.ts | 2 +- src/injector/decorator.ts | 26 +- src/injector/injectable/constructor.ts | 8 +- src/injector/injectable/decorator.ts | 12 +- src/injector/injector.ts | 6 +- src/kv-queue/decorator.ts | 6 + src/kv-queue/module.ts | 16 +- src/logger.ts | 4 +- src/metadata/decorator.ts | 12 +- src/metadata/helper.ts | 26 +- src/mod.ts | 2 +- src/module/constructor.ts | 5 +- src/module/decorator.ts | 16 +- src/router/controller/constructor.ts | 4 +- src/router/controller/decorator.ts | 40 +- src/router/controller/params/decorators.ts | 57 +-- src/router/middleware/decorator.ts | 14 +- src/router/middleware/executor.ts | 4 +- src/router/middleware/global-container.ts | 4 +- src/router/router.ts | 9 +- src/schedule/decorator.ts | 2 +- src/schedule/enum.ts | 13 +- 36 files changed, 456 insertions(+), 386 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2b3e22c4..b01d7b1f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,4 +22,4 @@ jobs: deno-version: canary - name: Publish package - run: deno publish \ No newline at end of file + run: deno publish diff --git a/README.md b/README.md index 5087c25e..e00a8bb2 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,9 @@ ## Warning -From version 2.4.0, Danet is only available via [JSR](https://jsr.io/) at [@danet/core](https://jsr.io/@danet/core). It's a step closer to runtime agnosticism. +From version 2.4.0, Danet is only available via [JSR](https://jsr.io/) at +[@danet/core](https://jsr.io/@danet/core). It's a step closer to runtime +agnosticism. ## Description @@ -52,8 +54,8 @@ bug on our [Github Repository](https://github.com/Savory/Danet) and ## Installation ```sh - deno install --global -A -n danet jsr:@danet/cli - danet new +deno install --global -A -n danet jsr:@danet/cli +danet new ``` ## Documentation @@ -64,7 +66,6 @@ bug on our [Github Repository](https://github.com/Savory/Danet) and [Read our blog](https://savory.github.io/) - ## Contributing - Contributions make the open-source community such an amazing place to learn, diff --git a/deno.json b/deno.json index cae6c588..00e495bc 100644 --- a/deno.json +++ b/deno.json @@ -7,7 +7,7 @@ "./validation": "./validation.ts", "./hook": "./src/hook/mod.ts", "./logger": "./src/logger.ts" - }, + }, "lint": { "include": [ "src/" diff --git a/spec/queue.test.ts b/spec/queue.test.ts index c7ea969d..25d31ff0 100644 --- a/spec/queue.test.ts +++ b/spec/queue.test.ts @@ -7,7 +7,12 @@ import { Module, OnQueueMessage, } from '../mod.ts'; -import { assertEquals, assertSpyCall, spy, assertSpyCalls } from '../src/deps_test.ts'; +import { + assertEquals, + assertSpyCall, + assertSpyCalls, + spy, +} from '../src/deps_test.ts'; const sleep = (msec: number) => new Promise((resolve) => setTimeout(resolve, msec)); @@ -64,7 +69,7 @@ Deno.test('Queue Module', async (t) => { assertEquals(await res.text(), 'OK'); await sleep(500); - assertSpyCalls(callback, 1) + assertSpyCalls(callback, 1); assertSpyCall(callback, 0, { args: [payload], }); diff --git a/src/app.ts b/src/app.ts index 791f50e1..fd070bb3 100644 --- a/src/app.ts +++ b/src/app.ts @@ -4,41 +4,39 @@ * @example * ```typescript * import { - * Controller, - * DanetApplication, - * Get, - * Module, - * Query, - * } from '../src/mod.ts'; + * Controller, + * DanetApplication, + * Get, + * Module, + * Query, + * } from '../src/mod.ts'; * + * @Controller('') + * class FirstController { + * constructor() { + * } * - * @Controller('') - * class FirstController { - * constructor() { - * } + * @Get('hello-world/:name') + * getHelloWorld( + * @Param('name') name: string, + * ) { + * return `Hello World ${name}`; + * } + * } * + * @Module({ + * controllers: [FirstController] + * }) + * class FirstModule {} * - * @Get('hello-world/:name') - * getHelloWorld( - * @Param('name') name: string, - * ) { - * return `Hello World ${name}`; - * } - * } + * const app = new DanetApplication(); + * await app.init(FirstModule); * - * @Module({ - * controllers: [FirstController] - * }) - * class FirstModule {} - * - * const app = new DanetApplication(); - * await app.init(FirstModule); - * - * let port = Number(Deno.env.get('PORT')); - * if (isNaN(port)) { - * port = 3000; - * } - * app.listen(port); + * let port = Number(Deno.env.get('PORT')); + * if (isNaN(port)) { + * port = 3000; + * } + * app.listen(port); * ``` */ @@ -188,7 +186,7 @@ export class DanetApplication { /** * Initializes the application with the provided module. - * + * * @param Module - The constructor of the module to initialize. * @returns A promise that resolves when the initialization process is complete. */ @@ -202,7 +200,7 @@ export class DanetApplication { /** * Closes the application by executing the necessary hooks and shutting down the internal HTTP server. - * + * * @async * @returns {Promise} A promise that resolves when the application has been closed. */ @@ -214,18 +212,18 @@ export class DanetApplication { /** * Starts the HTTP server and begins listening on the specified port. - * + * * @param {number} [port=3000] - The port number on which the server will listen. * @returns {Promise<{ port: number }>} A promise that resolves with an object containing the port number. - * + * * @remarks * This method initializes an `AbortController` to manage the server's lifecycle and uses Deno's `serve` function to start the server. * The server will log a message indicating the port it is listening on. - * + * * @example * ```typescript * const app = new DanetApplication(); - * await app.init(FirstModule); + * await app.init(FirstModule); * const { port } = app.listen(3000); * ``` */ @@ -247,7 +245,7 @@ export class DanetApplication { /** * Get hono application instance. - * + * * @returns {Application} The hono instance. */ get router(): Application { diff --git a/src/events/events.ts b/src/events/events.ts index 4b5e3d98..b848284f 100644 --- a/src/events/events.ts +++ b/src/events/events.ts @@ -4,22 +4,23 @@ import { Logger } from '../mod.ts'; type Listener

= (payload: P) => void; /** - * @class EventEmitter - * @description A class that provides a simple event-driven architecture for subscribing, emitting, and unsubscribing events. - * + * Provides event-driven architecture for subscribing, emitting, and unsubscribing events. + * * @example + * ```ts * const emitter = new EventEmitter(); - * + * * // Subscribe to an event * emitter.subscribe('eventName', (payload) => { * console.log(payload); * }); - * + * * // Emit an event * emitter.emit('eventName', { key: 'value' }); - * + * * // Unsubscribe from an event * emitter.unsubscribe('eventName'); + * ``` */ export class EventEmitter { private logger: Logger = new Logger('EventEmitter'); diff --git a/src/exception/filter/decorator.ts b/src/exception/filter/decorator.ts index b259730d..4803dedd 100644 --- a/src/exception/filter/decorator.ts +++ b/src/exception/filter/decorator.ts @@ -19,5 +19,5 @@ export const filterCatchTypeMetadataKey = 'errorCaught'; * @returns A metadata function that sets the metadata for the error type to catch. */ export function Catch(ErrorType: Constructor): MetadataFunction { - return SetMetadata(filterCatchTypeMetadataKey, ErrorType); -} \ No newline at end of file + return SetMetadata(filterCatchTypeMetadataKey, ErrorType); +} diff --git a/src/exception/filter/executor.ts b/src/exception/filter/executor.ts index 965ee713..5c978664 100644 --- a/src/exception/filter/executor.ts +++ b/src/exception/filter/executor.ts @@ -11,11 +11,9 @@ import { Injector } from '../../injector/injector.ts'; import { WebSocketPayload } from '../../router/websocket/payload.ts'; /** - * @class FilterExecutor - * @description - * The `FilterExecutor` class is responsible for executing exception filters + * Responsible for executing exception filters * based on metadata and handling errors within the context of an HTTP request. - * It utilizes an injector to manage dependencies and retrieve filter instances. + * It utilizes the injector to manage dependencies and retrieve filter instances. * * @constructor * @param {Injector} injector - The dependency injector used to manage and retrieve filter instances. diff --git a/src/exception/filter/interface.ts b/src/exception/filter/interface.ts index 056e83d6..078adda0 100644 --- a/src/exception/filter/interface.ts +++ b/src/exception/filter/interface.ts @@ -2,10 +2,10 @@ import { HttpContext } from '../../router/router.ts'; /** * Interface representing an exception filter. - * + * * This interface defines a method to handle exceptions that occur within an HTTP context. * Implementations of this interface can provide custom logic for handling different types of exceptions. - * + * * @interface ExceptionFilter */ export interface ExceptionFilter { diff --git a/src/exception/http/exceptions.ts b/src/exception/http/exceptions.ts index 95db2ac2..f01de05b 100644 --- a/src/exception/http/exceptions.ts +++ b/src/exception/http/exceptions.ts @@ -12,16 +12,16 @@ import { HTTP_STATUS } from './enum.ts'; * @extends {Error} */ export class HttpException extends Error { - /** - * Creates an instance of HttpException. - * - * @param {number} status - The HTTP status code associated with the exception. - * @param {string} description - A brief description of the exception. - */ - constructor(readonly status: number, description: string) { - super(`${status} - ${description}`); - this.name = this.constructor.name; - } + /** + * Creates an instance of HttpException. + * + * @param {number} status - The HTTP status code associated with the exception. + * @param {string} description - A brief description of the exception. + */ + constructor(readonly status: number, description: string) { + super(`${status} - ${description}`); + this.name = this.constructor.name; + } } /** @@ -32,12 +32,12 @@ export class HttpException extends Error { * @extends {HttpException} */ export class ForbiddenException extends HttpException { - /** - * Creates an instance of ForbiddenException. - */ - constructor() { - super(HTTP_STATUS.FORBIDDEN, 'Forbidden'); - } + /** + * Creates an instance of ForbiddenException. + */ + constructor() { + super(HTTP_STATUS.FORBIDDEN, 'Forbidden'); + } } /** @@ -48,12 +48,12 @@ export class ForbiddenException extends HttpException { * @extends {HttpException} */ export class BadRequestException extends HttpException { - /** - * Creates an instance of BadRequestException. - */ - constructor() { - super(HTTP_STATUS.BAD_REQUEST, 'Bad request'); - } + /** + * Creates an instance of BadRequestException. + */ + constructor() { + super(HTTP_STATUS.BAD_REQUEST, 'Bad request'); + } } /** @@ -64,12 +64,12 @@ export class BadRequestException extends HttpException { * @extends {HttpException} */ export class UnauthorizedException extends HttpException { - /** - * Creates an instance of UnauthorizedException. - */ - constructor() { - super(HTTP_STATUS.UNAUTHORIZED, 'Unauthorized'); - } + /** + * Creates an instance of UnauthorizedException. + */ + constructor() { + super(HTTP_STATUS.UNAUTHORIZED, 'Unauthorized'); + } } /** @@ -80,12 +80,12 @@ export class UnauthorizedException extends HttpException { * @extends {HttpException} */ export class PaymentRequiredException extends HttpException { - /** - * Creates an instance of PaymentRequiredException. - */ - constructor() { - super(HTTP_STATUS.PAYMENT_REQUIRED, 'Payment required'); - } + /** + * Creates an instance of PaymentRequiredException. + */ + constructor() { + super(HTTP_STATUS.PAYMENT_REQUIRED, 'Payment required'); + } } /** @@ -96,12 +96,12 @@ export class PaymentRequiredException extends HttpException { * @extends {HttpException} */ export class NotFoundException extends HttpException { - /** - * Creates an instance of NotFoundException. - */ - constructor() { - super(HTTP_STATUS.NOT_FOUND, 'Not found'); - } + /** + * Creates an instance of NotFoundException. + */ + constructor() { + super(HTTP_STATUS.NOT_FOUND, 'Not found'); + } } /** @@ -112,12 +112,12 @@ export class NotFoundException extends HttpException { * @extends {HttpException} */ export class MethodNotAllowedException extends HttpException { - /** - * Creates an instance of MethodNotAllowedException. - */ - constructor() { - super(HTTP_STATUS.METHOD_NOT_ALLOWED, 'Method not allowed'); - } + /** + * Creates an instance of MethodNotAllowedException. + */ + constructor() { + super(HTTP_STATUS.METHOD_NOT_ALLOWED, 'Method not allowed'); + } } /** @@ -128,12 +128,12 @@ export class MethodNotAllowedException extends HttpException { * @extends {HttpException} */ export class NotAcceptableException extends HttpException { - /** - * Creates an instance of NotAcceptableException. - */ - constructor() { - super(HTTP_STATUS.NOT_ACCEPTABLE, 'Not acceptable'); - } + /** + * Creates an instance of NotAcceptableException. + */ + constructor() { + super(HTTP_STATUS.NOT_ACCEPTABLE, 'Not acceptable'); + } } /** @@ -144,15 +144,15 @@ export class NotAcceptableException extends HttpException { * @extends {HttpException} */ export class ProxyAuthenticationRequiredException extends HttpException { - /** - * Creates an instance of ProxyAuthenticationRequiredException. - */ - constructor() { - super( - HTTP_STATUS.PROXY_AUTHENTICATION_REQUIRED, - 'Proxy authentication required', - ); - } + /** + * Creates an instance of ProxyAuthenticationRequiredException. + */ + constructor() { + super( + HTTP_STATUS.PROXY_AUTHENTICATION_REQUIRED, + 'Proxy authentication required', + ); + } } /** @@ -163,12 +163,12 @@ export class ProxyAuthenticationRequiredException extends HttpException { * @extends {HttpException} */ export class RequestTimeoutException extends HttpException { - /** - * Creates an instance of RequestTimeoutException. - */ - constructor() { - super(HTTP_STATUS.REQUEST_TIMEOUT, 'Request timeout'); - } + /** + * Creates an instance of RequestTimeoutException. + */ + constructor() { + super(HTTP_STATUS.REQUEST_TIMEOUT, 'Request timeout'); + } } /** @@ -179,12 +179,12 @@ export class RequestTimeoutException extends HttpException { * @extends {HttpException} */ export class ConflictException extends HttpException { - /** - * Creates an instance of ConflictException. - */ - constructor() { - super(HTTP_STATUS.CONFLICT, 'Conflict'); - } + /** + * Creates an instance of ConflictException. + */ + constructor() { + super(HTTP_STATUS.CONFLICT, 'Conflict'); + } } /** @@ -195,12 +195,12 @@ export class ConflictException extends HttpException { * @extends {HttpException} */ export class GoneException extends HttpException { - /** - * Creates an instance of GoneException. - */ - constructor() { - super(HTTP_STATUS.GONE, 'Gone'); - } + /** + * Creates an instance of GoneException. + */ + constructor() { + super(HTTP_STATUS.GONE, 'Gone'); + } } /** @@ -211,12 +211,12 @@ export class GoneException extends HttpException { * @extends {HttpException} */ export class LengthRequiredException extends HttpException { - /** - * Creates an instance of LengthRequiredException. - */ - constructor() { - super(HTTP_STATUS.LENGTH_REQUIRED, 'Length required'); - } + /** + * Creates an instance of LengthRequiredException. + */ + constructor() { + super(HTTP_STATUS.LENGTH_REQUIRED, 'Length required'); + } } /** @@ -227,12 +227,12 @@ export class LengthRequiredException extends HttpException { * @extends {HttpException} */ export class PreconditionFailedException extends HttpException { - /** - * Creates an instance of PreconditionFailedException. - */ - constructor() { - super(HTTP_STATUS.PRECONDITION_FAILED, 'Precondition failed'); - } + /** + * Creates an instance of PreconditionFailedException. + */ + constructor() { + super(HTTP_STATUS.PRECONDITION_FAILED, 'Precondition failed'); + } } /** @@ -243,12 +243,12 @@ export class PreconditionFailedException extends HttpException { * @extends {HttpException} */ export class PayloadTooLargeException extends HttpException { - /** - * Creates an instance of PayloadTooLargeException. - */ - constructor() { - super(HTTP_STATUS.PAYLOAD_TOO_LARGE, 'Payload too large'); - } + /** + * Creates an instance of PayloadTooLargeException. + */ + constructor() { + super(HTTP_STATUS.PAYLOAD_TOO_LARGE, 'Payload too large'); + } } /** @@ -259,12 +259,12 @@ export class PayloadTooLargeException extends HttpException { * @extends {HttpException} */ export class URITooLongException extends HttpException { - /** - * Creates an instance of URITooLongException. - */ - constructor() { - super(HTTP_STATUS.URI_TOO_LONG, 'URI too long'); - } + /** + * Creates an instance of URITooLongException. + */ + constructor() { + super(HTTP_STATUS.URI_TOO_LONG, 'URI too long'); + } } /** @@ -275,12 +275,12 @@ export class URITooLongException extends HttpException { * @extends {HttpException} */ export class UnsupportedMediaTypeException extends HttpException { - /** - * Creates an instance of UnsupportedMediaTypeException. - */ - constructor() { - super(HTTP_STATUS.UNSUPPORTED_MEDIA_TYPE, 'Unsupported media type'); - } + /** + * Creates an instance of UnsupportedMediaTypeException. + */ + constructor() { + super(HTTP_STATUS.UNSUPPORTED_MEDIA_TYPE, 'Unsupported media type'); + } } /** @@ -291,15 +291,15 @@ export class UnsupportedMediaTypeException extends HttpException { * @extends {HttpException} */ export class RequestedRangeNotSatisfiableException extends HttpException { - /** - * Creates an instance of RequestedRangeNotSatisfiableException. - */ - constructor() { - super( - HTTP_STATUS.REQUESTED_RANGE_NOT_SATISFIABLE, - 'Requested range not statisfiable', - ); - } + /** + * Creates an instance of RequestedRangeNotSatisfiableException. + */ + constructor() { + super( + HTTP_STATUS.REQUESTED_RANGE_NOT_SATISFIABLE, + 'Requested range not statisfiable', + ); + } } /** @@ -310,12 +310,12 @@ export class RequestedRangeNotSatisfiableException extends HttpException { * @extends {HttpException} */ export class ExpectationFailedException extends HttpException { - /** - * Creates an instance of ExpectationFailedException. - */ - constructor() { - super(HTTP_STATUS.EXPECTATION_FAILED, 'Expectation failed'); - } + /** + * Creates an instance of ExpectationFailedException. + */ + constructor() { + super(HTTP_STATUS.EXPECTATION_FAILED, 'Expectation failed'); + } } /** @@ -326,12 +326,12 @@ export class ExpectationFailedException extends HttpException { * @extends {HttpException} */ export class IAmATeapotException extends HttpException { - /** - * Creates an instance of IAmATeapotException. - */ - constructor() { - super(HTTP_STATUS.I_AM_A_TEAPOT, 'I am a teapot'); - } + /** + * Creates an instance of IAmATeapotException. + */ + constructor() { + super(HTTP_STATUS.I_AM_A_TEAPOT, 'I am a teapot'); + } } /** @@ -342,12 +342,12 @@ export class IAmATeapotException extends HttpException { * @extends {HttpException} */ export class MisdirectedException extends HttpException { - /** - * Creates an instance of MisdirectedException. - */ - constructor() { - super(HTTP_STATUS.MISDIRECTED, 'Misdirected'); - } + /** + * Creates an instance of MisdirectedException. + */ + constructor() { + super(HTTP_STATUS.MISDIRECTED, 'Misdirected'); + } } /** @@ -358,12 +358,12 @@ export class MisdirectedException extends HttpException { * @extends {HttpException} */ export class UnprocessableEntityException extends HttpException { - /** - * Creates an instance of UnprocessableEntityException. - */ - constructor() { - super(HTTP_STATUS.UNPROCESSABLE_ENTITY, 'Unprocessable entity'); - } + /** + * Creates an instance of UnprocessableEntityException. + */ + constructor() { + super(HTTP_STATUS.UNPROCESSABLE_ENTITY, 'Unprocessable entity'); + } } /** @@ -374,12 +374,12 @@ export class UnprocessableEntityException extends HttpException { * @extends {HttpException} */ export class FailedDependencyException extends HttpException { - /** - * Creates an instance of FailedDependencyException. - */ - constructor() { - super(HTTP_STATUS.FAILED_DEPENDENCY, 'Failed dependency'); - } + /** + * Creates an instance of FailedDependencyException. + */ + constructor() { + super(HTTP_STATUS.FAILED_DEPENDENCY, 'Failed dependency'); + } } /** @@ -390,12 +390,12 @@ export class FailedDependencyException extends HttpException { * @extends {HttpException} */ export class PreconditionRequiredException extends HttpException { - /** - * Creates an instance of PreconditionRequiredException. - */ - constructor() { - super(HTTP_STATUS.PRECONDITION_REQUIRED, 'Precondition required'); - } + /** + * Creates an instance of PreconditionRequiredException. + */ + constructor() { + super(HTTP_STATUS.PRECONDITION_REQUIRED, 'Precondition required'); + } } /** @@ -406,12 +406,12 @@ export class PreconditionRequiredException extends HttpException { * @extends {HttpException} */ export class TooManyRequestsException extends HttpException { - /** - * Creates an instance of TooManyRequestsException. - */ - constructor() { - super(HTTP_STATUS.TOO_MANY_REQUESTS, 'Too many requests'); - } + /** + * Creates an instance of TooManyRequestsException. + */ + constructor() { + super(HTTP_STATUS.TOO_MANY_REQUESTS, 'Too many requests'); + } } /** @@ -422,12 +422,12 @@ export class TooManyRequestsException extends HttpException { * @extends {HttpException} */ export class InternalServerErrorException extends HttpException { - /** - * Creates an instance of InternalServerErrorException. - */ - constructor() { - super(HTTP_STATUS.INTERNAL_SERVER_ERROR, 'Internal server error'); - } + /** + * Creates an instance of InternalServerErrorException. + */ + constructor() { + super(HTTP_STATUS.INTERNAL_SERVER_ERROR, 'Internal server error'); + } } /** @@ -438,12 +438,12 @@ export class InternalServerErrorException extends HttpException { * @extends {HttpException} */ export class NotImplementedException extends HttpException { - /** - * Creates an instance of NotImplementedException. - */ - constructor() { - super(HTTP_STATUS.NOT_IMPLEMENTED, 'Not implemented'); - } + /** + * Creates an instance of NotImplementedException. + */ + constructor() { + super(HTTP_STATUS.NOT_IMPLEMENTED, 'Not implemented'); + } } /** @@ -454,12 +454,12 @@ export class NotImplementedException extends HttpException { * @extends {HttpException} */ export class BadGatewayException extends HttpException { - /** - * Creates an instance of BadGatewayException. - */ - constructor() { - super(HTTP_STATUS.BAD_GATEWAY, 'Bad gateway'); - } + /** + * Creates an instance of BadGatewayException. + */ + constructor() { + super(HTTP_STATUS.BAD_GATEWAY, 'Bad gateway'); + } } /** @@ -470,12 +470,12 @@ export class BadGatewayException extends HttpException { * @extends {HttpException} */ export class ServiceUnavailableException extends HttpException { - /** - * Creates an instance of ServiceUnavailableException. - */ - constructor() { - super(HTTP_STATUS.SERVICE_UNAVAILABLE, 'Service unavailable'); - } + /** + * Creates an instance of ServiceUnavailableException. + */ + constructor() { + super(HTTP_STATUS.SERVICE_UNAVAILABLE, 'Service unavailable'); + } } /** @@ -486,12 +486,12 @@ export class ServiceUnavailableException extends HttpException { * @extends {HttpException} */ export class GatewayTimeoutException extends HttpException { - /** - * Creates an instance of GatewayTimeoutException. - */ - constructor() { - super(HTTP_STATUS.GATEWAY_TIMEOUT, 'Gateway timeout'); - } + /** + * Creates an instance of GatewayTimeoutException. + */ + constructor() { + super(HTTP_STATUS.GATEWAY_TIMEOUT, 'Gateway timeout'); + } } /** @@ -502,12 +502,12 @@ export class GatewayTimeoutException extends HttpException { * @extends {HttpException} */ export class HttpVersionNotSupportedException extends HttpException { - /** - * Creates an instance of HttpVersionNotSupportedException. - */ - constructor() { - super(HTTP_STATUS.HTTP_VERSION_NOT_SUPPORTED, 'Http version not supported'); - } + /** + * Creates an instance of HttpVersionNotSupportedException. + */ + constructor() { + super(HTTP_STATUS.HTTP_VERSION_NOT_SUPPORTED, 'Http version not supported'); + } } /** @@ -519,14 +519,14 @@ export class HttpVersionNotSupportedException extends HttpException { * @template T */ export class NotValidBodyException extends HttpException { - reasons: T; - /** - * Creates an instance of NotValidBodyException. - * - * @param {T} reasons - The reasons why the body is not valid. - */ - constructor(reasons: T) { - super(HTTP_STATUS.BAD_REQUEST, 'Body bad formatted'); - this.reasons = reasons; - } -} \ No newline at end of file + reasons: T; + /** + * Creates an instance of NotValidBodyException. + * + * @param {T} reasons - The reasons why the body is not valid. + */ + constructor(reasons: T) { + super(HTTP_STATUS.BAD_REQUEST, 'Body bad formatted'); + this.reasons = reasons; + } +} diff --git a/src/guard/decorator.ts b/src/guard/decorator.ts index 3d440ae6..ff386569 100644 --- a/src/guard/decorator.ts +++ b/src/guard/decorator.ts @@ -4,9 +4,9 @@ import { MetadataFunction, SetMetadata } from '../metadata/decorator.ts'; export const guardMetadataKey = 'authGuards'; /** * Applies a guard to a route handler or controller. - * + * * https://danet.land/overview/guards.html - * + * * @param guard - The constructor of the guard to be applied. * @returns A function that sets the metadata for the guard. */ diff --git a/src/guard/executor.ts b/src/guard/executor.ts index e69d322a..d483ee66 100644 --- a/src/guard/executor.ts +++ b/src/guard/executor.ts @@ -9,11 +9,9 @@ import { guardMetadataKey } from './decorator.ts'; import { AuthGuard } from './interface.ts'; /** - * @class GuardExecutor - * @description - * The `GuardExecutor` class is responsible for executing various guards in a given execution context. + * Responsible for executing various guards in a given execution context. * It handles the execution of global guards, controller-level guards, and method-level guards. - * + * https://danet.land/overview/guards.html * @constructor * @param {Injector} injector - The injector instance used to retrieve and manage dependencies. */ diff --git a/src/hook/executor.ts b/src/hook/executor.ts index d17207f0..6fd1c228 100644 --- a/src/hook/executor.ts +++ b/src/hook/executor.ts @@ -4,7 +4,6 @@ * Provides a class to execute hooks for every injectable. */ - import { InjectableHelper } from '../injector/injectable/helper.ts'; import { Injector } from '../injector/injector.ts'; import { MetadataHelper } from '../metadata/helper.ts'; @@ -26,7 +25,7 @@ export class HookExecutor { * Executes a specified hook on every injectable retrieved from the injector. * It iterates through all injectables, checks if they are objects, and then * executes the hook on each instance. - * + * * @param hookName - The name of the hook to be executed. */ public async executeHookForEveryInjectable(hookName: hookName) { @@ -42,11 +41,11 @@ export class HookExecutor { /** * Executes a specified hook on a given instance if the instance is marked as global. - * + * * @param instance - The instance on which the hook is to be executed. * @param hookName - The name of the hook to be executed. */ - + // deno-lint-ignore no-explicit-any private async executeInstanceHook(instance: any, hookName: hookName) { if (InjectableHelper.isGlobal(instance?.constructor)) { diff --git a/src/hook/interfaces.ts b/src/hook/interfaces.ts index e4b7eb49..37d9bc38 100644 --- a/src/hook/interfaces.ts +++ b/src/hook/interfaces.ts @@ -32,7 +32,7 @@ export interface BeforeControllerMethodIsCalled { /** * Enum representing the names of various hooks in the application. - * + * * @enum {string} * @property {string} APP_CLOSE - Hook triggered when the application is closing. * @property {string} APP_BOOTSTRAP - Hook triggered when the application is bootstrapping. diff --git a/src/hook/mod.ts b/src/hook/mod.ts index 518fc953..f26e989d 100644 --- a/src/hook/mod.ts +++ b/src/hook/mod.ts @@ -4,4 +4,4 @@ */ export * from './executor.ts'; -export * from './interfaces.ts'; \ No newline at end of file +export * from './interfaces.ts'; diff --git a/src/injector/decorator.ts b/src/injector/decorator.ts index 4368aac9..5de00d87 100644 --- a/src/injector/decorator.ts +++ b/src/injector/decorator.ts @@ -11,21 +11,21 @@ export function getInjectionTokenMetadataKey(parameterIndex: number): string { * Decorator to inject using token. * * Get example here https://danet.land/fundamentals/dynamic-modules.html#module-configuration - * + * * @param token - Optional token to identify the dependency. * @returns A decorator function that sets the metadata for the injection token. */ export function Inject(token?: string): DecoratorFunction { - return ( - // deno-lint-ignore no-explicit-any - target: Record | any, - propertyKey: string | symbol | undefined, - parameterIndex: number, -) => { - MetadataHelper.setMetadata( - getInjectionTokenMetadataKey(parameterIndex), - token, - target, - ); + return ( + // deno-lint-ignore no-explicit-any + target: Record | any, + propertyKey: string | symbol | undefined, + parameterIndex: number, + ) => { + MetadataHelper.setMetadata( + getInjectionTokenMetadataKey(parameterIndex), + token, + target, + ); + }; } -}; diff --git a/src/injector/injectable/constructor.ts b/src/injector/injectable/constructor.ts index 5ad21dc1..f9363d3c 100644 --- a/src/injector/injectable/constructor.ts +++ b/src/injector/injectable/constructor.ts @@ -1,16 +1,18 @@ import { Constructor } from '../../utils/constructor.ts'; +/** + * Type Alias for Constructor + */ export type InjectableConstructor = Constructor; /** @deprecated Prefer plain object of Type UseClassInjector */ export class TokenInjector { constructor(public useClass: InjectableConstructor, public token: string) { } - } /** * Represents an injector configuration that uses a class constructor for dependency injection. - * + * * @typedef {Object} UseClassInjector * @property {InjectableConstructor} useClass - The class constructor to be used for injection. * @property {string} token - The token that identifies the dependency. @@ -21,7 +23,7 @@ export type UseClassInjector = { }; /** * Represents an injector that uses a specific value for dependency injection. - * + * * @typedef {Object} UseValueInjector * @property {any} useValue - The value to be used for injection. * @property {string} token - The token that identifies the value. diff --git a/src/injector/injectable/decorator.ts b/src/injector/injectable/decorator.ts index 8912690a..7b9f0d07 100644 --- a/src/injector/injectable/decorator.ts +++ b/src/injector/injectable/decorator.ts @@ -2,7 +2,7 @@ import { MetadataFunction, SetMetadata } from '../../metadata/decorator.ts'; /** * The different scopes for dependency injection. - * + * * @enum {string} * @property {string} GLOBAL - Represents a global scope where the instance is shared across the entire application. * @property {string} REQUEST - Represents a request scope where a new instance is created for each request. @@ -16,9 +16,9 @@ export enum SCOPE { /** * Options for the Injectable decorator. - * + * * @interface InjectableOption - * + * * @property {SCOPE} scope - The scope in which the injectable should be instantiated. */ export interface InjectableOption { @@ -29,7 +29,7 @@ export const injectionData = 'dependency-injection'; /** * Mark class as an injectable. - * + * * @template T - The type of the class being decorated. * @param {InjectableOption} [options={ scope: SCOPE.GLOBAL }] - The options for the injectable, including the scope. * @returns {MetadataFunction} - A function that sets the metadata for the injectable. @@ -37,5 +37,5 @@ export const injectionData = 'dependency-injection'; export function Injectable( options: InjectableOption = { scope: SCOPE.GLOBAL }, ): MetadataFunction { - return SetMetadata(injectionData, options) -} \ No newline at end of file + return SetMetadata(injectionData, options); +} diff --git a/src/injector/injector.ts b/src/injector/injector.ts index d6c6fc5e..7f7ce97f 100644 --- a/src/injector/injector.ts +++ b/src/injector/injector.ts @@ -22,7 +22,7 @@ import { ModuleMetadata } from '../mod.ts'; * available types, and context-specific injectables. It also handles the * bootstrapping of modules, resolving of controllers and injectables, and * managing the lifecycle of dependencies. - * + * * @class * @property {Map Promise | unknown>} resolved - A map of resolved instances. * @property {Map} availableTypes - A map of available types for injection. @@ -77,7 +77,7 @@ export class Injector { /** * Retrieves an instance of the specified type from the injector. - * + * * @template T - The type of the instance to retrieve. * @param {Constructor | string} Type - The constructor function or string identifier of the type to retrieve. * @param {ExecutionContext} [ctx] - Optional execution context to pass to the instance. @@ -93,7 +93,7 @@ export class Injector { /** * Bootstraps the given module by registering its injectables and resolving its controllers. - * + * * @param module - The module metadata to bootstrap, containing controllers and injectables. * @returns A promise that resolves when the module has been fully bootstrapped. */ diff --git a/src/kv-queue/decorator.ts b/src/kv-queue/decorator.ts index c7a06f2b..8b733953 100644 --- a/src/kv-queue/decorator.ts +++ b/src/kv-queue/decorator.ts @@ -1,6 +1,12 @@ import { MetadataHelper } from '../metadata/mod.ts'; import { queueListenerMetadataKey } from './constants.ts'; +/** + * Method decorator that registers a method as a listener for a specific queue channel. + * + * @param channel - The name of the queue channel to listen to. + * @returns A method decorator function. + */ export const OnQueueMessage = (channel: string): MethodDecorator => { return (_target, _propertyKey, descriptor) => { MetadataHelper.setMetadata( diff --git a/src/kv-queue/module.ts b/src/kv-queue/module.ts index b399a6e8..e173e756 100644 --- a/src/kv-queue/module.ts +++ b/src/kv-queue/module.ts @@ -1,6 +1,14 @@ import { OnAppBootstrap, OnAppClose } from '../hook/interfaces.ts'; import { MetadataHelper } from '../metadata/helper.ts'; -import { InjectableConstructor, injector, Logger, Module, ModuleConstructor, TokenInjector, UseValueInjector } from '../mod.ts'; +import { + InjectableConstructor, + injector, + Logger, + Module, + ModuleConstructor, + TokenInjector, + UseValueInjector, +} from '../mod.ts'; import { KV_QUEUE_NAME, queueListenerMetadataKey } from './constants.ts'; import { KvQueue } from './kv.ts'; @@ -12,8 +20,10 @@ export class KvQueueModule implements OnAppBootstrap { constructor() {} public static forRoot(kvName?: string): { - injectables: Array, - module: typeof KvQueueModule + injectables: Array< + InjectableConstructor | TokenInjector | UseValueInjector + >; + module: typeof KvQueueModule; } { return { injectables: [{ token: KV_QUEUE_NAME, useValue: kvName }, KvQueue], diff --git a/src/logger.ts b/src/logger.ts index c21ebd19..0edd3ae1 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -9,12 +9,12 @@ import { Injectable } from './injector/injectable/decorator.ts'; /** * A Logger class to handle logging with optional namespace and color-coded output. - * + * * @remarks * This class provides methods to log messages with different severity levels (log, error, warn). * It supports optional namespaces for better context in logs and uses color functions to * differentiate log types. - * + * * @example * ```typescript * const logger = new Logger('MyNamespace'); diff --git a/src/metadata/decorator.ts b/src/metadata/decorator.ts index 84feee6f..fe77847c 100644 --- a/src/metadata/decorator.ts +++ b/src/metadata/decorator.ts @@ -1,8 +1,8 @@ -/** -** metadataDecorator -** Provides decorator to set Metadata -** @module -*/ +/** + ** metadataDecorator + ** Provides decorator to set Metadata + ** @module + */ import { ControllerConstructor } from '../router/controller/constructor.ts'; import { MetadataHelper } from './helper.ts'; @@ -14,7 +14,7 @@ import { MetadataHelper } from './helper.ts'; * @param propertyKey - An optional property key for the target. * @param descriptor - An optional property descriptor for the target. */ -export type MetadataFunction = ( +export type MetadataFunction = ( // deno-lint-ignore ban-types target: ControllerConstructor | Object, propertyKey?: string | symbol, diff --git a/src/metadata/helper.ts b/src/metadata/helper.ts index b2d8f18c..eaa61272 100644 --- a/src/metadata/helper.ts +++ b/src/metadata/helper.ts @@ -1,14 +1,32 @@ -/** +/** * metadata * Provides metadata helper functions * Dependencies: Reflect * @module -*/ + */ import { Reflect } from '../deps.ts'; +/** + * A helper class for managing metadata on objects and their properties. + * + * This class provides static methods to determine if a value is an object, + * retrieve metadata from an object or its property, and set metadata on an + * object or its property. + * + * @example + * ```ts + * // Check if a value is an object + * const isObject = MetadataHelper.IsObject(someValue); + * + * // Retrieve metadata from an object + * const metadataValue = MetadataHelper.getMetadata('metadataKey', someObject); + * + * // Set metadata on an object + * MetadataHelper.setMetadata('metadataKey', 'metadataValue', someObject); + * ``` + */ export class MetadataHelper { - /** * Determines if the provided value is an object. * @@ -53,7 +71,7 @@ export class MetadataHelper { * @param target - The target object to set the metadata on. * @param property - Optional. The property of the target object to set the metadata on. * If not provided, the metadata is set on the target object itself. - * + * * @returns void */ static setMetadata( diff --git a/src/mod.ts b/src/mod.ts index a854efda..19310398 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -1,6 +1,6 @@ /** * @module - * + * * A probably too big module that exports almost everything. */ diff --git a/src/module/constructor.ts b/src/module/constructor.ts index ae483155..b94b271a 100644 --- a/src/module/constructor.ts +++ b/src/module/constructor.ts @@ -1,4 +1,7 @@ import { Constructor } from '../utils/constructor.ts'; -/* A ModuleConstructor is simply a Constructor */ +/** + * Type Alias for Constructor + */ + export type ModuleConstructor = Constructor; diff --git a/src/module/decorator.ts b/src/module/decorator.ts index e531ed90..f162f5aa 100644 --- a/src/module/decorator.ts +++ b/src/module/decorator.ts @@ -7,9 +7,9 @@ import { UseClassInjector, UseValueInjector } from '../mod.ts'; /** * Metadata for a module. - * + * * https://danet.land/overview/modules.html - * + * * @property {Array} [imports] - Optional array of modules or dynamic modules to be imported. * @property {ControllerConstructor[]} [controllers] - Optional array of controller constructors. * @property {Array} [injectables] - Optional array of injectables, which can be constructors, value injectors, or class injectors. @@ -24,12 +24,12 @@ export interface ModuleMetadata { /** * Represents a dynamic module in the application. - * + * * https://danet.land/fundamentals/dynamic-modules.html - * + * * @interface DynamicModule * @extends {ModuleMetadata} - * + * * @property {ModuleConstructor} module - The constructor of the module. */ export interface DynamicModule extends ModuleMetadata { @@ -42,12 +42,14 @@ export const moduleMetadataKey = 'module'; * Module Decorator. * * https://danet.land/overview/modules.html - * + * * @template T - The type of the class to which the metadata will be attached. * @param {ModuleMetadata} options - The metadata options to be attached to the class. * @returns {(Type: Constructor) => void} - A function that takes a class constructor and attaches the metadata to it. */ -export function Module(options: ModuleMetadata): ((Type: Constructor) => void) { +export function Module( + options: ModuleMetadata, +): (Type: Constructor) => void { return (Type: Constructor): void => { MetadataHelper.setMetadata(moduleMetadataKey, options, Type); }; diff --git a/src/router/controller/constructor.ts b/src/router/controller/constructor.ts index e7017626..f5cb693f 100644 --- a/src/router/controller/constructor.ts +++ b/src/router/controller/constructor.ts @@ -1,4 +1,6 @@ import { Constructor } from '../../utils/constructor.ts'; -/* A simple Constructor */ +/** + * Type Alias for Constructor + */ export type ControllerConstructor = Constructor; diff --git a/src/router/controller/decorator.ts b/src/router/controller/decorator.ts index f0cd4515..b32e00ec 100644 --- a/src/router/controller/decorator.ts +++ b/src/router/controller/decorator.ts @@ -2,9 +2,9 @@ import { MetadataHelper } from '../../metadata/helper.ts'; import { MetadataFunction, SetMetadata } from '../../metadata/decorator.ts'; /** * Represents the HTTP methods that can be used in routing. - * + * * @typedef {('GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD')} HttpMethod - * + * * @example * // Example usage: * const method: HttpMethod = 'GET'; @@ -28,7 +28,7 @@ export type HttpMethod = export function Controller(endpoint = ''): MetadataFunction { return SetMetadata('endpoint', endpoint); } -type MappingDecoratorFunction = ((endpoint?: string) => MethodDecorator); +type MappingDecoratorFunction = (endpoint?: string) => MethodDecorator; function createMappingDecorator(method?: HttpMethod): MappingDecoratorFunction { return (endpoint = ''): MethodDecorator => { @@ -44,9 +44,9 @@ function createMappingDecorator(method?: HttpMethod): MappingDecoratorFunction { /** * Define a method as a GET request handler. - * + * * This decorator can be used to annotate controller methods to handle HTTP GET requests. - * + * * @example * ```typescript * @Get('/path') @@ -54,12 +54,12 @@ function createMappingDecorator(method?: HttpMethod): MappingDecoratorFunction { * return 'This is a GET request'; * } * ``` - * + * * @type {MappingDecoratorFunction} */ export const Get: MappingDecoratorFunction = createMappingDecorator('GET'); /** - * Define a method as a POST request handler . + * Define a method as a POST request handler . * * @example * ```typescript * @Post('/path') @@ -70,7 +70,7 @@ export const Get: MappingDecoratorFunction = createMappingDecorator('GET'); */ export const Post: MappingDecoratorFunction = createMappingDecorator('POST'); /** - * Define a method as a PUT request handler . + * Define a method as a PUT request handler . * * @example * ```typescript * @Put('/path') @@ -81,7 +81,7 @@ export const Post: MappingDecoratorFunction = createMappingDecorator('POST'); */ export const Put: MappingDecoratorFunction = createMappingDecorator('PUT'); /** - * Define a method as a PATCH request handler . + * Define a method as a PATCH request handler . * * @example * ```typescript * @Patch('/path') @@ -92,7 +92,7 @@ export const Put: MappingDecoratorFunction = createMappingDecorator('PUT'); */ export const Patch: MappingDecoratorFunction = createMappingDecorator('PATCH'); /** - * Define a method as a DELETE request handler . + * Define a method as a DELETE request handler . * * @example * ```typescript * @Delete('/path') @@ -101,9 +101,11 @@ export const Patch: MappingDecoratorFunction = createMappingDecorator('PATCH'); * } * ``` */ -export const Delete: MappingDecoratorFunction = createMappingDecorator('DELETE'); +export const Delete: MappingDecoratorFunction = createMappingDecorator( + 'DELETE', +); /** - * Define a method as an OPTIONS request handler . + * Define a method as an OPTIONS request handler . * * @example * ```typescript * @Options('/path') @@ -112,9 +114,11 @@ export const Delete: MappingDecoratorFunction = createMappingDecorator('DELETE') * } * ``` */ -export const Options: MappingDecoratorFunction = createMappingDecorator('OPTIONS'); +export const Options: MappingDecoratorFunction = createMappingDecorator( + 'OPTIONS', +); /** - * Define a method as an HEAD request handler . + * Define a method as an HEAD request handler . * * @example * ```typescript * @Head('/path') @@ -125,7 +129,7 @@ export const Options: MappingDecoratorFunction = createMappingDecorator('OPTIONS */ export const Head: MappingDecoratorFunction = createMappingDecorator('HEAD'); /** - * Define a method as a request handler for all HTTP METHOD . + * Define a method as a request handler for all HTTP METHOD . * * @example * ```typescript * @All('/path') @@ -136,7 +140,7 @@ export const Head: MappingDecoratorFunction = createMappingDecorator('HEAD'); */ export const All: MappingDecoratorFunction = createMappingDecorator(); /** - * Define a method as a request handler that will send event with SSE. + * Define a method as a request handler that will send event with SSE. * * @example * ```typescript * @SSE('/path') @@ -168,7 +172,9 @@ export const All: MappingDecoratorFunction = createMappingDecorator(); * } * ``` */ -export const SSE: MappingDecoratorFunction = (endpoint = ''): MethodDecorator => { +export const SSE: MappingDecoratorFunction = ( + endpoint = '', +): MethodDecorator => { return (_target, _propertyKey, descriptor) => { MetadataHelper.setMetadata('endpoint', endpoint, descriptor.value); MetadataHelper.setMetadata('method', 'GET', descriptor.value); diff --git a/src/router/controller/params/decorators.ts b/src/router/controller/params/decorators.ts index ec214a81..1dc23035 100644 --- a/src/router/controller/params/decorators.ts +++ b/src/router/controller/params/decorators.ts @@ -84,31 +84,36 @@ export function createParamDecorator( } /** - * Get current request -*/ -export const Req: DecoratorFunction = createParamDecorator((context: ExecutionContext) => { - return context.req; -}); + * Get current request + */ +export const Req: DecoratorFunction = createParamDecorator( + (context: ExecutionContext) => { + return context.req; + }, +); /** * Get current response -*/ -export const Res: DecoratorFunction = createParamDecorator((context: ExecutionContext) => { - return context.res; -}); - + */ +export const Res: DecoratorFunction = createParamDecorator( + (context: ExecutionContext) => { + return context.res; + }, +); /** - * Get current request websocket instance -*/ -export const WebSocket: DecoratorFunction = createParamDecorator((context: ExecutionContext) => { - return context.websocket; -}); + * Get current request websocket instance + */ +export const WebSocket: DecoratorFunction = createParamDecorator( + (context: ExecutionContext) => { + return context.websocket; + }, +); /** - * Get all headers or a specific header -*/ -export const Header: ((prop?: string) => DecoratorFunction) = (prop?: string) => + * Get all headers or a specific header + */ +export const Header: (prop?: string) => DecoratorFunction = (prop?: string) => createParamDecorator((context: ExecutionContext) => { if (!context.req.raw.headers) { return null; @@ -119,9 +124,9 @@ export const Header: ((prop?: string) => DecoratorFunction) = (prop?: string) = export const BODY_TYPE_KEY = 'body-type'; /** - * Get request's body or a given property - **/ -export const Body: ((prop?: string) => DecoratorFunction) = (prop?: string) => + * Get request's body or a given property + */ +export const Body: (prop?: string) => DecoratorFunction = (prop?: string) => createParamDecorator( async (context: ExecutionContext, opts?: OptionsResolver) => { if (!opts) { @@ -204,7 +209,7 @@ export interface QueryOption { } /** * Get all query params or a given query param -*/ + */ export function Query( options?: QueryOption, ): ReturnType>; @@ -260,7 +265,7 @@ export function Query( /** * Get an url param for example /user/:userId -*/ + */ export function Param(paramName: string): DecoratorFunction { return createParamDecorator((context: ExecutionContext) => { const params = context.req.param(); @@ -274,7 +279,7 @@ export function Param(paramName: string): DecoratorFunction { /** * Get Session or a given property of session -*/ + */ export function Session(prop?: string): DecoratorFunction { return createParamDecorator((context: ExecutionContext) => { if (prop) { @@ -282,5 +287,5 @@ export function Session(prop?: string): DecoratorFunction { } else { return context.get('session'); } - })() -}; + })(); +} diff --git a/src/router/middleware/decorator.ts b/src/router/middleware/decorator.ts index d4d66faa..f0dd88fc 100644 --- a/src/router/middleware/decorator.ts +++ b/src/router/middleware/decorator.ts @@ -5,9 +5,9 @@ import { MetadataFunction, SetMetadata } from '../../metadata/decorator.ts'; /** * Interface representing a middleware. - * + * * @interface DanetMiddleware - * + * * @method action * @param {ExecutionContext} ctx - The execution context for the middleware. * @param {NextFunction} next - The next function to call in the middleware chain. @@ -19,7 +19,7 @@ export interface DanetMiddleware { /** * Represents a function that, when called, proceeds to the next middleware in the chain. - * + * * @returns A promise that resolves to either void or a Response object. */ export type NextFunction = () => Promise; @@ -37,10 +37,12 @@ export const isMiddlewareClass = (s: PossibleMiddlewareType) => !!s.prototype; export const middlewareMetadataKey = 'middlewares'; /** * A decorator function that attaches middleware to a route handler or controller. - * + * * @param {...PossibleMiddlewareType[]} middlewares - A list of middleware functions to be applied. * @returns {MetadataFunction} - A function that sets the metadata for the middleware. */ -export function Middleware(...middlewares: PossibleMiddlewareType[]): MetadataFunction{ +export function Middleware( + ...middlewares: PossibleMiddlewareType[] +): MetadataFunction { return SetMetadata(middlewareMetadataKey, middlewares); -} \ No newline at end of file +} diff --git a/src/router/middleware/executor.ts b/src/router/middleware/executor.ts index 5dad7184..de3d25aa 100644 --- a/src/router/middleware/executor.ts +++ b/src/router/middleware/executor.ts @@ -21,14 +21,14 @@ import { globalMiddlewareContainer } from './global-container.ts'; export class MiddlewareExecutor { /** * Constructs a new `MiddlewareExecutor` instance. - * + * * @param injector - The injector used to manage dependencies. */ constructor(private injector: Injector) {} /** * Executes all relevant middlewares for the given context, controller, and controller method. - * + * * @param context - The execution context. * @param Controller - The controller constructor. * @param ControllerMethod - The controller method callback. diff --git a/src/router/middleware/global-container.ts b/src/router/middleware/global-container.ts index 939ead05..28f5db0e 100644 --- a/src/router/middleware/global-container.ts +++ b/src/router/middleware/global-container.ts @@ -2,11 +2,11 @@ import { PossibleMiddlewareType } from './decorator.ts'; /** * A global container for middleware functions. - * + * * This array holds instances of middleware that can be applied globally * across the application. Each element in the array should conform to the * `PossibleMiddlewareType` type. - * + * * @type {PossibleMiddlewareType[]} */ export const globalMiddlewareContainer: PossibleMiddlewareType[] = []; diff --git a/src/router/router.ts b/src/router/router.ts index bab1aef6..cac4f70b 100644 --- a/src/router/router.ts +++ b/src/router/router.ts @@ -27,11 +27,14 @@ import { SSEEvent } from '../sse/event.ts'; // deno-lint-ignore no-explicit-any export type Callback = (...args: any[]) => unknown; +/** + * Type Alias for Hono's Context + */ export type HttpContext = Context; /** * Represents Danet's execution context for an HTTP request, extending Hono's HttpContext. - * + * * @typedef {Object} ExecutionContext * @property {string} _id - Unique identifier for the execution context. * @property {Function} getHandler - Function to retrieve the handler for the current context. @@ -54,7 +57,7 @@ export type ExecutionContext = HttpContext & { /** * The `DanetHTTPRouter` class is responsible for managing HTTP routes and their associated handlers. * It provides methods to register controllers, set route prefixes, and handle middleware, guards, filters, and responses. - * + * * @class DanetHTTPRouter */ export class DanetHTTPRouter { @@ -180,7 +183,7 @@ export class DanetHTTPRouter { private handleRoute( Controller: ControllerConstructor, ControllerMethod: Callback, - ): ((context: HttpContext) => Promise) { + ): (context: HttpContext) => Promise { return async (context: HttpContext) => { (context as ExecutionContext)._id = context.get('_id'); (context as ExecutionContext).getClass = () => Controller; diff --git a/src/schedule/decorator.ts b/src/schedule/decorator.ts index bcbb0ac1..8f79d472 100644 --- a/src/schedule/decorator.ts +++ b/src/schedule/decorator.ts @@ -8,7 +8,7 @@ import { CronString } from './types.ts'; /** * Assigns a cron schedule to a method. The method will be executed according to the provided cron schedule. - * + * * @param cron - A string representing the cron schedule. * @returns A method decorator that sets the metadata key with the provided cron schedule. */ diff --git a/src/schedule/enum.ts b/src/schedule/enum.ts index 0e9264b8..df2e54fb 100644 --- a/src/schedule/enum.ts +++ b/src/schedule/enum.ts @@ -2,7 +2,7 @@ /** * Enum representing various cron expressions for scheduling tasks. - * + * * @enum {string} * @readonly * @property {string} EVERY_MINUTE - Runs every minute. @@ -167,6 +167,17 @@ export enum CronExpression { MONDAY_TO_FRIDAY_AT_11PM = '0 0 23 * * 1-5', } +/** + * Various time intervals in milliseconds. + * + * @enum {number} + * @readonly + * @property {number} MILISECOND - Represents one millisecond. + * @property {number} SECOND - Represents one second (1000 milliseconds). + * @property {number} MINUTE - Represents one minute (60,000 milliseconds). + * @property {number} HOUR - Represents one hour (3,600,000 milliseconds). + * @property {number} DAY - Represents one day (86,400,000 milliseconds). + */ export enum IntervalExpression { MILISECOND = 1, SECOND = 1000,