@sap-cloud-sdk/odata-common
Version:
SAP Cloud SDK for JavaScript common functions of OData client generator and OpenAPI clint generator.
66 lines • 3.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EdmTypeField = void 0;
const filter_1 = require("../filter");
const complex_type_field_1 = require("./complex-type-field");
const field_1 = require("./field");
/**
* Represents a property of an OData entity with an EDM type.
*
* `EdmTypeField`s are used as static properties of entities or EDM typed fields of complex type fields. They are generated from the OData metadata, i.e. for each property of
* an OData entity, that has an EDM type, there is one static instance of `EdmTypeField` (or rather one of its subclasses) in the corresponding generated class file.
* `EdmTypeField`s are used to represent the domain of more or less primitive values that can be used in select, filter and order by functions.
* For example, when constructing a query on the BusinessPartner entity, an instance of `EdmTypeField<BusinessPartner, string>`
* can be supplied as argument to the select function, e.g. `BusinessPartner.FIRST_NAME`.
*
* See also: {@link Selectable}.
* @typeParam EntityT - Type of the entity the field belongs to.
* @typeParam DeSerializersT - Type of the (de-)serializers.
* @typeParam EdmT - EDM type of the field.
* @typeParam NullableT - Boolean type that represents whether the field is nullable.
* @typeParam SelectableT - Boolean type that represents whether the field is selectable.
*/
class EdmTypeField extends field_1.Field {
/**
* Creates an instance of EdmTypeField.
* @param fieldName - Actual name of the field used in the OData request.
* @param _fieldOf - Constructor type of the entity the field belongs to.
* @param edmType - Type of the field according to the metadata description.
* @param _deSerializers - (De-)serializers used for transformation.
* @param fieldOptions - Optional settings for this field.
*/
constructor(fieldName, _fieldOf, edmType, _deSerializers, // Only necessary for the type, unused otherwise
fieldOptions) {
super(fieldName, (0, complex_type_field_1.getEntityConstructor)(_fieldOf), fieldOptions);
this._fieldOf = _fieldOf;
this.edmType = edmType;
this._deSerializers = _deSerializers;
}
/**
* 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);
}
/**
* Path to the field to be used in filter and order by queries.
* @returns Path to the field to be used in filter and order by queries.
*/
fieldPath() {
return this._fieldOf instanceof complex_type_field_1.ComplexTypeField
? `${this._fieldOf.fieldPath()}/${this._fieldName}`
: this._fieldName;
}
}
exports.EdmTypeField = EdmTypeField;
//# sourceMappingURL=edm-type-field.js.map