@abaplint/transpiler 2.1.91 → 2.2.0

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.
@@ -3,6 +3,7 @@ export declare class SQLiteDatabaseSchema {
3
3
  private readonly reg;
4
4
  constructor(reg: abaplint.IRegistry);
5
5
  run(): string[];
6
- private transparentTable;
6
+ private buildVIEW;
7
+ private buildTABL;
7
8
  private toType;
8
9
  }
@@ -12,13 +12,38 @@ class SQLiteDatabaseSchema {
12
12
  for (const obj of this.reg.getObjects()) {
13
13
  if (obj instanceof abaplint.Objects.Table
14
14
  && obj.getTableCategory() === abaplint.Objects.TableCategory.Transparent) {
15
- statements.push(this.transparentTable(obj).trim());
15
+ statements.push(this.buildTABL(obj).trim());
16
+ }
17
+ else if (obj instanceof abaplint.Objects.View) {
18
+ statements.push(this.buildVIEW(obj).trim());
16
19
  }
17
20
  }
18
21
  return statements;
19
22
  }
20
23
  //////////////////
21
- transparentTable(tabl) {
24
+ // https://www.sqlite.org/lang_createview.html
25
+ buildVIEW(view) {
26
+ // @ts-ignore
27
+ const fields = view.parsedData.fields; // todo, call method introduced in https://github.com/abaplint/abaplint/pull/2714
28
+ const columns = fields.map((f) => f.TABNAME.toLowerCase() + "." + f.FIELDNAME.toLowerCase() + " AS " + f.VIEWFIELD.toLowerCase()).join(", ");
29
+ let from = "";
30
+ let previous = "";
31
+ for (const j of view.getJoin() || []) {
32
+ if (previous === "") {
33
+ from += j.LTAB.toLowerCase() + " INNER JOIN " + j.RTAB.toLowerCase() + " ON " + j.LTAB.toLowerCase() + "." + j.LFIELD.toLowerCase() + " = " + j.RTAB.toLowerCase() + "." + j.RFIELD.toLowerCase();
34
+ }
35
+ else if (previous === j.LTAB + "," + j.RTAB) {
36
+ from += " AND " + j.LTAB.toLowerCase() + "." + j.LFIELD.toLowerCase() + " = " + j.RTAB.toLowerCase() + "." + j.RFIELD.toLowerCase();
37
+ }
38
+ else {
39
+ from += " INNER JOIN " + j.RTAB.toLowerCase() + " ON " + j.LTAB.toLowerCase() + "." + j.LFIELD.toLowerCase() + " = " + j.RTAB.toLowerCase() + "." + j.RFIELD.toLowerCase();
40
+ }
41
+ previous = j.LTAB + "," + j.RTAB;
42
+ }
43
+ from = from.trim();
44
+ return `CREATE VIEW ${view.getName().toLowerCase()} AS SELECT ${columns} FROM ${from};\n`;
45
+ }
46
+ buildTABL(tabl) {
22
47
  const type = tabl.parseType(this.reg);
23
48
  if (!(type instanceof abaplint.BasicTypes.StructureType)) {
24
49
  return "";
@@ -32,7 +57,7 @@ class SQLiteDatabaseSchema {
32
57
  const key = ", PRIMARY KEY(" + tabl.listKeys().map(e => "'" + e.toLowerCase() + "'").join(",") + ")";
33
58
  return `CREATE TABLE ${tabl.getName().toLowerCase()} (${fields.join(", ")}${key});\n`;
34
59
  }
35
- toType(type, fieldname, table) {
60
+ toType(type, fieldname, errorInfo) {
36
61
  if (type instanceof abaplint.BasicTypes.CharacterType) {
37
62
  return `NCHAR(${type.getLength()})`;
38
63
  }
@@ -67,10 +92,10 @@ class SQLiteDatabaseSchema {
67
92
  return `DECIMAL(${type.getLength()},${type.getDecimals()})`;
68
93
  }
69
94
  else if (type instanceof abaplint.BasicTypes.VoidType) {
70
- throw `Type of ${table}-${fieldname} is VoidType(${type.getVoided()}), make sure the type is known, enable strict syntax checking`;
95
+ throw `Type of ${errorInfo}-${fieldname} is VoidType(${type.getVoided()}), make sure the type is known, enable strict syntax checking`;
71
96
  }
72
97
  else {
73
- throw "database_setup: " + table + "-" + fieldname + ", todo toType handle: " + type.constructor.name;
98
+ throw "database_setup: " + errorInfo + "-" + fieldname + ", todo toType handle: " + type.constructor.name;
74
99
  }
75
100
  }
76
101
  }
@@ -1,6 +1,6 @@
1
1
  import * as abaplint from "@abaplint/core";
2
- import { IOutputFile, ITranspilerOptions } from "./types";
3
- import { Chunk } from "./chunk";
2
+ import { IOutputFile, ITranspilerOptions } from "../types";
3
+ import { Chunk } from "../chunk";
4
4
  export declare class HandleABAP {
5
5
  private readonly options;
6
6
  constructor(options?: ITranspilerOptions);
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HandleABAP = void 0;
4
4
  const abaplint = require("@abaplint/core");
5
- const traversal_1 = require("./traversal");
6
- const requires_1 = require("./requires");
7
- const rearranger_1 = require("./rearranger");
8
- const chunk_1 = require("./chunk");
5
+ const traversal_1 = require("../traversal");
6
+ const requires_1 = require("../requires");
7
+ const rearranger_1 = require("../rearranger");
8
+ const chunk_1 = require("../chunk");
9
9
  class HandleABAP {
10
10
  constructor(options) {
11
11
  this.options = options;
@@ -1,5 +1,5 @@
1
1
  import * as abaplint from "@abaplint/core";
2
- import { IOutputFile } from "./types";
2
+ import { IOutputFile } from "../types";
3
3
  export declare class HandleDataElement {
4
4
  runObject(obj: abaplint.Objects.DataElement, reg: abaplint.IRegistry): IOutputFile[];
5
5
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HandleDataElement = void 0;
4
- const chunk_1 = require("./chunk");
5
- const transpile_types_1 = require("./transpile_types");
4
+ const chunk_1 = require("../chunk");
5
+ const transpile_types_1 = require("../transpile_types");
6
6
  class HandleDataElement {
7
7
  runObject(obj, reg) {
8
8
  var _a;
@@ -1,5 +1,5 @@
1
1
  import * as abaplint from "@abaplint/core";
2
- import { IOutputFile } from "./types";
2
+ import { IOutputFile } from "../types";
3
3
  export declare class HandleTable {
4
4
  runObject(obj: abaplint.Objects.Table, reg: abaplint.IRegistry): IOutputFile[];
5
5
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HandleTable = void 0;
4
- const chunk_1 = require("./chunk");
5
- const transpile_types_1 = require("./transpile_types");
4
+ const chunk_1 = require("../chunk");
5
+ const transpile_types_1 = require("../transpile_types");
6
6
  // tables or structures
7
7
  class HandleTable {
8
8
  runObject(obj, reg) {
@@ -1,5 +1,5 @@
1
1
  import * as abaplint from "@abaplint/core";
2
- import { IOutputFile } from "./types";
2
+ import { IOutputFile } from "../types";
3
3
  export declare class HandleTableType {
4
4
  runObject(obj: abaplint.Objects.TableType, reg: abaplint.IRegistry): IOutputFile[];
5
5
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HandleTableType = void 0;
4
- const chunk_1 = require("./chunk");
5
- const transpile_types_1 = require("./transpile_types");
4
+ const chunk_1 = require("../chunk");
5
+ const transpile_types_1 = require("../transpile_types");
6
6
  class HandleTableType {
7
7
  runObject(obj, reg) {
8
8
  var _a;
@@ -0,0 +1,5 @@
1
+ import * as abaplint from "@abaplint/core";
2
+ import { IOutputFile } from "../types";
3
+ export declare class HandleView {
4
+ runObject(obj: abaplint.Objects.View, reg: abaplint.IRegistry): IOutputFile[];
5
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HandleView = void 0;
4
+ const chunk_1 = require("../chunk");
5
+ const transpile_types_1 = require("../transpile_types");
6
+ // view, much like the tables
7
+ class HandleView {
8
+ runObject(obj, reg) {
9
+ var _a;
10
+ const filename = (_a = obj.getXMLFile()) === null || _a === void 0 ? void 0 : _a.getFilename().replace(".xml", ".mjs").toLowerCase();
11
+ if (filename === undefined) {
12
+ return [];
13
+ }
14
+ const type = obj.parseType(reg);
15
+ const chunk = new chunk_1.Chunk().appendString(`abap.DDIC["${obj.getName().toUpperCase()}"] = {
16
+ "objectType": "VIEW",
17
+ "type": ${new transpile_types_1.TranspileTypes().toType(type)},
18
+ };`);
19
+ // todo, "keyFields": ${JSON.stringify(obj.listKeys())},
20
+ const output = {
21
+ object: {
22
+ name: obj.getName(),
23
+ type: obj.getType(),
24
+ },
25
+ filename: filename,
26
+ chunk: chunk,
27
+ requires: [],
28
+ exports: [],
29
+ };
30
+ return [output];
31
+ }
32
+ }
33
+ exports.HandleView = HandleView;
34
+ //# sourceMappingURL=handle_view.js.map
@@ -6,11 +6,12 @@ const validation_1 = require("./validation");
6
6
  Object.defineProperty(exports, "config", { enumerable: true, get: function () { return validation_1.config; } });
7
7
  const unit_test_1 = require("./unit_test");
8
8
  const keywords_1 = require("./keywords");
9
- const handle_table_1 = require("./handle_table");
10
- const handle_abap_1 = require("./handle_abap");
11
- const handle_data_element_1 = require("./handle_data_element");
12
- const handle_table_type_1 = require("./handle_table_type");
13
9
  const db_1 = require("./db");
10
+ const handle_table_1 = require("./handlers/handle_table");
11
+ const handle_abap_1 = require("./handlers/handle_abap");
12
+ const handle_data_element_1 = require("./handlers/handle_data_element");
13
+ const handle_table_type_1 = require("./handlers/handle_table_type");
14
+ const handle_view_1 = require("./handlers/handle_view");
14
15
  class Transpiler {
15
16
  constructor(options) {
16
17
  this.options = options;
@@ -59,6 +60,9 @@ class Transpiler {
59
60
  else if (obj instanceof abaplint.Objects.Table) {
60
61
  output.objects.push(...new handle_table_1.HandleTable().runObject(obj, reg));
61
62
  }
63
+ else if (obj instanceof abaplint.Objects.View) {
64
+ output.objects.push(...new handle_view_1.HandleView().runObject(obj, reg));
65
+ }
62
66
  else if (obj instanceof abaplint.Objects.DataElement) {
63
67
  output.objects.push(...new handle_data_element_1.HandleDataElement().runObject(obj, reg));
64
68
  }
@@ -257,8 +257,6 @@ class Traversal {
257
257
  ret += `await super.constructor_(INPUT);\n`;
258
258
  }
259
259
  const cName = Traversal.escapeClassName(def.getName().toLowerCase());
260
- ret += "this.INTERNAL_TYPE = " + cName + ".INTERNAL_TYPE;\n";
261
- ret += "this.IMPLEMENTED_INTERFACES = " + cName + ".IMPLEMENTED_INTERFACES;\n";
262
260
  ret += "this.me = new abap.types.ABAPObject();\n";
263
261
  ret += "this.me.set(this);\n";
264
262
  for (const a of def.getAttributes().getAll()) {
@@ -28,7 +28,7 @@ exports.config = {
28
28
  },
29
29
  "parser_error": true,
30
30
  "allowed_object_types": {
31
- "allowed": ["INTF", "CLAS", "PROG", "DEVC", "TABL", "SHLP", "XSLT", "SHMA", "SICF", "NROB", "TYPE", "DTEL", "DOMA", "TTYP", "MSAG", "FUGR"],
31
+ "allowed": ["INTF", "CLAS", "PROG", "DEVC", "TABL", "SHLP", "VIEW", "XSLT", "SHMA", "SICF", "NROB", "TYPE", "DTEL", "DOMA", "TTYP", "MSAG", "FUGR"],
32
32
  },
33
33
  /*
34
34
  "exit_or_check": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.1.91",
3
+ "version": "2.2.0",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "author": "abaplint",
29
29
  "license": "MIT",
30
30
  "dependencies": {
31
- "@abaplint/core": "^2.93.33",
31
+ "@abaplint/core": "^2.93.34",
32
32
  "source-map": "^0.7.4"
33
33
  },
34
34
  "devDependencies": {