@abaplint/runtime 2.5.59 → 2.5.61

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.
@@ -1,4 +1,4 @@
1
- import { ABAPObject, FieldSymbol, Float, Hex, Structure, Table } from "../types";
1
+ import { ABAPObject, FieldSymbol, Float, HashedTable, Hex, Structure, Table } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
- export declare function eq(left: number | string | ICharacter | INumeric | Float | ABAPObject | Structure | Hex | Table | FieldSymbol, right: number | string | ICharacter | INumeric | Float | ABAPObject | Structure | Hex | Table | FieldSymbol): boolean;
4
+ export declare function eq(left: number | string | ICharacter | INumeric | Float | ABAPObject | Structure | Hex | HashedTable | Table | FieldSymbol, right: number | string | ICharacter | INumeric | Float | ABAPObject | Structure | Hex | HashedTable | Table | FieldSymbol): boolean;
@@ -27,8 +27,9 @@ function eq(left, right) {
27
27
  else if (left instanceof types_1.FieldSymbol) {
28
28
  return eq(left.getPointer(), right);
29
29
  }
30
- if (left instanceof types_1.Table || right instanceof types_1.Table) {
31
- if (left instanceof types_1.Table && right instanceof types_1.Table) {
30
+ if (left instanceof types_1.Table || right instanceof types_1.Table || left instanceof types_1.HashedTable || right instanceof types_1.HashedTable) {
31
+ if ((left instanceof types_1.Table || left instanceof types_1.HashedTable)
32
+ && (right instanceof types_1.Table || right instanceof types_1.HashedTable)) {
32
33
  return compareTables(left, right);
33
34
  }
34
35
  else {
@@ -1,4 +1,4 @@
1
- import { ABAPObject, Structure, Table } from "../types";
1
+ import { ABAPObject, HashedTable, Structure, Table } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
- export declare function gt(left: number | string | ICharacter | INumeric | ABAPObject | Structure | Table, right: number | string | ICharacter | INumeric | ABAPObject | Structure | Table): boolean;
4
+ export declare function gt(left: number | string | ICharacter | INumeric | ABAPObject | Structure | Table | HashedTable, right: number | string | ICharacter | INumeric | ABAPObject | Structure | Table | HashedTable): boolean;
@@ -16,7 +16,7 @@ function gt(left, right) {
16
16
  }
17
17
  return gt(left, right.getPointer());
18
18
  }
19
- if (left instanceof types_1.Table || right instanceof types_1.Table) {
19
+ if (left instanceof types_1.Table || right instanceof types_1.Table || left instanceof types_1.HashedTable || right instanceof types_1.HashedTable) {
20
20
  throw new Error("runtime_todo, gt TABLE");
21
21
  }
22
22
  if (left instanceof types_1.Hex || right instanceof types_1.Hex) {
@@ -4,7 +4,7 @@ exports.initial = void 0;
4
4
  const types_1 = require("../types");
5
5
  function initial(val) {
6
6
  // todo, refactor? add as method in each type instead?
7
- if (val instanceof types_1.Table) {
7
+ if (val instanceof types_1.Table || val instanceof types_1.HashedTable) {
8
8
  return val.array().length === 0;
9
9
  }
10
10
  else if (val instanceof types_1.DataReference) {
@@ -48,6 +48,9 @@ async function deleteInternal(target, options) {
48
48
  return;
49
49
  }
50
50
  if ((options === null || options === void 0 ? void 0 : options.adjacent) === true) {
51
+ if (target instanceof types_1.HashedTable) {
52
+ throw new Error("delete adjacent, hashed table");
53
+ }
51
54
  const array = target.array();
52
55
  for (let index = array.length - 1; index > 0; index--) {
53
56
  const prev = array[index - 1];
@@ -10,7 +10,7 @@ function describe(input) {
10
10
  describe({ field: input.field.getPointer(), type: input.type, length: input.length, mode: input.mode });
11
11
  return;
12
12
  }
13
- if (input.field instanceof types_1.Table) {
13
+ if (input.field instanceof types_1.Table || input.field instanceof types_1.HashedTable) {
14
14
  input.type.set("h");
15
15
  }
16
16
  else if (input.field instanceof types_1.Character || typeof input.field === "string") {
@@ -78,9 +78,21 @@ function insertInternal(options) {
78
78
  options.assigning.assign(val);
79
79
  }
80
80
  }
81
- else if (options.lines && options.data instanceof types_1.Table) {
82
- for (const i of options.data.array()) {
83
- options.table.append(i);
81
+ else if (options.lines
82
+ && (options.data instanceof types_1.Table
83
+ || options.data instanceof types_1.HashedTable)) {
84
+ if (options.table instanceof types_1.HashedTable) {
85
+ for (const source of options.data.array()) {
86
+ const result = options.table.insert(source);
87
+ if (result.subrc !== 0) {
88
+ throw new Error("ITAB_DUPLICATE_KEY");
89
+ }
90
+ }
91
+ }
92
+ else {
93
+ for (const i of options.data.array()) {
94
+ options.table.append(i);
95
+ }
84
96
  }
85
97
  }
86
98
  else if (options.initial === true) {
@@ -1,4 +1,4 @@
1
- import { DataReference, FieldSymbol, Structure, Table } from "../types";
1
+ import { DataReference, FieldSymbol, HashedTable, Structure, Table } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
4
  export interface IReadTableOptions {
@@ -24,4 +24,4 @@ export type ReadTableReturn = {
24
24
  subrc: number;
25
25
  foundIndex: number;
26
26
  };
27
- export declare function readTable(table: Table | FieldSymbol, options?: IReadTableOptions): ReadTableReturn;
27
+ export declare function readTable(table: Table | HashedTable | FieldSymbol, options?: IReadTableOptions): ReadTableReturn;
@@ -29,10 +29,31 @@ function searchWithKey(arr, withKey, startIndex = 0, usesTableLine) {
29
29
  }
30
30
  /////////////////
31
31
  function readTable(table, options) {
32
- var _a, _b;
32
+ var _a, _b, _c;
33
33
  let found = undefined;
34
34
  let foundIndex = 0;
35
+ if (table instanceof types_1.FieldSymbol) {
36
+ if (table.getPointer() === undefined) {
37
+ throw new Error("GETWA_NOT_ASSIGNED");
38
+ }
39
+ return readTable(table.getPointer(), options);
40
+ }
41
+ // check if it is a primary index read specified with WITH KEY instead of WITH TABLE KEY
42
+ if ((options === null || options === void 0 ? void 0 : options.withTableKey) === undefined
43
+ && (options === null || options === void 0 ? void 0 : options.withKeySimple)
44
+ && (((_a = table.getOptions().primaryKey) === null || _a === void 0 ? void 0 : _a.keyFields) || []).length > 0) {
45
+ const fields = new Set(table.getOptions().primaryKey.keyFields);
46
+ for (const name in options.withKeySimple) {
47
+ fields.delete(name.toUpperCase());
48
+ }
49
+ if (fields.size === 0) {
50
+ options.withTableKey = true;
51
+ }
52
+ }
35
53
  if (options === null || options === void 0 ? void 0 : options.index) {
54
+ if (table instanceof types_1.HashedTable) {
55
+ throw new Error("Hashed table, READ INDEX not possible");
56
+ }
36
57
  const arr = table.array();
37
58
  let index = options.index;
38
59
  if (typeof index !== "number") {
@@ -54,6 +75,17 @@ function readTable(table, options) {
54
75
  foundIndex = index;
55
76
  }
56
77
  }
78
+ else if (table instanceof types_1.HashedTable && (options === null || options === void 0 ? void 0 : options.withTableKey) === true && options.withKeySimple) {
79
+ const hash = table.buildHashFromSimple(options.withKeySimple);
80
+ found = table.read(hash);
81
+ foundIndex = 0;
82
+ }
83
+ else if (table instanceof types_1.HashedTable && (options === null || options === void 0 ? void 0 : options.withKey)) {
84
+ // this is slow..
85
+ const searchResult = searchWithKey(table.array(), options.withKey, 0, options === null || options === void 0 ? void 0 : options.usesTableLine);
86
+ found = searchResult.found;
87
+ foundIndex = 0;
88
+ }
57
89
  else if (((options === null || options === void 0 ? void 0 : options.binarySearch) === true || (options === null || options === void 0 ? void 0 : options.withTableKey) === true)
58
90
  && options.withKeyValue
59
91
  && options.withKey) {
@@ -75,12 +107,12 @@ function readTable(table, options) {
75
107
  if (options.from instanceof types_1.FieldSymbol) {
76
108
  options.from = options.from.getPointer();
77
109
  }
78
- if (table instanceof types_1.FieldSymbol) {
79
- table = table.getPointer();
110
+ if (table instanceof types_1.HashedTable) {
111
+ throw new Error("runtime, todo readTable Hashed FROM");
80
112
  }
81
113
  if (table instanceof types_1.Table && options.from instanceof types_1.Structure) {
82
114
  const arr = table.array();
83
- const keys = (_b = (_a = table.getOptions()) === null || _a === void 0 ? void 0 : _a.primaryKey) === null || _b === void 0 ? void 0 : _b.keyFields;
115
+ const keys = (_c = (_b = table.getOptions()) === null || _b === void 0 ? void 0 : _b.primaryKey) === null || _c === void 0 ? void 0 : _c.keyFields;
84
116
  const isStructured = arr[0] instanceof types_1.Structure;
85
117
  if (keys !== undefined && isStructured === true) {
86
118
  // console.dir(keys);
@@ -1,8 +1,8 @@
1
1
  import { Context } from "../context";
2
2
  import { SelectDatabaseOptions, SelectRuntimeOptions } from "../db/db";
3
- import { FieldSymbol, Structure, Table } from "../types";
3
+ import { FieldSymbol, HashedTable, Structure, Table } from "../types";
4
4
  export declare class SelectDatabase {
5
5
  private readonly context;
6
6
  constructor(context: Context);
7
- select(target: Structure | Table | FieldSymbol, input: SelectDatabaseOptions, runtimeOptions?: SelectRuntimeOptions): Promise<void>;
7
+ select(target: Structure | Table | HashedTable | FieldSymbol, input: SelectDatabaseOptions, runtimeOptions?: SelectRuntimeOptions): Promise<void>;
8
8
  }
@@ -36,7 +36,7 @@ class SelectDatabase {
36
36
  // @ts-ignore
37
37
  abap.statements.moveCorresponding(new types_1.Structure(result), target);
38
38
  }
39
- else if (target instanceof types_1.Table) {
39
+ else if (target instanceof types_1.Table || target instanceof types_1.HashedTable) {
40
40
  for (const row of rows) {
41
41
  const targetRow = (0, clone_1.clone)(target.getRowType());
42
42
  if (targetRow instanceof types_1.Structure) {
@@ -10,7 +10,7 @@ function templateFormatting(source, options) {
10
10
  }
11
11
  return templateFormatting(source.getPointer(), options);
12
12
  }
13
- else if (source instanceof types_1.Table) {
13
+ else if (source instanceof types_1.Table || source instanceof types_1.HashedTable) {
14
14
  throw new Error("STRG_ILLEGAL_DATA_TYPE");
15
15
  }
16
16
  else if (source instanceof types_1.Character) {
@@ -19,6 +19,7 @@ export declare class DataReference {
19
19
  clear(): void;
20
20
  get(): any;
21
21
  array(): any;
22
+ getLength(): any;
22
23
  set(value: any): void | Float | ABAPObject | this | Table | Structure;
23
24
  getOffset(input: {
24
25
  offset?: number | INumeric | Hex;
@@ -42,6 +42,11 @@ class DataReference {
42
42
  // @ts-ignore
43
43
  return (_a = this.pointer) === null || _a === void 0 ? void 0 : _a.array();
44
44
  }
45
+ getLength() {
46
+ var _a;
47
+ // @ts-ignore
48
+ return (_a = this.pointer) === null || _a === void 0 ? void 0 : _a.getLength();
49
+ }
45
50
  set(value) {
46
51
  var _a;
47
52
  if (value instanceof DataReference) {
@@ -23,6 +23,7 @@ export declare class FieldSymbol {
23
23
  get(): any;
24
24
  appendInitial(): import("./table").TableRowType | undefined;
25
25
  array(): any;
26
+ getLength(): any;
26
27
  set(value: any): this;
27
28
  getOffset(input: {
28
29
  offset?: number | INumeric | Hex;
@@ -87,6 +87,11 @@ class FieldSymbol {
87
87
  // @ts-ignore
88
88
  return (_a = this.pointer) === null || _a === void 0 ? void 0 : _a.array();
89
89
  }
90
+ getLength() {
91
+ var _a;
92
+ // @ts-ignore
93
+ return (_a = this.pointer) === null || _a === void 0 ? void 0 : _a.getLength();
94
+ }
90
95
  set(value) {
91
96
  var _a;
92
97
  (_a = this.pointer) === null || _a === void 0 ? void 0 : _a.set(value);
@@ -51,6 +51,11 @@ export declare class HashedTable implements ITable {
51
51
  getLength(): number;
52
52
  getKeyByName(name: string): ITableKey | undefined;
53
53
  getSecondaryIndex(name: string): any[];
54
+ buildHashFromData(data: TableRowType): string;
55
+ buildHashFromSimple(data: {
56
+ [key: string]: any;
57
+ }): string;
58
+ read(hash: string): TableRowType | undefined;
54
59
  insert(data: TableRowType): {
55
60
  value: TableRowType | undefined;
56
61
  subrc: number;
@@ -85,26 +85,40 @@ class HashedTable {
85
85
  this.secondaryIndexes[name.toUpperCase()] = copy;
86
86
  return copy;
87
87
  }
88
- insert(data) {
89
- if (this.loops.size !== 0) {
90
- throw new Error("Hash table insert inside LOOP");
91
- }
88
+ buildHashFromData(data) {
92
89
  let hash = "";
93
90
  for (const k of this.options.primaryKey.keyFields) {
94
91
  if (k === "TABLE_LINE") {
95
92
  if (data instanceof structure_1.Structure) {
96
- hash += k + ":" + data.getCharacter();
93
+ hash += k + ":" + data.getCharacter() + "|";
97
94
  }
98
95
  else {
99
96
  // @ts-ignore
100
- hash += k + ":" + data.get();
97
+ hash += k + ":" + data.get() + "|";
101
98
  }
102
99
  }
103
100
  else {
104
101
  // @ts-ignore
105
- hash += k + ":" + data.get()[k.toLowerCase()].get();
102
+ hash += k + ":" + data.get()[k.toLowerCase()].get() + "|";
106
103
  }
107
104
  }
105
+ return hash;
106
+ }
107
+ buildHashFromSimple(data) {
108
+ let hash = "";
109
+ for (const k of this.options.primaryKey.keyFields) {
110
+ hash += k + ":" + data[k.toLowerCase()].get() + "|";
111
+ }
112
+ return hash;
113
+ }
114
+ read(hash) {
115
+ return this.value[hash];
116
+ }
117
+ insert(data) {
118
+ if (this.loops.size !== 0) {
119
+ throw new Error("Hash table insert inside LOOP");
120
+ }
121
+ const hash = this.buildHashFromData(data);
108
122
  if (this.value[hash] !== undefined) {
109
123
  return { value: undefined, subrc: 4 };
110
124
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.5.59",
3
+ "version": "2.5.61",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",