@sap/odata-v4
Version:
OData V4.0 server library
234 lines (206 loc) • 5.59 kB
JavaScript
'use strict';
/**
* Stores the parsed prefer headers from the request.
*
* <a href="../ODataSpecification/odata-v4.0-errata03-os/complete/part1-protocol/odata-v4.0-errata03-os-part1-protocol-complete.html#_Toc453752234">
* OData V4 part1 protocol 8.2.8 Header Prefer
* </a>
*
* @hideconstructor
*/
class Preferences {
constructor() {
this._odataAllowEntityReferences = false;
this._odataCallback = null;
this._odataContinueOnError = false;
this._odataIncludeAnnotations = null;
this._odataMaxPageSize = null;
this._odataTrackChanges = null;
this._return = null;
this._respondAsync = false;
this._wait = null;
this._customPreferences = new Map();
}
/**
* Returns true if Preference "odata.allow-entityreferences" is set.
* @returns {boolean}
*/
getOdataAllowEntityReferences() {
return this._odataAllowEntityReferences;
}
/**
* @param {boolean} value
* @package
*/
setOdataAllowEntityReferences(value) {
this._odataAllowEntityReferences = value;
}
/**
* Returns the URI in Preference "odata.callback;url=<URI>".
* @returns {?string}
*/
getOdataCallback() {
return this._odataCallback;
}
/**
* @param {?string} value
* @package
*/
setOdataCallback(value) {
this._odataCallback = value;
}
/**
* Returns true if Preference "odata.continue-on-error" is set.
* @returns {boolean}
*/
getOdataContinueOnError() {
return this._odataContinueOnError;
}
/**
* @param {boolean} value
* @package
*/
setOdataContinueOnError(value) {
this._odataContinueOnError = value;
}
/**
* Returns the annotations list in "odata.include-annotations".
* @returns {*}
*/
getOdataIncludeAnnotations() {
return this._odataIncludeAnnotations;
}
/**
* @param {*} value
* @package
*/
setOdataIncludeAnnotations(value) {
this._odataIncludeAnnotations = value;
}
/**
* Returns the number set in Preference "odata.maxpagesize=<number>".
* @returns {?number}
*/
getOdataMaxPageSize() {
return this._odataMaxPageSize;
}
/**
* @param {?number} value
* @package
*/
setOdataMaxPageSize(value) {
this._odataMaxPageSize = value;
}
/**
* Returns true if Preference "odata.track-changes" is set.
* @returns {boolean}
*/
getOdataTrackChanges() {
return this._odataTrackChanges;
}
/**
* @param {boolean} value
* @package
*/
setOdataTrackChanges(value) {
this._odataTrackChanges = value;
}
/**
* Returns the ReturnName set in Preference "return=<Preferences.ReturnValues>".
* @returns {?Preferences.ReturnValues}
*/
getReturn() {
return this._return;
}
/**
* @param {?Preferences.ReturnValues} value
* @package
*/
setReturn(value) {
this._return = value;
}
/**
* Returns true if Preference "respond-async" is set.
* @returns {boolean}
*/
getRespondAsync() {
return this._respondAsync;
}
/**
* @param {boolean} value
* @package
*/
setRespondAsync(value) {
this._respondAsync = value;
}
/**
* Returns the number in Preference "wait=<number>"
* @returns {?number}
*/
getWait() {
return this._wait;
}
/**
* @param {?number} value
* @package
*/
setWait(value) {
this._wait = value;
}
/**
* Adds a custom preference object to the custom preferences map.
* The key in the map is the name of the preference (the token referring to the ABNF)
* @param {CustomPreference} customPreference the custom preference to add to the map
* @package
*/
setCustomPreference(customPreference) {
this._customPreferences.set(customPreference.getPreferenceName(), customPreference);
}
/**
* Returns the value of a custom preference.
* Returns null if the custom preference does not exist.
* @param {string} customPreferenceName
* @returns {?(string|boolean)} The value of the given custom preference
*/
getCustomPreferenceValue(customPreferenceName) {
const customPreference = this._customPreferences.get(customPreferenceName);
return customPreference ? customPreference.getValue() : null;
}
/**
* Returns all parameters of a custom preference.
* @param {string} preferenceName name of the preference
* @returns {Map.<string, string|boolean>} the parameters of the custom preference
*/
getCustomPreferenceParameters(preferenceName) {
return this._customPreferences.get(preferenceName).getParameters();
}
}
/**
* Values for the return preference
*
* @enum {string}
* @readonly
*/
Preferences.ReturnValues = {
MINIMAL: 'minimal',
REPRESENTATION: 'representation'
};
/**
* Names of the odata prefer headers
*
* @enum {string}
* @readonly
* @package
*/
Preferences.Names = {
ALLOW_ENTITYREFERENCES: 'odata.allow-entityreferences',
CALLBACK: 'odata.callback',
CONTINUE_ON_ERROR: 'odata.continue-on-error',
INCLUDE_ANNOTATIONS: 'odata.include-annotations',
MAXPAGESIZE: 'odata.maxpagesize',
RESPOND_ASYNC: 'respond-async',
RETURN: 'return',
TRACK_CHANGES: 'odata.track-changes',
WAIT: 'wait'
};
module.exports = Preferences;