UNPKG

igniteui-webcomponents-datasources

Version:

Reference custom data providers for the Ignite UI Web Components data source.

80 lines (79 loc) 2.76 kB
import { EntityProperty } from "./EntityProperty"; import { XName } from "igniteui-webcomponents-core"; import { toArray } from './util'; var Entity = /** @class */ /*@__PURE__*/ (function () { function Entity(name, entityNode) { this._properties = null; this._primaryKey = null; this._name = null; this.name = name; this.loadProperties(entityNode); this.loadPrimaryKey(entityNode); } Object.defineProperty(Entity.prototype, "name", { get: function () { return this._name; }, set: function (value) { this._name = value; }, enumerable: false, configurable: true }); Object.defineProperty(Entity.prototype, "properties", { get: function () { if (null == this._properties) { this._properties = new Map(); } return this._properties; }, enumerable: false, configurable: true }); Object.defineProperty(Entity.prototype, "primaryKey", { get: function () { if (null == this._primaryKey) { this._primaryKey = []; } return this._primaryKey; }, enumerable: false, configurable: true }); Entity.prototype.loadProperties = function (entityNode) { var children = toArray(entityNode.elements()); var elementCount = children.length; var nameAttr = XName.get("Name", ""); var typeAttr = XName.get("Type", ""); for (var i = 0; i < elementCount; i++) { var node = children[i]; if (node.name.localName == "Property") { var name_1 = node.attribute(nameAttr).value; var type = node.attribute(typeAttr).value; this.properties.set(name_1, new EntityProperty(name_1, type)); } } ; }; Entity.prototype.loadPrimaryKey = function (entityNode) { var children = toArray(entityNode.elements()); var elementCount = children.length; var nameAttr = XName.get("Name", ""); for (var i = 0; i < elementCount; i++) { var node = children[i]; if (node.name.localName == "Key") { var subChildren = toArray(node.elements()); var keyNodeCOunt = subChildren.length; for (var j = 0; j < keyNodeCOunt; j++) { var keyNode = subChildren[j]; if (keyNode.name.localName == "PropertyRef") { this.primaryKey.push(keyNode.attribute(nameAttr).value); } } } } ; }; return Entity; }()); export { Entity };