@odata2ts/odata2ts 0.36.3 → 0.37.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.
Files changed (132) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/lib/FactoryFunctionModel.d.ts +5 -5
  3. package/lib/FactoryFunctionModel.js +1 -2
  4. package/lib/FactoryFunctionModel.js.map +1 -1
  5. package/lib/NamingModel.js +2 -5
  6. package/lib/NamingModel.js.map +1 -1
  7. package/lib/OptionModel.d.ts +2 -2
  8. package/lib/OptionModel.js +4 -7
  9. package/lib/OptionModel.js.map +1 -1
  10. package/lib/TypeModel.js +2 -5
  11. package/lib/TypeModel.js.map +1 -1
  12. package/lib/app.d.ts +2 -2
  13. package/lib/app.js +23 -27
  14. package/lib/app.js.map +1 -1
  15. package/lib/cli/cli.d.ts +1 -0
  16. package/lib/cli/cli.js +27 -0
  17. package/lib/cli/cli.js.map +1 -0
  18. package/lib/cli/index.d.ts +4 -0
  19. package/lib/cli/index.js +5 -0
  20. package/lib/cli/index.js.map +1 -0
  21. package/lib/cli/processCliArgs.d.ts +2 -0
  22. package/lib/cli/processCliArgs.js +57 -0
  23. package/lib/cli/processCliArgs.js.map +1 -0
  24. package/lib/cli/processConfigFile.d.ts +2 -0
  25. package/lib/cli/processConfigFile.js +24 -0
  26. package/lib/cli/processConfigFile.js.map +1 -0
  27. package/lib/cli/serviceGenerationRun.d.ts +2 -0
  28. package/lib/cli/serviceGenerationRun.js +77 -0
  29. package/lib/cli/serviceGenerationRun.js.map +1 -0
  30. package/lib/data-model/DataModel.d.ts +2 -2
  31. package/lib/data-model/DataModel.js +5 -10
  32. package/lib/data-model/DataModel.js.map +1 -1
  33. package/lib/data-model/DataModelDigestion.d.ts +10 -10
  34. package/lib/data-model/DataModelDigestion.js +19 -23
  35. package/lib/data-model/DataModelDigestion.js.map +1 -1
  36. package/lib/data-model/DataModelDigestionV2.d.ts +2 -2
  37. package/lib/data-model/DataModelDigestionV2.js +27 -31
  38. package/lib/data-model/DataModelDigestionV2.js.map +1 -1
  39. package/lib/data-model/DataModelDigestionV4.d.ts +2 -2
  40. package/lib/data-model/DataModelDigestionV4.js +31 -35
  41. package/lib/data-model/DataModelDigestionV4.js.map +1 -1
  42. package/lib/data-model/DataTypeModel.d.ts +1 -1
  43. package/lib/data-model/DataTypeModel.js +2 -5
  44. package/lib/data-model/DataTypeModel.js.map +1 -1
  45. package/lib/data-model/NamingHelper.d.ts +2 -2
  46. package/lib/data-model/NamingHelper.js +12 -19
  47. package/lib/data-model/NamingHelper.js.map +1 -1
  48. package/lib/data-model/ServiceConfigHelper.d.ts +3 -3
  49. package/lib/data-model/ServiceConfigHelper.js +18 -22
  50. package/lib/data-model/ServiceConfigHelper.js.map +1 -1
  51. package/lib/data-model/edmx/ODataEdmxModelBase.js +1 -2
  52. package/lib/data-model/edmx/ODataEdmxModelV3.d.ts +1 -1
  53. package/lib/data-model/edmx/ODataEdmxModelV3.js +1 -2
  54. package/lib/data-model/edmx/ODataEdmxModelV3.js.map +1 -1
  55. package/lib/data-model/edmx/ODataEdmxModelV4.d.ts +1 -1
  56. package/lib/data-model/edmx/ODataEdmxModelV4.js +1 -2
  57. package/lib/data-model/edmx/ODataEdmxModelV4.js.map +1 -1
  58. package/lib/data-model/validation/NameClashValidator.d.ts +2 -2
  59. package/lib/data-model/validation/NameClashValidator.js +10 -14
  60. package/lib/data-model/validation/NameClashValidator.js.map +1 -1
  61. package/lib/data-model/validation/NameValidator.d.ts +1 -1
  62. package/lib/data-model/validation/NameValidator.js +1 -2
  63. package/lib/data-model/validation/NameValidator.js.map +1 -1
  64. package/lib/data-model/validation/NoopValidator.d.ts +1 -1
  65. package/lib/data-model/validation/NoopValidator.js +1 -5
  66. package/lib/data-model/validation/NoopValidator.js.map +1 -1
  67. package/lib/defaultConfig.d.ts +1 -1
  68. package/lib/defaultConfig.js +21 -26
  69. package/lib/defaultConfig.js.map +1 -1
  70. package/lib/download/downloadMetadata.d.ts +1 -1
  71. package/lib/download/downloadMetadata.js +6 -10
  72. package/lib/download/downloadMetadata.js.map +1 -1
  73. package/lib/download/index.d.ts +2 -2
  74. package/lib/download/index.js +2 -7
  75. package/lib/download/index.js.map +1 -1
  76. package/lib/download/storeMetadata.js +15 -17
  77. package/lib/download/storeMetadata.js.map +1 -1
  78. package/lib/evaluateConfig.d.ts +1 -1
  79. package/lib/evaluateConfig.js +14 -18
  80. package/lib/evaluateConfig.js.map +1 -1
  81. package/lib/generator/ImportContainer.d.ts +2 -2
  82. package/lib/generator/ImportContainer.js +17 -22
  83. package/lib/generator/ImportContainer.js.map +1 -1
  84. package/lib/generator/ImportedNameValidator.js +1 -5
  85. package/lib/generator/ImportedNameValidator.js.map +1 -1
  86. package/lib/generator/ModelGenerator.d.ts +1 -1
  87. package/lib/generator/ModelGenerator.js +8 -12
  88. package/lib/generator/ModelGenerator.js.map +1 -1
  89. package/lib/generator/QueryObjectGenerator.d.ts +1 -1
  90. package/lib/generator/QueryObjectGenerator.js +25 -29
  91. package/lib/generator/QueryObjectGenerator.js.map +1 -1
  92. package/lib/generator/ServiceGenerator.d.ts +4 -4
  93. package/lib/generator/ServiceGenerator.js +52 -56
  94. package/lib/generator/ServiceGenerator.js.map +1 -1
  95. package/lib/generator/import/ImportObjects.js +11 -14
  96. package/lib/generator/import/ImportObjects.js.map +1 -1
  97. package/lib/generator/index.d.ts +3 -3
  98. package/lib/generator/index.js +3 -9
  99. package/lib/generator/index.js.map +1 -1
  100. package/lib/index.d.ts +4 -4
  101. package/lib/index.js +4 -7
  102. package/lib/index.js.map +1 -1
  103. package/lib/project/FileHandler.d.ts +3 -3
  104. package/lib/project/FileHandler.js +12 -16
  105. package/lib/project/FileHandler.js.map +1 -1
  106. package/lib/project/ProjectManager.d.ts +5 -5
  107. package/lib/project/ProjectManager.js +25 -32
  108. package/lib/project/ProjectManager.js.map +1 -1
  109. package/lib/project/TsMorphHelper.d.ts +1 -1
  110. package/lib/project/TsMorphHelper.js +21 -22
  111. package/lib/project/TsMorphHelper.js.map +1 -1
  112. package/lib/project/formatter/BaseFormatter.d.ts +1 -1
  113. package/lib/project/formatter/BaseFormatter.js +1 -5
  114. package/lib/project/formatter/BaseFormatter.js.map +1 -1
  115. package/lib/project/formatter/FileFormatter.js +1 -2
  116. package/lib/project/formatter/NoopFormatter.d.ts +1 -1
  117. package/lib/project/formatter/NoopFormatter.js +5 -9
  118. package/lib/project/formatter/NoopFormatter.js.map +1 -1
  119. package/lib/project/formatter/PrettierFormatter.d.ts +1 -1
  120. package/lib/project/formatter/PrettierFormatter.js +20 -25
  121. package/lib/project/formatter/PrettierFormatter.js.map +1 -1
  122. package/lib/project/formatter/index.d.ts +1 -1
  123. package/lib/project/formatter/index.js +6 -10
  124. package/lib/project/formatter/index.js.map +1 -1
  125. package/lib/project/logger/logFilePath.js +4 -9
  126. package/lib/project/logger/logFilePath.js.map +1 -1
  127. package/lib/run-cli.js +2 -4
  128. package/lib/run-cli.js.map +1 -1
  129. package/package.json +53 -63
  130. package/lib/cli.d.ts +0 -3
  131. package/lib/cli.js +0 -176
  132. package/lib/cli.js.map +0 -1
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NoopFormatter = void 0;
4
- const tslib_1 = require("tslib");
5
- const BaseFormatter_1 = require("./BaseFormatter");
1
+ import { __awaiter } from "tslib";
2
+ import { BaseFormatter } from "./BaseFormatter.js";
6
3
  /**
7
4
  * Prettier formatter.
8
5
  *
@@ -12,7 +9,7 @@ const BaseFormatter_1 = require("./BaseFormatter");
12
9
  * @class NoopFormatter
13
10
  * @extends {Formatter}
14
11
  */
