@sap-cloud-sdk/odata-common
Version:
SAP Cloud SDK for JavaScript common functions of OData client generator and OpenAPI clint generator.
55 lines • 2.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnumField = void 0;
const filter_1 = require("../filter");
const field_1 = require("./field");
const complex_type_field_1 = require("./complex-type-field");
/**
* Represents a property with an enum value.
* @typeParam EntityT - Type of the entity the field belongs to.
* @typeParam EnumT - Enum type that contains all valid enum entries for this field.
* @typeParam NullableT - Boolean type that represents whether the field is nullable.
* @typeParam SelectableT - Boolean type that represents whether the field is selectable.
*/
class EnumField extends field_1.Field {
/**
* Creates an instance of EnumField.
* @param fieldName - Actual name of the field used in the OData request.
* @param _fieldOf - The constructor of the entity or the complex type field this field belongs to.
* @param enumType - Enum type of the field according to the metadata description.
* @param fieldOptions - Optional settings for this field.
*/
constructor(fieldName, _fieldOf, enumType, fieldOptions) {
super(fieldName, (0, complex_type_field_1.getEntityConstructor)(_fieldOf), fieldOptions);
this._fieldOf = _fieldOf;
this.enumType = enumType;
this.edmType = 'Edm.Enum';
}
/**
* Gets the path to the complex type property represented by this.
* @returns The path to the complex type property.
*/
fieldPath() {
return this._fieldOf instanceof complex_type_field_1.ComplexTypeField
? `${this._fieldOf.fieldPath()}/${this._fieldName}`
: this._fieldName;
}
/**
* Creates an instance of Filter for this field and the given value using the operator 'eq', i.e. `==`.
* @param value - Value to be used in the filter.
* @returns The resulting filter.
*/
equals(value) {
return new filter_1.Filter(this.fieldPath(), 'eq', value, this.edmType);
}
/**
* Creates an instance of Filter for this field and the given value using the operator 'ne', i.e. `!=`.
* @param value - Value to be used in the filter.
* @returns The resulting filter.
*/
notEquals(value) {
return new filter_1.Filter(this.fieldPath(), 'ne', value, this.edmType);
}
}
exports.EnumField = EnumField;
//# sourceMappingURL=enum-field.js.map