@abaplint/runtime 2.5.58 → 2.5.60

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 {
@@ -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) {
@@ -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);
@@ -31,7 +31,7 @@ interface ITable {
31
31
  getRowType(): TableRowType;
32
32
  getLength(): number;
33
33
  clear(): void;
34
- set(tab: Table | TableRowType): ITable;
34
+ set(tab: Table | HashedTable | TableRowType): ITable;
35
35
  getHeader(): TableRowType;
36
36
  }
37
37
  export declare class TableFactory {
@@ -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;
@@ -64,7 +69,7 @@ export declare class HashedTable implements ITable {
64
69
  getOptions(): ITableOptions;
65
70
  getRowType(): TableRowType;
66
71
  clear(): void;
67
- set(_tab: TableRowType): ITable;
72
+ set(tab: TableRowType): ITable;
68
73
  getHeader(): TableRowType;
69
74
  private getValue;
70
75
  }
@@ -85,15 +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");
88
+ buildHashFromData(data) {
89
+ let hash = "";
90
+ for (const k of this.options.primaryKey.keyFields) {
91
+ if (k === "TABLE_LINE") {
92
+ if (data instanceof structure_1.Structure) {
93
+ hash += k + ":" + data.getCharacter() + "|";
94
+ }
95
+ else {
96
+ // @ts-ignore
97
+ hash += k + ":" + data.get() + "|";
98
+ }
99
+ }
100
+ else {
101
+ // @ts-ignore
102
+ hash += k + ":" + data.get()[k.toLowerCase()].get() + "|";
103
+ }
91
104
  }
105
+ return hash;
106
+ }
107
+ buildHashFromSimple(data) {
92
108
  let hash = "";
93
109
  for (const k of this.options.primaryKey.keyFields) {
94
- // @ts-ignore
95
- hash += k + ":" + data.get()[k.toLowerCase()].get();
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");
96
120
  }
121
+ const hash = this.buildHashFromData(data);
97
122
  if (this.value[hash] !== undefined) {
98
123
  return { value: undefined, subrc: 4 };
99
124
  }
@@ -137,8 +162,17 @@ class HashedTable {
137
162
  clear() {
138
163
  this.value = {};
139
164
  }
140
- set(_tab) {
141
- throw new Error("Method not implemented, set hashed table");
165
+ set(tab) {
166
+ this.clear();
167
+ if (tab instanceof Table || tab instanceof HashedTable) {
168
+ for (const a of tab.array()) {
169
+ this.insert(a);
170
+ }
171
+ return this;
172
+ }
173
+ else {
174
+ throw new Error("Method not implemented, set hashed table");
175
+ }
142
176
  }
143
177
  getHeader() {
144
178
  if (this.header === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.5.58",
3
+ "version": "2.5.60",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",