15
- class NoopFormatter extends BaseFormatter_1.BaseFormatter {
12
+ export class NoopFormatter extends BaseFormatter {
16
13
  /**
17
14
  * Initializes the formatter.
18
15
  *
@@ -21,7 +18,7 @@ class NoopFormatter extends BaseFormatter_1.BaseFormatter {
21
18
  * @memberof Formatter
22
19
  */
23
20
  init() {
24
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
21
+ return __awaiter(this, void 0, void 0, function* () {
25
22
  return this;
26
23
  });
27
24
  }
@@ -34,10 +31,9 @@ class NoopFormatter extends BaseFormatter_1.BaseFormatter {
34
31
  * @memberof Formatter
35
32
  */
36
33
  format(source) {
37
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
34
+ return __awaiter(this, void 0, void 0, function* () {
38
35
  return source;
39
36
  });
40
37
  }
41
38
  }
42
- exports.NoopFormatter = NoopFormatter;
43
39
  //# sourceMappingURL=NoopFormatter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NoopFormatter.js","sourceRoot":"","sources":["../../../src/project/formatter/NoopFormatter.ts"],"names":[],"mappings":";;;;AAAA,mDAAgD;AAEhD;;;;;;;;GAQG;AACH,MAAa,aAAc,SAAQ,6BAAa;IAC9C;;;;;;OAMG;IACU,IAAI;;YACf,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAED;;;;;;;OAOG;IACU,MAAM,CAAC,MAAc;;YAChC,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF;AAvBD,sCAuBC","sourcesContent":["import { BaseFormatter } from \"./BaseFormatter\";\r\n\r\n/**\r\n * Prettier formatter.\r\n *\r\n * NOTE: Should be created like this => const formatter = await new NoopFormatter(\"./test.ts\").init();\r\n *\r\n * @export\r\n * @class NoopFormatter\r\n * @extends {Formatter}\r\n */\r\nexport class NoopFormatter extends BaseFormatter {\r\n /**\r\n * Initializes the formatter.\r\n *\r\n * @abstract\r\n * @returns {Promise<Formatter>} Initialized formatter\r\n * @memberof Formatter\r\n */\r\n public async init(): Promise<BaseFormatter> {\r\n return this;\r\n }\r\n\r\n /**\r\n * Formats a given source code.\r\n *\r\n * @abstract\r\n * @param {string} source Source code to format\r\n * @returns {string} Formatted source code\r\n * @memberof Formatter\r\n */\r\n public async format(source: string): Promise<string> {\r\n return source;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"NoopFormatter.js","sourceRoot":"","sources":["../../../src/project/formatter/NoopFormatter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;;;;;;GAQG;AACH,MAAM,OAAO,aAAc,SAAQ,aAAa;IAC9C;;;;;;OAMG;IACU,IAAI;;YACf,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAED;;;;;;;OAOG;IACU,MAAM,CAAC,MAAc;;YAChC,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF","sourcesContent":["import { BaseFormatter } from \"./BaseFormatter.js\";\r\n\r\n/**\r\n * Prettier formatter.\r\n *\r\n * NOTE: Should be created like this => const formatter = await new NoopFormatter(\"./test.ts\").init();\r\n *\r\n * @export\r\n * @class NoopFormatter\r\n * @extends {Formatter}\r\n */\r\nexport class NoopFormatter extends BaseFormatter {\r\n /**\r\n * Initializes the formatter.\r\n *\r\n * @abstract\r\n * @returns {Promise<Formatter>} Initialized formatter\r\n * @memberof Formatter\r\n */\r\n public async init(): Promise<BaseFormatter> {\r\n return this;\r\n }\r\n\r\n /**\r\n * Formats a given source code.\r\n *\r\n * @abstract\r\n * @param {string} source Source code to format\r\n * @returns {string} Formatted source code\r\n * @memberof Formatter\r\n */\r\n public async format(source: string): Promise<string> {\r\n return source;\r\n }\r\n}\r\n"]}
@@ -1,4 +1,4 @@
1
- import { BaseFormatter } from "./BaseFormatter";
1
+ import { BaseFormatter } from "./BaseFormatter.js";
2
2
  export declare class PrettierFormatter extends BaseFormatter {
3
3
  /**
4
4
  * Prettier options found in the project.
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PrettierFormatter = void 0;
4
- const tslib_1 = require("tslib");
5
- const prettier_1 = tslib_1.__importDefault(require("prettier"));
6
- const ts_morph_1 = require("ts-morph");
7
- const BaseFormatter_1 = require("./BaseFormatter");
8
- class PrettierFormatter extends BaseFormatter_1.BaseFormatter {
1
+ import { __awaiter } from "tslib";
2
+ import prettier from "prettier";
3
+ import { IndentationText, NewLineKind, QuoteKind } from "ts-morph";
4
+ import { BaseFormatter } from "./BaseFormatter.js";
5
+ export class PrettierFormatter extends BaseFormatter {
9
6
  /**
10
7
  * Initializes the formatter.
11
8
  *
@@ -13,22 +10,21 @@ class PrettierFormatter extends BaseFormatter_1.BaseFormatter {
13
10
  * @memberof PrettierFormatter
14
11
  */
15
12
  init() {
16
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
17
- const options = yield prettier_1.default.resolveConfig(this.output);
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ const options = yield prettier.resolveConfig(this.output);
18
15
  if (options) {
19
16
  this.options = options;
20
17
  this.settings = {
21
18
  indentationText: this.convertIndentation(this.options.useTabs, this.options.tabWidth),
22
19
  insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: this.options.bracketSpacing !== undefined ? this.options.bracketSpacing : true,
23
20
  newLineKind: this.convertNewline(this.options.endOfLine),
24
- quoteKind: this.options.singleQuote ? ts_morph_1.QuoteKind.Single : ts_morph_1.QuoteKind.Double,
21
+ quoteKind: this.options.singleQuote ? QuoteKind.Single : QuoteKind.Double,
25
22
  useTrailingCommas: this.options.trailingComma === "none" ? false : true,
26
23
  };
27
24
  }
28
25
  else {
29
26
  this.settings = {};
30
27
  }
31
- ;
32
28
  return this;
33
29
  });
34
30
  }
@@ -41,8 +37,8 @@ class PrettierFormatter extends BaseFormatter_1.BaseFormatter {
41
37
  * @memberof Formatter
42
38
  */
43
39
  format(source) {
44
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
45
- return prettier_1.default.format(source, Object.assign({ parser: "typescript" }, this.options));
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return prettier.format(source, Object.assign({ parser: "typescript" }, this.options));
46
42
  });
47
43
  }
