angular-odata
Version:
Client side OData typescript library for Angular
129 lines • 4.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CsdlPropertyRef = exports.CsdlKey = exports.CsdlEntityType = exports.CsdlComplexType = exports.CsdlStructuredType = void 0;
const csdl_annotation_1 = require("./csdl-annotation");
const csdl_structural_property_1 = require("./csdl-structural-property");
class CsdlStructuredType extends csdl_annotation_1.CsdlAnnotable {
constructor(schema, { Name, Property, NavigationProperty, BaseType, OpenType, Abstract, Annotation, }) {
super({ Annotation });
this.schema = schema;
this.Name = Name;
this.Property = Property === null || Property === void 0 ? void 0 : Property.map((p) => new csdl_structural_property_1.CsdlProperty(this, p));
this.NavigationProperty = NavigationProperty === null || NavigationProperty === void 0 ? void 0 : NavigationProperty.map((n) => new csdl_structural_property_1.CsdlNavigationProperty(this, n));
this.BaseType = BaseType;
this.OpenType = OpenType;
this.Abstract = Abstract;
}
toJson() {
const json = Object.assign(Object.assign({}, super.toJson()), { Name: this.Name });
if (Array.isArray(this.Property) && this.Property.length > 0) {
json['Property'] = this.Property.map((p) => p.toJson());
}
if (Array.isArray(this.NavigationProperty) && this.NavigationProperty.length > 0) {
json['NavigationProperty'] = this.NavigationProperty.map((n) => n.toJson());
}
if (this.BaseType !== undefined) {
json['BaseType'] = this.BaseType;
}
if (this.OpenType !== undefined) {
json['OpenType'] = this.OpenType;
}
if (this.Abstract !== undefined) {
json['Abstract'] = this.Abstract;
}
return json;
}
name() {
return `${this.Name}`;
}
namespace() {
return `${this.schema.Namespace}`;
}
fullName() {
return `${this.schema.Namespace}.${this.Name}`;
}
findNavigationPropertyType(propertyName, findEntityType) {
var _a;
let nav;
let structured = this;
while (true) {
nav = (_a = structured.NavigationProperty) === null || _a === void 0 ? void 0 : _a.find((n) => n.Name === propertyName);
if (nav)
return nav;
if (!structured.BaseType)
break;
structured = findEntityType(structured.BaseType);
}
throw new Error(`Navigation property '${propertyName}' not found on type '${this.fullName()}' or its base types.`);
}
}
exports.CsdlStructuredType = CsdlStructuredType;
class CsdlComplexType extends CsdlStructuredType {
constructor(schema, { Name, Property, NavigationProperty, BaseType, OpenType, Abstract, Annotation, }) {
super(schema, {
Name,
Property,
NavigationProperty,
BaseType,
OpenType,
Abstract,
Annotation,
});
}
toJson() {
return Object.assign({}, super.toJson());
}
}
exports.CsdlComplexType = CsdlComplexType;
class CsdlEntityType extends CsdlStructuredType {
constructor(schema, { Name, Key, Property, NavigationProperty, BaseType, OpenType, Abstract, HasStream, Annotation, }) {
super(schema, {
Name,
Property,
NavigationProperty,
BaseType,
OpenType,
Abstract,
Annotation,
});
this.Key = Key ? new CsdlKey(Key) : undefined;
this.HasStream = HasStream;
}
toJson() {
const json = Object.assign({}, super.toJson());
if (this.Key !== undefined) {
json['Key'] = this.Key.toJson();
}
if (this.HasStream !== undefined) {
json['HasStream'] = this.HasStream;
}
return json;
}
}
exports.CsdlEntityType = CsdlEntityType;
class CsdlKey {
constructor({ PropertyRef }) {
this.PropertyRef = PropertyRef === null || PropertyRef === void 0 ? void 0 : PropertyRef.map((p) => new CsdlPropertyRef(p));
}
toJson() {
var _a;
return {
PropertyRef: (_a = this.PropertyRef) === null || _a === void 0 ? void 0 : _a.map((p) => p.toJson()),
};
}
}
exports.CsdlKey = CsdlKey;
class CsdlPropertyRef {
constructor({ Name, Alias }) {
this.Name = Name;
this.Alias = Alias;
}
toJson() {
return {
Name: this.Name,
Alias: this.Alias,
};
}
}
exports.CsdlPropertyRef = CsdlPropertyRef;
//# sourceMappingURL=csdl-structured-type.js.map