@ui5/task-adaptation
Version:
Custom task for ui5-builder which allows building UI5 Flexibility Adaptation Projects for SAP BTP, Cloud Foundry environment
70 lines • 2.51 kB
JavaScript
export default class MetadataJsonUtil {
static mapAnnotationsPerTarget(json) {
const annotations = Array.isArray(json) ? json : this.getAnnotations(json);
return new Map(annotations.map((json, index) => [json?._attributes?.Target, { json, index }]));
}
static getVersion(json) {
return this.getEdmx(json)?._attributes?.Version;
}
static getAnnotations(json) {
return this.toArrayReadOnly(this.getSchemaNode(json)?.Annotations);
}
static setAnnotations(json, annotations) {
const schema = this.getSchemaNode(json);
annotations.forEach(annotation => annotation._attributes.xmlns = "http://docs.oasis-open.org/odata/ns/edm");
schema.Annotations = annotations;
}
static getSchemaNode(json) {
return this.getDataServices(json)?.Schema;
}
static getSchemaReference(json) {
return MetadataInclude.fromJson(this.getDataServices(json)?.Schema?._attributes);
}
static getEdmx(json) {
return json["edmx:Edmx"];
}
static getDataServices(json) {
return this.getEdmx(json)["edmx:DataServices"];
}
static getReferences(json) {
const referenceNode = this.toArrayReadOnly(this.getEdmx(json)["edmx:Reference"]);
return referenceNode.map(ref => new MetadataReference(ref));
}
static toArrayReadOnly(json) {
return Array.isArray(json) ? json : [json];
}
static toArrayTransform(json, property) {
if (!Array.isArray(json[property])) {
json[property] = [json[property]];
}
}
}
export class MetadataReference {
uri;
includes = new Array();
constructor(referenceJson) {
this.uri = referenceJson._attributes.Uri;
for (const include of MetadataJsonUtil.toArrayReadOnly(referenceJson["edmx:Include"])) {
this.includes.push(MetadataInclude.fromJson(include));
}
}
getAlias(namespace) {
const include = this.includes.find(include => include.namespace === namespace);
return include?.alias;
}
}
export class MetadataInclude {
namespace;
alias;
constructor(alias, namespace) {
this.alias = alias;
this.namespace = namespace;
}
equals(other) {
return this.alias === other.alias && this.namespace === other.namespace;
}
static fromJson(json) {
return new MetadataInclude(json?._attributes?.Alias, json?._attributes?.Namespace);
}
}
//# sourceMappingURL=metadataJsonUtil.js.map