@odata2ts/odata2ts 0.35.0 → 0.36.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/app.js +1 -0
- package/lib/app.js.map +1 -1
- package/lib/data-model/DataModel.js +20 -3
- package/lib/data-model/DataModel.js.map +1 -1
- package/lib/data-model/DataModelDigestion.d.ts +15 -0
- package/lib/data-model/DataModelDigestion.js +73 -22
- package/lib/data-model/DataModelDigestion.js.map +1 -1
- package/lib/data-model/DataTypeModel.d.ts +3 -0
- package/lib/data-model/DataTypeModel.js.map +1 -1
- package/lib/data-model/validation/NameClashValidator.js +12 -2
- package/lib/data-model/validation/NameClashValidator.js.map +1 -1
- package/lib/generator/ImportContainer.d.ts +11 -9
- package/lib/generator/ImportContainer.js +96 -75
- package/lib/generator/ImportContainer.js.map +1 -1
- package/lib/generator/ModelGenerator.js +40 -15
- package/lib/generator/ModelGenerator.js.map +1 -1
- package/lib/generator/QueryObjectGenerator.js +43 -34
- package/lib/generator/QueryObjectGenerator.js.map +1 -1
- package/lib/generator/ServiceGenerator.js +40 -27
- package/lib/generator/ServiceGenerator.js.map +1 -1
- package/lib/generator/import/ImportObjects.d.ts +12 -12
- package/lib/generator/import/ImportObjects.js +12 -12
- package/lib/generator/import/ImportObjects.js.map +1 -1
- package/lib/project/FileHandler.d.ts +4 -14
- package/lib/project/FileHandler.js +14 -6
- package/lib/project/FileHandler.js.map +1 -1
- package/lib/project/ProjectManager.d.ts +1 -0
- package/lib/project/ProjectManager.js +8 -5
- package/lib/project/ProjectManager.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ValueConverterImport } from "@odata2ts/converter-runtime";
|
|
2
|
+
import { Modes } from "../OptionModel";
|
|
2
3
|
export declare enum ODataVersion {
|
|
3
4
|
V2 = "2.0",
|
|
4
5
|
V4 = "4.0"
|
|
@@ -58,6 +59,7 @@ export interface ComplexType {
|
|
|
58
59
|
finalBaseClass: string | undefined;
|
|
59
60
|
abstract: boolean;
|
|
60
61
|
open: boolean;
|
|
62
|
+
genMode: Modes;
|
|
61
63
|
}
|
|
62
64
|
export interface EnumType {
|
|
63
65
|
dataType: DataTypes;
|
|
@@ -78,6 +80,7 @@ export interface OperationType {
|
|
|
78
80
|
parameters: Array<PropertyModel>;
|
|
79
81
|
returnType?: ReturnTypeModel;
|
|
80
82
|
usePost?: boolean;
|
|
83
|
+
overrides?: Array<Array<PropertyModel>>;
|
|
81
84
|
}
|
|
82
85
|
export interface ReturnTypeModel extends PropertyModel {
|
|
83
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTypeModel.js","sourceRoot":"","sources":["../../src/data-model/DataTypeModel.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"DataTypeModel.js","sourceRoot":"","sources":["../../src/data-model/DataTypeModel.ts"],"names":[],"mappings":";;;AAIA,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,0BAAU,CAAA;IACV,0BAAU,CAAA;AACZ,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\r\n\r\nimport { Modes } from \"../OptionModel\";\r\n\r\nexport enum ODataVersion {\r\n V2 = \"2.0\",\r\n V4 = \"4.0\",\r\n}\r\n\r\nexport const enum DataTypes {\r\n PrimitiveType = \"PrimitiveType\",\r\n EnumType = \"EnumType\",\r\n ComplexType = \"ComplexType\",\r\n ModelType = \"ModelType\",\r\n}\r\n\r\nexport const enum OperationTypes {\r\n Function = \"Function\",\r\n Action = \"Action\",\r\n}\r\n\r\nexport interface PropertyModel {\r\n odataName: string;\r\n name: string;\r\n odataType: string;\r\n fqType: string;\r\n type: string;\r\n typeModule?: string;\r\n qObject?: string;\r\n qPath: string;\r\n qParam?: string;\r\n required: boolean;\r\n isCollection: boolean;\r\n dataType: DataTypes;\r\n converters?: Array<ValueConverterImport>;\r\n managed?: boolean;\r\n}\r\n\r\nexport type ModelType = EntityType | ComplexType | EnumType;\r\n\r\nexport interface EntityType extends ComplexType {\r\n id: {\r\n // fully qualified name of entity to which this id belongs (might have been inherited)\r\n fqName: string;\r\n // that's the name of the param model for the id function\r\n modelName: string;\r\n // that's the name of the id function which is a q-object\r\n qName: string;\r\n };\r\n generateId: boolean;\r\n keyNames: Array<string>;\r\n keys: Array<PropertyModel>;\r\n getKeyUnion(): string;\r\n}\r\n\r\nexport interface ComplexType {\r\n dataType: DataTypes;\r\n fqName: string;\r\n odataName: string;\r\n name: string;\r\n modelName: string;\r\n editableName: string;\r\n qName: string;\r\n serviceName: string;\r\n serviceCollectionName: string;\r\n folderPath: string;\r\n props: Array<PropertyModel>;\r\n baseProps: Array<PropertyModel>;\r\n baseClasses: Array<string>;\r\n finalBaseClass: string | undefined;\r\n abstract: boolean;\r\n open: boolean;\r\n genMode: Modes;\r\n}\r\n\r\nexport interface EnumType {\r\n dataType: DataTypes;\r\n odataName: string;\r\n fqName: string;\r\n name: string;\r\n modelName: string;\r\n folderPath: string;\r\n members: Array<string>;\r\n}\r\n\r\nexport interface OperationType {\r\n fqName: string;\r\n odataName: string;\r\n name: string;\r\n qName: string;\r\n paramsModelName: string;\r\n type: OperationTypes;\r\n parameters: Array<PropertyModel>;\r\n returnType?: ReturnTypeModel;\r\n usePost?: boolean;\r\n overrides?: Array<Array<PropertyModel>>;\r\n}\r\n\r\nexport interface ReturnTypeModel extends PropertyModel {}\r\n\r\nexport type EntityContainerModel = {\r\n entitySets: { [name: string]: EntitySetType };\r\n singletons: { [name: string]: SingletonType };\r\n functions: { [name: string]: FunctionImportType };\r\n actions: { [name: string]: ActionImportType };\r\n};\r\n\r\nexport interface SingletonType {\r\n fqName: string;\r\n odataName: string;\r\n name: string;\r\n entityType: EntityType;\r\n navPropBinding?: Array<NavPropBindingType>;\r\n}\r\n\r\nexport interface EntitySetType {\r\n fqName: string;\r\n odataName: string;\r\n name: string;\r\n entityType: EntityType;\r\n navPropBinding?: Array<NavPropBindingType>;\r\n}\r\n\r\nexport interface NavPropBindingType {\r\n path: string;\r\n target: string;\r\n}\r\n\r\nexport interface ActionImportType {\r\n fqName: string;\r\n odataName: string;\r\n name: string;\r\n operation: string;\r\n}\r\n\r\nexport interface FunctionImportType extends ActionImportType {\r\n entitySet: string;\r\n}\r\n"]}
|
|
@@ -58,13 +58,23 @@ class NameClashValidator {
|
|
|
58
58
|
return this.addToTypes(fqName, name, TypeModel_1.TypeModel.EnumType);
|
|
59
59
|
}
|
|
60
60
|
addUnboundOperationType(fqName, name) {
|
|
61
|
-
|
|
61
|
+
const validationObject = { type: TypeModel_1.TypeModel.OperationType, fqName };
|
|
62
|
+
const hit = this.store.get(name);
|
|
63
|
+
// to support function overloads: allow multiple operation definitions with same fully qualified name
|
|
64
|
+
if (hit && hit.fqName !== fqName) {
|
|
65
|
+
return this.addToError(name, hit, validationObject);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
this.store.set(name, validationObject);
|
|
69
|
+
return name;
|
|
70
|
+
}
|
|
62
71
|
}
|
|
63
72
|
addBoundOperationType(bindingName, fqName, name) {
|
|
64
73
|
const nameWithBinding = `${bindingName}_${name}`;
|
|
65
74
|
const validationObject = { type: TypeModel_1.TypeModel.OperationType, fqName };
|
|
66
75
|
const hit = this.store.get(nameWithBinding);
|
|
67
|
-
|
|
76
|
+
// to support function overloads: allow multiple operation definitions with same fully qualified name
|
|
77
|
+
if (hit && hit.fqName !== fqName) {
|
|
68
78
|
return this.addToError(name, hit, validationObject);
|
|
69
79
|
}
|
|
70
80
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NameClashValidator.js","sourceRoot":"","sources":["../../../src/data-model/validation/NameClashValidator.ts"],"names":[],"mappings":";;;AACA,+CAA4C;AAM5C,MAAa,kBAAkB;IAK7B,YAAoB,UAAgC,EAAE;QAAlC,YAAO,GAAP,OAAO,CAA2B;QAJ9C,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oBAAoB,CAAC,MAAc,EAAE,IAAY,EAAE,IAAe;QACxE,MAAM,gBAAgB,GAAoB,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,GAAG,EAAE;YACP,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,gBAAgB,CAAC,CAAC;SACrD;aAAM;YACL,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;YACjD,OAAO,IAAI,CAAC;SACb;IACH,CAAC;IAED,aAAa,CAAC,MAAc,EAAE,IAAY;QACxC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,qBAAS,CAAC,UAAU,CAAC,CAAC;IAC7D,CAAC;IAED,cAAc,CAAC,MAAc,EAAE,IAAY;QACzC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,qBAAS,CAAC,WAAW,CAAC,CAAC;IAC9D,CAAC;IAED,WAAW,CAAC,MAAc,EAAE,IAAY;QACtC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,qBAAS,CAAC,QAAQ,CAAC,CAAC;IAC3D,CAAC;IAED,uBAAuB,CAAC,MAAc,EAAE,IAAY;QAClD,
|
|
1
|
+
{"version":3,"file":"NameClashValidator.js","sourceRoot":"","sources":["../../../src/data-model/validation/NameClashValidator.ts"],"names":[],"mappings":";;;AACA,+CAA4C;AAM5C,MAAa,kBAAkB;IAK7B,YAAoB,UAAgC,EAAE;QAAlC,YAAO,GAAP,OAAO,CAA2B;QAJ9C,oBAAe,GAAG,IAAI,GAAG,EAA2B,CAAC;QACrD,UAAK,GAAG,IAAI,GAAG,EAA2B,CAAC;QAC3C,WAAM,GAAG,IAAI,GAAG,EAA6B,CAAC;IAEG,CAAC;IAElD,UAAU,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AM,eAAe,GAAG,GAAG,WAAW,IAAI,IAAI,EAAE,CAAC;QACjD,MAAM,gBAAgB,GAAoB,EAAE,IAAI,EAAE,qBAAS,CAAC,aAAa,EAAE,MAAM,EAAE,CAAC;QACpF,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAC5C,qGAAqG;QACrG,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE;YAChC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,gBAAgB,CAAC,CAAC;SACrD;aAAM;YACL,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;YAClD,OAAO,IAAI,CAAC;SACb;IACH,CAAC;IAED,sBAAsB,CAAC,MAAc,EAAE,IAAY;QACjD,OAAO,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,EAAE,qBAAS,CAAC,mBAAmB,CAAC,CAAC;IAChF,CAAC;IAED,YAAY,CAAC,MAAc,EAAE,IAAY;QACvC,OAAO,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,EAAE,qBAAS,CAAC,SAAS,CAAC,CAAC;IACtE,CAAC;IAED,YAAY,CAAC,MAAc,EAAE,IAAY;QACvC,OAAO,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,EAAE,qBAAS,CAAC,SAAS,CAAC,CAAC;IACtE,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAlGD,gDAkGC","sourcesContent":["import { ConfigFileOptions } from \"../../OptionModel\";\r\nimport { TypeModel } from \"../../TypeModel\";\r\nimport { NameValidator, ValidationError } from \"./NameValidator\";\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) {\r\n const validationObject: ValidationError = { type: TypeModel.OperationType, fqName };\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 && 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) {\r\n const nameWithBinding = `${bindingName}_${name}`;\r\n const validationObject: ValidationError = { type: TypeModel.OperationType, fqName };\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 && 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,5 +1,5 @@
|
|
|
1
1
|
import { ODataVersions } from "@odata2ts/odata-core";
|
|
2
|
-
import { ImportDeclarationStructure } from "ts-morph";
|
|
2
|
+
import { ImportDeclarationStructure, OptionalKind } from "ts-morph";
|
|
3
3
|
import { DataModel } from "../data-model/DataModel";
|
|
4
4
|
import { ClientApiImports, CoreImports, QueryObjectImports, ServiceImports } from "./import/ImportObjects";
|
|
5
5
|
/**
|
|
@@ -30,19 +30,21 @@ export declare class ImportContainer {
|
|
|
30
30
|
qObject: string;
|
|
31
31
|
service: string;
|
|
32
32
|
}, bundledFileGeneration: boolean, reservedNames: Array<string> | undefined);
|
|
33
|
-
addCoreLib(odataVersion: ODataVersions,
|
|
34
|
-
addFromQObject
|
|
35
|
-
addQObject(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
addCoreLib(odataVersion: ODataVersions, coreLib: CoreImports): string;
|
|
34
|
+
private addFromQObject;
|
|
35
|
+
addQObject(qObject: QueryObjectImports | string): string;
|
|
36
|
+
addQObjectType(qObject: string): string;
|
|
37
|
+
addClientApi(clientApi: ClientApiImports): string;
|
|
38
|
+
addServiceObject(odataVersion: ODataVersions, serviceObject: ServiceImports): string;
|
|
39
|
+
addCustomType(moduleName: string, typeName: string, isTypeOnly?: boolean): string;
|
|
39
40
|
private pathAndFile;
|
|
40
41
|
private isDifferentFile;
|
|
41
42
|
private addGeneratedImport;
|
|
42
43
|
addGeneratedModel(fqName: string, name: string): string;
|
|
43
|
-
addGeneratedQObject(fqName: string, name: string): string;
|
|
44
|
+
addGeneratedQObject(fqName: string, name: string, isTypeOnly?: boolean): string;
|
|
44
45
|
addGeneratedService(fqName: string, name: string): string;
|
|
45
|
-
|
|
46
|
+
private createImportDecl;
|
|
47
|
+
getImportDeclarations(): Array<OptionalKind<ImportDeclarationStructure>>;
|
|
46
48
|
private getNamedImports;
|
|
47
49
|
private getModuleSpecifier;
|
|
48
50
|
}
|
|
@@ -6,6 +6,7 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
6
6
|
const odata_core_1 = require("@odata2ts/odata-core");
|
|
7
7
|
const ImportObjects_1 = require("./import/ImportObjects");
|
|
8
8
|
const ImportedNameValidator_1 = require("./ImportedNameValidator");
|
|
9
|
+
function generateImportId() { }
|
|
9
10
|
/**
|
|
10
11
|
* Handles all the import statements for a given file.
|
|
11
12
|
*
|
|
@@ -23,61 +24,66 @@ class ImportContainer {
|
|
|
23
24
|
this.bundledFileGeneration = bundledFileGeneration;
|
|
24
25
|
this.reservedNames = reservedNames;
|
|
25
26
|
// mapping of a custom defined type to a primitive type
|
|
26
|
-
this.customTypes =
|
|
27
|
+
this.customTypes = {
|
|
28
|
+
regular: new Map(),
|
|
29
|
+
typeOnly: new Map(),
|
|
30
|
+
};
|
|
27
31
|
// imports to generated artefacts
|
|
28
|
-
this.internalImports =
|
|
32
|
+
this.internalImports = {
|
|
33
|
+
regular: new Map(),
|
|
34
|
+
typeOnly: new Map(),
|
|
35
|
+
};
|
|
29
36
|
this.libs = {
|
|
30
|
-
core: new Map(),
|
|
31
|
-
qObject: new Map(),
|
|
32
|
-
clientApi: new Map(),
|
|
33
|
-
service: new Map(),
|
|
37
|
+
core: { regular: new Map(), typeOnly: new Map() },
|
|
38
|
+
qObject: { regular: new Map(), typeOnly: new Map() },
|
|
39
|
+
clientApi: { regular: new Map(), typeOnly: new Map() },
|
|
40
|
+
service: { regular: new Map(), typeOnly: new Map() },
|
|
34
41
|
};
|
|
35
42
|
this.importedNameValidator = new ImportedNameValidator_1.ImportedNameValidator(reservedNames);
|
|
36
43
|
}
|
|
37
|
-
addCoreLib(odataVersion,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
addFromQObject(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
let importList =
|
|
44
|
+
addCoreLib(odataVersion, coreLib) {
|
|
45
|
+
const isVersioned = ImportObjects_1.VERSIONED_CORE_IMPORTS.includes(coreLib);
|
|
46
|
+
const name = ImportObjects_1.CoreImports[coreLib] + (isVersioned ? odata_core_1.ODataVersions[odataVersion] : "");
|
|
47
|
+
const importName = this.importedNameValidator.validateName(ImportObjects_1.LIB_MODULES.core, name);
|
|
48
|
+
// TODO: currently only types are imported, however enums could potentially be imported too
|
|
49
|
+
this.libs.core.typeOnly.set(name, importName);
|
|
50
|
+
return importName;
|
|
51
|
+
}
|
|
52
|
+
addFromQObject(name, typeOnlyImport = false) {
|
|
53
|
+
const importName = this.importedNameValidator.validateName(ImportObjects_1.LIB_MODULES.qObject, name);
|
|
54
|
+
const imports = typeOnlyImport ? this.libs.qObject.typeOnly : this.libs.qObject.regular;
|
|
55
|
+
imports.set(name, importName);
|
|
56
|
+
return importName;
|
|
57
|
+
}
|
|
58
|
+
addQObject(qObject) {
|
|
59
|
+
return this.addFromQObject(qObject);
|
|
60
|
+
}
|
|
61
|
+
addQObjectType(qObject) {
|
|
62
|
+
return this.addFromQObject(qObject, true);
|
|
63
|
+
}
|
|
64
|
+
addClientApi(clientApi) {
|
|
65
|
+
const name = ImportObjects_1.ClientApiImports[clientApi];
|
|
66
|
+
const importName = this.importedNameValidator.validateName(ImportObjects_1.LIB_MODULES.clientApi, name);
|
|
67
|
+
// complete client api consists only of types
|
|
68
|
+
this.libs.clientApi.typeOnly.set(name, importName);
|
|
69
|
+
return importName;
|
|
70
|
+
}
|
|
71
|
+
addServiceObject(odataVersion, serviceObject) {
|
|
72
|
+
const isVersioned = ImportObjects_1.VERSIONED_SERVICE_IMPORTS.includes(serviceObject);
|
|
73
|
+
const name = ImportObjects_1.ServiceImports[serviceObject] + (isVersioned ? odata_core_1.ODataVersions[odataVersion] : "");
|
|
74
|
+
const importName = this.importedNameValidator.validateName(ImportObjects_1.LIB_MODULES.service, name);
|
|
75
|
+
// only regular imports for the service package
|
|
76
|
+
this.libs.service.regular.set(name, importName);
|
|
77
|
+
return importName;
|
|
78
|
+
}
|
|
79
|
+
addCustomType(moduleName, typeName, isTypeOnly = false) {
|
|
80
|
+
const importName = this.importedNameValidator.validateName(moduleName, typeName);
|
|
81
|
+
const imports = isTypeOnly ? this.customTypes.typeOnly : this.customTypes.regular;
|
|
82
|
+
let importList = imports.get(moduleName);
|
|
76
83
|
if (!importList) {
|
|
77
84
|
importList = new Map();
|
|
78
|
-
|
|
85
|
+
imports.set(moduleName, importList);
|
|
79
86
|
}
|
|
80
|
-
const importName = this.importedNameValidator.validateName(moduleName, typeName);
|
|
81
87
|
importList.set(typeName, importName);
|
|
82
88
|
return importName;
|
|
83
89
|
}
|
|
@@ -87,21 +93,22 @@ class ImportContainer {
|
|
|
87
93
|
isDifferentFile(filePath, fileName) {
|
|
88
94
|
return this.pathAndFile(this.path, this.fileName) !== this.pathAndFile(filePath, fileName);
|
|
89
95
|
}
|
|
90
|
-
addGeneratedImport(folderPath, fileName, name) {
|
|
96
|
+
addGeneratedImport(folderPath, fileName, name, isTypeOnly = false) {
|
|
91
97
|
// imports are only relevant for different files
|
|
92
98
|
if (!this.isDifferentFile(folderPath, fileName)) {
|
|
93
99
|
return name;
|
|
94
100
|
}
|
|
95
101
|
const moduleName = this.pathAndFile(folderPath, fileName);
|
|
96
102
|
const importName = this.importedNameValidator.validateName(moduleName, name);
|
|
97
|
-
const imports = this.internalImports.
|
|
98
|
-
imports.
|
|
99
|
-
|
|
103
|
+
const imports = isTypeOnly ? this.internalImports.typeOnly : this.internalImports.regular;
|
|
104
|
+
const importList = imports.get(moduleName) || new Map();
|
|
105
|
+
importList.set(name, importName);
|
|
106
|
+
imports.set(moduleName, importList);
|
|
100
107
|
return importName;
|
|
101
108
|
}
|
|
102
109
|
addGeneratedModel(fqName, name) {
|
|
103
110
|
if (this.bundledFileGeneration) {
|
|
104
|
-
return this.addGeneratedImport("", this.mainFileNames.model, name);
|
|
111
|
+
return this.addGeneratedImport("", this.mainFileNames.model, name, true);
|
|
105
112
|
}
|
|
106
113
|
else {
|
|
107
114
|
const model = this.dataModel.getModel(fqName);
|
|
@@ -110,10 +117,10 @@ class ImportContainer {
|
|
|
110
117
|
}
|
|
111
118
|
const folderPath = model ? model.folderPath : "";
|
|
112
119
|
const modelName = model ? model.modelName : this.mainFileNames.model;
|
|
113
|
-
return this.addGeneratedImport(folderPath, modelName, name);
|
|
120
|
+
return this.addGeneratedImport(folderPath, modelName, name, true);
|
|
114
121
|
}
|
|
115
122
|
}
|
|
116
|
-
addGeneratedQObject(fqName, name) {
|
|
123
|
+
addGeneratedQObject(fqName, name, isTypeOnly = false) {
|
|
117
124
|
if (this.bundledFileGeneration) {
|
|
118
125
|
return this.addGeneratedImport("", this.mainFileNames.qObject, name);
|
|
119
126
|
}
|
|
@@ -124,7 +131,7 @@ class ImportContainer {
|
|
|
124
131
|
}
|
|
125
132
|
const folderPath = model ? model.folderPath : "";
|
|
126
133
|
const qName = model ? model.qName : this.mainFileNames.qObject;
|
|
127
|
-
return this.addGeneratedImport(folderPath, qName, name);
|
|
134
|
+
return this.addGeneratedImport(folderPath, qName, name, isTypeOnly);
|
|
128
135
|
}
|
|
129
136
|
}
|
|
130
137
|
addGeneratedService(fqName, name) {
|
|
@@ -136,32 +143,46 @@ class ImportContainer {
|
|
|
136
143
|
return this.addGeneratedImport(model.folderPath, model.serviceName, name);
|
|
137
144
|
}
|
|
138
145
|
}
|
|
139
|
-
|
|
146
|
+
createImportDecl(module, toImport, isTypeOnly = false) {
|
|
147
|
+
return {
|
|
148
|
+
namedImports: this.getNamedImports(toImport),
|
|
149
|
+
moduleSpecifier: module,
|
|
150
|
+
isTypeOnly,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
getImportDeclarations() {
|
|
140
154
|
return [
|
|
141
|
-
...Object.entries(this.libs)
|
|
142
|
-
|
|
155
|
+
...Object.entries(this.libs).reduce((result, [moduleName, toImport]) => {
|
|
156
|
+
const module = ImportObjects_1.LIB_MODULES[moduleName];
|
|
157
|
+
if (toImport.typeOnly.size) {
|
|
158
|
+
result.push(this.createImportDecl(module, toImport.typeOnly, true));
|
|
159
|
+
}
|
|
160
|
+
if (toImport.regular.size) {
|
|
161
|
+
result.push(this.createImportDecl(module, toImport.regular));
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}, []),
|
|
165
|
+
...[...this.customTypes.typeOnly]
|
|
166
|
+
.filter(([moduleName, toImport]) => toImport.size > 0)
|
|
167
|
+
.map(([moduleName, toImport]) => {
|
|
168
|
+
return this.createImportDecl(moduleName, toImport, true);
|
|
169
|
+
}),
|
|
170
|
+
...[...this.customTypes.regular]
|
|
171
|
+
.filter(([moduleName, toImport]) => toImport.size > 0)
|
|
143
172
|
.map(([moduleName, toImport]) => {
|
|
144
|
-
return
|
|
145
|
-
namedImports: this.getNamedImports(toImport),
|
|
146
|
-
moduleSpecifier: ImportObjects_1.LIB_MODULES[moduleName],
|
|
147
|
-
};
|
|
173
|
+
return this.createImportDecl(moduleName, toImport);
|
|
148
174
|
}),
|
|
149
|
-
...[...this.
|
|
150
|
-
.filter((
|
|
151
|
-
.map((
|
|
152
|
-
const
|
|
153
|
-
return
|
|
154
|
-
namedImports: this.getNamedImports(toImport),
|
|
155
|
-
moduleSpecifier: moduleName,
|
|
156
|
-
};
|
|
175
|
+
...[...this.internalImports.typeOnly]
|
|
176
|
+
.filter(([_, toImport]) => toImport.size > 0)
|
|
177
|
+
.map(([key, toImport]) => {
|
|
178
|
+
const module = this.getModuleSpecifier(key);
|
|
179
|
+
return this.createImportDecl(module, toImport, true);
|
|
157
180
|
}),
|
|
158
|
-
...[...this.internalImports.
|
|
181
|
+
...[...this.internalImports.regular]
|
|
159
182
|
.filter(([_, toImport]) => toImport.size > 0)
|
|
160
183
|
.map(([key, toImport]) => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
moduleSpecifier: this.getModuleSpecifier(key),
|
|
164
|
-
};
|
|
184
|
+
const module = this.getModuleSpecifier(key);
|
|
185
|
+
return this.createImportDecl(module, toImport);
|
|
165
186
|
}),
|
|
166
187
|
];
|
|
167
188
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportContainer.js","sourceRoot":"","sources":["../../src/generator/ImportContainer.ts"],"names":[],"mappings":";;;;AAAA,wDAAwB;AAExB,qDAAqD;AAKrD,0DAQgC;AAChC,mEAAgE;AAIhE;;;;;;;GAOG;AACH,MAAa,eAAe;IAc1B,YACY,IAAY,EACZ,QAAgB,EAChB,SAAoB,EACpB,aAAkE,EACzD,qBAA8B,EAC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D,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;AAvLD,0CAuLC","sourcesContent":["import path from \"path\";\r\n\r\nimport { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { ImportDeclarationStructure } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport { ComplexType, OperationType } 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<keyof typeof LIB_MODULES, Map<string, string>>;\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 = new Map<string, Map<string, string>>();\r\n // imports to generated artefacts\r\n private internalImports = new Map<string, Map<string, string>>();\r\n\r\n private libs: ImportContainerType = {\r\n core: new Map(),\r\n qObject: new Map(),\r\n clientApi: new Map(),\r\n service: 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, ...coreLibs: Array<CoreImports>) {\r\n return coreLibs.map((coreLib) => {\r\n const name = CoreImports[coreLib] + (VERSIONED_CORE_IMPORTS.includes(coreLib) ? ODataVersions[odataVersion] : \"\");\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.core, name);\r\n this.libs.core.set(name, importName);\r\n return importName;\r\n });\r\n }\r\n\r\n public addFromQObject(...names: Array<string>) {\r\n return names.map((n) => {\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.qObject, n);\r\n this.libs.qObject.set(n, importName);\r\n return importName;\r\n });\r\n }\r\n\r\n public addQObject(...qObjects: Array<QueryObjectImports>) {\r\n return this.addFromQObject(...qObjects.map((qObject) => QueryObjectImports[qObject]));\r\n }\r\n\r\n public addClientApi(...clientApis: Array<ClientApiImports>) {\r\n return clientApis.map((clientApi) => {\r\n const name = ClientApiImports[clientApi];\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.clientApi, name);\r\n this.libs.clientApi.set(name, importName);\r\n return importName;\r\n });\r\n }\r\n\r\n public addServiceObject(odataVersion: ODataVersions, ...serviceObjects: Array<ServiceImports>) {\r\n return serviceObjects\r\n .map((so) => {\r\n return ServiceImports[so] + (VERSIONED_SERVICE_IMPORTS.includes(so) ? ODataVersions[odataVersion] : \"\");\r\n })\r\n .map((so) => {\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.service, so);\r\n this.libs.service.set(so, importName);\r\n return importName;\r\n });\r\n }\r\n\r\n public addCustomType(moduleName: string, typeName: string) {\r\n let importList = this.customTypes.get(moduleName);\r\n if (!importList) {\r\n importList = new Map();\r\n this.customTypes.set(moduleName, importList);\r\n }\r\n\r\n const importName = this.importedNameValidator.validateName(moduleName, typeName);\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): 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\r\n const imports = this.internalImports.get(moduleName) || new Map<string, string>();\r\n imports.set(name, importName);\r\n this.internalImports.set(moduleName, imports);\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);\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);\r\n }\r\n }\r\n\r\n public addGeneratedQObject(fqName: string, name: string) {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.qObject, name);\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);\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 public getImportDeclarations(fromSubPath: boolean = false): Array<ImportDeclarationStructure> {\r\n return [\r\n ...Object.entries(this.libs)\r\n .filter(([_, values]) => !!values.size)\r\n .map(([moduleName, toImport]) => {\r\n return {\r\n namedImports: this.getNamedImports(toImport),\r\n moduleSpecifier: LIB_MODULES[moduleName as keyof typeof LIB_MODULES],\r\n } as ImportDeclarationStructure;\r\n }),\r\n ...[...this.customTypes.keys()]\r\n .filter((moduleName) => !!this.customTypes.get(moduleName)?.size)\r\n .map((moduleName) => {\r\n const toImport = this.customTypes.get(moduleName)!;\r\n return {\r\n namedImports: this.getNamedImports(toImport),\r\n moduleSpecifier: moduleName,\r\n } as ImportDeclarationStructure;\r\n }),\r\n ...[...this.internalImports.entries()]\r\n .filter(([_, toImport]) => toImport.size > 0)\r\n .map(([key, toImport]) => {\r\n return {\r\n namedImports: this.getNamedImports(toImport),\r\n moduleSpecifier: this.getModuleSpecifier(key),\r\n } as ImportDeclarationStructure;\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,wDAAwB;AAExB,qDAAqD;AAKrD,0DAQgC;AAChC,mEA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C,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,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, OperationType } 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\nfunction generateImportId() {}\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);\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"]}
|
|
@@ -140,13 +140,13 @@ class ModelGenerator {
|
|
|
140
140
|
// V2 entity special: deferred content
|
|
141
141
|
let suffix = "";
|
|
142
142
|
if (this.dataModel.isV2() && prop.dataType == "ModelType" /* DataTypes.ModelType */) {
|
|
143
|
-
const
|
|
143
|
+
const defContent = imports.addCoreLib(this.version, ImportObjects_1.CoreImports.DeferredContent);
|
|
144
144
|
suffix = ` | ${defContent}`;
|
|
145
145
|
}
|
|
146
146
|
let typeName;
|
|
147
147
|
if (prop.dataType === "PrimitiveType" /* DataTypes.PrimitiveType */) {
|
|
148
148
|
// custom types which require type imports => possible via converters
|
|
149
|
-
typeName = prop.typeModule ? imports.addCustomType(prop.typeModule, prop.type) : prop.type;
|
|
149
|
+
typeName = prop.typeModule ? imports.addCustomType(prop.typeModule, prop.type, true) : prop.type;
|
|
150
150
|
}
|
|
151
151
|
else {
|
|
152
152
|
typeName = imports.addGeneratedModel(prop.fqType, prop.type);
|
|
@@ -234,20 +234,45 @@ class ModelGenerator {
|
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
236
|
generateOperationParams(file, operation) {
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
var _a;
|
|
238
|
+
const paramSets = [operation.parameters, ...((_a = operation.overrides) !== null && _a !== void 0 ? _a : [])].filter((pSet) => !!pSet.length);
|
|
239
|
+
// standard: one interface for parameters
|
|
240
|
+
if (paramSets.length === 1) {
|
|
241
|
+
file.getFile().addInterface({
|
|
242
|
+
name: operation.paramsModelName,
|
|
243
|
+
isExported: true,
|
|
244
|
+
properties: paramSets[0].map((p) => {
|
|
245
|
+
return {
|
|
246
|
+
name: p.name,
|
|
247
|
+
type: this.getPropType(file.getImports(), p),
|
|
248
|
+
hasQuestionToken: !p.required,
|
|
249
|
+
};
|
|
250
|
+
}),
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
// function overload: one type with intersections of different param models
|
|
254
|
+
else if (paramSets.length > 1) {
|
|
255
|
+
file.getFile().addTypeAlias({
|
|
256
|
+
name: operation.paramsModelName,
|
|
257
|
+
isExported: true,
|
|
258
|
+
type: (writer) => {
|
|
259
|
+
paramSets.forEach((pSet, index) => {
|
|
260
|
+
writer.block(() => {
|
|
261
|
+
pSet.forEach((param, index) => {
|
|
262
|
+
const paramType = this.getPropType(file.getImports(), param);
|
|
263
|
+
writer.write(`${param.name}${param.required ? "" : "?"}: ${paramType}`);
|
|
264
|
+
if (index < pSet.length - 1) {
|
|
265
|
+
writer.write(",");
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
if (index < paramSets.length - 1) {
|
|
270
|
+
writer.write(" | ");
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
},
|
|
274
|
+
});
|
|
239
275
|
}
|
|
240
|
-
file.getFile().addInterface({
|
|
241
|
-
name: operation.paramsModelName,
|
|
242
|
-
isExported: true,
|
|
243
|
-
properties: operation.parameters.map((p) => {
|
|
244
|
-
return {
|
|
245
|
-
name: p.name,
|
|
246
|
-
type: this.getPropType(file.getImports(), p),
|
|
247
|
-
hasQuestionToken: !p.required,
|
|
248
|
-
};
|
|
249
|
-
}),
|
|
250
|
-
});
|
|
251
276
|
}
|
|
252
277
|
}
|
|
253
278
|
//# sourceMappingURL=ModelGenerator.js.map
|