UNPKG

abap-adt-api

Version:

Interface to Abap Developer Tools webservice

475 lines (474 loc) 17.8 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseTraceRequestList = exports.parseTraceStatements = exports.parseTraceDbAccess = exports.parseTraceHitList = exports.parseTraceResults = exports.traceProcessObjects = exports.traceObjectTypeUris = exports.traceProcessTypeUris = void 0; const t = __importStar(require("io-ts")); const utilities_1 = require("../utilities"); const AdtException_1 = require("../AdtException"); const contributorClass = t.type({ name: t.string }); const link = t.type({ "@_href": t.string, "@_rel": t.string, "@_type": t.string, "@_title": t.string }); // A Active // R Read Only // E Error // S SizeLim // T TimeLim // C Close Error const state = t.type({ "@_value": t.string, "@_text": t.string }); const extendedData = t.type({ host: t.string, size: t.number, runtime: t.number, runtimeABAP: t.number, runtimeSystem: t.number, runtimeDatabase: t.number, expiration: t.string, system: t.string, client: t.number, isAggregated: t.boolean, aggregationKind: (0, utilities_1.orUndefined)(t.string), objectName: t.string, state: state }); const entryAuthor = t.type({ name: t.string, uri: t.string }); const entry = t.type({ author: entryAuthor, content: t.type({ "@_type": t.string, "@_src": t.string }), id: t.string, link: (0, utilities_1.xmlArrayType)(link), published: t.string, title: t.string, updated: t.string, extendedData: extendedData, "@_lang": t.string }); const feed = t.type({ author: contributorClass, contributor: contributorClass, title: t.string, updated: t.string, entry: (0, utilities_1.xmlArrayType)(entry) }); const traceResults = t.type({ feed: feed }); const time = t.type({ "@_time": t.number, "@_percentage": t.number }); const baseLink = t.type({ "@_rel": t.string, "@_href": t.string }); const calledProgram = t.type({ "@_context": t.string }); const callingProgram = (0, utilities_1.mixed)({ "@_context": t.string, "@_byteCodeOffset": t.number }, { "@_uri": t.string, "@_type": t.string, "@_name": t.string, "@_packageName": t.string, "@_objectReferenceQuery": t.string }); const hlentry = (0, utilities_1.mixed)({ calledProgram: calledProgram, grossTime: time, traceEventNetTime: time, proceduralNetTime: time, "@_topDownIndex": t.number, "@_index": t.number, "@_hitCount": t.number, "@_recursionDepth": t.number, "@_description": t.string }, { callingProgram: callingProgram, "@_stackCount": t.number, "@_proceduralEntryAnchor": t.number, "@_dbAccessAnchor": t.number }); const Hitlist = t.type({ link: baseLink, entry: (0, utilities_1.xmlArrayType)(hlentry) }); const HitListResponse = t.type({ hitlist: Hitlist }); /// const accessTime = t.type({ "@_total": t.number, "@_applicationServer": t.number, "@_database": t.number, "@_ratioOfTraceTotal": t.number }); const dBAccess = (0, utilities_1.mixed)({ accessTime: accessTime, "@_index": t.number, "@_tableName": t.string, "@_statement": t.string, "@_type": t.union([ t.literal("EXEC SQL"), t.literal("OpenSQL"), t.literal("") ]), "@_totalCount": t.number, "@_bufferedCount": t.number }, { callingProgram: callingProgram }); const dBAccesses = t.type({ link: baseLink, dbAccess: (0, utilities_1.xmlArrayType)(dBAccess), tables: t.union([ t.type({ table: (0, utilities_1.xmlArrayType)(t.type({ "@_name": t.string, "@_type": t.string, "@_description": t.string, "@_bufferMode": t.string, "@_storageType": t.string, "@_package": t.string })) }), t.literal("") ]), "@_totalDbTime": t.number }); const traceDBAccesResponse = t.type({ dbAccesses: dBAccesses }); /// const statement = (0, utilities_1.mixed)({ callingProgram: callingProgram, grossTime: time, traceEventNetTime: time, proceduralNetTime: time, "@_index": t.number, "@_id": t.number, "@_description": t.string, "@_hitCount": t.number, "@_hasDetailSubnodes": t.boolean, "@_hasProcedureLikeSubnodes": t.boolean, "@_callerId": t.number, "@_callLevel": t.number, "@_subnodeCount": t.number, "@_directSubnodeCount": t.number, "@_directSubnodeCountProcedureLike": t.number, "@_hitlistAnchor": t.number }, { "@_isProcedureLike": t.boolean, "@_isProceduralUnit": t.boolean, "@_isAutoDrillDowned": t.boolean, "@_calltreeAnchor": t.number, "@_moduleHitlistAnchor": t.number }); const traceStatementResponse = t.type({ statements: t.type({ link: baseLink, statement: (0, utilities_1.xmlArrayType)(statement), "@_withDetails": t.boolean, "@_withSysEvents": t.boolean, "@_count": t.union([t.number, t.string]) }) }); /// const author = t.type({ name: t.string, uri: t.string, "@_role": t.string }); const client = t.partial({ "#text": (0, utilities_1.orUndefined)(t.number), "@_role": t.string }); const executions = t.type({ "@_maximal": t.number, "@_completed": t.number }); const rawProcessTypes = t.union([ t.literal("/sap/bc/adt/runtime/traces/abaptraces/processtypes/any"), t.literal("/sap/bc/adt/runtime/traces/abaptraces/processtypes/http"), t.literal("/sap/bc/adt/runtime/traces/abaptraces/processtypes/dialog"), t.literal("/sap/bc/adt/runtime/traces/abaptraces/processtypes/batch"), t.literal("/sap/bc/adt/runtime/traces/abaptraces/processtypes/rfc"), t.literal("/sap/bc/adt/runtime/traces/abaptraces/processtypes/sharedobjectsarea") ]); const rawObjectTypes = t.union([ t.literal("/sap/bc/adt/runtime/traces/abaptraces/objecttypes/any"), t.literal("/sap/bc/adt/runtime/traces/abaptraces/objecttypes/url"), t.literal("/sap/bc/adt/runtime/traces/abaptraces/objecttypes/transaction"), t.literal("/sap/bc/adt/runtime/traces/abaptraces/objecttypes/report"), t.literal("/sap/bc/adt/runtime/traces/abaptraces/objecttypes/functionmodule"), t.literal("/sap/bc/adt/runtime/traces/abaptraces/objecttypes/sharedobjectarea") ]); const traceListextendedData = t.type({ host: t.string, requestIndex: t.number, client: (0, utilities_1.xmlArrayType)(client), description: t.string, isAggregated: t.boolean, expires: t.string, processType: t.type({ "@_processTypeId": rawProcessTypes }), object: t.type({ "@_objectTypeId": rawObjectTypes }), executions: executions }); const traceListEntry = (0, utilities_1.mixed)({ id: t.string, author: (0, utilities_1.xmlArrayType)(author), content: t.type({ "@_type": t.string, "@_src": t.string }), published: t.string, title: t.string, updated: t.string, extendedData: traceListextendedData, "@_lang": t.string }, { link: (0, utilities_1.xmlArrayType)(link) }); const tlFeed = t.type({ contributor: t.type({ name: t.string, "@_role": t.string }), title: t.string, updated: t.string, entry: (0, utilities_1.xmlArrayType)(traceListEntry) }); const tracesListRequest = t.type({ feed: tlFeed }); exports.traceProcessTypeUris = { ANY: "/sap/bc/adt/runtime/traces/abaptraces/processtypes/any", HTTP: "/sap/bc/adt/runtime/traces/abaptraces/processtypes/http", DIALOG: "/sap/bc/adt/runtime/traces/abaptraces/processtypes/dialog", BATCH: "/sap/bc/adt/runtime/traces/abaptraces/processtypes/batch", RFC: "/sap/bc/adt/runtime/traces/abaptraces/processtypes/rfc", SHARED_OBJECTS_AREA: "/sap/bc/adt/runtime/traces/abaptraces/processtypes/sharedobjectsarea" }; exports.traceObjectTypeUris = { ANY: "/sap/bc/adt/runtime/traces/abaptraces/objecttypes/any", URL: "/sap/bc/adt/runtime/traces/abaptraces/objecttypes/url", TRANSACTION: "/sap/bc/adt/runtime/traces/abaptraces/objecttypes/transaction", REPORT: "/sap/bc/adt/runtime/traces/abaptraces/objecttypes/report", FUNCTION_MODULE: "/sap/bc/adt/runtime/traces/abaptraces/objecttypes/functionmodule", SHARED_OBJECTS_AREA: "/sap/bc/adt/runtime/traces/abaptraces/objecttypes/sharedobjectarea" }; const decodeObjectType = (x) => { switch (x) { case "/sap/bc/adt/runtime/traces/abaptraces/objecttypes/any": return "ANY"; case "/sap/bc/adt/runtime/traces/abaptraces/objecttypes/url": return "URL"; case "/sap/bc/adt/runtime/traces/abaptraces/objecttypes/transaction": return "TRANSACTION"; case "/sap/bc/adt/runtime/traces/abaptraces/objecttypes/report": return "REPORT"; case "/sap/bc/adt/runtime/traces/abaptraces/objecttypes/functionmodule": return "FUNCTION_MODULE"; case "/sap/bc/adt/runtime/traces/abaptraces/objecttypes/sharedobjectarea": return "SHARED_OBJECTS_AREA"; default: return "ANY"; } }; const decodeProcessType = (x) => { switch (x) { case "/sap/bc/adt/runtime/traces/abaptraces/processtypes/any": return "ANY"; case "/sap/bc/adt/runtime/traces/abaptraces/processtypes/http": return "HTTP"; case "/sap/bc/adt/runtime/traces/abaptraces/processtypes/dialog": return "DIALOG"; case "/sap/bc/adt/runtime/traces/abaptraces/processtypes/batch": return "BATCH"; case "/sap/bc/adt/runtime/traces/abaptraces/processtypes/rfc": return "RFC"; case "/sap/bc/adt/runtime/traces/abaptraces/processtypes/sharedobjectsarea": return "SHARED_OBJECTS_AREA"; default: return "ANY"; } }; exports.traceProcessObjects = { ANY: [ "FUNCTION_MODULE", "URL", "TRANSACTION", "REPORT", "SHARED_OBJECTS_AREA", "ANY" ], HTTP: ["URL"], DIALOG: ["TRANSACTION", "REPORT"], BATCH: ["REPORT"], RFC: ["FUNCTION_MODULE"], SHARED_OBJECTS_AREA: ["SHARED_OBJECTS_AREA"] }; const parseRawTrace = (x) => (0, AdtException_1.validateParseResult)(traceResults.decode(x)).feed; const parseTraceResults = (xml) => { const raw = parseRawTrace((0, utilities_1.fullParse)(xml, { removeNSPrefix: true })); const runs = (0, utilities_1.extractXmlArray)(raw.entry).map(l => { const links = (0, utilities_1.extractXmlArray)(l.link).map(utilities_1.typedNodeAttr); const { id, author: { name: author, uri: authorUri }, content: { "@_type": type, "@_src": src }, "@_lang": lang, title } = l; const published = new Date(l.published); const updated = new Date(l.updated); const extendedData = { ...l.extendedData, expiration: new Date(l.extendedData.expiration), state: (0, utilities_1.typedNodeAttr)(l.extendedData.state) }; // @ts-ignore delete extendedData["#text"]; return { id, author, title, published, updated, authorUri, type, src, lang, extendedData, links }; }); const { author: { name: author }, contributor: { name: contributor }, title } = raw; const updated = new Date((0, utilities_1.xmlNode)(raw, "updated")); return { author, contributor, title, updated, runs }; }; exports.parseTraceResults = parseTraceResults; const parseTraceHitList = (xml) => { const raw = (0, AdtException_1.validateParseResult)(HitListResponse.decode((0, utilities_1.fullParse)(xml, { removeNSPrefix: true }))).hitlist; const parentLink = raw.link["@_href"]; const entries = (0, utilities_1.extractXmlArray)(raw.entry).map(e => { var _a; const callingProgram = e.callingProgram ? (0, utilities_1.typedNodeAttr)(e.callingProgram) : undefined; const calledProgram = (_a = e.calledProgram) === null || _a === void 0 ? void 0 : _a["@_context"]; const grossTime = (0, utilities_1.typedNodeAttr)(e.grossTime); const traceEventNetTime = (0, utilities_1.typedNodeAttr)(e.traceEventNetTime); const proceduralNetTime = (0, utilities_1.typedNodeAttr)(e.proceduralNetTime); return { ...(0, utilities_1.typedNodeAttr)(e), callingProgram, calledProgram, grossTime, traceEventNetTime, proceduralNetTime }; }); return { parentLink, entries }; }; exports.parseTraceHitList = parseTraceHitList; const parseTraceDbAccess = (xml) => { const toParse = (0, utilities_1.fullParse)(xml, { removeNSPrefix: true }); const parsed = traceDBAccesResponse.decode(toParse); const raw = (0, AdtException_1.validateParseResult)(parsed).dbAccesses; const parentLink = raw.link["@_href"]; const dbaccesses = (0, utilities_1.extractXmlArray)(raw.dbAccess).map(a => { const callingProgram = a.callingProgram && (0, utilities_1.typedNodeAttr)(a.callingProgram); const accessTime = (0, utilities_1.typedNodeAttr)(a.accessTime); return { ...(0, utilities_1.typedNodeAttr)(a), accessTime, callingProgram }; }); const tables = raw.tables === "" ? [] : (0, utilities_1.extractXmlArray)(raw.tables.table).map(utilities_1.typedNodeAttr); return { parentLink, dbaccesses, tables }; }; exports.parseTraceDbAccess = parseTraceDbAccess; const parseCount = (count) => { if ((0, utilities_1.isNumber)(count)) return count; const [base, exp] = count.split("E").map(utilities_1.toInt); if (exp) return base * 10 ** exp; return base; }; const parseTraceStatements = (xml) => { const raw = (0, AdtException_1.validateParseResult)(traceStatementResponse.decode((0, utilities_1.fullParse)(xml, { removeNSPrefix: true }))).statements; const parentLink = raw.link["@_href"]; const statements = (0, utilities_1.extractXmlArray)(raw.statement).map(s => { const callingProgram = (0, utilities_1.typedNodeAttr)(s.callingProgram); const grossTime = (0, utilities_1.typedNodeAttr)(s.grossTime); const proceduralNetTime = (0, utilities_1.typedNodeAttr)(s.proceduralNetTime); const traceEventNetTime = (0, utilities_1.typedNodeAttr)(s.traceEventNetTime); return { ...(0, utilities_1.typedNodeAttr)(s), callingProgram, grossTime, traceEventNetTime, proceduralNetTime }; }); const count = parseCount(raw["@_count"]); return { ...(0, utilities_1.typedNodeAttr)(raw), count, parentLink, statements }; }; exports.parseTraceStatements = parseTraceStatements; const parseTraceRequestList = (xml) => { const raw = tracesListRequest.decode((0, utilities_1.fullParse)(xml, { removeNSPrefix: true })); const parsed = (0, AdtException_1.validateParseResult)(raw).feed; const { contributor: { name: contributorName, "@_role": contributorRole }, title } = parsed; const requests = (0, utilities_1.extractXmlArray)(parsed.entry).map(e => { const { id, "@_lang": lang, title } = e; const published = new Date(e.published); const updated = new Date(e.updated); const links = (0, utilities_1.extractXmlArray)(e.link).map(utilities_1.typedNodeAttr); const authors = (0, utilities_1.extractXmlArray)(e.author).map(({ name, uri, "@_role": role }) => ({ name, role, uri })); const { "@_src": contentSrc, "@_type": contentType } = e.content; const { description, executions, isAggregated, host, requestIndex } = e.extendedData; const expires = new Date(e.extendedData.expires); const processType = decodeProcessType(e.extendedData.processType["@_processTypeId"]); const objectType = decodeObjectType(e.extendedData.object["@_objectTypeId"]); const clients = (0, utilities_1.extractXmlArray)(e.extendedData.client).map(({ "#text": id = 0, "@_role": role = "" }) => ({ id, role })); const extendedData = { description, executions: (0, utilities_1.typedNodeAttr)(executions), isAggregated, host, expires, processType, objectType, requestIndex, clients }; return { id, lang, title, published, updated, links, authors, contentSrc, contentType, extendedData }; }); return { title, contributorName, contributorRole, requests }; }; exports.parseTraceRequestList = parseTraceRequestList;