@abaplint/runtime 2.5.59 → 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.
- package/build/src/compare/eq.d.ts +2 -2
- package/build/src/compare/eq.js +3 -2
- package/build/src/compare/initial.js +1 -1
- package/build/src/statements/describe.js +1 -1
- package/build/src/statements/insert_internal.js +15 -3
- package/build/src/statements/read_table.d.ts +2 -2
- package/build/src/statements/read_table.js +36 -4
- package/build/src/types/table.d.ts +5 -0
- package/build/src/types/table.js +21 -7
- package/package.json +1 -1
|
@@ -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;
|
package/build/src/compare/eq.js
CHANGED
|
@@ -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
|
|
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
|
|
82
|
-
|
|
83
|
-
options.
|
|
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.
|
|
79
|
-
|
|
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 = (
|
|
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);
|
|
@@ -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;
|
package/build/src/types/table.js
CHANGED
|
@@ -85,26 +85,40 @@ class HashedTable {
|
|
|
85
85
|
this.secondaryIndexes[name.toUpperCase()] = copy;
|
|
86
86
|
return copy;
|
|
87
87
|
}
|
|
88
|
-
|
|
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
|
}
|