@abaplint/runtime 1.8.38 → 2.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.
@@ -6,6 +6,7 @@ exports.sy = new types_1.Structure({
6
6
  abcde: new types_1.Character({ length: 26 }).set("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
7
7
  datlo: new types_1.Date(),
8
8
  datum: new types_1.Date(),
9
+ dbcnt: new types_1.Integer(),
9
10
  fdpos: new types_1.Integer(),
10
11
  index: new types_1.Integer(),
11
12
  langu: new types_1.Character({ length: 1 }).set("E"),
@@ -9,6 +9,7 @@ function cs(left, right) {
9
9
  else {
10
10
  l = left.get().toString();
11
11
  }
12
+ l = l.toUpperCase();
12
13
  let r = "";
13
14
  if (typeof right === "string") {
14
15
  r = right.toString();
@@ -16,7 +17,8 @@ function cs(left, right) {
16
17
  else {
17
18
  r = right.get().toString();
18
19
  }
19
- const index = r.indexOf(l);
20
+ r = r.toUpperCase();
21
+ const index = l.indexOf(r);
20
22
  if (index < 0) {
21
23
  // @ts-ignore
22
24
  abap.builtin.sy.get().fdpos.set(l.length);
@@ -0,0 +1,13 @@
1
+ import { Console } from "./console";
2
+ import { DatabaseClient } from "./db/db";
3
+ import * as RFC from "./rfc";
4
+ export declare class Context {
5
+ console: Console;
6
+ databaseConnections: {
7
+ [name: string]: DatabaseClient;
8
+ };
9
+ RFCDestinations: {
10
+ [name: string]: RFC.RFCClient;
11
+ };
12
+ defaultDB(): DatabaseClient;
13
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Context = void 0;
4
+ class Context {
5
+ constructor() {
6
+ // DEFAULT and secondary database connections
7
+ this.databaseConnections = {};
8
+ this.RFCDestinations = {};
9
+ }
10
+ defaultDB() {
11
+ if (this.databaseConnections["DEFAULT"] === undefined) {
12
+ throw new Error("Runtime, database not initialized");
13
+ }
14
+ return this.databaseConnections["DEFAULT"];
15
+ }
16
+ }
17
+ exports.Context = Context;
18
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,46 @@
1
+ export interface DeleteDatabaseOptions {
2
+ table: string;
3
+ where: string;
4
+ }
5
+ export interface UpdateDatabaseOptions {
6
+ table: string;
7
+ where: string;
8
+ set: string[];
9
+ }
10
+ export interface InsertDatabaseOptions {
11
+ table: string;
12
+ columns: string[];
13
+ values: string[];
14
+ }
15
+ export interface SelectDatabaseOptions {
16
+ select: string;
17
+ }
18
+ export declare type DatabaseValue = number | string | Uint8Array | null;
19
+ export declare type DatabaseRow = {
20
+ [name: string]: DatabaseValue;
21
+ };
22
+ export declare type DatabaseRows = DatabaseRow[];
23
+ export interface SelectDatabaseResult {
24
+ rows: DatabaseRows;
25
+ }
26
+ export interface DatabaseClient {
27
+ /*** the type/name/identifier of the database */
28
+ name: string;
29
+ connect(): Promise<void>;
30
+ disconnect(): Promise<void>;
31
+ /*** execute any native SQL command */
32
+ execute(sql: string): Promise<void>;
33
+ delete(options: DeleteDatabaseOptions): Promise<{
34
+ subrc: number;
35
+ dbcnt: number;
36
+ }>;
37
+ update(options: UpdateDatabaseOptions): Promise<{
38
+ subrc: number;
39
+ dbcnt: number;
40
+ }>;
41
+ insert(options: InsertDatabaseOptions): Promise<{
42
+ subrc: number;
43
+ dbcnt: number;
44
+ }>;
45
+ select(options: SelectDatabaseOptions): Promise<SelectDatabaseResult>;
46
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=db.js.map
@@ -1,14 +1,16 @@
1
- import * as types from "./types";
1
+ import { Console } from "./console";
2
+ import { Context } from "./context";
3
+ import { OffsetLength } from "./offset_length";
4
+ import { Statements } from "./statements";
5
+ import { templateFormatting } from "./template_formatting";
6
+ import { UnitTestResult } from "./unit_test";
2
7
  import * as builtin from "./builtin";
3
8
  import * as compare from "./compare";
9
+ import * as DB from "./db/db";
4
10
  import * as operators from "./operators";
5
- import { Statements } from "./statements";
6
11
  import * as RFC from "./rfc";
7
- import { Console } from "./console";
8
- import { UnitTestResult } from "./unit_test";
9
- import { OffsetLength } from "./offset_length";
10
- import { templateFormatting } from "./template_formatting";
11
- export { UnitTestResult, RFC, types };
12
+ import * as types from "./types";
13
+ export { UnitTestResult, RFC, types, DB };
12
14
  export declare class ABAP {
13
15
  FunctionModules: {
14
16
  [name: string]: any;
@@ -22,18 +24,14 @@ export declare class ABAP {
22
24
  DDIC: {
23
25
  [name: string]: any;
24
26
  };
25
- RFCDestinations: {
26
- [name: string]: RFC.RFCClient;
27
- };
28
27
  statements: Statements;
29
28
  types: typeof types;
30
29
  builtin: typeof builtin;
31
30
  operators: typeof operators;
32
31
  compare: typeof compare;
33
- console: Console;
34
- db: undefined | any;
32
+ readonly console: Console;
35
33
  OffsetLength: typeof OffsetLength;
36
34
  templateFormatting: typeof templateFormatting;
35
+ readonly context: Context;
37
36
  constructor();
38
- initDB(sql?: string): Promise<void>;
39
37
  }
@@ -1,20 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ABAP = exports.types = exports.RFC = exports.UnitTestResult = void 0;
4
- const types = require("./types");
5
- exports.types = types;
3
+ exports.ABAP = exports.DB = exports.types = exports.RFC = exports.UnitTestResult = void 0;
4
+ const console_1 = require("./console");
5
+ const context_1 = require("./context");
6
+ const offset_length_1 = require("./offset_length");
7
+ const statements_1 = require("./statements");
8
+ const template_formatting_1 = require("./template_formatting");
9
+ const unit_test_1 = require("./unit_test");
10
+ Object.defineProperty(exports, "UnitTestResult", { enumerable: true, get: function () { return unit_test_1.UnitTestResult; } });
6
11
  const builtin = require("./builtin");
7
12
  const compare = require("./compare");
13
+ const DB = require("./db/db");
14
+ exports.DB = DB;
8
15
  const operators = require("./operators");
9
- const statements_1 = require("./statements");
10
16
  const RFC = require("./rfc");
11
17
  exports.RFC = RFC;
12
- const sql_js_1 = require("sql.js");
13
- const console_1 = require("./console");
14
- const unit_test_1 = require("./unit_test");
15
- Object.defineProperty(exports, "UnitTestResult", { enumerable: true, get: function () { return unit_test_1.UnitTestResult; } });
16
- const offset_length_1 = require("./offset_length");
17
- const template_formatting_1 = require("./template_formatting");
18
+ const types = require("./types");
19
+ exports.types = types;
18
20
  class ABAP {
19
21
  constructor() {
20
22
  // global objects
@@ -22,29 +24,22 @@ class ABAP {
22
24
  this.Classes = {};
23
25
  this.Interfaces = {};
24
26
  this.DDIC = {};
25
- // RFC Destinations
26
- this.RFCDestinations = {};
27
27
  this.types = types;
28
28
  this.builtin = builtin;
29
29
  this.operators = operators;
30
30
  this.compare = compare;
31
31
  this.OffsetLength = offset_length_1.OffsetLength;
32
32
  this.templateFormatting = template_formatting_1.templateFormatting;
33
+ this.context = new context_1.Context();
33
34
  this.console = new console_1.Console();
34
- this.statements = new statements_1.Statements(this.console);
35
+ this.context.console = this.console;
36
+ this.statements = new statements_1.Statements(this.context);
35
37
  // todo, this should not be a singleton, it should be part of this instance
38
+ // todo, move to context
36
39
  builtin.sy.get().subrc.set(0);
37
40
  builtin.sy.get().tabix.set(0);
38
41
  builtin.sy.get().index.set(0);
39
42
  }
40
- async initDB(sql) {
41
- const SQL = await (0, sql_js_1.default)();
42
- this.db = new SQL.Database();
43
- if (sql && sql !== "") {
44
- this.db.run(sql);
45
- }
46
- this.statements.setDb(this.db);
47
- }
48
43
  }
49
44
  exports.ABAP = ABAP;
50
45
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,4 @@
1
+ import { Context } from "../context";
1
2
  export interface ICallFunctionOptions {
2
3
  name: string;
3
4
  destination: string;
@@ -7,4 +8,8 @@ export interface ICallFunctionOptions {
7
8
  changing?: any;
8
9
  exceptions?: any;
9
10
  }
10
- export declare function callFunction(options: ICallFunctionOptions): Promise<void>;
11
+ export declare class CallFunction {
12
+ private readonly context;
13
+ constructor(context: Context);
14
+ callFunction(options: ICallFunctionOptions): Promise<void>;
15
+ }
@@ -1,20 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.callFunction = void 0;
4
- // note: this is only called if DESTNIATION is supplied
5
- async function callFunction(options) {
6
- // @ts-ignore
7
- const dest = abap.RFCDestinations[options.destination];
8
- if (dest === undefined) {
9
- throw new Error(`RFC destination ${options.destination} does not exist`);
3
+ exports.CallFunction = void 0;
4
+ class CallFunction {
5
+ constructor(context) {
6
+ this.context = context;
7
+ }
8
+ // note: this is only called if DESTINIATION is supplied
9
+ async callFunction(options) {
10
+ const dest = this.context.RFCDestinations[options.destination];
11
+ if (dest === undefined) {
12
+ throw new Error(`RFC destination ${options.destination} does not exist`);
13
+ }
14
+ await dest.call(options.name, {
15
+ exporting: options.exporting,
16
+ importing: options.importing,
17
+ tables: options.tables,
18
+ changing: options.changing,
19
+ exceptions: options.exceptions,
20
+ });
10
21
  }
11
- await dest.call(options.name, {
12
- exporting: options.exporting,
13
- importing: options.importing,
14
- tables: options.tables,
15
- changing: options.changing,
16
- exceptions: options.exceptions,
17
- });
18
22
  }
19
- exports.callFunction = callFunction;
23
+ exports.CallFunction = CallFunction;
20
24
  //# sourceMappingURL=call_function.js.map
@@ -1,7 +1,12 @@
1
+ import { Context } from "../context";
1
2
  import { FieldSymbol, Structure, Table } from "../types";
2
3
  import { ICharacter } from "../types/_character";
3
- export interface IInsertDatabaseOptions {
4
+ export interface IDeleteDatabaseOptions {
4
5
  from?: Structure | FieldSymbol;
5
6
  table?: Table | FieldSymbol;
6
7
  }
7
- export declare function deleteDatabase(table: string | ICharacter, options: IInsertDatabaseOptions): void;
8
+ export declare class DeleteDatabase {
9
+ private readonly context;
10
+ constructor(context: Context);
11
+ deleteDatabase(table: string | ICharacter, options: IDeleteDatabaseOptions): Promise<void>;
12
+ }
@@ -1,44 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deleteDatabase = void 0;
3
+ exports.DeleteDatabase = void 0;
4
4
  const types_1 = require("../types");
5
- function deleteDatabase(table, options) {
6
- if (this.db === undefined) {
7
- throw new Error("Runtime, database not initialized");
5
+ class DeleteDatabase {
6
+ constructor(context) {
7
+ this.context = context;
8
8
  }
9
- if (options.table instanceof types_1.FieldSymbol) {
10
- options.table = options.table.getPointer();
11
- }
12
- if (options.from instanceof types_1.FieldSymbol) {
13
- options.from = options.from.getPointer();
14
- }
15
- if (options.table) {
16
- for (const row of options.table.array()) {
17
- deleteDatabase.bind(this)(table, { from: row });
9
+ async deleteDatabase(table, options) {
10
+ if (options.table instanceof types_1.FieldSymbol) {
11
+ options.table = options.table.getPointer();
18
12
  }
19
- }
20
- else if (options.from) {
21
- const where = [];
22
- const structure = options.from.get();
23
- for (const k of Object.keys(structure)) {
24
- // todo, integers should not be surrounded by '"'?
25
- const str = k + ' = "' + structure[k].get() + '"';
26
- where.push(str);
13
+ if (options.from instanceof types_1.FieldSymbol) {
14
+ options.from = options.from.getPointer();
27
15
  }
28
- const sql = `DELETE FROM ${table} WHERE ${where.join(" AND ")}`;
29
- let subrc = 0;
30
- try {
31
- this.db.exec(sql);
16
+ if (typeof table !== "string") {
17
+ table = table.get();
32
18
  }
33
- catch (error) {
34
- subrc = 4;
19
+ if (options.table) {
20
+ for (const row of options.table.array()) {
21
+ this.deleteDatabase(table, { from: row });
22
+ }
23
+ }
24
+ else if (options.from) {
25
+ let where = [];
26
+ const structure = options.from.get();
27
+ for (const k of Object.keys(structure)) {
28
+ // todo, integers should not be surrounded by '"'?
29
+ const str = k + ' = "' + structure[k].get() + '"';
30
+ where.push(str);
31
+ }
32
+ where = where.join(" AND ");
33
+ const { subrc, dbcnt } = await this.context.defaultDB().delete({ table, where });
34
+ // @ts-ignore
35
+ abap.builtin.sy.get().subrc.set(subrc);
36
+ // @ts-ignore
37
+ abap.builtin.sy.get().dbcnt.set(dbcnt);
38
+ }
39
+ else {
40
+ throw "deleteDatabase todo";
35
41
  }
36
- // @ts-ignore
37
- abap.builtin.sy.get().subrc.set(subrc);
38
- }
39
- else {
40
- throw "deleteDatabase todo";
41
42
  }
42
43
  }
43
- exports.deleteDatabase = deleteDatabase;
44
+ exports.DeleteDatabase = DeleteDatabase;
44
45
  //# sourceMappingURL=delete_database.js.map
@@ -1,12 +1,10 @@
1
1
  import { append } from "./append";
2
2
  import { assert } from "./assert";
3
3
  import { assign } from "./assign";
4
- import { callFunction } from "./call_function";
5
4
  import { clear } from "./clear";
6
5
  import { commit } from "./commit";
7
6
  import { concatenate } from "./concatenate";
8
7
  import { condense } from "./condense";
9
- import { Console } from "../console";
10
8
  import { convert } from "./convert";
11
9
  import { createData } from "./create_data";
12
10
  import { deleteInternal } from "./delete_internal";
@@ -15,25 +13,29 @@ import { find } from "./find";
15
13
  import { getBit } from "./get_bit";
16
14
  import { getRunTime } from "./get_run_time";
17
15
  import { getTime } from "./get_time";
18
- import { insertDatabase } from "./insert_database";
16
+ import { IInsertDatabaseOptions } from "./insert_database";
19
17
  import { insertInternal } from "./insert_internal";
20
- import { deleteDatabase } from "./delete_database";
18
+ import { IDeleteDatabaseOptions } from "./delete_database";
21
19
  import { loop } from "./loop";
22
- import { message } from "./message";
23
- import { modifyDatabase } from "./modify_database";
20
+ import { IMessageOptions } from "./message";
21
+ import { IModifyDatabaseOptions } from "./modify_database";
24
22
  import { modifyInternal } from "./modify_internal";
25
23
  import { moveCorresponding } from "./move_corresponding";
26
24
  import { readTable } from "./read_table";
27
25
  import { replace } from "./replace";
28
26
  import { rollback } from "./rollback";
29
- import { select } from "./select";
30
27
  import { setBit } from "./set_bit";
31
28
  import { shift } from "./shift";
32
29
  import { sort } from "./sort";
33
30
  import { split } from "./split";
34
31
  import { translate } from "./translate";
35
- import { updateDatabase } from "./update_database";
36
- import { write } from "./write";
32
+ import { IUpdateDatabaseOptions } from "./update_database";
33
+ import { IWriteOptions } from "./write";
34
+ import { Context } from "../context";
35
+ import { ICharacter } from "../types/_character";
36
+ import { FieldSymbol, Structure, Table } from "../types";
37
+ import { INumeric } from "../types/_numeric";
38
+ import { ICallFunctionOptions } from "./call_function";
37
39
  export declare class Statements {
38
40
  append: typeof append;
39
41
  assert: typeof assert;
@@ -48,30 +50,28 @@ export declare class Statements {
48
50
  describe: typeof describe;
49
51
  find: typeof find;
50
52
  getBit: typeof getBit;
51
- callFunction: typeof callFunction;
52
53
  getRunTime: typeof getRunTime;
53
- deleteDatabase: typeof deleteDatabase;
54
54
  getTime: typeof getTime;
55
- insertDatabase: typeof insertDatabase;
56
55
  insertInternal: typeof insertInternal;
57
56
  loop: typeof loop;
58
- message: typeof message;
59
57
  modifyInternal: typeof modifyInternal;
60
58
  moveCorresponding: typeof moveCorresponding;
61
59
  readTable: typeof readTable;
62
- updateDatabase: typeof updateDatabase;
63
- modifyDatabase: typeof modifyDatabase;
64
60
  replace: typeof replace;
65
61
  rollback: typeof rollback;
66
- select: typeof select;
67
62
  setBit: typeof setBit;
68
63
  shift: typeof shift;
69
64
  sort: typeof sort;
70
65
  split: typeof split;
71
66
  translate: typeof translate;
72
- write: typeof write;
73
- private readonly console;
74
- private db;
75
- constructor(console: Console);
76
- setDb(db: any): void;
67
+ private readonly context;
68
+ constructor(context: Context);
69
+ deleteDatabase(table: string | ICharacter, options: IDeleteDatabaseOptions): Promise<void>;
70
+ insertDatabase(table: string | ICharacter, options: IInsertDatabaseOptions): Promise<number>;
71
+ message(options: IMessageOptions): Promise<void>;
72
+ modifyDatabase(table: string | ICharacter, options: IModifyDatabaseOptions): Promise<void>;
73
+ select(target: Structure | Table | FieldSymbol, select: string): Promise<void>;
74
+ updateDatabase(table: string | ICharacter, options: IUpdateDatabaseOptions): Promise<number>;
75
+ callFunction(options: ICallFunctionOptions): Promise<void>;
76
+ write(source: INumeric | ICharacter | FieldSymbol | string | number, options?: IWriteOptions): void;
77
77
  }
@@ -4,7 +4,6 @@ exports.Statements = void 0;
4
4
  const append_1 = require("./append");
5
5
  const assert_1 = require("./assert");
6
6
  const assign_1 = require("./assign");
7
- const call_function_1 = require("./call_function");
8
7
  const clear_1 = require("./clear");
9
8
  const commit_1 = require("./commit");
10
9
  const concatenate_1 = require("./concatenate");
@@ -36,10 +35,11 @@ const split_1 = require("./split");
36
35
  const translate_1 = require("./translate");
37
36
  const update_database_1 = require("./update_database");
38
37
  const write_1 = require("./write");
38
+ const call_function_1 = require("./call_function");
39
39
  // this is a class, as statements like SELECT needs access to the database object instance
40
40
  // and WRITE will access the Console
41
41
  class Statements {
42
- constructor(console) {
42
+ constructor(context) {
43
43
  this.append = append_1.append;
44
44
  this.assert = assert_1.assert;
45
45
  this.assign = assign_1.assign;
@@ -53,32 +53,45 @@ class Statements {
53
53
  this.describe = describe_1.describe;
54
54
  this.find = find_1.find;
55
55
  this.getBit = get_bit_1.getBit;
56
- this.callFunction = call_function_1.callFunction;
57
56
  this.getRunTime = get_run_time_1.getRunTime;
58
- this.deleteDatabase = delete_database_1.deleteDatabase;
59
57
  this.getTime = get_time_1.getTime;
60
- this.insertDatabase = insert_database_1.insertDatabase;
61
58
  this.insertInternal = insert_internal_1.insertInternal;
62
59
  this.loop = loop_1.loop;
63
- this.message = message_1.message;
64
60
  this.modifyInternal = modify_internal_1.modifyInternal;
65
61
  this.moveCorresponding = move_corresponding_1.moveCorresponding;
66
62
  this.readTable = read_table_1.readTable;
67
- this.updateDatabase = update_database_1.updateDatabase;
68
- this.modifyDatabase = modify_database_1.modifyDatabase;
69
63
  this.replace = replace_1.replace;
70
64
  this.rollback = rollback_1.rollback;
71
- this.select = select_1.select;
72
65
  this.setBit = set_bit_1.setBit;
73
66
  this.shift = shift_1.shift;
74
67
  this.sort = sort_1.sort;
75
68
  this.split = split_1.split;
76
69
  this.translate = translate_1.translate;
77
- this.write = write_1.write;
78
- this.console = console;
70
+ this.context = context;
71
+ }
72
+ async deleteDatabase(table, options) {
73
+ return new delete_database_1.DeleteDatabase(this.context).deleteDatabase(table, options);
74
+ }
75
+ async insertDatabase(table, options) {
76
+ return new insert_database_1.InsertDatabase(this.context).insertDatabase(table, options);
77
+ }
78
+ async message(options) {
79
+ return new message_1.MessageStatement(this.context).message(options);
80
+ }
81
+ async modifyDatabase(table, options) {
82
+ return new modify_database_1.ModifyDatabase(this.context).modifyDatabase(table, options);
83
+ }
84
+ async select(target, select) {
85
+ return new select_1.SelectDatabase(this.context).select(target, select);
86
+ }
87
+ async updateDatabase(table, options) {
88
+ return new update_database_1.UpdateDatabase(this.context).updateDatabase(table, options);
89
+ }
90
+ async callFunction(options) {
91
+ return new call_function_1.CallFunction(this.context).callFunction(options);
79
92
  }
80
- setDb(db) {
81
- this.db = db;
93
+ write(source, options) {
94
+ return new write_1.WriteStatement(this.context).write(source, options);
82
95
  }
83
96
  }
84
97
  exports.Statements = Statements;
@@ -1,6 +1,11 @@
1
+ import { Context } from "../context";
1
2
  import { Structure } from "../types";
2
3
  import { ICharacter } from "../types/_character";
3
4
  export interface IInsertDatabaseOptions {
4
5
  values: Structure;
5
6
  }
6
- export declare function insertDatabase(table: string | ICharacter, options: IInsertDatabaseOptions): number;
7
+ export declare class InsertDatabase {
8
+ private readonly context;
9
+ constructor(context: Context);
10
+ insertDatabase(table: string | ICharacter, options: IInsertDatabaseOptions): Promise<number>;
11
+ }
@@ -1,34 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.insertDatabase = void 0;
4
- function insertDatabase(table, options) {
5
- if (this.db === undefined) {
6
- throw new Error("Runtime, database not initialized");
3
+ exports.InsertDatabase = void 0;
4
+ class InsertDatabase {
5
+ constructor(context) {
6
+ this.context = context;
7
7
  }
8
- const columns = [];
9
- const values = [];
10
- const structure = options.values.get();
11
- for (const k of Object.keys(structure)) {
12
- columns.push(k);
13
- // todo, integers should not be surrounded by '"'?
14
- values.push('"' + structure[k].get() + '"');
8
+ async insertDatabase(table, options) {
9
+ const columns = [];
10
+ const values = [];
11
+ const structure = options.values.get();
12
+ for (const k of Object.keys(structure)) {
13
+ columns.push(k);
14
+ // todo, integers should not be surrounded by '"'?
15
+ values.push('"' + structure[k].get() + '"');
16
+ }
17
+ if (typeof table !== "string") {
18
+ table = table.get();
19
+ }
20
+ const { subrc, dbcnt } = await this.context.defaultDB().insert({ table, columns, values });
21
+ // @ts-ignore
22
+ abap.builtin.sy.get().subrc.set(subrc);
23
+ // @ts-ignore
24
+ abap.builtin.sy.get().dbcnt.set(dbcnt);
25
+ return subrc;
15
26
  }
16
- if (typeof table !== "string") {
17
- table = table.get();
18
- }
19
- const sql = `INSERT INTO ${table} (${columns.join(",")}) VALUES (${values.join(",")})`;
20
- // console.dir(sql);
21
- let subrc = 0;
22
- try {
23
- this.db.exec(sql);
24
- }
25
- catch (error) {
26
- // eg "UNIQUE constraint failed" errors
27
- subrc = 4;
28
- }
29
- // @ts-ignore
30
- abap.builtin.sy.get().subrc.set(subrc);
31
- return subrc;
32
27
  }
33
- exports.insertDatabase = insertDatabase;
28
+ exports.InsertDatabase = InsertDatabase;
34
29
  //# sourceMappingURL=insert_database.js.map
@@ -1,3 +1,4 @@
1
+ import { Context } from "../context";
1
2
  import { ICharacter } from "../types/_character";
2
3
  export interface IMessageOptions {
3
4
  id?: ICharacter | string;
@@ -6,4 +7,8 @@ export interface IMessageOptions {
6
7
  with?: (ICharacter | string)[];
7
8
  into?: ICharacter;
8
9
  }
9
- export declare function message(options: IMessageOptions): void;
10
+ export declare class MessageStatement {
11
+ private readonly context;
12
+ constructor(context: Context);
13
+ message(options: IMessageOptions): Promise<void>;
14
+ }
@@ -1,27 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.message = void 0;
4
- function message(options) {
5
- let arbgb = options.id;
6
- if (arbgb !== undefined && typeof arbgb !== "string") {
7
- arbgb = arbgb.get();
8
- }
9
- arbgb = arbgb === null || arbgb === void 0 ? void 0 : arbgb.toUpperCase();
10
- // @ts-ignore
11
- abap.builtin.sy.get().msgid.set(arbgb);
12
- let msgnr = options.number;
13
- if (msgnr !== undefined && typeof msgnr !== "string") {
14
- msgnr = msgnr.get();
15
- }
16
- // @ts-ignore
17
- abap.builtin.sy.get().msgno.set(msgnr);
18
- const text = findText.bind(this)(arbgb, msgnr);
19
- const replaced = replace(text, options.with);
20
- if (options.into) {
21
- options.into.set(replaced);
22
- }
23
- }
24
- exports.message = message;
3
+ exports.MessageStatement = void 0;
25
4
  function replace(text, w) {
26
5
  for (let i = 0; i < 6; i++) {
27
6
  const search = "&" + (i + 1);
@@ -44,19 +23,15 @@ function replace(text, w) {
44
23
  }
45
24
  return text.trim();
46
25
  }
47
- function findText(arbgb, msgnr) {
26
+ async function findText(context, arbgb, msgnr) {
48
27
  let text = undefined;
49
- const db = this.db;
50
- if (db && arbgb && msgnr) {
28
+ if (arbgb && msgnr) {
51
29
  try {
52
- const stmt = db.prepare("SELECT * FROM t100 WHERE sprsl=:sprsl AND arbgb=:arbgb AND msgnr=:msgnr LIMIT 1");
53
- const result = stmt.getAsObject({
54
- ":sprsl": "E",
55
- ":arbgb": arbgb,
56
- ":msgnr": msgnr,
57
- });
58
- if (result.text) {
59
- text = result.text;
30
+ // todo, sql injection?
31
+ const select = `SELECT * FROM t100 WHERE sprsl='E' AND arbgb='${arbgb}' AND msgnr='${msgnr}' LIMIT 1`;
32
+ const { rows: result } = await context.defaultDB().select({ select });
33
+ if (result[0]) {
34
+ text = result[0]["text"];
60
35
  }
61
36
  }
62
37
  catch (_a) {
@@ -69,4 +44,30 @@ function findText(arbgb, msgnr) {
69
44
  }
70
45
  return text;
71
46
  }
47
+ class MessageStatement {
48
+ constructor(context) {
49
+ this.context = context;
50
+ }
51
+ async message(options) {
52
+ let arbgb = options.id;
53
+ if (arbgb !== undefined && typeof arbgb !== "string") {
54
+ arbgb = arbgb.get();
55
+ }
56
+ arbgb = arbgb === null || arbgb === void 0 ? void 0 : arbgb.toUpperCase();
57
+ // @ts-ignore
58
+ abap.builtin.sy.get().msgid.set(arbgb);
59
+ let msgnr = options.number;
60
+ if (msgnr !== undefined && typeof msgnr !== "string") {
61
+ msgnr = msgnr.get();
62
+ }
63
+ // @ts-ignore
64
+ abap.builtin.sy.get().msgno.set(msgnr);
65
+ const text = await findText(this.context, arbgb, msgnr);
66
+ const replaced = replace(text, options.with);
67
+ if (options.into) {
68
+ options.into.set(replaced);
69
+ }
70
+ }
71
+ }
72
+ exports.MessageStatement = MessageStatement;
72
73
  //# sourceMappingURL=message.js.map
@@ -1,7 +1,12 @@
1
+ import { Context } from "../context";
1
2
  import { FieldSymbol, Structure, Table } from "../types";
2
3
  import { ICharacter } from "../types/_character";
3
- export interface IInsertDatabaseOptions {
4
+ export interface IModifyDatabaseOptions {
4
5
  from?: Structure | FieldSymbol;
5
6
  table?: Table | FieldSymbol;
6
7
  }
7
- export declare function modifyDatabase(table: string | ICharacter, options: IInsertDatabaseOptions): void;
8
+ export declare class ModifyDatabase {
9
+ private readonly context;
10
+ constructor(context: Context);
11
+ modifyDatabase(table: string | ICharacter, options: IModifyDatabaseOptions): Promise<void>;
12
+ }
@@ -1,36 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.modifyDatabase = void 0;
3
+ exports.ModifyDatabase = void 0;
4
4
  const types_1 = require("../types");
5
5
  const insert_database_1 = require("./insert_database");
6
6
  const update_database_1 = require("./update_database");
7
- function modifyDatabase(table, options) {
8
- if (this.db === undefined) {
9
- throw new Error("Runtime, database not initialized");
7
+ class ModifyDatabase {
8
+ constructor(context) {
9
+ this.context = context;
10
10
  }
11
- if (options.table instanceof types_1.FieldSymbol) {
12
- options.table = options.table.getPointer();
13
- }
14
- if (options.from instanceof types_1.FieldSymbol) {
15
- options.from = options.from.getPointer();
16
- }
17
- if (options.table) {
18
- for (const row of options.table.array()) {
19
- const subrc = insert_database_1.insertDatabase.bind(this)(table, { values: row });
11
+ async modifyDatabase(table, options) {
12
+ if (options.table instanceof types_1.FieldSymbol) {
13
+ options.table = options.table.getPointer();
14
+ }
15
+ if (options.from instanceof types_1.FieldSymbol) {
16
+ options.from = options.from.getPointer();
17
+ }
18
+ const insert = new insert_database_1.InsertDatabase(this.context);
19
+ const update = new update_database_1.UpdateDatabase(this.context);
20
+ if (options.table) {
21
+ for (const row of options.table.array()) {
22
+ const subrc = await insert.insertDatabase(table, { values: row });
23
+ if (subrc !== 0) {
24
+ await update.updateDatabase(table, { from: row });
25
+ }
26
+ }
27
+ }
28
+ else if (options.from) {
29
+ const subrc = await insert.insertDatabase(table, { values: options.from });
20
30
  if (subrc !== 0) {
21
- update_database_1.updateDatabase.bind(this)(table, { from: row });
31
+ await update.updateDatabase(table, { from: options.from });
22
32
  }
23
33
  }
24
- }
25
- else if (options.from) {
26
- const subrc = insert_database_1.insertDatabase.bind(this)(table, { values: options.from });
27
- if (subrc !== 0) {
28
- update_database_1.updateDatabase.bind(this)(table, { from: options.from });
34
+ else {
35
+ throw "modifyDatabase todo";
29
36
  }
30
37
  }
31
- else {
32
- throw "modifyDatabase todo";
33
- }
34
38
  }
35
- exports.modifyDatabase = modifyDatabase;
39
+ exports.ModifyDatabase = ModifyDatabase;
36
40
  //# sourceMappingURL=modify_database.js.map
@@ -1,2 +1,7 @@
1
+ import { Context } from "../context";
1
2
  import { FieldSymbol, Structure, Table } from "../types";
2
- export declare function select(target: Structure | Table | FieldSymbol, select: string): void;
3
+ export declare class SelectDatabase {
4
+ private readonly context;
5
+ constructor(context: Context);
6
+ select(target: Structure | Table | FieldSymbol, select: string): Promise<void>;
7
+ }
@@ -1,70 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.select = void 0;
3
+ exports.SelectDatabase = void 0;
4
4
  const clone_1 = require("../clone");
5
5
  const types_1 = require("../types");
6
- function select(target, select) {
7
- var _a, _b, _c;
8
- if (this.db === undefined) {
9
- throw new Error("Runtime, database not initialized");
6
+ class SelectDatabase {
7
+ constructor(context) {
8
+ this.context = context;
10
9
  }
11
- let res = undefined;
12
- try {
13
- res = this.db.exec(select);
14
- }
15
- catch (error) {
16
- // @ts-ignore
17
- if (abap.Classes["CX_SY_DYNAMIC_OSQL_SEMANTICS"] !== undefined) {
10
+ async select(target, select) {
11
+ var _a;
12
+ const { rows: rows } = await this.context.defaultDB().select({ select });
13
+ if (target instanceof types_1.FieldSymbol) {
14
+ if (target.isAssigned() === false) {
15
+ throw "select, fs not assigned";
16
+ }
18
17
  // @ts-ignore
19
- throw new abap.Classes["CX_SY_DYNAMIC_OSQL_SEMANTICS"]();
18
+ target = target.getPointer();
20
19
  }
21
- throw error;
22
- }
23
- if (target instanceof types_1.FieldSymbol) {
24
- // @ts-ignore
25
- target = target.getPointer();
26
- }
27
- target.clear();
28
- if (target instanceof types_1.Structure) {
29
- if (((_a = res[0]) === null || _a === void 0 ? void 0 : _a.values[0]) === undefined) {
20
+ target.clear();
21
+ if (rows.length === 0) {
30
22
  // @ts-ignore
31
23
  abap.builtin.sy.get().subrc.set(4);
24
+ return;
32
25
  }
33
- else {
34
- const columns = res[0].columns;
35
- const values = res[0].values[0];
26
+ if (target instanceof types_1.Structure) {
36
27
  const result = {};
37
- for (const c of columns) {
38
- result[c] = (0, clone_1.clone)(target.get()[c]).set(values.shift());
28
+ for (const column in rows[0]) {
29
+ result[column] = (0, clone_1.clone)(target.get()[column]).set(rows[0][column]);
39
30
  }
40
31
  target.set(new types_1.Structure(result));
41
- // @ts-ignore
42
- abap.builtin.sy.get().subrc.set(0);
43
- }
44
- }
45
- else if (target instanceof types_1.Table) {
46
- if (((_b = res[0]) === null || _b === void 0 ? void 0 : _b.values[0]) === undefined) {
47
- // @ts-ignore
48
- abap.builtin.sy.get().subrc.set(4);
49
32
  }
50
- else {
51
- for (const selectRow of res[0].values) {
33
+ else if (target instanceof types_1.Table) {
34
+ for (const row of rows) {
52
35
  const targetRow = (0, clone_1.clone)(target.getRowType());
53
- const values = selectRow;
54
- for (const c of res[0].columns) {
36
+ for (const columnName in row) {
37
+ // todo, non structured table = table with simple rows
55
38
  // @ts-ignore
56
- (_c = targetRow.get()[c]) === null || _c === void 0 ? void 0 : _c.set(values.shift());
39
+ (_a = targetRow.get()[columnName]) === null || _a === void 0 ? void 0 : _a.set(row[columnName]);
57
40
  }
58
41
  // @ts-ignore
59
42
  abap.statements.insertInternal({ table: target, data: targetRow });
60
43
  }
61
- // @ts-ignore
62
- abap.builtin.sy.get().subrc.set(0);
63
44
  }
64
- }
65
- else {
66
- throw new Error("Runtime, SELECT todo");
45
+ else {
46
+ throw new Error("Runtime, SELECT todo");
47
+ }
48
+ // @ts-ignore
49
+ abap.builtin.sy.get().subrc.set(0);
67
50
  }
68
51
  }
69
- exports.select = select;
52
+ exports.SelectDatabase = SelectDatabase;
70
53
  //# sourceMappingURL=select.js.map
@@ -1,7 +1,12 @@
1
+ import { Context } from "../context";
1
2
  import { FieldSymbol, Structure, Table } from "../types";
2
3
  import { ICharacter } from "../types/_character";
3
- export interface IInsertDatabaseOptions {
4
+ export interface IUpdateDatabaseOptions {
4
5
  from?: Structure | FieldSymbol;
5
6
  table?: Table | FieldSymbol;
6
7
  }
7
- export declare function updateDatabase(table: string | ICharacter, options: IInsertDatabaseOptions): number;
8
+ export declare class UpdateDatabase {
9
+ private readonly context;
10
+ constructor(context: Context);
11
+ updateDatabase(table: string | ICharacter, options: IUpdateDatabaseOptions): Promise<number>;
12
+ }
@@ -1,51 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateDatabase = void 0;
3
+ exports.UpdateDatabase = void 0;
4
4
  const types_1 = require("../types");
5
- function updateDatabase(table, options) {
6
- if (this.db === undefined) {
7
- throw new Error("Runtime, database not initialized");
5
+ class UpdateDatabase {
6
+ constructor(context) {
7
+ this.context = context;
8
8
  }
9
- if (options.table instanceof types_1.FieldSymbol) {
10
- options.table = options.table.getPointer();
11
- }
12
- if (options.from instanceof types_1.FieldSymbol) {
13
- options.from = options.from.getPointer();
14
- }
15
- if (typeof table !== "string") {
16
- table = table.get();
17
- }
18
- // @ts-ignore
19
- const keys = abap.DDIC[table.toUpperCase()].keyFields;
20
- const where = [];
21
- const set = [];
22
- if (options.from) {
23
- const structure = options.from.get();
24
- for (const k of Object.keys(structure)) {
25
- // todo, integers should not be surrounded by '"'?
26
- const str = k + ' = "' + structure[k].get() + '"';
27
- if (keys.includes(k.toUpperCase())) {
28
- where.push(str);
29
- }
30
- else {
31
- set.push(str);
9
+ async updateDatabase(table, options) {
10
+ if (options.table instanceof types_1.FieldSymbol) {
11
+ options.table = options.table.getPointer();
12
+ }
13
+ if (options.from instanceof types_1.FieldSymbol) {
14
+ options.from = options.from.getPointer();
15
+ }
16
+ if (typeof table !== "string") {
17
+ table = table.get();
18
+ }
19
+ // @ts-ignore
20
+ const keys = abap.DDIC[table.toUpperCase()].keyFields;
21
+ const where = [];
22
+ const set = [];
23
+ if (options.from) {
24
+ const structure = options.from.get();
25
+ for (const k of Object.keys(structure)) {
26
+ // todo, integers should not be surrounded by '"'?
27
+ const str = k + ' = "' + structure[k].get() + '"';
28
+ if (keys.includes(k.toUpperCase())) {
29
+ where.push(str);
30
+ }
31
+ else {
32
+ set.push(str);
33
+ }
32
34
  }
33
35
  }
36
+ else {
37
+ throw "updateDatabase, todo";
38
+ }
39
+ const { subrc, dbcnt } = await this.context.defaultDB().update({ table, where: where.join(" AND "), set });
40
+ // @ts-ignore
41
+ abap.builtin.sy.get().subrc.set(subrc);
42
+ // @ts-ignore
43
+ abap.builtin.sy.get().dbcnt.set(dbcnt);
44
+ return subrc;
34
45
  }
35
- else {
36
- throw "updateDatabase, todo";
37
- }
38
- const sql = `UPDATE ${table} SET ${set.join(", ")} WHERE ${where.join(" AND ")}`;
39
- let subrc = 0;
40
- try {
41
- this.db.exec(sql);
42
- }
43
- catch (error) {
44
- subrc = 4;
45
- }
46
- // @ts-ignore
47
- abap.builtin.sy.get().subrc.set(subrc);
48
- return subrc;
49
46
  }
50
- exports.updateDatabase = updateDatabase;
47
+ exports.UpdateDatabase = UpdateDatabase;
51
48
  //# sourceMappingURL=update_database.js.map
@@ -1,10 +1,14 @@
1
+ import { Context } from "../context";
1
2
  import { FieldSymbol } from "../types/field_symbol";
2
3
  import { ICharacter } from "../types/_character";
3
4
  import { INumeric } from "../types/_numeric";
4
- interface IWriteOptions {
5
+ export interface IWriteOptions {
5
6
  newLine?: boolean;
6
7
  skipLine?: boolean;
7
8
  target?: ICharacter;
8
9
  }
9
- export declare function write(source: INumeric | ICharacter | FieldSymbol | string | number, options?: IWriteOptions): void;
10
- export {};
10
+ export declare class WriteStatement {
11
+ private readonly context;
12
+ constructor(context: Context);
13
+ write(source: INumeric | ICharacter | FieldSymbol | string | number, options?: IWriteOptions): void;
14
+ }
@@ -1,41 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.write = void 0;
3
+ exports.WriteStatement = void 0;
4
4
  const types_1 = require("../types");
5
- function write(source, options) {
6
- if ((options === null || options === void 0 ? void 0 : options.skipLine) === true) {
7
- this.console.add("\n");
5
+ class WriteStatement {
6
+ constructor(context) {
7
+ this.context = context;
8
8
  }
9
- else {
10
- if ((options === null || options === void 0 ? void 0 : options.newLine) === true && this.console.get().length > 0) {
11
- this.console.add("\n");
12
- }
13
- if (typeof source === "string" || typeof source === "number") {
14
- if (options === null || options === void 0 ? void 0 : options.target) {
15
- options.target.set(source.toString());
16
- }
17
- else {
18
- this.console.add(source.toString());
19
- }
9
+ write(source, options) {
10
+ if ((options === null || options === void 0 ? void 0 : options.skipLine) === true) {
11
+ this.context.console.add("\n");
20
12
  }
21
13
  else {
22
- if (source instanceof types_1.Structure) {
23
- const obj = source.get();
24
- for (const f in obj) {
25
- // @ts-ignore
26
- abap.statements.write(obj[f]);
14
+ if ((options === null || options === void 0 ? void 0 : options.newLine) === true && this.context.console.get().length > 0) {
15
+ this.context.console.add("\n");
16
+ }
17
+ if (typeof source === "string" || typeof source === "number") {
18
+ if (options === null || options === void 0 ? void 0 : options.target) {
19
+ options.target.set(source.toString());
20
+ }
21
+ else {
22
+ this.context.console.add(source.toString());
27
23
  }
28
24
  }
29
25
  else {
30
- if (options === null || options === void 0 ? void 0 : options.target) {
31
- options.target.set(source.get().toString());
26
+ if (source instanceof types_1.Structure) {
27
+ const obj = source.get();
28
+ for (const f in obj) {
29
+ // @ts-ignore
30
+ abap.statements.write(obj[f]);
31
+ }
32
32
  }
33
33
  else {
34
- this.console.add(source.get().toString());
34
+ if (options === null || options === void 0 ? void 0 : options.target) {
35
+ options.target.set(source.get().toString());
36
+ }
37
+ else {
38
+ this.context.console.add(source.get().toString());
39
+ }
35
40
  }
36
41
  }
37
42
  }
38
43
  }
39
44
  }
40
- exports.write = write;
45
+ exports.WriteStatement = WriteStatement;
41
46
  //# sourceMappingURL=write.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "1.8.38",
3
+ "version": "2.0.0",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -10,6 +10,7 @@
10
10
  },
11
11
  "scripts": {
12
12
  "compile": "tsc",
13
+ "publish:major": "npm --no-git-tag-version version major && rm -rf build && npm install && npm run test && npm publish --access public",
13
14
  "publish:minor": "npm --no-git-tag-version version minor && rm -rf build && npm install && npm run test && npm publish --access public",
14
15
  "publish:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
15
16
  "test": "npm run compile && mocha"
@@ -26,9 +27,6 @@
26
27
  ],
27
28
  "author": "abaplint",
28
29
  "license": "MIT",
29
- "dependencies": {
30
- "sql.js": "^1.6.2"
31
- },
32
30
  "devDependencies": {
33
31
  "@types/chai": "^4.3.0",
34
32
  "@types/mocha": "^9.1.0",