-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from medishen/dev/v2
Fix event system and enhance decorators with unit tests
- Loading branch information
Showing
29 changed files
with
1,393 additions
and
123 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export type ParsedBody = { | ||
body: Record<string, any> | string | undefined | { [key: string]: any } | null; | ||
bodyRaw: Buffer | undefined; | ||
body: Record<string, any> | { [key: string]: any } | null; | ||
bodyRaw: Buffer | null; | ||
bodySize: number | string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,35 @@ | ||
import { RouterMetadataKeys } from '../common/enums'; | ||
import { MultiLanguageContext } from '../common/interfaces'; | ||
import Reflector from '../metadata'; | ||
|
||
/** | ||
* @module MultiLanguage | ||
* @description | ||
* The `@MultiLanguage` decorator is used to register multiple translations for a route. | ||
* It automatically selects the language based on the 'accept-language' header of the request, | ||
* providing the correct route or translation for that language. | ||
* | ||
* @param {MultiLanguageContext} translations - An object containing language mappings. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { MultiLanguage } from './decorators/MultiLanguage'; | ||
* import { MultiLanguageContext } from './common/interfaces'; | ||
* | ||
* class ExampleController { | ||
* @MultiLanguage({ | ||
* en: '/foo', // English route | ||
* fr: '/bar', // French route | ||
* default: '/foo' // Default route | ||
* }) | ||
* public handleRequest(ctx: ServerRequest) { | ||
* console.log(`Selected language: ${ctx.language}`); | ||
* ctx.end() | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
export function MultiLanguage(translations: MultiLanguageContext): MethodDecorator { | ||
return (target) => { | ||
Reflector.define(RouterMetadataKeys.MULTI_LANG, translations, target.constructor); | ||
Reflector.define(RouterMetadataKeys.MULTI_LANGUAGE, translations, target.constructor); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.