UNPKG

angular-odata

Version:

Client side OData typescript library for Angular

77 lines 2.75 kB
"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 utils_1 = require("../utils"); class EntityProperty { constructor(edmType) { this.edmType = edmType; } name() { return this.edmType.Name; } type() { let type = (0, utils_1.toTypescriptType)(this.edmType.Type); type += this.edmType.Collection ? '[]' : ''; type += this.edmType.Nullable ? ' | null' : ''; return type; } } exports.EntityProperty = EntityProperty; class Entity extends base_1.Base { constructor(options, edmType) { super(options); this.edmType = edmType; } template() { return (0, schematics_1.url)('./files/entity'); } variables() { var _a, _b; return { type: this.name() + (this.edmType instanceof csdl_structured_type_1.CsdlEntityType ? 'EntityType' : 'ComplexType'), baseType: this.edmType.BaseType, properties: [ ...((_a = this.edmType.Property) !== null && _a !== void 0 ? _a : []).map((p) => new EntityProperty(p)), ...((_b = this.edmType.NavigationProperty) !== null && _b !== void 0 ? _b : []).map((p) => new EntityProperty(p)), ], }; } 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.Type.startsWith('Edm.')) { 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.Type.startsWith('Edm.')) { imports.push(prop.Type); } } return imports; } } exports.Entity = Entity; //# sourceMappingURL=entity.js.map