All files / lib/model/oasis/annotations PropertyValue.js

100% Statements 13/13
100% Branches 4/4
100% Functions 4/4
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49    1x                                   3x 53x     3x 3x 6x     3x 1x     2x         2x     2x 2x         1x  
"use strict";
 
const _ = require("lodash");
 
/**
 * Envelops an Property Value. (OASIS-CSDL)
 *
 * http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/cs01/odata-csdl-xml-v4.01-cs01.html#_Toc501463385
 * (https://docs.microsoft.com/en-us/openspecs/windows_protocols/mc-csdl/cc1d9892-120e-4446-aa05-79db89897f4f)
 *
 * @class PropertyValue
 */
class PropertyValue {
  /**
   * Creates an instance of PropertyValue.
   * @param {Object} rawMetadata raw metadata object for the record
   * @param {Object} expressionBuilder expression builder for creating value objects
   * @memberof PropertyValue
   */
  constructor(rawMetadata, expressionBuilder) {
    Object.defineProperty(this, "raw", {
      get: () => rawMetadata,
    });
 
    let property = rawMetadata.$ ? rawMetadata.$.Property : undefined;
    Object.defineProperty(this, "property", {
      get: () => property,
    });
 
    if (!this.property) {
      throw new Error("PropertyValue must contain attribute Property.");
    }
 
    expressionBuilder.assignElementValue(
      this,
      `PropertyValue '${this.property}'`
    );
 
    let annotations = _.get(this.raw, "Annotation", []).map(
      expressionBuilder.buildAnnotation
    );
    Object.defineProperty(this, "annotations", {
      get: () => annotations,
    });
  }
}
 
module.exports = PropertyValue;