@abaplint/runtime 2.1.53 → 2.1.56

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/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # @abaplint/runtime
2
-
1
+ # @abaplint/runtime
2
+
3
3
  Runtime
@@ -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): void;
12
+ export declare function deleteInternal(target: Table | FieldSymbol, options?: IDeleteInternalOptions): Promise<void>;
@@ -1,10 +1,18 @@
1
1
  "use strict";
2
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
3
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4
+ var m = o[Symbol.asyncIterator], i;
5
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
6
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
7
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
8
+ };
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  exports.deleteInternal = void 0;
4
11
  const types_1 = require("../types");
5
12
  const compare_1 = require("../compare");
6
13
  const loop_1 = require("./loop");
7
- function deleteInternal(target, options) {
14
+ async function deleteInternal(target, options) {
15
+ var e_1, _a;
8
16
  let prev = undefined;
9
17
  let index = 0;
10
18
  if (target instanceof types_1.FieldSymbol) {
@@ -31,45 +39,55 @@ function deleteInternal(target, options) {
31
39
  return;
32
40
  }
33
41
  }
34
- for (const i of (0, loop_1.loop)(target)) {
35
- // @ts-ignore
36
- index = abap.builtin.sy.get().tabix.get() - 1;
37
- if (options === null || options === void 0 ? void 0 : options.where) {
38
- const row = i instanceof types_1.Structure ? i.get() : { table_line: i };
39
- if (options.where(row) === true) {
40
- target.deleteIndex(index);
42
+ try {
43
+ for (var _b = __asyncValues((0, loop_1.loop)(target)), _c; _c = await _b.next(), !_c.done;) {
44
+ const i = _c.value;
45
+ // @ts-ignore
46
+ index = abap.builtin.sy.get().tabix.get() - 1;
47
+ if (options === null || options === void 0 ? void 0 : options.where) {
48
+ const row = i instanceof types_1.Structure ? i.get() : { table_line: i };
49
+ if (options.where(row) === true) {
50
+ target.deleteIndex(index);
51
+ }
41
52
  }
42
- }
43
- else if ((options === null || options === void 0 ? void 0 : options.adjacent) === true && prev !== undefined) {
44
- if (options === null || options === void 0 ? void 0 : options.comparing) {
45
- let match = false;
46
- for (const compareField of options.comparing) {
47
- match = (0, compare_1.eq)(prev.get()[compareField], i.get()[compareField]);
48
- if (!match) {
49
- break;
53
+ else if ((options === null || options === void 0 ? void 0 : options.adjacent) === true && prev !== undefined) {
54
+ if (options === null || options === void 0 ? void 0 : options.comparing) {
55
+ let match = false;
56
+ for (const compareField of options.comparing) {
57
+ match = (0, compare_1.eq)(prev.get()[compareField], i.get()[compareField]);
58
+ if (!match) {
59
+ break;
60
+ }
61
+ }
62
+ if (match) {
63
+ target.deleteIndex(index);
50
64
  }
51
65
  }
52
- if (match) {
66
+ else if ((0, compare_1.eq)(prev, i) === true) {
53
67
  target.deleteIndex(index);
54
68
  }
55
69
  }
56
- else if ((0, compare_1.eq)(prev, i) === true) {
70
+ else if ((options === null || options === void 0 ? void 0 : options.index) && options.index.get() === index) {
71
+ target.deleteIndex(options.index.get() - 1);
72
+ }
73
+ else if ((options === null || options === void 0 ? void 0 : options.fromValue) && (0, compare_1.eq)(options.fromValue, i)) {
57
74
  target.deleteIndex(index);
58
75
  }
76
+ else if ((options === null || options === void 0 ? void 0 : options.from) && options.from.get() <= index + 1) {
77
+ target.deleteIndex(index);
78
+ }
79
+ else if ((options === null || options === void 0 ? void 0 : options.to) && options.to.get() <= index + 1) {
80
+ target.deleteIndex(0);
81
+ }
82
+ prev = i;
59
83
  }
60
- else if ((options === null || options === void 0 ? void 0 : options.index) && options.index.get() === index) {
61
- target.deleteIndex(options.index.get() - 1);
62
- }
63
- else if ((options === null || options === void 0 ? void 0 : options.fromValue) && (0, compare_1.eq)(options.fromValue, i)) {
64
- target.deleteIndex(index);
65
- }
66
- else if ((options === null || options === void 0 ? void 0 : options.from) && options.from.get() <= index + 1) {
67
- target.deleteIndex(index);
68
- }
69
- else if ((options === null || options === void 0 ? void 0 : options.to) && options.to.get() <= index + 1) {
70
- target.deleteIndex(0);
84
+ }
85
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
86
+ finally {
87
+ try {
88
+ if (_c && !_c.done && (_a = _b.return)) await _a.call(_b);
71
89
  }
72
- prev = i;
90
+ finally { if (e_1) throw e_1.error; }
73
91
  }
74
92
  }
75
93
  exports.deleteInternal = deleteInternal;
@@ -1,7 +1,7 @@
1
1
  import { FieldSymbol, Integer, Table } from "../types";
2
2
  export interface ILoopOptions {
3
- where?: (i: any) => boolean;
3
+ where?: (i: any) => Promise<boolean>;
4
4
  from?: Integer;
5
5
  to?: Integer;
6
6
  }
7
- export declare function loop(table: Table | FieldSymbol | undefined, options?: ILoopOptions): Generator<any, void, unknown>;
7
+ export declare function loop(table: Table | FieldSymbol | undefined, options?: ILoopOptions): AsyncGenerator<any, void, unknown>;
@@ -1,54 +1,80 @@
1
1
  "use strict";
2
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
3
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4
+ var m = o[Symbol.asyncIterator], i;
5
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
6
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
7
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
8
+ };
9
+ var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
10
+ var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
11
+ var i, p;
12
+ return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
13
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
14
+ };
15
+ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
16
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
17
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
18
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
19
+ function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
20
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
21
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
22
+ function fulfill(value) { resume("next", value); }
23
+ function reject(value) { resume("throw", value); }
24
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
25
+ };
2
26
  Object.defineProperty(exports, "__esModule", { value: true });
3
27
  exports.loop = void 0;
4
28
  const types_1 = require("../types");
5
- function* loop(table, options) {
6
- if (table === undefined) {
7
- throw new Error("LOOP at undefined");
8
- }
9
- else if (table instanceof types_1.FieldSymbol) {
10
- // @ts-ignore
11
- yield* loop(table.getPointer(), options);
12
- return;
13
- }
14
- const length = table.array().length;
15
- if (length === 0) {
16
- // @ts-ignore
17
- abap.builtin.sy.get().subrc.set(4);
18
- return;
19
- }
20
- const loopFrom = (options === null || options === void 0 ? void 0 : options.from) && (options === null || options === void 0 ? void 0 : options.from.get()) > 0 ? options.from.get() - 1 : 0;
21
- let loopTo = (options === null || options === void 0 ? void 0 : options.to) && options.to.get() < length ? options.to.get() : length;
22
- const loopIndex = table.startLoop(loopFrom);
23
- let entered = false;
24
- try {
25
- const array = table.array();
26
- const isStructured = array[0] instanceof types_1.Structure;
27
- while (loopIndex.index < loopTo) {
28
- if (loopIndex.index > array.length) {
29
- break;
30
- }
31
- const current = array[loopIndex.index];
32
- if (options === null || options === void 0 ? void 0 : options.where) {
33
- const row = isStructured ? current.get() : { table_line: current };
34
- if (options.where(row) === false) {
35
- loopIndex.index++;
36
- continue;
29
+ function loop(table, options) {
30
+ return __asyncGenerator(this, arguments, function* loop_1() {
31
+ if (table === undefined) {
32
+ throw new Error("LOOP at undefined");
33
+ }
34
+ else if (table instanceof types_1.FieldSymbol) {
35
+ // @ts-ignore
36
+ yield __await(yield* __asyncDelegator(__asyncValues(loop(table.getPointer(), options))));
37
+ return yield __await(void 0);
38
+ }
39
+ const length = table.array().length;
40
+ if (length === 0) {
41
+ // @ts-ignore
42
+ abap.builtin.sy.get().subrc.set(4);
43
+ return yield __await(void 0);
44
+ }
45
+ const loopFrom = (options === null || options === void 0 ? void 0 : options.from) && (options === null || options === void 0 ? void 0 : options.from.get()) > 0 ? options.from.get() - 1 : 0;
46
+ let loopTo = (options === null || options === void 0 ? void 0 : options.to) && options.to.get() < length ? options.to.get() : length;
47
+ const loopIndex = table.startLoop(loopFrom);
48
+ let entered = false;
49
+ try {
50
+ const array = table.array();
51
+ const isStructured = array[0] instanceof types_1.Structure;
52
+ while (loopIndex.index < loopTo) {
53
+ if (loopIndex.index > array.length) {
54
+ break;
37
55
  }
56
+ const current = array[loopIndex.index];
57
+ if (options === null || options === void 0 ? void 0 : options.where) {
58
+ const row = isStructured ? current.get() : { table_line: current };
59
+ if ((yield __await(options.where(row))) === false) {
60
+ loopIndex.index++;
61
+ continue;
62
+ }
63
+ }
64
+ // @ts-ignore
65
+ abap.builtin.sy.get().tabix.set(loopIndex.index + 1);
66
+ entered = true;
67
+ yield yield __await(current);
68
+ loopIndex.index++;
69
+ loopTo = (options === null || options === void 0 ? void 0 : options.to) && options.to.get() < array.length ? options.to.get() : array.length;
38
70
  }
71
+ }
72
+ finally {
73
+ table.unregisterLoop(loopIndex);
39
74
  // @ts-ignore
40
- abap.builtin.sy.get().tabix.set(loopIndex.index + 1);
41
- entered = true;
42
- yield current;
43
- loopIndex.index++;
44
- loopTo = (options === null || options === void 0 ? void 0 : options.to) && options.to.get() < array.length ? options.to.get() : array.length;
75
+ abap.builtin.sy.get().subrc.set(entered ? 0 : 4);
45
76
  }
46
- }
47
- finally {
48
- table.unregisterLoop(loopIndex);
49
- // @ts-ignore
50
- abap.builtin.sy.get().subrc.set(entered ? 0 : 4);
51
- }
77
+ });
52
78
  }
53
79
  exports.loop = loop;
54
80
  //# sourceMappingURL=loop.js.map
@@ -1,27 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.replace = void 0;
4
+ function escapeRegExp(text) {
5
+ return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
6
+ }
4
7
  function replace(input) {
5
8
  let temp = input.target.get();
6
9
  const ignoreCase = input.ignoringCase === true ? "i" : "";
7
- let search = "";
10
+ const allOccurrences = input.all === true ? "g" : "";
11
+ let search = undefined;
8
12
  let found = false;
9
13
  if (input.of) {
10
- search = input.of.get();
11
- if (search.length === 0 && input.all === true) {
14
+ let inp = input.of.get();
15
+ if (inp.length === 0 && input.all === true) {
12
16
  throw "REPLACE, zero length input";
13
17
  }
14
- found = temp.indexOf(search) >= 0;
15
- if (ignoreCase.length > 0) {
16
- search = new RegExp(search, ignoreCase);
17
- }
18
+ found = temp.indexOf(inp) >= 0;
19
+ inp = escapeRegExp(inp);
20
+ search = new RegExp(inp, ignoreCase + allOccurrences);
18
21
  }
19
22
  else if (input.regex) {
20
23
  if (input.regex.get().length === 0 && input.all === true) {
21
24
  throw "REPLACE, zero length input";
22
25
  }
23
- found = temp.match(search) !== null;
24
- search = new RegExp(input.regex.get(), ignoreCase);
26
+ found = temp.match(input.regex.get()) !== null;
27
+ search = new RegExp(input.regex.get(), ignoreCase + allOccurrences);
28
+ }
29
+ else {
30
+ throw "REPLACE, unexpected input";
25
31
  }
26
32
  let replace = "";
27
33
  if (typeof input.with === "string") {
@@ -33,19 +39,7 @@ function replace(input) {
33
39
  replace = replace.replace(/\\\{/g, "{");
34
40
  replace = replace.replace(/\\\}/g, "}");
35
41
  }
36
- if (input.all === true) {
37
- if (input.regex) {
38
- temp = temp.replace(new RegExp(input.regex.get(), "g" + ignoreCase), replace);
39
- }
40
- else {
41
- while (temp.replace(search, replace) !== temp) {
42
- temp = temp.replace(search, replace);
43
- }
44
- }
45
- }
46
- else {
47
- temp = temp.replace(search, replace);
48
- }
42
+ temp = temp.replace(search, replace);
49
43
  const subrc = found ? 0 : 4;
50
44
  // @ts-ignore
51
45
  abap.builtin.sy.get().subrc.set(subrc);
package/package.json CHANGED
@@ -1,41 +1,41 @@
1
- {
2
- "name": "@abaplint/runtime",
3
- "version": "2.1.53",
4
- "description": "Transpiler - Runtime",
5
- "main": "build/src/index.js",
6
- "typings": "build/src/index.d.ts",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/abaplint/transpiler.git"
10
- },
11
- "scripts": {
12
- "compile": "tsc",
13
- "publish:major": "npm --no-git-tag-version version major && rm -rf build && npm install && npm run test && npm publish --access public",
14
- "publish:minor": "npm --no-git-tag-version version minor && rm -rf build && npm install && npm run test && npm publish --access public",
15
- "publish:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
16
- "test": "npm run compile && mocha"
17
- },
18
- "mocha": {
19
- "recursive": true,
20
- "reporter": "progress",
21
- "spec": "build/test/**/*.js",
22
- "require": "source-map-support/register"
23
- },
24
- "keywords": [
25
- "ABAP",
26
- "abaplint"
27
- ],
28
- "author": "abaplint",
29
- "license": "MIT",
30
- "devDependencies": {
31
- "@types/chai": "^4.3.3",
32
- "@types/mocha": "^9.1.1",
33
- "chai": "^4.3.6",
34
- "mocha": "^10.0.0",
35
- "source-map-support": "^0.5.21",
36
- "typescript": "^4.8.2"
37
- },
38
- "dependencies": {
39
- "temporal-polyfill": "^0.0.8"
40
- }
41
- }
1
+ {
2
+ "name": "@abaplint/runtime",
3
+ "version": "2.1.56",
4
+ "description": "Transpiler - Runtime",
5
+ "main": "build/src/index.js",
6
+ "typings": "build/src/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/abaplint/transpiler.git"
10
+ },
11
+ "scripts": {
12
+ "compile": "tsc",
13
+ "publish:major": "npm --no-git-tag-version version major && rm -rf build && npm install && npm run test && npm publish --access public",
14
+ "publish:minor": "npm --no-git-tag-version version minor && rm -rf build && npm install && npm run test && npm publish --access public",
15
+ "publish:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
16
+ "test": "npm run compile && mocha"
17
+ },
18
+ "mocha": {
19
+ "recursive": true,
20
+ "reporter": "progress",
21
+ "spec": "build/test/**/*.js",
22
+ "require": "source-map-support/register"
23
+ },
24
+ "keywords": [
25
+ "ABAP",
26
+ "abaplint"
27
+ ],
28
+ "author": "abaplint",
29
+ "license": "MIT",
30
+ "devDependencies": {
31
+ "@types/chai": "^4.3.3",
32
+ "@types/mocha": "^9.1.1",
33
+ "chai": "^4.3.6",
34
+ "mocha": "^10.0.0",
35
+ "source-map-support": "^0.5.21",
36
+ "typescript": "^4.8.3"
37
+ },
38
+ "dependencies": {
39
+ "temporal-polyfill": "^0.0.8"
40
+ }
41
+ }