48
44
  /**
@@ -56,16 +52,16 @@ class PrettierFormatter extends BaseFormatter_1.BaseFormatter {
56
52
  */
57
53
  convertIndentation(useTabs, tabWidth) {
58
54
  if (useTabs)
59
- return ts_morph_1.IndentationText.Tab;
55
+ return IndentationText.Tab;
60
56
  switch (tabWidth) {
61
57
  case 2:
62
- return ts_morph_1.IndentationText.TwoSpaces;
58
+ return IndentationText.TwoSpaces;
63
59
  case 4:
64
- return ts_morph_1.IndentationText.FourSpaces;
60
+ return IndentationText.FourSpaces;
65
61
  case 8:
66
- return ts_morph_1.IndentationText.EightSpaces;
62
+ return IndentationText.EightSpaces;
67
63
  default:
68
- return ts_morph_1.IndentationText.TwoSpaces;
64
+ return IndentationText.TwoSpaces;
69
65
  }
70
66
  }
71
67
  /**
@@ -79,17 +75,16 @@ class PrettierFormatter extends BaseFormatter_1.BaseFormatter {
79
75
  convertNewline(eol) {
80
76
  switch (eol) {
81
77
  case "lf":
82
- return ts_morph_1.NewLineKind.LineFeed;
78
+ return NewLineKind.LineFeed;
83
79
  case "crlf":
84
- return ts_morph_1.NewLineKind.CarriageReturnLineFeed;
80
+ return NewLineKind.CarriageReturnLineFeed;
85
81
  case "cr":
86
- return ts_morph_1.NewLineKind.CarriageReturnLineFeed;
82
+ return NewLineKind.CarriageReturnLineFeed;
87
83
  case "auto":
88
- return ts_morph_1.NewLineKind.LineFeed;
84
+ return NewLineKind.LineFeed;
89
85
  default:
90
- return ts_morph_1.NewLineKind.LineFeed;
86
+ return NewLineKind.LineFeed;
91
87
  }
92
88
  }
93
89
  }
94
- exports.PrettierFormatter = PrettierFormatter;
95
90
  //# sourceMappingURL=PrettierFormatter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrettierFormatter.js","sourceRoot":"","sources":["../../../src/project/formatter/PrettierFormatter.ts"],"names":[],"mappings":";;;;AAAA,gEAAgC;AAChC,uCAAmE;AAEnE,mDAAgD;AAEhD,MAAa,iBAAkB,SAAQ,6BAAa;IAUlD;;;;;OAKG;IACU,IAAI;;YACf,MAAM,OAAO,GAAG,MAAM,kBAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAE1D,IAAI,OAAO,EAAE;gB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WAAW,CAAC;YACrC;gBACE,OAAO,0BAAe,CAAC,SAAS,CAAC;SACpC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,cAAc,CAAC,GAAuB;QAC5C,QAAQ,GAAG,EAAE;YACX,KAAK,IAAI;gBACP,OAAO,sBAAW,CAAC,QAAQ,CAAC;YAC9B,KAAK,MAAM;gBACT,OAAO,sBAAW,CAAC,sBAAsB,CAAC;YAC5C,KAAK,IAAI;gBACP,OAAO,sBAAW,CAAC,sBAAsB,CAAC;YAC5C,KAAK,MAAM;gBACT,OAAO,sBAAW,CAAC,QAAQ,CAAC;YAC9B;gBACE,OAAO,sBAAW,CAAC,QAAQ,CAAC;SAC/B;IACH,CAAC;CACF;AAjGD,8CAiGC","sourcesContent":["import prettier from \"prettier\";\r\nimport { IndentationText, NewLineKind, QuoteKind } from \"ts-morph\";\r\n\r\nimport { BaseFormatter } from \"./BaseFormatter\";\r\n\r\nexport class PrettierFormatter extends BaseFormatter {\r\n /**\r\n * Prettier options found in the project.\r\n *\r\n * @private\r\n * @type {prettier.Options}\r\n * @memberof PrettierFormatter\r\n */\r\n private options!: prettier.Options;\r\n\r\n /**\r\n * Initializes the formatter.\r\n *\r\n * @returns {Promise<PrettierFormatter>} Initialized formatter\r\n * @memberof PrettierFormatter\r\n */\r\n public async init(): Promise<PrettierFormatter> {\r\n const options = await prettier.resolveConfig(this.output);\r\n\r\n if (options) {\r\n this.options = options;\r\n this.settings = {\r\n indentationText: this.convertIndentation(this.options.useTabs, this.options.tabWidth),\r\n insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces:\r\n this.options.bracketSpacing !== undefined ? this.options.bracketSpacing : true,\r\n newLineKind: this.convertNewline(this.options.endOfLine),\r\n quoteKind: this.options.singleQuote ? QuoteKind.Single : QuoteKind.Double,\r\n useTrailingCommas: this.options.trailingComma === \"none\" ? false : true,\r\n };\r\n } else {\r\n this.settings = {};\r\n };\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Formats a given source code.\r\n *\r\n * @abstract\r\n * @param {string} source Source code to format\r\n * @returns {string} Formatted source code\r\n * @memberof Formatter\r\n */\r\n public async format(source: string): Promise<string> {\r\n return prettier.format(source, {\r\n parser: \"typescript\",\r\n ...this.options,\r\n });\r\n }\r\n\r\n /**\r\n * Converts prettier indentation config to ts-morph settings.\r\n *\r\n * @private\r\n * @param {boolean | undefined} useTabs Flag, whether to use tabs or not\r\n * @param {number | undefined} tabWidth Width of a simulated tab, each number represents a space\r\n * @returns {IndentationText} Converted indentation text\r\n * @memberof PrettierFormatter\r\n */\r\n private convertIndentation(useTabs: boolean | undefined, tabWidth: number | undefined): IndentationText {\r\n if (useTabs) return IndentationText.Tab;\r\n\r\n switch (tabWidth) {\r\n case 2:\r\n return IndentationText.TwoSpaces;\r\n case 4:\r\n return IndentationText.FourSpaces;\r\n case 8:\r\n return IndentationText.EightSpaces;\r\n default:\r\n return IndentationText.TwoSpaces;\r\n }\r\n }\r\n\r\n /**\r\n * Converts prettier newline config to ts-morph settings.\r\n *\r\n * @private\r\n * @param {string | undefined} eol prettier end-of-line config\r\n * @returns {NewLineKind | undefined} Converted new line kind\r\n * @memberof PrettierFormatter\r\n */\r\n private convertNewline(eol: string | undefined): NewLineKind | undefined {\r\n switch (eol) {\r\n case \"lf\":\r\n return NewLineKind.LineFeed;\r\n case \"crlf\":\r\n return NewLineKind.CarriageReturnLineFeed;\r\n case \"cr\":\r\n return NewLineKind.CarriageReturnLineFeed;\r\n case \"auto\":\r\n return NewLineKind.LineFeed;\r\n default:\r\n return NewLineKind.LineFeed;\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"PrettierFormatter.js","sourceRoot":"","sources":["../../../src/project/formatter/PrettierFormatter.ts"],"names":[],"mappings":";AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,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QAAQ,EAAE;YAChB,KAAK,CAAC;gBACJ,OAAO,eAAe,CAAC,SAAS,CAAC;YACnC,KAAK,CAAC;gBACJ,OAAO,eAAe,CAAC,UAAU,CAAC;YACpC,KAAK,CAAC;gBACJ,OAAO,eAAe,CAAC,WAAW,CAAC;YACrC;gBACE,OAAO,eAAe,CAAC,SAAS,CAAC;SACpC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,cAAc,CAAC,GAAuB;QAC5C,QAAQ,GAAG,EAAE;YACX,KAAK,IAAI;gBACP,OAAO,WAAW,CAAC,QAAQ,CAAC;YAC9B,KAAK,MAAM;gBACT,OAAO,WAAW,CAAC,sBAAsB,CAAC;YAC5C,KAAK,IAAI;gBACP,OAAO,WAAW,CAAC,sBAAsB,CAAC;YAC5C,KAAK,MAAM;gBACT,OAAO,WAAW,CAAC,QAAQ,CAAC;YAC9B;gBACE,OAAO,WAAW,CAAC,QAAQ,CAAC;SAC/B;IACH,CAAC;CACF","sourcesContent":["import prettier from \"prettier\";\r\nimport { IndentationText, NewLineKind, QuoteKind } from \"ts-morph\";\r\n\r\nimport { BaseFormatter } from \"./BaseFormatter.js\";\r\n\r\nexport class PrettierFormatter extends BaseFormatter {\r\n /**\r\n * Prettier options found in the project.\r\n *\r\n * @private\r\n * @type {prettier.Options}\r\n * @memberof PrettierFormatter\r\n */\r\n private options!: prettier.Options;\r\n\r\n /**\r\n * Initializes the formatter.\r\n *\r\n * @returns {Promise<PrettierFormatter>} Initialized formatter\r\n * @memberof PrettierFormatter\r\n */\r\n public async init(): Promise<PrettierFormatter> {\r\n const options = await prettier.resolveConfig(this.output);\r\n\r\n if (options) {\r\n this.options = options;\r\n this.settings = {\r\n indentationText: this.convertIndentation(this.options.useTabs, this.options.tabWidth),\r\n insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces:\r\n this.options.bracketSpacing !== undefined ? this.options.bracketSpacing : true,\r\n newLineKind: this.convertNewline(this.options.endOfLine),\r\n quoteKind: this.options.singleQuote ? QuoteKind.Single : QuoteKind.Double,\r\n useTrailingCommas: this.options.trailingComma === \"none\" ? false : true,\r\n };\r\n } else {\r\n this.settings = {};\r\n }\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Formats a given source code.\r\n *\r\n * @abstract\r\n * @param {string} source Source code to format\r\n * @returns {string} Formatted source code\r\n * @memberof Formatter\r\n */\r\n public async format(source: string): Promise<string> {\r\n return prettier.format(source, {\r\n parser: \"typescript\",\r\n ...this.options,\r\n });\r\n }\r\n\r\n /**\r\n * Converts prettier indentation config to ts-morph settings.\r\n *\r\n * @private\r\n * @param {boolean | undefined} useTabs Flag, whether to use tabs or not\r\n * @param {number | undefined} tabWidth Width of a simulated tab, each number represents a space\r\n * @returns {IndentationText} Converted indentation text\r\n * @memberof PrettierFormatter\r\n */\r\n private convertIndentation(useTabs: boolean | undefined, tabWidth: number | undefined): IndentationText {\r\n if (useTabs) return IndentationText.Tab;\r\n\r\n switch (tabWidth) {\r\n case 2:\r\n return IndentationText.TwoSpaces;\r\n case 4:\r\n return IndentationText.FourSpaces;\r\n case 8:\r\n return IndentationText.EightSpaces;\r\n default:\r\n return IndentationText.TwoSpaces;\r\n }\r\n }\r\n\r\n /**\r\n * Converts prettier newline config to ts-morph settings.\r\n *\r\n * @private\r\n * @param {string | undefined} eol prettier end-of-line config\r\n * @returns {NewLineKind | undefined} Converted new line kind\r\n * @memberof PrettierFormatter\r\n */\r\n private convertNewline(eol: string | undefined): NewLineKind | undefined {\r\n switch (eol) {\r\n case \"lf\":\r\n return NewLineKind.LineFeed;\r\n case \"crlf\":\r\n return NewLineKind.CarriageReturnLineFeed;\r\n case \"cr\":\r\n return NewLineKind.CarriageReturnLineFeed;\r\n case \"auto\":\r\n return NewLineKind.LineFeed;\r\n default:\r\n return NewLineKind.LineFeed;\r\n }\r\n }\r\n}\r\n"]}
@@ -1,2 +1,2 @@
1
- import type { FileFormatter } from "./FileFormatter";
1
+ import type { FileFormatter } from "./FileFormatter.js";
2
2
  export declare function createFormatter(outputDir: string, usePrettier: boolean): Promise<FileFormatter>;
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createFormatter = void 0;
4
- const tslib_1 = require("tslib");
5
- const PrettierFormatter_1 = require("./PrettierFormatter");
6
- const NoopFormatter_1 = require("./NoopFormatter");
7
- function createFormatter(outputDir, usePrettier) {
8
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
- const formatter = usePrettier ? new PrettierFormatter_1.PrettierFormatter(outputDir) : new NoopFormatter_1.NoopFormatter(outputDir);
1
+ import { __awaiter } from "tslib";
2
+ import { NoopFormatter } from "./NoopFormatter.js";
3
+ import { PrettierFormatter } from "./PrettierFormatter.js";
4
+ export function createFormatter(outputDir, usePrettier) {
5
+ return __awaiter(this, void 0, void 0, function* () {
6
+ const formatter = usePrettier ? new PrettierFormatter(outputDir) : new NoopFormatter(outputDir);
10
7
  yield formatter.init();
11
8
  return formatter;
12
9
  });
13
10
  }
14
- exports.createFormatter = createFormatter;
15
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/project/formatter/index.ts"],"names":[],"mappings":";;;;AACA,2DAAwD;AACxD,mDAAgD;AAEhD,SAAsB,eAAe,CAAC,SAAiB,EAAE,WAAoB;;QAC3E,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,qCAAiB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,6BAAa,CAAC,SAAS,CAAC,CAAC;QAChG,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC;QAEvB,OAAO,SAAS,CAAC;IACnB,CAAC;CAAA;AALD,0CAKC","sourcesContent":["import type { FileFormatter } from \"./FileFormatter\";\r\nimport { PrettierFormatter } from \"./PrettierFormatter\";\r\nimport { NoopFormatter } from \"./NoopFormatter\";\r\n\r\nexport async function createFormatter(outputDir: string, usePrettier: boolean): Promise<FileFormatter> {\r\n const formatter = usePrettier ? new PrettierFormatter(outputDir) : new NoopFormatter(outputDir);\r\n await formatter.init();\r\n\r\n return formatter;\r\n}\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/project/formatter/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,UAAgB,eAAe,CAAC,SAAiB,EAAE,WAAoB;;QAC3E,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,SAAS,CAAC,CAAC;QAChG,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC;QAEvB,OAAO,SAAS,CAAC;IACnB,CAAC;CAAA","sourcesContent":["import type { FileFormatter } from \"./FileFormatter.js\";\r\nimport { NoopFormatter } from \"./NoopFormatter.js\";\r\nimport { PrettierFormatter } from \"./PrettierFormatter.js\";\r\n\r\nexport async function createFormatter(outputDir: string, usePrettier: boolean): Promise<FileFormatter> {\r\n const formatter = usePrettier ? new PrettierFormatter(outputDir) : new NoopFormatter(outputDir);\r\n await formatter.init();\r\n\r\n return formatter;\r\n}\r\n"]}
@@ -1,13 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logFilePath = void 0;
4
- const tslib_1 = require("tslib");
5
- const path_1 = tslib_1.__importDefault(require("path"));
6
- function logFilePath(filePath) {
1
+ import path from "path";
2
+ export function logFilePath(filePath) {
7
3
  // we only show file paths relative to work dir of running process
8
- const relativePath = path_1.default.relative(process.cwd(), filePath);
4
+ const relativePath = path.relative(process.cwd(), filePath);
9
5
  // beautify slashes for windows
10
- return relativePath.split(path_1.default.sep).join("/");
6
+ return relativePath.split(path.sep).join("/");
11
7
  }
12
- exports.logFilePath = logFilePath;
13
8
  //# sourceMappingURL=logFilePath.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logFilePath.js","sourceRoot":"","sources":["../../../src/project/logger/logFilePath.ts"],"names":[],"mappings":";;;;AAAA,wDAAwB;AAExB,SAAgB,WAAW,CAAC,QAAgB;IAC1C,kEAAkE;IAClE,MAAM,YAAY,GAAG,cAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC5D,+BAA+B;IAC/B,OAAO,YAAY,CAAC,KAAK,CAAC,cAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChD,CAAC;AALD,kCAKC","sourcesContent":["import path from \"path\";\r\n\r\nexport function logFilePath(filePath: string) {\r\n // we only show file paths relative to work dir of running process\r\n const relativePath = path.relative(process.cwd(), filePath);\r\n // beautify slashes for windows\r\n return relativePath.split(path.sep).join(\"/\");\r\n}\r\n"]}
1
+ {"version":3,"file":"logFilePath.js","sourceRoot":"","sources":["../../../src/project/logger/logFilePath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,UAAU,WAAW,CAAC,QAAgB;IAC1C,kEAAkE;IAClE,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC5D,+BAA+B;IAC/B,OAAO,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import path from \"path\";\r\n\r\nexport function logFilePath(filePath: string) {\r\n // we only show file paths relative to work dir of running process\r\n const relativePath = path.relative(process.cwd(), filePath);\r\n // beautify slashes for windows\r\n return relativePath.split(path.sep).join(\"/\");\r\n}\r\n"]}
package/lib/run-cli.js CHANGED
@@ -1,7 +1,5 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const cli_1 = require("./cli");
2
+ import { run } from "./cli/cli.js";
5
3
  // noinspection JSIgnoredPromiseFromCall
6
- new cli_1.Cli().run();
4
+ run();
7
5
  //# sourceMappingURL=run-cli.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-cli.js","sourceRoot":"","sources":["../src/run-cli.ts"],"names":[],"mappings":";;;AAEA,+BAA4B;AAE5B,wCAAwC;AACxC,IAAI,SAAG,EAAE,CAAC,GAAG,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\r\n\r\nimport { Cli } from \"./cli\";\r\n\r\n// noinspection JSIgnoredPromiseFromCall\r\nnew Cli().run();\r\n"]}
1
+ {"version":3,"file":"run-cli.js","sourceRoot":"","sources":["../src/run-cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,wCAAwC;AACxC,GAAG,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\r\nimport { run } from \"./cli/cli.js\";\r\n\r\n// noinspection JSIgnoredPromiseFromCall\r\nrun();\r\n"]}
package/package.json CHANGED
@@ -1,39 +1,7 @@
1
1
  {
2
2
  "name": "@odata2ts/odata2ts",
3
- "version": "0.36.3",
4
- "publishConfig": {
5
- "access": "public"
6
- },
3
+ "version": "0.37.0",
7
4
  "description": "Flexible generator to produce various TypeScript artefacts (from simple model interfaces to complete odata clients) from OData metadata files",
8
- "license": "MIT",
9
- "repository": "git@github.com:odata2ts/odata2ts.git",
10
- "author": "texttechne",
11
- "homepage": "https://odata2ts.github.io/",
12
- "main": "lib/index.js",
13
- "bin": "lib/run-cli.js",
14
- "scripts": {
15
- "build": "yarn clean && yarn compile",
16
- "check-circular-deps": "madge ./src --extensions ts --circular",
17
- "check-circular-generated": "madge ./build --extensions ts --circular",
18
- "clean": "rimraf lib build",
19
- "clean-v2": "rimraf build/v2",
20
- "clean-v4": "rimraf build/v4",
21
- "clear-cache": "jest --clearCache",
22
- "compile": "tsc",
23
- "compile-fixtures": "tsc -p ./tsconfig.fixture.json",
24
- "compile-generated": "tsc -p ./tsconfig.generated.json",
25
- "dev": "yarn generate trippin odata",
26
- "generate": "ts-node --cwd-mode src/run-cli.ts ",
27
- "int-test": "yarn clean && jest ./int-test",
28
- "prepublish": "yarn build",
29
- "test": "yarn compile-fixtures && jest ./test"
30
- },
31
- "files": [
32
- "*.md",
33
- "bin",
34
- "lib",
35
- "LICENSE"
36
- ],
37
5
  "keywords": [
38
6
  "odata2ts",
39
7
  "generator",
@@ -46,50 +14,72 @@
46
14
  "v2",
47
15
  "v4"
48
16
  ],
49
- "peerDependencies": {
50
- "@odata2ts/odata-query-objects": "^0.23.1",
51
- "@odata2ts/odata-service": "^0.19.3"
17
+ "homepage": "https://odata2ts.github.io/",
18
+ "repository": "git@github.com:odata2ts/odata2ts.git",
19
+ "license": "MIT",
20
+ "author": "texttechne",
21
+ "type": "module",
22
+ "main": "lib/index.js",
23
+ "types": "./lib/index.d.ts",
24
+ "bin": "lib/run-cli.js",
25
+ "files": [
26
+ "*.md",
27
+ "bin",
28
+ "lib",
29
+ "LICENSE"
30
+ ],
31
+ "scripts": {
32
+ "build": "yarn clean && tsc",
33
+ "check-circular-deps": "madge ./src --extensions ts --circular",
34
+ "check-circular-generated": "madge ./build --extensions ts --circular",
35
+ "clean": "rimraf lib build",
36
+ "clean-v2": "rimraf build/v2",
37
+ "clean-v4": "rimraf build/v4",
38
+ "compile": "tsc -p tsconfig.compile.json",
39
+ "dev": "yarn generate trippin odata",
40
+ "generate": "ts-node --esm --cwd-mode src/run-cli.ts",
41
+ "int-test": "yarn clean && vitest run --dir int-test",
42
+ "prepublish": "yarn build",
43
+ "test": "vitest run --dir test",
44
+ "testing": "vitest --dir test"
52
45
  },
53
46
  "dependencies": {
54
- "@odata2ts/converter-api": "^0.1.2",
55
- "@odata2ts/converter-runtime": "^0.2.2",
56
- "@odata2ts/http-client-api": "^0.5.1",
57
- "@odata2ts/odata-core": "^0.5.0",
58
- "@prettier/plugin-xml": "^2.2.0",
47
+ "@odata2ts/converter-api": "^0.2.2",
48
+ "@odata2ts/converter-runtime": "^0.5.0",
49
+ "@odata2ts/http-client-api": "^0.6.2",
50
+ "@odata2ts/odata-core": "^0.6.0",
51
+ "@prettier/plugin-xml": "^3.4.1",
52
+ "@types/xml2js": "^0.4.11",
59
53
  "axios": "^1.4.0",
60
- "camel-case": "^4.1.2",
54
+ "change-case": "^5.4.4",
61
55
  "commander": "^10.0.1",
62
- "constant-case": "^3.0.4",
63
56
  "cosmiconfig": "^8.2.0",
64
57
  "cosmiconfig-typescript-loader": "^5.0.0",
65
58
  "deepmerge": "^4.3.1",
66
- "fs-extra": "^11.1.1",
67
- "pascal-case": "^3.1.2",
68
- "prettier": "^2.8.8",
69
- "snake-case": "^3.0.4",
59
+ "mkdirp": "^3.0.1",
60
+ "prettier": "^3.3.3",
70
61
  "ts-morph": "^18.0.0",
71
62
  "ts-node": "^10.9.1",
72
63
  "tsconfig-loader": "^1.1.0",
64
+ "type-fest": "2.12.2",
73
65
  "upper-case-first": "^2.0.2",
74
66
  "xml2js": "^0.6.0"
75
67
  },
76
68
  "devDependencies": {
77
- "@odata2ts/converter-v2-to-v4": "^0.1.4",
78
- "@odata2ts/odata-query-objects": "^0.23.1",
79
- "@odata2ts/odata-service": "^0.19.3",
80
- "@odata2ts/test-converters": "^0.3.1",
81
- "@types/fs-extra": "^11.0.1",
82
- "@types/jest": "^29.5.2",
83
- "@types/node": "^20.3.0",
84
- "@types/prettier": "^2.7.3",
85
- "@types/xml2js": "^0.4.11",
86
- "jest": "^29.5.0",
87
- "rimraf": "^5.0.1",
88
- "ts-jest": "^29.1.0",
89
- "type-fest": "2.12.2",
90
- "typescript": "^5.1.3"
69
+ "@odata2ts/converter-v2-to-v4": "^0.5.1",
70
+ "@odata2ts/odata-query-objects": "^0.24.0",
71
+ "@odata2ts/odata-service": "^0.20.0",
72
+ "@odata2ts/test-converters": "^0.4.0",
73
+ "@types/node": "^22.4.0",
74
+ "typescript": "5.1.3"
91
75
  },
92
- "types": "./lib/index.d.ts",
93
- "gitHead": "8a0ef94131c114b44edcddc0bc0af4fc5ab800fd",
76
+ "peerDependencies": {
77
+ "@odata2ts/odata-query-objects": "^0.24.0",
78
+ "@odata2ts/odata-service": "^0.20.0"
79
+ },
80
+ "publishConfig": {
81
+ "access": "public"
82
+ },
83
+ "gitHead": "4d68f9e9394abc81028c901be51fedfe55cb786c",
94
84
  "readme": "README.md"
95
85
  }
package/lib/cli.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare class Cli {
2
- run(): Promise<void>;
3
- }
package/lib/cli.js DELETED
@@ -1,176 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Cli = void 0;
4
- const tslib_1 = require("tslib");
5
- const commander_1 = tslib_1.__importStar(require("commander"));
6
- const cosmiconfig_1 = require("cosmiconfig");
7
- const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader");
8
- const fs_extra_1 = require("fs-extra");
9
- const xml2js_1 = require("xml2js");
10
- const app_1 = require("./app");
11
- const download_1 = require("./download/");
12
- const evaluateConfig_1 = require("./evaluateConfig");
13
- const OptionModel_1 = require("./OptionModel");
14
- const logFilePath_1 = require("./project/logger/logFilePath");
15
- function parseMode(value, dummyPrevious) {
16
- switch (value) {
17
- case "models":
18
- return OptionModel_1.Modes.models;
19
- case "qobjects":
20
- return OptionModel_1.Modes.qobjects;
21
- case "service":
22
- return OptionModel_1.Modes.service;
23
- case "all":
24
- return OptionModel_1.Modes.all;
25
- default:
26
- throw new Error(`Not a valid Mode: ${value}`);
27
- }
28
- }
29
- function parseEmitMode(value, dummyPrevious) {
30
- switch (value) {
31
- case "dts":
32
- return OptionModel_1.EmitModes.dts;
33
- case "js":
34
- return OptionModel_1.EmitModes.js;
35
- case "ts":
36
- return OptionModel_1.EmitModes.ts;
37
- case "js_dts":
38
- return OptionModel_1.EmitModes.js_dts;
39
- default:
40
- throw new Error(`Not a valid EmitMode: ${value}`);
41
- }
42
- }
43
- function processCliArgs() {
44
- var _a;
45
- const cli = new commander_1.default.Command()
46
- .version("0.3.0")
47
- .description("CLI to generate Typescript Interfaces for models of a given OData service.")
48
- .argument("[services...]", "Run the generation process only for certain services specified in config file", [])
49
- .option("-s, --source <url or metadata.xml>", "Path to metadata file")
50
- .option("-o, --output <path>", "Output location for generated files")
51
- .option("-u, --source-url <sourceUrl>", "URL to the root of the OData service")
52
- .option("-f, --refresh-file", "Download metadata again and overwrite existing file (only applies if sourceUrl is specified)")
53
- .addOption(new commander_1.Option("-m, --mode <mode>", "What kind of stuff gets generated")
54
- .choices(Object.values(OptionModel_1.Modes).filter((t) => isNaN(Number(t))))
55
- .argParser(parseMode))
56
- .addOption(new commander_1.Option("-e, --emit-mode <mode>", "Output TS source files, compiled JS files with/wihthout generated d.ts files")
57
- .choices(Object.values(OptionModel_1.EmitModes))
58
- .argParser(parseEmitMode))
59
- .option("-p, --prettier", "Format result with prettier (only applies if emitMode=ts)")
60
- .option("-t, --tsconfig <path>", "Specify alternative to 'tsconfig.json' to use specific compilerOptions (applies if emitMode is not ts)")
61
- .option("-d, --debug", "Verbose debug infos")
62
- .option("-name, --service-name <serviceName>", "Give the service your own name")
63
- .option("-n, --disable-auto-managed-key", "Don't mark single key props as managed by the server side (not editable)")
64
- .option("-r, --allow-renaming", "Allow that property and entity names may be changed by configured casing")
65
- .parse(process.argv);
66
- const args = ((_a = cli.args) === null || _a === void 0 ? void 0 : _a.length) ? { services: cli.args } : {};
67
- return Object.assign(Object.assign({}, cli.opts()), args);
68
- }
69
- function processConfigFile() {
70
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
71
- const moduleName = "odata2ts";
72
- const explorer = (0, cosmiconfig_1.cosmiconfig)(moduleName, {
73
- searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.ts`, `${moduleName}.config.cjs`],
74
- loaders: {
75
- ".ts": (0, cosmiconfig_typescript_loader_1.TypeScriptLoader)(),
76
- },
77
- });
78
- const discoveredConfig = yield explorer.search();
79
- if (discoveredConfig === null || discoveredConfig === void 0 ? void 0 : discoveredConfig.config) {
80
- console.log("Loaded config file: ", (0, logFilePath_1.logFilePath)(discoveredConfig.filepath));
81
- }
82
- else {
83
- console.log("No config file found.");
84
- }
85
- return discoveredConfig === null || discoveredConfig === void 0 ? void 0 : discoveredConfig.config;
86
- });
87
- }
88
- class Cli {
89
- run() {
90
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
91
- let runs;
92
- try {
93
- const cliOpts = processCliArgs();
94
- if (cliOpts.debug) {
95
- console.log("CLI opts:", cliOpts);
96
- }
97
- const fileOpts = yield processConfigFile();
98
- runs = (0, evaluateConfig_1.evaluateConfigOptions)(cliOpts, fileOpts);
99
- }
100
- catch (error) {
101
- console.error("Bad arguments!", error === null || error === void 0 ? void 0 : error.message);
102
- process.exit(1);
103
- }
104
- for (let run of runs) {
105
- yield startServiceGenerationRun(run);
106
- }
107
- });
108
- }
109
- }
110
- exports.Cli = Cli;
111
- function startServiceGenerationRun(options) {
112
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
113
- const { source, output, sourceUrl, refreshFile, sourceUrlConfig, debug, mode, emitMode, prettier, serviceName } = options;
114
- console.log("---------------------------");
115
- console.log(`Starting generation process. Service name ${serviceName ? `"${serviceName}"` : "will be detected automatically!"}`);
116
- if (debug) {
117
- console.log("Resolved config:", {
118
- source,
119
- output,
120
- sourceUrl,
121
- refreshFile,
122
- debug,
123
- mode: OptionModel_1.Modes[mode],
124
- emitMode,
125
- prettier,
126
- serviceName,
127
- });
128
- }
129
- // evaluate source
130
- const exists = yield (0, fs_extra_1.pathExists)(source);
131
- console.log(`${exists ? "Found" : "Didn't find"} metadata file at: `, source);
132
- let metadataXml;
133
- // download metadata and store on disk
134
- if (sourceUrl && (!exists || refreshFile)) {
135
- try {
136
- metadataXml = yield (0, download_1.downloadMetadata)(sourceUrl, sourceUrlConfig, debug);
137
- }
138
- catch (e) {
139
- console.error(`Failed to load metadata! Message: ${e === null || e === void 0 ? void 0 : e.message}`);
140
- process.exit(10);
141
- }
142
- metadataXml = yield (0, download_1.storeMetadata)(source, metadataXml, prettier);
143
- }
144
- // otherwise file must exist
145
- else if (!exists) {
146
- console.error(`Input source [${source}] doesn't exist!`);
147
- process.exit(2);
148
- }
149
- // read the metadata from file
150
- else {
151
- console.log("Reading metadata from file:", source);
152
- metadataXml = yield (0, fs_extra_1.readFile)(source);
153
- }
154
- const metadataJson = (yield (0, xml2js_1.parseStringPromise)(metadataXml));
155
- // TODO find out if "1.0" and "4.0" are really correct
156
- // TODO exit here if no version not suitable version was detected
157
- // console.log(`OData version detected: ${metadataJson["edmx:Edmx"].$.Version}`);
158
- // ensure that output directory exists
159
- try {
160
- yield (0, fs_extra_1.emptyDir)(output);
161
- }
162
- catch (error) {
163
- console.error(`Output path [${output}] couldn't be created!`, error);
164
- process.exit(3);
165
- }
166
- // run the app
167
- try {
168
- yield (0, app_1.runApp)(metadataJson, options);
169
- }
170
- catch (err) {
171
- console.error("Error while running the program", err);
172
- process.exit(99);
173
- }
174
- });
175
- }
176
- //# sourceMappingURL=cli.js.map
package/lib/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;AAAA,+DAA8C;AAC9C,6CAA0C;AAC1C,iFAAiE;AACjE,uCAA0D;AAC1D,mCAA4C;AAE5C,+BAA+B;AAE/B,0CAA8D;AAC9D,qDAAyD;AACzD,+CAAoH;AACpH,8DAA2D;AAE3D,SAAS,SAAS,CAAC,KAAa,EAAE,aAAgC;IAChE,QAAQ,KAAK,EAAE;QACb,KAAK,QAAQ;YACX,OAAO,mBAAK,CAAC,MAAM,CAAC;QACtB,KAAK,UAAU;YACb,OAAO,mBAAK,CAAC,QAAQ,CAAC;QACxB,KAAK,SAAS;YACZ,OAAO,mBAAK,CAAC,OAAO,CAAC;QACvB,KAAK,KAAK;YACR,OAAO,mBAAK,CAAC,GAAG,CAAC;QACnB;YACE,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Q,EAAC,MAAM,CAAC,CAAC;SACxB;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,gBAAgB,MAAM,wBAAwB,EAAE,KAAK,CAAC,CAAC;YACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;QAED,cAAc;QACd,IAAI;YACF,MAAM,IAAA,YAAM,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;SACrC;QAAC,OAAO,GAAQ,EAAE;YACjB,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,GAAG,CAAC,CAAC;YACtD,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SAClB;IACH,CAAC;CAAA","sourcesContent":["import commander, { Option } from \"commander\";\r\nimport { cosmiconfig } from \"cosmiconfig\";\r\nimport { TypeScriptLoader } from \"cosmiconfig-typescript-loader\";\r\nimport { emptyDir, pathExists, readFile } from \"fs-extra\";\r\nimport { parseStringPromise } from \"xml2js\";\r\n\r\nimport { runApp } from \"./app\";\r\nimport { ODataEdmxModelBase } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { downloadMetadata, storeMetadata } from \"./download/\";\r\nimport { evaluateConfigOptions } from \"./evaluateConfig\";\r\nimport { CliOptions, ConfigFileOptions, EmitModes, Modes, RunOptions, UrlSourceConfiguration } from \"./OptionModel\";\r\nimport { logFilePath } from \"./project/logger/logFilePath\";\r\n\r\nfunction parseMode(value: string, dummyPrevious: Modes | undefined) {\r\n switch (value) {\r\n case \"models\":\r\n return Modes.models;\r\n case \"qobjects\":\r\n return Modes.qobjects;\r\n case \"service\":\r\n return Modes.service;\r\n case \"all\":\r\n return Modes.all;\r\n default:\r\n throw new Error(`Not a valid Mode: ${value}`);\r\n }\r\n}\r\n\r\nfunction parseEmitMode(value: string, dummyPrevious: EmitModes) {\r\n switch (value) {\r\n case \"dts\":\r\n return EmitModes.dts;\r\n case \"js\":\r\n return EmitModes.js;\r\n case \"ts\":\r\n return EmitModes.ts;\r\n case \"js_dts\":\r\n return EmitModes.js_dts;\r\n default:\r\n throw new Error(`Not a valid EmitMode: ${value}`);\r\n }\r\n}\r\n\r\nfunction processCliArgs() {\r\n const cli = new commander.Command()\r\n .version(\"0.3.0\")\r\n .description(\"CLI to generate Typescript Interfaces for models of a given OData service.\")\r\n .argument(\"[services...]\", \"Run the generation process only for certain services specified in config file\", [])\r\n .option(\"-s, --source <url or metadata.xml>\", \"Path to metadata file\")\r\n .option(\"-o, --output <path>\", \"Output location for generated files\")\r\n .option(\"-u, --source-url <sourceUrl>\", \"URL to the root of the OData service\")\r\n .option(\r\n \"-f, --refresh-file\",\r\n \"Download metadata again and overwrite existing file (only applies if sourceUrl is specified)\"\r\n )\r\n .addOption(\r\n new Option(\"-m, --mode <mode>\", \"What kind of stuff gets generated\")\r\n .choices(Object.values(Modes).filter((t): t is string => isNaN(Number(t))))\r\n .argParser<Modes>(parseMode)\r\n )\r\n .addOption(\r\n new Option(\r\n \"-e, --emit-mode <mode>\",\r\n \"Output TS source files, compiled JS files with/wihthout generated d.ts files\"\r\n )\r\n .choices(Object.values(EmitModes))\r\n .argParser<EmitModes>(parseEmitMode)\r\n )\r\n .option(\"-p, --prettier\", \"Format result with prettier (only applies if emitMode=ts)\")\r\n .option(\r\n \"-t, --tsconfig <path>\",\r\n \"Specify alternative to 'tsconfig.json' to use specific compilerOptions (applies if emitMode is not ts)\"\r\n )\r\n .option(\"-d, --debug\", \"Verbose debug infos\")\r\n .option(\"-name, --service-name <serviceName>\", \"Give the service your own name\")\r\n .option(\r\n \"-n, --disable-auto-managed-key\",\r\n \"Don't mark single key props as managed by the server side (not editable)\"\r\n )\r\n .option(\"-r, --allow-renaming\", \"Allow that property and entity names may be changed by configured casing\")\r\n .parse(process.argv);\r\n\r\n const args = cli.args?.length ? { services: cli.args } : {};\r\n return {\r\n ...cli.opts(),\r\n ...args,\r\n } as CliOptions;\r\n}\r\n\r\nasync function processConfigFile() {\r\n const moduleName = \"odata2ts\";\r\n const explorer = cosmiconfig(moduleName, {\r\n searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.ts`, `${moduleName}.config.cjs`],\r\n loaders: {\r\n \".ts\": TypeScriptLoader(),\r\n },\r\n });\r\n const discoveredConfig = await explorer.search();\r\n\r\n if (discoveredConfig?.config) {\r\n console.log(\"Loaded config file: \", logFilePath(discoveredConfig.filepath));\r\n } else {\r\n console.log(\"No config file found.\");\r\n }\r\n\r\n return discoveredConfig?.config as ConfigFileOptions;\r\n}\r\n\r\nexport class Cli {\r\n async run(): Promise<void> {\r\n let runs;\r\n try {\r\n const cliOpts = processCliArgs();\r\n if (cliOpts.debug) {\r\n console.log(\"CLI opts:\", cliOpts);\r\n }\r\n const fileOpts = await processConfigFile();\r\n\r\n runs = evaluateConfigOptions(cliOpts, fileOpts);\r\n } catch (error: any) {\r\n console.error(\"Bad arguments!\", error?.message);\r\n process.exit(1);\r\n }\r\n\r\n for (let run of runs) {\r\n await startServiceGenerationRun(run);\r\n }\r\n }\r\n}\r\n\r\nasync function startServiceGenerationRun(options: RunOptions) {\r\n const { source, output, sourceUrl, refreshFile, sourceUrlConfig, debug, mode, emitMode, prettier, serviceName } =\r\n options;\r\n console.log(\"---------------------------\");\r\n console.log(\r\n `Starting generation process. Service name ${serviceName ? `\"${serviceName}\"` : \"will be detected automatically!\"}`\r\n );\r\n\r\n if (debug) {\r\n console.log(\"Resolved config:\", {\r\n source,\r\n output,\r\n sourceUrl,\r\n refreshFile,\r\n debug,\r\n mode: Modes[mode],\r\n emitMode,\r\n prettier,\r\n serviceName,\r\n });\r\n }\r\n\r\n // evaluate source\r\n const exists = await pathExists(source);\r\n console.log(`${exists ? \"Found\" : \"Didn't find\"} metadata file at: `, source);\r\n\r\n let metadataXml;\r\n // download metadata and store on disk\r\n if (sourceUrl && (!exists || refreshFile)) {\r\n try {\r\n metadataXml = await downloadMetadata(sourceUrl, sourceUrlConfig, debug);\r\n } catch (e) {\r\n console.error(`Failed to load metadata! Message: ${(e as Error)?.message}`);\r\n process.exit(10);\r\n }\r\n metadataXml = await storeMetadata(source, metadataXml, prettier);\r\n }\r\n // otherwise file must exist\r\n else if (!exists) {\r\n console.error(`Input source [${source}] doesn't exist!`);\r\n process.exit(2);\r\n }\r\n // read the metadata from file\r\n else {\r\n console.log(\"Reading metadata from file:\", source);\r\n metadataXml = await readFile(source);\r\n }\r\n\r\n const metadataJson = (await parseStringPromise(metadataXml)) as ODataEdmxModelBase<any>;\r\n // TODO find out if \"1.0\" and \"4.0\" are really correct\r\n // TODO exit here if no version not suitable version was detected\r\n // console.log(`OData version detected: ${metadataJson[\"edmx:Edmx\"].$.Version}`);\r\n\r\n // ensure that output directory exists\r\n try {\r\n await emptyDir(output);\r\n } catch (error) {\r\n console.error(`Output path [${output}] couldn't be created!`, error);\r\n process.exit(3);\r\n }\r\n\r\n // run the app\r\n try {\r\n await runApp(metadataJson, options);\r\n } catch (err: any) {\r\n console.error(\"Error while running the program\", err);\r\n process.exit(99);\r\n }\r\n}\r\n"]}