@abaplint/runtime 2.13.83 → 2.13.85

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.
@@ -0,0 +1,11 @@
1
+ import { Integer } from "../types";
2
+ import { ICharacter } from "../types/_character";
3
+ import { INumeric } from "../types/_numeric";
4
+ export interface IFindAnyNotOfInput {
5
+ val: ICharacter | string;
6
+ sub: ICharacter | string;
7
+ off?: INumeric | number;
8
+ len?: INumeric | number;
9
+ occ?: INumeric | number;
10
+ }
11
+ export declare function find_any_not_of(input: IFindAnyNotOfInput): Integer;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.find_any_not_of = find_any_not_of;
4
+ const types_1 = require("../types");
5
+ const throw_error_1 = require("../throw_error");
6
+ function find_any_not_of(input) {
7
+ const val = typeof input.val === "string" ? input.val : input.val.get();
8
+ const sub = typeof input.sub === "string" ? input.sub : input.sub.get();
9
+ const off = typeof input.off === "number" ? input.off : input.off?.get() || 0;
10
+ const len = typeof input.len === "number" ? input.len : input.len?.get();
11
+ let occ = typeof input.occ === "number" ? input.occ : input.occ?.get();
12
+ if (occ === 0) {
13
+ (0, throw_error_1.throwError)("CX_SY_STRG_PAR_VAL");
14
+ }
15
+ else if (occ === undefined) {
16
+ occ = 1;
17
+ }
18
+ if (off < 0 || off > val.length) {
19
+ (0, throw_error_1.throwError)("CX_SY_RANGE_OUT_OF_BOUNDS");
20
+ }
21
+ if (len !== undefined && (len < 0 || off + len > val.length)) {
22
+ (0, throw_error_1.throwError)("CX_SY_RANGE_OUT_OF_BOUNDS");
23
+ }
24
+ const end = len === undefined ? val.length : off + len;
25
+ const characters = new Set(sub.split(""));
26
+ let remaining = Math.abs(occ);
27
+ if (occ > 0) {
28
+ for (let i = off; i < end; i++) {
29
+ if (!characters.has(val.charAt(i)) && --remaining === 0) {
30
+ return new types_1.Integer().set(i);
31
+ }
32
+ }
33
+ }
34
+ else {
35
+ for (let i = end - 1; i >= off; i--) {
36
+ if (!characters.has(val.charAt(i)) && --remaining === 0) {
37
+ return new types_1.Integer().set(i);
38
+ }
39
+ }
40
+ }
41
+ return new types_1.Integer().set(-1);
42
+ }
43
+ //# sourceMappingURL=find_any_not_of.js.map
@@ -0,0 +1,11 @@
1
+ import { Integer } from "../types";
2
+ import { ICharacter } from "../types/_character";
3
+ import { INumeric } from "../types/_numeric";
4
+ export interface IFindAnyOfInput {
5
+ val: ICharacter | string;
6
+ sub: ICharacter | string;
7
+ off?: INumeric | number;
8
+ len?: INumeric | number;
9
+ occ?: INumeric | number;
10
+ }
11
+ export declare function find_any_of(input: IFindAnyOfInput): Integer;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.find_any_of = find_any_of;
4
+ const types_1 = require("../types");
5
+ const throw_error_1 = require("../throw_error");
6
+ function find_any_of(input) {
7
+ const val = typeof input.val === "string" ? input.val : input.val.get();
8
+ const sub = typeof input.sub === "string" ? input.sub : input.sub.get();
9
+ const off = typeof input.off === "number" ? input.off : input.off?.get() || 0;
10
+ const len = typeof input.len === "number" ? input.len : input.len?.get();
11
+ let occ = typeof input.occ === "number" ? input.occ : input.occ?.get();
12
+ if (occ === 0) {
13
+ (0, throw_error_1.throwError)("CX_SY_STRG_PAR_VAL");
14
+ }
15
+ else if (occ === undefined) {
16
+ occ = 1;
17
+ }
18
+ if (off < 0 || off > val.length) {
19
+ (0, throw_error_1.throwError)("CX_SY_RANGE_OUT_OF_BOUNDS");
20
+ }
21
+ if (len !== undefined && (len < 0 || off + len > val.length)) {
22
+ (0, throw_error_1.throwError)("CX_SY_RANGE_OUT_OF_BOUNDS");
23
+ }
24
+ if (sub === "") {
25
+ return new types_1.Integer().set(-1);
26
+ }
27
+ const end = len === undefined ? val.length : off + len;
28
+ const characters = new Set(sub.split(""));
29
+ let remaining = Math.abs(occ);
30
+ if (occ > 0) {
31
+ for (let i = off; i < end; i++) {
32
+ if (characters.has(val.charAt(i)) && --remaining === 0) {
33
+ return new types_1.Integer().set(i);
34
+ }
35
+ }
36
+ }
37
+ else {
38
+ for (let i = end - 1; i >= off; i--) {
39
+ if (characters.has(val.charAt(i)) && --remaining === 0) {
40
+ return new types_1.Integer().set(i);
41
+ }
42
+ }
43
+ }
44
+ return new types_1.Integer().set(-1);
45
+ }
46
+ //# sourceMappingURL=find_any_of.js.map
@@ -15,6 +15,8 @@ export * from "./count";
15
15
  export * from "./escape";
