@abaplint/runtime 2.5.62 → 2.5.64

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 { FieldSymbol, Table } from "../types";
1
+ import { FieldSymbol, HashedTable, Table } from "../types";
2
2
  import { INumeric } from "../types/_numeric";
3
3
  export interface IDeleteInternalOptions {
4
4
  where?: (i: any) => boolean;
@@ -9,4 +9,4 @@ export interface IDeleteInternalOptions {
9
9
  from?: any;
10
10
  to?: any;
11
11
  }
12
- export declare function deleteInternal(target: Table | FieldSymbol, options?: IDeleteInternalOptions): Promise<void>;
12
+ export declare function deleteInternal(target: Table | HashedTable | FieldSymbol, options?: IDeleteInternalOptions): Promise<void>;
@@ -17,7 +17,7 @@ async function deleteInternal(target, options) {
17
17
  if (target instanceof types_1.FieldSymbol) {
18
18
  target = target.getPointer();
19
19
  if (target === undefined) {
20
- throw "FS not assigned";
20
+ throw new Error("deleteInternal, FS not assigned");
21
21
  }
22
22
  }
23
23
  if ((options === null || options === void 0 ? void 0 : options.index)
@@ -84,7 +84,12 @@ async function deleteInternal(target, options) {
84
84
  if (options === null || options === void 0 ? void 0 : options.where) {
85
85
  const row = i instanceof types_1.Structure ? i.get() : { table_line: i };
86
86
  if (options.where(row) === true) {
87
- target.deleteIndex(index);
87
+ if (target instanceof types_1.HashedTable) {
88
+ target.deleteFrom(i);
89
+ }
90
+ else {
91
+ target.deleteIndex(index);
92
+ }
88
93
  }
89
94
  }
90
95
  else if ((options === null || options === void 0 ? void 0 : options.index) && options.index.get() === index) {
@@ -82,8 +82,8 @@ function describe(input) {
82
82
  }
83
83
  if (input.table) {
84
84
  // @ts-ignore
85
- abap.builtin.sy.get().tfill.set(input.table.array().length);
86
- (_a = input.lines) === null || _a === void 0 ? void 0 : _a.set(input.table.array().length);
85
+ abap.builtin.sy.get().tfill.set(input.table.getArrayLength());
86
+ (_a = input.lines) === null || _a === void 0 ? void 0 : _a.set(input.table.getArrayLength());
87
87
  }
88
88
  }
89
89
  exports.describe = describe;
@@ -96,7 +96,7 @@ function insertInternal(options) {
96
96
  }
97
97
  }
98
98
  else if (options.initial === true) {
99
- let index = options.table.array().length;
99
+ let index = options.table.getArrayLength();
100
100
  if (options.index) {
101
101
  index = options.index.get() - 1;
102
102
  }
@@ -122,7 +122,7 @@ function insertInternal(options) {
122
122
  }
123
123
  else if (data) {
124
124
  // todo, for now it just appends, this is not correct, but currently the table type is not known
125
- const val = options.table.insertIndex(data, options.table.array().length);
125
+ const val = options.table.insertIndex(data, options.table.getArrayLength());
126
126
  if (options.assigning) {
127
127
  options.assigning.assign(val);
128
128
  }
@@ -1,4 +1,4 @@
1
- import { FieldSymbol, Integer, Table } from "../types";
1
+ import { FieldSymbol, HashedTable, Integer, Table } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
4
  type topType = {
@@ -11,5 +11,5 @@ export interface ILoopOptions {
11
11
  to?: Integer;
12
12
  topEquals?: topType;
13
13
  }
14
- export declare function loop(table: Table | FieldSymbol | undefined, options?: ILoopOptions): AsyncGenerator<any, void, unknown>;
14
+ export declare function loop(table: Table | HashedTable | FieldSymbol | undefined, options?: ILoopOptions): AsyncGenerator<any, void, unknown>;
15
15
  export {};
@@ -78,35 +78,35 @@ function loop(table, options) {
78
78
  else {
79
79
  array = table.array();
80
80
  }
81
- const loopIndex = table.startLoop(loopFrom);
81
+ const loopController = table.startLoop(loopFrom, loopTo, array);
82
82
  let entered = false;
83
83
  try {
84
84
  const isStructured = array[0] instanceof types_1.Structure;
85
- while (loopIndex.index < loopTo) {
86
- if (loopIndex.index > array.length) {
85
+ while (loopController.index < loopController.loopTo) {
86
+ if (loopController.index > array.length) {
87
87
  break;
88
88
  }
89
- const current = array[loopIndex.index];
89
+ const current = array[loopController.index];
90
90
  if (options === null || options === void 0 ? void 0 : options.where) {
91
91
  const row = isStructured ? current.get() : { table_line: current };
92
92
  if ((yield __await(options.where(row))) === false) {
93
- loopIndex.index++;
93
+ loopController.index++;
94
94
  continue;
95
95
  }
96
96
  }
97
97
  // @ts-ignore
98
- abap.builtin.sy.get().tabix.set(loopIndex.index + 1);
98
+ abap.builtin.sy.get().tabix.set(loopController.index + 1);
99
99
  entered = true;
100
100
  yield yield __await(current);
101
- loopIndex.index++;
101
+ loopController.index++;
102
102
  if ((options === null || options === void 0 ? void 0 : options.to) === undefined && (options === null || options === void 0 ? void 0 : options.usingKey) === undefined) {
103
103
  // extra rows might have been inserted inside the loop
104
- loopTo = array.length;
104
+ loopController.loopTo = array.length;
105
105
  }
106
106
  }
107
107
  }
108
108
  finally {
109
- table.unregisterLoop(loopIndex);
109
+ table.unregisterLoop(loopController);
110
110
  // @ts-ignore
111
111
  abap.builtin.sy.get().subrc.set(entered ? 0 : 4);
112
112
  }
@@ -51,6 +51,9 @@ function sort(input, options) {
51
51
  sort(pnt, options);
52
52
  return;
53
53
  }
54
+ if (input instanceof types_1.HashedTable) {
55
+ throw new Error("Sort hashed table, ugh?");
56
+ }
54
57
  if (options === null || options === void 0 ? void 0 : options.by) {
55
58
  if (options.by.length === 0) {
56
59
  throw "SortByLengthZero";
@@ -5,8 +5,6 @@ const _parse_1 = require("../operators/_parse");
5
5
  const throw_error_1 = require("../throw_error");
6
6
  const field_symbol_1 = require("./field_symbol");
7
7
  const structure_1 = require("./structure");
8
- // eslint-disable-next-line prefer-const
9
- let featureFixLength = true;
10
8
  class Character {
11
9
  constructor(length, extra) {
12
10
  this.constant = false;
@@ -48,7 +46,7 @@ class Character {
48
46
  if (this.value.length > this.length) {
49
47
  this.value = this.value.substr(0, this.length);
50
48
  }
51
- else if (featureFixLength && this.value.length < this.length) {
49
+ else if (this.value.length < this.length) {
52
50
  this.value.padEnd(this.length, " ");
53
51
  }
54
52
  return this;
@@ -69,12 +67,7 @@ class Character {
69
67
  return this.length;
70
68
  }
71
69
  clear() {
72
- if (featureFixLength) {
73
- this.value = " ".repeat(this.length);
74
- }
75
- else {
76
- this.value = "";
77
- }
70
+ this.value = " ".repeat(this.length);
78
71
  }
79
72
  get() {
80
73
  return this.value;
@@ -9,9 +9,11 @@ export declare enum TableAccessType {
9
9
  index = "INDEX",
10
10
  any = "ANY"
11
11
  }
12
- export declare class LoopIndex {
12
+ export declare class LoopController {
13
13
  index: number;
14
- constructor(start: number);
14
+ loopTo: number;
15
+ array: any[];
16
+ constructor(from: number, loopTo: number, array: any[]);
15
17
  }
16
18
  export type ITableKey = {
17
19
  name: string;
@@ -34,6 +36,7 @@ interface ITable {
34
36
  set(tab: Table | HashedTable | TableRowType): ITable;
35
37
  getHeader(): TableRowType;
36
38
  }
39
+ export declare let featureHashedTables: boolean;
37
40
  export declare class TableFactory {
38
41
  static construct(rowType: TableRowType, options?: ITableOptions, qualifiedName?: string): Table | HashedTable;
39
42
  }
@@ -52,6 +55,8 @@ export declare class HashedTable implements ITable {
52
55
  getKeyByName(name: string): ITableKey | undefined;
53
56
  getSecondaryIndex(name: string): any[];
54
57
  buildHashFromData(data: TableRowType): string;
58
+ deleteIndex(_index: number): void;
59
+ deleteFrom(row: TableRowType): void;
55
60
  buildHashFromSimple(data: {
56
61
  [key: string]: any;
57
62
  }): string;
@@ -60,9 +65,9 @@ export declare class HashedTable implements ITable {
60
65
  value: TableRowType | undefined;
61
66
  subrc: number;
62
67
  };
63
- array(): readonly any[];
64
- startLoop(start?: number): LoopIndex;
65
- unregisterLoop(loop: LoopIndex): void;
68
+ array(): any[];
69
+ startLoop(from: number, to: number, array: any[]): LoopController;
70
+ unregisterLoop(loop: LoopController): void;
66
71
  insertIndex(_item: TableRowType, _index: number): void;
67
72
  append(_item: TableRowType): void;
68
73
  getQualifiedName(): string | undefined;
@@ -88,10 +93,10 @@ export declare class Table implements ITable {
88
93
  getSecondaryIndex(name: string): TableRowType[];
89
94
  getQualifiedName(): string | undefined;
90
95
  getOptions(): ITableOptions;
91
- startLoop(start?: number): LoopIndex;
92
- unregisterLoop(loop: LoopIndex): void;
96
+ startLoop(from: number, to: number, array: any[]): LoopController;
97
+ unregisterLoop(loop: LoopController): void;
93
98
  getRowType(): TableRowType;
94
- array(): readonly any[];
99
+ array(): any[];
95
100
  clear(): void;
96
101
  set(tab: Table | TableRowType): this;
97
102
  getHeader(): TableRowType;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Table = exports.HashedTable = exports.SortedTable = exports.TableFactory = exports.LoopIndex = exports.TableAccessType = void 0;
3
+ exports.Table = exports.HashedTable = exports.SortedTable = exports.TableFactory = exports.featureHashedTables = exports.LoopController = exports.TableAccessType = void 0;
4
4
  const integer_1 = require("./integer");
5
5
  const string_1 = require("./string");
6
6
  const clone_1 = require("../clone");
@@ -17,14 +17,16 @@ var TableAccessType;
17
17
  TableAccessType["index"] = "INDEX";
18
18
  TableAccessType["any"] = "ANY";
19
19
  })(TableAccessType = exports.TableAccessType || (exports.TableAccessType = {}));
20
- class LoopIndex {
21
- constructor(start) {
22
- this.index = start;
20
+ class LoopController {
21
+ constructor(from, loopTo, array) {
22
+ this.index = from;
23
+ this.loopTo = loopTo;
24
+ this.array = array;
23
25
  }
24
26
  }
25
- exports.LoopIndex = LoopIndex;
27
+ exports.LoopController = LoopController;
26
28
  // eslint-disable-next-line prefer-const
27
- let featureHashedTables = false;
29
+ exports.featureHashedTables = true;
28
30
  class TableFactory {
29
31
  static construct(rowType, options, qualifiedName) {
30
32
  var _a;
@@ -39,7 +41,7 @@ class TableFactory {
39
41
  withHeader: false,
40
42
  };
41
43
  }
42
- if (featureHashedTables === true && ((_a = options.primaryKey) === null || _a === void 0 ? void 0 : _a.type) === TableAccessType.hashed) {
44
+ if (exports.featureHashedTables === true && ((_a = options.primaryKey) === null || _a === void 0 ? void 0 : _a.type) === TableAccessType.hashed) {
43
45
  return new HashedTable(rowType, options, qualifiedName);
44
46
  }
45
47
  else {
@@ -99,15 +101,36 @@ class HashedTable {
99
101
  }
100
102
  else {
101
103
  // @ts-ignore
102
- hash += k + ":" + data.get()[k.toLowerCase()].get() + "|";
104
+ let val = data.get()[k.toLowerCase()];
105
+ if (val instanceof structure_1.Structure) {
106
+ val = val.getCharacter();
107
+ }
108
+ else {
109
+ val = val.get();
110
+ }
111
+ hash += k + ":" + val + "|";
103
112
  }
104
113
  }
105
114
  return hash;
106
115
  }
116
+ deleteIndex(_index) {
117
+ throw new Error("HashedTable, deleteIndex");
118
+ }
119
+ deleteFrom(row) {
120
+ const hash = this.buildHashFromData(row);
121
+ delete this.value[hash];
122
+ }
107
123
  buildHashFromSimple(data) {
108
124
  let hash = "";
109
125
  for (const k of this.options.primaryKey.keyFields) {
110
- hash += k + ":" + data[k.toLowerCase()].get() + "|";
126
+ let val = data[k.toLowerCase()];
127
+ if (val instanceof structure_1.Structure) {
128
+ val = val.getCharacter();
129
+ }
130
+ else {
131
+ val = val.get();
132
+ }
133
+ hash += k + ":" + val + "|";
111
134
  }
112
135
  return hash;
113
136
  }
@@ -115,15 +138,15 @@ class HashedTable {
115
138
  return this.value[hash];
116
139
  }
117
140
  insert(data) {
118
- if (this.loops.size !== 0) {
119
- throw new Error("Hash table insert inside LOOP");
120
- }
121
141
  const hash = this.buildHashFromData(data);
122
142
  if (this.value[hash] !== undefined) {
123
143
  return { value: undefined, subrc: 4 };
124
144
  }
125
145
  else {
126
146
  const val = this.getValue(data);
147
+ for (const loopController of this.loops.values()) {
148
+ loopController.array.push(val);
149
+ }
127
150
  this.value[hash] = val;
128
151
  return { value: val, subrc: 0 };
129
152
  }
@@ -136,8 +159,8 @@ class HashedTable {
136
159
  }
137
160
  return ret;
138
161
  }
139
- startLoop(start = 0) {
140
- const l = new LoopIndex(start);
162
+ startLoop(from, to, array) {
163
+ const l = new LoopController(from, to, array);
141
164
  this.loops.add(l);
142
165
  return l;
143
166
  }
@@ -247,8 +270,8 @@ class Table {
247
270
  getOptions() {
248
271
  return this.options;
249
272
  }
250
- startLoop(start = 0) {
251
- const l = new LoopIndex(start);
273
+ startLoop(from, to, array) {
274
+ const l = new LoopController(from, to, array);
252
275
  this.loops.add(l);
253
276
  return l;
254
277
  }
@@ -305,12 +328,15 @@ class Table {
305
328
  if (index === 0) {
306
329
  this.value.unshift(val);
307
330
  }
331
+ else if (index === this.value.length) {
332
+ this.value.push(val);
333
+ }
308
334
  else {
309
335
  this.value.splice(index, 0, val);
310
336
  }
311
- for (const l of this.loops.values()) {
312
- if (l.index <= index) {
313
- l.index++;
337
+ for (const loopController of this.loops.values()) {
338
+ if (index <= loopController.index) {
339
+ loopController.index++;
314
340
  }
315
341
  }
316
342
  return val;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.5.62",
3
+ "version": "2.5.64",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",