@st-gr/abap-adt-skill 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.execCommand = execCommand;
37
+ const fs = __importStar(require("fs"));
38
+ const crypto = __importStar(require("crypto"));
39
+ const abap_adt_api_patched_1 = require("@st-gr/abap-adt-api-patched");
40
+ const client_1 = require("../client");
41
+ async function execCommand(options) {
42
+ let userCode;
43
+ if (options.sourceFile) {
44
+ userCode = fs.readFileSync(options.sourceFile, "utf-8");
45
+ }
46
+ else if (options.code) {
47
+ userCode = options.code;
48
+ }
49
+ else {
50
+ console.error("Error: Provide --source-file or --code");
51
+ process.exit(1);
52
+ }
53
+ const suffix = crypto.randomBytes(3).toString("hex").toUpperCase();
54
+ const className = `ZCL_EXEC_${suffix}`;
55
+ const classUrl = `/sap/bc/adt/oo/classes/${className.toLowerCase()}`;
56
+ const source = `CLASS ${className} DEFINITION PUBLIC CREATE PUBLIC.
57
+ PUBLIC SECTION.
58
+ INTERFACES if_oo_adt_classrun.
59
+ ENDCLASS.
60
+
61
+ CLASS ${className} IMPLEMENTATION.
62
+ METHOD if_oo_adt_classrun~main.
63
+ ${userCode}
64
+ ENDMETHOD.
65
+ ENDCLASS.`;
66
+ const client = await (0, client_1.getClient)();
67
+ // Use stateless clone for non-session operations (createObject/activate leave backend in weird state otherwise)
68
+ const sc = client.statelessClone;
69
+ try {
70
+ // Create temp class in $TMP
71
+ await sc.createObject("CLAS/OC", className, "$TMP", "Temp exec", "/sap/bc/adt/packages/%24tmp", "", "");
72
+ // Write source — resolve source URL via object structure
73
+ const struct = await sc.objectStructure(classUrl);
74
+ const sourceUrl = abap_adt_api_patched_1.ADTClient.mainInclude(struct);
75
+ await (0, client_1.withStatefulSession)(async (c) => {
76
+ const lock = await c.lock(classUrl);
77
+ try {
78
+ await c.setObjectSource(sourceUrl, source, lock.LOCK_HANDLE);
79
+ }
80
+ finally {
81
+ await c.unLock(classUrl, lock.LOCK_HANDLE);
82
+ }
83
+ });
84
+ // Activate
85
+ const actResult = await sc.activate(className, classUrl);
86
+ if (!actResult.success) {
87
+ const msgs = (actResult.messages || []).map((m) => m.shortText || "").join("; ");
88
+ throw new Error(`Activation failed: ${msgs || "unknown error"}`);
89
+ }
90
+ // Run
91
+ const raw = await sc.runClass(className);
92
+ const output = raw.replace(/\n{2,}/g, "\n").trim();
93
+ if (options.json) {
94
+ console.log(JSON.stringify({ className, output }));
95
+ }
96
+ else {
97
+ console.log(output);
98
+ }
99
+ }
100
+ finally {
101
+ // Best-effort cleanup: delete temp class
102
+ try {
103
+ await (0, client_1.withStatefulSession)(async (c) => {
104
+ const lock = await c.lock(classUrl);
105
+ await c.deleteObject(classUrl, lock.LOCK_HANDLE);
106
+ });
107
+ }
108
+ catch (_a) {
109
+ console.error(`Warning: Could not delete temp class ${className} — clean up manually in $TMP`);
110
+ }
111
+ }
112
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.packageContentsCommand = packageContentsCommand;
4
+ const client_1 = require("../client");
5
+ async function packageContentsCommand(packageName, options) {
6
+ const client = await (0, client_1.getStatelessClient)();
7
+ const result = await client.nodeContents("DEVC/K", packageName.toUpperCase());
8
+ if (options.json) {
9
+ console.log(JSON.stringify(result, null, 2));
10
+ return;
11
+ }
12
+ if (result.nodes.length === 0) {
13
+ console.log(`Package ${packageName.toUpperCase()} is empty or not found.`);
14
+ return;
15
+ }
16
+ console.log(`Package ${packageName.toUpperCase()} — ${result.nodes.length} object(s):\n`);
17
+ for (const node of result.nodes) {
18
+ const desc = node.DESCRIPTION ? ` ${node.DESCRIPTION}` : "";
19
+ console.log(` ${padRight(node.OBJECT_TYPE, 10)} ${padRight(node.OBJECT_NAME, 30)}${desc}`);
20
+ }
21
+ }
22
+ function padRight(s, len) {
23
+ return s.length >= len ? s : s + " ".repeat(len - s.length);
24
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.prettyPrintCommand = prettyPrintCommand;
37
+ const fs = __importStar(require("fs"));
38
+ const client_1 = require("../client");
39
+ async function prettyPrintCommand(options) {
40
+ const client = await (0, client_1.getStatelessClient)();
41
+ const source = fs.readFileSync(options.sourceFile, "utf-8");
42
+ const formatted = await client.prettyPrinter(source);
43
+ // Sanity check: warn if output length differs >20% from input (guards against server bugs)
44
+ if (source.length > 0) {
45
+ const ratio = Math.abs(formatted.length - source.length) / source.length;
46
+ if (ratio > 0.2) {
47
+ console.error(`Warning: Formatted output differs by ${Math.round(ratio * 100)}% in length from input — review carefully.`);
48
+ }
49
+ }
50
+ if (options.output) {
51
+ fs.writeFileSync(options.output, formatted, "utf-8");
52
+ console.log(`Formatted source written to: ${options.output}`);
53
+ }
54
+ else {
55
+ console.log(formatted);
56
+ }
57
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.quickfixCommand = quickfixCommand;
37
+ const fs = __importStar(require("fs"));
38
+ const client_1 = require("../client");
39
+ async function quickfixCommand(objectUrl, options) {
40
+ const client = await (0, client_1.getStatelessClient)();
41
+ const source = fs.readFileSync(options.sourceFile, "utf-8");
42
+ const line = parseInt(options.line);
43
+ const column = parseInt(options.column);
44
+ const proposals = await client.fixProposals(objectUrl, source, line, column);
45
+ if (options.apply !== undefined) {
46
+ const idx = parseInt(options.apply);
47
+ if (idx < 0 || idx >= proposals.length) {
48
+ console.error(`Error: Index ${idx} out of range (0..${proposals.length - 1})`);
49
+ process.exit(1);
50
+ }
51
+ const deltas = await client.fixEdits(proposals[idx], source);
52
+ if (options.json) {
53
+ console.log(JSON.stringify(deltas, null, 2));
54
+ }
55
+ else {
56
+ for (const d of deltas) {
57
+ console.log(`${d.uri} [${d.range.start.line}:${d.range.start.column}–${d.range.end.line}:${d.range.end.column}]`);
58
+ if (d.content)
59
+ console.log(` → ${d.content}`);
60
+ }
61
+ }
62
+ return;
63
+ }
64
+ if (options.json) {
65
+ console.log(JSON.stringify(proposals, null, 2));
66
+ return;
67
+ }
68
+ if (proposals.length === 0) {
69
+ console.log("No fix proposals available.");
70
+ return;
71
+ }
72
+ console.log(`${proposals.length} fix proposal(s):\n`);
73
+ for (let i = 0; i < proposals.length; i++) {
74
+ const p = proposals[i];
75
+ console.log(` [${i}] ${p["adtcore:name"]} — ${p["adtcore:description"] || ""}`);
76
+ }
77
+ console.log(`\nUse --apply <index> to apply a fix.`);
78
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readCommand = readCommand;
4
+ const abap_adt_api_patched_1 = require("@st-gr/abap-adt-api-patched");
5
+ const client_1 = require("../client");
6
+ async function readCommand(objectUrl, options) {
7
+ const client = await (0, client_1.getStatelessClient)();
8
+ let sourceUrl = objectUrl;
9
+ // If the URL doesn't look like a source URL, resolve it
10
+ if (!objectUrl.includes("/source/")) {
11
+ const struct = await client.objectStructure(objectUrl);
12
+ if (options.include && (0, abap_adt_api_patched_1.isClassStructure)(struct)) {
13
+ const classStruct = struct;
14
+ const includes = abap_adt_api_patched_1.ADTClient.classIncludes(classStruct);
15
+ const include = includes.get(options.include);
16
+ if (include) {
17
+ sourceUrl = include;
18
+ }
19
+ else {
20
+ console.error(`Include '${options.include}' not found. Available: ${Array.from(includes.keys()).join(", ")}`);
21
+ process.exit(1);
22
+ }
23
+ }
24
+ else {
25
+ sourceUrl = abap_adt_api_patched_1.ADTClient.mainInclude(struct);
26
+ }
27
+ }
28
+ const version = options.version;
29
+ const source = await client.getObjectSource(sourceUrl, version ? { version } : undefined);
30
+ console.log(source);
31
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renameCommand = renameCommand;
4
+ const client_1 = require("../client");
5
+ async function renameCommand(objectUrl, options) {
6
+ const line = parseInt(options.line);
7
+ const startCol = parseInt(options.startCol);
8
+ const endCol = parseInt(options.endCol);
9
+ await (0, client_1.withStatefulSession)(async (client) => {
10
+ var _a;
11
+ // Step 1: Evaluate — get the rename proposal
12
+ const proposal = await client.renameEvaluate(objectUrl, line, startCol, endCol);
13
+ if (options.json) {
14
+ console.log(JSON.stringify({ proposal, oldName: proposal.oldName }, null, 2));
15
+ }
16
+ else {
17
+ console.log(`Renaming "${proposal.oldName}" → "${options.newName}"`);
18
+ }
19
+ // Set the new name
20
+ proposal.newName = options.newName;
21
+ // Step 2: Preview — see affected objects
22
+ const transport = options.transport || "";
23
+ const preview = await client.renamePreview(proposal, transport);
24
+ if (!options.json && preview.affectedObjects && preview.affectedObjects.length > 0) {
25
+ console.log(`\nAffected objects:`);
26
+ for (const obj of preview.affectedObjects) {
27
+ const deltas = ((_a = obj.textReplaceDeltas) === null || _a === void 0 ? void 0 : _a.length) || 0;
28
+ console.log(` ${obj.name} (${obj.type}) — ${deltas} change(s)`);
29
+ }
30
+ }
31
+ // Step 3: Execute
32
+ const result = await client.renameExecute(preview);
33
+ if (options.json) {
34
+ console.log(JSON.stringify(result, null, 2));
35
+ }
36
+ else {
37
+ console.log(`\nRename completed successfully.`);
38
+ }
39
+ });
40
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCommand = runCommand;
4
+ const client_1 = require("../client");
5
+ async function runCommand(className, options) {
6
+ const client = await (0, client_1.getStatelessClient)();
7
+ const raw = await client.runClass(className);
8
+ // ADT classrun returns double newlines between lines — collapse to single
9
+ const output = raw.replace(/\n{2,}/g, "\n").trim();
10
+ if (options.json) {
11
+ console.log(JSON.stringify({ className: className.toUpperCase(), output }));
12
+ }
13
+ else {
14
+ console.log(output);
15
+ }
16
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.searchCommand = searchCommand;
4
+ const client_1 = require("../client");
5
+ const formatter_1 = require("../util/formatter");
6
+ async function searchCommand(query, options) {
7
+ const client = await (0, client_1.getStatelessClient)();
8
+ const results = await client.searchObject(query, options.type, options.max ? parseInt(options.max, 10) : 100);
9
+ if (options.json) {
10
+ (0, formatter_1.output)(results, true);
11
+ return;
12
+ }
13
+ if (results.length === 0) {
14
+ console.log("No objects found.");
15
+ return;
16
+ }
17
+ const rows = results.map(r => ({
18
+ Name: r["adtcore:name"],
19
+ Type: r["adtcore:type"],
20
+ Package: r["adtcore:packageName"] || "",
21
+ Description: r["adtcore:description"] || "",
22
+ URI: r["adtcore:uri"]
23
+ }));
24
+ console.log((0, formatter_1.formatTable)(rows));
25
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.structureCommand = structureCommand;
4
+ const abap_adt_api_patched_1 = require("@st-gr/abap-adt-api-patched");
5
+ const client_1 = require("../client");
6
+ const formatter_1 = require("../util/formatter");
7
+ async function structureCommand(objectUrl, options) {
8
+ const client = await (0, client_1.getStatelessClient)();
9
+ const struct = await client.objectStructure(objectUrl);
10
+ if (options.json) {
11
+ (0, formatter_1.output)(struct, true);
12
+ return;
13
+ }
14
+ const meta = struct.metaData;
15
+ console.log(`Object: ${meta["adtcore:name"]}`);
16
+ console.log(`Type: ${meta["adtcore:type"]}`);
17
+ console.log(`Description: ${meta["adtcore:description"] || ""}`);
18
+ console.log(`Package: ${meta["adtcore:responsible"] || ""}`);
19
+ console.log(`URI: ${struct.objectUrl}`);
20
+ // Source URI
21
+ const mainInclude = abap_adt_api_patched_1.ADTClient.mainInclude(struct);
22
+ console.log(`Source URI: ${mainInclude}`);
23
+ // For classes, list includes
24
+ if ((0, abap_adt_api_patched_1.isClassStructure)(struct)) {
25
+ const classStruct = struct;
26
+ console.log("\nClass Includes:");
27
+ const includes = abap_adt_api_patched_1.ADTClient.classIncludes(classStruct);
28
+ for (const [type, uri] of includes) {
29
+ console.log(` ${type}: ${uri}`);
30
+ }
31
+ }
32
+ // Links
33
+ if (struct.links && struct.links.length > 0) {
34
+ console.log("\nLinks:");
35
+ for (const link of struct.links) {
36
+ console.log(` [${link.rel || ""}] ${link.href} (${link.type || ""})`);
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.syntaxCheckCommand = syntaxCheckCommand;
37
+ const fs = __importStar(require("fs"));
38
+ const abap_adt_api_patched_1 = require("@st-gr/abap-adt-api-patched");
39
+ const client_1 = require("../client");
40
+ const formatter_1 = require("../util/formatter");
41
+ async function syntaxCheckCommand(objectUrl, options) {
42
+ const client = await (0, client_1.getClient)();
43
+ const source = fs.readFileSync(options.sourceFile, "utf-8");
44
+ // Resolve source URL and main URL
45
+ let sourceUrl = objectUrl;
46
+ let mainUrl = options.mainUrl || objectUrl;
47
+ if (!objectUrl.includes("/source/")) {
48
+ const struct = await client.objectStructure(objectUrl);
49
+ sourceUrl = abap_adt_api_patched_1.ADTClient.mainInclude(struct);
50
+ mainUrl = options.mainUrl || sourceUrl;
51
+ }
52
+ const results = await client.syntaxCheck(sourceUrl, mainUrl, source, options.mainProgram || "", "active");
53
+ if (options.json) {
54
+ (0, formatter_1.output)(results, true);
55
+ return;
56
+ }
57
+ if (results.length === 0) {
58
+ console.log("Syntax check: OK (no errors)");
59
+ return;
60
+ }
61
+ let hasErrors = false;
62
+ for (const msg of results) {
63
+ const severity = msg.severity || "W";
64
+ if (severity === "E" || severity === "A")
65
+ hasErrors = true;
66
+ const line = msg.line || "";
67
+ const offset = msg.offset || "";
68
+ const loc = line ? ` (line ${line}:${offset})` : "";
69
+ console.log(`[${severity}]${loc} ${msg.text}`);
70
+ if (msg.uri)
71
+ console.log(` URI: ${msg.uri}`);
72
+ }
73
+ if (hasErrors)
74
+ process.exit(1);
75
+ }