Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #191 from smartive/develop
Browse files Browse the repository at this point in the history
release
  • Loading branch information
buehler authored Jun 28, 2018
2 parents 83370c5 + e483725 commit bd46aa8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ language: node_js
stages:
- name: test
if: tag IS blank
- name: build
if: tag IS blank
- name: deploy
if: branch = master AND type != pull_request

Expand All @@ -25,6 +27,9 @@ jobs:
after_success:
- npm i -g codecov
- codecov
- stage: build
node_js: '10'
script: npm run build
- stage: deploy
node_js: '10'
script: npm run typedoc
Expand Down
10 changes: 5 additions & 5 deletions src/ReturnTypeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { ReturnType } from './routes/ReturnType';
* This handler is registered within the giuseppe core and holds all registered return type handlers. All those
* {@link ReturnType} are than checked when a return value is given to the handler. If no matching handler is found
* the default handler is taken. If even that isn't found, an error is thrown.
*
*
* @export
* @class ReturnTypeHandler
*/
export class ReturnTypeHandler {
private returnTypes: { [type: string]: ReturnType<any> } = {};
private returnTypes: { [type: string]: ReturnType<any, any> } = {};

constructor(types: ReturnType<any>[]) {
constructor(types: ReturnType<any, any>[]) {
for (const type of types) {
this.returnTypes[type.type] = type;
}
Expand All @@ -26,8 +26,8 @@ export class ReturnTypeHandler {
* Handles the response for a given value. Searches in the handlers for the correct return type handler. If no matching
* handler is found, the `default` handler is used. And if no default is registered (or was overwritten with undefined)
* an error is thrown.
*
* @param {*} value
*
* @param {*} value
* @param {Response} response
* @throws {NoReturnValueHandlerFoundError} One handler must be there to handle the value.
* @memberof ReturnTypeHandler
Expand Down
33 changes: 17 additions & 16 deletions src/routes/ReturnType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,47 @@
* Return type handler. This element registers a hander for specific return types. When an object is received from
* a route function, it's constructor name is checked against all various registered return type handler. When no one
* is found, giuseppe throws an error, otherwise the registered handler (or the default) will be used.
*
*
* @export
* @interface ReturnType
* @template T
* @template TValue Type for the incomming value
* @template TResult Type for the returned value of the `getValue` function
*/
export interface ReturnType<T> {
export interface ReturnType<TValue, TResult = string> {
/**
* The name of the type that is handled. This can be 'String', 'Number', or anything else.
* One special name is possible: 'default'. The default is used whenever no other types that matches are found.
*
*
* @type {string}
* @memberof ReturnType
*/
type: string;

/**
* Returns the headers for the given value. The function must return something. Even if it's an empty header hash.
*
* @param {T} [value]
* @returns {{ [field: string]: string }}
*
* @param {TValue} [value]
* @returns {{ [field: string]: string }}
* @memberof ReturnType
*/
getHeaders(value?: T): { [field: string]: string };
getHeaders(value?: TValue): { [field: string]: string };

/**
* Get the return http status code for the given value.
*
* @param {T} [value]
* @returns {number}
*
* @param {TValue} [value]
* @returns {number}
* @memberof ReturnType
*/
getStatus(value?: T): number;
getStatus(value?: TValue): number;

/**
* Get the stringified value for a given value. This value is sent by express with the set headers and
* status codes. This function is only called if an actual value exists.
*
* @param {T} value
* @returns {string}
*
* @param {TValue} value
* @returns {string}
* @memberof ReturnType
*/
getValue(value: T): string;
getValue(value: TValue): TResult;
}

0 comments on commit bd46aa8

Please sign in to comment.