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

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

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 53 54 55    1x     54x 2453x     54x 114x     54x 1x     54x 1x                                           54x   50x     50x 2x     50x       1x  
"use strict";
 
const _ = require("lodash");
 
function createBasicProperties(annotation, rawMetadata) {
  Object.defineProperty(annotation, "raw", {
    get: () => rawMetadata,
  });
 
  Object.defineProperty(annotation, "term", {
    get: () => rawMetadata.$.Term,
  });
 
  Object.defineProperty(annotation, "qualifier", {
    get: () => rawMetadata.$.Qualifier,
  });
 
  if (!annotation.term) {
    throw new Error("Annotation must contain attribute Term.");
  }
}
 
/**
 * Envelops an annotation. (OASIS-CSDL)
 *
 * http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/cs01/odata-csdl-xml-v4.01-cs01.html#sec_Annotation
 *
 * MC-CSDL has different concept (TypeAnnotation and ValueAnnotation)
 * see https://docs.microsoft.com/en-us/openspecs/windows_protocols/mc-csdl/9fb2fa3c-5aac-4430-87c6-6786314b1588
 *
 * @class Annotation
 */
class Annotation {
  /**
   * Creates an instance of Annotation.
   * @param {Object} rawMetadata raw metadata object for the annotation
   * @param {Object} expressionBuilder expression builder for creating value objects
   * @memberof Annotation
   */
  constructor(rawMetadata, expressionBuilder) {
    createBasicProperties(this, rawMetadata);
 
    let annotations = _.get(this.raw, "Annotation", []).map(
      expressionBuilder.buildAnnotation
    );
    Object.defineProperty(this, "annotations", {
      get: () => annotations,
    });
 
    expressionBuilder.assignElementValue(this, `Annotation '${this.term}'`);
  }
}
 
module.exports = Annotation;