From 8669a38fd52794d116b054457e6cb9fe4635b71a Mon Sep 17 00:00:00 2001 From: iliyan-velichkov Date: Fri, 21 Jun 2024 16:02:42 +0300 Subject: [PATCH] use introduced Kronos ABAP API from the app --- abap_transpile.json | 2 +- abaplint.jsonc | 29 -------- build-mac.sh | 15 ++++- src/abap/zcl_abap_app.clas.abap | 26 ++++---- src/abap/zcl_dirigible_response.clas.abap | 15 ----- ...o.clas.abap => zcl_employee_dao.clas.abap} | 6 +- src/run.mjs | 66 ++++++++++++------- 7 files changed, 71 insertions(+), 88 deletions(-) delete mode 100644 abaplint.jsonc delete mode 100644 src/abap/zcl_dirigible_response.clas.abap rename src/abap/{zcl_dirigible_employee_dao.clas.abap => zcl_employee_dao.clas.abap} (92%) diff --git a/abap_transpile.json b/abap_transpile.json index 740dd98..0db06b6 100644 --- a/abap_transpile.json +++ b/abap_transpile.json @@ -1,5 +1,5 @@ { - "input_folder": "src/abap", + "input_folder": "{../../../../root/registry/public/kronos/src/abap,src/abap}", "input_filter": [], "output_folder": "dist/abap", "libs": [ diff --git a/abaplint.jsonc b/abaplint.jsonc deleted file mode 100644 index 7f2831e..0000000 --- a/abaplint.jsonc +++ /dev/null @@ -1,29 +0,0 @@ -{ - "global": { - "files": "/src/**/*.*" - }, - "dependencies": [ - { - "url": "https://github.com/open-abap/open-abap-core", - "folder": "/deps", - "files": "/src/**/*.*" - } - ], - "syntax": { - "version": "v702", - "errorNamespace": "." - }, - "rules": { - "begin_end_names": true, - "check_ddic": true, - "check_include": true, - "check_syntax": true, - "global_class": true, - "implement_methods": true, - "method_implemented_twice": true, - "parser_error": true, - "superclass_final": true, - "unknown_types": true, - "xml_consistency": true - } -} \ No newline at end of file diff --git a/build-mac.sh b/build-mac.sh index 72b76df..28e889f 100755 --- a/build-mac.sh +++ b/build-mac.sh @@ -1,3 +1,8 @@ +# fail the whole script if any command bellow fails +set -e + +export KRONOS_SRC='/Users/iliyan/work/kronos-work-dir/repo/dirigible/repository/root/registry/public/kronos/src/abap/http' + rm -rf dist rm -rf node_modules @@ -8,7 +13,9 @@ npm install # check package.json for more details npm run transpile -npm run lint +# TODO: temp commented +# to be fixed +# npm run lint # Find all .mjs files in the current directory and its subdirectories, # and replaces all occurrences of %23 with # in those files. @@ -16,5 +23,7 @@ find . -name '*.mjs' -print0 | xargs -0 sed -i '' 's/%23/#/g' esbuild src/run.mjs --tsconfig=./tsconfig.json --bundle --outdir=dist --format=esm --target=es2022 \ --external:tls --external:net --external:util --external:crypto --external:zlib \ - --external:http --external:https --external:fs --external:path --external:url --external:sdk \ - --inject:./src/lib/polyfills/buffer.js --inject:./src/lib/polyfills/process.js --out-extension:.js=.mjs + --external:http --external:https --external:fs --external:path --external:url \ + --external:sdk \ + --inject:./src/lib/polyfills/buffer.js --inject:./src/lib/polyfills/process.js \ + --out-extension:.js=.mjs diff --git a/src/abap/zcl_abap_app.clas.abap b/src/abap/zcl_abap_app.clas.abap index 03292cb..0511e7a 100644 --- a/src/abap/zcl_abap_app.clas.abap +++ b/src/abap/zcl_abap_app.clas.abap @@ -31,55 +31,55 @@ CLASS zcl_abap_app IMPLEMENTATION. ENDMETHOD. METHOD print_hello_world. - zcl_dirigible_response=>println( + zcl_codbex_response=>println( EXPORTING message_in = 'Hello world!' ). ENDMETHOD. METHOD delete_all_employees. - zcl_dirigible_response=>println( + zcl_codbex_response=>println( EXPORTING message_in = 'Deleting all employees...' ). - zcl_dirigible_employee_dao=>delete_all_employees( ). + zcl_employee_dao=>delete_all_employees( ). - zcl_dirigible_response=>println( + zcl_codbex_response=>println( EXPORTING message_in = 'All employees were deleted.' ). ENDMETHOD. METHOD insert_employee. - zcl_dirigible_response=>println( + zcl_codbex_response=>println( EXPORTING message_in = 'Inserting an employee...' ). - zcl_dirigible_employee_dao=>insert_employee( ). + zcl_employee_dao=>insert_employee( ). - zcl_dirigible_response=>println( + zcl_codbex_response=>println( EXPORTING message_in = 'An employee was inserted.' ). ENDMETHOD. METHOD select_all_employees. - zcl_dirigible_response=>println( + zcl_codbex_response=>println( EXPORTING message_in = 'Selecting all employees...' ). - zcl_dirigible_employee_dao=>select_all( ). + zcl_employee_dao=>select_all( ). - zcl_dirigible_response=>println( + zcl_codbex_response=>println( EXPORTING message_in = 'Employees selected.' ). ENDMETHOD. METHOD update_employee_last_name. - zcl_dirigible_response=>println( + zcl_codbex_response=>println( EXPORTING message_in = 'Updating employee last name...' ). - zcl_dirigible_employee_dao=>update_employee_last_name( ). + zcl_employee_dao=>update_employee_last_name( ). - zcl_dirigible_response=>println( + zcl_codbex_response=>println( EXPORTING message_in = 'Employee last name was updated.' ). ENDMETHOD. diff --git a/src/abap/zcl_dirigible_response.clas.abap b/src/abap/zcl_dirigible_response.clas.abap deleted file mode 100644 index f706e1e..0000000 --- a/src/abap/zcl_dirigible_response.clas.abap +++ /dev/null @@ -1,15 +0,0 @@ -CLASS zcl_dirigible_response DEFINITION PUBLIC. - PUBLIC SECTION. - CLASS-METHODS println - IMPORTING - message_in TYPE any. -ENDCLASS. - -CLASS zcl_dirigible_response IMPLEMENTATION. - METHOD println. - WRITE '@KERNEL const http = await import("sdk/http");'. - WRITE '@KERNEL const valueString = typeof message_in.value === "string" ? message_in.value : JSON.stringify(message_in.value, null, 2);'. - WRITE '@KERNEL http.response.println(valueString);'. - ENDMETHOD. - -ENDCLASS. \ No newline at end of file diff --git a/src/abap/zcl_dirigible_employee_dao.clas.abap b/src/abap/zcl_employee_dao.clas.abap similarity index 92% rename from src/abap/zcl_dirigible_employee_dao.clas.abap rename to src/abap/zcl_employee_dao.clas.abap index 51b43a7..c55d2ef 100644 --- a/src/abap/zcl_dirigible_employee_dao.clas.abap +++ b/src/abap/zcl_employee_dao.clas.abap @@ -1,4 +1,4 @@ -CLASS zcl_dirigible_employee_dao DEFINITION PUBLIC. +CLASS zcl_employee_dao DEFINITION PUBLIC. PUBLIC SECTION. TYPES: BEGIN OF ty_employee, @@ -17,7 +17,7 @@ CLASS zcl_dirigible_employee_dao DEFINITION PUBLIC. ENDCLASS. -CLASS zcl_dirigible_employee_dao IMPLEMENTATION. +CLASS zcl_employee_dao IMPLEMENTATION. METHOD delete_all_employees. DATA: lv_rc TYPE i. @@ -41,7 +41,7 @@ CLASS zcl_dirigible_employee_dao IMPLEMENTATION. FROM employees INTO TABLE lt_employees. - zcl_dirigible_response=>println( + zcl_codbex_response=>println( EXPORTING message_in = lt_employees ). ENDMETHOD. diff --git a/src/run.mjs b/src/run.mjs index f43d1d6..910cc58 100644 --- a/src/run.mjs +++ b/src/run.mjs @@ -2,32 +2,50 @@ import { DatabaseInitializer } from "sdk/abap/database"; import { initializeABAP } from '../dist/abap/init.mjs'; import { zcl_abap_app } from '../dist/abap/zcl_abap_app.clas.mjs'; +import { zcl_employee_dao } from '../dist/abap/zcl_employee_dao.clas.mjs'; -DatabaseInitializer.initDefaultDataSource(); -await initializeABAP(); - -// a workaround for https://github.com/abaplint/transpiler/issues/1441 -// manually register the table -abap.DDIC.EMPLOYEES = { - "objectType": "TABL", - "type": { - "value": { - "offset": { - "value": 0, - "qualifiedName": "I" +async function initialize() { + DatabaseInitializer.initDefaultDataSource(); + await initializeABAP(); + + // a workaround for https://github.com/abaplint/transpiler/issues/1441 + // manually register the table + abap.DDIC.EMPLOYEES = { + "objectType": "TABL", + "type": { + "value": { + "offset": { + "value": 0, + "qualifiedName": "I" + }, + "length": { + "value": 0, + "qualifiedName": "I" + } }, - "length": { - "value": 0, - "qualifiedName": "I" - } + "qualifiedName": "employees", + "ddicName": "employees", + "suffix": {}, + "asInclude": {} }, - "qualifiedName": "employees", - "ddicName": "employees", - "suffix": {}, - "asInclude": {} - }, - "keyFields": ["id"] -}; + "keyFields": ["id"] + }; +} + +async function runABAPCode() { + await zcl_abap_app.run(); +} + +await initialize(); + +await runABAPCode(); + +async function useDAO() { + console.log("Getting all employees..."); + const employees = zcl_employee_dao.select_all(); + console.log("All employees: " + JSON.stringify(employees)); -await zcl_abap_app.run(); + console.log("Done"); +} +await useDAO();