UNPKG

@sap/xsodata

Version:

Expose data from a HANA database as OData V2 service with help of .xsodata files.

114 lines (88 loc) 3.15 kB
'use strict'; var configuration = require('./../configuration'); var Logger = require('./../utils/logger'); /** * Contains the context for a http request-response cycle * E.g. when processing several request-response cycles within $batch this context is * unique for batch request-response cycle * @class * @param networkContext * @param requestOptions * @constructor */ module.exports = function RequestContext(networkContext, requestOptions ) { //filled by index.js requestOptions = requestOptions || {}; this.handlerConfiguration = networkContext.handlerConfiguration; this.networkContext = networkContext; this.uniqueNetworkRequestID = networkContext.uniqueNetworkRequestID; this.uniqueRequestID = networkContext.getNextRequestID(); this.keyCounter = -1; this.getNextKeyCounter = function () { this.keyCounter += 1; return this.keyCounter; }; this.getScopes = function getScopes() { return this.gModel.getScopes(); }; //requestOptions this.mode = requestOptions.mode || this.handlerConfiguration.mode; this.trace = { time: this.mode === configuration.modes.development }; this.debugView = null; if (typeof requestOptions === 'string') { this.uriPrefix = requestOptions; this.db = { client: null, opener: null, closer: null }; } else { this.db = requestOptions ? { client: requestOptions.dbClient, opener : requestOptions.dbOpenCB, closer : requestOptions.dbCloseCB } : null; this.functionExecutor = requestOptions.functionExecutor; this.moduleLoader = requestOptions.moduleLoader; this.uriPrefix = requestOptions.uriPrefix; } /** * If this context is used to process a OData request which is was send via $batch && multipart/mixed to the server * @type {null} */ this.batchContext = null; //fast access to logger if (requestOptions.logger) { this.logger = new Logger(requestOptions.logger, this); } else { this.logger = this.handlerConfiguration.logger.cloneWithContext(this); } this.profileData = {"info": "showing context.profileData"}; //request this.request = null; this.response = null; //fast access to xsodata serviceDirectory this.serviceConfiguration = this.handlerConfiguration.serviceConfiguration; this.servingDirectory = this.handlerConfiguration.servingDirectory; this.defaultSchema = this.handlerConfiguration.defaultSchema; //filled and used by db.js this.client = null; //filled by uriParser this.uriTree = null; //filled by xsoDataFileReader /** * Doc typing helps syntax completion * @type {Model} */ this.gModel = null; //filled by odataUriParser.js this.oData = null; //one db segment per table access this.appData = this.handlerConfiguration.appData || {}; //collect time measurements this.measurements = []; this.isAuthorized = false; this.locale = requestOptions.locale || 'default'; };