@odata2ts/odata2ts 0.36.3 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/lib/FactoryFunctionModel.d.ts +5 -5
- package/lib/FactoryFunctionModel.js +1 -2
- package/lib/FactoryFunctionModel.js.map +1 -1
- package/lib/NamingModel.js +2 -5
- package/lib/NamingModel.js.map +1 -1
- package/lib/OptionModel.d.ts +2 -2
- package/lib/OptionModel.js +4 -7
- package/lib/OptionModel.js.map +1 -1
- package/lib/TypeModel.js +2 -5
- package/lib/TypeModel.js.map +1 -1
- package/lib/app.d.ts +2 -2
- package/lib/app.js +23 -27
- package/lib/app.js.map +1 -1
- package/lib/cli/cli.d.ts +1 -0
- package/lib/cli/cli.js +27 -0
- package/lib/cli/cli.js.map +1 -0
- package/lib/cli/index.d.ts +4 -0
- package/lib/cli/index.js +5 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/cli/processCliArgs.d.ts +2 -0
- package/lib/cli/processCliArgs.js +57 -0
- package/lib/cli/processCliArgs.js.map +1 -0
- package/lib/cli/processConfigFile.d.ts +2 -0
- package/lib/cli/processConfigFile.js +24 -0
- package/lib/cli/processConfigFile.js.map +1 -0
- package/lib/cli/serviceGenerationRun.d.ts +2 -0
- package/lib/cli/serviceGenerationRun.js +77 -0
- package/lib/cli/serviceGenerationRun.js.map +1 -0
- package/lib/data-model/DataModel.d.ts +2 -2
- package/lib/data-model/DataModel.js +5 -10
- package/lib/data-model/DataModel.js.map +1 -1
- package/lib/data-model/DataModelDigestion.d.ts +10 -10
- package/lib/data-model/DataModelDigestion.js +19 -23
- package/lib/data-model/DataModelDigestion.js.map +1 -1
- package/lib/data-model/DataModelDigestionV2.d.ts +2 -2
- package/lib/data-model/DataModelDigestionV2.js +27 -31
- package/lib/data-model/DataModelDigestionV2.js.map +1 -1
- package/lib/data-model/DataModelDigestionV4.d.ts +2 -2
- package/lib/data-model/DataModelDigestionV4.js +31 -35
- package/lib/data-model/DataModelDigestionV4.js.map +1 -1
- package/lib/data-model/DataTypeModel.d.ts +1 -1
- package/lib/data-model/DataTypeModel.js +2 -5
- package/lib/data-model/DataTypeModel.js.map +1 -1
- package/lib/data-model/NamingHelper.d.ts +2 -2
- package/lib/data-model/NamingHelper.js +12 -19
- package/lib/data-model/NamingHelper.js.map +1 -1
- package/lib/data-model/ServiceConfigHelper.d.ts +3 -3
- package/lib/data-model/ServiceConfigHelper.js +18 -22
- package/lib/data-model/ServiceConfigHelper.js.map +1 -1
- package/lib/data-model/edmx/ODataEdmxModelBase.js +1 -2
- package/lib/data-model/edmx/ODataEdmxModelV3.d.ts +1 -1
- package/lib/data-model/edmx/ODataEdmxModelV3.js +1 -2
- package/lib/data-model/edmx/ODataEdmxModelV3.js.map +1 -1
- package/lib/data-model/edmx/ODataEdmxModelV4.d.ts +1 -1
- package/lib/data-model/edmx/ODataEdmxModelV4.js +1 -2
- package/lib/data-model/edmx/ODataEdmxModelV4.js.map +1 -1
- package/lib/data-model/validation/NameClashValidator.d.ts +2 -2
- package/lib/data-model/validation/NameClashValidator.js +10 -14
- package/lib/data-model/validation/NameClashValidator.js.map +1 -1
- package/lib/data-model/validation/NameValidator.d.ts +1 -1
- package/lib/data-model/validation/NameValidator.js +1 -2
- package/lib/data-model/validation/NameValidator.js.map +1 -1
- package/lib/data-model/validation/NoopValidator.d.ts +1 -1
- package/lib/data-model/validation/NoopValidator.js +1 -5
- package/lib/data-model/validation/NoopValidator.js.map +1 -1
- package/lib/defaultConfig.d.ts +1 -1
- package/lib/defaultConfig.js +21 -26
- package/lib/defaultConfig.js.map +1 -1
- package/lib/download/downloadMetadata.d.ts +1 -1
- package/lib/download/downloadMetadata.js +6 -10
- package/lib/download/downloadMetadata.js.map +1 -1
- package/lib/download/index.d.ts +2 -2
- package/lib/download/index.js +2 -7
- package/lib/download/index.js.map +1 -1
- package/lib/download/storeMetadata.js +15 -17
- package/lib/download/storeMetadata.js.map +1 -1
- package/lib/evaluateConfig.d.ts +1 -1
- package/lib/evaluateConfig.js +14 -18
- package/lib/evaluateConfig.js.map +1 -1
- package/lib/generator/ImportContainer.d.ts +2 -2
- package/lib/generator/ImportContainer.js +17 -22
- package/lib/generator/ImportContainer.js.map +1 -1
- package/lib/generator/ImportedNameValidator.js +1 -5
- package/lib/generator/ImportedNameValidator.js.map +1 -1
- package/lib/generator/ModelGenerator.d.ts +1 -1
- package/lib/generator/ModelGenerator.js +8 -12
- package/lib/generator/ModelGenerator.js.map +1 -1
- package/lib/generator/QueryObjectGenerator.d.ts +1 -1
- package/lib/generator/QueryObjectGenerator.js +25 -29
- package/lib/generator/QueryObjectGenerator.js.map +1 -1
- package/lib/generator/ServiceGenerator.d.ts +4 -4
- package/lib/generator/ServiceGenerator.js +52 -56
- package/lib/generator/ServiceGenerator.js.map +1 -1
- package/lib/generator/import/ImportObjects.js +11 -14
- package/lib/generator/import/ImportObjects.js.map +1 -1
- package/lib/generator/index.d.ts +3 -3
- package/lib/generator/index.js +3 -9
- package/lib/generator/index.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.js +4 -7
- package/lib/index.js.map +1 -1
- package/lib/project/FileHandler.d.ts +3 -3
- package/lib/project/FileHandler.js +12 -16
- package/lib/project/FileHandler.js.map +1 -1
- package/lib/project/ProjectManager.d.ts +5 -5
- package/lib/project/ProjectManager.js +25 -32
- package/lib/project/ProjectManager.js.map +1 -1
- package/lib/project/TsMorphHelper.d.ts +1 -1
- package/lib/project/TsMorphHelper.js +21 -22
- package/lib/project/TsMorphHelper.js.map +1 -1
- package/lib/project/formatter/BaseFormatter.d.ts +1 -1
- package/lib/project/formatter/BaseFormatter.js +1 -5
- package/lib/project/formatter/BaseFormatter.js.map +1 -1
- package/lib/project/formatter/FileFormatter.js +1 -2
- package/lib/project/formatter/NoopFormatter.d.ts +1 -1
- package/lib/project/formatter/NoopFormatter.js +5 -9
- package/lib/project/formatter/NoopFormatter.js.map +1 -1
- package/lib/project/formatter/PrettierFormatter.d.ts +1 -1
- package/lib/project/formatter/PrettierFormatter.js +20 -25
- package/lib/project/formatter/PrettierFormatter.js.map +1 -1
- package/lib/project/formatter/index.d.ts +1 -1
- package/lib/project/formatter/index.js +6 -10
- package/lib/project/formatter/index.js.map +1 -1
- package/lib/project/logger/logFilePath.js +4 -9
- package/lib/project/logger/logFilePath.js.map +1 -1
- package/lib/run-cli.js +2 -4
- package/lib/run-cli.js.map +1 -1
- package/package.json +53 -63
- package/lib/cli.d.ts +0 -3
- package/lib/cli.js +0 -176
- package/lib/cli.js.map +0 -1
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImportedNameValidator = void 0;
|
|
4
|
-
class ImportedNameValidator {
|
|
1
|
+
export class ImportedNameValidator {
|
|
5
2
|
constructor(reservedNames) {
|
|
6
3
|
this.importedNames = new Map();
|
|
7
4
|
reservedNames === null || reservedNames === void 0 ? void 0 : reservedNames.forEach((rn) => {
|
|
@@ -22,5 +19,4 @@ class ImportedNameValidator {
|
|
|
22
19
|
return result;
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
exports.ImportedNameValidator = ImportedNameValidator;
|
|
26
22
|
//# sourceMappingURL=ImportedNameValidator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportedNameValidator.js","sourceRoot":"","sources":["../../src/generator/ImportedNameValidator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ImportedNameValidator.js","sourceRoot":"","sources":["../../src/generator/ImportedNameValidator.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,qBAAqB;IAGhC,YAAmB,aAAyC;QAFpD,kBAAa,GAAG,IAAI,GAAG,EAAkC,CAAC;QAGhE,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;YAC5B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,YAAY,CAAC,SAAiB,EAAE,IAAY;;QACjD,MAAM,UAAU,GAAG,MAAA,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,mCAAI,EAAE,CAAC;QACtD,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;QAEtC,IAAI,OAAO,EAAE;YACX,OAAO,OAAO,CAAC;SAChB;QAED,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC;QACtD,MAAM,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,cAAc,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAEnE,UAAU,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;QAC/B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAEzC,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["export class ImportedNameValidator {\r\n private importedNames = new Map<string, Record<string, string>>();\r\n\r\n public constructor(reservedNames?: Array<string> | undefined) {\r\n reservedNames?.forEach((rn) => {\r\n this.importedNames.set(rn, { [\"_\"]: rn });\r\n });\r\n }\r\n\r\n public validateName(qualifier: string, name: string): string {\r\n const qualifiers = this.importedNames.get(name) ?? {};\r\n const hitName = qualifiers[qualifier];\r\n\r\n if (hitName) {\r\n return hitName;\r\n }\r\n\r\n const qualifiersSize = Object.keys(qualifiers).length;\r\n const result = qualifiersSize ? `${name}_${qualifiersSize}` : name;\r\n\r\n qualifiers[qualifier] = result;\r\n this.importedNames.set(name, qualifiers);\r\n\r\n return result;\r\n }\r\n}\r\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EntityBasedGeneratorFunction } from "../FactoryFunctionModel";
|
|
1
|
+
import { EntityBasedGeneratorFunction } from "../FactoryFunctionModel.js";
|
|
2
2
|
export declare const generateModels: EntityBasedGeneratorFunction;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const ts_morph_1 = require("ts-morph");
|
|
6
|
-
const ImportObjects_1 = require("./import/ImportObjects");
|
|
7
|
-
const generateModels = (project, dataModel, version, options, namingHelper) => {
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { StructureKind } from "ts-morph";
|
|
3
|
+
import { CoreImports } from "./import/ImportObjects.js";
|
|
4
|
+
export const generateModels = (project, dataModel, version, options, namingHelper) => {
|
|
8
5
|
const generator = new ModelGenerator(project, dataModel, version, options, namingHelper);
|
|
9
6
|
return generator.generate();
|
|
10
7
|
};
|
|
11
|
-
exports.generateModels = generateModels;
|
|
12
8
|
class ModelGenerator {
|
|
13
9
|
constructor(project, dataModel, version, options, namingHelper) {
|
|
14
10
|
this.project = project;
|
|
@@ -18,7 +14,7 @@ class ModelGenerator {
|
|
|
18
14
|
this.namingHelper = namingHelper;
|
|
19
15
|
}
|
|
20
16
|
generate() {
|
|
21
|
-
return
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
18
|
this.project.initModels();
|
|
23
19
|
const promises = [
|
|
24
20
|
...this.generateEnums(),
|
|
@@ -134,13 +130,13 @@ class ModelGenerator {
|
|
|
134
130
|
"OData Attributes:\n" +
|
|
135
131
|
"|Attribute Name | Attribute Value |\n| --- | ---|\n" +
|
|
136
132
|
attributeTable.map((row) => `| ${row[0]} | \`${row[1]}\` |`).join("\n");
|
|
137
|
-
return { kind:
|
|
133
|
+
return { kind: StructureKind.JSDoc, description };
|
|
138
134
|
}
|
|
139
135
|
getPropType(imports, prop) {
|
|
140
136
|
// V2 entity special: deferred content
|
|
141
137
|
let suffix = "";
|
|
142
138
|
if (this.dataModel.isV2() && prop.dataType == "ModelType" /* DataTypes.ModelType */) {
|
|
143
|
-
const defContent = imports.addCoreLib(this.version,
|
|
139
|
+
const defContent = imports.addCoreLib(this.version, CoreImports.DeferredContent);
|
|
144
140
|
suffix = ` | ${defContent}`;
|
|
145
141
|
}
|
|
146
142
|
let typeName;
|
|
@@ -224,7 +220,7 @@ class ModelGenerator {
|
|
|
224
220
|
return editableType + (prop.required ? "" : " | null");
|
|
225
221
|
}
|
|
226
222
|
generateUnboundOperationParams() {
|
|
227
|
-
return
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
228
224
|
const unboundOps = this.dataModel.getUnboundOperationTypes();
|
|
229
225
|
const reservedNames = unboundOps.map((op) => op.paramsModelName);
|
|
230
226
|
const file = this.project.createOrGetMainModelFile(reservedNames);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelGenerator.js","sourceRoot":"","sources":["../../src/generator/ModelGenerator.ts"],"names":[],"mappings":";;;;AACA,uCAAuE;AAQvE,0DAAqD;AAG9C,MAAM,cAAc,GAAiC,CAC1D,OAAuB,EACvB,SAAS,EACT,OAAO,EACP,OAAO,EACP,YAAY,EACZ,EAAE;IACF,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IACzF,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AATW,QAAA,cAAc,kBASzB;AAEF,MAAM,cAAc;IAClB,YACU,OAAuB,EACvB,SAAoB,EACpB,OAAsB,EACtB,OAAiC,EACjC,YAA0B;QAJ1B,YAAO,GAAP,OAAO,CAAgB;QACvB,cAAS,GAAT,SAAS,CAAW;QACpB,YAAO,GAAP,OAAO,CAAe;QACtB,YAAO,GAAP,OAAO,CAA0B;QACjC,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAES,QAAQ;;YACnB,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;YAE1B,M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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\";\r\nimport { ComplexType, DataTypes, EntityType, OperationType, PropertyModel } from \"../data-model/DataTypeModel\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\r\nimport { FileHandler } from \"../project/FileHandler\";\r\nimport { ProjectManager } from \"../project/ProjectManager\";\r\nimport { CoreImports } from \"./import/ImportObjects\";\r\nimport { ImportContainer } from \"./ImportContainer\";\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;AAQvE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,MAAM,CAAC,MAAM,cAAc,GAAiC,CAC1D,OAAuB,EACvB,SAAS,EACT,OAAO,EACP,OAAO,EACP,YAAY,EACZ,EAAE;IACF,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IACzF,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AAEF,MAAM,cAAc;IAClB,YACU,OAAuB,EACvB,SAAoB,EACpB,OAAsB,EACtB,OAAiC,EACjC,YAA0B;QAJ1B,YAAO,GAAP,OAAO,CAAgB;QACvB,cAAS,GAAT,SAAS,CAAW;QACpB,YAAO,GAAP,OAAO,CAAe;QACtB,YAAO,GAAP,OAAO,CAA0B;QACjC,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAES,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I,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,2 +1,2 @@
|
|
|
1
|
-
import { EntityBasedGeneratorFunction } from "../FactoryFunctionModel";
|
|
1
|
+
import { EntityBasedGeneratorFunction } from "../FactoryFunctionModel.js";
|
|
2
2
|
export declare const generateQueryObjects: EntityBasedGeneratorFunction;
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const processors_1 = require("xml2js/lib/processors");
|
|
8
|
-
const ImportObjects_1 = require("./import/ImportObjects");
|
|
9
|
-
const generateQueryObjects = (project, dataModel, version, options, namingHelper) => {
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { ODataVersions } from "@odata2ts/odata-core";
|
|
3
|
+
import { Scope, VariableDeclarationKind } from "ts-morph";
|
|
4
|
+
import { firstCharLowerCase } from "xml2js/lib/processors.js";
|
|
5
|
+
import { QueryObjectImports } from "./import/ImportObjects.js";
|
|
6
|
+
export const generateQueryObjects = (project, dataModel, version, options, namingHelper) => {
|
|
10
7
|
const generator = new QueryObjectGenerator(project, dataModel, version, options, namingHelper);
|
|
11
8
|
return generator.generate();
|
|
12
9
|
};
|
|
13
|
-
exports.generateQueryObjects = generateQueryObjects;
|
|
14
10
|
class QueryObjectGenerator {
|
|
15
11
|
constructor(project, dataModel, version, options, namingHelper) {
|
|
16
12
|
this.project = project;
|
|
@@ -20,7 +16,7 @@ class QueryObjectGenerator {
|
|
|
20
16
|
this.namingHelper = namingHelper;
|
|
21
17
|
}
|
|
22
18
|
generate() {
|
|
23
|
-
return
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
20
|
this.project.initQObjects();
|
|
25
21
|
// process EntityType & ComplexType
|
|
26
22
|
const promises = [...this.generateEntityTypes(), ...this.generateComplexTypes()];
|
|
@@ -36,7 +32,7 @@ class QueryObjectGenerator {
|
|
|
36
32
|
return this.dataModel.getEntityTypes().map((model) => {
|
|
37
33
|
const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [
|
|
38
34
|
model.qName,
|
|
39
|
-
|
|
35
|
+
firstCharLowerCase(model.qName),
|
|
40
36
|
model.id.qName,
|
|
41
37
|
]);
|
|
42
38
|
// q object
|
|
@@ -61,7 +57,7 @@ class QueryObjectGenerator {
|
|
|
61
57
|
return this.dataModel.getComplexTypes().map((model) => {
|
|
62
58
|
const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [
|
|
63
59
|
model.qName,
|
|
64
|
-
|
|
60
|
+
firstCharLowerCase(model.qName),
|
|
65
61
|
]);
|
|
66
62
|
this.generateModel(file, model);
|
|
67
63
|
return this.project.finalizeFile(file);
|
|
@@ -79,7 +75,7 @@ class QueryObjectGenerator {
|
|
|
79
75
|
extendsClause = imports.addGeneratedQObject(baseClass, baseModel.qName);
|
|
80
76
|
}
|
|
81
77
|
else {
|
|
82
|
-
extendsClause = imports.addQObject(
|
|
78
|
+
extendsClause = imports.addQObject(QueryObjectImports.QueryObject);
|
|
83
79
|
}
|
|
84
80
|
file.getFile().addClass({
|
|
85
81
|
name: model.qName,
|
|
@@ -89,11 +85,11 @@ class QueryObjectGenerator {
|
|
|
89
85
|
properties: this.generateQueryObjectProps(file.getImports(), model.props),
|
|
90
86
|
});
|
|
91
87
|
file.getFile().addVariableStatement({
|
|
92
|
-
declarationKind:
|
|
88
|
+
declarationKind: VariableDeclarationKind.Const,
|
|
93
89
|
isExported: true,
|
|
94
90
|
declarations: [
|
|
95
91
|
{
|
|
96
|
-
name:
|
|
92
|
+
name: firstCharLowerCase(model.qName),
|
|
97
93
|
initializer: `new ${model.qName}()`,
|
|
98
94
|
},
|
|
99
95
|
],
|
|
@@ -107,7 +103,7 @@ class QueryObjectGenerator {
|
|
|
107
103
|
let qPathInit;
|
|
108
104
|
// factor in collections
|
|
109
105
|
if (prop.isCollection) {
|
|
110
|
-
const qPath = importContainer.addQObject(isModelType ?
|
|
106
|
+
const qPath = importContainer.addQObject(isModelType ? QueryObjectImports.QEntityCollectionPath : QueryObjectImports.QCollectionPath);
|
|
111
107
|
const qObject = isModelType
|
|
112
108
|
? importContainer.addGeneratedQObject(prop.fqType, prop.qObject)
|
|
113
109
|
: importContainer.addQObject(prop.qObject);
|
|
@@ -127,7 +123,7 @@ class QueryObjectGenerator {
|
|
|
127
123
|
}
|
|
128
124
|
return {
|
|
129
125
|
name,
|
|
130
|
-
scope:
|
|
126
|
+
scope: Scope.Public,
|
|
131
127
|
isReadonly: true,
|
|
132
128
|
initializer: qPathInit,
|
|
133
129
|
};
|
|
@@ -151,7 +147,7 @@ class QueryObjectGenerator {
|
|
|
151
147
|
}
|
|
152
148
|
generateIdFunction(file, model) {
|
|
153
149
|
const importContainer = file.getImports();
|
|
154
|
-
const qFunc = importContainer.addQObject(
|
|
150
|
+
const qFunc = importContainer.addQObject(QueryObjectImports.QId);
|
|
155
151
|
const idModelName = importContainer.addGeneratedModel(model.fqName, model.id.modelName);
|
|
156
152
|
file.getFile().addClass({
|
|
157
153
|
name: model.id.qName,
|
|
@@ -160,7 +156,7 @@ class QueryObjectGenerator {
|
|
|
160
156
|
properties: [
|
|
161
157
|
{
|
|
162
158
|
name: "params",
|
|
163
|
-
scope:
|
|
159
|
+
scope: Scope.Private,
|
|
164
160
|
isReadonly: true,
|
|
165
161
|
initializer: this.getParamInitString(importContainer, model.keys),
|
|
166
162
|
},
|
|
@@ -201,7 +197,7 @@ class QueryObjectGenerator {
|
|
|
201
197
|
return allParams.length === 1 ? allParams[0] : `[${allParams.join(",")}]`;
|
|
202
198
|
}
|
|
203
199
|
generateUnboundOperations() {
|
|
204
|
-
return
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
201
|
const unboundOps = this.dataModel.getUnboundOperationTypes();
|
|
206
202
|
const reservedNames = unboundOps.map((op) => op.qName);
|
|
207
203
|
const file = this.project.createOrGetMainQObjectFile(reservedNames);
|
|
@@ -213,12 +209,12 @@ class QueryObjectGenerator {
|
|
|
213
209
|
generateOperation(file, operation, baseFqName) {
|
|
214
210
|
var _a, _b;
|
|
215
211
|
const imports = file.getImports();
|
|
216
|
-
const isV2 = this.version ===
|
|
212
|
+
const isV2 = this.version === ODataVersions.V2;
|
|
217
213
|
const returnType = operation.returnType;
|
|
218
214
|
const hasParams = operation.parameters.length > 0 || ((_a = operation.overrides) === null || _a === void 0 ? void 0 : _a.length);
|
|
219
215
|
const isParamsOptional = !![operation.parameters, ...((_b = operation.overrides) !== null && _b !== void 0 ? _b : [])].find((pSet) => pSet.length === 0);
|
|
220
216
|
// imports
|
|
221
|
-
const qOp = operation.type === "Action" /* OperationTypes.Action */ ?
|
|
217
|
+
const qOp = operation.type === "Action" /* OperationTypes.Action */ ? QueryObjectImports.QAction : QueryObjectImports.QFunction;
|
|
222
218
|
const qOperation = imports.addQObject(qOp);
|
|
223
219
|
const paramModelName = hasParams ? imports.addGeneratedModel(baseFqName, operation.paramsModelName) : undefined;
|
|
224
220
|
let returnTypeOpStmt = "";
|
|
@@ -226,17 +222,17 @@ class QueryObjectGenerator {
|
|
|
226
222
|
const collectionSuffix = returnType.isCollection ? "_COLLECTION" : "";
|
|
227
223
|
if (returnType.dataType === "ComplexType" /* DataTypes.ComplexType */ || returnType.dataType === "ModelType" /* DataTypes.ModelType */) {
|
|
228
224
|
if (returnType.qObject) {
|
|
229
|
-
const opRt = imports.addQObject(
|
|
230
|
-
const rts = imports.addQObject(
|
|
231
|
-
const qComplexParam = imports.addQObject(
|
|
225
|
+
const opRt = imports.addQObject(QueryObjectImports.OperationReturnType);
|
|
226
|
+
const rts = imports.addQObject(QueryObjectImports.ReturnTypes);
|
|
227
|
+
const qComplexParam = imports.addQObject(QueryObjectImports.QComplexParam);
|
|
232
228
|
const returnQName = imports.addGeneratedQObject(returnType.fqType, returnType.qObject);
|
|
233
229
|
returnTypeOpStmt = `new ${opRt}(${rts}.COMPLEX${collectionSuffix}, new ${qComplexParam}("NONE", new ${returnQName}))`;
|
|
234
230
|
}
|
|
235
231
|
}
|
|
236
232
|
// currently, it only makes sense to add the OperationReturnType if a converter is present
|
|
237
233
|
else if (returnType.converters && returnType.qParam) {
|
|
238
|
-
const rtClass = imports.addQObject(
|
|
239
|
-
const rtTypes = imports.addQObject(
|
|
234
|
+
const rtClass = imports.addQObject(QueryObjectImports.OperationReturnType);
|
|
235
|
+
const rtTypes = imports.addQObject(QueryObjectImports.ReturnTypes);
|
|
240
236
|
const qParam = imports.addQObject(returnType.qParam);
|
|
241
237
|
// TODO: some constants with string concat
|
|
242
238
|
const rtKind = `${rtTypes}.VALUE${collectionSuffix}`;
|
|
@@ -253,7 +249,7 @@ class QueryObjectGenerator {
|
|
|
253
249
|
properties: [
|
|
254
250
|
{
|
|
255
251
|
name: "params",
|
|
256
|
-
scope:
|
|
252
|
+
scope: Scope.Private,
|
|
257
253
|
isReadonly: true,
|
|
258
254
|
type: hasParams ? undefined : "[]",
|
|
259
255
|
initializer: this.getParamInitString(imports, operation.parameters, operation.overrides),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Query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AAI,CAAC,SAAS;oBAC1D,CAAC,CAAC;wBACE;4BACE,IAAI,EAAE,UAAU;4BAChB,UAAU,EAAE,CAAC,kCAAkC,CAAC;yBACjD;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\r\nimport { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { OptionalKind, PropertyDeclarationStructure, Scope, VariableDeclarationKind } from \"ts-morph\";\r\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport {\r\n ComplexType,\r\n DataTypes,\r\n EntityType,\r\n OperationType,\r\n OperationTypes,\r\n PropertyModel,\r\n} from \"../data-model/DataTypeModel\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\r\nimport { Modes } from \"../OptionModel\";\r\nimport { FileHandler } from \"../project/FileHandler\";\r\nimport { ProjectManager } from \"../project/ProjectManager\";\r\nimport { QueryObjectImports } from \"./import/ImportObjects\";\r\nimport { ImportContainer } from \"./ImportContainer\";\r\n\r\nexport const generateQueryObjects: EntityBasedGeneratorFunction = (\r\n project,\r\n dataModel,\r\n version,\r\n options,\r\n namingHelper\r\n) => {\r\n const generator = new QueryObjectGenerator(project, dataModel, version, options, namingHelper);\r\n return generator.generate();\r\n};\r\n\r\nclass QueryObjectGenerator {\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.initQObjects();\r\n\r\n // process EntityType & ComplexType\r\n const promises: Array<Promise<void>> = [...this.generateEntityTypes(), ...this.generateComplexTypes()];\r\n if (!this.options.skipOperations) {\r\n // process unbound operations\r\n promises.push(this.generateUnboundOperations());\r\n }\r\n\r\n await Promise.all(promises);\r\n\r\n return this.project.finalizeQObjects();\r\n }\r\n\r\n private generateEntityTypes() {\r\n return this.dataModel.getEntityTypes().map((model) => {\r\n const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [\r\n model.qName,\r\n firstCharLowerCase(model.qName),\r\n model.id.qName,\r\n ]);\r\n\r\n // q object\r\n this.generateModel(file, model);\r\n\r\n // qId function\r\n if (!this.options.skipIdModels && model.generateId) {\r\n this.generateIdFunction(file, model);\r\n }\r\n\r\n // bound q 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.generateOperation(file, operation, model.fqName);\r\n });\r\n }\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateComplexTypes() {\r\n return this.dataModel.getComplexTypes().map((model) => {\r\n const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [\r\n model.qName,\r\n firstCharLowerCase(model.qName),\r\n ]);\r\n\r\n this.generateModel(file, model);\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateModel(file: FileHandler, model: ComplexType) {\r\n const imports = file.getImports();\r\n\r\n let extendsClause: string;\r\n if (model.baseClasses.length) {\r\n const baseClass = model.baseClasses[0];\r\n const baseModel = this.dataModel.getModel(baseClass) as ComplexType;\r\n if (!baseModel) {\r\n throw new Error(`Entity or complex type \"${baseClass}\" from baseClass attribute not found!`);\r\n }\r\n extendsClause = imports.addGeneratedQObject(baseClass, baseModel.qName);\r\n } else {\r\n extendsClause = imports.addQObject(QueryObjectImports.QueryObject);\r\n }\r\n\r\n file.getFile().addClass({\r\n name: model.qName,\r\n isExported: true,\r\n extends: extendsClause,\r\n // isAbstract: model.abstract,\r\n properties: this.generateQueryObjectProps(file.getImports(), model.props),\r\n });\r\n\r\n file.getFile().addVariableStatement({\r\n declarationKind: VariableDeclarationKind.Const,\r\n isExported: true,\r\n declarations: [\r\n {\r\n name: firstCharLowerCase(model.qName),\r\n initializer: `new ${model.qName}()`,\r\n },\r\n ],\r\n });\r\n }\r\n\r\n private generateQueryObjectProps(\r\n importContainer: ImportContainer,\r\n props: Array<PropertyModel>\r\n ): Array<OptionalKind<PropertyDeclarationStructure>> {\r\n return props.map((prop) => {\r\n const { odataName } = prop;\r\n const name = this.namingHelper.getQPropName(prop.name);\r\n const isModelType = prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType;\r\n let qPathInit: string;\r\n\r\n // factor in collections\r\n if (prop.isCollection) {\r\n const qPath = importContainer.addQObject(\r\n isModelType ? QueryObjectImports.QEntityCollectionPath : QueryObjectImports.QCollectionPath\r\n );\r\n const qObject = isModelType\r\n ? importContainer.addGeneratedQObject(prop.fqType, prop.qObject!)\r\n : importContainer.addQObject(prop.qObject!);\r\n\r\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\"), () => ${qObject})`;\r\n } else {\r\n // add import for data type\r\n const qPath = importContainer.addQObject(prop.qPath);\r\n if (isModelType) {\r\n const qObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject!);\r\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\"), () => ${qObject})`;\r\n } else {\r\n let converterStmt = this.generateConverterStmt(importContainer, prop.converters);\r\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\")${converterStmt ? `, ${converterStmt}` : \"\"})`;\r\n }\r\n }\r\n\r\n return {\r\n name,\r\n scope: Scope.Public,\r\n isReadonly: true,\r\n initializer: qPathInit,\r\n } as OptionalKind<PropertyDeclarationStructure>;\r\n });\r\n }\r\n\r\n private generateConverterStmt(importContainer: ImportContainer, converters: Array<ValueConverterImport> | undefined) {\r\n if (!converters?.length) {\r\n return undefined;\r\n }\r\n const converterIds = converters.map((converter) => {\r\n return importContainer.addCustomType(converter.package, converter.converterId);\r\n });\r\n\r\n if (converterIds.length === 1) {\r\n return converterIds[0];\r\n } else {\r\n const createChain = importContainer.addCustomType(\"@odata2ts/converter-runtime\", \"createChain\");\r\n\r\n const [first, second, ...moreConverters] = converterIds;\r\n return moreConverters.reduce((stmt, convId) => `${stmt}.chain(${convId})`, `${createChain}(${first}, ${second})`);\r\n }\r\n }\r\n\r\n private generateIdFunction(file: FileHandler, model: EntityType) {\r\n const importContainer = file.getImports();\r\n const qFunc = importContainer.addQObject(QueryObjectImports.QId);\r\n const idModelName = importContainer.addGeneratedModel(model.fqName, model.id.modelName);\r\n\r\n file.getFile().addClass({\r\n name: model.id.qName,\r\n isExported: true,\r\n extends: `${qFunc}<${idModelName}>`,\r\n properties: [\r\n {\r\n name: \"params\",\r\n scope: Scope.Private,\r\n isReadonly: true,\r\n initializer: this.getParamInitString(importContainer, model.keys),\r\n },\r\n ],\r\n methods: [\r\n {\r\n name: \"getParams\",\r\n statements: [\"return this.params\"],\r\n },\r\n ],\r\n });\r\n }\r\n\r\n private getParamInitString(\r\n importContainer: ImportContainer,\r\n props: Array<PropertyModel>,\r\n overloads?: Array<Array<PropertyModel>>\r\n ) {\r\n const allParams = [props, ...(overloads ?? [])].map((paramSet) => {\r\n const pString = paramSet\r\n .map((prop) => {\r\n let complexQParam = \"\";\r\n if (prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType) {\r\n const importedQObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject!);\r\n complexQParam = `, new ${importedQObject}()`;\r\n }\r\n\r\n const qParam = importContainer.addQObject(prop.qParam!);\r\n const isMappedNameNecessary = prop.odataName !== prop.name;\r\n const mappedName = isMappedNameNecessary\r\n ? `\"${prop.name}\"`\r\n : prop.converters?.length\r\n ? \"undefined\"\r\n : undefined;\r\n const converterStmt = this.generateConverterStmt(importContainer, prop.converters);\r\n const mappedNameParam = mappedName ? `, ${mappedName}` : \"\";\r\n const converterParam = converterStmt ? `, ${converterStmt}` : \"\";\r\n return `new ${qParam}(\"${prop.odataName}\"${complexQParam}${mappedNameParam}${converterParam})`;\r\n })\r\n .join(\",\");\r\n return `[${pString}]`;\r\n });\r\n\r\n return allParams.length === 1 ? allParams[0] : `[${allParams.join(\",\")}]`;\r\n }\r\n\r\n private async generateUnboundOperations() {\r\n const unboundOps = this.dataModel.getUnboundOperationTypes();\r\n const reservedNames = unboundOps.map((op) => op.qName);\r\n const file = this.project.createOrGetMainQObjectFile(reservedNames);\r\n\r\n unboundOps.forEach((operation) => {\r\n this.generateOperation(file, operation, \"\");\r\n });\r\n }\r\n\r\n private generateOperation(file: FileHandler, operation: OperationType, baseFqName: string) {\r\n const imports = file.getImports();\r\n const isV2 = this.version === ODataVersions.V2;\r\n const returnType = operation.returnType;\r\n const hasParams = operation.parameters.length > 0 || operation.overrides?.length;\r\n const isParamsOptional = !![operation.parameters, ...(operation.overrides ?? [])].find((pSet) => pSet.length === 0);\r\n\r\n // imports\r\n const qOp = operation.type === OperationTypes.Action ? QueryObjectImports.QAction : QueryObjectImports.QFunction;\r\n const qOperation = imports.addQObject(qOp);\r\n const paramModelName = hasParams ? imports.addGeneratedModel(baseFqName, operation.paramsModelName) : undefined;\r\n\r\n let returnTypeOpStmt: string = \"\";\r\n if (returnType) {\r\n const collectionSuffix = returnType.isCollection ? \"_COLLECTION\" : \"\";\r\n if (returnType.dataType === DataTypes.ComplexType || returnType.dataType === DataTypes.ModelType) {\r\n if (returnType.qObject) {\r\n const opRt = imports.addQObject(QueryObjectImports.OperationReturnType);\r\n const rts = imports.addQObject(QueryObjectImports.ReturnTypes);\r\n const qComplexParam = imports.addQObject(QueryObjectImports.QComplexParam);\r\n const returnQName = imports.addGeneratedQObject(returnType.fqType, returnType.qObject);\r\n\r\n returnTypeOpStmt = `new ${opRt}(${rts}.COMPLEX${collectionSuffix}, new ${qComplexParam}(\"NONE\", new ${returnQName}))`;\r\n }\r\n }\r\n // currently, it only makes sense to add the OperationReturnType if a converter is present\r\n else if (returnType.converters && returnType.qParam) {\r\n const rtClass = imports.addQObject(QueryObjectImports.OperationReturnType);\r\n const rtTypes = imports.addQObject(QueryObjectImports.ReturnTypes);\r\n const qParam = imports.addQObject(returnType.qParam);\r\n\r\n // TODO: some constants with string concat\r\n const rtKind = `${rtTypes}.VALUE${collectionSuffix}`;\r\n\r\n const converterParam = returnType.converters\r\n ? \", \" + this.generateConverterStmt(imports, returnType.converters)\r\n : \"\";\r\n returnTypeOpStmt = `new ${rtClass}(${rtKind}, new ${qParam}(\"NONE\", undefined${converterParam}))`;\r\n }\r\n }\r\n\r\n file.getFile().addClass({\r\n name: operation.qName,\r\n isExported: true,\r\n extends: qOperation + (hasParams ? `<${paramModelName}>` : \"\"),\r\n properties: [\r\n {\r\n name: \"params\",\r\n scope: Scope.Private,\r\n isReadonly: true,\r\n type: hasParams ? undefined : \"[]\",\r\n initializer: this.getParamInitString(imports, operation.parameters, operation.overrides),\r\n },\r\n ],\r\n ctors: [\r\n {\r\n statements: [\r\n `super(\"${operation.odataName}\"${returnTypeOpStmt ? \", \" + returnTypeOpStmt : isV2 ? \", undefined\" : \"\"}${\r\n isV2 ? \", { v2Mode: true }\" : \"\"\r\n })`,\r\n ],\r\n },\r\n ],\r\n methods: [\r\n {\r\n name: \"getParams\",\r\n statements: [\"return this.params\"],\r\n },\r\n // functions without params: add an overriding buildUrl() to not force users to have to pass undefined as param\r\n ...(operation.type === OperationTypes.Function && !hasParams\r\n ? [\r\n {\r\n name: \"buildUrl\",\r\n statements: [\"return super.buildUrl(undefined)\"],\r\n },\r\n ]\r\n : []),\r\n ],\r\n });\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"QueryObjectGenerator.js","sourceRoot":"","sources":["../../src/generator/QueryObjectGenerator.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAA8C,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACtG,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAe9D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oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\r\nimport { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { OptionalKind, PropertyDeclarationStructure, Scope, VariableDeclarationKind } from \"ts-morph\";\r\nimport { firstCharLowerCase } from \"xml2js/lib/processors.js\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel.js\";\r\nimport {\r\n ComplexType,\r\n DataTypes,\r\n EntityType,\r\n OperationType,\r\n OperationTypes,\r\n PropertyModel,\r\n} 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 { QueryObjectImports } from \"./import/ImportObjects.js\";\r\nimport { ImportContainer } from \"./ImportContainer.js\";\r\n\r\nexport const generateQueryObjects: EntityBasedGeneratorFunction = (\r\n project,\r\n dataModel,\r\n version,\r\n options,\r\n namingHelper\r\n) => {\r\n const generator = new QueryObjectGenerator(project, dataModel, version, options, namingHelper);\r\n return generator.generate();\r\n};\r\n\r\nclass QueryObjectGenerator {\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.initQObjects();\r\n\r\n // process EntityType & ComplexType\r\n const promises: Array<Promise<void>> = [...this.generateEntityTypes(), ...this.generateComplexTypes()];\r\n if (!this.options.skipOperations) {\r\n // process unbound operations\r\n promises.push(this.generateUnboundOperations());\r\n }\r\n\r\n await Promise.all(promises);\r\n\r\n return this.project.finalizeQObjects();\r\n }\r\n\r\n private generateEntityTypes() {\r\n return this.dataModel.getEntityTypes().map((model) => {\r\n const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [\r\n model.qName,\r\n firstCharLowerCase(model.qName),\r\n model.id.qName,\r\n ]);\r\n\r\n // q object\r\n this.generateModel(file, model);\r\n\r\n // qId function\r\n if (!this.options.skipIdModels && model.generateId) {\r\n this.generateIdFunction(file, model);\r\n }\r\n\r\n // bound q 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.generateOperation(file, operation, model.fqName);\r\n });\r\n }\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateComplexTypes() {\r\n return this.dataModel.getComplexTypes().map((model) => {\r\n const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [\r\n model.qName,\r\n firstCharLowerCase(model.qName),\r\n ]);\r\n\r\n this.generateModel(file, model);\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateModel(file: FileHandler, model: ComplexType) {\r\n const imports = file.getImports();\r\n\r\n let extendsClause: string;\r\n if (model.baseClasses.length) {\r\n const baseClass = model.baseClasses[0];\r\n const baseModel = this.dataModel.getModel(baseClass) as ComplexType;\r\n if (!baseModel) {\r\n throw new Error(`Entity or complex type \"${baseClass}\" from baseClass attribute not found!`);\r\n }\r\n extendsClause = imports.addGeneratedQObject(baseClass, baseModel.qName);\r\n } else {\r\n extendsClause = imports.addQObject(QueryObjectImports.QueryObject);\r\n }\r\n\r\n file.getFile().addClass({\r\n name: model.qName,\r\n isExported: true,\r\n extends: extendsClause,\r\n // isAbstract: model.abstract,\r\n properties: this.generateQueryObjectProps(file.getImports(), model.props),\r\n });\r\n\r\n file.getFile().addVariableStatement({\r\n declarationKind: VariableDeclarationKind.Const,\r\n isExported: true,\r\n declarations: [\r\n {\r\n name: firstCharLowerCase(model.qName),\r\n initializer: `new ${model.qName}()`,\r\n },\r\n ],\r\n });\r\n }\r\n\r\n private generateQueryObjectProps(\r\n importContainer: ImportContainer,\r\n props: Array<PropertyModel>\r\n ): Array<OptionalKind<PropertyDeclarationStructure>> {\r\n return props.map((prop) => {\r\n const { odataName } = prop;\r\n const name = this.namingHelper.getQPropName(prop.name);\r\n const isModelType = prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType;\r\n let qPathInit: string;\r\n\r\n // factor in collections\r\n if (prop.isCollection) {\r\n const qPath = importContainer.addQObject(\r\n isModelType ? QueryObjectImports.QEntityCollectionPath : QueryObjectImports.QCollectionPath\r\n );\r\n const qObject = isModelType\r\n ? importContainer.addGeneratedQObject(prop.fqType, prop.qObject!)\r\n : importContainer.addQObject(prop.qObject!);\r\n\r\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\"), () => ${qObject})`;\r\n } else {\r\n // add import for data type\r\n const qPath = importContainer.addQObject(prop.qPath);\r\n if (isModelType) {\r\n const qObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject!);\r\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\"), () => ${qObject})`;\r\n } else {\r\n let converterStmt = this.generateConverterStmt(importContainer, prop.converters);\r\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\")${converterStmt ? `, ${converterStmt}` : \"\"})`;\r\n }\r\n }\r\n\r\n return {\r\n name,\r\n scope: Scope.Public,\r\n isReadonly: true,\r\n initializer: qPathInit,\r\n } as OptionalKind<PropertyDeclarationStructure>;\r\n });\r\n }\r\n\r\n private generateConverterStmt(importContainer: ImportContainer, converters: Array<ValueConverterImport> | undefined) {\r\n if (!converters?.length) {\r\n return undefined;\r\n }\r\n const converterIds = converters.map((converter) => {\r\n return importContainer.addCustomType(converter.package, converter.converterId);\r\n });\r\n\r\n if (converterIds.length === 1) {\r\n return converterIds[0];\r\n } else {\r\n const createChain = importContainer.addCustomType(\"@odata2ts/converter-runtime\", \"createChain\");\r\n\r\n const [first, second, ...moreConverters] = converterIds;\r\n return moreConverters.reduce((stmt, convId) => `${stmt}.chain(${convId})`, `${createChain}(${first}, ${second})`);\r\n }\r\n }\r\n\r\n private generateIdFunction(file: FileHandler, model: EntityType) {\r\n const importContainer = file.getImports();\r\n const qFunc = importContainer.addQObject(QueryObjectImports.QId);\r\n const idModelName = importContainer.addGeneratedModel(model.fqName, model.id.modelName);\r\n\r\n file.getFile().addClass({\r\n name: model.id.qName,\r\n isExported: true,\r\n extends: `${qFunc}<${idModelName}>`,\r\n properties: [\r\n {\r\n name: \"params\",\r\n scope: Scope.Private,\r\n isReadonly: true,\r\n initializer: this.getParamInitString(importContainer, model.keys),\r\n },\r\n ],\r\n methods: [\r\n {\r\n name: \"getParams\",\r\n statements: [\"return this.params\"],\r\n },\r\n ],\r\n });\r\n }\r\n\r\n private getParamInitString(\r\n importContainer: ImportContainer,\r\n props: Array<PropertyModel>,\r\n overloads?: Array<Array<PropertyModel>>\r\n ) {\r\n const allParams = [props, ...(overloads ?? [])].map((paramSet) => {\r\n const pString = paramSet\r\n .map((prop) => {\r\n let complexQParam = \"\";\r\n if (prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType) {\r\n const importedQObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject!);\r\n complexQParam = `, new ${importedQObject}()`;\r\n }\r\n\r\n const qParam = importContainer.addQObject(prop.qParam!);\r\n const isMappedNameNecessary = prop.odataName !== prop.name;\r\n const mappedName = isMappedNameNecessary\r\n ? `\"${prop.name}\"`\r\n : prop.converters?.length\r\n ? \"undefined\"\r\n : undefined;\r\n const converterStmt = this.generateConverterStmt(importContainer, prop.converters);\r\n const mappedNameParam = mappedName ? `, ${mappedName}` : \"\";\r\n const converterParam = converterStmt ? `, ${converterStmt}` : \"\";\r\n return `new ${qParam}(\"${prop.odataName}\"${complexQParam}${mappedNameParam}${converterParam})`;\r\n })\r\n .join(\",\");\r\n return `[${pString}]`;\r\n });\r\n\r\n return allParams.length === 1 ? allParams[0] : `[${allParams.join(\",\")}]`;\r\n }\r\n\r\n private async generateUnboundOperations() {\r\n const unboundOps = this.dataModel.getUnboundOperationTypes();\r\n const reservedNames = unboundOps.map((op) => op.qName);\r\n const file = this.project.createOrGetMainQObjectFile(reservedNames);\r\n\r\n unboundOps.forEach((operation) => {\r\n this.generateOperation(file, operation, \"\");\r\n });\r\n }\r\n\r\n private generateOperation(file: FileHandler, operation: OperationType, baseFqName: string) {\r\n const imports = file.getImports();\r\n const isV2 = this.version === ODataVersions.V2;\r\n const returnType = operation.returnType;\r\n const hasParams = operation.parameters.length > 0 || operation.overrides?.length;\r\n const isParamsOptional = !![operation.parameters, ...(operation.overrides ?? [])].find((pSet) => pSet.length === 0);\r\n\r\n // imports\r\n const qOp = operation.type === OperationTypes.Action ? QueryObjectImports.QAction : QueryObjectImports.QFunction;\r\n const qOperation = imports.addQObject(qOp);\r\n const paramModelName = hasParams ? imports.addGeneratedModel(baseFqName, operation.paramsModelName) : undefined;\r\n\r\n let returnTypeOpStmt: string = \"\";\r\n if (returnType) {\r\n const collectionSuffix = returnType.isCollection ? \"_COLLECTION\" : \"\";\r\n if (returnType.dataType === DataTypes.ComplexType || returnType.dataType === DataTypes.ModelType) {\r\n if (returnType.qObject) {\r\n const opRt = imports.addQObject(QueryObjectImports.OperationReturnType);\r\n const rts = imports.addQObject(QueryObjectImports.ReturnTypes);\r\n const qComplexParam = imports.addQObject(QueryObjectImports.QComplexParam);\r\n const returnQName = imports.addGeneratedQObject(returnType.fqType, returnType.qObject);\r\n\r\n returnTypeOpStmt = `new ${opRt}(${rts}.COMPLEX${collectionSuffix}, new ${qComplexParam}(\"NONE\", new ${returnQName}))`;\r\n }\r\n }\r\n // currently, it only makes sense to add the OperationReturnType if a converter is present\r\n else if (returnType.converters && returnType.qParam) {\r\n const rtClass = imports.addQObject(QueryObjectImports.OperationReturnType);\r\n const rtTypes = imports.addQObject(QueryObjectImports.ReturnTypes);\r\n const qParam = imports.addQObject(returnType.qParam);\r\n\r\n // TODO: some constants with string concat\r\n const rtKind = `${rtTypes}.VALUE${collectionSuffix}`;\r\n\r\n const converterParam = returnType.converters\r\n ? \", \" + this.generateConverterStmt(imports, returnType.converters)\r\n : \"\";\r\n returnTypeOpStmt = `new ${rtClass}(${rtKind}, new ${qParam}(\"NONE\", undefined${converterParam}))`;\r\n }\r\n }\r\n\r\n file.getFile().addClass({\r\n name: operation.qName,\r\n isExported: true,\r\n extends: qOperation + (hasParams ? `<${paramModelName}>` : \"\"),\r\n properties: [\r\n {\r\n name: \"params\",\r\n scope: Scope.Private,\r\n isReadonly: true,\r\n type: hasParams ? undefined : \"[]\",\r\n initializer: this.getParamInitString(imports, operation.parameters, operation.overrides),\r\n },\r\n ],\r\n ctors: [\r\n {\r\n statements: [\r\n `super(\"${operation.odataName}\"${returnTypeOpStmt ? \", \" + returnTypeOpStmt : isV2 ? \", undefined\" : \"\"}${\r\n isV2 ? \", { v2Mode: true }\" : \"\"\r\n })`,\r\n ],\r\n },\r\n ],\r\n methods: [\r\n {\r\n name: \"getParams\",\r\n statements: [\"return this.params\"],\r\n },\r\n // functions without params: add an overriding buildUrl() to not force users to have to pass undefined as param\r\n ...(operation.type === OperationTypes.Function && !hasParams\r\n ? [\r\n {\r\n name: \"buildUrl\",\r\n statements: [\"return super.buildUrl(undefined)\"],\r\n },\r\n ]\r\n : []),\r\n ],\r\n });\r\n }\r\n}\r\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ODataVersions } from "@odata2ts/odata-core";
|
|
2
2
|
import { ClassDeclarationStructure } from "ts-morph";
|
|
3
|
-
import { DataModel } from "../data-model/DataModel";
|
|
4
|
-
import { NamingHelper } from "../data-model/NamingHelper";
|
|
5
|
-
import { ConfigFileOptions } from "../OptionModel";
|
|
6
|
-
import { ProjectManager } from "../project/ProjectManager";
|
|
3
|
+
import { DataModel } from "../data-model/DataModel.js";
|
|
4
|
+
import { NamingHelper } from "../data-model/NamingHelper.js";
|
|
5
|
+
import { ConfigFileOptions } from "../OptionModel.js";
|
|
6
|
+
import { ProjectManager } from "../project/ProjectManager.js";
|
|
7
7
|
export interface PropsAndOps extends Required<Pick<ClassDeclarationStructure, "properties" | "methods">> {
|
|
8
8
|
}
|
|
9
9
|
export interface ServiceGeneratorOptions extends Pick<ConfigFileOptions, "enablePrimitivePropertyServices" | "v4BigNumberAsString"> {
|