angular-odata
Version:
Client side OData typescript library for Angular
107 lines • 3.97 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Entity = exports.EntityProperty = void 0;
const core_1 = require("@angular-devkit/core");
const base_1 = require("./base");
const csdl_structured_type_1 = require("../metadata/csdl/csdl-structured-type");
const schematics_1 = require("@angular-devkit/schematics");
const csdl_structural_property_1 = require("../metadata/csdl/csdl-structural-property");
const utils_1 = require("../utils");
class EntityProperty {
constructor(entity, edmType) {
this.entity = entity;
this.edmType = edmType;
}
name() {
const required = !(this.edmType instanceof csdl_structural_property_1.CsdlNavigationProperty || this.edmType.Nullable);
const name = this.edmType.Name;
return name + (!required ? '?' : '');
}
type() {
const pkg = this.entity.getPackage();
const enumType = pkg.findEnum(this.edmType.Type);
const entityType = pkg.findEntity(this.edmType.Type);
let type = "any";
if (enumType !== undefined) {
type = enumType.importedName;
type += this.edmType.Collection ? '[]' : '';
}
else if (entityType !== undefined) {
type = entityType.importedName;
type += this.edmType.Collection ? '[]' : '';
}
else {
type = (0, utils_1.toTypescriptType)(this.edmType.Type);
type += this.edmType.Collection ? '[]' : '';
}
return type;
}
isGeoSpatial() {
return this.edmType.Type.startsWith('Edm.Geography') || this.edmType.Type.startsWith('Edm.Geometry');
}
}
exports.EntityProperty = EntityProperty;
class Entity extends base_1.Base {
constructor(pkg, options, edmType) {
super(pkg, options);
this.edmType = edmType;
}
template() {
return (0, schematics_1.url)('./files/entity');
}
variables() {
return {
type: this.name() + (this.edmType instanceof csdl_structured_type_1.CsdlEntityType ? 'EntityType' : 'ComplexType'),
baseType: this.edmType.BaseType,
properties: this.properties(),
geoProperties: this.geoProperties(),
hasGeoProperties: this.hasGeoProperties(),
};
}
name() {
return core_1.strings.classify(this.edmType.name());
}
fileName() {
return (core_1.strings.dasherize(this.edmType.name()) +
(this.edmType instanceof csdl_structured_type_1.CsdlEntityType ? '.entity' : '.complex'));
}
directory() {
return this.edmType.namespace().replace(/\./g, '/');
}
fullName() {
return this.edmType.fullName();
}
importTypes() {
var _a, _b, _c, _d;
const imports = [];
if (this.edmType.BaseType) {
imports.push(this.edmType.BaseType);
}
for (let prop of (_b = (_a = this.edmType) === null || _a === void 0 ? void 0 : _a.Property) !== null && _b !== void 0 ? _b : []) {
if (!prop.isEdmType()) {
imports.push(prop.Type);
}
}
for (let prop of (_d = (_c = this.edmType) === null || _c === void 0 ? void 0 : _c.NavigationProperty) !== null && _d !== void 0 ? _d : []) {
if (!prop.isEdmType()) {
imports.push(prop.Type);
}
}
return imports;
}
properties() {
var _a, _b;
return [
...((_a = this.edmType.Property) !== null && _a !== void 0 ? _a : []).map((p) => new EntityProperty(this, p)),
...((_b = this.edmType.NavigationProperty) !== null && _b !== void 0 ? _b : []).map((p) => new EntityProperty(this, p)),
];
}
geoProperties() {
return this.properties().filter((p) => p.isGeoSpatial());
}
hasGeoProperties() {
return this.geoProperties().length > 0;
}
}
exports.Entity = Entity;
//# sourceMappingURL=entity.js.map