@foal/core
Advanced tools
Comparing version 0.8.5 to 0.8.6
import { HookDecorator } from '../core'; | ||
/** | ||
* Hook factory to authenticate users using cookies and sessions. | ||
* | ||
* The hook does not return any error when no user could be authenticated. | ||
* | ||
* @export | ||
* @param {({ user: (id: number|string) => Promise<any> })} options - Hook options. | ||
* @param {(id: number|string) => Promise<any>} options.user - Function that takes an id as parameter and returns | ||
* the corresponding user. If no user is found, the function must return undefined. | ||
* @returns {HookDecorator} | ||
*/ | ||
export declare function LoginOptional(options: { | ||
user: (id: number | string) => Promise<any>; | ||
}): HookDecorator; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const login_hook_1 = require("./login.hook"); | ||
/** | ||
* Hook factory to authenticate users using cookies and sessions. | ||
* | ||
* The hook does not return any error when no user could be authenticated. | ||
* | ||
* @export | ||
* @param {({ user: (id: number|string) => Promise<any> })} options - Hook options. | ||
* @param {(id: number|string) => Promise<any>} options.user - Function that takes an id as parameter and returns | ||
* the corresponding user. If no user is found, the function must return undefined. | ||
* @returns {HookDecorator} | ||
*/ | ||
function LoginOptional(options) { | ||
@@ -5,0 +16,0 @@ return login_hook_1.Login(false, options); |
import { HookDecorator } from '../core'; | ||
/** | ||
* Hook factory to authenticate users using cookies and sessions. | ||
* | ||
* The hook returns a 401 error if no user could be authenticated. | ||
* | ||
* @export | ||
* @param {({ redirect?: string, user: (id: number|string) => Promise<any> })} options - Hook options. | ||
* @param {string|undefined} options.redirect - Optional URL path where unauthenticated users should be redirected. | ||
* @param {(id: number|string) => Promise<any>} options.user - Function that takes an id as parameter and returns | ||
* the corresponding user. If no user is found, the function must return undefined. | ||
* @returns {HookDecorator} The hook | ||
*/ | ||
export declare function LoginRequired(options: { | ||
@@ -3,0 +15,0 @@ redirect?: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const login_hook_1 = require("./login.hook"); | ||
/** | ||
* Hook factory to authenticate users using cookies and sessions. | ||
* | ||
* The hook returns a 401 error if no user could be authenticated. | ||
* | ||
* @export | ||
* @param {({ redirect?: string, user: (id: number|string) => Promise<any> })} options - Hook options. | ||
* @param {string|undefined} options.redirect - Optional URL path where unauthenticated users should be redirected. | ||
* @param {(id: number|string) => Promise<any>} options.user - Function that takes an id as parameter and returns | ||
* the corresponding user. If no user is found, the function must return undefined. | ||
* @returns {HookDecorator} The hook | ||
*/ | ||
function LoginRequired(options) { | ||
@@ -5,0 +17,0 @@ return login_hook_1.Login(true, options); |
import { HookDecorator } from '../core'; | ||
/** | ||
* Sub-function used by LoginRequired and LoginOptional to avoid code duplication. | ||
* | ||
* @export | ||
* @param {boolean} required | ||
* @param {({ redirect?: string, user: (id: number|string) => Promise<any> })} options | ||
* @returns {HookDecorator} | ||
*/ | ||
export declare function Login(required: boolean, options: { | ||
@@ -3,0 +11,0 @@ redirect?: string; |
@@ -5,2 +5,10 @@ "use strict"; | ||
const core_1 = require("../core"); | ||
/** | ||
* Sub-function used by LoginRequired and LoginOptional to avoid code duplication. | ||
* | ||
* @export | ||
* @param {boolean} required | ||
* @param {({ redirect?: string, user: (id: number|string) => Promise<any> })} options | ||
* @returns {HookDecorator} | ||
*/ | ||
function Login(required, options) { | ||
@@ -7,0 +15,0 @@ return core_1.Hook(async (ctx) => { |
@@ -7,4 +7,8 @@ /** | ||
* | ||
* The random salt is 16 bytes long. | ||
* The number of iterations is 150000. | ||
* The length key is 32 bytes long. | ||
* | ||
* @export | ||
* @param {string} plainTextPassword The password to encrypt. | ||
* @param {string} plainTextPassword - The password to encrypt. | ||
* @param {{ legacy?: boolean }} [options={}] | ||
@@ -11,0 +15,0 @@ * @returns {Promise<string>} The derived key with the algorithm name, the number of iterations and the salt. |
@@ -23,4 +23,8 @@ "use strict"; | ||
* | ||
* The random salt is 16 bytes long. | ||
* The number of iterations is 150000. | ||
* The length key is 32 bytes long. | ||
* | ||
* @export | ||
* @param {string} plainTextPassword The password to encrypt. | ||
* @param {string} plainTextPassword - The password to encrypt. | ||
* @param {{ legacy?: boolean }} [options={}] | ||
@@ -27,0 +31,0 @@ * @returns {Promise<string>} The derived key with the algorithm name, the number of iterations and the salt. |
import { Context } from '../../core'; | ||
/** | ||
* Save the user id in the current session. | ||
* | ||
* @export | ||
* @param {Context} ctx - The request context. | ||
* @param {object} user - The user object. | ||
* @param {string} [idKey='id'] - The name of the user's id property. | ||
*/ | ||
export declare function logIn(ctx: Context, user: object, idKey?: string): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Save the user id in the current session. | ||
* | ||
* @export | ||
* @param {Context} ctx - The request context. | ||
* @param {object} user - The user object. | ||
* @param {string} [idKey='id'] - The name of the user's id property. | ||
*/ | ||
function logIn(ctx, user, idKey = 'id') { | ||
@@ -4,0 +12,0 @@ ctx.request.session.authentication = Object.assign({}, ctx.request.session.authentication, { userId: user[idKey] }); |
import { Context } from '../../core'; | ||
/** | ||
* Remove the user id from the current session. | ||
* | ||
* @export | ||
* @param {Context} ctx - The request context. | ||
*/ | ||
export declare function logOut(ctx: Context): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Remove the user id from the current session. | ||
* | ||
* @export | ||
* @param {Context} ctx - The request context. | ||
*/ | ||
function logOut(ctx) { | ||
@@ -4,0 +10,0 @@ delete ctx.request.session.authentication; |
@@ -0,3 +1,12 @@ | ||
/** | ||
* Compare a plain text password and a hash to see if they match. | ||
* | ||
* @export | ||
* @param {string} plainTextPassword - The password in clear text. | ||
* @param {string} encryptedPassword - The password hash generated by the `encryptPassword` function. | ||
* @param {{ legacy?: boolean }} [options={}] | ||
* @returns {Promise<boolean>} True if the hash and the password match. False otherwise. | ||
*/ | ||
export declare function verifyPassword(plainTextPassword: string, encryptedPassword: string, options?: { | ||
legacy?: boolean; | ||
}): Promise<boolean>; |
@@ -6,2 +6,11 @@ "use strict"; | ||
const util_1 = require("util"); | ||
/** | ||
* Compare a plain text password and a hash to see if they match. | ||
* | ||
* @export | ||
* @param {string} plainTextPassword - The password in clear text. | ||
* @param {string} encryptedPassword - The password hash generated by the `encryptPassword` function. | ||
* @param {{ legacy?: boolean }} [options={}] | ||
* @returns {Promise<boolean>} True if the hash and the password match. False otherwise. | ||
*/ | ||
async function verifyPassword(plainTextPassword, encryptedPassword, options = {}) { | ||
@@ -8,0 +17,0 @@ const legacy = options.legacy || false; |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Represent an object that was expected to be found but that does not exist. | ||
* | ||
* @export | ||
* @class ObjectDoesNotExist | ||
* @extends {Error} | ||
*/ | ||
export declare class ObjectDoesNotExist extends Error { | ||
@@ -6,2 +13,15 @@ content?: any; | ||
} | ||
/** | ||
* Check if an error is an instance of ObjectDoesNotExist. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {object} err - The error to check. | ||
* @returns {err is ObjectDoesNotExist} True if the error is an instance of ObjectDoesNotExist. False otherwise. | ||
*/ | ||
export declare function isObjectDoesNotExist(err: object): err is ObjectDoesNotExist; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Represent an object that was expected to be found but that does not exist. | ||
* | ||
* @export | ||
* @class ObjectDoesNotExist | ||
* @extends {Error} | ||
*/ | ||
class ObjectDoesNotExist extends Error { | ||
@@ -12,2 +19,15 @@ constructor(content) { | ||
exports.ObjectDoesNotExist = ObjectDoesNotExist; | ||
/** | ||
* Check if an error is an instance of ObjectDoesNotExist. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {object} err - The error to check. | ||
* @returns {err is ObjectDoesNotExist} True if the error is an instance of ObjectDoesNotExist. False otherwise. | ||
*/ | ||
function isObjectDoesNotExist(err) { | ||
@@ -14,0 +34,0 @@ return err instanceof ObjectDoesNotExist || err.isObjectDoesNotExist === true; |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Represent the prohibition to perform an action that was expected to be accessible. | ||
* | ||
* @export | ||
* @class PermissionDenied | ||
* @extends {Error} | ||
*/ | ||
export declare class PermissionDenied extends Error { | ||
@@ -6,2 +13,15 @@ content?: any; | ||
} | ||
/** | ||
* Check if an error is an instance of PermissionDenied. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {object} err - The error to check. | ||
* @returns {err is PermissionDenied} True if the error is an instance of PermissionDenied. False otherwise. | ||
*/ | ||
export declare function isPermissionDenied(err: object): err is PermissionDenied; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Represent the prohibition to perform an action that was expected to be accessible. | ||
* | ||
* @export | ||
* @class PermissionDenied | ||
* @extends {Error} | ||
*/ | ||
class PermissionDenied extends Error { | ||
@@ -12,2 +19,15 @@ constructor(content) { | ||
exports.PermissionDenied = PermissionDenied; | ||
/** | ||
* Check if an error is an instance of PermissionDenied. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {object} err - The error to check. | ||
* @returns {err is PermissionDenied} True if the error is an instance of PermissionDenied. False otherwise. | ||
*/ | ||
function isPermissionDenied(err) { | ||
@@ -14,0 +34,0 @@ return err instanceof PermissionDenied || err.isPermissionDenied === true; |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Represent an incorrect data format. | ||
* | ||
* @export | ||
* @class ValidationError | ||
* @extends {Error} | ||
*/ | ||
export declare class ValidationError extends Error { | ||
@@ -6,2 +13,15 @@ content?: any; | ||
} | ||
/** | ||
* Check if an error is an instance of ValidationError. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {object} err - The error to check | ||
* @returns {err is ValidationError} True if the error is an instance of ValidationError. False otherwise. | ||
*/ | ||
export declare function isValidationError(err: object): err is ValidationError; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Represent an incorrect data format. | ||
* | ||
* @export | ||
* @class ValidationError | ||
* @extends {Error} | ||
*/ | ||
class ValidationError extends Error { | ||
@@ -12,2 +19,15 @@ constructor(content) { | ||
exports.ValidationError = ValidationError; | ||
/** | ||
* Check if an error is an instance of ValidationError. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {object} err - The error to check | ||
* @returns {err is ValidationError} True if the error is an instance of ValidationError. False otherwise. | ||
*/ | ||
function isValidationError(err) { | ||
@@ -14,0 +34,0 @@ return err instanceof ValidationError || err.isValidationError === true; |
import { HookDecorator } from '../../core'; | ||
/** | ||
* Options of the `Log` hook. | ||
* | ||
* @export | ||
* @interface LogOptions | ||
*/ | ||
export interface LogOptions { | ||
@@ -10,3 +16,3 @@ body?: boolean; | ||
/** | ||
* Logs a message with optional information on the HTTP request. | ||
* Hook logging a message with optional information on the HTTP request. | ||
* | ||
@@ -16,2 +22,10 @@ * @param message The message to print. | ||
*/ | ||
/** | ||
* Hook factory logging a message with optional information on the HTTP request. | ||
* | ||
* @export | ||
* @param {string} message - The message to print on each request. | ||
* @param {LogOptions} [options={}] - Options to specify which information on the HTTP request should be printed. | ||
* @returns {HookDecorator} The hook. | ||
*/ | ||
export declare function Log(message: string, options?: LogOptions): HookDecorator; |
@@ -5,3 +5,3 @@ "use strict"; | ||
/** | ||
* Logs a message with optional information on the HTTP request. | ||
* Hook logging a message with optional information on the HTTP request. | ||
* | ||
@@ -11,2 +11,10 @@ * @param message The message to print. | ||
*/ | ||
/** | ||
* Hook factory logging a message with optional information on the HTTP request. | ||
* | ||
* @export | ||
* @param {string} message - The message to print on each request. | ||
* @param {LogOptions} [options={}] - Options to specify which information on the HTTP request should be printed. | ||
* @returns {HookDecorator} The hook. | ||
*/ | ||
function Log(message, options = {}) { | ||
@@ -13,0 +21,0 @@ const logFn = options.logFn || console.log; |
import { HookDecorator } from '../../core'; | ||
/** | ||
* Hook to validate the body of the request. | ||
* Hook factory validating the body of the request against a AJV schema. | ||
* | ||
* @param schema Schema used to validate the body request. | ||
* @export | ||
* @param {object} schema - Schema used to validate the body request. | ||
* @returns {HookDecorator} - The hook. | ||
*/ | ||
export declare function ValidateBody(schema: object): HookDecorator; |
@@ -6,5 +6,7 @@ "use strict"; | ||
/** | ||
* Hook to validate the body of the request. | ||
* Hook factory validating the body of the request against a AJV schema. | ||
* | ||
* @param schema Schema used to validate the body request. | ||
* @export | ||
* @param {object} schema - Schema used to validate the body request. | ||
* @returns {HookDecorator} - The hook. | ||
*/ | ||
@@ -11,0 +13,0 @@ function ValidateBody(schema) { |
import { HookDecorator } from '../../core'; | ||
/** | ||
* Hook to validate the headers of the request. | ||
* Hook factory validating the headers of the request against a AJV schema. | ||
* | ||
* @param schema Schema used to validate the headers request. | ||
* @export | ||
* @param {object} schema - Schema used to validate the headers request. | ||
* @returns {HookDecorator} - The hook. | ||
*/ | ||
export declare function ValidateHeaders(schema: object): HookDecorator; |
@@ -6,5 +6,7 @@ "use strict"; | ||
/** | ||
* Hook to validate the headers of the request. | ||
* Hook factory validating the headers of the request against a AJV schema. | ||
* | ||
* @param schema Schema used to validate the headers request. | ||
* @export | ||
* @param {object} schema - Schema used to validate the headers request. | ||
* @returns {HookDecorator} - The hook. | ||
*/ | ||
@@ -11,0 +13,0 @@ function ValidateHeaders(schema) { |
import { HookDecorator } from '../../core'; | ||
/** | ||
* Hook to validate the params of the request. | ||
* Hook factory validating the params of the request against a AJV schema. | ||
* | ||
* @param schema Schema used to validate the params request. | ||
* @export | ||
* @param {object} schema - Schema used to validate the params request. | ||
* @returns {HookDecorator} - The hook. | ||
*/ | ||
export declare function ValidateParams(schema: object): HookDecorator; |
@@ -6,5 +6,7 @@ "use strict"; | ||
/** | ||
* Hook to validate the params of the request. | ||
* Hook factory validating the params of the request against a AJV schema. | ||
* | ||
* @param schema Schema used to validate the params request. | ||
* @export | ||
* @param {object} schema - Schema used to validate the params request. | ||
* @returns {HookDecorator} - The hook. | ||
*/ | ||
@@ -11,0 +13,0 @@ function ValidateParams(schema) { |
import { HookDecorator } from '../../core'; | ||
/** | ||
* Hook to validate the query of the request. | ||
* Hook factory validating the query of the request against a AJV schema. | ||
* | ||
* @param schema Schema used to validate the query request. | ||
* @export | ||
* @param {object} schema - Schema used to validate the query request. | ||
* @returns {HookDecorator} - The hook. | ||
*/ | ||
export declare function ValidateQuery(schema: object): HookDecorator; |
@@ -6,5 +6,7 @@ "use strict"; | ||
/** | ||
* Hook to validate the query of the request. | ||
* Hook factory validating the query of the request against a AJV schema. | ||
* | ||
* @param schema Schema used to validate the query request. | ||
* @export | ||
* @param {object} schema - Schema used to validate the query request. | ||
* @returns {HookDecorator} - The hook. | ||
*/ | ||
@@ -11,0 +13,0 @@ function ValidateQuery(schema) { |
import 'reflect-metadata'; | ||
import { Class } from '../../core'; | ||
/** | ||
* Define the HTTP path of a controller class. This function is usually called | ||
* when adding the controller as a sub-controller. | ||
* | ||
* @export | ||
* @param {string} path - The HTTP path. | ||
* @param {Class} controllerClass - The controller class. | ||
* @returns {Class} The controller class. | ||
*/ | ||
export declare function controller(path: string, controllerClass: Class): Class; |
@@ -5,2 +5,11 @@ "use strict"; | ||
require("reflect-metadata"); | ||
/** | ||
* Define the HTTP path of a controller class. This function is usually called | ||
* when adding the controller as a sub-controller. | ||
* | ||
* @export | ||
* @param {string} path - The HTTP path. | ||
* @param {Class} controllerClass - The controller class. | ||
* @returns {Class} The controller class. | ||
*/ | ||
function controller(path, controllerClass) { | ||
@@ -7,0 +16,0 @@ Reflect.defineMetadata('path', path, controllerClass); |
@@ -0,1 +1,11 @@ | ||
/** | ||
* Escape a string property of an object following OWASP recommandations to prevent XSS attacks. | ||
* | ||
* Source: https://github.com/OWASP/CheatSheetSeries/blob/master/ | ||
* cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.md | ||
* | ||
* @export | ||
* @param {object} object - The object which contains the property to escape. | ||
* @param {string} propName - The property name. | ||
*/ | ||
export declare function escapeProp(object: object, propName: string): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const escape_1 = require("./escape"); | ||
/** | ||
* Escape a string property of an object following OWASP recommandations to prevent XSS attacks. | ||
* | ||
* Source: https://github.com/OWASP/CheatSheetSeries/blob/master/ | ||
* cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.md | ||
* | ||
* @export | ||
* @param {object} object - The object which contains the property to escape. | ||
* @param {string} propName - The property name. | ||
*/ | ||
function escapeProp(object, propName) { | ||
@@ -5,0 +15,0 @@ const type = typeof object[propName]; |
@@ -0,1 +1,11 @@ | ||
/** | ||
* Escape a string following OWASP recommandations to prevent XSS attacks. | ||
* | ||
* Source: https://github.com/OWASP/CheatSheetSeries/blob/master/ | ||
* cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.md | ||
* | ||
* @export | ||
* @param {string} str - The string to escape. | ||
* @returns {string} The escaped string. | ||
*/ | ||
export declare function escape(str: string): string; |
@@ -11,2 +11,12 @@ "use strict"; | ||
}; | ||
/** | ||
* Escape a string following OWASP recommandations to prevent XSS attacks. | ||
* | ||
* Source: https://github.com/OWASP/CheatSheetSeries/blob/master/ | ||
* cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.md | ||
* | ||
* @export | ||
* @param {string} str - The string to escape. | ||
* @returns {string} The escaped string. | ||
*/ | ||
function escape(str) { | ||
@@ -13,0 +23,0 @@ return str.replace(/[&<>"'\/]/g, match => escapeMap[match]); |
@@ -6,3 +6,3 @@ import * as Ajv from 'ajv'; | ||
/** | ||
* Returns the Ajv instance used internally by FoalTS. | ||
* Return the Ajv instance used internally by FoalTS. | ||
* | ||
@@ -16,3 +16,6 @@ * It has this default configuration: | ||
* variables: SETTINGS_AJV_COERCE_TYPES, SETTINGS_AJV_REMOVE_ADDITIONAL, SETTINGS_AJV_USE_DEFAULTS. | ||
* | ||
* @export | ||
* @returns {Ajv.Ajv} The AJV instance | ||
*/ | ||
export declare function getAjvInstance(): Ajv.Ajv; |
@@ -12,3 +12,3 @@ "use strict"; | ||
/** | ||
* Returns the Ajv instance used internally by FoalTS. | ||
* Return the Ajv instance used internally by FoalTS. | ||
* | ||
@@ -22,2 +22,5 @@ * It has this default configuration: | ||
* variables: SETTINGS_AJV_COERCE_TYPES, SETTINGS_AJV_REMOVE_ADDITIONAL, SETTINGS_AJV_USE_DEFAULTS. | ||
* | ||
* @export | ||
* @returns {Ajv.Ajv} The AJV instance | ||
*/ | ||
@@ -24,0 +27,0 @@ function getAjvInstance() { |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Generate a function checking if a string is included in a text file. | ||
* | ||
* @export | ||
* @param {string} path - The file path. | ||
* @returns {(content: string) => Promise<boolean>} The generated function. | ||
*/ | ||
export declare function isInFile(path: string): (content: string) => Promise<boolean>; |
@@ -6,2 +6,9 @@ "use strict"; | ||
const util_1 = require("util"); | ||
/** | ||
* Generate a function checking if a string is included in a text file. | ||
* | ||
* @export | ||
* @param {string} path - The file path. | ||
* @returns {(content: string) => Promise<boolean>} The generated function. | ||
*/ | ||
function isInFile(path) { | ||
@@ -8,0 +15,0 @@ return async (content) => { |
import { HttpResponseOK } from '../../core'; | ||
/** | ||
* Render a template in a new HttpResponseOK object. | ||
* | ||
* @export | ||
* @param {string} templatePath - The path of the template. | ||
* @param {object} locals - The variables used to render the template. | ||
* @param {string} dirname - The directory name where the templated is located. | ||
* The passed value is usually `__dirname`. The function then joins `dirname` and | ||
* `templatePath` together. | ||
* @returns {HttpResponseOK} | ||
*/ | ||
export declare function render(templatePath: string, locals: object, dirname: string): HttpResponseOK; |
@@ -8,2 +8,13 @@ "use strict"; | ||
const core_1 = require("../../core"); | ||
/** | ||
* Render a template in a new HttpResponseOK object. | ||
* | ||
* @export | ||
* @param {string} templatePath - The path of the template. | ||
* @param {object} locals - The variables used to render the template. | ||
* @param {string} dirname - The directory name where the templated is located. | ||
* The passed value is usually `__dirname`. The function then joins `dirname` and | ||
* `templatePath` together. | ||
* @returns {HttpResponseOK} | ||
*/ | ||
function render(templatePath, locals, dirname) { | ||
@@ -10,0 +21,0 @@ const templateEngine = core_1.Config.get('settings.templateEngine', '@foal/ejs'); |
@@ -0,1 +1,9 @@ | ||
/** | ||
* Validate an object against an AJV schema. If the object is not validated, | ||
* the function throws a ValidationError with the failure details. | ||
* | ||
* @export | ||
* @param {object} schema - The AJV schema. | ||
* @param {*} data - The tested data. | ||
*/ | ||
export declare function validate(schema: object, data: any): void; |
@@ -6,2 +6,10 @@ "use strict"; | ||
const get_ajv_instance_1 = require("./get-ajv-instance"); | ||
/** | ||
* Validate an object against an AJV schema. If the object is not validated, | ||
* the function throws a ValidationError with the failure details. | ||
* | ||
* @export | ||
* @param {object} schema - The AJV schema. | ||
* @param {*} data - The tested data. | ||
*/ | ||
function validate(schema, data) { | ||
@@ -8,0 +16,0 @@ const ajv = get_ajv_instance_1.getAjvInstance(); |
@@ -0,1 +1,6 @@ | ||
/** | ||
* Interface of a class from its class definition. | ||
* | ||
* @export | ||
*/ | ||
export declare type Class<T = any> = new (...args: any[]) => T; |
@@ -0,3 +1,42 @@ | ||
/** | ||
* Static class to access environment variables and configuration files. | ||
* | ||
* This class can also be used as a service. | ||
* | ||
* @export | ||
* @class Config | ||
*/ | ||
export declare class Config { | ||
/** | ||
* Access environment variables and configuration files. | ||
* | ||
* For example, if it is called with the string `settings.session.secret`, | ||
* the method will go through these steps: | ||
* | ||
* 1. If the environment variable `SETTINGS_SESSION_SECRET` exists, then return its value. | ||
* 2. If `.env` exists and has a line `SETTINGS_SESSION_SECRET=`, then return its value. | ||
* 3. If `config/${NODE_ENV}.json` exists and the property `config['settings']['session']['secret']` | ||
* does too, then return its value. | ||
* 4. Same with `config/${NODE_ENV}.yml`. | ||
* 5. If `config/default.json` exists and the property `config['settings']['session']['secret']` | ||
* does too, then return its value. | ||
* 6. Same with `config/default.yml`. | ||
* | ||
* If none value is found, then the method returns the default value provided as second argument | ||
* to the function. If none was given, it returns undefined. | ||
* | ||
* @static | ||
* @template T - TypeScript type of the returned value. Default is `any`. | ||
* @param {string} key - Name of the config key using dots and camel case. | ||
* @param {T} [defaultValue] - Default value to return if no configuration is found with that key. | ||
* @returns {T} The configuration value. | ||
* @memberof Config | ||
*/ | ||
static get<T = any>(key: string, defaultValue?: T): T; | ||
/** | ||
* Clear the cache of the loaded files. | ||
* | ||
* @static | ||
* @memberof Config | ||
*/ | ||
static clearCache(): void; | ||
@@ -13,3 +52,27 @@ private static yaml; | ||
private static getValue; | ||
/** | ||
* Access environment variables and configuration files. | ||
* | ||
* For example, if it is called with the string `settings.session.secret`, | ||
* the method will go through these steps: | ||
* | ||
* 1. If the environment variable `SETTINGS_SESSION_SECRET` exists, then return its value. | ||
* 2. If `.env` exists and has a line `SETTINGS_SESSION_SECRET=`, then return its value. | ||
* 3. If `config/${NODE_ENV}.json` exists and the property `config['settings']['session']['secret']` | ||
* does too, then return its value. | ||
* 4. Same with `config/${NODE_ENV}.yml`. | ||
* 5. If `config/default.json` exists and the property `config['settings']['session']['secret']` | ||
* does too, then return its value. | ||
* 6. Same with `config/default.yml`. | ||
* | ||
* If none value is found, then the method returns the default value provided as second argument | ||
* to the function. If none was given, it returns undefined. | ||
* | ||
* @template T - TypeScript type of the returned value. Default is `any`. | ||
* @param {string} key - Name of the config key using dots and camel case. | ||
* @param {T} [defaultValue] - Default value to return if no configuration is found with that key. | ||
* @returns {T} The configuration value. | ||
* @memberof Config | ||
*/ | ||
get<T = any>(key: string, defaultValue?: T): T; | ||
} |
@@ -5,3 +5,36 @@ "use strict"; | ||
const fs_1 = require("fs"); | ||
/** | ||
* Static class to access environment variables and configuration files. | ||
* | ||
* This class can also be used as a service. | ||
* | ||
* @export | ||
* @class Config | ||
*/ | ||
class Config { | ||
/** | ||
* Access environment variables and configuration files. | ||
* | ||
* For example, if it is called with the string `settings.session.secret`, | ||
* the method will go through these steps: | ||
* | ||
* 1. If the environment variable `SETTINGS_SESSION_SECRET` exists, then return its value. | ||
* 2. If `.env` exists and has a line `SETTINGS_SESSION_SECRET=`, then return its value. | ||
* 3. If `config/${NODE_ENV}.json` exists and the property `config['settings']['session']['secret']` | ||
* does too, then return its value. | ||
* 4. Same with `config/${NODE_ENV}.yml`. | ||
* 5. If `config/default.json` exists and the property `config['settings']['session']['secret']` | ||
* does too, then return its value. | ||
* 6. Same with `config/default.yml`. | ||
* | ||
* If none value is found, then the method returns the default value provided as second argument | ||
* to the function. If none was given, it returns undefined. | ||
* | ||
* @static | ||
* @template T - TypeScript type of the returned value. Default is `any`. | ||
* @param {string} key - Name of the config key using dots and camel case. | ||
* @param {T} [defaultValue] - Default value to return if no configuration is found with that key. | ||
* @returns {T} The configuration value. | ||
* @memberof Config | ||
*/ | ||
static get(key, defaultValue) { | ||
@@ -37,2 +70,8 @@ const underscoreName = this.dotToUnderscore(key); | ||
} | ||
/** | ||
* Clear the cache of the loaded files. | ||
* | ||
* @static | ||
* @memberof Config | ||
*/ | ||
static clearCache() { | ||
@@ -131,2 +170,26 @@ this.cache = { | ||
} | ||
/** | ||
* Access environment variables and configuration files. | ||
* | ||
* For example, if it is called with the string `settings.session.secret`, | ||
* the method will go through these steps: | ||
* | ||
* 1. If the environment variable `SETTINGS_SESSION_SECRET` exists, then return its value. | ||
* 2. If `.env` exists and has a line `SETTINGS_SESSION_SECRET=`, then return its value. | ||
* 3. If `config/${NODE_ENV}.json` exists and the property `config['settings']['session']['secret']` | ||
* does too, then return its value. | ||
* 4. Same with `config/${NODE_ENV}.yml`. | ||
* 5. If `config/default.json` exists and the property `config['settings']['session']['secret']` | ||
* does too, then return its value. | ||
* 6. Same with `config/default.yml`. | ||
* | ||
* If none value is found, then the method returns the default value provided as second argument | ||
* to the function. If none was given, it returns undefined. | ||
* | ||
* @template T - TypeScript type of the returned value. Default is `any`. | ||
* @param {string} key - Name of the config key using dots and camel case. | ||
* @param {T} [defaultValue] - Default value to return if no configuration is found with that key. | ||
* @returns {T} The configuration value. | ||
* @memberof Config | ||
*/ | ||
get(key, defaultValue) { | ||
@@ -133,0 +196,0 @@ return Config.get(key, defaultValue); |
import 'reflect-metadata'; | ||
import { Class } from './class.interface'; | ||
import { ServiceManager } from './service-manager'; | ||
export declare function createController<T>(controllerClass: Class<T>, dependencies?: object | ServiceManager): T; | ||
/** | ||
* Create a new controller with its dependencies. | ||
* | ||
* @export | ||
* @template Controller | ||
* @param {Class<Controller>} controllerClass - The controller class. | ||
* @param {(object|ServiceManager)} [dependencies] - Either a ServiceManager or an | ||
* object which key/values are the controller properties/instances. | ||
* @returns {Controller} - The created controller. | ||
*/ | ||
export declare function createController<Controller>(controllerClass: Class<Controller>, dependencies?: object | ServiceManager): Controller; |
@@ -6,2 +6,12 @@ "use strict"; | ||
const service_manager_1 = require("./service-manager"); | ||
/** | ||
* Create a new controller with its dependencies. | ||
* | ||
* @export | ||
* @template Controller | ||
* @param {Class<Controller>} controllerClass - The controller class. | ||
* @param {(object|ServiceManager)} [dependencies] - Either a ServiceManager or an | ||
* object which key/values are the controller properties/instances. | ||
* @returns {Controller} - The created controller. | ||
*/ | ||
function createController(controllerClass, dependencies) { | ||
@@ -8,0 +18,0 @@ const controllerDependencies = Reflect.getMetadata('dependencies', controllerClass.prototype) || []; |
import 'reflect-metadata'; | ||
import { Context, HttpResponse } from './http'; | ||
import { ServiceManager } from './service-manager'; | ||
/** | ||
* Interface of a function that can be returned in a hook function. This function is then | ||
* executed after the controller method execution. | ||
* | ||
* @export | ||
*/ | ||
export declare type HookPostFunction = (ctx: Context, services: ServiceManager, response: HttpResponse) => void | Promise<void>; | ||
/** | ||
* Interface of a function from which a hook can be created. | ||
* | ||
* @export | ||
*/ | ||
export declare type HookFunction = (ctx: Context, services: ServiceManager) => void | HttpResponse | HookPostFunction | Promise<void | HttpResponse | HookPostFunction>; | ||
/** | ||
* Interface of a hook. It is actually the interface of a decorator. | ||
* | ||
* @export | ||
*/ | ||
export declare type HookDecorator = (target: any, propertyKey?: string) => any; | ||
/** | ||
* Create a hook from a function. | ||
* | ||
* @export | ||
* @param {HookFunction} hookFunction - The function from which the hook should be created. | ||
* @returns {HookDecorator} - The hook decorator. | ||
*/ | ||
export declare function Hook(hookFunction: HookFunction): HookDecorator; | ||
/** | ||
* Get the function from which the hook was made. | ||
* | ||
* @export | ||
* @param {HookDecorator} hook - The hook decorator. | ||
* @returns {HookFunction} - The hook function. | ||
*/ | ||
export declare function getHookFunction(hook: HookDecorator): HookFunction; |
@@ -11,2 +11,9 @@ "use strict"; | ||
require("reflect-metadata"); | ||
/** | ||
* Create a hook from a function. | ||
* | ||
* @export | ||
* @param {HookFunction} hookFunction - The function from which the hook should be created. | ||
* @returns {HookDecorator} - The hook decorator. | ||
*/ | ||
function Hook(hookFunction) { | ||
@@ -21,2 +28,9 @@ return (target, propertyKey) => { | ||
exports.Hook = Hook; | ||
/** | ||
* Get the function from which the hook was made. | ||
* | ||
* @export | ||
* @param {HookDecorator} hook - The hook decorator. | ||
* @returns {HookFunction} - The hook function. | ||
*/ | ||
function getHookFunction(hook) { | ||
@@ -23,0 +37,0 @@ let Foo = class Foo { |
import { Request } from 'express'; | ||
interface HTTPRequest extends Request { | ||
/** | ||
* Interface of the express request object. It also includes | ||
* a `session` property and a `csrfToken` method. | ||
* | ||
* @export | ||
* @interface HTTPRequest | ||
* @extends {Request} | ||
*/ | ||
export interface HTTPRequest extends Request { | ||
session: any; | ||
csrfToken: () => string; | ||
} | ||
/** | ||
* Class instantiated on each request. It includes: | ||
* - the express request object, | ||
* - the user object if available, | ||
* - and a `state` object that can be used to pass data across several hooks. | ||
* | ||
* @export | ||
* @class Context | ||
* @template User | ||
*/ | ||
export declare class Context<User = any> { | ||
@@ -12,4 +30,8 @@ state: { | ||
request: HTTPRequest; | ||
/** | ||
* Creates an instance of Context. | ||
* @param {*} request - Either the express request object or a mock (for testing). | ||
* @memberof Context | ||
*/ | ||
constructor(request: any); | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Class instantiated on each request. It includes: | ||
* - the express request object, | ||
* - the user object if available, | ||
* - and a `state` object that can be used to pass data across several hooks. | ||
* | ||
* @export | ||
* @class Context | ||
* @template User | ||
*/ | ||
class Context { | ||
/** | ||
* Creates an instance of Context. | ||
* @param {*} request - Either the express request object or a mock (for testing). | ||
* @memberof Context | ||
*/ | ||
constructor(request) { | ||
@@ -5,0 +20,0 @@ this.state = {}; |
import 'reflect-metadata'; | ||
/** | ||
* HTTP methods available. | ||
*/ | ||
export declare type HttpMethod = 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'; | ||
/** | ||
* Decorator specifying that a controller method handles HEAD requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
export declare function Head(path?: string): (target: any, propertyKey: string) => void; | ||
/** | ||
* Decorator specifying that a controller method handles OPTIONS requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
export declare function Options(path?: string): (target: any, propertyKey: string) => void; | ||
/** | ||
* Decorator specifying that a controller method handles GET requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
export declare function Get(path?: string): (target: any, propertyKey: string) => void; | ||
/** | ||
* Decorator specifying that a controller method handles POST requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
export declare function Post(path?: string): (target: any, propertyKey: string) => void; | ||
/** | ||
* Decorator specifying that a controller method handles PUT requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
export declare function Put(path?: string): (target: any, propertyKey: string) => void; | ||
/** | ||
* Decorator specifying that a controller method handles PATCH requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
export declare function Patch(path?: string): (target: any, propertyKey: string) => void; | ||
/** | ||
* Decorator specifying that a controller method handles DELETE requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
export declare function Delete(path?: string): (target: any, propertyKey: string) => void; |
@@ -5,2 +5,9 @@ "use strict"; | ||
require("reflect-metadata"); | ||
/** | ||
* Decorator specifying that a controller method handles HEAD requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
function Head(path) { | ||
@@ -13,2 +20,9 @@ return (target, propertyKey) => { | ||
exports.Head = Head; | ||
/** | ||
* Decorator specifying that a controller method handles OPTIONS requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
function Options(path) { | ||
@@ -21,2 +35,9 @@ return (target, propertyKey) => { | ||
exports.Options = Options; | ||
/** | ||
* Decorator specifying that a controller method handles GET requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
function Get(path) { | ||
@@ -29,2 +50,9 @@ return (target, propertyKey) => { | ||
exports.Get = Get; | ||
/** | ||
* Decorator specifying that a controller method handles POST requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
function Post(path) { | ||
@@ -37,2 +65,9 @@ return (target, propertyKey) => { | ||
exports.Post = Post; | ||
/** | ||
* Decorator specifying that a controller method handles PUT requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
function Put(path) { | ||
@@ -45,2 +80,9 @@ return (target, propertyKey) => { | ||
exports.Put = Put; | ||
/** | ||
* Decorator specifying that a controller method handles PATCH requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
function Patch(path) { | ||
@@ -53,2 +95,9 @@ return (target, propertyKey) => { | ||
exports.Patch = Patch; | ||
/** | ||
* Decorator specifying that a controller method handles DELETE requests. | ||
* | ||
* @export | ||
* @param {string} [path] - The path of the request. | ||
* @returns The decorator. | ||
*/ | ||
function Delete(path) { | ||
@@ -55,0 +104,0 @@ return (target, propertyKey) => { |
@@ -0,1 +1,7 @@ | ||
/** | ||
* Cookie options of the HttpResponse.setCookie method. | ||
* | ||
* @export | ||
* @interface CookieOptions | ||
*/ | ||
export interface CookieOptions { | ||
@@ -10,16 +16,87 @@ domain?: string; | ||
} | ||
/** | ||
* Reprensent an HTTP response. This class must be extended. | ||
* Instances of HttpResponse are returned in hooks and controller | ||
* methods. | ||
* | ||
* @export | ||
* @abstract | ||
* @class HttpResponse | ||
*/ | ||
export declare abstract class HttpResponse { | ||
body?: any; | ||
/** | ||
* Property used internally by isHttpResponse. | ||
* | ||
* @memberof HttpResponse | ||
*/ | ||
readonly isHttpResponse: boolean; | ||
/** | ||
* Status code of the response. | ||
* | ||
* @abstract | ||
* @type {number} | ||
* @memberof HttpResponse | ||
*/ | ||
abstract statusCode: number; | ||
/** | ||
* Status message of the response. It must follow the HTTP conventions | ||
* and be consistent with the statusCode property. | ||
* | ||
* @abstract | ||
* @type {string} | ||
* @memberof HttpResponse | ||
*/ | ||
abstract statusMessage: string; | ||
private cookies; | ||
private headers; | ||
/** | ||
* Create an instance of HttpResponse. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponse | ||
*/ | ||
constructor(body?: any); | ||
/** | ||
* Add or replace a header in the response. | ||
* | ||
* @param {string} name - The header name. | ||
* @param {string} value - The value name. | ||
* @memberof HttpResponse | ||
*/ | ||
setHeader(name: string, value: string): void; | ||
/** | ||
* Read the value of a header added with setHeader. | ||
* | ||
* @param {string} name - The header name. | ||
* @returns {(string|undefined)} The header value or undefined if it | ||
* does not exist. | ||
* @memberof HttpResponse | ||
*/ | ||
getHeader(name: string): string | undefined; | ||
/** | ||
* Read all the headers added with setHeader. | ||
* | ||
* @returns {{ [key: string]: string }} - The headers. | ||
* @memberof HttpResponse | ||
*/ | ||
getHeaders(): { | ||
[key: string]: string; | ||
}; | ||
/** | ||
* Add or replace a cookie in the response. | ||
* | ||
* @param {string} name - The cookie name. | ||
* @param {string} value - The cookie value. | ||
* @param {CookieOptions} [options={}] - The cookie directives if any. | ||
* @memberof HttpResponse | ||
*/ | ||
setCookie(name: string, value: string, options?: CookieOptions): void; | ||
/** | ||
* Read the value and directives of a cookie added with setCookie. | ||
* | ||
* @param {string} name - The cookie name. | ||
* @returns {({ value: string|undefined, options: CookieOptions })} The cookie value and directives | ||
* or undefined and an empty object if the cookie does not exist. | ||
* @memberof HttpResponse | ||
*/ | ||
getCookie(name: string): { | ||
@@ -29,2 +106,9 @@ value: string | undefined; | ||
}; | ||
/** | ||
* Read all the cookies added with setCookie. | ||
* | ||
* @returns {({ [key: string]: { value: string|undefined, options: CookieOptions } })} | ||
* The name, value and directives of the cookies. | ||
* @memberof HttpResponse | ||
*/ | ||
getCookies(): { | ||
@@ -37,107 +121,607 @@ [key: string]: { | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponse. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponse} - True if the error is an instance of HttpResponse. False otherwise. | ||
*/ | ||
export declare function isHttpResponse(obj: any): obj is HttpResponse; | ||
/** | ||
* Represent an HTTP response with a success status 2xx. | ||
* | ||
* @export | ||
* @abstract | ||
* @class HttpResponseSuccess | ||
* @extends {HttpResponse} | ||
*/ | ||
export declare abstract class HttpResponseSuccess extends HttpResponse { | ||
/** | ||
* Property used internally by isHttpResponseSuccess. | ||
* | ||
* @memberof HttpResponseSuccess | ||
*/ | ||
readonly isHttpResponseSuccess: boolean; | ||
/** | ||
* Create an instance of HttpResponseSuccess. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseSuccess | ||
*/ | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseSuccess. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseSuccess} - True if the error is an instance of HttpResponseSuccess. False otherwise. | ||
*/ | ||
export declare function isHttpResponseSuccess(obj: any): obj is HttpResponseSuccess; | ||
/** | ||
* Represent an HTTP response with the status 200 - OK. | ||
* | ||
* @export | ||
* @class HttpResponseOK | ||
* @extends {HttpResponseSuccess} | ||
*/ | ||
export declare class HttpResponseOK extends HttpResponseSuccess { | ||
/** | ||
* Property used internally by isHttpResponOK. | ||
* | ||
* @memberof HttpResponseOK | ||
*/ | ||
readonly isHttpResponseOK: boolean; | ||
statusCode: number; | ||
statusMessage: string; | ||
/** | ||
* Create an instance of HttpResponseOK. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseOK | ||
*/ | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseOK. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseOK} - True if the error is an instance of HttpResponseOK. False otherwise. | ||
*/ | ||
export declare function isHttpResponseOK(obj: any): obj is HttpResponseOK; | ||
/** | ||
* Represent an HTTP response with the status 201 - CREATED. | ||
* | ||
* @export | ||
* @class HttpResponseCreated | ||
* @extends {HttpResponseSuccess} | ||
*/ | ||
export declare class HttpResponseCreated extends HttpResponseSuccess { | ||
/** | ||
* Property used internally by isHttpResponseCreated. | ||
* | ||
* @memberof HttpResponseCreated | ||
*/ | ||
readonly isHttpResponseCreated: boolean; | ||
statusCode: number; | ||
statusMessage: string; | ||
/** | ||
* Create an instance of HttpResponseCreated. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseCreated | ||
*/ | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseCreated. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseCreated} - True if the error is an instance of HttpResponseCreated. False otherwise. | ||
*/ | ||
export declare function isHttpResponseCreated(obj: any): obj is HttpResponseCreated; | ||
/** | ||
* Represent an HTTP response with the status 204 - NO CONTENT. | ||
* | ||
* @export | ||
* @class HttpResponseNoContent | ||
* @extends {HttpResponseSuccess} | ||
*/ | ||
export declare class HttpResponseNoContent extends HttpResponseSuccess { | ||
/** | ||
* Property used internally by is HttpResponseNoContent. | ||
* | ||
* @memberof HttpResponseNoContent | ||
*/ | ||
readonly isHttpResponseNoContent: boolean; | ||
statusCode: number; | ||
statusMessage: string; | ||
/** | ||
* Create an instance of HttpResponseNoContent. | ||
* @memberof HttpResponseNoContent | ||
*/ | ||
constructor(); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseNoContent. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseNoContent} - True if the error is an instance of HttpResponseNoContent. False otherwise. | ||
*/ | ||
export declare function isHttpResponseNoContent(obj: any): obj is HttpResponseNoContent; | ||
/** | ||
* Represent an HTTP response with a redirection status 3xx. | ||
* | ||
* @export | ||
* @abstract | ||
* @class HttpResponseRedirection | ||
* @extends {HttpResponse} | ||
*/ | ||
export declare abstract class HttpResponseRedirection extends HttpResponse { | ||
/** | ||
* Property used internally by isHttpResponseRediction. | ||
* | ||
* @memberof HttpResponseRedirection | ||
*/ | ||
readonly isHttpResponseRedirection: boolean; | ||
/** | ||
* Create an instance of HttpResponseRedirection. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseRedirection | ||
*/ | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseRedirection. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseRedirection} - True if the error is an instance of HttpResponseRedirection. | ||
* False otherwise. | ||
*/ | ||
export declare function isHttpResponseRedirection(obj: any): obj is HttpResponseRedirection; | ||
/** | ||
* Represent an HTTP response with the status 302 - FOUND. | ||
* | ||
* @export | ||
* @class HttpResponseRedirect | ||
* @extends {HttpResponseRedirection} | ||
*/ | ||
export declare class HttpResponseRedirect extends HttpResponseRedirection { | ||
path: string; | ||
/** | ||
* Property used internally by isHttpResponseRedirect. | ||
* | ||
* @memberof HttpResponseRedirect | ||
*/ | ||
readonly isHttpResponseRedirect: boolean; | ||
statusCode: number; | ||
statusMessage: string; | ||
/** | ||
* Create an instance of HttpResponseRedirect. | ||
* @param {string} path - The redirection path. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseRedirect | ||
*/ | ||
constructor(path: string, body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseRedirect. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseRedirect} - True if the error is an instance of HttpResponseRedirect. False otherwise. | ||
*/ | ||
export declare function isHttpResponseRedirect(obj: any): obj is HttpResponseRedirect; | ||
/** | ||
* Represent an HTTP response with a client error status 4xx. | ||
* | ||
* @export | ||
* @abstract | ||
* @class HttpResponseClientError | ||
* @extends {HttpResponse} | ||
*/ | ||
export declare abstract class HttpResponseClientError extends HttpResponse { | ||
/** | ||
* Property used internally by isHttpResponseClientError. | ||
* | ||
* @memberof HttpResponseClientError | ||
*/ | ||
readonly isHttpResponseClientError: boolean; | ||
/** | ||
* Create an instance of HttpResponseClientError. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseClientError | ||
*/ | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseClientError. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseClientError} - True if the error is an instance of HttpResponseClientError. | ||
* False otherwise. | ||
*/ | ||
export declare function isHttpResponseClientError(obj: any): obj is HttpResponseClientError; | ||
/** | ||
* Represent an HTTP response with the status 400 - BAD REQUEST. | ||
* | ||
* @export | ||
* @class HttpResponseBadRequest | ||
* @extends {HttpResponseClientError} | ||
*/ | ||
export declare class HttpResponseBadRequest extends HttpResponseClientError { | ||
/** | ||
* Property used internally by isHttpResponseBadRequest. | ||
* | ||
* @memberof HttpResponseBadRequest | ||
*/ | ||
readonly isHttpResponseBadRequest: boolean; | ||
statusCode: number; | ||
statusMessage: string; | ||
/** | ||
* Create an instance of HttpResponseBadRequest. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseBadRequest | ||
*/ | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseBadRequest. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseBadRequest} - True if the error is an instance of HttpResponseBadRequest. | ||
* False otherwise. | ||
*/ | ||
export declare function isHttpResponseBadRequest(obj: any): obj is HttpResponseBadRequest; | ||
/** | ||
* Represent an HTTP response with the status 401 - UNAUTHORIZED. | ||
* | ||
* @export | ||
* @class HttpResponseUnauthorized | ||
* @extends {HttpResponseClientError} | ||
*/ | ||
export declare class HttpResponseUnauthorized extends HttpResponseClientError { | ||
/** | ||
* Property used internally by isHttpResponseUnauthorized. | ||
* | ||
* @memberof HttpResponseUnauthorized | ||
*/ | ||
readonly isHttpResponseUnauthorized: boolean; | ||
statusCode: number; | ||
statusMessage: string; | ||
/** | ||
* Create an instance of HttpResponseUnauthorized. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseUnauthorized | ||
*/ | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseUnauthorized. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseUnauthorized} - True if the error is an instance of HttpResponseUnauthorized. | ||
* False otherwise. | ||
*/ | ||
export declare function isHttpResponseUnauthorized(obj: any): obj is HttpResponseUnauthorized; | ||
/** | ||
* Represent an HTTP response with the status 403 - FORBIDDEN. | ||
* | ||
* @export | ||
* @class HttpResponseForbidden | ||
* @extends {HttpResponseClientError} | ||
*/ | ||
export declare class HttpResponseForbidden extends HttpResponseClientError { | ||
/** | ||
* Property used internally by isHttpResponseForbidden. | ||
* | ||
* @memberof HttpResponseForbidden | ||
*/ | ||
readonly isHttpResponseForbidden: boolean; | ||
statusCode: number; | ||
statusMessage: string; | ||
/** | ||
* Create an instance of HttpResponseForbidden. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseForbidden | ||
*/ | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseForbidden. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseForbidden} - True if the error is an instance of HttpResponseForbidden. False otherwise. | ||
*/ | ||
export declare function isHttpResponseForbidden(obj: any): obj is HttpResponseForbidden; | ||
/** | ||
* Represent an HTTP response with the status 404 - NOT FOUND. | ||
* | ||
* @export | ||
* @class HttpResponseNotFound | ||
* @extends {HttpResponseClientError} | ||
*/ | ||
export declare class HttpResponseNotFound extends HttpResponseClientError { | ||
/** | ||
* Property used internally by isHttpResponseNotFound. | ||
* | ||
* @memberof HttpResponseNotFound | ||
*/ | ||
readonly isHttpResponseNotFound: boolean; | ||
statusCode: number; | ||
statusMessage: string; | ||
/** | ||
* Create an instance of HttpResponseNotFound. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseNotFound | ||
*/ | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseNotFound. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseNotFound} - True if the error is an instance of HttpResponseNotFound. False otherwise. | ||
*/ | ||
export declare function isHttpResponseNotFound(obj: any): obj is HttpResponseNotFound; | ||
/** | ||
* Represent an HTTP response with the status 405 - METHOD NOT ALLOWED. | ||
* | ||
* @export | ||
* @class HttpResponseMethodNotAllowed | ||
* @extends {HttpResponseClientError} | ||
*/ | ||
export declare class HttpResponseMethodNotAllowed extends HttpResponseClientError { | ||
/** | ||
* Property used internally by isHttpResponseMethodNotAllowed. | ||
* | ||
* @memberof HttpResponseMethodNotAllowed | ||
*/ | ||
readonly isHttpResponseMethodNotAllowed: boolean; | ||
statusCode: number; | ||
statusMessage: string; | ||
/** | ||
* Create an instance of HttpResponseMethodNotAllowed. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseMethodNotAllowed | ||
*/ | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseMethodNotAllowed. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseMethodNotAllowed} - True if the error is an instance of HttpResponseMethodNotAllowed. | ||
* False otherwise. | ||
*/ | ||
export declare function isHttpResponseMethodNotAllowed(obj: any): obj is HttpResponseMethodNotAllowed; | ||
/** | ||
* Represent an HTTP response with the status 409 - CONFLICT. | ||
* | ||
* @export | ||
* @class HttpResponseConflict | ||
* @extends {HttpResponseClientError} | ||
*/ | ||
export declare class HttpResponseConflict extends HttpResponseClientError { | ||
/** | ||
* Property used internally by isHttpResponseConflict. | ||
* | ||
* @memberof HttpResponseConflict | ||
*/ | ||
readonly isHttpResponseConflict: boolean; | ||
statusCode: number; | ||
statusMessage: string; | ||
/** | ||
* Create an instance of HttpResponseConflict. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseConflict | ||
*/ | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseConflict. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseConflict} - True if the error is an instance of HttpResponseConflict. False otherwise. | ||
*/ | ||
export declare function isHttpResponseConflict(obj: any): obj is HttpResponseConflict; | ||
/** | ||
* Represent an HTTP response with a server error status 5xx. | ||
* | ||
* @export | ||
* @abstract | ||
* @class HttpResponseServerError | ||
* @extends {HttpResponse} | ||
*/ | ||
export declare abstract class HttpResponseServerError extends HttpResponse { | ||
/** | ||
* Property used internally by isHttpResponseServerError. | ||
* | ||
* @memberof HttpResponseServerError | ||
*/ | ||
readonly isHttpResponseServerError: boolean; | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseServerError. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseServerError} - True if the error is an instance of HttpResponseServerError. | ||
* False otherwise. | ||
*/ | ||
export declare function isHttpResponseServerError(obj: any): obj is HttpResponseServerError; | ||
/** | ||
* Represent an HTTP response with the status 500 - INTERNAL SERVER ERROR. | ||
* | ||
* @export | ||
* @class HttpResponseInternalServerError | ||
* @extends {HttpResponseServerError} | ||
*/ | ||
export declare class HttpResponseInternalServerError extends HttpResponseServerError { | ||
/** | ||
* Property used internally by isHttpResponseInternalServerError. | ||
* | ||
* @memberof HttpResponseInternalServerError | ||
*/ | ||
readonly isHttpResponseInternalServerError: boolean; | ||
statusCode: number; | ||
statusMessage: string; | ||
/** | ||
* Create an instance of HttpResponseInternalServerError. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseInternalServerError | ||
*/ | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseInternalServerError. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseInternalServerError} - True if the error is an instance of | ||
* HttpResponseInternalServerError. False otherwise. | ||
*/ | ||
export declare function isHttpResponseInternalServerError(obj: any): obj is HttpResponseInternalServerError; | ||
/** | ||
* Represent an HTTP response with the status 501 - NOT IMPLEMENTED. | ||
* | ||
* @export | ||
* @class HttpResponseNotImplemented | ||
* @extends {HttpResponseServerError} | ||
*/ | ||
export declare class HttpResponseNotImplemented extends HttpResponseServerError { | ||
/** | ||
* Property used internally by isHttpResponseNotImplemented. | ||
* | ||
* @memberof HttpResponseNotImplemented | ||
*/ | ||
readonly isHttpResponseNotImplemented: boolean; | ||
statusCode: number; | ||
statusMessage: string; | ||
/** | ||
* Create an instance of HttpResponseNotImplemented. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseNotImplemented | ||
*/ | ||
constructor(body?: any); | ||
} | ||
/** | ||
* Check if an object is an instance of HttpResponseNotImplemented. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseNotImplemented} - True if the error is an instance of HttpResponseNotImplemented. | ||
* False otherwise. | ||
*/ | ||
export declare function isHttpResponseNotImplemented(obj: any): obj is HttpResponseNotImplemented; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Reprensent an HTTP response. This class must be extended. | ||
* Instances of HttpResponse are returned in hooks and controller | ||
* methods. | ||
* | ||
* @export | ||
* @abstract | ||
* @class HttpResponse | ||
*/ | ||
class HttpResponse { | ||
/** | ||
* Create an instance of HttpResponse. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponse | ||
*/ | ||
constructor(body) { | ||
this.body = body; | ||
/** | ||
* Property used internally by isHttpResponse. | ||
* | ||
* @memberof HttpResponse | ||
*/ | ||
this.isHttpResponse = true; | ||
@@ -10,14 +29,51 @@ this.cookies = {}; | ||
} | ||
/** | ||
* Add or replace a header in the response. | ||
* | ||
* @param {string} name - The header name. | ||
* @param {string} value - The value name. | ||
* @memberof HttpResponse | ||
*/ | ||
setHeader(name, value) { | ||
this.headers[name] = value; | ||
} | ||
/** | ||
* Read the value of a header added with setHeader. | ||
* | ||
* @param {string} name - The header name. | ||
* @returns {(string|undefined)} The header value or undefined if it | ||
* does not exist. | ||
* @memberof HttpResponse | ||
*/ | ||
getHeader(name) { | ||
return this.headers[name]; | ||
} | ||
/** | ||
* Read all the headers added with setHeader. | ||
* | ||
* @returns {{ [key: string]: string }} - The headers. | ||
* @memberof HttpResponse | ||
*/ | ||
getHeaders() { | ||
return Object.assign({}, this.headers); | ||
} | ||
/** | ||
* Add or replace a cookie in the response. | ||
* | ||
* @param {string} name - The cookie name. | ||
* @param {string} value - The cookie value. | ||
* @param {CookieOptions} [options={}] - The cookie directives if any. | ||
* @memberof HttpResponse | ||
*/ | ||
setCookie(name, value, options = {}) { | ||
this.cookies[name] = { value, options }; | ||
} | ||
/** | ||
* Read the value and directives of a cookie added with setCookie. | ||
* | ||
* @param {string} name - The cookie name. | ||
* @returns {({ value: string|undefined, options: CookieOptions })} The cookie value and directives | ||
* or undefined and an empty object if the cookie does not exist. | ||
* @memberof HttpResponse | ||
*/ | ||
getCookie(name) { | ||
@@ -30,2 +86,9 @@ if (!this.cookies[name]) { | ||
} | ||
/** | ||
* Read all the cookies added with setCookie. | ||
* | ||
* @returns {({ [key: string]: { value: string|undefined, options: CookieOptions } })} | ||
* The name, value and directives of the cookies. | ||
* @memberof HttpResponse | ||
*/ | ||
getCookies() { | ||
@@ -42,2 +105,15 @@ const cookies = {}; | ||
exports.HttpResponse = HttpResponse; | ||
/** | ||
* Check if an object is an instance of HttpResponse. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponse} - True if the error is an instance of HttpResponse. False otherwise. | ||
*/ | ||
function isHttpResponse(obj) { | ||
@@ -49,5 +125,23 @@ return obj instanceof HttpResponse || | ||
/* 2xx Success */ | ||
/** | ||
* Represent an HTTP response with a success status 2xx. | ||
* | ||
* @export | ||
* @abstract | ||
* @class HttpResponseSuccess | ||
* @extends {HttpResponse} | ||
*/ | ||
class HttpResponseSuccess extends HttpResponse { | ||
/** | ||
* Create an instance of HttpResponseSuccess. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseSuccess | ||
*/ | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponseSuccess. | ||
* | ||
* @memberof HttpResponseSuccess | ||
*/ | ||
this.isHttpResponseSuccess = true; | ||
@@ -57,2 +151,15 @@ } | ||
exports.HttpResponseSuccess = HttpResponseSuccess; | ||
/** | ||
* Check if an object is an instance of HttpResponseSuccess. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseSuccess} - True if the error is an instance of HttpResponseSuccess. False otherwise. | ||
*/ | ||
function isHttpResponseSuccess(obj) { | ||
@@ -63,5 +170,22 @@ return obj instanceof HttpResponseSuccess || | ||
exports.isHttpResponseSuccess = isHttpResponseSuccess; | ||
/** | ||
* Represent an HTTP response with the status 200 - OK. | ||
* | ||
* @export | ||
* @class HttpResponseOK | ||
* @extends {HttpResponseSuccess} | ||
*/ | ||
class HttpResponseOK extends HttpResponseSuccess { | ||
/** | ||
* Create an instance of HttpResponseOK. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseOK | ||
*/ | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponOK. | ||
* | ||
* @memberof HttpResponseOK | ||
*/ | ||
this.isHttpResponseOK = true; | ||
@@ -73,2 +197,15 @@ this.statusCode = 200; | ||
exports.HttpResponseOK = HttpResponseOK; | ||
/** | ||
* Check if an object is an instance of HttpResponseOK. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseOK} - True if the error is an instance of HttpResponseOK. False otherwise. | ||
*/ | ||
function isHttpResponseOK(obj) { | ||
@@ -79,5 +216,22 @@ return obj instanceof HttpResponseOK || | ||
exports.isHttpResponseOK = isHttpResponseOK; | ||
/** | ||
* Represent an HTTP response with the status 201 - CREATED. | ||
* | ||
* @export | ||
* @class HttpResponseCreated | ||
* @extends {HttpResponseSuccess} | ||
*/ | ||
class HttpResponseCreated extends HttpResponseSuccess { | ||
/** | ||
* Create an instance of HttpResponseCreated. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseCreated | ||
*/ | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponseCreated. | ||
* | ||
* @memberof HttpResponseCreated | ||
*/ | ||
this.isHttpResponseCreated = true; | ||
@@ -89,2 +243,15 @@ this.statusCode = 201; | ||
exports.HttpResponseCreated = HttpResponseCreated; | ||
/** | ||
* Check if an object is an instance of HttpResponseCreated. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseCreated} - True if the error is an instance of HttpResponseCreated. False otherwise. | ||
*/ | ||
function isHttpResponseCreated(obj) { | ||
@@ -95,5 +262,21 @@ return obj instanceof HttpResponseCreated || | ||
exports.isHttpResponseCreated = isHttpResponseCreated; | ||
/** | ||
* Represent an HTTP response with the status 204 - NO CONTENT. | ||
* | ||
* @export | ||
* @class HttpResponseNoContent | ||
* @extends {HttpResponseSuccess} | ||
*/ | ||
class HttpResponseNoContent extends HttpResponseSuccess { | ||
/** | ||
* Create an instance of HttpResponseNoContent. | ||
* @memberof HttpResponseNoContent | ||
*/ | ||
constructor() { | ||
super(); | ||
/** | ||
* Property used internally by is HttpResponseNoContent. | ||
* | ||
* @memberof HttpResponseNoContent | ||
*/ | ||
this.isHttpResponseNoContent = true; | ||
@@ -105,2 +288,15 @@ this.statusCode = 204; | ||
exports.HttpResponseNoContent = HttpResponseNoContent; | ||
/** | ||
* Check if an object is an instance of HttpResponseNoContent. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseNoContent} - True if the error is an instance of HttpResponseNoContent. False otherwise. | ||
*/ | ||
function isHttpResponseNoContent(obj) { | ||
@@ -112,5 +308,23 @@ return obj instanceof HttpResponseNoContent || | ||
/* 3xx Redirection */ | ||
/** | ||
* Represent an HTTP response with a redirection status 3xx. | ||
* | ||
* @export | ||
* @abstract | ||
* @class HttpResponseRedirection | ||
* @extends {HttpResponse} | ||
*/ | ||
class HttpResponseRedirection extends HttpResponse { | ||
/** | ||
* Create an instance of HttpResponseRedirection. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseRedirection | ||
*/ | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponseRediction. | ||
* | ||
* @memberof HttpResponseRedirection | ||
*/ | ||
this.isHttpResponseRedirection = true; | ||
@@ -120,2 +334,16 @@ } | ||
exports.HttpResponseRedirection = HttpResponseRedirection; | ||
/** | ||
* Check if an object is an instance of HttpResponseRedirection. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseRedirection} - True if the error is an instance of HttpResponseRedirection. | ||
* False otherwise. | ||
*/ | ||
function isHttpResponseRedirection(obj) { | ||
@@ -126,6 +354,24 @@ return obj instanceof HttpResponseRedirection || | ||
exports.isHttpResponseRedirection = isHttpResponseRedirection; | ||
/** | ||
* Represent an HTTP response with the status 302 - FOUND. | ||
* | ||
* @export | ||
* @class HttpResponseRedirect | ||
* @extends {HttpResponseRedirection} | ||
*/ | ||
class HttpResponseRedirect extends HttpResponseRedirection { | ||
/** | ||
* Create an instance of HttpResponseRedirect. | ||
* @param {string} path - The redirection path. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseRedirect | ||
*/ | ||
constructor(path, body) { | ||
super(body); | ||
this.path = path; | ||
/** | ||
* Property used internally by isHttpResponseRedirect. | ||
* | ||
* @memberof HttpResponseRedirect | ||
*/ | ||
this.isHttpResponseRedirect = true; | ||
@@ -137,2 +383,15 @@ this.statusCode = 302; | ||
exports.HttpResponseRedirect = HttpResponseRedirect; | ||
/** | ||
* Check if an object is an instance of HttpResponseRedirect. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseRedirect} - True if the error is an instance of HttpResponseRedirect. False otherwise. | ||
*/ | ||
function isHttpResponseRedirect(obj) { | ||
@@ -144,5 +403,23 @@ return obj instanceof HttpResponseRedirect || | ||
/* 4xx Client Error */ | ||
/** | ||
* Represent an HTTP response with a client error status 4xx. | ||
* | ||
* @export | ||
* @abstract | ||
* @class HttpResponseClientError | ||
* @extends {HttpResponse} | ||
*/ | ||
class HttpResponseClientError extends HttpResponse { | ||
/** | ||
* Create an instance of HttpResponseClientError. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseClientError | ||
*/ | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponseClientError. | ||
* | ||
* @memberof HttpResponseClientError | ||
*/ | ||
this.isHttpResponseClientError = true; | ||
@@ -152,2 +429,16 @@ } | ||
exports.HttpResponseClientError = HttpResponseClientError; | ||
/** | ||
* Check if an object is an instance of HttpResponseClientError. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseClientError} - True if the error is an instance of HttpResponseClientError. | ||
* False otherwise. | ||
*/ | ||
function isHttpResponseClientError(obj) { | ||
@@ -158,5 +449,22 @@ return obj instanceof HttpResponseClientError || | ||
exports.isHttpResponseClientError = isHttpResponseClientError; | ||
/** | ||
* Represent an HTTP response with the status 400 - BAD REQUEST. | ||
* | ||
* @export | ||
* @class HttpResponseBadRequest | ||
* @extends {HttpResponseClientError} | ||
*/ | ||
class HttpResponseBadRequest extends HttpResponseClientError { | ||
/** | ||
* Create an instance of HttpResponseBadRequest. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseBadRequest | ||
*/ | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponseBadRequest. | ||
* | ||
* @memberof HttpResponseBadRequest | ||
*/ | ||
this.isHttpResponseBadRequest = true; | ||
@@ -168,2 +476,16 @@ this.statusCode = 400; | ||
exports.HttpResponseBadRequest = HttpResponseBadRequest; | ||
/** | ||
* Check if an object is an instance of HttpResponseBadRequest. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseBadRequest} - True if the error is an instance of HttpResponseBadRequest. | ||
* False otherwise. | ||
*/ | ||
function isHttpResponseBadRequest(obj) { | ||
@@ -174,5 +496,22 @@ return obj instanceof HttpResponseBadRequest || | ||
exports.isHttpResponseBadRequest = isHttpResponseBadRequest; | ||
/** | ||
* Represent an HTTP response with the status 401 - UNAUTHORIZED. | ||
* | ||
* @export | ||
* @class HttpResponseUnauthorized | ||
* @extends {HttpResponseClientError} | ||
*/ | ||
class HttpResponseUnauthorized extends HttpResponseClientError { | ||
/** | ||
* Create an instance of HttpResponseUnauthorized. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseUnauthorized | ||
*/ | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponseUnauthorized. | ||
* | ||
* @memberof HttpResponseUnauthorized | ||
*/ | ||
this.isHttpResponseUnauthorized = true; | ||
@@ -185,2 +524,16 @@ this.statusCode = 401; | ||
exports.HttpResponseUnauthorized = HttpResponseUnauthorized; | ||
/** | ||
* Check if an object is an instance of HttpResponseUnauthorized. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseUnauthorized} - True if the error is an instance of HttpResponseUnauthorized. | ||
* False otherwise. | ||
*/ | ||
function isHttpResponseUnauthorized(obj) { | ||
@@ -191,5 +544,22 @@ return obj instanceof HttpResponseUnauthorized || | ||
exports.isHttpResponseUnauthorized = isHttpResponseUnauthorized; | ||
/** | ||
* Represent an HTTP response with the status 403 - FORBIDDEN. | ||
* | ||
* @export | ||
* @class HttpResponseForbidden | ||
* @extends {HttpResponseClientError} | ||
*/ | ||
class HttpResponseForbidden extends HttpResponseClientError { | ||
/** | ||
* Create an instance of HttpResponseForbidden. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseForbidden | ||
*/ | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponseForbidden. | ||
* | ||
* @memberof HttpResponseForbidden | ||
*/ | ||
this.isHttpResponseForbidden = true; | ||
@@ -201,2 +571,15 @@ this.statusCode = 403; | ||
exports.HttpResponseForbidden = HttpResponseForbidden; | ||
/** | ||
* Check if an object is an instance of HttpResponseForbidden. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseForbidden} - True if the error is an instance of HttpResponseForbidden. False otherwise. | ||
*/ | ||
function isHttpResponseForbidden(obj) { | ||
@@ -207,5 +590,22 @@ return obj instanceof HttpResponseForbidden || | ||
exports.isHttpResponseForbidden = isHttpResponseForbidden; | ||
/** | ||
* Represent an HTTP response with the status 404 - NOT FOUND. | ||
* | ||
* @export | ||
* @class HttpResponseNotFound | ||
* @extends {HttpResponseClientError} | ||
*/ | ||
class HttpResponseNotFound extends HttpResponseClientError { | ||
/** | ||
* Create an instance of HttpResponseNotFound. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseNotFound | ||
*/ | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponseNotFound. | ||
* | ||
* @memberof HttpResponseNotFound | ||
*/ | ||
this.isHttpResponseNotFound = true; | ||
@@ -217,2 +617,15 @@ this.statusCode = 404; | ||
exports.HttpResponseNotFound = HttpResponseNotFound; | ||
/** | ||
* Check if an object is an instance of HttpResponseNotFound. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseNotFound} - True if the error is an instance of HttpResponseNotFound. False otherwise. | ||
*/ | ||
function isHttpResponseNotFound(obj) { | ||
@@ -223,5 +636,22 @@ return obj instanceof HttpResponseNotFound || | ||
exports.isHttpResponseNotFound = isHttpResponseNotFound; | ||
/** | ||
* Represent an HTTP response with the status 405 - METHOD NOT ALLOWED. | ||
* | ||
* @export | ||
* @class HttpResponseMethodNotAllowed | ||
* @extends {HttpResponseClientError} | ||
*/ | ||
class HttpResponseMethodNotAllowed extends HttpResponseClientError { | ||
/** | ||
* Create an instance of HttpResponseMethodNotAllowed. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseMethodNotAllowed | ||
*/ | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponseMethodNotAllowed. | ||
* | ||
* @memberof HttpResponseMethodNotAllowed | ||
*/ | ||
this.isHttpResponseMethodNotAllowed = true; | ||
@@ -233,2 +663,16 @@ this.statusCode = 405; | ||
exports.HttpResponseMethodNotAllowed = HttpResponseMethodNotAllowed; | ||
/** | ||
* Check if an object is an instance of HttpResponseMethodNotAllowed. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseMethodNotAllowed} - True if the error is an instance of HttpResponseMethodNotAllowed. | ||
* False otherwise. | ||
*/ | ||
function isHttpResponseMethodNotAllowed(obj) { | ||
@@ -239,5 +683,22 @@ return obj instanceof HttpResponseMethodNotAllowed || | ||
exports.isHttpResponseMethodNotAllowed = isHttpResponseMethodNotAllowed; | ||
/** | ||
* Represent an HTTP response with the status 409 - CONFLICT. | ||
* | ||
* @export | ||
* @class HttpResponseConflict | ||
* @extends {HttpResponseClientError} | ||
*/ | ||
class HttpResponseConflict extends HttpResponseClientError { | ||
/** | ||
* Create an instance of HttpResponseConflict. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseConflict | ||
*/ | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponseConflict. | ||
* | ||
* @memberof HttpResponseConflict | ||
*/ | ||
this.isHttpResponseConflict = true; | ||
@@ -249,2 +710,15 @@ this.statusCode = 409; | ||
exports.HttpResponseConflict = HttpResponseConflict; | ||
/** | ||
* Check if an object is an instance of HttpResponseConflict. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseConflict} - True if the error is an instance of HttpResponseConflict. False otherwise. | ||
*/ | ||
function isHttpResponseConflict(obj) { | ||
@@ -256,5 +730,18 @@ return obj instanceof HttpResponseConflict || | ||
/* 5xx Server Error */ | ||
/** | ||
* Represent an HTTP response with a server error status 5xx. | ||
* | ||
* @export | ||
* @abstract | ||
* @class HttpResponseServerError | ||
* @extends {HttpResponse} | ||
*/ | ||
class HttpResponseServerError extends HttpResponse { | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponseServerError. | ||
* | ||
* @memberof HttpResponseServerError | ||
*/ | ||
this.isHttpResponseServerError = true; | ||
@@ -264,2 +751,16 @@ } | ||
exports.HttpResponseServerError = HttpResponseServerError; | ||
/** | ||
* Check if an object is an instance of HttpResponseServerError. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseServerError} - True if the error is an instance of HttpResponseServerError. | ||
* False otherwise. | ||
*/ | ||
function isHttpResponseServerError(obj) { | ||
@@ -270,5 +771,22 @@ return obj instanceof HttpResponseServerError || | ||
exports.isHttpResponseServerError = isHttpResponseServerError; | ||
/** | ||
* Represent an HTTP response with the status 500 - INTERNAL SERVER ERROR. | ||
* | ||
* @export | ||
* @class HttpResponseInternalServerError | ||
* @extends {HttpResponseServerError} | ||
*/ | ||
class HttpResponseInternalServerError extends HttpResponseServerError { | ||
/** | ||
* Create an instance of HttpResponseInternalServerError. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseInternalServerError | ||
*/ | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponseInternalServerError. | ||
* | ||
* @memberof HttpResponseInternalServerError | ||
*/ | ||
this.isHttpResponseInternalServerError = true; | ||
@@ -280,2 +798,16 @@ this.statusCode = 500; | ||
exports.HttpResponseInternalServerError = HttpResponseInternalServerError; | ||
/** | ||
* Check if an object is an instance of HttpResponseInternalServerError. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseInternalServerError} - True if the error is an instance of | ||
* HttpResponseInternalServerError. False otherwise. | ||
*/ | ||
function isHttpResponseInternalServerError(obj) { | ||
@@ -286,5 +818,22 @@ return obj instanceof HttpResponseInternalServerError || | ||
exports.isHttpResponseInternalServerError = isHttpResponseInternalServerError; | ||
/** | ||
* Represent an HTTP response with the status 501 - NOT IMPLEMENTED. | ||
* | ||
* @export | ||
* @class HttpResponseNotImplemented | ||
* @extends {HttpResponseServerError} | ||
*/ | ||
class HttpResponseNotImplemented extends HttpResponseServerError { | ||
/** | ||
* Create an instance of HttpResponseNotImplemented. | ||
* @param {*} [body] - Optional body of the response. | ||
* @memberof HttpResponseNotImplemented | ||
*/ | ||
constructor(body) { | ||
super(body); | ||
/** | ||
* Property used internally by isHttpResponseNotImplemented. | ||
* | ||
* @memberof HttpResponseNotImplemented | ||
*/ | ||
this.isHttpResponseNotImplemented = true; | ||
@@ -296,2 +845,16 @@ this.statusCode = 501; | ||
exports.HttpResponseNotImplemented = HttpResponseNotImplemented; | ||
/** | ||
* Check if an object is an instance of HttpResponseNotImplemented. | ||
* | ||
* This function is a help when you have several packages using @foal/core. | ||
* Npm can install the package several times, which leads to duplicate class | ||
* definitions. If this is the case, the keyword `instanceof` may return false | ||
* while the object is an instance of the class. This function fixes this | ||
* problem. | ||
* | ||
* @export | ||
* @param {*} obj - The object to check. | ||
* @returns {obj is HttpResponseNotImplemented} - True if the error is an instance of HttpResponseNotImplemented. | ||
* False otherwise. | ||
*/ | ||
function isHttpResponseNotImplemented(obj) { | ||
@@ -298,0 +861,0 @@ return obj instanceof HttpResponseNotImplemented || |
@@ -5,2 +5,13 @@ import { Class } from '../class.interface'; | ||
import { Route } from './route.interface'; | ||
/** | ||
* Recursively create the routes of a controller and its subcontrollers from the | ||
* controller class definition. | ||
* | ||
* @export | ||
* @param {string} parentPath - Prefix of all the route paths. | ||
* @param {HookFunction[]} parentHooks - First hooks of all the route hooks. | ||
* @param {Class} controllerClass - The controller class. | ||
* @param {ServiceManager} services - The application services. | ||
* @returns {Route[]} The created routes. | ||
*/ | ||
export declare function makeControllerRoutes(parentPath: string, parentHooks: HookFunction[], controllerClass: Class, services: ServiceManager): Route[]; |
@@ -5,2 +5,8 @@ "use strict"; | ||
const utils_1 = require("./utils"); | ||
/** | ||
* Recursively get the property names of an object and its prototypes. | ||
* | ||
* @param {(object|null)} obj - The object. | ||
* @returns {string[]} The property names. | ||
*/ | ||
function getMethods(obj) { | ||
@@ -12,2 +18,13 @@ if (obj === Object.prototype) { | ||
} | ||
/** | ||
* Recursively create the routes of a controller and its subcontrollers from the | ||
* controller class definition. | ||
* | ||
* @export | ||
* @param {string} parentPath - Prefix of all the route paths. | ||
* @param {HookFunction[]} parentHooks - First hooks of all the route hooks. | ||
* @param {Class} controllerClass - The controller class. | ||
* @param {ServiceManager} services - The application services. | ||
* @returns {Route[]} The created routes. | ||
*/ | ||
function makeControllerRoutes(parentPath, parentHooks, controllerClass, services) { | ||
@@ -14,0 +31,0 @@ const routes = []; |
import { HookFunction } from '../hooks'; | ||
import { HttpMethod } from '../http'; | ||
/** | ||
* Represent a Foal route with its controller handler and hooks. | ||
* | ||
* @export | ||
* @interface Route | ||
*/ | ||
export interface Route { | ||
@@ -4,0 +10,0 @@ httpMethod: HttpMethod; |
import 'reflect-metadata'; | ||
import { Class } from '../class.interface'; | ||
/** | ||
* Get metadata of a class or a class method. | ||
* | ||
* @export | ||
* @param {string} metadataKey - The name of the metadata. | ||
* @param {Class} target - The class. | ||
* @param {string} [propertyKey] - The class method name if relevant. | ||
* @returns The metadata value. | ||
*/ | ||
export declare function getMetadata(metadataKey: string, target: Class, propertyKey?: string): any; | ||
/** | ||
* Get the HTTP method of a controller method. | ||
* | ||
* @export | ||
* @param {Class} target - The controller class. | ||
* @param {string} [propertyKey] - The method name. | ||
* @returns {(string|undefined)} - The HTTP method or undefined if none was defined. | ||
*/ | ||
export declare function getHttpMethod(target: Class, propertyKey?: string): string | undefined; | ||
/** | ||
* Get the path of a controller method. | ||
* | ||
* @export | ||
* @param {Class} target - The controller class. | ||
* @param {string} [propertyKey] - The method name. | ||
* @returns {(string|undefined)} - The path or undefined if none was defined. | ||
*/ | ||
export declare function getPath(target: Class, propertyKey?: string): string | undefined; | ||
/** | ||
* Join several HTTP request paths together. | ||
* | ||
* @export | ||
* @param {(...(string|undefined)[])} paths - The paths. | ||
* @returns {string} The resulted path. | ||
*/ | ||
export declare function join(...paths: (string | undefined)[]): string; |
@@ -5,2 +5,11 @@ "use strict"; | ||
require("reflect-metadata"); | ||
/** | ||
* Get metadata of a class or a class method. | ||
* | ||
* @export | ||
* @param {string} metadataKey - The name of the metadata. | ||
* @param {Class} target - The class. | ||
* @param {string} [propertyKey] - The class method name if relevant. | ||
* @returns The metadata value. | ||
*/ | ||
function getMetadata(metadataKey, target, propertyKey) { | ||
@@ -13,2 +22,10 @@ if (propertyKey === undefined) { | ||
exports.getMetadata = getMetadata; | ||
/** | ||
* Get the HTTP method of a controller method. | ||
* | ||
* @export | ||
* @param {Class} target - The controller class. | ||
* @param {string} [propertyKey] - The method name. | ||
* @returns {(string|undefined)} - The HTTP method or undefined if none was defined. | ||
*/ | ||
function getHttpMethod(target, propertyKey) { | ||
@@ -18,2 +35,10 @@ return getMetadata('httpMethod', target, propertyKey); | ||
exports.getHttpMethod = getHttpMethod; | ||
/** | ||
* Get the path of a controller method. | ||
* | ||
* @export | ||
* @param {Class} target - The controller class. | ||
* @param {string} [propertyKey] - The method name. | ||
* @returns {(string|undefined)} - The path or undefined if none was defined. | ||
*/ | ||
function getPath(target, propertyKey) { | ||
@@ -23,2 +48,9 @@ return getMetadata('path', target, propertyKey); | ||
exports.getPath = getPath; | ||
/** | ||
* Join several HTTP request paths together. | ||
* | ||
* @export | ||
* @param {(...(string|undefined)[])} paths - The paths. | ||
* @returns {string} The resulted path. | ||
*/ | ||
function join(...paths) { | ||
@@ -25,0 +57,0 @@ return paths.join('').replace(/(\/)+/g, '/'); |
@@ -8,3 +8,5 @@ import 'reflect-metadata'; | ||
/** | ||
* Decorator used to inject a service inside a controller or another service. | ||
* Decorator injecting a service inside a controller or another service. | ||
* | ||
* @export | ||
*/ | ||
@@ -15,4 +17,8 @@ export declare function dependency(target: any, propertyKey: string): void; | ||
* | ||
* @param serviceClass The service class. | ||
* @param dependencies Either a ServiceManager or an object which key/values are the service properties/instances. | ||
* @export | ||
* @template Service | ||
* @param {Class<Service>} serviceClass - The service class. | ||
* @param {(object|ServiceManager)} [dependencies] - Either a ServiceManager or an | ||
* object which key/values are the service properties/instances. | ||
* @returns {Service} - The created service. | ||
*/ | ||
@@ -22,12 +28,27 @@ export declare function createService<Service>(serviceClass: Class<Service>, dependencies?: object | ServiceManager): Service; | ||
* Identity Mapper that instantiates and returns service singletons. | ||
* | ||
* @export | ||
* @class ServiceManager | ||
*/ | ||
export declare class ServiceManager { | ||
readonly map: Map<Class<any>, any>; | ||
/** | ||
* Add manually a service to the identity mapper. This function is | ||
* useful during tests to inject mocks. | ||
* | ||
* @template Service | ||
* @param {Class<Service>} serviceClass - The service class representing the key. | ||
* @param {*} service - The service object (or mock) representing the value. | ||
* @memberof ServiceManager | ||
*/ | ||
set<Service>(serviceClass: Class<Service>, service: any): void; | ||
/** | ||
* Get or create the service singleton. | ||
* Get (and create if necessary) the service singleton. | ||
* | ||
* @param serviceClass | ||
* @template Service | ||
* @param {Class<Service>} serviceClass - The service class. | ||
* @returns {Service} - The service instance. | ||
* @memberof ServiceManager | ||
*/ | ||
get<Service>(serviceClass: Class<Service>): Service; | ||
} |
@@ -5,3 +5,5 @@ "use strict"; | ||
/** | ||
* Decorator used to inject a service inside a controller or another service. | ||
* Decorator injecting a service inside a controller or another service. | ||
* | ||
* @export | ||
*/ | ||
@@ -18,4 +20,8 @@ function dependency(target, propertyKey) { | ||
* | ||
* @param serviceClass The service class. | ||
* @param dependencies Either a ServiceManager or an object which key/values are the service properties/instances. | ||
* @export | ||
* @template Service | ||
* @param {Class<Service>} serviceClass - The service class. | ||
* @param {(object|ServiceManager)} [dependencies] - Either a ServiceManager or an | ||
* object which key/values are the service properties/instances. | ||
* @returns {Service} - The created service. | ||
*/ | ||
@@ -43,2 +49,5 @@ function createService(serviceClass, dependencies) { | ||
* Identity Mapper that instantiates and returns service singletons. | ||
* | ||
* @export | ||
* @class ServiceManager | ||
*/ | ||
@@ -49,2 +58,11 @@ class ServiceManager { | ||
} | ||
/** | ||
* Add manually a service to the identity mapper. This function is | ||
* useful during tests to inject mocks. | ||
* | ||
* @template Service | ||
* @param {Class<Service>} serviceClass - The service class representing the key. | ||
* @param {*} service - The service object (or mock) representing the value. | ||
* @memberof ServiceManager | ||
*/ | ||
set(serviceClass, service) { | ||
@@ -54,5 +72,8 @@ this.map.set(serviceClass, service); | ||
/** | ||
* Get or create the service singleton. | ||
* Get (and create if necessary) the service singleton. | ||
* | ||
* @param serviceClass | ||
* @template Service | ||
* @param {Class<Service>} serviceClass - The service class. | ||
* @returns {Service} - The service instance. | ||
* @memberof ServiceManager | ||
*/ | ||
@@ -59,0 +80,0 @@ get(serviceClass) { |
import { Class } from '../core'; | ||
/** | ||
* Options of the `createApp` function. | ||
* | ||
* @export | ||
* @interface CreateAppOptions | ||
*/ | ||
export interface CreateAppOptions { | ||
@@ -6,7 +12,10 @@ store?(session: any): any; | ||
/** | ||
* Main function to create a node.js (express) application from the root controller. | ||
* @param rootControllerClass The root controller, usually called `AppController` | ||
* @param options Optional options to specify the session store (default is MemoryStore) | ||
* @param expressInstance Optional express instance to be used as base. | ||
* Create an express application from the root controller of the Foal project. | ||
* | ||
* @export | ||
* @param {Class} rootControllerClass - The root controller, usually called `AppController` and located in `src/app`. | ||
* @param {CreateAppOptions} [options={}] - Optional options to specify the session store (default is MemoryStore). | ||
* @param {*} [expressInstance] - Optional express instance to be used as base. | ||
* @returns The express application. | ||
*/ | ||
export declare function createApp(rootControllerClass: Class, options?: CreateAppOptions, expressInstance?: any): any; |
@@ -16,6 +16,9 @@ "use strict"; | ||
/** | ||
* Main function to create a node.js (express) application from the root controller. | ||
* @param rootControllerClass The root controller, usually called `AppController` | ||
* @param options Optional options to specify the session store (default is MemoryStore) | ||
* @param expressInstance Optional express instance to be used as base. | ||
* Create an express application from the root controller of the Foal project. | ||
* | ||
* @export | ||
* @param {Class} rootControllerClass - The root controller, usually called `AppController` and located in `src/app`. | ||
* @param {CreateAppOptions} [options={}] - Optional options to specify the session store (default is MemoryStore). | ||
* @param {*} [expressInstance] - Optional express instance to be used as base. | ||
* @returns The express application. | ||
*/ | ||
@@ -47,3 +50,3 @@ function createApp(rootControllerClass, options = {}, expressInstance) { | ||
if (core_1.Config.get('settings.csrf', false)) { | ||
app.use(csurf({ cookie: true })); | ||
app.use(csurf()); | ||
} | ||
@@ -50,0 +53,0 @@ else { |
import { Route, ServiceManager } from '../core'; | ||
/** | ||
* Create an express middleware from a Route and the application services. | ||
* | ||
* @export | ||
* @param {Route} route - The route object. | ||
* @param {ServiceManager} services - The application services. | ||
* @returns {(...args) => any} The express middleware. | ||
*/ | ||
export declare function createMiddleware(route: Route, services: ServiceManager): (...args: any[]) => any; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core_1 = require("../core"); | ||
/** | ||
* Create an express middleware from a Route and the application services. | ||
* | ||
* @export | ||
* @param {Route} route - The route object. | ||
* @param {ServiceManager} services - The application services. | ||
* @returns {(...args) => any} The express middleware. | ||
*/ | ||
function createMiddleware(route, services) { | ||
@@ -5,0 +13,0 @@ return async (req, res, next) => { |
@@ -0,1 +1,9 @@ | ||
/** | ||
* Create an express middleware to return a 500 HTML page if an error is thrown and is not caught. | ||
* | ||
* @export | ||
* @param {boolean} debug - Specify if the error stack should be included in the page. | ||
* @param {*} [logFn=console.error] | ||
* @returns The express middleware. | ||
*/ | ||
export declare function handleErrors(debug: boolean, logFn?: { | ||
@@ -2,0 +10,0 @@ (message?: any, ...optionalParams: any[]): void; |
@@ -17,2 +17,10 @@ "use strict"; | ||
} | ||
/** | ||
* Create an express middleware to return a 500 HTML page if an error is thrown and is not caught. | ||
* | ||
* @export | ||
* @param {boolean} debug - Specify if the error stack should be included in the page. | ||
* @param {*} [logFn=console.error] | ||
* @returns The express middleware. | ||
*/ | ||
function handleErrors(debug, logFn = console.error) { | ||
@@ -19,0 +27,0 @@ return (err, req, res, next) => { |
@@ -0,1 +1,7 @@ | ||
/** | ||
* Create an express middleware to display a 404 HTML page. | ||
* | ||
* @export | ||
* @returns The express middleware. | ||
*/ | ||
export declare function notFound(): (req: any, res: any) => void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const page404 = '<html><head><title>PAGE NOT FOUND</title></head><body><h1>404 - PAGE NOT FOUND</h1></body></html>'; | ||
/** | ||
* Create an express middleware to display a 404 HTML page. | ||
* | ||
* @export | ||
* @returns The express middleware. | ||
*/ | ||
function notFound() { | ||
@@ -5,0 +11,0 @@ return (req, res) => { |
{ | ||
"name": "@foal/core", | ||
"version": "0.8.5", | ||
"version": "0.8.6", | ||
"description": "High level web framework to create enterprise-grade Node.JS applications.", | ||
@@ -90,3 +90,3 @@ "main": "./lib/index.js", | ||
"devDependencies": { | ||
"@foal/ejs": "^0.8.0", | ||
"@foal/ejs": "^0.8.6", | ||
"@types/mocha": "^2.2.43", | ||
@@ -93,0 +93,0 @@ "@types/node": "^10.1.2", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
144771
3816