@sap-cloud-sdk/core
Version:
SAP Cloud SDK for JavaScript core
94 lines • 4.52 kB
JavaScript
/* eslint-disable max-classes-per-file */
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldBuilder = void 0;
var edm_types_1 = require("../edm-types");
var complex_type_field_1 = require("./complex-type-field");
var edm_type_field_1 = require("./edm-type-field");
var orderable_edm_type_field_1 = require("./orderable-edm-type-field");
var collection_field_1 = require("./collection-field");
var enum_field_1 = require("./enum-field");
/**
* Field builder to orchestrate the creation of the different kinds of fields.
* @typeparam FieldOfT - Type of the entity or complex type field this field belongs to.
*/
var FieldBuilder = /** @class */ (function () {
/**
* Creates an instance of `FieldBuilder`.
* @param fieldOf - Entity or complex type field, for which the field builder shall create fields.
*/
function FieldBuilder(fieldOf) {
this.fieldOf = fieldOf;
}
/**
* Build a field for a property with an EDM type.
* For `[[OrderableEdmType]]` fields, the returned fields are of type `OrderableEdmTypeField`.
* All other EDM types yield `EdmTypeField`s.
* Fields of entities are selectable; fields of complex types are not selectable.
* @param fieldName - Name of the field.
* @param edmType - EDM type of the field.
* @param isNullable - Whether the field is nullable.
* @returns An EDM type field.
*/
FieldBuilder.prototype.buildEdmTypeField = function (fieldName, edmType, isNullable) {
var isSelectable = (this.fieldOf instanceof
complex_type_field_1.ComplexTypeField);
// The type assertion is necessary because the signatures of the two constructors differ (TS design limitation)
var ctor = ((0, edm_types_1.isOrderableEdmType)(edmType) ? orderable_edm_type_field_1.OrderableEdmTypeField : edm_type_field_1.EdmTypeField);
return new ctor(fieldName, this.fieldOf, edmType, {
isNullable: isNullable,
isSelectable: isSelectable
});
};
/**
* Build a field for a property with a complex type.
* Fields of entities are selectable; fields of complex types are not selectable.
* @param fieldName - Name of the field.
* @param complexTypeFieldCtor - Constructor of the complex type field.
* @param isNullable - Whether the field is nullable.
* @returns A complex type field of the given type.
*/
FieldBuilder.prototype.buildComplexTypeField = function (fieldName, complexTypeFieldCtor, isNullable) {
var isSelectable = (this.fieldOf instanceof
complex_type_field_1.ComplexTypeField);
return new complexTypeFieldCtor(fieldName, this.fieldOf, {
isNullable: isNullable,
isSelectable: isSelectable
});
};
/**
* Build a field for a property with a collection type.
* The type of the field can either be an EDM type or a complex type.
* Fields of entities are selectable; fields of complex types are not selectable.
* @param fieldName - Name of the field.
* @param collectionFieldType - Type of the collection. Can either be an EDM type or complex type (not complex type field).
* @param isNullable - Whether the field is nullable.
* @returns A collection field with the given collection type.
*/
FieldBuilder.prototype.buildCollectionField = function (fieldName, collectionFieldType, isNullable) {
var isSelectable = (this.fieldOf instanceof
complex_type_field_1.ComplexTypeField);
return new collection_field_1.CollectionField(fieldName, this.fieldOf, collectionFieldType, {
isNullable: isNullable,
isSelectable: isSelectable
});
};
/**
* Build a field for a property with a enum type.
* @param fieldName - Name of the field.
* @param enumType - Enum type of this field.
* @param isNullable - Whether the field is nullable.
* @returns A collection field with the given collection type.
*/
FieldBuilder.prototype.buildEnumField = function (fieldName, enumType, isNullable) {
var isSelectable = (this.fieldOf instanceof
complex_type_field_1.ComplexTypeField);
return new enum_field_1.EnumField(fieldName, this.fieldOf, enumType, {
isNullable: isNullable,
isSelectable: isSelectable
});
};
return FieldBuilder;
}());
exports.FieldBuilder = FieldBuilder;
//# sourceMappingURL=field-builder.js.map
;