@odata2ts/odata2ts 0.36.2 → 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.
- package/CHANGELOG.md +21 -0
- package/lib/FactoryFunctionModel.d.ts +5 -5
- package/lib/FactoryFunctionModel.js +1 -2
- package/lib/FactoryFunctionModel.js.map +1 -1
- package/lib/NamingModel.js +2 -5
- package/lib/NamingModel.js.map +1 -1
- package/lib/OptionModel.d.ts +2 -2
- package/lib/OptionModel.js +4 -7
- package/lib/OptionModel.js.map +1 -1
- package/lib/TypeModel.js +2 -5
- package/lib/TypeModel.js.map +1 -1
- package/lib/app.d.ts +2 -2
- package/lib/app.js +23 -27
- package/lib/app.js.map +1 -1
- package/lib/cli/cli.d.ts +1 -0
- package/lib/cli/cli.js +27 -0
- package/lib/cli/cli.js.map +1 -0
- package/lib/cli/index.d.ts +4 -0
- package/lib/cli/index.js +5 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/cli/processCliArgs.d.ts +2 -0
- package/lib/cli/processCliArgs.js +57 -0
- package/lib/cli/processCliArgs.js.map +1 -0
- package/lib/cli/processConfigFile.d.ts +2 -0
- package/lib/cli/processConfigFile.js +24 -0
- package/lib/cli/processConfigFile.js.map +1 -0
- package/lib/cli/serviceGenerationRun.d.ts +2 -0
- package/lib/cli/serviceGenerationRun.js +77 -0
- package/lib/cli/serviceGenerationRun.js.map +1 -0
- package/lib/data-model/DataModel.d.ts +2 -2
- package/lib/data-model/DataModel.js +5 -10
- package/lib/data-model/DataModel.js.map +1 -1
- package/lib/data-model/DataModelDigestion.d.ts +10 -10
- package/lib/data-model/DataModelDigestion.js +19 -23
- package/lib/data-model/DataModelDigestion.js.map +1 -1
- package/lib/data-model/DataModelDigestionV2.d.ts +2 -2
- package/lib/data-model/DataModelDigestionV2.js +27 -31
- package/lib/data-model/DataModelDigestionV2.js.map +1 -1
- package/lib/data-model/DataModelDigestionV4.d.ts +2 -2
- package/lib/data-model/DataModelDigestionV4.js +38 -35
- package/lib/data-model/DataModelDigestionV4.js.map +1 -1
- package/lib/data-model/DataTypeModel.d.ts +1 -1
- package/lib/data-model/DataTypeModel.js +2 -5
- package/lib/data-model/DataTypeModel.js.map +1 -1
- package/lib/data-model/NamingHelper.d.ts +2 -2
- package/lib/data-model/NamingHelper.js +12 -19
- package/lib/data-model/NamingHelper.js.map +1 -1
- package/lib/data-model/ServiceConfigHelper.d.ts +3 -3
- package/lib/data-model/ServiceConfigHelper.js +18 -22
- package/lib/data-model/ServiceConfigHelper.js.map +1 -1
- package/lib/data-model/edmx/ODataEdmxModelBase.js +1 -2
- package/lib/data-model/edmx/ODataEdmxModelV3.d.ts +1 -1
- package/lib/data-model/edmx/ODataEdmxModelV3.js +1 -2
- package/lib/data-model/edmx/ODataEdmxModelV3.js.map +1 -1
- package/lib/data-model/edmx/ODataEdmxModelV4.d.ts +1 -1
- package/lib/data-model/edmx/ODataEdmxModelV4.js +1 -2
- package/lib/data-model/edmx/ODataEdmxModelV4.js.map +1 -1
- package/lib/data-model/validation/NameClashValidator.d.ts +2 -2
- package/lib/data-model/validation/NameClashValidator.js +10 -14
- package/lib/data-model/validation/NameClashValidator.js.map +1 -1
- package/lib/data-model/validation/NameValidator.d.ts +1 -1
- package/lib/data-model/validation/NameValidator.js +1 -2
- package/lib/data-model/validation/NameValidator.js.map +1 -1
- package/lib/data-model/validation/NoopValidator.d.ts +1 -1
- package/lib/data-model/validation/NoopValidator.js +1 -5
- package/lib/data-model/validation/NoopValidator.js.map +1 -1
- package/lib/defaultConfig.d.ts +1 -1
- package/lib/defaultConfig.js +21 -26
- package/lib/defaultConfig.js.map +1 -1
- package/lib/download/downloadMetadata.d.ts +1 -1
- package/lib/download/downloadMetadata.js +6 -10
- package/lib/download/downloadMetadata.js.map +1 -1
- package/lib/download/index.d.ts +2 -2
- package/lib/download/index.js +2 -7
- package/lib/download/index.js.map +1 -1
- package/lib/download/storeMetadata.js +15 -17
- package/lib/download/storeMetadata.js.map +1 -1
- package/lib/evaluateConfig.d.ts +1 -1
- package/lib/evaluateConfig.js +14 -18
- package/lib/evaluateConfig.js.map +1 -1
- package/lib/generator/ImportContainer.d.ts +2 -2
- package/lib/generator/ImportContainer.js +17 -22
- package/lib/generator/ImportContainer.js.map +1 -1
- package/lib/generator/ImportedNameValidator.js +1 -5
- package/lib/generator/ImportedNameValidator.js.map +1 -1
- package/lib/generator/ModelGenerator.d.ts +1 -1
- package/lib/generator/ModelGenerator.js +8 -12
- package/lib/generator/ModelGenerator.js.map +1 -1
- package/lib/generator/QueryObjectGenerator.d.ts +1 -1
- package/lib/generator/QueryObjectGenerator.js +25 -29
- package/lib/generator/QueryObjectGenerator.js.map +1 -1
- package/lib/generator/ServiceGenerator.d.ts +4 -4
- package/lib/generator/ServiceGenerator.js +52 -56
- package/lib/generator/ServiceGenerator.js.map +1 -1
- package/lib/generator/import/ImportObjects.js +11 -14
- package/lib/generator/import/ImportObjects.js.map +1 -1
- package/lib/generator/index.d.ts +3 -3
- package/lib/generator/index.js +3 -9
- package/lib/generator/index.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.js +4 -7
- package/lib/index.js.map +1 -1
- package/lib/project/FileHandler.d.ts +3 -3
- package/lib/project/FileHandler.js +12 -16
- package/lib/project/FileHandler.js.map +1 -1
- package/lib/project/ProjectManager.d.ts +5 -5
- package/lib/project/ProjectManager.js +25 -32
- package/lib/project/ProjectManager.js.map +1 -1
- package/lib/project/TsMorphHelper.d.ts +1 -1
- package/lib/project/TsMorphHelper.js +21 -22
- package/lib/project/TsMorphHelper.js.map +1 -1
- package/lib/project/formatter/BaseFormatter.d.ts +1 -1
- package/lib/project/formatter/BaseFormatter.js +1 -5
- package/lib/project/formatter/BaseFormatter.js.map +1 -1
- package/lib/project/formatter/FileFormatter.js +1 -2
- package/lib/project/formatter/NoopFormatter.d.ts +1 -1
- package/lib/project/formatter/NoopFormatter.js +5 -9
- package/lib/project/formatter/NoopFormatter.js.map +1 -1
- package/lib/project/formatter/PrettierFormatter.d.ts +1 -1
- package/lib/project/formatter/PrettierFormatter.js +20 -25
- package/lib/project/formatter/PrettierFormatter.js.map +1 -1
- package/lib/project/formatter/index.d.ts +1 -1
- package/lib/project/formatter/index.js +6 -10
- package/lib/project/formatter/index.js.map +1 -1
- package/lib/project/logger/logFilePath.js +4 -9
- package/lib/project/logger/logFilePath.js.map +1 -1
- package/lib/run-cli.js +2 -4
- package/lib/run-cli.js.map +1 -1
- package/package.json +53 -63
- package/lib/cli.d.ts +0 -3
- package/lib/cli.js +0 -176
- package/lib/cli.js.map +0 -1
package/lib/defaultConfig.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const deepmerge_1 = tslib_1.__importDefault(require("deepmerge"));
|
|
6
|
-
const NamingModel_1 = require("./NamingModel");
|
|
7
|
-
const OptionModel_1 = require("./OptionModel");
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import deepmerge from "deepmerge";
|
|
3
|
+
import { NamingStrategies } from "./NamingModel.js";
|
|
4
|
+
import { EmitModes, Modes } from "./OptionModel.js";
|
|
8
5
|
/**
|
|
9
6
|
* The default configuration.
|
|
10
7
|
*/
|
|
11
8
|
const defaultConfig = {
|
|
12
9
|
sourceUrlConfig: {},
|
|
13
10
|
refreshFile: false,
|
|
14
|
-
mode:
|
|
15
|
-
emitMode:
|
|
11
|
+
mode: Modes.all,
|
|
12
|
+
emitMode: EmitModes.js_dts,
|
|
16
13
|
debug: false,
|
|
17
14
|
prettier: false,
|
|
18
15
|
tsconfig: "tsconfig.json",
|
|
@@ -30,8 +27,8 @@ const defaultConfig = {
|
|
|
30
27
|
bundledFileGeneration: true,
|
|
31
28
|
naming: {
|
|
32
29
|
models: {
|
|
33
|
-
namingStrategy:
|
|
34
|
-
propNamingStrategy:
|
|
30
|
+
namingStrategy: NamingStrategies.PASCAL_CASE,
|
|
31
|
+
propNamingStrategy: NamingStrategies.CAMEL_CASE,
|
|
35
32
|
editableModels: {
|
|
36
33
|
prefix: "Editable",
|
|
37
34
|
suffix: "",
|
|
@@ -48,14 +45,14 @@ const defaultConfig = {
|
|
|
48
45
|
applyModelNaming: true,
|
|
49
46
|
},
|
|
50
47
|
fileName: {
|
|
51
|
-
namingStrategy:
|
|
48
|
+
namingStrategy: NamingStrategies.PASCAL_CASE,
|
|
52
49
|
prefix: "",
|
|
53
50
|
suffix: "Model",
|
|
54
51
|
},
|
|
55
52
|
},
|
|
56
53
|
queryObjects: {
|
|
57
|
-
namingStrategy:
|
|
58
|
-
propNamingStrategy:
|
|
54
|
+
namingStrategy: NamingStrategies.PASCAL_CASE,
|
|
55
|
+
propNamingStrategy: NamingStrategies.CAMEL_CASE,
|
|
59
56
|
prefix: "Q",
|
|
60
57
|
suffix: "",
|
|
61
58
|
idFunctions: {
|
|
@@ -63,7 +60,7 @@ const defaultConfig = {
|
|
|
63
60
|
suffix: "Id",
|
|
64
61
|
},
|
|
65
62
|
fileName: {
|
|
66
|
-
namingStrategy:
|
|
63
|
+
namingStrategy: NamingStrategies.PASCAL_CASE,
|
|
67
64
|
prefix: "Q",
|
|
68
65
|
suffix: "",
|
|
69
66
|
},
|
|
@@ -71,7 +68,7 @@ const defaultConfig = {
|
|
|
71
68
|
services: {
|
|
72
69
|
prefix: "",
|
|
73
70
|
suffix: "Service",
|
|
74
|
-
namingStrategy:
|
|
71
|
+
namingStrategy: NamingStrategies.PASCAL_CASE,
|
|
75
72
|
main: {
|
|
76
73
|
applyServiceNaming: true,
|
|
77
74
|
},
|
|
@@ -81,15 +78,15 @@ const defaultConfig = {
|
|
|
81
78
|
applyServiceNaming: true,
|
|
82
79
|
},
|
|
83
80
|
operations: {
|
|
84
|
-
namingStrategy:
|
|
81
|
+
namingStrategy: NamingStrategies.CAMEL_CASE,
|
|
85
82
|
},
|
|
86
83
|
relatedServiceGetter: {
|
|
87
|
-
namingStrategy:
|
|
84
|
+
namingStrategy: NamingStrategies.CAMEL_CASE,
|
|
88
85
|
prefix: "",
|
|
89
86
|
suffix: "",
|
|
90
87
|
},
|
|
91
88
|
privateProps: {
|
|
92
|
-
namingStrategy:
|
|
89
|
+
namingStrategy: NamingStrategies.CAMEL_CASE,
|
|
93
90
|
prefix: "_",
|
|
94
91
|
suffix: "",
|
|
95
92
|
},
|
|
@@ -157,16 +154,14 @@ const minimalNamingConfig = {
|
|
|
157
154
|
/**
|
|
158
155
|
* Creates a defensive copy of the default config.
|
|
159
156
|
*/
|
|
160
|
-
function getDefaultConfig() {
|
|
161
|
-
return (
|
|
157
|
+
export function getDefaultConfig() {
|
|
158
|
+
return deepmerge(defaultConfig, {});
|
|
162
159
|
}
|
|
163
|
-
exports.getDefaultConfig = getDefaultConfig;
|
|
164
160
|
/**
|
|
165
161
|
* Creates a defensive copy of the minimal config: minimal in respect to naming.
|
|
166
162
|
*/
|
|
167
|
-
function getMinimalConfig() {
|
|
168
|
-
const { naming } = defaultConfig, passThrough =
|
|
169
|
-
return (
|
|
163
|
+
export function getMinimalConfig() {
|
|
164
|
+
const { naming } = defaultConfig, passThrough = __rest(defaultConfig, ["naming"]);
|
|
165
|
+
return deepmerge(passThrough, { naming: minimalNamingConfig });
|
|
170
166
|
}
|
|
171
|
-
exports.getMinimalConfig = getMinimalConfig;
|
|
172
167
|
//# sourceMappingURL=defaultConfig.js.map
|
package/lib/defaultConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultConfig.js","sourceRoot":"","sources":["../src/defaultConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"defaultConfig.js","sourceRoot":"","sources":["../src/defaultConfig.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAgB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAc,MAAM,kBAAkB,CAAC;AAGhE;;GAEG;AACH,MAA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AAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,EAAE,MAAM,KAAqB,aAAa,EAA7B,WAAW,UAAK,aAAa,EAA1C,UAA0B,CAAgB,CAAC;IACjD,OAAO,SAAS,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import deepmerge from \"deepmerge\";\r\n\r\nimport { NameSettings, NamingStrategies } from \"./NamingModel.js\";\r\nimport { EmitModes, Modes, RunOptions } from \"./OptionModel.js\";\r\n\r\nexport type DefaultConfiguration = Omit<RunOptions, \"sourceUrl\" | \"source\" | \"output\" | \"serviceName\">;\r\n/**\r\n * The default configuration.\r\n */\r\nconst defaultConfig: DefaultConfiguration = {\r\n sourceUrlConfig: {},\r\n refreshFile: false,\r\n mode: Modes.all,\r\n emitMode: EmitModes.js_dts,\r\n debug: false,\r\n prettier: false,\r\n tsconfig: \"tsconfig.json\",\r\n converters: [],\r\n skipEditableModels: false,\r\n skipIdModels: false,\r\n skipOperations: false,\r\n skipComments: false,\r\n enablePrimitivePropertyServices: false,\r\n disableAutoManagedKey: false,\r\n allowRenaming: false,\r\n v2ModelsWithExtraResultsWrapping: false,\r\n v4BigNumberAsString: false,\r\n disableAutomaticNameClashResolution: false,\r\n bundledFileGeneration: true,\r\n naming: {\r\n models: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\r\n editableModels: {\r\n prefix: \"Editable\",\r\n suffix: \"\",\r\n applyModelNaming: true,\r\n },\r\n idModels: {\r\n prefix: \"\",\r\n suffix: \"Id\",\r\n applyModelNaming: true,\r\n },\r\n operationParamModels: {\r\n prefix: \"\",\r\n suffix: \"Params\",\r\n applyModelNaming: true,\r\n },\r\n fileName: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n prefix: \"\",\r\n suffix: \"Model\",\r\n },\r\n },\r\n queryObjects: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"Q\",\r\n suffix: \"\",\r\n idFunctions: {\r\n prefix: \"\",\r\n suffix: \"Id\",\r\n },\r\n fileName: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n prefix: \"Q\",\r\n suffix: \"\",\r\n },\r\n },\r\n services: {\r\n prefix: \"\",\r\n suffix: \"Service\",\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n main: {\r\n applyServiceNaming: true,\r\n },\r\n collection: {\r\n prefix: \"\",\r\n suffix: \"Collection\",\r\n applyServiceNaming: true,\r\n },\r\n operations: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n },\r\n relatedServiceGetter: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"\",\r\n suffix: \"\",\r\n },\r\n privateProps: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"_\",\r\n suffix: \"\",\r\n },\r\n },\r\n },\r\n propertiesByName: [],\r\n byTypeAndName: [],\r\n};\r\n\r\nconst { models, queryObjects, services } = defaultConfig.naming;\r\nconst minimalNamingConfig: NameSettings = {\r\n models: {\r\n fileName: {\r\n prefix: models.fileName.prefix,\r\n suffix: models.fileName.suffix,\r\n },\r\n idModels: {\r\n applyModelNaming: true,\r\n prefix: models.idModels.prefix,\r\n suffix: models.idModels.suffix,\r\n },\r\n editableModels: {\r\n applyModelNaming: true,\r\n prefix: models.editableModels.prefix,\r\n suffix: models.editableModels.suffix,\r\n },\r\n operationParamModels: {\r\n applyModelNaming: true,\r\n prefix: models.operationParamModels.prefix,\r\n suffix: models.operationParamModels.suffix,\r\n },\r\n },\r\n queryObjects: {\r\n prefix: queryObjects.prefix,\r\n suffix: queryObjects.suffix,\r\n fileName: {\r\n prefix: queryObjects.fileName.prefix,\r\n suffix: queryObjects.fileName.suffix,\r\n },\r\n idFunctions: {\r\n prefix: queryObjects.idFunctions.prefix,\r\n suffix: queryObjects.idFunctions.suffix,\r\n },\r\n },\r\n services: {\r\n prefix: services.prefix,\r\n suffix: services.suffix,\r\n main: {\r\n applyServiceNaming: true,\r\n },\r\n collection: {\r\n applyServiceNaming: true,\r\n prefix: services.collection.prefix,\r\n suffix: services.collection.suffix,\r\n },\r\n privateProps: {\r\n prefix: services.privateProps.prefix,\r\n suffix: services.privateProps.suffix,\r\n },\r\n relatedServiceGetter: {\r\n prefix: services.relatedServiceGetter.prefix,\r\n suffix: services.relatedServiceGetter.suffix,\r\n },\r\n },\r\n};\r\n\r\n/**\r\n * Creates a defensive copy of the default config.\r\n */\r\nexport function getDefaultConfig(): DefaultConfiguration {\r\n return deepmerge(defaultConfig, {});\r\n}\r\n\r\n/**\r\n * Creates a defensive copy of the minimal config: minimal in respect to naming.\r\n */\r\nexport function getMinimalConfig(): DefaultConfiguration {\r\n const { naming, ...passThrough } = defaultConfig;\r\n return deepmerge(passThrough, { naming: minimalNamingConfig });\r\n}\r\n"]}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.downloadMetadata = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
1
|
+
import { __awaiter, __rest } from "tslib";
|
|
2
|
+
import axios from "axios";
|
|
6
3
|
const METADATA_PATH = "$metadata";
|
|
7
4
|
const PWD_BLIND_TEXT = { password: "xxx hidden xxx" };
|
|
8
5
|
function evaluateRequestConfig(url, config) {
|
|
@@ -24,8 +21,8 @@ function evaluateRequestConfig(url, config) {
|
|
|
24
21
|
* @param sourceConfig
|
|
25
22
|
* @param debug
|
|
26
23
|
*/
|
|
27
|
-
function downloadMetadata(sourceUrl, sourceConfig = {}, debug = false) {
|
|
28
|
-
return
|
|
24
|
+
export function downloadMetadata(sourceUrl, sourceConfig = {}, debug = false) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
26
|
// add the $metadata suffix
|
|
30
27
|
const url = sourceUrl.endsWith(METADATA_PATH)
|
|
31
28
|
? sourceUrl
|
|
@@ -35,14 +32,13 @@ function downloadMetadata(sourceUrl, sourceConfig = {}, debug = false) {
|
|
|
35
32
|
const config = evaluateRequestConfig(url, sourceConfig);
|
|
36
33
|
// log request configuration without password
|
|
37
34
|
if (debug) {
|
|
38
|
-
const { auth } = config, loggable =
|
|
35
|
+
const { auth } = config, loggable = __rest(config, ["auth"]);
|
|
39
36
|
const safeConfig = auth ? Object.assign(Object.assign({}, loggable), { auth: Object.assign(Object.assign({}, auth), (auth.password ? PWD_BLIND_TEXT : {})) }) : loggable;
|
|
40
37
|
console.log(`Request configuration:`, safeConfig);
|
|
41
38
|
}
|
|
42
39
|
// execute the request & return response data
|
|
43
|
-
const response = yield
|
|
40
|
+
const response = yield axios.request(config);
|
|
44
41
|
return response.data;
|
|
45
42
|
});
|
|
46
43
|
}
|
|
47
|
-
exports.downloadMetadata = downloadMetadata;
|
|
48
44
|
//# sourceMappingURL=downloadMetadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadMetadata.js","sourceRoot":"","sources":["../../src/download/downloadMetadata.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"downloadMetadata.js","sourceRoot":"","sources":["../../src/download/downloadMetadata.ts"],"names":[],"mappings":";AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAIlD,MAAM,aAAa,GAAG,WAAW,CAAC;AAClC,MAAM,cAAc,GAAG,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAC;AAEtD,SAAS,qBAAqB,CAAC,GAAW,EAAE,MAA8B;IACxE,MAAM,gBAAgB,GAAuB,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IACzE,MAAM,SAAS,GAAuB,MAAM,CAAC,MAAM;QACjD,CAAC,CAAC,MAAM,CAAC,MAAM;QACf,CAAC,CAAC,OAAO,MAAM,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,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7C,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CAAA","sourcesContent":["import axios, { AxiosRequestConfig } from \"axios\";\r\n\r\nimport { UrlSourceConfiguration } from \"../OptionModel.js\";\r\n\r\nconst METADATA_PATH = \"$metadata\";\r\nconst PWD_BLIND_TEXT = { password: \"xxx hidden xxx\" };\r\n\r\nfunction evaluateRequestConfig(url: string, config: UrlSourceConfiguration): AxiosRequestConfig {\r\n const defaultReqConfig: AxiosRequestConfig = { url: url, method: \"GET\" };\r\n const reqConfig: AxiosRequestConfig = config.custom\r\n ? config.custom\r\n : typeof config.username === \"string\" && typeof config?.password === \"string\"\r\n ? { auth: { username: config.username, password: config.password } }\r\n : {};\r\n return { ...defaultReqConfig, ...reqConfig };\r\n}\r\n\r\n/**\r\n * Retrieves the metadata from the given URL using the given configuration.\r\n *\r\n * Failure handling must be implemented by consumer.\r\n * Exception is thrown for failed requests (400, 401, ...).\r\n *\r\n * @param sourceUrl\r\n * @param sourceConfig\r\n * @param debug\r\n */\r\nexport async function downloadMetadata(\r\n sourceUrl: string,\r\n sourceConfig: UrlSourceConfiguration = {},\r\n debug: boolean = false\r\n): Promise<string> {\r\n // add the $metadata suffix\r\n const url = sourceUrl.endsWith(METADATA_PATH)\r\n ? sourceUrl\r\n : sourceUrl + (sourceUrl.endsWith(\"/\") ? \"\" : \"/\") + METADATA_PATH;\r\n console.log(`Reading metadata from URL:`, url);\r\n\r\n // evaluate configured request config options\r\n const config = evaluateRequestConfig(url, sourceConfig);\r\n\r\n // log request configuration without password\r\n if (debug) {\r\n const { auth, ...loggable } = config;\r\n const safeConfig = auth ? { ...loggable, auth: { ...auth, ...(auth.password ? PWD_BLIND_TEXT : {}) } } : loggable;\r\n console.log(`Request configuration:`, safeConfig);\r\n }\r\n\r\n // execute the request & return response data\r\n const response = await axios.request(config);\r\n return response.data;\r\n}\r\n"]}
|
package/lib/download/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { downloadMetadata } from "./downloadMetadata";
|
|
2
|
-
export { storeMetadata } from "./storeMetadata";
|
|
1
|
+
export { downloadMetadata } from "./downloadMetadata.js";
|
|
2
|
+
export { storeMetadata } from "./storeMetadata.js";
|
package/lib/download/index.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.storeMetadata = exports.downloadMetadata = void 0;
|
|
4
|
-
var downloadMetadata_1 = require("./downloadMetadata");
|
|
5
|
-
Object.defineProperty(exports, "downloadMetadata", { enumerable: true, get: function () { return downloadMetadata_1.downloadMetadata; } });
|
|
6
|
-
var storeMetadata_1 = require("./storeMetadata");
|
|
7
|
-
Object.defineProperty(exports, "storeMetadata", { enumerable: true, get: function () { return storeMetadata_1.storeMetadata; } });
|
|
1
|
+
export { downloadMetadata } from "./downloadMetadata.js";
|
|
2
|
+
export { storeMetadata } from "./storeMetadata.js";
|
|
8
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/download/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/download/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { downloadMetadata } from \"./downloadMetadata.js\";\r\nexport { storeMetadata } from \"./storeMetadata.js\";\r\n"]}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const fs_extra_1 = require("fs-extra");
|
|
7
|
-
const prettier_1 = tslib_1.__importDefault(require("prettier"));
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { mkdirp } from "mkdirp";
|
|
5
|
+
import { format, resolveConfig } from "prettier";
|
|
8
6
|
/**
|
|
9
7
|
* Write (prettified) data to disk.
|
|
10
8
|
*
|
|
@@ -12,17 +10,17 @@ const prettier_1 = tslib_1.__importDefault(require("prettier"));
|
|
|
12
10
|
* @param metadataXml
|
|
13
11
|
* @param prettify
|
|
14
12
|
*/
|
|
15
|
-
function storeMetadata(filePath, metadataXml, prettify) {
|
|
16
|
-
return
|
|
17
|
-
const outDir =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
:
|
|
22
|
-
|
|
23
|
-
yield (
|
|
13
|
+
export function storeMetadata(filePath, metadataXml, prettify) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const outDir = path.dirname(filePath);
|
|
16
|
+
let prettified = metadataXml;
|
|
17
|
+
if (prettify) {
|
|
18
|
+
const prettierConfig = yield resolveConfig(outDir);
|
|
19
|
+
prettified = yield format(metadataXml, Object.assign(Object.assign({}, prettierConfig), { parser: "xml", plugins: ["@prettier/plugin-xml"] }));
|
|
20
|
+
}
|
|
21
|
+
yield mkdirp(outDir);
|
|
22
|
+
yield writeFile(filePath, prettified);
|
|
24
23
|
return prettified;
|
|
25
24
|
});
|
|
26
25
|
}
|
|
27
|
-
exports.storeMetadata = storeMetadata;
|
|
28
26
|
//# sourceMappingURL=storeMetadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storeMetadata.js","sourceRoot":"","sources":["../../src/download/storeMetadata.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"storeMetadata.js","sourceRoot":"","sources":["../../src/download/storeMetadata.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,UAAgB,aAAa,CAAC,QAAgB,EAAE,WAAmB,EAAE,QAAiB;;QAC1F,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAEtC,IAAI,UAAU,GAAG,WAAW,CAAC;QAC7B,IAAI,QAAQ,EAAE;YACZ,MAAM,cAAc,GAAG,MAAM,aAAa,CAAC,MAAM,CAAC,CAAC;YACnD,UAAU,GAAG,MAAM,MAAM,CACvB,WAAW,kCAEN,cAAc,KAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,sBAAsB,CAAC,IACtE,CAAC;SACH;QAED,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;QACrB,MAAM,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAEtC,OAAO,UAAU,CAAC;IACpB,CAAC;CAAA","sourcesContent":["import { writeFile } from \"node:fs/promises\";\r\nimport path from \"node:path\";\r\nimport { mkdirp } from \"mkdirp\";\r\nimport { format, resolveConfig } from \"prettier\";\r\n\r\n/**\r\n * Write (prettified) data to disk.\r\n *\r\n * @param filePath\r\n * @param metadataXml\r\n * @param prettify\r\n */\r\nexport async function storeMetadata(filePath: string, metadataXml: string, prettify: boolean) {\r\n const outDir = path.dirname(filePath);\r\n\r\n let prettified = metadataXml;\r\n if (prettify) {\r\n const prettierConfig = await resolveConfig(outDir);\r\n prettified = await format(\r\n metadataXml,\r\n // @ts-ignore: xmlWhitespaceSensitivity is an option of the plugin\r\n { ...prettierConfig, parser: \"xml\", plugins: [\"@prettier/plugin-xml\"] },\r\n );\r\n }\r\n\r\n await mkdirp(outDir);\r\n await writeFile(filePath, prettified);\r\n\r\n return prettified;\r\n}\r\n"]}
|
package/lib/evaluateConfig.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CliOptions, ConfigFileOptions, RunOptions } from "./OptionModel";
|
|
1
|
+
import { CliOptions, ConfigFileOptions, RunOptions } from "./OptionModel.js";
|
|
2
2
|
/**
|
|
3
3
|
* Provides default values and evaluates the various config file and CLI options.
|
|
4
4
|
* This function always returns a list of RunOptions,
|
package/lib/evaluateConfig.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const deepmerge_1 = tslib_1.__importDefault(require("deepmerge"));
|
|
6
|
-
const defaultConfig_1 = require("./defaultConfig");
|
|
7
|
-
const OptionModel_1 = require("./OptionModel");
|
|
1
|
+
import { __rest } from "tslib";
|
|
2
|
+
import deepmerge from "deepmerge";
|
|
3
|
+
import { getDefaultConfig, getMinimalConfig } from "./defaultConfig.js";
|
|
4
|
+
import { Modes } from "./OptionModel.js";
|
|
8
5
|
/**
|
|
9
6
|
* Provides default values and evaluates the various config file and CLI options.
|
|
10
7
|
* This function always returns a list of RunOptions,
|
|
@@ -28,25 +25,25 @@ const OptionModel_1 = require("./OptionModel");
|
|
|
28
25
|
* @param cliOpts CLI passed options
|
|
29
26
|
* @param configOpts config file options
|
|
30
27
|
*/
|
|
31
|
-
function evaluateConfigOptions(cliOpts, configOpts) {
|
|
28
|
+
export function evaluateConfigOptions(cliOpts, configOpts) {
|
|
32
29
|
var _a;
|
|
33
|
-
const defaultConfig = ((_a = configOpts === null || configOpts === void 0 ? void 0 : configOpts.naming) === null || _a === void 0 ? void 0 : _a.minimalDefaults) ?
|
|
30
|
+
const defaultConfig = ((_a = configOpts === null || configOpts === void 0 ? void 0 : configOpts.naming) === null || _a === void 0 ? void 0 : _a.minimalDefaults) ? getMinimalConfig() : getDefaultConfig();
|
|
34
31
|
// No config file
|
|
35
32
|
if (!configOpts) {
|
|
36
33
|
if (!cliOpts.source || !cliOpts.output) {
|
|
37
34
|
throw new Error("Without any configuration file options --source and --output must be specified!");
|
|
38
35
|
}
|
|
39
|
-
return [(
|
|
36
|
+
return [deepmerge(defaultConfig, cliOpts)];
|
|
40
37
|
}
|
|
41
|
-
const { services: cliServices, source, output } = cliOpts, cliBaseOpts =
|
|
42
|
-
const { services: confServices } = configOpts, confBaseOpts =
|
|
38
|
+
const { services: cliServices, source, output } = cliOpts, cliBaseOpts = __rest(cliOpts, ["services", "source", "output"]);
|
|
39
|
+
const { services: confServices } = configOpts, confBaseOpts = __rest(configOpts, ["services"]);
|
|
43
40
|
// No configurations of services in config file
|
|
44
41
|
// or CLI opts specify source and output => ignore service config
|
|
45
42
|
if ((source && output) || !confServices) {
|
|
46
43
|
if (!source || !output) {
|
|
47
44
|
throw new Error("No services were configured in config file, so options --source and --output must be specified!");
|
|
48
45
|
}
|
|
49
|
-
const merged =
|
|
46
|
+
const merged = deepmerge.all([defaultConfig, confBaseOpts, cliOpts]);
|
|
50
47
|
return [safeGuardOptions(merged)];
|
|
51
48
|
}
|
|
52
49
|
// Either services are specified or we use all configured services
|
|
@@ -57,25 +54,24 @@ function evaluateConfigOptions(cliOpts, configOpts) {
|
|
|
57
54
|
if (!service) {
|
|
58
55
|
throw new Error(`Specified service "${s}" doesn't exist in configuration!`);
|
|
59
56
|
}
|
|
60
|
-
const serviceDefault = ((_a = service.naming) === null || _a === void 0 ? void 0 : _a.minimalDefaults) && !((_b = configOpts.naming) === null || _b === void 0 ? void 0 : _b.minimalDefaults) ?
|
|
61
|
-
const merged =
|
|
57
|
+
const serviceDefault = ((_a = service.naming) === null || _a === void 0 ? void 0 : _a.minimalDefaults) && !((_b = configOpts.naming) === null || _b === void 0 ? void 0 : _b.minimalDefaults) ? getMinimalConfig() : defaultConfig;
|
|
58
|
+
const merged = deepmerge.all([serviceDefault, confBaseOpts, service, cliBaseOpts]);
|
|
62
59
|
return safeGuardOptions(merged);
|
|
63
60
|
});
|
|
64
61
|
}
|
|
65
|
-
exports.evaluateConfigOptions = evaluateConfigOptions;
|
|
66
62
|
/**
|
|
67
63
|
* Make sure that some options are only active if in correct mode.
|
|
68
64
|
* @param options
|
|
69
65
|
*/
|
|
70
66
|
function safeGuardOptions(options) {
|
|
71
67
|
// skip options are not valid for service generation
|
|
72
|
-
if (options.mode ===
|
|
68
|
+
if (options.mode === Modes.service || options.mode === Modes.all) {
|
|
73
69
|
options.skipEditableModels = false;
|
|
74
70
|
options.skipIdModels = false;
|
|
75
71
|
options.skipOperations = false;
|
|
76
72
|
}
|
|
77
73
|
// special option which is only valid for model generation
|
|
78
|
-
if (options.mode !==
|
|
74
|
+
if (options.mode !== Modes.models) {
|
|
79
75
|
options.v2ModelsWithExtraResultsWrapping = false;
|
|
80
76
|
}
|
|
81
77
|
return options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateConfig.js","sourceRoot":"","sources":["../src/evaluateConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"evaluateConfig.js","sourceRoot":"","sources":["../src/evaluateConfig.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAiC,KAAK,EAAc,MAAM,kBAAkB,CAAC;AAEpF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAmB,EACnB,UAAyC;;IAEzC,MAAM,aAAa,GAAG,CAAA,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,0CAAE,eAAe,EAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACpG,iBAAiB;IACjB,IAAI,CAAC,UAAU,EAAE;QACf,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACtC,MAAM,IAAI,KAAK,CAAC,iFAAiF,CAAC,CAAC;SACpG;QACD,OAAO,CAAC,SAAS,CAAC,aAAa,EAAE,OAAO,C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C,GAAG,CAAC,CAAC,cAAc,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,CAAC,CAAe,CAAC;QACjG,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CAAC,OAAmB;IAC3C,oDAAoD;IACpD,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,CAAC,GAAG,EAAE;QAChE,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC;QACnC,OAAO,CAAC,YAAY,GAAG,KAAK,CAAC;QAC7B,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC;KAChC;IACD,0DAA0D;IAC1D,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,CAAC,MAAM,EAAE;QACjC,OAAO,CAAC,gCAAgC,GAAG,KAAK,CAAC;KAClD;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import deepmerge from \"deepmerge\";\r\n\r\nimport { getDefaultConfig, getMinimalConfig } from \"./defaultConfig.js\";\r\nimport { CliOptions, ConfigFileOptions, Modes, RunOptions } from \"./OptionModel.js\";\r\n\r\n/**\r\n * Provides default values and evaluates the various config file and CLI options.\r\n * This function always returns a list of RunOptions,\r\n * whereby each item represents one generation run / one service.\r\n *\r\n * Configurations are merged in the following order (last one wins):\r\n * - default values\r\n * - config file: base settings\r\n * - config file: service specific settings\r\n * - CLI options\r\n *\r\n * If the CLI options specify source and output, then the service config is completely ignored and only the\r\n * base settings are applied from the config file.\r\n *\r\n * If the CLI options do not specify source and output, but do specify services, then these services must\r\n * exist in the config file and each service must supply values for source and output as a minimum.\r\n *\r\n * If the CLI options neither entail source nor services, then at least one service must be configured in the\r\n * config file. All configured services are returned.\r\n *\r\n * @param cliOpts CLI passed options\r\n * @param configOpts config file options\r\n */\r\nexport function evaluateConfigOptions(\r\n cliOpts: CliOptions,\r\n configOpts: ConfigFileOptions | undefined\r\n): Array<RunOptions> {\r\n const defaultConfig = configOpts?.naming?.minimalDefaults ? getMinimalConfig() : getDefaultConfig();\r\n // No config file\r\n if (!configOpts) {\r\n if (!cliOpts.source || !cliOpts.output) {\r\n throw new Error(\"Without any configuration file options --source and --output must be specified!\");\r\n }\r\n return [deepmerge(defaultConfig, cliOpts)];\r\n }\r\n\r\n const { services: cliServices, source, output, ...cliBaseOpts } = cliOpts;\r\n const { services: confServices, ...confBaseOpts } = configOpts;\r\n\r\n // No configurations of services in config file\r\n // or CLI opts specify source and output => ignore service config\r\n if ((source && output) || !confServices) {\r\n if (!source || !output) {\r\n throw new Error(\r\n \"No services were configured in config file, so options --source and --output must be specified!\"\r\n );\r\n }\r\n const merged = deepmerge.all([defaultConfig, confBaseOpts, cliOpts]) as RunOptions;\r\n return [safeGuardOptions(merged)];\r\n }\r\n\r\n // Either services are specified or we use all configured services\r\n const servicesToUse = cliServices?.length ? cliServices : Object.keys(confServices);\r\n return servicesToUse.map((s) => {\r\n const service = confServices[s];\r\n if (!service) {\r\n throw new Error(`Specified service \"${s}\" doesn't exist in configuration!`);\r\n }\r\n const serviceDefault =\r\n service.naming?.minimalDefaults && !configOpts.naming?.minimalDefaults ? getMinimalConfig() : defaultConfig;\r\n const merged = deepmerge.all([serviceDefault, confBaseOpts, service, cliBaseOpts]) as RunOptions;\r\n return safeGuardOptions(merged);\r\n });\r\n}\r\n\r\n/**\r\n * Make sure that some options are only active if in correct mode.\r\n * @param options\r\n */\r\nfunction safeGuardOptions(options: RunOptions): RunOptions {\r\n // skip options are not valid for service generation\r\n if (options.mode === Modes.service || options.mode === Modes.all) {\r\n options.skipEditableModels = false;\r\n options.skipIdModels = false;\r\n options.skipOperations = false;\r\n }\r\n // special option which is only valid for model generation\r\n if (options.mode !== Modes.models) {\r\n options.v2ModelsWithExtraResultsWrapping = false;\r\n }\r\n\r\n return options;\r\n}\r\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ODataVersions } from "@odata2ts/odata-core";
|
|
2
2
|
import { ImportDeclarationStructure, OptionalKind } from "ts-morph";
|
|
3
|
-
import { DataModel } from "../data-model/DataModel";
|
|
4
|
-
import { ClientApiImports, CoreImports, QueryObjectImports, ServiceImports } from "./import/ImportObjects";
|
|
3
|
+
import { DataModel } from "../data-model/DataModel.js";
|
|
4
|
+
import { ClientApiImports, CoreImports, QueryObjectImports, ServiceImports } from "./import/ImportObjects.js";
|
|
5
5
|
/**
|
|
6
6
|
* Handles all the import statements for a given file.
|
|
7
7
|
*
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
|
-
const odata_core_1 = require("@odata2ts/odata-core");
|
|
7
|
-
const ImportObjects_1 = require("./import/ImportObjects");
|
|
8
|
-
const ImportedNameValidator_1 = require("./ImportedNameValidator");
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { ODataVersions } from "@odata2ts/odata-core";
|
|
3
|
+
import { ClientApiImports, CoreImports, LIB_MODULES, ServiceImports, VERSIONED_CORE_IMPORTS, VERSIONED_SERVICE_IMPORTS, } from "./import/ImportObjects.js";
|
|
4
|
+
import { ImportedNameValidator } from "./ImportedNameValidator.js";
|
|
9
5
|
/**
|
|
10
6
|
* Handles all the import statements for a given file.
|
|
11
7
|
*
|
|
@@ -14,7 +10,7 @@ const ImportedNameValidator_1 = require("./ImportedNameValidator");
|
|
|
14
10
|
*
|
|
15
11
|
* Map<string,string>
|
|
16
12
|
*/
|
|
17
|
-
class ImportContainer {
|
|
13
|
+
export class ImportContainer {
|
|
18
14
|
constructor(path, fileName, dataModel, mainFileNames, bundledFileGeneration, reservedNames) {
|
|
19
15
|
this.path = path;
|
|
20
16
|
this.fileName = fileName;
|
|
@@ -38,18 +34,18 @@ class ImportContainer {
|
|
|
38
34
|
clientApi: { regular: new Map(), typeOnly: new Map() },
|
|
39
35
|
service: { regular: new Map(), typeOnly: new Map() },
|
|
40
36
|
};
|
|
41
|
-
this.importedNameValidator = new
|
|
37
|
+
this.importedNameValidator = new ImportedNameValidator(reservedNames);
|
|
42
38
|
}
|
|
43
39
|
addCoreLib(odataVersion, coreLib) {
|
|
44
|
-
const isVersioned =
|
|
45
|
-
const name =
|
|
46
|
-
const importName = this.importedNameValidator.validateName(
|
|
40
|
+
const isVersioned = VERSIONED_CORE_IMPORTS.includes(coreLib);
|
|
41
|
+
const name = CoreImports[coreLib] + (isVersioned ? ODataVersions[odataVersion] : "");
|
|
42
|
+
const importName = this.importedNameValidator.validateName(LIB_MODULES.core, name);
|
|
47
43
|
// TODO: currently only types are imported, however enums could potentially be imported too
|
|
48
44
|
this.libs.core.typeOnly.set(name, importName);
|
|
49
45
|
return importName;
|
|
50
46
|
}
|
|
51
47
|
addFromQObject(name, typeOnlyImport = false) {
|
|
52
|
-
const importName = this.importedNameValidator.validateName(
|
|
48
|
+
const importName = this.importedNameValidator.validateName(LIB_MODULES.qObject, name);
|
|
53
49
|
const imports = typeOnlyImport ? this.libs.qObject.typeOnly : this.libs.qObject.regular;
|
|
54
50
|
imports.set(name, importName);
|
|
55
51
|
return importName;
|
|
@@ -61,16 +57,16 @@ class ImportContainer {
|
|
|
61
57
|
return this.addFromQObject(qObject, true);
|
|
62
58
|
}
|
|
63
59
|
addClientApi(clientApi) {
|
|
64
|
-
const name =
|
|
65
|
-
const importName = this.importedNameValidator.validateName(
|
|
60
|
+
const name = ClientApiImports[clientApi];
|
|
61
|
+
const importName = this.importedNameValidator.validateName(LIB_MODULES.clientApi, name);
|
|
66
62
|
// complete client api consists only of types
|
|
67
63
|
this.libs.clientApi.typeOnly.set(name, importName);
|
|
68
64
|
return importName;
|
|
69
65
|
}
|
|
70
66
|
addServiceObject(odataVersion, serviceObject) {
|
|
71
|
-
const isVersioned =
|
|
72
|
-
const name =
|
|
73
|
-
const importName = this.importedNameValidator.validateName(
|
|
67
|
+
const isVersioned = VERSIONED_SERVICE_IMPORTS.includes(serviceObject);
|
|
68
|
+
const name = ServiceImports[serviceObject] + (isVersioned ? ODataVersions[odataVersion] : "");
|
|
69
|
+
const importName = this.importedNameValidator.validateName(LIB_MODULES.service, name);
|
|
74
70
|
// only regular imports for the service package
|
|
75
71
|
this.libs.service.regular.set(name, importName);
|
|
76
72
|
return importName;
|
|
@@ -152,7 +148,7 @@ class ImportContainer {
|
|
|
152
148
|
getImportDeclarations() {
|
|
153
149
|
return [
|
|
154
150
|
...Object.entries(this.libs).reduce((result, [moduleName, toImport]) => {
|
|
155
|
-
const module =
|
|
151
|
+
const module = LIB_MODULES[moduleName];
|
|
156
152
|
if (toImport.typeOnly.size) {
|
|
157
153
|
result.push(this.createImportDecl(module, toImport.typeOnly, true));
|
|
158
154
|
}
|
|
@@ -192,9 +188,8 @@ class ImportContainer {
|
|
|
192
188
|
}));
|
|
193
189
|
}
|
|
194
190
|
getModuleSpecifier(filePath) {
|
|
195
|
-
const relativePath =
|
|
191
|
+
const relativePath = path.relative(this.path, filePath).replaceAll(path.sep, "/");
|
|
196
192
|
return !relativePath.startsWith(".") ? "./" + relativePath : relativePath;
|
|
197
193
|
}
|
|
198
194
|
}
|
|
199
|
-
exports.ImportContainer = ImportContainer;
|
|
200
195
|
//# sourceMappingURL=ImportContainer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportContainer.js","sourceRoot":"","sources":["../../src/generator/ImportContainer.ts"],"names":[],"mappings":";;;;AAAA,wDAAwB;AAExB,qDAAqD;AAKrD,0DAQgC;AAChC,mEAAgE;AAOhE;;;;;;;GAOG;AACH,MAAa,eAAe;IAoB1B,YACY,IAAY,EACZ,QAAgB,EAChB,SAAoB,EACpB,aAAkE,EACzD,qBAA8B,EACvC,aAAwC;QALxC,SAAI,GAAJ,IAAI,CAAQ;QACZ,aAAQ,GAAR,QAAQ,CAAQ;QAChB,cAAS,GAAT,SAAS,CAAW;QACpB,kBAAa,GAAb,aAAa,C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gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACjD,CAAC,CAAC;SACL,CAAC;IACJ,CAAC;IAEO,eAAe,CAAC,QAA6B;QACnD,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YACrD,IAAI;YACJ,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SAC1C,CAAC,CAAC,CAAC;IACN,CAAC;IAEO,kBAAkB,CAAC,QAAgB;QACzC,MAAM,YAAY,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,UAAU,CAAC,cAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAClF,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC;IAC5E,CAAC;CACF;AA1ND,0CA0NC","sourcesContent":["import path from \"path\";\r\n\r\nimport { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { ImportDeclarationStructure, OptionalKind } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport { ComplexType } from \"../data-model/DataTypeModel\";\r\nimport {\r\n ClientApiImports,\r\n CoreImports,\r\n LIB_MODULES,\r\n QueryObjectImports,\r\n ServiceImports,\r\n VERSIONED_CORE_IMPORTS,\r\n VERSIONED_SERVICE_IMPORTS,\r\n} from \"./import/ImportObjects\";\r\nimport { ImportedNameValidator } from \"./ImportedNameValidator\";\r\n\r\ntype ImportContainerType = Record<\r\n keyof typeof LIB_MODULES,\r\n { regular: Map<string, string>; typeOnly: Map<string, string> }\r\n>;\r\n\r\n/**\r\n * Handles all the import statements for a given file.\r\n *\r\n * Features a renaming mechanism, so that when the import name conflicts with an existing import a new\r\n * name is generated and returned.\r\n *\r\n * Map<string,string>\r\n */\r\nexport class ImportContainer {\r\n private readonly importedNameValidator: ImportedNameValidator;\r\n // mapping of a custom defined type to a primitive type\r\n private customTypes = {\r\n regular: new Map<string, Map<string, string>>(),\r\n typeOnly: new Map<string, Map<string, string>>(),\r\n };\r\n // imports to generated artefacts\r\n private internalImports = {\r\n regular: new Map<string, Map<string, string>>(),\r\n typeOnly: new Map<string, Map<string, string>>(),\r\n };\r\n\r\n private libs: ImportContainerType = {\r\n core: { regular: new Map(), typeOnly: new Map() },\r\n qObject: { regular: new Map(), typeOnly: new Map() },\r\n clientApi: { regular: new Map(), typeOnly: new Map() },\r\n service: { regular: new Map(), typeOnly: new Map() },\r\n };\r\n\r\n constructor(\r\n protected path: string,\r\n protected fileName: string,\r\n protected dataModel: DataModel,\r\n protected mainFileNames: { model: string; qObject: string; service: string },\r\n protected readonly bundledFileGeneration: boolean,\r\n protected reservedNames: Array<string> | undefined\r\n ) {\r\n this.importedNameValidator = new ImportedNameValidator(reservedNames);\r\n }\r\n\r\n public addCoreLib(odataVersion: ODataVersions, coreLib: CoreImports) {\r\n const isVersioned = VERSIONED_CORE_IMPORTS.includes(coreLib);\r\n const name = CoreImports[coreLib] + (isVersioned ? ODataVersions[odataVersion] : \"\");\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.core, name);\r\n\r\n // TODO: currently only types are imported, however enums could potentially be imported too\r\n this.libs.core.typeOnly.set(name, importName);\r\n\r\n return importName;\r\n }\r\n\r\n private addFromQObject(name: string, typeOnlyImport = false) {\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.qObject, name);\r\n\r\n const imports = typeOnlyImport ? this.libs.qObject.typeOnly : this.libs.qObject.regular;\r\n imports.set(name, importName);\r\n\r\n return importName;\r\n }\r\n\r\n public addQObject(qObject: QueryObjectImports | string) {\r\n return this.addFromQObject(qObject);\r\n }\r\n\r\n public addQObjectType(qObject: string) {\r\n return this.addFromQObject(qObject, true);\r\n }\r\n\r\n public addClientApi(clientApi: ClientApiImports) {\r\n const name = ClientApiImports[clientApi];\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.clientApi, name);\r\n\r\n // complete client api consists only of types\r\n this.libs.clientApi.typeOnly.set(name, importName);\r\n return importName;\r\n }\r\n\r\n public addServiceObject(odataVersion: ODataVersions, serviceObject: ServiceImports) {\r\n const isVersioned = VERSIONED_SERVICE_IMPORTS.includes(serviceObject);\r\n const name = ServiceImports[serviceObject] + (isVersioned ? ODataVersions[odataVersion] : \"\");\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.service, name);\r\n\r\n // only regular imports for the service package\r\n this.libs.service.regular.set(name, importName);\r\n return importName;\r\n }\r\n\r\n public addCustomType(moduleName: string, typeName: string, isTypeOnly: boolean = false) {\r\n const importName = this.importedNameValidator.validateName(moduleName, typeName);\r\n const imports = isTypeOnly ? this.customTypes.typeOnly : this.customTypes.regular;\r\n let importList = imports.get(moduleName);\r\n if (!importList) {\r\n importList = new Map();\r\n imports.set(moduleName, importList);\r\n }\r\n\r\n importList.set(typeName, importName);\r\n return importName;\r\n }\r\n\r\n private pathAndFile(filePath: string, fileName: string) {\r\n return filePath ? `${filePath}/${fileName}` : fileName;\r\n }\r\n\r\n private isDifferentFile(filePath: string, fileName: string) {\r\n return this.pathAndFile(this.path, this.fileName) !== this.pathAndFile(filePath, fileName);\r\n }\r\n\r\n private addGeneratedImport(folderPath: string, fileName: string, name: string, isTypeOnly = false): string {\r\n // imports are only relevant for different files\r\n if (!this.isDifferentFile(folderPath, fileName)) {\r\n return name;\r\n }\r\n\r\n const moduleName = this.pathAndFile(folderPath, fileName);\r\n const importName = this.importedNameValidator.validateName(moduleName, name);\r\n const imports = isTypeOnly ? this.internalImports.typeOnly : this.internalImports.regular;\r\n\r\n const importList = imports.get(moduleName) || new Map<string, string>();\r\n importList.set(name, importName);\r\n imports.set(moduleName, importList);\r\n\r\n return importName;\r\n }\r\n\r\n public addGeneratedModel(fqName: string, name: string): string {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.model, name, true);\r\n } else {\r\n const model = this.dataModel.getModel(fqName) as ComplexType | undefined;\r\n if (!model && fqName !== \"\") {\r\n throw new Error(`Cannot find model by its fully qualified name: ${fqName}!`);\r\n }\r\n\r\n const folderPath = model ? model.folderPath : \"\";\r\n const modelName = model ? model.modelName : this.mainFileNames.model;\r\n return this.addGeneratedImport(folderPath, modelName, name, true);\r\n }\r\n }\r\n\r\n public addGeneratedQObject(fqName: string, name: string, isTypeOnly = false) {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.qObject, name, isTypeOnly);\r\n } else {\r\n const model = this.dataModel.getModel(fqName) as ComplexType | undefined;\r\n if (!model && fqName !== \"\") {\r\n throw new Error(`Cannot find q-object by its fully qualified name: ${fqName}!`);\r\n }\r\n\r\n const folderPath = model ? model.folderPath : \"\";\r\n const qName = model ? model.qName : this.mainFileNames!.qObject;\r\n return this.addGeneratedImport(folderPath, qName, name, isTypeOnly);\r\n }\r\n }\r\n\r\n public addGeneratedService(fqName: string, name: string) {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.service, name);\r\n } else {\r\n const model = this.dataModel.getModel(fqName) as ComplexType;\r\n return this.addGeneratedImport(model.folderPath, model.serviceName, name);\r\n }\r\n }\r\n\r\n private createImportDecl(\r\n module: string,\r\n toImport: Map<string, string>,\r\n isTypeOnly = false\r\n ): OptionalKind<ImportDeclarationStructure> {\r\n return {\r\n namedImports: this.getNamedImports(toImport),\r\n moduleSpecifier: module,\r\n isTypeOnly,\r\n };\r\n }\r\n\r\n public getImportDeclarations(): Array<OptionalKind<ImportDeclarationStructure>> {\r\n return [\r\n ...Object.entries(this.libs).reduce<Array<OptionalKind<ImportDeclarationStructure>>>(\r\n (result, [moduleName, toImport]) => {\r\n const module = LIB_MODULES[moduleName as keyof typeof LIB_MODULES];\r\n if (toImport.typeOnly.size) {\r\n result.push(this.createImportDecl(module, toImport.typeOnly, true));\r\n }\r\n if (toImport.regular.size) {\r\n result.push(this.createImportDecl(module, toImport.regular));\r\n }\r\n return result;\r\n },\r\n []\r\n ),\r\n ...[...this.customTypes.typeOnly]\r\n .filter(([moduleName, toImport]) => toImport.size > 0)\r\n .map(([moduleName, toImport]) => {\r\n return this.createImportDecl(moduleName, toImport, true);\r\n }),\r\n ...[...this.customTypes.regular]\r\n .filter(([moduleName, toImport]) => toImport.size > 0)\r\n .map(([moduleName, toImport]) => {\r\n return this.createImportDecl(moduleName, toImport);\r\n }),\r\n ...[...this.internalImports.typeOnly]\r\n .filter(([_, toImport]) => toImport.size > 0)\r\n .map(([key, toImport]) => {\r\n const module = this.getModuleSpecifier(key);\r\n return this.createImportDecl(module, toImport, true);\r\n }),\r\n ...[...this.internalImports.regular]\r\n .filter(([_, toImport]) => toImport.size > 0)\r\n .map(([key, toImport]) => {\r\n const module = this.getModuleSpecifier(key);\r\n return this.createImportDecl(module, toImport);\r\n }),\r\n ];\r\n }\r\n\r\n private getNamedImports(toImport: Map<string, string>): Array<{ name: string; alias: string | undefined }> {\r\n return [...toImport.entries()].map(([name, alias]) => ({\r\n name,\r\n alias: alias !== name ? alias : undefined,\r\n }));\r\n }\r\n\r\n private getModuleSpecifier(filePath: string): string {\r\n const relativePath = path.relative(this.path, filePath).replaceAll(path.sep, \"/\");\r\n return !relativePath.startsWith(\".\") ? \"./\" + relativePath : relativePath;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ImportContainer.js","sourceRoot":"","sources":["../../src/generator/ImportContainer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAKrD,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,WAAW,EAEX,cAAc,EACd,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;A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AC,OAAO,CAAC;iBACjC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAC;iBAC5C,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,EAAE;gBACvB,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;gBAC5C,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACjD,CAAC,CAAC;SACL,CAAC;IACJ,CAAC;IAEO,eAAe,CAAC,QAA6B;QACnD,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YACrD,IAAI;YACJ,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SAC1C,CAAC,CAAC,CAAC;IACN,CAAC;IAEO,kBAAkB,CAAC,QAAgB;QACzC,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAClF,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC;IAC5E,CAAC;CACF","sourcesContent":["import path from \"path\";\r\n\r\nimport { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { ImportDeclarationStructure, OptionalKind } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel.js\";\r\nimport { ComplexType } from \"../data-model/DataTypeModel.js\";\r\nimport {\r\n ClientApiImports,\r\n CoreImports,\r\n LIB_MODULES,\r\n QueryObjectImports,\r\n ServiceImports,\r\n VERSIONED_CORE_IMPORTS,\r\n VERSIONED_SERVICE_IMPORTS,\r\n} from \"./import/ImportObjects.js\";\r\nimport { ImportedNameValidator } from \"./ImportedNameValidator.js\";\r\n\r\ntype ImportContainerType = Record<\r\n keyof typeof LIB_MODULES,\r\n { regular: Map<string, string>; typeOnly: Map<string, string> }\r\n>;\r\n\r\n/**\r\n * Handles all the import statements for a given file.\r\n *\r\n * Features a renaming mechanism, so that when the import name conflicts with an existing import a new\r\n * name is generated and returned.\r\n *\r\n * Map<string,string>\r\n */\r\nexport class ImportContainer {\r\n private readonly importedNameValidator: ImportedNameValidator;\r\n // mapping of a custom defined type to a primitive type\r\n private customTypes = {\r\n regular: new Map<string, Map<string, string>>(),\r\n typeOnly: new Map<string, Map<string, string>>(),\r\n };\r\n // imports to generated artefacts\r\n private internalImports = {\r\n regular: new Map<string, Map<string, string>>(),\r\n typeOnly: new Map<string, Map<string, string>>(),\r\n };\r\n\r\n private libs: ImportContainerType = {\r\n core: { regular: new Map(), typeOnly: new Map() },\r\n qObject: { regular: new Map(), typeOnly: new Map() },\r\n clientApi: { regular: new Map(), typeOnly: new Map() },\r\n service: { regular: new Map(), typeOnly: new Map() },\r\n };\r\n\r\n constructor(\r\n protected path: string,\r\n protected fileName: string,\r\n protected dataModel: DataModel,\r\n protected mainFileNames: { model: string; qObject: string; service: string },\r\n protected readonly bundledFileGeneration: boolean,\r\n protected reservedNames: Array<string> | undefined\r\n ) {\r\n this.importedNameValidator = new ImportedNameValidator(reservedNames);\r\n }\r\n\r\n public addCoreLib(odataVersion: ODataVersions, coreLib: CoreImports) {\r\n const isVersioned = VERSIONED_CORE_IMPORTS.includes(coreLib);\r\n const name = CoreImports[coreLib] + (isVersioned ? ODataVersions[odataVersion] : \"\");\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.core, name);\r\n\r\n // TODO: currently only types are imported, however enums could potentially be imported too\r\n this.libs.core.typeOnly.set(name, importName);\r\n\r\n return importName;\r\n }\r\n\r\n private addFromQObject(name: string, typeOnlyImport = false) {\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.qObject, name);\r\n\r\n const imports = typeOnlyImport ? this.libs.qObject.typeOnly : this.libs.qObject.regular;\r\n imports.set(name, importName);\r\n\r\n return importName;\r\n }\r\n\r\n public addQObject(qObject: QueryObjectImports | string) {\r\n return this.addFromQObject(qObject);\r\n }\r\n\r\n public addQObjectType(qObject: string) {\r\n return this.addFromQObject(qObject, true);\r\n }\r\n\r\n public addClientApi(clientApi: ClientApiImports) {\r\n const name = ClientApiImports[clientApi];\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.clientApi, name);\r\n\r\n // complete client api consists only of types\r\n this.libs.clientApi.typeOnly.set(name, importName);\r\n return importName;\r\n }\r\n\r\n public addServiceObject(odataVersion: ODataVersions, serviceObject: ServiceImports) {\r\n const isVersioned = VERSIONED_SERVICE_IMPORTS.includes(serviceObject);\r\n const name = ServiceImports[serviceObject] + (isVersioned ? ODataVersions[odataVersion] : \"\");\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.service, name);\r\n\r\n // only regular imports for the service package\r\n this.libs.service.regular.set(name, importName);\r\n return importName;\r\n }\r\n\r\n public addCustomType(moduleName: string, typeName: string, isTypeOnly: boolean = false) {\r\n const importName = this.importedNameValidator.validateName(moduleName, typeName);\r\n const imports = isTypeOnly ? this.customTypes.typeOnly : this.customTypes.regular;\r\n let importList = imports.get(moduleName);\r\n if (!importList) {\r\n importList = new Map();\r\n imports.set(moduleName, importList);\r\n }\r\n\r\n importList.set(typeName, importName);\r\n return importName;\r\n }\r\n\r\n private pathAndFile(filePath: string, fileName: string) {\r\n return filePath ? `${filePath}/${fileName}` : fileName;\r\n }\r\n\r\n private isDifferentFile(filePath: string, fileName: string) {\r\n return this.pathAndFile(this.path, this.fileName) !== this.pathAndFile(filePath, fileName);\r\n }\r\n\r\n private addGeneratedImport(folderPath: string, fileName: string, name: string, isTypeOnly = false): string {\r\n // imports are only relevant for different files\r\n if (!this.isDifferentFile(folderPath, fileName)) {\r\n return name;\r\n }\r\n\r\n const moduleName = this.pathAndFile(folderPath, fileName);\r\n const importName = this.importedNameValidator.validateName(moduleName, name);\r\n const imports = isTypeOnly ? this.internalImports.typeOnly : this.internalImports.regular;\r\n\r\n const importList = imports.get(moduleName) || new Map<string, string>();\r\n importList.set(name, importName);\r\n imports.set(moduleName, importList);\r\n\r\n return importName;\r\n }\r\n\r\n public addGeneratedModel(fqName: string, name: string): string {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.model, name, true);\r\n } else {\r\n const model = this.dataModel.getModel(fqName) as ComplexType | undefined;\r\n if (!model && fqName !== \"\") {\r\n throw new Error(`Cannot find model by its fully qualified name: ${fqName}!`);\r\n }\r\n\r\n const folderPath = model ? model.folderPath : \"\";\r\n const modelName = model ? model.modelName : this.mainFileNames.model;\r\n return this.addGeneratedImport(folderPath, modelName, name, true);\r\n }\r\n }\r\n\r\n public addGeneratedQObject(fqName: string, name: string, isTypeOnly = false) {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.qObject, name, isTypeOnly);\r\n } else {\r\n const model = this.dataModel.getModel(fqName) as ComplexType | undefined;\r\n if (!model && fqName !== \"\") {\r\n throw new Error(`Cannot find q-object by its fully qualified name: ${fqName}!`);\r\n }\r\n\r\n const folderPath = model ? model.folderPath : \"\";\r\n const qName = model ? model.qName : this.mainFileNames!.qObject;\r\n return this.addGeneratedImport(folderPath, qName, name, isTypeOnly);\r\n }\r\n }\r\n\r\n public addGeneratedService(fqName: string, name: string) {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.service, name);\r\n } else {\r\n const model = this.dataModel.getModel(fqName) as ComplexType;\r\n return this.addGeneratedImport(model.folderPath, model.serviceName, name);\r\n }\r\n }\r\n\r\n private createImportDecl(\r\n module: string,\r\n toImport: Map<string, string>,\r\n isTypeOnly = false\r\n ): OptionalKind<ImportDeclarationStructure> {\r\n return {\r\n namedImports: this.getNamedImports(toImport),\r\n moduleSpecifier: module,\r\n isTypeOnly,\r\n };\r\n }\r\n\r\n public getImportDeclarations(): Array<OptionalKind<ImportDeclarationStructure>> {\r\n return [\r\n ...Object.entries(this.libs).reduce<Array<OptionalKind<ImportDeclarationStructure>>>(\r\n (result, [moduleName, toImport]) => {\r\n const module = LIB_MODULES[moduleName as keyof typeof LIB_MODULES];\r\n if (toImport.typeOnly.size) {\r\n result.push(this.createImportDecl(module, toImport.typeOnly, true));\r\n }\r\n if (toImport.regular.size) {\r\n result.push(this.createImportDecl(module, toImport.regular));\r\n }\r\n return result;\r\n },\r\n []\r\n ),\r\n ...[...this.customTypes.typeOnly]\r\n .filter(([moduleName, toImport]) => toImport.size > 0)\r\n .map(([moduleName, toImport]) => {\r\n return this.createImportDecl(moduleName, toImport, true);\r\n }),\r\n ...[...this.customTypes.regular]\r\n .filter(([moduleName, toImport]) => toImport.size > 0)\r\n .map(([moduleName, toImport]) => {\r\n return this.createImportDecl(moduleName, toImport);\r\n }),\r\n ...[...this.internalImports.typeOnly]\r\n .filter(([_, toImport]) => toImport.size > 0)\r\n .map(([key, toImport]) => {\r\n const module = this.getModuleSpecifier(key);\r\n return this.createImportDecl(module, toImport, true);\r\n }),\r\n ...[...this.internalImports.regular]\r\n .filter(([_, toImport]) => toImport.size > 0)\r\n .map(([key, toImport]) => {\r\n const module = this.getModuleSpecifier(key);\r\n return this.createImportDecl(module, toImport);\r\n }),\r\n ];\r\n }\r\n\r\n private getNamedImports(toImport: Map<string, string>): Array<{ name: string; alias: string | undefined }> {\r\n return [...toImport.entries()].map(([name, alias]) => ({\r\n name,\r\n alias: alias !== name ? alias : undefined,\r\n }));\r\n }\r\n\r\n private getModuleSpecifier(filePath: string): string {\r\n const relativePath = path.relative(this.path, filePath).replaceAll(path.sep, \"/\");\r\n return !relativePath.startsWith(\".\") ? \"./\" + relativePath : relativePath;\r\n }\r\n}\r\n"]}
|