@foal/core
Version:
Full-featured Node.js framework, with no complexity
44 lines (43 loc) • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Context = void 0;
const file_1 = require("../../common/file");
/**
* Class instantiated on each request. It includes:
* - the express request object,
* - the user object if available,
* - the session object if available,
* - a file list object,
* - the name of the controller and the name of the method,
* - and a `state` object that can be used to pass data across several hooks.
*
* @export
* @class Context
* @template User
*/
class Context {
request;
session;
user;
state;
files;
controllerName;
controllerMethodName;
/**
* Creates an instance of Context.
* @param {*} request - Either the express request object or a mock (for testing).
* @param {string} [controllerName=''] - The name of the controller.
* @param {string} [controllerMethodName=''] - The name of the method.
* @memberof Context
*/
constructor(request, controllerName = '', controllerMethodName = '') {
this.request = request;
this.session = null;
this.user = null;
this.state = {};
this.files = new file_1.FileList();
this.controllerName = controllerName;
this.controllerMethodName = controllerMethodName;
}
}
exports.Context = Context;