@odata2ts/odata2ts 0.37.0 → 0.38.1
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 +20 -0
- package/lib/FactoryFunctionModel.d.ts +2 -2
- package/lib/FactoryFunctionModel.js.map +1 -1
- package/lib/OptionModel.d.ts +5 -0
- package/lib/OptionModel.js.map +1 -1
- package/lib/data-model/DataModelDigestion.d.ts +5 -0
- package/lib/data-model/DataModelDigestion.js +19 -8
- package/lib/data-model/DataModelDigestion.js.map +1 -1
- package/lib/data-model/DataModelDigestionV4.js +2 -2
- package/lib/data-model/DataModelDigestionV4.js.map +1 -1
- package/lib/data-model/DataTypeModel.d.ts +4 -1
- package/lib/data-model/DataTypeModel.js.map +1 -1
- package/lib/data-model/validation/NameClashValidator.d.ts +3 -2
- package/lib/data-model/validation/NameClashValidator.js +6 -4
- package/lib/data-model/validation/NameClashValidator.js.map +1 -1
- package/lib/data-model/validation/NameValidator.d.ts +4 -3
- package/lib/data-model/validation/NameValidator.js.map +1 -1
- package/lib/data-model/validation/NoopValidator.d.ts +3 -2
- package/lib/data-model/validation/NoopValidator.js +4 -4
- package/lib/data-model/validation/NoopValidator.js.map +1 -1
- package/lib/defaultConfig.js +1 -0
- package/lib/defaultConfig.js.map +1 -1
- package/lib/generator/ImportContainer.d.ts +1 -1
- package/lib/generator/ImportContainer.js +23 -5
- package/lib/generator/ImportContainer.js.map +1 -1
- package/lib/generator/ModelGenerator.js +5 -1
- package/lib/generator/ModelGenerator.js.map +1 -1
- package/lib/generator/QueryObjectGenerator.js +17 -3
- package/lib/generator/QueryObjectGenerator.js.map +1 -1
- package/lib/generator/ServiceGenerator.d.ts +1 -1
- package/lib/generator/ServiceGenerator.js +13 -12
- package/lib/generator/ServiceGenerator.js.map +1 -1
- package/lib/generator/import/ImportObjects.d.ts +3 -1
- package/lib/generator/import/ImportObjects.js +3 -1
- package/lib/generator/import/ImportObjects.js.map +1 -1
- package/package.json +13 -12
|
@@ -54,11 +54,12 @@ export class NameClashValidator {
|
|
|
54
54
|
addEnumType(fqName, name) {
|
|
55
55
|
return this.addToTypes(fqName, name, TypeModel.EnumType);
|
|
56
56
|
}
|
|
57
|
-
addUnboundOperationType(fqName, name) {
|
|
57
|
+
addUnboundOperationType(fqName, name, operationType) {
|
|
58
58
|
const validationObject = { type: TypeModel.OperationType, fqName };
|
|
59
|
+
const isAction = operationType === "Action" /* OperationTypes.Action */;
|
|
59
60
|
const hit = this.store.get(name);
|
|
60
61
|
// to support function overloads: allow multiple operation definitions with same fully qualified name
|
|
61
|
-
if (hit && hit.fqName !== fqName) {
|
|
62
|
+
if (hit && (isAction || hit.fqName !== fqName)) {
|
|
62
63
|
return this.addToError(name, hit, validationObject);
|
|
63
64
|
}
|
|
64
65
|
else {
|
|
@@ -66,12 +67,13 @@ export class NameClashValidator {
|
|
|
66
67
|
return name;
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
|
-
addBoundOperationType(bindingName, fqName, name) {
|
|
70
|
+
addBoundOperationType(bindingName, fqName, name, operationType) {
|
|
70
71
|
const nameWithBinding = `${bindingName}_${name}`;
|
|
71
72
|
const validationObject = { type: TypeModel.OperationType, fqName };
|
|
73
|
+
const isAction = operationType === "Action" /* OperationTypes.Action */;
|
|
72
74
|
const hit = this.store.get(nameWithBinding);
|
|
73
75
|
// to support function overloads: allow multiple operation definitions with same fully qualified name
|
|
74
|
-
if (hit && hit.fqName !== fqName) {
|
|
76
|
+
if (hit && (isAction || hit.fqName !== fqName)) {
|
|
75
77
|
return this.addToError(name, hit, validationObject);
|
|
76
78
|
}
|
|
77
79
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NameClashValidator.js","sourceRoot":"","sources":["../../../src/data-model/validation/NameClashValidator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"NameClashValidator.js","sourceRoot":"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M,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACtE,CAAC;IAED,YAAY,CAAC,MAAc,EAAE,IAAY;QACvC,OAAO,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACtE,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF","sourcesContent":["import { ConfigFileOptions } from \"../../OptionModel.js\";\r\nimport { TypeModel } from \"../../TypeModel.js\";\r\nimport { OperationTypes } from \"../DataTypeModel.js\";\r\nimport { NameValidator, ValidationError } from \"./NameValidator.js\";\r\n\r\nexport interface NameValidatorOptions\r\n extends Pick<ConfigFileOptions, \"disableAutomaticNameClashResolution\" | \"bundledFileGeneration\"> {}\r\n\r\nexport class NameClashValidator implements NameValidator {\r\n private entityContainer = new Map<string, ValidationError>();\r\n private store = new Map<string, ValidationError>();\r\n private errors = new Map<string, ValidationError[]>();\r\n\r\n constructor(private options: NameValidatorOptions = {}) {}\r\n\r\n private addToError(name: string, hit: ValidationError, validationObject: ValidationError) {\r\n const existingErrors = this.errors.get(name);\r\n if (existingErrors) {\r\n if (!this.options.disableAutomaticNameClashResolution) {\r\n validationObject.renamedTo = `${name}${existingErrors.length + 1}`;\r\n }\r\n existingErrors.push(validationObject);\r\n } else {\r\n if (!this.options.disableAutomaticNameClashResolution) {\r\n validationObject.renamedTo = `${name}2`;\r\n }\r\n this.errors.set(name, [hit, validationObject]);\r\n }\r\n return validationObject.renamedTo ?? name;\r\n }\r\n\r\n private addToTypes(fqName: string, name: string, type: TypeModel): string {\r\n const validationObject: ValidationError = { type, fqName };\r\n const hit = this.store.get(name);\r\n if (hit) {\r\n return this.addToError(name, hit, validationObject);\r\n } else {\r\n this.store.set(name, validationObject);\r\n return name;\r\n }\r\n }\r\n\r\n private addToEntityContainer(fqName: string, name: string, type: TypeModel): string {\r\n const validationObject: ValidationError = { type, fqName };\r\n const hit = this.entityContainer.get(name);\r\n if (hit) {\r\n return this.addToError(name, hit, validationObject);\r\n } else {\r\n this.entityContainer.set(name, validationObject);\r\n return name;\r\n }\r\n }\r\n\r\n addEntityType(fqName: string, name: string) {\r\n return this.addToTypes(fqName, name, TypeModel.EntityType);\r\n }\r\n\r\n addComplexType(fqName: string, name: string) {\r\n return this.addToTypes(fqName, name, TypeModel.ComplexType);\r\n }\r\n\r\n addEnumType(fqName: string, name: string) {\r\n return this.addToTypes(fqName, name, TypeModel.EnumType);\r\n }\r\n\r\n addUnboundOperationType(fqName: string, name: string, operationType: OperationTypes) {\r\n const validationObject: ValidationError = { type: TypeModel.OperationType, fqName };\r\n const isAction = operationType === OperationTypes.Action;\r\n\r\n const hit = this.store.get(name);\r\n // to support function overloads: allow multiple operation definitions with same fully qualified name\r\n if (hit && (isAction || hit.fqName !== fqName)) {\r\n return this.addToError(name, hit, validationObject);\r\n } else {\r\n this.store.set(name, validationObject);\r\n return name;\r\n }\r\n }\r\n\r\n addBoundOperationType(bindingName: string, fqName: string, name: string, operationType: OperationTypes) {\r\n const nameWithBinding = `${bindingName}_${name}`;\r\n const validationObject: ValidationError = { type: TypeModel.OperationType, fqName };\r\n const isAction = operationType === OperationTypes.Action;\r\n\r\n const hit = this.store.get(nameWithBinding);\r\n // to support function overloads: allow multiple operation definitions with same fully qualified name\r\n if (hit && (isAction || hit.fqName !== fqName)) {\r\n return this.addToError(name, hit, validationObject);\r\n } else {\r\n this.store.set(nameWithBinding, validationObject);\r\n return name;\r\n }\r\n }\r\n\r\n addOperationImportType(fqName: string, name: string) {\r\n return this.addToEntityContainer(fqName, name, TypeModel.OperationImportType);\r\n }\r\n\r\n addEntitySet(fqName: string, name: string) {\r\n return this.addToEntityContainer(fqName, name, TypeModel.EntitySet);\r\n }\r\n\r\n addSingleton(fqName: string, name: string) {\r\n return this.addToEntityContainer(fqName, name, TypeModel.Singleton);\r\n }\r\n\r\n validate() {\r\n return this.errors;\r\n }\r\n}\r\n"]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { TypeModel } from "../../TypeModel
|
|
1
|
+
import { TypeModel } from "../../TypeModel";
|
|
2
|
+
import { OperationTypes } from "../DataTypeModel";
|
|
2
3
|
export interface NameValidator {
|
|
3
4
|
addEntityType(fqName: string, name: string): string;
|
|
4
5
|
addComplexType(fqName: string, name: string): string;
|
|
5
6
|
addEnumType(fqName: string, name: string): string;
|
|
6
|
-
addUnboundOperationType(fqName: string, name: string): string;
|
|
7
|
-
addBoundOperationType(bindingName: string, fqName: string, name: string): string;
|
|
7
|
+
addUnboundOperationType(fqName: string, name: string, operationType: OperationTypes): string;
|
|
8
|
+
addBoundOperationType(bindingName: string, fqName: string, name: string, operationType: OperationTypes): string;
|
|
8
9
|
addOperationImportType(fqName: string, name: string): string;
|
|
9
10
|
addEntitySet(fqName: string, name: string): string;
|
|
10
11
|
addSingleton(fqName: string, name: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NameValidator.js","sourceRoot":"","sources":["../../../src/data-model/validation/NameValidator.ts"],"names":[],"mappings":"","sourcesContent":["import { TypeModel } from \"../../TypeModel
|
|
1
|
+
{"version":3,"file":"NameValidator.js","sourceRoot":"","sources":["../../../src/data-model/validation/NameValidator.ts"],"names":[],"mappings":"","sourcesContent":["import { TypeModel } from \"../../TypeModel\";\r\nimport { OperationTypes } from \"../DataTypeModel\";\r\n\r\nexport interface NameValidator {\r\n addEntityType(fqName: string, name: string): string;\r\n\r\n addComplexType(fqName: string, name: string): string;\r\n\r\n addEnumType(fqName: string, name: string): string;\r\n\r\n addUnboundOperationType(fqName: string, name: string, operationType: OperationTypes): string;\r\n\r\n addBoundOperationType(bindingName: string, fqName: string, name: string, operationType: OperationTypes): string;\r\n\r\n addOperationImportType(fqName: string, name: string): string;\r\n\r\n addEntitySet(fqName: string, name: string): string;\r\n\r\n addSingleton(fqName: string, name: string): string;\r\n\r\n validate(): Map<string, ValidationError[]>;\r\n}\r\n\r\nexport interface ValidationError {\r\n fqName: string;\r\n type: TypeModel;\r\n renamedTo?: string;\r\n}\r\n"]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { OperationTypes } from "../DataTypeModel";
|
|
1
2
|
import { NameValidator, ValidationError } from "./NameValidator.js";
|
|
2
3
|
export declare class NoopValidator implements NameValidator {
|
|
3
|
-
addBoundOperationType(bindingName: string, fqName: string, name: string): string;
|
|
4
4
|
addComplexType(fqName: string, name: string): string;
|
|
5
5
|
addEntitySet(fqName: string, name: string): string;
|
|
6
6
|
addEntityType(fqName: string, name: string): string;
|
|
7
7
|
addEnumType(fqName: string, name: string): string;
|
|
8
8
|
addOperationImportType(fqName: string, name: string): string;
|
|
9
9
|
addSingleton(fqName: string, name: string): string;
|
|
10
|
-
|
|
10
|
+
addBoundOperationType(bindingName: string, fqName: string, name: string, operationType: OperationTypes): string;
|
|
11
|
+
addUnboundOperationType(fqName: string, name: string, operationType: OperationTypes): string;
|
|
11
12
|
validate(): Map<string, ValidationError[]>;
|
|
12
13
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
export class NoopValidator {
|
|
2
|
-
addBoundOperationType(bindingName, fqName, name) {
|
|
3
|
-
return name;
|
|
4
|
-
}
|
|
5
2
|
addComplexType(fqName, name) {
|
|
6
3
|
return name;
|
|
7
4
|
}
|
|
@@ -20,7 +17,10 @@ export class NoopValidator {
|
|
|
20
17
|
addSingleton(fqName, name) {
|
|
21
18
|
return name;
|
|
22
19
|
}
|
|
23
|
-
|
|
20
|
+
addBoundOperationType(bindingName, fqName, name, operationType) {
|
|
21
|
+
return name;
|
|
22
|
+
}
|
|
23
|
+
addUnboundOperationType(fqName, name, operationType) {
|
|
24
24
|
return name;
|
|
25
25
|
}
|
|
26
26
|
validate() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NoopValidator.js","sourceRoot":"","sources":["../../../src/data-model/validation/NoopValidator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NoopValidator.js","sourceRoot":"","sources":["../../../src/data-model/validation/NoopValidator.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,aAAa;IACxB,cAAc,CAAC,MAAc,EAAE,IAAY;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,YAAY,CAAC,MAAc,EAAE,IAAY;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,aAAa,CAAC,MAAc,EAAE,IAAY;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,WAAW,CAAC,MAAc,EAAE,IAAY;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,sBAAsB,CAAC,MAAc,EAAE,IAAY;QACjD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,YAAY,CAAC,MAAc,EAAE,IAAY;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,qBAAqB,CAAC,WAAmB,EAAE,MAAc,EAAE,IAAY,EAAE,aAA6B;QACpG,OAAO,IAAI,CAAC;IACd,CAAC;IAED,uBAAuB,CAAC,MAAc,EAAE,IAAY,EAAE,aAA6B;QACjF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,GAAG,EAAE,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { OperationTypes } from \"../DataTypeModel\";\r\nimport { NameValidator, ValidationError } from \"./NameValidator.js\";\r\n\r\nexport class NoopValidator implements NameValidator {\r\n addComplexType(fqName: string, name: string): string {\r\n return name;\r\n }\r\n\r\n addEntitySet(fqName: string, name: string): string {\r\n return name;\r\n }\r\n\r\n addEntityType(fqName: string, name: string): string {\r\n return name;\r\n }\r\n\r\n addEnumType(fqName: string, name: string): string {\r\n return name;\r\n }\r\n\r\n addOperationImportType(fqName: string, name: string): string {\r\n return name;\r\n }\r\n\r\n addSingleton(fqName: string, name: string): string {\r\n return name;\r\n }\r\n\r\n addBoundOperationType(bindingName: string, fqName: string, name: string, operationType: OperationTypes): string {\r\n return name;\r\n }\r\n\r\n addUnboundOperationType(fqName: string, name: string, operationType: OperationTypes): string {\r\n return name;\r\n }\r\n\r\n validate(): Map<string, ValidationError[]> {\r\n return new Map();\r\n }\r\n}\r\n"]}
|
package/lib/defaultConfig.js
CHANGED
package/lib/defaultConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultConfig.js","sourceRoot":"","sources":["../src/defaultConfig.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"defaultConfig.js","sourceRoot":"","sources":["../src/defaultConfig.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAgB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAc,MAAM,kBAAkB,CAAC;AAGhE;;GAEG;AACH,MAAM,aAAa,GAAyB;IAC1C,eAAe,EAAE,EAAE;IACnB,WAAW,EAAE,KAAK;IAClB,IAAI,EAAE,KAAK,CAAC,GAAG;IACf,QAAQ,EAAE,SAAS,CAAC,MAAM;IAC1B,KAAK,EAAE,KAAK;IACZ,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,eAAe;IACzB,UAAU,EAAE,EAAE;IACd,kBAAkB,EAAE,KAAK;IACzB,YAAY,EAAE,KAAK;IACnB,cAAc,EAAE,KAAK;IACrB,YAAY,EAAE,KAAK;IACnB,+BAA+B,EAAE,KAAK;IACtC,qBAAqB,EAAE,KAAK;IAC5B,aAAa,EAAE,KAAK;IACpB,gCAAgC,EAAE,KAAK;IACvC,mBAAmB,EAAE,KAAK;IAC1B,mCAAmC,EAAE,KAAK;IAC1C,qBAAqB,EAAE,IAAI;IAC3B,YAAY,EAAE,KAAK;IACnB,MAAM,EAAE;QACN,MAAM,EAAE;YACN,cAAc,EAAE,gBAAgB,CAAC,WAAW;YAC5C,kBAAkB,EAAE,gBAAgB,CAAC,UAAU;YAC/C,cAAc,EAAE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AAE,QAAQ,CAAC,MAAM;QACvB,IAAI,EAAE;YACJ,kBAAkB,EAAE,IAAI;SACzB;QACD,UAAU,EAAE;YACV,kBAAkB,EAAE,IAAI;YACxB,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM;YAClC,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM;SACnC;QACD,YAAY,EAAE;YACZ,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,MAAM;YACpC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,MAAM;SACrC;QACD,oBAAoB,EAAE;YACpB,MAAM,EAAE,QAAQ,CAAC,oBAAoB,CAAC,MAAM;YAC5C,MAAM,EAAE,QAAQ,CAAC,oBAAoB,CAAC,MAAM;SAC7C;KACF;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,SAAS,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;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\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 numericEnums: false,\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"]}
|
|
@@ -40,7 +40,7 @@ export declare class ImportContainer {
|
|
|
40
40
|
private pathAndFile;
|
|
41
41
|
private isDifferentFile;
|
|
42
42
|
private addGeneratedImport;
|
|
43
|
-
addGeneratedModel(fqName: string, name: string): string;
|
|
43
|
+
addGeneratedModel(fqName: string, name: string, isTypeOnly?: boolean): string;
|
|
44
44
|
addGeneratedQObject(fqName: string, name: string, isTypeOnly?: boolean): string;
|
|
45
45
|
addGeneratedService(fqName: string, name: string): string;
|
|
46
46
|
private createImportDecl;
|
|
@@ -46,8 +46,18 @@ export class ImportContainer {
|
|
|
46
46
|
}
|
|
47
47
|
addFromQObject(name, typeOnlyImport = false) {
|
|
48
48
|
const importName = this.importedNameValidator.validateName(LIB_MODULES.qObject, name);
|
|
49
|
-
const imports =
|
|
50
|
-
|
|
49
|
+
const imports = this.libs.qObject;
|
|
50
|
+
if (typeOnlyImport) {
|
|
51
|
+
if (!imports.regular.has(name)) {
|
|
52
|
+
imports.typeOnly.set(name, importName);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
if (imports.typeOnly.has(name)) {
|
|
57
|
+
imports.typeOnly.delete(name);
|
|
58
|
+
}
|
|
59
|
+
imports.regular.set(name, importName);
|
|
60
|
+
}
|
|
51
61
|
return importName;
|
|
52
62
|
}
|
|
53
63
|
addQObject(qObject) {
|
|
@@ -71,6 +81,7 @@ export class ImportContainer {
|
|
|
71
81
|
this.libs.service.regular.set(name, importName);
|
|
72
82
|
return importName;
|
|
73
83
|
}
|
|
84
|
+
// TODO: make sure that regular imports win over additional typeOnly imports
|
|
74
85
|
addCustomType(moduleName, typeName, isTypeOnly = false) {
|
|
75
86
|
const importName = this.importedNameValidator.validateName(moduleName, typeName);
|
|
76
87
|
const imports = isTypeOnly ? this.customTypes.typeOnly : this.customTypes.regular;
|
|
@@ -89,6 +100,7 @@ export class ImportContainer {
|
|
|
89
100
|
return this.pathAndFile(this.path, this.fileName) !== this.pathAndFile(filePath, fileName);
|
|
90
101
|
}
|
|
91
102
|
addGeneratedImport(folderPath, fileName, name, isTypeOnly = false) {
|
|
103
|
+
var _a, _b, _c;
|
|
92
104
|
// imports are only relevant for different files
|
|
93
105
|
if (!this.isDifferentFile(folderPath, fileName)) {
|
|
94
106
|
return name;
|
|
@@ -96,14 +108,20 @@ export class ImportContainer {
|
|
|
96
108
|
const moduleName = this.pathAndFile(folderPath, fileName);
|
|
97
109
|
const importName = this.importedNameValidator.validateName(moduleName, name);
|
|
98
110
|
const imports = isTypeOnly ? this.internalImports.typeOnly : this.internalImports.regular;
|
|
111
|
+
if (isTypeOnly && ((_a = this.internalImports.regular.get(moduleName)) === null || _a === void 0 ? void 0 : _a.has(name))) {
|
|
112
|
+
return importName;
|
|
113
|
+
}
|
|
114
|
+
if (!isTypeOnly && ((_b = this.internalImports.typeOnly.get(moduleName)) === null || _b === void 0 ? void 0 : _b.has(name))) {
|
|
115
|
+
(_c = this.internalImports.typeOnly.get(moduleName)) === null || _c === void 0 ? void 0 : _c.delete(name);
|
|
116
|
+
}
|
|
99
117
|
const importList = imports.get(moduleName) || new Map();
|
|
100
118
|
importList.set(name, importName);
|
|
101
119
|
imports.set(moduleName, importList);
|
|
102
120
|
return importName;
|
|
103
121
|
}
|
|
104
|
-
addGeneratedModel(fqName, name) {
|
|
122
|
+
addGeneratedModel(fqName, name, isTypeOnly = true) {
|
|
105
123
|
if (this.bundledFileGeneration) {
|
|
106
|
-
return this.addGeneratedImport("", this.mainFileNames.model, name,
|
|
124
|
+
return this.addGeneratedImport("", this.mainFileNames.model, name, isTypeOnly);
|
|
107
125
|
}
|
|
108
126
|
else {
|
|
109
127
|
const model = this.dataModel.getModel(fqName);
|
|
@@ -112,7 +130,7 @@ export class ImportContainer {
|
|
|
112
130
|
}
|
|
113
131
|
const folderPath = model ? model.folderPath : "";
|
|
114
132
|
const modelName = model ? model.modelName : this.mainFileNames.model;
|
|
115
|
-
return this.addGeneratedImport(folderPath, modelName, name,
|
|
133
|
+
return this.addGeneratedImport(folderPath, modelName, name, isTypeOnly);
|
|
116
134
|
}
|
|
117
135
|
}
|
|
118
136
|
addGeneratedQObject(fqName, name, isTypeOnly = false) {
|
|
@@ -1 +1 @@
|
|
|
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;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAOnE;;;;;;;GAOG;AACH,MAAM,OAAO,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,CAAqD;QACzD,0BAAqB,GAArB,qBAAqB,CAAS;QACvC,kBAAa,GAAb,aAAa,CAA2B;QAxBpD,uDAAuD;QAC/C,gBAAW,GAAG;YACpB,OAAO,EAAE,IAAI,GAAG,EAA+B;YAC/C,QAAQ,EAAE,IAAI,GAAG,EAA+B;SACjD,CAAC;QACF,iCAAiC;QACzB,oBAAe,GAAG;YACxB,OAAO,EAAE,IAAI,GAAG,EAA+B;YAC/C,QAAQ,EAAE,IAAI,GAAG,EAA+B;SACjD,CAAC;QAEM,SAAI,GAAwB;YAClC,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE;YACjD,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,GAAG,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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"]}
|
|
1
|
+
{"version":3,"file":"ImportContainer.js","sourceRoot":"","sources":["../../src/generator/ImportContainer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,WAAW,EAEX,cAAc,EACd,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAOnE;;;;;;;GAOG;AACH,MAAM,OAAO,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,CAAqD;QACzD,0BAAqB,GAArB,qBAAqB,CAAS;QACvC,kBAAa,GAAb,aAAa,CAA2B;QAxBpD,uDAAuD;QAC/C,gBAAW,GAAG;YACpB,OAAO,EAAE,IAAI,GAAG,EAA+B;YAC/C,QAAQ,EAAE,IAAI,GAAG,EAA+B;SACjD,CAAC;QACF,iCAAiC;QACzB,oBAAe,GAAG;YACx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from \"ts-morph\";\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 = this.libs.qObject;\r\n if (typeOnlyImport) {\r\n if (!imports.regular.has(name)) {\r\n imports.typeOnly.set(name, importName);\r\n }\r\n } else {\r\n if (imports.typeOnly.has(name)) {\r\n imports.typeOnly.delete(name);\r\n }\r\n imports.regular.set(name, importName);\r\n }\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 // TODO: make sure that regular imports win over additional typeOnly imports\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 if (isTypeOnly && this.internalImports.regular.get(moduleName)?.has(name)) {\r\n return importName;\r\n }\r\n if (!isTypeOnly && this.internalImports.typeOnly.get(moduleName)?.has(name)) {\r\n this.internalImports.typeOnly.get(moduleName)?.delete(name);\r\n }\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, isTypeOnly = true): string {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.model, 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 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, isTypeOnly);\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"]}
|
|
@@ -31,10 +31,14 @@ class ModelGenerator {
|
|
|
31
31
|
generateEnums() {
|
|
32
32
|
return this.dataModel.getEnums().map((et) => {
|
|
33
33
|
const file = this.project.createOrGetModelFile(et.folderPath, et.modelName);
|
|
34
|
+
const isNumeric = this.options.numericEnums;
|
|
34
35
|
file.getFile().addEnum({
|
|
35
36
|
name: et.modelName,
|
|
36
37
|
isExported: true,
|
|
37
|
-
members: et.members.map((mem) => ({
|
|
38
|
+
members: et.members.map((mem) => ({
|
|
39
|
+
name: mem.name,
|
|
40
|
+
initializer: isNumeric ? String(mem.value) : `"${mem.name}"`,
|
|
41
|
+
})),
|
|
38
42
|
});
|
|
39
43
|
return this.project.finalizeFile(file);
|
|
40
44
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelGenerator.js","sourceRoot":"","sources":["../../src/generator/ModelGenerator.ts"],"names":[],"mappings":";AACA,OAAO,EAAgC,aAAa,EAAE,MAAM,UAAU,CAAC;AAQvE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,MAAM,CAAC,MAAM,cAAc,GAAiC,CAC1D,OAAuB,EACvB,SAAS,EACT,OAAO,EACP,OA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AAC,CAAC;aACH,CAAC,CAAC;SACJ;QACD,2EAA2E;aACtE,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;YAC7B,IAAI,CAAC,OAAO,EAAE,CAAC,YAAY,CAAC;gBAC1B,IAAI,EAAE,SAAS,CAAC,eAAe;gBAC/B,UAAU,EAAE,IAAI;gBAChB,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE;oBACf,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;wBAChC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;4BAChB,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;gCAC5B,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,KAAK,CAAC,CAAC;gCAC7D,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC,CAAC;gCACxE,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;oCAC3B,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;iCACnB;4BACH,CAAC,CAAC,CAAC;wBACL,CAAC,CAAC,CAAC;wBACH,IAAI,KAAK,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;4BAChC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;yBACrB;oBACH,CAAC,CAAC,CAAC;gBACL,CAAC;aACF,CAAC,CAAC;SACJ;IACH,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { JSDocStructure, OptionalKind, StructureKind } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel.js\";\r\nimport { ComplexType, DataTypes, EntityType, OperationType, PropertyModel } from \"../data-model/DataTypeModel.js\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper.js\";\r\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel.js\";\r\nimport { FileHandler } from \"../project/FileHandler.js\";\r\nimport { ProjectManager } from \"../project/ProjectManager.js\";\r\nimport { CoreImports } from \"./import/ImportObjects.js\";\r\nimport { ImportContainer } from \"./ImportContainer.js\";\r\n\r\nexport const generateModels: EntityBasedGeneratorFunction = (\r\n project: ProjectManager,\r\n dataModel,\r\n version,\r\n options,\r\n namingHelper\r\n) => {\r\n const generator = new ModelGenerator(project, dataModel, version, options, namingHelper);\r\n return generator.generate();\r\n};\r\n\r\nclass ModelGenerator {\r\n constructor(\r\n private project: ProjectManager,\r\n private dataModel: DataModel,\r\n private version: ODataVersions,\r\n private options: GeneratorFunctionOptions,\r\n private namingHelper: NamingHelper\r\n ) {}\r\n\r\n public async generate(): Promise<void> {\r\n this.project.initModels();\r\n\r\n const promises: Array<Promise<void>> = [\r\n ...this.generateEnums(),\r\n ...this.generateEntityTypeModels(),\r\n ...this.generateComplexTypeModels(),\r\n ];\r\n\r\n if (!this.options.skipOperations) {\r\n promises.push(this.generateUnboundOperationParams());\r\n }\r\n\r\n await Promise.all(promises);\r\n\r\n return this.project.finalizeModels();\r\n }\r\n\r\n private generateEnums() {\r\n return this.dataModel.getEnums().map((et) => {\r\n const file = this.project.createOrGetModelFile(et.folderPath, et.modelName);\r\n\r\n file.getFile().addEnum({\r\n name: et.modelName,\r\n isExported: true,\r\n members: et.members.map((mem) => ({ name: mem, initializer: `\"${mem}\"` })),\r\n });\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateEntityTypeModels() {\r\n return this.dataModel.getEntityTypes().map((model) => {\r\n const file = this.project.createOrGetModelFile(model.folderPath, model.modelName, [\r\n model.modelName,\r\n model.id.modelName,\r\n model.editableName,\r\n ]);\r\n\r\n // query model\r\n this.generateModel(file, model);\r\n\r\n // key model\r\n if (!this.options.skipIdModels && model.generateId) {\r\n this.generateIdModel(file, model);\r\n }\r\n\r\n // editable model\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(file, model);\r\n }\r\n\r\n // param models for bound operations\r\n if (!this.options.skipOperations) {\r\n [\r\n ...this.dataModel.getEntityTypeOperations(model.fqName),\r\n ...this.dataModel.getEntitySetOperations(model.fqName),\r\n ].forEach((operation) => {\r\n this.generateOperationParams(file, operation);\r\n });\r\n }\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateComplexTypeModels() {\r\n return this.dataModel.getComplexTypes().map((model) => {\r\n const file = this.project.createOrGetModelFile(model.folderPath, model.modelName, [\r\n model.modelName,\r\n model.editableName,\r\n ]);\r\n\r\n // query model\r\n this.generateModel(file, model);\r\n\r\n // editable model\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(file, model);\r\n }\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateModel(file: FileHandler, model: ComplexType | EntityType) {\r\n const imports = file.getImports();\r\n let extendsClause = undefined;\r\n if (model.finalBaseClass) {\r\n const modelName = imports.addGeneratedModel(\r\n model.baseClasses[0],\r\n this.namingHelper.getModelName(model.finalBaseClass)\r\n );\r\n extendsClause = [modelName];\r\n }\r\n\r\n file.getFile().addInterface({\r\n name: model.modelName,\r\n isExported: true,\r\n properties: model.props.map((p) => {\r\n const isEntity = p.dataType == DataTypes.ModelType;\r\n return {\r\n name: p.name,\r\n type: this.getPropType(file.getImports(), p),\r\n // props for entities or entity collections are not added in V4 if not explicitly expanded\r\n hasQuestionToken: this.dataModel.isV4() && isEntity,\r\n docs: this.options.skipComments ? undefined : [this.generatePropDoc(p, model)],\r\n };\r\n }),\r\n extends: extendsClause,\r\n });\r\n }\r\n\r\n private generatePropDoc(prop: PropertyModel, model: ComplexType | EntityType): OptionalKind<JSDocStructure> {\r\n const isKeyProp = (model as EntityType).keyNames?.includes(prop.odataName);\r\n const baseAttribs: Array<string> = [];\r\n if (isKeyProp) {\r\n baseAttribs.push(\"**Key Property**: This is a key property used to identify the entity.\");\r\n }\r\n if (prop.managed) {\r\n baseAttribs.push(\"**Managed**: This property is managed on the server side and cannot be edited.\");\r\n }\r\n if (prop.converters?.length) {\r\n baseAttribs.push(`**Applied Converters**: ${prop.converters.map((c) => c.converterId).join(\",\")}.`);\r\n }\r\n\r\n const attributeTable: Array<[string, string]> = [\r\n [\"Name\", prop.odataName],\r\n [\"Type\", prop.odataType],\r\n ];\r\n if (prop.required) {\r\n attributeTable.push([\"Nullable\", \"false\"]);\r\n }\r\n\r\n const description =\r\n (baseAttribs ? baseAttribs.join(\"<br/>\") + \"\\n\\n\" : \"\") +\r\n \"OData Attributes:\\n\" +\r\n \"|Attribute Name | Attribute Value |\\n| --- | ---|\\n\" +\r\n attributeTable.map((row) => `| ${row[0]} | \\`${row[1]}\\` |`).join(\"\\n\");\r\n\r\n return { kind: StructureKind.JSDoc, description };\r\n }\r\n\r\n private getPropType(imports: ImportContainer, prop: PropertyModel): string {\r\n // V2 entity special: deferred content\r\n let suffix = \"\";\r\n if (this.dataModel.isV2() && prop.dataType == DataTypes.ModelType) {\r\n const defContent = imports.addCoreLib(this.version, CoreImports.DeferredContent);\r\n suffix = ` | ${defContent}`;\r\n }\r\n\r\n let typeName: string;\r\n if (prop.dataType === DataTypes.PrimitiveType) {\r\n // custom types which require type imports => possible via converters\r\n typeName = prop.typeModule ? imports.addCustomType(prop.typeModule, prop.type, true) : prop.type;\r\n } else {\r\n typeName = imports.addGeneratedModel(prop.fqType, prop.type);\r\n }\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n const type = `Array<${typeName}>`;\r\n if (this.dataModel.isV2() && this.options.v2ModelsWithExtraResultsWrapping) {\r\n return `{ results: ${type} }` + suffix;\r\n } else {\r\n return type + suffix;\r\n }\r\n }\r\n\r\n // primitive, enum & complex types\r\n return typeName + (prop.required ? \"\" : \" | null\") + suffix;\r\n }\r\n\r\n private generateIdModel(file: FileHandler, model: EntityType) {\r\n const singleType = model.keys.length === 1 ? `${model.keys[0].type} | ` : \"\";\r\n const keyTypes = model.keys\r\n .map((keyProp) => `${keyProp.name}: ${this.getPropType(file.getImports(), keyProp)}`)\r\n .join(\",\");\r\n const type = `${singleType}{${keyTypes}}`;\r\n\r\n file.getFile().addTypeAlias({\r\n name: model.id.modelName,\r\n isExported: true,\r\n type,\r\n });\r\n }\r\n\r\n private generateEditableModel(file: FileHandler, model: ComplexType) {\r\n const entityTypes = [DataTypes.ModelType, DataTypes.ComplexType];\r\n const allProps = [...model.baseProps, ...model.props].filter((p) => !p.managed);\r\n\r\n const requiredProps = allProps\r\n .filter((p) => p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const optionalProps = allProps\r\n .filter((p) => !p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const complexProps = allProps.filter((p) => p.dataType === DataTypes.ComplexType);\r\n\r\n const extendsClause = [\r\n requiredProps ? `Pick<${model.modelName}, ${requiredProps}>` : null,\r\n optionalProps ? `Partial<Pick<${model.modelName}, ${optionalProps}>>` : null,\r\n ].filter((e): e is string => !!e);\r\n\r\n file.getFile().addInterface({\r\n name: model.editableName,\r\n isExported: true,\r\n extends: extendsClause,\r\n properties: !complexProps\r\n ? undefined\r\n : complexProps.map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getEditablePropType(file.getImports(), p),\r\n // optional props don't need to be specified in editable model\r\n // also, entities would require deep insert func => we make it optional for now\r\n hasQuestionToken: !p.required || p.dataType === DataTypes.ModelType,\r\n };\r\n }),\r\n });\r\n }\r\n\r\n private getEditablePropType(imports: ImportContainer, prop: PropertyModel): string {\r\n const isModelType = [DataTypes.ModelType, DataTypes.ComplexType].includes(prop.dataType);\r\n\r\n let editableType = prop.type;\r\n if (isModelType) {\r\n const editName = this.dataModel.getComplexType(prop.fqType)!.editableName;\r\n editableType = imports.addGeneratedModel(prop.fqType, editName);\r\n }\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n return `Array<${editableType}>`;\r\n }\r\n\r\n // primitive, enum & complex types\r\n return editableType + (prop.required ? \"\" : \" | null\");\r\n }\r\n\r\n private async generateUnboundOperationParams() {\r\n const unboundOps = this.dataModel.getUnboundOperationTypes();\r\n const reservedNames = unboundOps.map((op) => op.paramsModelName);\r\n const file = this.project.createOrGetMainModelFile(reservedNames);\r\n\r\n unboundOps.forEach((operation) => {\r\n this.generateOperationParams(file, operation);\r\n });\r\n }\r\n\r\n private generateOperationParams(file: FileHandler, operation: OperationType) {\r\n const paramSets = [operation.parameters, ...(operation.overrides ?? [])].filter((pSet) => !!pSet.length);\r\n\r\n // standard: one interface for parameters\r\n if (paramSets.length === 1) {\r\n file.getFile().addInterface({\r\n name: operation.paramsModelName,\r\n isExported: true,\r\n properties: paramSets[0].map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getPropType(file.getImports(), p),\r\n hasQuestionToken: !p.required,\r\n };\r\n }),\r\n });\r\n }\r\n // function overload: one type with intersections of different param models\r\n else if (paramSets.length > 1) {\r\n file.getFile().addTypeAlias({\r\n name: operation.paramsModelName,\r\n isExported: true,\r\n type: (writer) => {\r\n paramSets.forEach((pSet, index) => {\r\n writer.block(() => {\r\n pSet.forEach((param, index) => {\r\n const paramType = this.getPropType(file.getImports(), param);\r\n writer.write(`${param.name}${param.required ? \"\" : \"?\"}: ${paramType}`);\r\n if (index < pSet.length - 1) {\r\n writer.write(\",\");\r\n }\r\n });\r\n });\r\n if (index < paramSets.length - 1) {\r\n writer.write(\" | \");\r\n }\r\n });\r\n },\r\n });\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ModelGenerator.js","sourceRoot":"","sources":["../../src/generator/ModelGenerator.ts"],"names":[],"mappings":";AACA,OAAO,EAAgC,aAAa,EAAE,MAAM,UAAU,CAAC;AAOvE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;A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CAAC,CAAC;gBACL,CAAC;aACF,CAAC,CAAC;SACJ;IACH,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { JSDocStructure, OptionalKind, StructureKind } from \"ts-morph\";\r\nimport { DataModel } from \"../data-model/DataModel.js\";\r\nimport { ComplexType, DataTypes, EntityType, OperationType, PropertyModel } from \"../data-model/DataTypeModel.js\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper.js\";\r\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel.js\";\r\nimport { FileHandler } from \"../project/FileHandler.js\";\r\nimport { ProjectManager } from \"../project/ProjectManager.js\";\r\nimport { CoreImports } from \"./import/ImportObjects.js\";\r\nimport { ImportContainer } from \"./ImportContainer.js\";\r\n\r\nexport const generateModels: EntityBasedGeneratorFunction = (\r\n project: ProjectManager,\r\n dataModel,\r\n version,\r\n options,\r\n namingHelper,\r\n) => {\r\n const generator = new ModelGenerator(project, dataModel, version, options, namingHelper);\r\n return generator.generate();\r\n};\r\n\r\nclass ModelGenerator {\r\n constructor(\r\n private project: ProjectManager,\r\n private dataModel: DataModel,\r\n private version: ODataVersions,\r\n private options: GeneratorFunctionOptions,\r\n private namingHelper: NamingHelper,\r\n ) {}\r\n\r\n public async generate(): Promise<void> {\r\n this.project.initModels();\r\n\r\n const promises: Array<Promise<void>> = [\r\n ...this.generateEnums(),\r\n ...this.generateEntityTypeModels(),\r\n ...this.generateComplexTypeModels(),\r\n ];\r\n\r\n if (!this.options.skipOperations) {\r\n promises.push(this.generateUnboundOperationParams());\r\n }\r\n\r\n await Promise.all(promises);\r\n\r\n return this.project.finalizeModels();\r\n }\r\n\r\n private generateEnums() {\r\n return this.dataModel.getEnums().map((et) => {\r\n const file = this.project.createOrGetModelFile(et.folderPath, et.modelName);\r\n\r\n const isNumeric = this.options.numericEnums;\r\n file.getFile().addEnum({\r\n name: et.modelName,\r\n isExported: true,\r\n members: et.members.map((mem) => ({\r\n name: mem.name,\r\n initializer: isNumeric ? String(mem.value) : `\"${mem.name}\"`,\r\n })),\r\n });\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateEntityTypeModels() {\r\n return this.dataModel.getEntityTypes().map((model) => {\r\n const file = this.project.createOrGetModelFile(model.folderPath, model.modelName, [\r\n model.modelName,\r\n model.id.modelName,\r\n model.editableName,\r\n ]);\r\n\r\n // query model\r\n this.generateModel(file, model);\r\n\r\n // key model\r\n if (!this.options.skipIdModels && model.generateId) {\r\n this.generateIdModel(file, model);\r\n }\r\n\r\n // editable model\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(file, model);\r\n }\r\n\r\n // param models for bound operations\r\n if (!this.options.skipOperations) {\r\n [\r\n ...this.dataModel.getEntityTypeOperations(model.fqName),\r\n ...this.dataModel.getEntitySetOperations(model.fqName),\r\n ].forEach((operation) => {\r\n this.generateOperationParams(file, operation);\r\n });\r\n }\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateComplexTypeModels() {\r\n return this.dataModel.getComplexTypes().map((model) => {\r\n const file = this.project.createOrGetModelFile(model.folderPath, model.modelName, [\r\n model.modelName,\r\n model.editableName,\r\n ]);\r\n\r\n // query model\r\n this.generateModel(file, model);\r\n\r\n // editable model\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(file, model);\r\n }\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateModel(file: FileHandler, model: ComplexType | EntityType) {\r\n const imports = file.getImports();\r\n let extendsClause = undefined;\r\n if (model.finalBaseClass) {\r\n const modelName = imports.addGeneratedModel(\r\n model.baseClasses[0],\r\n this.namingHelper.getModelName(model.finalBaseClass),\r\n );\r\n extendsClause = [modelName];\r\n }\r\n\r\n file.getFile().addInterface({\r\n name: model.modelName,\r\n isExported: true,\r\n properties: model.props.map((p) => {\r\n const isEntity = p.dataType == DataTypes.ModelType;\r\n return {\r\n name: p.name,\r\n type: this.getPropType(file.getImports(), p),\r\n // props for entities or entity collections are not added in V4 if not explicitly expanded\r\n hasQuestionToken: this.dataModel.isV4() && isEntity,\r\n docs: this.options.skipComments ? undefined : [this.generatePropDoc(p, model)],\r\n };\r\n }),\r\n extends: extendsClause,\r\n });\r\n }\r\n\r\n private generatePropDoc(prop: PropertyModel, model: ComplexType | EntityType): OptionalKind<JSDocStructure> {\r\n const isKeyProp = (model as EntityType).keyNames?.includes(prop.odataName);\r\n const baseAttribs: Array<string> = [];\r\n if (isKeyProp) {\r\n baseAttribs.push(\"**Key Property**: This is a key property used to identify the entity.\");\r\n }\r\n if (prop.managed) {\r\n baseAttribs.push(\"**Managed**: This property is managed on the server side and cannot be edited.\");\r\n }\r\n if (prop.converters?.length) {\r\n baseAttribs.push(`**Applied Converters**: ${prop.converters.map((c) => c.converterId).join(\",\")}.`);\r\n }\r\n\r\n const attributeTable: Array<[string, string]> = [\r\n [\"Name\", prop.odataName],\r\n [\"Type\", prop.odataType],\r\n ];\r\n if (prop.required) {\r\n attributeTable.push([\"Nullable\", \"false\"]);\r\n }\r\n\r\n const description =\r\n (baseAttribs ? baseAttribs.join(\"<br/>\") + \"\\n\\n\" : \"\") +\r\n \"OData Attributes:\\n\" +\r\n \"|Attribute Name | Attribute Value |\\n| --- | ---|\\n\" +\r\n attributeTable.map((row) => `| ${row[0]} | \\`${row[1]}\\` |`).join(\"\\n\");\r\n\r\n return { kind: StructureKind.JSDoc, description };\r\n }\r\n\r\n private getPropType(imports: ImportContainer, prop: PropertyModel): string {\r\n // V2 entity special: deferred content\r\n let suffix = \"\";\r\n if (this.dataModel.isV2() && prop.dataType == DataTypes.ModelType) {\r\n const defContent = imports.addCoreLib(this.version, CoreImports.DeferredContent);\r\n suffix = ` | ${defContent}`;\r\n }\r\n\r\n let typeName: string;\r\n if (prop.dataType === DataTypes.PrimitiveType) {\r\n // custom types which require type imports => possible via converters\r\n typeName = prop.typeModule ? imports.addCustomType(prop.typeModule, prop.type, true) : prop.type;\r\n } else {\r\n typeName = imports.addGeneratedModel(prop.fqType, prop.type);\r\n }\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n const type = `Array<${typeName}>`;\r\n if (this.dataModel.isV2() && this.options.v2ModelsWithExtraResultsWrapping) {\r\n return `{ results: ${type} }` + suffix;\r\n } else {\r\n return type + suffix;\r\n }\r\n }\r\n\r\n // primitive, enum & complex types\r\n return typeName + (prop.required ? \"\" : \" | null\") + suffix;\r\n }\r\n\r\n private generateIdModel(file: FileHandler, model: EntityType) {\r\n const singleType = model.keys.length === 1 ? `${model.keys[0].type} | ` : \"\";\r\n const keyTypes = model.keys\r\n .map((keyProp) => `${keyProp.name}: ${this.getPropType(file.getImports(), keyProp)}`)\r\n .join(\",\");\r\n const type = `${singleType}{${keyTypes}}`;\r\n\r\n file.getFile().addTypeAlias({\r\n name: model.id.modelName,\r\n isExported: true,\r\n type,\r\n });\r\n }\r\n\r\n private generateEditableModel(file: FileHandler, model: ComplexType) {\r\n const entityTypes = [DataTypes.ModelType, DataTypes.ComplexType];\r\n const allProps = [...model.baseProps, ...model.props].filter((p) => !p.managed);\r\n\r\n const requiredProps = allProps\r\n .filter((p) => p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const optionalProps = allProps\r\n .filter((p) => !p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const complexProps = allProps.filter((p) => p.dataType === DataTypes.ComplexType);\r\n\r\n const extendsClause = [\r\n requiredProps ? `Pick<${model.modelName}, ${requiredProps}>` : null,\r\n optionalProps ? `Partial<Pick<${model.modelName}, ${optionalProps}>>` : null,\r\n ].filter((e): e is string => !!e);\r\n\r\n file.getFile().addInterface({\r\n name: model.editableName,\r\n isExported: true,\r\n extends: extendsClause,\r\n properties: !complexProps\r\n ? undefined\r\n : complexProps.map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getEditablePropType(file.getImports(), p),\r\n // optional props don't need to be specified in editable model\r\n // also, entities would require deep insert func => we make it optional for now\r\n hasQuestionToken: !p.required || p.dataType === DataTypes.ModelType,\r\n };\r\n }),\r\n });\r\n }\r\n\r\n private getEditablePropType(imports: ImportContainer, prop: PropertyModel): string {\r\n const isModelType = [DataTypes.ModelType, DataTypes.ComplexType].includes(prop.dataType);\r\n\r\n let editableType = prop.type;\r\n if (isModelType) {\r\n const editName = this.dataModel.getComplexType(prop.fqType)!.editableName;\r\n editableType = imports.addGeneratedModel(prop.fqType, editName);\r\n }\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n return `Array<${editableType}>`;\r\n }\r\n\r\n // primitive, enum & complex types\r\n return editableType + (prop.required ? \"\" : \" | null\");\r\n }\r\n\r\n private async generateUnboundOperationParams() {\r\n const unboundOps = this.dataModel.getUnboundOperationTypes();\r\n const reservedNames = unboundOps.map((op) => op.paramsModelName);\r\n const file = this.project.createOrGetMainModelFile(reservedNames);\r\n\r\n unboundOps.forEach((operation) => {\r\n this.generateOperationParams(file, operation);\r\n });\r\n }\r\n\r\n private generateOperationParams(file: FileHandler, operation: OperationType) {\r\n const paramSets = [operation.parameters, ...(operation.overrides ?? [])].filter((pSet) => !!pSet.length);\r\n\r\n // standard: one interface for parameters\r\n if (paramSets.length === 1) {\r\n file.getFile().addInterface({\r\n name: operation.paramsModelName,\r\n isExported: true,\r\n properties: paramSets[0].map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getPropType(file.getImports(), p),\r\n hasQuestionToken: !p.required,\r\n };\r\n }),\r\n });\r\n }\r\n // function overload: one type with intersections of different param models\r\n else if (paramSets.length > 1) {\r\n file.getFile().addTypeAlias({\r\n name: operation.paramsModelName,\r\n isExported: true,\r\n type: (writer) => {\r\n paramSets.forEach((pSet, index) => {\r\n writer.block(() => {\r\n pSet.forEach((param, index) => {\r\n const paramType = this.getPropType(file.getImports(), param);\r\n writer.write(`${param.name}${param.required ? \"\" : \"?\"}: ${paramType}`);\r\n if (index < pSet.length - 1) {\r\n writer.write(\",\");\r\n }\r\n });\r\n });\r\n if (index < paramSets.length - 1) {\r\n writer.write(\" | \");\r\n }\r\n });\r\n },\r\n });\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -100,14 +100,24 @@ class QueryObjectGenerator {
|
|
|
100
100
|
const { odataName } = prop;
|
|
101
101
|
const name = this.namingHelper.getQPropName(prop.name);
|
|
102
102
|
const isModelType = prop.dataType === "ModelType" /* DataTypes.ModelType */ || prop.dataType === "ComplexType" /* DataTypes.ComplexType */;
|
|
103
|
+
const isEnumType = prop.dataType === "EnumType" /* DataTypes.EnumType */;
|
|
104
|
+
const isNumericEnum = this.options.numericEnums;
|
|
103
105
|
let qPathInit;
|
|
104
106
|
// factor in collections
|
|
105
107
|
if (prop.isCollection) {
|
|
106
|
-
const qPath = importContainer.addQObject(isModelType
|
|
108
|
+
const qPath = importContainer.addQObject(isModelType
|
|
109
|
+
? QueryObjectImports.QEntityCollectionPath
|
|
110
|
+
: isEnumType
|
|
111
|
+
? isNumericEnum
|
|
112
|
+
? QueryObjectImports.QNumericEnumCollectionPath
|
|
113
|
+
: QueryObjectImports.QEnumCollectionPath
|
|
114
|
+
: QueryObjectImports.QCollectionPath);
|
|
107
115
|
const qObject = isModelType
|
|
108
116
|
? importContainer.addGeneratedQObject(prop.fqType, prop.qObject)
|
|
109
|
-
:
|
|
110
|
-
|
|
117
|
+
: isEnumType
|
|
118
|
+
? importContainer.addGeneratedModel(prop.fqType, prop.type, false)
|
|
119
|
+
: importContainer.addQObject(prop.qObject);
|
|
120
|
+
qPathInit = `new ${qPath}(this.withPrefix("${odataName}"), ${isEnumType ? qObject : `() => ${qObject}`})`;
|
|
111
121
|
}
|
|
112
122
|
else {
|
|
113
123
|
// add import for data type
|
|
@@ -116,6 +126,10 @@ class QueryObjectGenerator {
|
|
|
116
126
|
const qObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject);
|
|
117
127
|
qPathInit = `new ${qPath}(this.withPrefix("${odataName}"), () => ${qObject})`;
|
|
118
128
|
}
|
|
129
|
+
else if (isEnumType) {
|
|
130
|
+
const qObject = importContainer.addGeneratedModel(prop.fqType, prop.type, false);
|
|
131
|
+
qPathInit = `new ${qPath}(this.withPrefix("${odataName}"), ${qObject})`;
|
|
132
|
+
}
|
|
119
133
|
else {
|
|
120
134
|
let converterStmt = this.generateConverterStmt(importContainer, prop.converters);
|
|
121
135
|
qPathInit = `new ${qPath}(this.withPrefix("${odataName}")${converterStmt ? `, ${converterStmt}` : ""})`;
|