Skip to content

Commit

Permalink
make API added
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrdjan committed Feb 18, 2021
1 parent dd1abd6 commit 226e074
Show file tree
Hide file tree
Showing 7 changed files with 1,668 additions and 584 deletions.
27 changes: 19 additions & 8 deletions abap-api-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,20 @@ short:

## Integration

Your tools and applications can use integration API `call` and `get` methods, to access ABAP annotations and call templates.
Integration api provides ABAP annotations, call templates and pre-fabricated ui components, for consumption by other tools, applications or SDKs:

Either the destination id or connection parameters can be provided, with one or more RFM names.
| Method | Output | Backend connection |
| ------ | -------------------------------- | ------------------ |
| `call` | Call templates | required |
| `get` | Call templates, ABAP annotations | required |
| `make` | Call templates, ui components | not required |

Check [unit tests](https://github.com/SAP/fundamental-tools/tree/main/abap-api-tools/tests) for usage details and result data structure.
Either the destination id or connection parameters can be used, with one or more RFM names.

Check usage examples in [unit tests](https://github.com/SAP/fundamental-tools/blob/main/abap-api-tools/tests/cliapi.spec.js) and [reference results](https://github.com/SAP/fundamental-tools/blob/main/abap-api-tools/tests/results.js) for data structures' details.

```ts
import { CliApi, CliResult, RfcConnectionParameters } from "abap-api-tools";
import { AbapCliApi, AbapCliResult, RfcConnectionParameters, AnnotationsType } from "abap-api-tools";
const cp: RfcConnectionParameters = {
user: "demo",
Expand All @@ -385,13 +391,18 @@ const cp: RfcConnectionParameters = {
};
(async () => {
let R:CliResult;
let R:AbapCliResult;
const api = new AbapCliApi();
const api = new CliApi();
// Call templates
R = await a.call("MME", "stfc_connection");
R = await a.get(cp, ["stfc_connection", "stfc_structure"]); // annotations only
// Call templates and annotations
R = await a.get(cp, ["stfc_connection", "stfc_structure"]);
R = await a.call("MME", "stfc_connection"); // annotations and call templates
// Call templates and ui components
R = await a.make(R.annotations as AnnotationsType, "fudamental-ngx");
})();
```
Expand Down
4 changes: 2 additions & 2 deletions abap-api-tools/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions abap-api-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "abap-api-tools",
"description": "ABAP api tools",
"version": "1.7.1",
"version": "1.8.0",
"homepage": "https://github.com/sap/fundamental-tools",
"author": "SAP",
"license": "Apache-2.0",
Expand Down Expand Up @@ -31,7 +31,8 @@
"dependencies": "npm i --save chalk js-yaml loglevel sprintf-js yargs node-rfc",
"devDependencies": "npm i --save-dev @types/node @types/js-yaml @types/sprintf-js @types/yargs @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint jest typescript",
"build": "reuse lint && rm -rf dist && npm run ts && npm run lint",
"lock": "npm install --package-lock-only"
"lock": "npm install --package-lock-only",
"test": "jest tests --detectOpenHandles"
},
"keywords": [
"sap",
Expand Down
65 changes: 51 additions & 14 deletions abap-api-tools/src/ts/abap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const Command = Object.freeze({
export type ApiListType = Record<string, string[]>;

export type Destination = string | RfcConnectionParameters;
export { RfcConnectionParameters };
export { RfcConnectionParameters, AnnotationsType };

export type Arguments = {
//[argName: string]: unknown;
Expand All @@ -53,13 +53,15 @@ export type Arguments = {
save?: boolean;
textOnly?: string;
ui?: string;
"sort-fields"?: boolean;
runInBg?: boolean;
};

export type CliResult = {
export type AbapCliResult = {
annotations?: AnnotationsType;
frontend?: FrontendResult;
};

class CliHandler {
private argv: Arguments;

Expand Down Expand Up @@ -98,20 +100,20 @@ class CliHandler {
log.debug(argv);
}

async run(): Promise<CliResult> {
const result: CliResult = {};
async run(): Promise<AbapCliResult> {
const result: AbapCliResult = {};
if (this.argv.apilist) {
for (const api_name of Object.keys(this.argv.apilist)) {
let annotations: AnnotationsType = {
parameters: {},
fields: {},
stat: {},
};
let annotations = {} as AnnotationsType;
if ([Command.call, Command.get].includes(this.argv.cmd)) {
log.debug(`backend run ${api_name}`);
const backend = new Backend(api_name, this.argv);
annotations = await backend.parse();
result[api_name] = { annotations: annotations };
if (this.argv.cmd === Command.get) {
// call method annotations are w/o search helps
// only get annotations are complete
result[api_name] = { annotations: annotations };
}
}

if (
Expand Down Expand Up @@ -155,14 +157,18 @@ class CliHandler {
}
}

export class CliApi {
private options = { lang: DefaultLanguage, debug: false };
export class AbapCliApi {
private options = {
lang: DefaultLanguage,
"sort-fields": false,
debug: false,
};

async call(
dest: Destination,
rfm_names: string | string[],
options?: { lang?: string; debug?: boolean }
): Promise<CliResult> {
): Promise<AbapCliResult> {
if (options) {
Object.assign(this.options, options);
}
Expand Down Expand Up @@ -194,7 +200,7 @@ export class CliApi {
dest: Destination,
rfm_names: string | string[],
options?: { lang?: string; debug?: boolean }
): Promise<CliResult> {
): Promise<AbapCliResult> {
if (options) {
Object.assign(this.options, options);
}
Expand All @@ -221,6 +227,37 @@ export class CliApi {

return result[""];
}

make(
annotations: AnnotationsType,
ui: string,
options?: { "sort-fields"?: boolean; debug?: boolean }
): AbapCliResult {
if (options) {
Object.assign(this.options, options);
}

log.setDefaultLevel(
this.options.debug ? log.levels.DEBUG : log.levels.SILENT
);

const args: Arguments = {
_: [Command.make],
$0: "abap",
cmd: Command.make,
output: "",
apilist: { "": Object.keys(annotations.parameters) },
ui: ui,
"sort-fields": this.options["sort-fields"],
lang: this.options.lang,
debug: this.options.debug,
runInBg: true,
};

const frontend = new Frontend("", annotations, args);
const result: AbapCliResult = { frontend: frontend.parse() };
return result;
}
}

// invoked via CLI
Expand Down
2 changes: 2 additions & 0 deletions abap-api-tools/src/ts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export function makeDir(dir: string): void {
}

export function isEmpty(obj: Record<string, unknown>): boolean {
if (obj === undefined) return true;
if (Array.isArray(obj)) return obj.length === 0;
return Object.keys(obj).length === 0;
}

Expand Down
Loading

0 comments on commit 226e074

Please sign in to comment.