ui5plugin-parser
Version:
117 lines (116 loc) • 4.28 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SAPNodeDAO = void 0;
const URLBuilder_1 = require("../http/URLBuilder");
const IFileReader_1 = require("../parsing/util/filereader/IFileReader");
const SAPNode_1 = require("./SAPNode");
class SAPNodeDAO {
constructor(parser) {
this._SAPNodes = [];
this._flatSAPNodes = {};
this.parser = parser;
}
async getAllNodes() {
if (this._SAPNodes.length === 0) {
await this._readAllNodes();
await this._generateSAPNodes();
}
return this._SAPNodes;
}
isInstanceOf(child, parent) {
let isInstance = child === parent;
const parentNode = this.findNode(parent);
const parentMetadata = parentNode?.getMetadata()?.getRawMetadata();
isInstance = isInstance || !!parentMetadata?.implements?.includes(child);
if (!isInstance && parentMetadata && parentMetadata?.extends) {
isInstance = this.isInstanceOf(child, parentMetadata?.extends);
}
return isInstance;
}
_getContentOfNode(node) {
let children = [];
children.push(node);
if (node.nodes) {
node.nodes.forEach(node => {
children = children.concat(this._getContentOfNode(node));
});
}
return children;
}
getAllNodesSync() {
return this._SAPNodes;
}
async _generateSAPNodes() {
const libs = this.parser.configHandler.getLibsToLoad();
const libMap = {};
libs.forEach((lib) => {
libMap[lib] = true;
});
for (const node of this._nodes.symbols) {
if (libMap[node.lib]) {
const newNode = new SAPNode_1.SAPNode(node, this.parser.metadataDAO);
this._SAPNodes.push(newNode);
}
}
this._recursiveFlatNodeGeneration(this._SAPNodes);
}
recursiveModuleAssignment() {
const nodes = this._SAPNodes;
nodes.forEach(node => {
if (node.getMetadata()?.getRawMetadata()) {
const moduleName = node.getMetadata()?.getRawMetadata()?.module?.replace(/\//g, ".");
if (moduleName !== node.getName()) {
const moduleNode = this.findNode(moduleName);
const nodeMetadata = node.getMetadata().getRawMetadata();
if (moduleNode && nodeMetadata) {
const rawMetadata = moduleNode.getMetadata().getRawMetadata();
if (!rawMetadata.properties) {
rawMetadata.properties = [];
}
const property = {
name: nodeMetadata.name,
visibility: nodeMetadata.visibility,
description: nodeMetadata.description,
type: node.getName()
};
rawMetadata.properties.push(property);
}
}
}
});
}
_recursiveFlatNodeGeneration(nodes) {
nodes.forEach(SAPNode => {
this._flatSAPNodes[SAPNode.getName()] = SAPNode;
if (SAPNode.nodes) {
this._recursiveFlatNodeGeneration(SAPNode.nodes);
}
});
}
async _readAllNodes() {
this._nodes = this._getApiIndexFromCache();
if (!this._nodes) {
await this._fetchApiIndex();
this._cacheApiIndex();
}
}
_getApiIndexFromCache() {
return this.parser.fileReader.getCache(IFileReader_1.IFileReader.CacheType.APIIndex);
}
_cacheApiIndex() {
const cache = JSON.stringify(this._nodes);
this.parser.fileReader.setCache(IFileReader_1.IFileReader.CacheType.APIIndex, cache);
}
async _fetchApiIndex() {
const path = new URLBuilder_1.URLBuilder(this.parser.configHandler).getAPIIndexUrl();
const data = await this.parser.httpHandler.get(path);
this._nodes = data;
}
findNode(name) {
return this._flatSAPNodes[name];
}
getFlatNodes() {
return this._flatSAPNodes;
}
}
exports.SAPNodeDAO = SAPNodeDAO;