@abaplint/runtime 2.0.0 → 2.0.3

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
@@ -10,6 +10,7 @@ export * from "./escape";
10
10
  export * from "./find";
11
11
  export * from "./floor";
12
12
  export * from "./frac";
13
+ export * from "./insert";
13
14
  export * from "./lines";
14
15
  export * from "./nmax";
15
16
  export * from "./nmin";
@@ -27,6 +27,7 @@ __exportStar(require("./escape"), exports);
27
27
  __exportStar(require("./find"), exports);
28
28
  __exportStar(require("./floor"), exports);
29
29
  __exportStar(require("./frac"), exports);
30
+ __exportStar(require("./insert"), exports);
30
31
  __exportStar(require("./lines"), exports);
31
32
  __exportStar(require("./nmax"), exports);
32
33
  __exportStar(require("./nmin"), exports);
@@ -0,0 +1,9 @@
1
+ import { String } from "../types";
2
+ import { ICharacter } from "../types/_character";
3
+ import { INumeric } from "../types/_numeric";
4
+ export interface IInsertInput {
5
+ val: ICharacter;
6
+ sub: ICharacter;
7
+ off?: INumeric;
8
+ }
9
+ export declare function insert(input: IInsertInput): String;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.insert = void 0;
4
+ const types_1 = require("../types");
5
+ function insert(input) {
6
+ let offset = 0;
7
+ if (input.off) {
8
+ offset = input.off.get();
9
+ }
10
+ const value = input.val.getOffset({ offset: 0, length: offset }).get() +
11
+ input.sub.get() +
12
+ input.val.getOffset({ offset: offset }).get();
13
+ return new types_1.String().set(value);
14
+ }
15
+ exports.insert = insert;
16
+ //# sourceMappingURL=insert.js.map
@@ -34,11 +34,18 @@ function replace(input) {
34
34
  else if (input.regex) {
35
35
  sub = input.regex.get();
36
36
  }
37
- if (input.off && input.len) {
37
+ if (input.off && input.len && typeof input.val === "string") {
38
38
  const offset = input.off.get();
39
39
  const length = input.len.get();
40
40
  val = val.substring(0, offset) + wi + val.substring(offset + length);
41
41
  }
42
+ else if (input.off && input.len && !(typeof input.val === "string")) {
43
+ const offset = input.off.get();
44
+ const length = input.len.get();
45
+ val = input.val.getOffset({ offset: 0, length: offset }).get() +
46
+ wi +
47
+ input.val.getOffset({ offset: offset + length }).get();
48
+ }
42
49
  else if (input.occ === undefined && sub && wi) {
43
50
  val = val.replace(sub, wi);
44
51
  }
@@ -4,13 +4,18 @@ exports.substring = void 0;
4
4
  const string_1 = require("../types/string");
5
5
  function substring(input) {
6
6
  var _a, _b;
7
- const val = typeof input.val === "string" ? input.val : input.val.get();
8
7
  let off = (_a = input === null || input === void 0 ? void 0 : input.off) === null || _a === void 0 ? void 0 : _a.get();
9
8
  if (off === undefined) {
10
9
  off = 0;
11
10
  }
12
11
  const len = (_b = input === null || input === void 0 ? void 0 : input.len) === null || _b === void 0 ? void 0 : _b.get();
13
- const sub = val.substr(off, len);
12
+ let sub = "";
13
+ if (typeof input.val === "string") {
14
+ sub = input.val.substr(off, len);
15
+ }
16
+ else {
17
+ sub = input.val.getOffset({ offset: off, length: len }).get();
18
+ }
14
19
  return new string_1.String().set(sub);
15
20
  }
16
21
  exports.substring = substring;
@@ -20,6 +20,7 @@ exports.sy = new types_1.Structure({
20
20
  subrc: new types_1.Integer(),
21
21
  sysid: new types_1.Character({ length: 3 }).set("ABC"),
22
22
  tabix: new types_1.Integer(),
23
+ tzone: new types_1.Integer(),
23
24
  timlo: new types_1.Time(),
24
25
  uname: new types_1.Character({ length: 12 }).set("USERNAME"),
25
26
  uzeit: new types_1.Time(),
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initial = void 0;
4
4
  const types_1 = require("../types");
5
5
  function initial(val) {
6
+ // todo, refactor? add as method in each type instead?
6
7
  if (val instanceof types_1.Table) {
7
8
  return val.array().length === 0;
8
9
  }
@@ -30,6 +30,9 @@ export interface DatabaseClient {
30
30
  disconnect(): Promise<void>;
31
31
  /*** execute any native SQL command */
32
32
  execute(sql: string): Promise<void>;
33
+ beginTransaction(): Promise<void>;
34
+ commit(): Promise<void>;
35
+ rollback(): Promise<void>;
33
36
  delete(options: DeleteDatabaseOptions): Promise<{
34
37
  subrc: number;
35
38
  dbcnt: number;
@@ -39,6 +39,7 @@ class ABAP {
39
39
  builtin.sy.get().subrc.set(0);
40
40
  builtin.sy.get().tabix.set(0);
41
41
  builtin.sy.get().index.set(0);
42
+ this.statements.getTime({ sy: builtin.sy });
42
43
  }
43
44
  }
44
45
  exports.ABAP = ABAP;
@@ -55,7 +55,7 @@ class OffsetLength {
55
55
  }
56
56
  if (this.length) {
57
57
  val = val.substr(0, this.length);
58
- if (this.isHex) {
58
+ if (this.isHex || this.obj instanceof types_1.Time) {
59
59
  val = val.padStart(this.length, "0");
60
60
  }
61
61
  }
@@ -1,3 +1,4 @@
1
+ import { Float, Integer } from "../types";
1
2
  import { ICharacter } from "../types/_character";
2
3
  import { INumeric } from "../types/_numeric";
3
- export declare function parse(val: INumeric | ICharacter | string | number): number;
4
+ export declare function parse(val: INumeric | ICharacter | string | number | Float | Integer): number;
@@ -1,4 +1,4 @@
1
- import { Float, Integer } from "../types";
1
+ import { Float, Hex, Integer } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
- export declare function add(left: INumeric | ICharacter | string | number, right: INumeric | ICharacter | string | number): Float | Integer;
4
+ export declare function add(left: INumeric | ICharacter | string | number | Float | Integer | Hex, right: INumeric | ICharacter | string | number | Float | Integer | Hex): Float | Integer;
@@ -1,4 +1,4 @@
1
1
  import { Float, Integer } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
- export declare function minus(left: INumeric | ICharacter | string | number, right: INumeric | ICharacter | string | number): Float | Integer;
4
+ export declare function minus(left: INumeric | ICharacter | string | number | Integer | Float, right: INumeric | ICharacter | string | number | Integer | Float): Float | Integer;
@@ -1,7 +1,9 @@
1
+ import { Structure } from "../types";
1
2
  import { ICharacter } from "../types/_character";
2
3
  declare type options = {
3
4
  field?: ICharacter;
4
5
  stamp?: ICharacter;
6
+ sy?: Structure;
5
7
  };
6
8
  export declare function getTime(options?: options): void;
7
9
  export {};
@@ -9,14 +9,17 @@ function getTime(options) {
9
9
  const time = (d.getUTCHours() + "").padStart(2, "0") +
10
10
  (d.getUTCMinutes() + "").padStart(2, "0") +
11
11
  (d.getUTCSeconds() + "").padStart(2, "0");
12
- // @ts-ignore
13
- abap.builtin.sy.get().datlo.set(date);
14
- // @ts-ignore
15
- abap.builtin.sy.get().datum.set(date);
16
- // @ts-ignore
17
- abap.builtin.sy.get().timlo.set(time);
18
- // @ts-ignore
19
- abap.builtin.sy.get().uzeit.set(time);
12
+ if (options === undefined) {
13
+ options = {};
14
+ }
15
+ if ((options === null || options === void 0 ? void 0 : options.sy) === undefined) {
16
+ // @ts-ignore
17
+ options.sy = abap.builtin.sy;
18
+ }
19
+ options.sy.get().datlo.set(date);
20
+ options.sy.get().datum.set(date);
21
+ options.sy.get().timlo.set(time);
22
+ options.sy.get().uzeit.set(time);
20
23
  if (options === null || options === void 0 ? void 0 : options.field) {
21
24
  options.field.set(time);
22
25
  }
@@ -47,13 +47,11 @@ function shift_character_mode(target, options) {
47
47
  value = value.substr(index);
48
48
  }
49
49
  }
50
+ else if (options === null || options === void 0 ? void 0 : options.circular) {
51
+ value = value.substr(1) + value.substr(0, 1);
52
+ }
50
53
  else {
51
- if (options === null || options === void 0 ? void 0 : options.circular) {
52
- value = value.substr(1) + value.substr(0, 1);
53
- }
54
- else {
55
- value = value.substr(1);
56
- }
54
+ value = value.substr(1);
57
55
  }
58
56
  target.set(value);
59
57
  }
@@ -91,6 +89,12 @@ function shift_byte_mode(target, options) {
91
89
  value = value.substr(index);
92
90
  }
93
91
  }
92
+ else if (options === null || options === void 0 ? void 0 : options.circular) {
93
+ value = value.substr(2) + value.substr(0, 2);
94
+ }
95
+ else {
96
+ value = value.substr(2);
97
+ }
94
98
  target.set(value);
95
99
  }
96
100
  //# sourceMappingURL=shift.js.map
@@ -7,6 +7,7 @@ declare type options = {
7
7
  pad?: string;
8
8
  width?: number;
9
9
  decimals?: number;
10
+ align?: "left" | "right";
10
11
  };
11
12
  export declare function templateFormatting(source: ICharacter | INumeric, options: options): string;
12
13
  export {};
@@ -14,7 +14,12 @@ function templateFormatting(source, options) {
14
14
  text = text.substr(0, 2) + ":" + text.substr(2, 2) + ":" + text.substr(4, 2);
15
15
  }
16
16
  if (options.width && options.pad) {
17
- text = text.trimEnd().padEnd(options.width, options.pad);
17
+ if (options.align === "right") {
18
+ text = text.trimEnd().padStart(options.width, options.pad);
19
+ }
20
+ else {
21
+ text = text.trimEnd().padEnd(options.width, options.pad);
22
+ }
18
23
  }
19
24
  else if (options.width) {
20
25
  text = text.trimEnd().padEnd(options.width, " ");
@@ -2,4 +2,8 @@ export interface ICharacter {
2
2
  set(value: ICharacter | string): void;
3
3
  get(): string;
4
4
  clear(): void;
5
+ getOffset(input: {
6
+ offset?: number;
7
+ length?: number;
8
+ }): ICharacter;
5
9
  }
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Character = void 0;
4
4
  class Character {
5
5
  constructor(input) {
6
- this.value = "";
7
6
  this.length = (input === null || input === void 0 ? void 0 : input.length) ? input === null || input === void 0 ? void 0 : input.length : 1;
7
+ if (this.length <= 0) {
8
+ throw "Character, invalid length";
9
+ }
8
10
  this.qualifiedName = input === null || input === void 0 ? void 0 : input.qualifiedName;
11
+ this.clear();
9
12
  }
10
13
  set(value) {
11
14
  if (typeof value === "string" || typeof value === "number") {
@@ -16,6 +19,9 @@ class Character {
16
19
  }
17
20
  if (this.value.length > this.length) {
18
21
  this.value = this.value.substr(0, this.length);
22
+ // todo, maintain consistent length
23
+ // } else if (this.value.length < this.length) {
24
+ // this.value.padEnd(this.length, " ");
19
25
  }
20
26
  return this;
21
27
  }
@@ -26,12 +32,24 @@ class Character {
26
32
  return this.length;
27
33
  }
28
34
  clear() {
35
+ // todo, maintain consistent length
36
+ // this.value = " ".repeat(this.length);
29
37
  this.value = "";
30
38
  }
31
39
  get() {
32
40
  return this.value;
33
41
  }
34
42
  getOffset(input) {
43
+ if (input.offset && input.offset >= this.length) {
44
+ // @ts-ignore
45
+ if (abap.Classes["CX_SY_RANGE_OUT_OF_BOUNDS"] !== undefined) {
46
+ // @ts-ignore
47
+ throw new abap.Classes["CX_SY_RANGE_OUT_OF_BOUNDS"]();
48
+ }
49
+ else {
50
+ throw "Global class CX_SY_RANGE_OUT_OF_BOUNDS not found";
51
+ }
52
+ }
35
53
  let ret = this.value;
36
54
  if (input === null || input === void 0 ? void 0 : input.offset) {
37
55
  ret = ret.substr(input.offset);
@@ -1,3 +1,5 @@
1
+ import { Float } from "./float";
2
+ import { Integer } from "./integer";
1
3
  import { XString } from "./xstring";
2
4
  import { ICharacter } from "./_character";
3
5
  import { INumeric } from "./_numeric";
@@ -7,7 +9,7 @@ export declare class Hex implements ICharacter {
7
9
  constructor(input?: {
8
10
  length?: number;
9
11
  });
10
- set(value: ICharacter | INumeric | string | number): void;
12
+ set(value: ICharacter | INumeric | string | number | Integer | Float): void;
11
13
  getLength(): number;
12
14
  clear(): void;
13
15
  get(): string;
@@ -1,10 +1,11 @@
1
+ import { Float } from "./float";
1
2
  import { Hex } from "./hex";
2
3
  import { ICharacter } from "./_character";
3
4
  import { INumeric } from "./_numeric";
4
5
  export declare class Integer implements INumeric {
5
6
  private value;
6
7
  constructor();
7
- set(value: INumeric | ICharacter | Hex | string | number): this;
8
+ set(value: INumeric | ICharacter | Hex | string | number | Integer | Float): this;
8
9
  clear(): void;
9
10
  get(): number;
10
11
  }
@@ -11,4 +11,8 @@ export declare class Numc implements ICharacter {
11
11
  getLength(): number;
12
12
  clear(): void;
13
13
  get(): string;
14
+ getOffset(_input: {
15
+ offset?: number;
16
+ length?: number;
17
+ }): Numc;
14
18
  }
@@ -37,6 +37,9 @@ class Numc {
37
37
  get() {
38
38
  return this.value;
39
39
  }
40
+ getOffset(_input) {
41
+ throw "todo, runtime, numc getOffset()";
42
+ }
40
43
  }
41
44
  exports.Numc = Numc;
42
45
  //# sourceMappingURL=numc.js.map
@@ -34,6 +34,16 @@ class String {
34
34
  return this.value;
35
35
  }
36
36
  getOffset(input) {
37
+ if (input.offset && input.offset > this.value.length) {
38
+ // @ts-ignore
39
+ if (abap.Classes["CX_SY_RANGE_OUT_OF_BOUNDS"] !== undefined) {
40
+ // @ts-ignore
41
+ throw new abap.Classes["CX_SY_RANGE_OUT_OF_BOUNDS"]();
42
+ }
43
+ else {
44
+ throw "Global class CX_SY_RANGE_OUT_OF_BOUNDS not found";
45
+ }
46
+ }
37
47
  let ret = this.value;
38
48
  if (input === null || input === void 0 ? void 0 : input.offset) {
39
49
  ret = ret.substr(input.offset);
package/package.json CHANGED
@@ -1,39 +1,39 @@
1
- {
2
- "name": "@abaplint/runtime",
3
- "version": "2.0.0",
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.0",
32
- "@types/mocha": "^9.1.0",
33
- "@types/sql.js": "^1.4.3",
34
- "chai": "^4.3.6",
35
- "mocha": "^9.2.2",
36
- "source-map-support": "^0.5.21",
37
- "typescript": "^4.6.3"
38
- }
39
- }
1
+ {
2
+ "name": "@abaplint/runtime",
3
+ "version": "2.0.3",
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.0",
32
+ "@types/mocha": "^9.1.0",
33
+ "@types/sql.js": "^1.4.3",
34
+ "chai": "^4.3.6",
35
+ "mocha": "^9.2.2",
36
+ "source-map-support": "^0.5.21",
37
+ "typescript": "^4.6.3"
38
+ }
39
+ }