All files / lib/model/oasis/extensions Extender.js

100% Statements 11/11
100% Branches 0/0
100% Functions 8/8
100% Lines 11/11

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      1x 1x     1x 1x 2x                                                 1x   1x 1x 1x 2x                 1x  
"use strict";
 
function applyEntityTypeExtensions(entityType) {
  Object.defineProperty(entityType, "sap", {
    get: () => ({}),
  });
 
  entityType.properties.forEach((p) =>
    Object.defineProperty(p, "sap", {
      get: () => ({
        sortable: true, // no longer used, SortRestrictions to be used
      }),
    })
  );
}
 
/**
 * Envelope for vendor specific extensions.
 *
 * SAP extensions implemented
 *
 * https://github.com/SAP/odata-vocabularies
 *
 * @class Extender
 */
class Extender {
  /**
   * Applies available extensions to given schema.
   *
   * @static
   * @param {CsdlSchema} [schema] schema for extension
   * @memberof Extender
   */
  static apply(schema) {
    schema.entityTypes.forEach(applyEntityTypeExtensions);
 
    schema.entityContainers.forEach((ec) =>
      ec.entitySets.forEach((es) =>
        Object.defineProperty(es, "sap", {
          get: () => ({
            pageable: true, // by OData v4 definition
          }),
        })
      )
    );
  }
}
 
module.exports = Extender;