UNPKG

abap-adt-api

Version:

Interface to Abap Developer Tools webservice

79 lines (78 loc) 2.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.nodeContents = exports.isNodeParent = void 0; const utilities_1 = require("../utilities"); function isNodeParent(t) { return t === "DEVC/K" || t === "PROG/P" || t === "FUGR/F" || t === "PROG/PI"; } exports.isNodeParent = isNodeParent; const decodeComponents = (keys) => (x) => { if ((0, utilities_1.isObject)(x)) { const o = keys.reduce((acc, key) => { const v = x[key] || ""; return (0, utilities_1.isString)(v) ? { ...acc, [key]: v } : acc; }, {}); return { ...x, ...o }; } return x; }; const parsePackageResponse = (data) => { let nodes = []; let categories = []; let objectTypes = []; if (data) { const xml = (0, utilities_1.parse)(data); const root = xml["asx:abap"]["asx:values"].DATA; nodes = (0, utilities_1.xmlArray)(root, "TREE_CONTENT", "SEU_ADT_REPOSITORY_OBJ_NODE"); for (const node of nodes) { if (!(0, utilities_1.isString)(node.OBJECT_NAME)) { node.OBJECT_NAME = (node.OBJECT_NAME || "").toString(); node.TECH_NAME = (node.TECH_NAME || "").toString(); } node.DESCRIPTION = node.DESCRIPTION || ""; } categories = (0, utilities_1.xmlArray)(root, "CATEGORIES", "SEU_ADT_OBJECT_CATEGORY_INFO"); objectTypes = (0, utilities_1.xmlArray)(root, "OBJECT_TYPES", "SEU_ADT_OBJECT_TYPE_INFO") .map(decodeComponents(["OBJECT_TYPE_LABEL"])) .map(ot => { const o = ot; return o.OBJECT_TYPE_LABEL === "<no type text>" && o.OBJECT_TYPE === "FUGR/I" ? { ...o, OBJECT_TYPE_LABEL: "Includes" } : o; }); } return { categories, nodes, objectTypes }; }; // tslint:disable: variable-name async function nodeContents(h, parent_type, parent_name, user_name, parent_tech_name, rebuild_tree, parentnodes) { const qs = { parent_type, withShortDescriptions: true }; const options = { method: "POST", qs }; if (parent_name) qs.parent_name = parent_name; if (parent_tech_name) qs.parent_tech_name = parent_tech_name; if (user_name) qs.user_name = user_name; if (rebuild_tree) qs.rebuild_tree = "X"; if (parentnodes === null || parentnodes === void 0 ? void 0 : parentnodes.length) options.body = `<?xml version="1.0" encoding="UTF-8" ?><asx:abap version="1.0" xmlns:asx="http://www.sap.com/abapxml"> <asx:values><DATA> ${parentnodes .map(n => `<TV_NODEKEY>${n.toString().padStart(6, "0")}</TV_NODEKEY>`) .join("")} <TV_NODEKEY>000000</TV_NODEKEY> </DATA></asx:values></asx:abap> `; const response = await h.request("/sap/bc/adt/repository/nodestructure", options); return parsePackageResponse(response.body); } exports.nodeContents = nodeContents;