@abaplint/transpiler 2.1.25 → 2.1.28

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,8 +1,8 @@
1
1
  export declare type DatabaseSetupResult = {
2
2
  schemas: {
3
- sqlite: string;
4
- pg: string;
5
- hdb: string;
3
+ sqlite: string[];
4
+ pg: string[];
5
+ hdb: string[];
6
6
  };
7
- insert: string;
7
+ insert: string[];
8
8
  };
@@ -5,6 +5,8 @@ export declare class DatabaseSetup {
5
5
  constructor(reg: abaplint.IRegistry);
6
6
  run(): DatabaseSetupResult;
7
7
  private buildInsert;
8
- private t000Insert;
9
- private messageClass;
8
+ private insertREPOSRC;
9
+ private insertT000;
10
+ private insertT100;
11
+ private escape;
10
12
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DatabaseSetup = void 0;
4
+ /* eslint-disable max-len */
4
5
  const abaplint = require("@abaplint/core");
5
6
  const sqlite_database_schema_1 = require("./sqlite_database_schema");
6
7
  class DatabaseSetup {
@@ -11,49 +12,73 @@ class DatabaseSetup {
11
12
  return {
12
13
  schemas: {
13
14
  sqlite: new sqlite_database_schema_1.SQLiteDatabaseSchema(this.reg).run(),
14
- hdb: "todo",
15
- pg: "todo",
15
+ hdb: ["todo"],
16
+ pg: ["todo"],
16
17
  },
17
18
  insert: this.buildInsert(),
18
19
  };
19
20
  }
20
21
  ////////////////////
21
22
  buildInsert() {
22
- let insert = "";
23
+ // note: avoid hitting maximum statement size by splitting into multiple statements
24
+ const insert = [];
23
25
  // INSERT data
24
26
  for (const obj of this.reg.getObjects()) {
25
27
  if (obj instanceof abaplint.Objects.MessageClass) {
26
- insert += this.messageClass(obj);
28
+ insert.push(this.insertT100(obj));
29
+ }
30
+ else if (obj instanceof abaplint.Objects.Class
31
+ || obj instanceof abaplint.Objects.Interface) {
32
+ insert.push(this.insertREPOSRC(obj));
27
33
  }
28
34
  }
29
- insert += this.t000Insert();
35
+ insert.push(this.insertT000());
30
36
  return insert;
31
37
  }
32
- t000Insert() {
33
- const obj = this.reg.getObject("TABL", "T000");
34
- if (obj === undefined) {
38
+ insertREPOSRC(obj) {
39
+ var _a;
40
+ if (this.reg.getObject("TABL", "REPOSRC") === undefined) {
41
+ return "";
42
+ }
43
+ const name = obj.getName().toUpperCase();
44
+ const raw = (_a = obj.getMainABAPFile()) === null || _a === void 0 ? void 0 : _a.getRaw();
45
+ if (raw === undefined) {
46
+ return "";
47
+ }
48
+ return `INSERT INTO reposrc ('PROGNAME', 'DATA') VALUES ('${name}', '${this.escape(raw)}');\n`;
49
+ }
50
+ insertT000() {
51
+ const tabl = this.reg.getObject("TABL", "T000");
52
+ if (tabl === undefined) {
35
53
  return "";
36
54
  }
37
- const type = obj.parseType(this.reg);
38
- if (type instanceof abaplint.BasicTypes.StructureType && type.getComponents().length === 3) {
55
+ const type = tabl.parseType(this.reg);
56
+ if (type instanceof abaplint.BasicTypes.StructureType && type.getComponents().length >= 3) {
39
57
  // todo, this should take the client number from the settings
40
- return `INSERT INTO t000 VALUES ('123', '', '');\n`;
58
+ return `INSERT INTO t000 ('MANDT', 'CCCATEGORY', 'CCNOCLIIND') VALUES ('123', '', '');\n`;
41
59
  }
42
60
  else {
43
61
  return "";
44
62
  }
45
63
  }
46
- messageClass(msag) {
64
+ insertT100(msag) {
47
65
  // ignore if T100 is unknown
48
66
  if (this.reg.getObject("TABL", "T100") === undefined) {
49
67
  return "";
50
68
  }
51
69
  let ret = "";
52
70
  for (const m of msag.getMessages()) {
53
- ret += `INSERT INTO t100 VALUES ('E', '${msag.getName()}', '${m.getNumber()}', '${m.getMessage().replace(/\'/g, "''")}');\n`;
71
+ ret += `INSERT INTO t100 ('SPRSL', 'ARBGB', 'MSGNR', 'TEXT') VALUES ('E', '${msag.getName()}', '${m.getNumber()}', '${this.escape(m.getMessage())}');\n`;
54
72
  }
55
73
  return ret;
56
74
  }
75
+ escape(value) {
76
+ let ret = value.replace(/\'/g, "''");
77
+ // statements are inside a javascript string stemplate
78
+ ret = ret.replace(/\\/g, "\\\\");
79
+ ret = ret.replace(/`/g, "\\`");
80
+ return ret;
81
+ }
57
82
  }
58
83
  exports.DatabaseSetup = DatabaseSetup;
59
84
  //# sourceMappingURL=index.js.map
@@ -2,7 +2,7 @@ import * as abaplint from "@abaplint/core";
2
2
  export declare class SQLiteDatabaseSchema {
3
3
  private readonly reg;
4
4
  constructor(reg: abaplint.IRegistry);
5
- run(): string;
5
+ run(): string[];
6
6
  private transparentTable;
7
7
  private toType;
8
8
  }
@@ -7,14 +7,15 @@ class SQLiteDatabaseSchema {
7
7
  this.reg = reg;
8
8
  }
9
9
  run() {
10
- let ret = "";
10
+ const statements = [];
11
11
  // CREATE TABLEs
12
12
  for (const obj of this.reg.getObjects()) {
13
- if (obj instanceof abaplint.Objects.Table && obj.getTableCategory() === abaplint.Objects.TableCategory.Transparent) {
14
- ret += this.transparentTable(obj);
13
+ if (obj instanceof abaplint.Objects.Table
14
+ && obj.getTableCategory() === abaplint.Objects.TableCategory.Transparent) {
15
+ statements.push(this.transparentTable(obj).trim());
15
16
  }
16
17
  }
17
- return ret.trim();
18
+ return statements;
18
19
  }
19
20
  //////////////////
20
21
  transparentTable(tabl) {
@@ -23,7 +23,10 @@ export async function initializeABAP() {\n`;
23
23
  ret += ` const hdb = \`${dbSetup.schemas.hdb}\`;\n`;
24
24
  ret += ` const pg = \`${dbSetup.schemas.pg}\`;\n`;
25
25
  ret += ` const schemas = {sqlite, hdb, pg};\n`;
26
- ret += ` const insert = \`${dbSetup.insert}\`;\n`;
26
+ ret += ` const insert = [];\n`;
27
+ for (const i of dbSetup.insert) {
28
+ ret += `insert.push(\`${i}\`);\n`;
29
+ }
27
30
  if (extraSetup === undefined) {
28
31
  ret += `// no setup logic specified in config\n`;
29
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.1.25",
3
+ "version": "2.1.28",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",