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

100% Statements 16/16
100% Branches 2/2
100% Functions 6/6
100% Lines 16/16

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 50 51 52    1x                                   5x 11x     5x 5x 2x     5x     5x 1x     5x     5x 2x     5x 5x 1x         1x  
"use strict";
 
const _ = require("lodash");
 
/**
 * Envelops an Record Expression. (OASIS-CSDL)
 *
 * http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/cs01/odata-csdl-xml-v4.01-cs01.html#sec_Record
 * (https://docs.microsoft.com/en-us/openspecs/windows_protocols/mc-csdl/acee574d-2fe1-4da7-a65e-acf35643eb1d)
 *
 * @class Record
 */
class Record {
  /**
   * Creates an instance of Record.
   * @param {Object} rawMetadata raw metadata object for the record
   * @param {Object} expressionBuilder expression builder for creating value objects
   * @memberof Record
   */
  constructor(rawMetadata, expressionBuilder) {
    Object.defineProperty(this, "raw", {
      get: () => rawMetadata,
    });
 
    let type = rawMetadata.$ ? rawMetadata.$.Type : undefined;
    Object.defineProperty(this, "type", {
      get: () => type,
    });
 
    let annotations = _.get(this.raw, "Annotation", []).map(
      expressionBuilder.buildAnnotation
    );
    Object.defineProperty(this, "annotations", {
      get: () => annotations,
    });
 
    let propertyValues = _.get(this.raw, "PropertyValue", []).map(
      expressionBuilder.buildPropertyValue
    );
    Object.defineProperty(this, "propertyValues", {
      get: () => propertyValues,
    });
 
    let value = _.keyBy(propertyValues, "property");
    Object.defineProperty(this, "value", {
      get: () => value,
    });
  }
}
 
module.exports = Record;