16
16
  export * from "./exp";
17
17
  export * from "./find";
18
+ export * from "./find_any_not_of";
19
+ export * from "./find_any_of";
18
20
  export * from "./floor";
19
21
  export * from "./frac";
20
22
  export * from "./from_mixed";
@@ -32,6 +32,8 @@ __exportStar(require("./count"), exports);
32
32
  __exportStar(require("./escape"), exports);
33
33
  __exportStar(require("./exp"), exports);
34
34
  __exportStar(require("./find"), exports);
35
+ __exportStar(require("./find_any_not_of"), exports);
36
+ __exportStar(require("./find_any_of"), exports);
35
37
  __exportStar(require("./floor"), exports);
36
38
  __exportStar(require("./frac"), exports);
37
39
  __exportStar(require("./from_mixed"), exports);
@@ -12,7 +12,12 @@ function find(input, options) {
12
12
  let s = "";
13
13
  if (options.find) {
14
14
  s = options.find;
15
- if (typeof s !== "string") {
15
+ if (s instanceof types_1.Character) {
16
+ // trailing blanks are ignored for fixed length character typed operands,
17
+ // note that text string operands keep them
18
+ s = s.getTrimEnd();
19
+ }
20
+ else if (typeof s !== "string") {
16
21
  s = s.get();
17
22
  }
18
23
  if (s === "") {
@@ -37,7 +37,7 @@ import { IRollbackOptions } from "./rollback";
37
37
  import { setBit } from "./set_bit";
38
38
  import { shift } from "./shift";
39
39
  import { sort } from "./sort";
40
- import { wait } from "./wait";
40
+ import { IWaitOptions } from "./wait";
41
41
  import { IOpenCursorDatabaseOptions } from "./open_cursor";
42
42
  import { setHandler } from "./set_handler";
43
43
  import { split } from "./split";
@@ -88,7 +88,6 @@ export declare class Statements {
88
88
  sort: typeof sort;
89
89
  split: typeof split;
90
90
  translate: typeof translate;
91
- wait: typeof wait;
92
91
  receive: typeof receive;
93
92
  callTransaction: typeof callTransaction;
94
93
  private readonly context;
@@ -99,6 +98,7 @@ export declare class Statements {
99
98
  closeCursor(cursor: INumeric): Promise<void>;
100
99
  commit(options?: ICommitOptions): Promise<void>;
101
100
  rollback(options?: IRollbackOptions): Promise<void>;
101
+ wait(options: IWaitOptions): Promise<void>;
102
102
  deleteDatabase(table: string | ICharacter, options: IDeleteDatabaseOptions): Promise<void>;
103
103
  insertDatabase(table: string | ICharacter, options: IInsertDatabaseOptions): Promise<number | undefined>;
104
104
  modifyDatabase(table: string | ICharacter, options: IModifyDatabaseOptions): Promise<void>;
@@ -91,7 +91,6 @@ class Statements {
91
91
  sort = sort_1.sort;
92
92
  split = split_1.split;
93
93
  translate = translate_1.translate;
94
- wait = wait_1.wait;
95
94
  receive = receive_1.receive;
96
95
  callTransaction = call_transaction_1.callTransaction;
97
96
  context;
@@ -117,6 +116,9 @@ class Statements {
117
116
  async rollback(options) {
118
117
  return (0, rollback_1.rollback)(this.context, options);
119
118
  }
119
+ async wait(options) {
120
+ return (0, wait_1.wait)(this.context, options);
121
+ }
120
122
  async deleteDatabase(table, options) {
121
123
  await (0, delete_database_1.deleteDatabase)(table, options, this.context);
122
124
  }
@@ -1,5 +1,9 @@
1
1
  import { INumeric } from "../types/_numeric";
2
- export declare function wait(options: {
3
- cond: () => any;
2
+ import { Context } from "../context";
3
+ export interface IWaitOptions {
4
+ /** UNTIL, the logical expression, if not supplied its the simple "WAIT UP TO" variant */
5
+ cond?: () => any;
6
+ /** UP TO sec SECONDS */
4
7
  seconds?: INumeric;
5
- }): Promise<void>;
8
+ }
9
+ export declare function wait(context: Context, options: IWaitOptions): Promise<void>;
@@ -1,9 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.wait = wait;
4
- async function wait(options) {
4
+ // WAIT ends the current database LUW when it interrupts the execution of the program,
5
+ // ie. all open database connections are committed, note that this is not a full COMMIT WORK,
6
+ // sy-subrc is owned by the WAIT statement itself
7
+ async function implicitCommit(context) {
8
+ for (const name of Object.keys(context.databaseConnections)) {
9
+ await context.databaseConnections[name].commit();
10
+ }
11
+ }
12
+ async function wait(context, options) {
5
13
  const timeout = options.seconds === undefined ? undefined : options.seconds.get() * 1000;
6
14
  const deadline = timeout === undefined ? undefined : Date.now() + timeout;
15
+ if (options.cond === undefined) {
16
+ // "WAIT UP TO sec SECONDS", the execution is always interrupted and sy-subrc is always zero
17
+ await implicitCommit(context);
18
+ await new Promise(r => setTimeout(r, timeout));
19
+ abap.builtin.sy.get().subrc.set(0);
20
+ return;
21
+ }
22
+ let interrupted = false;
7
23
  while (true) {
8
24
  if (options.cond() === true) {
9
25
  abap.builtin.sy.get().subrc.set(0);
@@ -14,6 +30,12 @@ async function wait(options) {
14
30
  abap.builtin.sy.get().subrc.set(8);
15
31
  return;
16
32
  }
33
+ if (interrupted === false) {
34
+ // the condition is not true, so the execution is about to be interrupted,
35
+ // commit before sleeping so the changes are visible to other sessions during the wait
36
+ interrupted = true;
37
+ await implicitCommit(context);
38
+ }
17
39
  await new Promise(r => setTimeout(r, Math.min(500, remaining)));
18
40
  }
19
41
  }
@@ -23,7 +23,9 @@ class XString {
23
23
  }
24
24
  set(value) {
25
25
  if (typeof value === "string") {
26
- this.value = value;
26
+ // the input is interpreted as hexadecimal digits, the conversion stops at
27
+ // the first character which is not an uppercase hex digit
28
+ this.value = /^[0-9A-F]*/.exec(value)?.[0] || "";
27
29
  if (this.value.length % 2 === 1) {
28
30
  this.value = this.value + "0";
29
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.13.83",
3
+ "version": "2.13.85",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",