UNPKG

@sap/odata-v4

Version:

OData V4.0 server library

137 lines (119 loc) 3.35 kB
'use strict'; const EdmTypeFactory = require('./EdmTypeFactory'); const EdmAnnotation = require('./EdmAnnotation'); const validateThat = require('../validator/ParameterValidator').validateThat; const FeatureSupport = require('../FeatureSupport'); /** * Abstract super class to manage facets, i.e., restrictions for typed values; * {@link EdmProperty}, {@link EdmReturnType}, {@link EdmParameter}, and {@link EdmTerm} * derive from this class. Since they all have an EDM type and can have annotations, * this class handles that as well. * * @abstract * @hideconstructor * @ignore */ class AbstractEdmFaceted { /** * Creates an instance of AbstractEdmFaceted. * @param {Edm} edm the entity-data model * @param {CsdlProperty|CsdlReturnType|CsdlParameter|CsdlTerm} csdlObject the associated CSDL object */ constructor(edm, csdlObject) { validateThat('edm', edm).truthy(); validateThat('csdlObject', csdlObject).truthy(); /** * @type {Edm} * @private */ this._edm = edm; if (csdlObject.unicode !== undefined && !csdlObject.unicode) { FeatureSupport.failUnsupported(FeatureSupport.features.AttributeUnicode); } /** * @type {CsdlProperty|CsdlReturnType|CsdlParameter|CsdlTerm} * @private */ this._csdlObject = csdlObject; /** * @type {EdmType} * @private */ this._type = null; /** * @type {EdmAnnotation[]} * @private */ this._annotations = null; } /** * Returns true if this EDM objedt is a collection, false otherwise. * @returns {boolean} */ isCollection() { return this._csdlObject.isCollection; } /** * Returns true if this EDM object is nullable, false otherwise. * @returns {boolean} */ isNullable() { return this._csdlObject.isNullable; } /** * Returns the max length. * @returns {?(number|string)} */ getMaxLength() { return this._csdlObject.maxLength; } /** * Returns the precision. * @returns {?number} */ getPrecision() { return this._csdlObject.precision; } /** * Returns the scale. * @returns {?(number|string)} */ getScale() { return this._csdlObject.scale; } /** * Returns the SRID. * @returns {?(number|string)} */ getSrid() { return this._csdlObject.srid; } /** * Returns true if the (string) value is Unicode encoded, false otherwise. * @returns {boolean} */ isUnicode() { return this._csdlObject.unicode; } /** * Returns the property type. * @returns {EdmType} */ getType() { if (!this._type) { this._type = EdmTypeFactory.createTypeFromFQN(this._edm, this._csdlObject.type); } return this._type; } /** * Returns the annotations for this EDM object. * @returns {EdmAnnotation[]} */ getAnnotations() { if (!this._annotations) { this._annotations = this._csdlObject.annotations.map(item => new EdmAnnotation(this._edm, item)); } return this._annotations; } } module.exports = AbstractEdmFaceted;