UNPKG

angular-odata

Version:

Client side OData typescript library for Angular

50 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CsdlNavigationPropertyBinding = void 0; const csdl_entity_set_1 = require("./csdl-entity-set"); class CsdlNavigationPropertyBinding { constructor(entitySet, { Path, Target }) { this.entitySet = entitySet; this.Path = Path; this.Target = Target; } toJson() { return { Path: this.Path, Target: this.Target, }; } entityType() { return this.entitySet instanceof csdl_entity_set_1.CsdlEntitySet ? this.entitySet.EntityType : this.entitySet.Type; } resolvePropertyName() { return this.Path.split('/').pop(); } resolvePropertyType(findEntityType) { const parts = this.Path.split('/'); let entityType = findEntityType(this.entityType()); if (parts.length > 1) { for (let i = 0; i < parts.length - 1; i++) { const part = parts[i]; const baseEntity = findEntityType(part); if (baseEntity) { entityType = baseEntity; } else { const navProp = entityType === null || entityType === void 0 ? void 0 : entityType.findNavigationPropertyType(part, findEntityType); entityType = navProp ? findEntityType(navProp.Type) : undefined; } } } return entityType; } resolveNavigationPropertyType(findEntityType) { const name = this.Path.split('/').pop(); let entity = this.resolvePropertyType(findEntityType); if (entity && name) { return entity.findNavigationPropertyType(name, findEntityType); } } } exports.CsdlNavigationPropertyBinding = CsdlNavigationPropertyBinding; //# sourceMappingURL=csdl-navigation-property-binding.js.map