@abaplint/runtime
Version:
Transpiler - Runtime
196 lines • 8.06 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Statements = void 0;
const append_1 = require("./append");
const assert_1 = require("./assert");
const assign_1 = require("./assign");
const commit_1 = require("./commit");
const concatenate_1 = require("./concatenate");
const condense_1 = require("./condense");
const convert_1 = require("./convert");
const create_data_1 = require("./create_data");
const delete_internal_1 = require("./delete_internal");
const describe_1 = require("./describe");
const find_1 = require("./find");
const collect_1 = require("./collect");
const overlay_1 = require("./overlay");
const cast_1 = require("./cast");
const get_bit_1 = require("./get_bit");
const read_report_1 = require("./read_report");
const raise_event_1 = require("./raise_event");
const receive_1 = require("./receive");
const get_locale_1 = require("./get_locale");
const unpack_1 = require("./unpack");
const get_parameter_1 = require("./get_parameter");
const set_locale_1 = require("./set_locale");
const get_run_time_1 = require("./get_run_time");
const get_time_1 = require("./get_time");
const insert_database_1 = require("./insert_database");
const insert_internal_1 = require("./insert_internal");
const delete_database_1 = require("./delete_database");
const loop_1 = require("./loop");
const message_1 = require("./message");
const modify_database_1 = require("./modify_database");
const modify_internal_1 = require("./modify_internal");
const move_corresponding_1 = require("./move_corresponding");
const read_table_1 = require("./read_table");
const replace_1 = require("./replace");
const rollback_1 = require("./rollback");
const select_1 = require("./select");
const set_bit_1 = require("./set_bit");
const shift_1 = require("./shift");
const sort_1 = require("./sort");
const wait_1 = require("./wait");
const fetch_next_cursor_1 = require("./fetch_next_cursor");
const open_cursor_1 = require("./open_cursor");
const close_cursor_1 = require("./close_cursor");
const set_handler_1 = require("./set_handler");
const split_1 = require("./split");
const translate_1 = require("./translate");
const call_transaction_1 = require("./call_transaction");
const update_database_1 = require("./update_database");
const write_1 = require("./write");
const call_function_1 = require("./call_function");
const types_1 = require("util/types");
// this is a class, as statements like SELECT needs access to the database object instance
// and WRITE will access the Console
class Statements {
constructor(context) {
this.append = append_1.append;
this.assert = assert_1.assert;
this.assign = assign_1.assign;
this.cast = cast_1.cast;
this.collect = collect_1.collect;
this.commit = commit_1.commit;
this.concatenate = concatenate_1.concatenate;
this.condense = condense_1.condense;
this.convert = convert_1.convert;
this.createData = create_data_1.createData;
this.deleteInternal = delete_internal_1.deleteInternal;
this.describe = describe_1.describe;
this.find = find_1.find;
this.unpack = unpack_1.unpack;
this.getBit = get_bit_1.getBit;
this.readReport = read_report_1.readReport;
this.getLocale = get_locale_1.getLocale;
this.getParameter = get_parameter_1.getParameter;
this.getRunTime = get_run_time_1.getRunTime;
this.getTime = get_time_1.getTime;
this.insertInternal = insert_internal_1.insertInternal;
this.loop = loop_1.loop;
this.modifyInternal = modify_internal_1.modifyInternal;
this.moveCorresponding = move_corresponding_1.moveCorresponding;
this.overlay = overlay_1.overlay;
this.raiseEvent = raise_event_1.raiseEvent;
this.readTable = read_table_1.readTable;
this.replace = replace_1.replace;
this.rollback = rollback_1.rollback;
this.setBit = set_bit_1.setBit;
this.setHandler = set_handler_1.setHandler;
this.setLocale = set_locale_1.setLocale;
this.shift = shift_1.shift;
this.sort = sort_1.sort;
this.split = split_1.split;
this.translate = translate_1.translate;
this.wait = wait_1.wait;
this.receive = receive_1.receive;
this.callTransaction = call_transaction_1.callTransaction;
this.context = context;
this.traceTotals = {};
}
_trace(func, name, min, totals) {
const tt = this.traceTotals;
const exec = (...options) => {
const start = Date.now();
const result = func.bind(this)(...options);
const runtime = Date.now() - start;
if (totals === true) {
if (tt[name] === undefined) {
tt[name] = 0;
}
tt[name] += runtime;
}
if (runtime >= min) {
console.log(`STATEMENT: ${name}, ${runtime} ms`);
if (totals === true) {
console.log(JSON.stringify(tt));
}
}
return result;
};
return exec;
}
_traceAsync(func, name, min, totals) {
const tt = this.traceTotals;
const exec = async (...options) => {
const start = Date.now();
const result = await func.bind(this)(...options);
const runtime = Date.now() - start;
if (totals === true) {
if (tt[name] === undefined) {
tt[name] = 0;
}
tt[name] += runtime;
}
if (runtime >= min) {
console.log(`STATEMENT: ${name}, ${runtime} ms`);
if (totals === true) {
console.log(JSON.stringify(tt));
}
}
return result;
};
return exec;
}
_setTrace(min = 10, totals = false) {
const candidates = [...Object.keys(this), ...Object.getOwnPropertyNames(Statements.prototype)];
for (const c of candidates) {
if (c === "context" || c === "constructor" || c.startsWith("_") || c === "loop") {
continue;
}
const func = this[c];
if ((0, types_1.isAsyncFunction)(func)) {
this[c] = this._traceAsync(func, c, min, totals);
}
else {
this[c] = this._trace(func, c, min, totals);
}
}
}
async openCursor(target, select, options) {
const num = await (0, open_cursor_1.openCursor)(this.context, select, options);
target.set(num);
}
async fetchNextCursor(cursor, target, packageSize) {
await (0, fetch_next_cursor_1.fetchNextCursor)(this.context, cursor.get(), target, packageSize?.get() || 0);
}
async closeCursor(cursor) {
await (0, close_cursor_1.closeCursor)(this.context, cursor.get());
}
async deleteDatabase(table, options) {
await (0, delete_database_1.deleteDatabase)(table, options, this.context);
}
async insertDatabase(table, options) {
return (0, insert_database_1.insertDatabase)(table, options, this.context);
}
async modifyDatabase(table, options) {
return (0, modify_database_1.modifyDatabase)(table, options, this.context);
}
async select(target, select, runtimeOptions) {
return (0, select_1.select)(target, select, runtimeOptions || {}, this.context);
}
async updateDatabase(table, options) {
return (0, update_database_1.updateDatabase)(table, options, this.context);
}
async callFunction(options) {
return new call_function_1.CallFunction(this.context).callFunction(options);
}
async message(options) {
return new message_1.MessageStatement(this.context).message(options);
}
write(source, options) {
return new write_1.WriteStatement(this.context).write(source, options);
}
}
exports.Statements = Statements;
//# sourceMappingURL=index.js.map