@odata2ts/odata2ts 0.21.0 → 0.23.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.
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceGenerator.js","sourceRoot":"","sources":["../../src/generator/ServiceGenerator.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AACrD,uCAAqH;AACrH,uDAAkD;AAClD,sDAA2D;AAiB3D,uDAAoD;AAEpD,MAAM,YAAY,GAAG,cAAc,CAAC;AAEpC,MAAM,cAAc,GAAG;IACrB,UAAU,EAAE,yBAAyB;IACrC,KAAK,EAAE,oBAAoB;IAC3B,KAAK,EAAE,oBAAoB;CAC5B,CAAC;AAEF,SAAsB,gBAAgB,CACpC,SAAoB,EACpB,OAAuB,EACvB,OAAsB,EACtB,YAA0B;;QAE1B,MAAM,SAAS,GAAG,IAAI,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;QAClF,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;CAAA;AARD,4CAQC;AAED,MAAM,gBAAgB;IACpB,YACU,SAAoB,EACpB,OAAuB,EACvB,OAAsB,EACtB,YAA0B;QAH1B,cAAS,GAAT,SAAS,CAAW;QACpB,YAAO,GAAP,OAAO,CAAgB;QACvB,YAAO,GAAP,OAAO,CAAe;QACtB,iBAAY,GAAZ,YAAY,CAAc;QA0F5B,4BAAuB,GAAG,CAAC,SAAwB,EAAE,EAAE;YAC7D,OAAO;gBACL,KAAK,EAAE,gBAAK,CAAC,OAAO;gBACpB,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,SAAS,CAAC,KAAK,CAAC;gBAC3D,IAAI,EAAE,SAAS,CAAC,KAAK;gBACrB,gBAAgB,EAAE,IAAI;aACvB,CAAC;QACJ,CAAC,CAAC;IAhGC,CAAC;IAES,QAAQ;;YACnB,MAAM,UAAU,GAAG,MAAM,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AAI,GAAG;wBACpD,CAAC,CAAC,sBAAsB;4BACtB,YAAY,kBAAkB,CAAC,IAAI,GACzC,GAAG;gBACH,UAAU,CAAC,CAAC,CAAC,UAAU,OAAO,6BAA6B,CAAC,CAAC,CAAC,EAAE;aACjE;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { MethodDeclarationStructure, OptionalKind, PropertyDeclarationStructure, Scope, SourceFile } from \"ts-morph\";\r\nimport { upperCaseFirst } from \"upper-case-first\";\r\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport {\r\n ActionImportType,\r\n ComplexType,\r\n DataTypes,\r\n EntitySetType,\r\n FunctionImportType,\r\n ModelType,\r\n OperationType,\r\n OperationTypes,\r\n PropertyModel,\r\n SingletonType,\r\n} from \"../data-model/DataTypeModel\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { ProjectManager } from \"../project/ProjectManager\";\r\nimport { ImportContainer } from \"./ImportContainer\";\r\n\r\nconst ROOT_SERVICE = \"ODataService\";\r\n\r\nconst RESPONSE_TYPES = {\r\n collection: \"ODataCollectionResponse\",\r\n model: \"ODataModelResponse\",\r\n value: \"ODataValueResponse\",\r\n};\r\n\r\nexport async function generateServices(\r\n dataModel: DataModel,\r\n project: ProjectManager,\r\n version: ODataVersions,\r\n namingHelper: NamingHelper\r\n) {\r\n const generator = new ServiceGenerator(dataModel, project, version, namingHelper);\r\n return generator.generate();\r\n}\r\n\r\nclass ServiceGenerator {\r\n constructor(\r\n private dataModel: DataModel,\r\n private project: ProjectManager,\r\n private version: ODataVersions,\r\n private namingHelper: NamingHelper\r\n ) {}\r\n\r\n public async generate(): Promise<void> {\r\n const sourceFile = await this.project.createMainServiceFile();\r\n const serviceName = this.namingHelper.getMainServiceName();\r\n const container = this.dataModel.getEntityContainer();\r\n const unboundOperations = [...Object.values(container.functions), ...Object.values(container.actions)];\r\n\r\n await this.generateModelServices();\r\n\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n importContainer.addFromClientApi(\"ODataClient\");\r\n importContainer.addFromService(ROOT_SERVICE);\r\n\r\n sourceFile.addClass({\r\n isExported: true,\r\n name: serviceName,\r\n typeParameters: [\"ClientType extends ODataClient\"],\r\n extends: `${ROOT_SERVICE}<ClientType>`,\r\n properties: [\r\n {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(\"name\"),\r\n type: \"string\",\r\n initializer: `\"${this.namingHelper.getODataServiceName()}\"`,\r\n },\r\n ...this.generateEntityServiceResolverProp(container.entitySets, importContainer),\r\n ...this.generateServiceGettersByAssignment(container.entitySets),\r\n ...this.generateServiceTypeProps(container.singletons, this.namingHelper.getServiceName, importContainer),\r\n ...Object.values(unboundOperations).map(({ operation }) => this.generateQOperationProps(operation)),\r\n ],\r\n methods: [\r\n ...this.generateServiceTypeGetters(container.singletons, this.namingHelper.getServiceName),\r\n ...this.generateUnboundOperations(unboundOperations, importContainer),\r\n ],\r\n });\r\n\r\n sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));\r\n }\r\n\r\n private generateEntityServiceResolverProp(\r\n services: Record<string, EntitySetType>,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure>[] {\r\n return Object.values(services).map(({ name, entityType }) => {\r\n const resolverName = this.namingHelper.getServiceResolverName(entityType.name);\r\n\r\n importContainer.addGeneratedService(this.namingHelper.getServiceName(entityType.name), resolverName);\r\n\r\n return {\r\n name: this.namingHelper.getPublicPropNameForService(name),\r\n scope: Scope.Public,\r\n initializer: `${resolverName}(this.client, this.getPath(), \"${name}\")`,\r\n };\r\n });\r\n }\r\n\r\n private generateServiceGettersByAssignment(\r\n services: Record<string, EntitySetType>\r\n ): OptionalKind<PropertyDeclarationStructure>[] {\r\n return Object.values(services).map(({ name, odataName, entityType }) => {\r\n const propName = this.namingHelper.getPublicPropNameForService(name);\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(name),\r\n initializer: `this.${propName}.get.bind(this.${propName})`,\r\n };\r\n });\r\n }\r\n\r\n private generateServiceTypeProps(\r\n services: Record<string, SingletonType | EntitySetType>,\r\n typeRetriever: (name: string) => string,\r\n importContainer: ImportContainer\r\n ): OptionalKind<PropertyDeclarationStructure>[] {\r\n return Object.values(services).map(({ name, entityType }) => {\r\n const type = typeRetriever(entityType.name);\r\n\r\n importContainer.addGeneratedService(this.namingHelper.getServiceName(entityType.name), type);\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(name),\r\n type: `${type}<ClientType>`,\r\n hasQuestionToken: true,\r\n };\r\n });\r\n }\r\n\r\n private generateQOperationProps = (operation: OperationType) => {\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(operation.qName),\r\n type: operation.qName,\r\n hasQuestionToken: true,\r\n };\r\n };\r\n\r\n private generateServiceTypeGetters(\r\n services: Record<string, SingletonType | EntitySetType>,\r\n typeRetriever: (name: string) => string\r\n ): OptionalKind<MethodDeclarationStructure>[] {\r\n return Object.values(services).map(({ name, odataName, entityType }) => {\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(name);\r\n const serviceType = typeRetriever(entityType.name);\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n // prettier-ignore\r\n ` ${propName} = new ${serviceType}(this.client, this.getPath(), \"${odataName}\")`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n };\r\n });\r\n }\r\n\r\n private getVersionSuffix() {\r\n return this.version === ODataVersions.V2 ? \"V2\" : \"V4\";\r\n }\r\n\r\n private async generateModelService(\r\n model: ComplexType,\r\n serviceName: string,\r\n serviceFile: SourceFile,\r\n importContainer: ImportContainer\r\n ) {\r\n const entityServiceType = \"EntityTypeService\" + this.getVersionSuffix();\r\n const collectionServiceType = \"CollectionService\" + this.getVersionSuffix();\r\n\r\n const editableModelName = model.editableName;\r\n const operations = this.dataModel.getOperationTypeByBinding(model.name);\r\n const props = [...model.baseProps, ...model.props];\r\n const modelProps = props.filter(\r\n (prop) => prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType\r\n );\r\n const primColProps = props.filter(\r\n (prop) => prop.isCollection && prop.dataType !== DataTypes.ModelType && prop.dataType !== DataTypes.ComplexType\r\n );\r\n\r\n importContainer.addFromService(entityServiceType);\r\n importContainer.addFromClientApi(\"ODataClient\");\r\n importContainer.addGeneratedModel(model.name, editableModelName);\r\n importContainer.addGeneratedQObject(model.qName, firstCharLowerCase(model.qName));\r\n\r\n // generate EntityTypeService\r\n serviceFile.addClass({\r\n isExported: true,\r\n name: serviceName,\r\n typeParameters: [\"ClientType extends ODataClient\"],\r\n extends: entityServiceType + `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}>`,\r\n ctors: [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n { name: \"name\", type: \"string\" },\r\n ],\r\n statements: [`super(client, basePath, name, ${firstCharLowerCase(model.qName)});`],\r\n },\r\n ],\r\n properties: [\r\n ...this.generateModelProps(modelProps, collectionServiceType, serviceName, importContainer),\r\n ...this.generatePrimitiveCollectionProps(primColProps, collectionServiceType, importContainer),\r\n ...operations.map(this.generateQOperationProps),\r\n ],\r\n methods: [\r\n ...this.generateModelPropGetters(modelProps, collectionServiceType),\r\n ...this.generatePrimitiveCollectionGetters(primColProps, collectionServiceType),\r\n ...this.generateBoundOperations(operations, importContainer),\r\n ],\r\n });\r\n }\r\n\r\n private generateModelProps(\r\n modelProps: Array<PropertyModel>,\r\n collectionServiceType: string,\r\n serviceName: string,\r\n importContainer: ImportContainer\r\n ): Array<PropertyDeclarationStructure> {\r\n return modelProps.map((prop) => {\r\n const complexType = this.dataModel.getComplexType(prop.type);\r\n const key = this.namingHelper.getServiceName(prop.type);\r\n let propModelType = prop.isCollection ? this.namingHelper.getCollectionServiceName(prop.type) : key;\r\n\r\n if (prop.isCollection && complexType) {\r\n const editableName = complexType.editableName;\r\n importContainer.addFromService(collectionServiceType);\r\n importContainer.addGeneratedModel(complexType.name, editableName);\r\n importContainer.addGeneratedQObject(complexType.qName, firstCharLowerCase(complexType.qName));\r\n propModelType = `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${editableName}>`;\r\n } else {\r\n // don't include imports for this type\r\n if (serviceName !== key) {\r\n importContainer.addGeneratedService(key, propModelType);\r\n }\r\n\r\n propModelType = `${propModelType}<ClientType>`;\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: propModelType,\r\n hasQuestionToken: true,\r\n } as PropertyDeclarationStructure;\r\n });\r\n }\r\n\r\n private generatePrimitiveCollectionProps(\r\n primColProps: Array<PropertyModel>,\r\n collectionServiceType: string,\r\n importContainer: ImportContainer\r\n ): Array<PropertyDeclarationStructure> {\r\n return primColProps.map((prop) => {\r\n const isEnum = prop.dataType === DataTypes.EnumType;\r\n const type = isEnum ? `EnumCollection<${prop.type}>` : `${upperCaseFirst(prop.type)}Collection`;\r\n const qType = isEnum ? \"QEnumCollection\" : `Q${type}`;\r\n const collectionType = `${collectionServiceType}<ClientType, ${type}, ${qType}>`;\r\n\r\n if (!prop.qObject) {\r\n throw new Error(\"Illegal State: [qObject] must be provided for Collection types!\");\r\n }\r\n\r\n importContainer.addFromService(collectionServiceType);\r\n importContainer.addFromQObject(prop.qObject, firstCharLowerCase(prop.qObject));\r\n if (isEnum) {\r\n importContainer.addGeneratedModel(prop.type);\r\n importContainer.addFromQObject(\"EnumCollection\");\r\n } else {\r\n importContainer.addFromQObject(type);\r\n }\r\n\r\n return {\r\n scope: Scope.Private,\r\n name: this.namingHelper.getPrivatePropName(prop.name),\r\n type: `${collectionType}`,\r\n hasQuestionToken: true,\r\n } as PropertyDeclarationStructure;\r\n });\r\n }\r\n\r\n private generateModelPropGetters(\r\n modelProps: Array<PropertyModel>,\r\n collectionServiceType: string\r\n ): Array<MethodDeclarationStructure> {\r\n return modelProps.map((prop) => {\r\n const complexType = this.dataModel.getComplexType(prop.type);\r\n const isComplexCollection = prop.isCollection && complexType;\r\n const type = isComplexCollection\r\n ? collectionServiceType\r\n : prop.isCollection\r\n ? this.namingHelper.getCollectionServiceName(prop.type)\r\n : this.namingHelper.getServiceName(prop.type);\r\n const typeWithGenerics = isComplexCollection\r\n ? `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${complexType.editableName}>`\r\n : `${type}<ClientType>`;\r\n\r\n const privateSrvProp = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n returnType: typeWithGenerics,\r\n statements: [\r\n `if(!${privateSrvProp}) {`,\r\n // prettier-ignore\r\n ` ${privateSrvProp} = new ${type}(this.client, this.getPath(), \"${prop.odataName}\"${isComplexCollection ? `, ${firstCharLowerCase(complexType.qName)}`: \"\"})`,\r\n \"}\",\r\n `return ${privateSrvProp}`,\r\n ],\r\n } as MethodDeclarationStructure;\r\n });\r\n }\r\n\r\n private generatePrimitiveCollectionGetters(\r\n primColProps: Array<PropertyModel>,\r\n collectionServiceType: string\r\n ): Array<MethodDeclarationStructure> {\r\n return primColProps.map((prop) => {\r\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\r\n return {\r\n scope: Scope.Public,\r\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\r\n statements: [\r\n `if(!${propName}) {`,\r\n // prettier-ignore\r\n ` ${propName} = new ${collectionServiceType}(this.client, this.getPath(), \"${prop.odataName}\", ${firstCharLowerCase(prop.qObject!)})`,\r\n \"}\",\r\n `return ${propName}`,\r\n ],\r\n } as MethodDeclarationStructure;\r\n });\r\n }\r\n\r\n private async generateEntityCollectionService(\r\n model: ModelType,\r\n serviceName: string,\r\n serviceFile: SourceFile,\r\n importContainer: ImportContainer\r\n ) {\r\n const entitySetServiceType = \"EntitySetService\" + this.getVersionSuffix();\r\n const editableModelName = model.editableName;\r\n const qObjectName = firstCharLowerCase(model.qName);\r\n\r\n importContainer.addFromService(entitySetServiceType);\r\n importContainer.addGeneratedModel(model.idModelName);\r\n importContainer.addGeneratedQObject(model.qIdFunctionName);\r\n\r\n const collectionOperations = this.dataModel.getOperationTypeByBinding(`Collection(${model.name})`);\r\n\r\n serviceFile.addClass({\r\n isExported: true,\r\n name: this.namingHelper.getCollectionServiceName(model.name),\r\n typeParameters: [\"ClientType extends ODataClient\"],\r\n extends:\r\n entitySetServiceType +\r\n `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}, ${model.idModelName}, ${serviceName}<ClientType>>`,\r\n ctors: [\r\n {\r\n parameters: [\r\n { name: \"client\", type: \"ClientType\" },\r\n { name: \"basePath\", type: \"string\" },\r\n { name: \"name\", type: \"string\" },\r\n ],\r\n statements: [\r\n `super(client, basePath, name, ${qObjectName}, ${serviceName}, new ${model.qIdFunctionName}(name));`,\r\n ],\r\n },\r\n ],\r\n properties: [...collectionOperations.map(this.generateQOperationProps)],\r\n methods: [...this.generateBoundOperations(collectionOperations, importContainer)],\r\n });\r\n }\r\n\r\n private generateEntityServiceResolver(\r\n model: ModelType,\r\n serviceName: string,\r\n serviceFile: SourceFile,\r\n importContainer: ImportContainer\r\n ) {\r\n const idFunctionName = model.qIdFunctionName;\r\n const collectionName = this.namingHelper.getCollectionServiceName(model.name);\r\n\r\n importContainer.addFromClientApi(\"ODataClient\");\r\n importContainer.addFromService(\"EntityServiceResolver\");\r\n importContainer.addGeneratedQObject(idFunctionName);\r\n\r\n serviceFile.addFunction({\r\n name: this.namingHelper.getServiceResolverName(model.name),\r\n isExported: true,\r\n parameters: [\r\n {\r\n name: \"client\",\r\n type: \"ODataClient\",\r\n },\r\n {\r\n name: \"basePath\",\r\n type: \"string\",\r\n },\r\n {\r\n name: \"entityName\",\r\n type: \"string\",\r\n },\r\n ],\r\n statements: [\r\n `return new EntityServiceResolver(client, basePath, entityName, ${idFunctionName}, ${serviceName}, ${collectionName});`,\r\n ],\r\n });\r\n }\r\n\r\n private async generateModelServices() {\r\n // build service file for each entity, consisting of EntityTypeService & EntityCollectionService\r\n for (const model of this.dataModel.getModels()) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n const serviceFile = await this.project.createServiceFile(serviceName);\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n\r\n // entity type service\r\n await this.generateModelService(model, serviceName, serviceFile, importContainer);\r\n\r\n // entity collection service\r\n await this.generateEntityCollectionService(model, serviceName, serviceFile, importContainer);\r\n\r\n // the resolver function\r\n await this.generateEntityServiceResolver(model, serviceName, serviceFile, importContainer);\r\n\r\n serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));\r\n }\r\n\r\n // build service file for complex types\r\n for (const model of this.dataModel.getComplexTypes()) {\r\n const serviceName = this.namingHelper.getServiceName(model.name);\r\n const serviceFile = await this.project.createServiceFile(serviceName);\r\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n\r\n // entity type service\r\n await this.generateModelService(model, serviceName, serviceFile, importContainer);\r\n serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));\r\n }\r\n }\r\n\r\n private generateBoundOperations(operations: Array<OperationType>, importContainer: ImportContainer) {\r\n return operations.reduce<Array<OptionalKind<MethodDeclarationStructure>>>((collector, operation) => {\r\n collector.push(this.generateMethod(operation.name, operation, importContainer));\r\n\r\n return collector;\r\n }, []);\r\n }\r\n\r\n private generateUnboundOperations(\r\n operations: Array<FunctionImportType | ActionImportType>,\r\n importContainer: ImportContainer\r\n ) {\r\n return Object.values(operations).reduce<Array<OptionalKind<MethodDeclarationStructure>>>(\r\n (collector, { name, operation }) => {\r\n collector.push(this.generateMethod(name, operation, importContainer));\r\n\r\n return collector;\r\n },\r\n []\r\n );\r\n }\r\n\r\n private generateMethod(\r\n name: string,\r\n operation: OperationType,\r\n importContainer: ImportContainer\r\n ): OptionalKind<MethodDeclarationStructure> {\r\n const isFunc = operation.type === OperationTypes.Function;\r\n const odataType = operation.returnType?.isCollection\r\n ? RESPONSE_TYPES.collection + this.getVersionSuffix()\r\n : operation.returnType?.dataType === DataTypes.PrimitiveType\r\n ? RESPONSE_TYPES.value + this.getVersionSuffix()\r\n : RESPONSE_TYPES.model + this.getVersionSuffix();\r\n const returnType = operation.returnType;\r\n const requestConfigParam = { name: \"requestConfig\", hasQuestionToken: true, type: \"ODataClientConfig<ClientType>\" };\r\n const hasParams = operation.parameters.length > 0;\r\n\r\n // importing dependencies\r\n importContainer.addFromClientApi(\"ODataClientConfig\", \"ODataResponse\");\r\n importContainer.addFromCore(odataType);\r\n if (returnType?.type) {\r\n if ([DataTypes.EnumType, DataTypes.ModelType, DataTypes.ComplexType].includes(returnType.dataType)) {\r\n importContainer.addGeneratedModel(returnType.type);\r\n }\r\n }\r\n importContainer.addGeneratedQObject(operation.qName);\r\n if (hasParams) {\r\n importContainer.addGeneratedModel(operation.paramsModelName);\r\n }\r\n\r\n const qOpProp = \"this.\" + this.namingHelper.getPrivatePropName(operation.qName);\r\n\r\n return {\r\n scope: Scope.Public,\r\n isAsync: true,\r\n name,\r\n parameters: hasParams\r\n ? [{ name: \"params\", type: operation.paramsModelName }, requestConfigParam]\r\n : [requestConfigParam],\r\n returnType: `ODataResponse<${odataType}<${returnType?.type || \"void\"}>>`,\r\n statements: [\r\n `if(!${qOpProp}) {`,\r\n ` ${qOpProp} = new ${operation.qName}()`,\r\n \"}\",\r\n\r\n `const url = this.addFullPath(${qOpProp}.buildUrl(${isFunc && hasParams ? \"params\" : \"\"}));`,\r\n `${returnType ? \"const response = await \" : \"return\"} this.client.${\r\n !isFunc\r\n ? // actions: since V4\r\n `post(url, ${hasParams ? `${qOpProp}.convertUserParams(params)` : \"{}\"}, ${requestConfigParam.name})`\r\n : operation.usePost\r\n ? // V2 POST => BUT values are still query params, they are not part of the request body\r\n `post(url, undefined, ${requestConfigParam.name})`\r\n : // functions: since V2\r\n `get(url, ${requestConfigParam.name})`\r\n };`,\r\n returnType ? `return ${qOpProp}.convertResponse(response);` : \"\",\r\n ],\r\n };\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ServiceGenerator.js","sourceRoot":"","sources":["../../src/generator/ServiceGenerator.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AACrD,kEAAkC;AAClC,uCAOkB;AAClB,uDAAkD;AAClD,sDAA2D;AAmB3D,uDAAoD;AAEpD,MAAM,YAAY,GAAG,cAAc,CAAC;AAEpC,MAAM,cAAc,GAAG;IACrB,UAAU,EAAE,yBAAyB;IACrC,KAAK,EAAE,oBAAoB;IAC3B,KAAK,EAAE,oBAAoB;CAC5B,CAAC;AAIF,SAAsB,gBAAgB,CACpC,SAAoB,EACpB,OAAuB,EACvB,OAAsB,EACtB,YAA0B;;QAE1B,MAAM,SAAS,GAAG,IAAI,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;QAClF,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;CAAA;AARD,4CAQC;AAED,MAAM,gBAAgB;IACpB,YACU,SAAoB,EACpB,OAAuB,EACvB,OAAsB,EACtB,YAA0B;QAH1B,cAAS,GAAT,SAAS,CAAW;QACpB,YAAO,GAAP,OAAO,CAAgB;QACvB,YAAO,GAAP,OAAO,CAAe;QACtB,iBAAY,GAAZ,YAAY,CAAc;QA6I5B,2BAAsB,GAAG,CAAC,SAAwB,EAAE,EAAE;YAC5D,OAAO;gBACL,KAAK,EAAE,gBAAK,CAAC,OAAO;gBACpB,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,SAAS,CAAC,KAAK,CAAC;gBAC3D,IAAI,EAAE,SAAS,CAAC,KAAK;gBACrB,gBAAgB,EAAE,IAAI;aACvB,CAAC;QACJ,CAAC,CAAC;IAnJC,CAAC;I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E;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\nimport deepmerge from \"deepmerge\";\nimport {\n ClassDeclarationStructure,\n MethodDeclarationStructure,\n OptionalKind,\n PropertyDeclarationStructure,\n Scope,\n SourceFile,\n} from \"ts-morph\";\nimport { upperCaseFirst } from \"upper-case-first\";\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\n\nimport { DataModel } from \"../data-model/DataModel\";\nimport {\n ActionImportType,\n ComplexType,\n DataTypes,\n EntityContainerModel,\n EntitySetType,\n FunctionImportType,\n ModelType,\n OperationType,\n OperationTypes,\n PropertyModel,\n SingletonType,\n} from \"../data-model/DataTypeModel\";\nimport { EntityType } from \"../data-model/edmx/ODataEdmxModelBase\";\nimport { NamingHelper } from \"../data-model/NamingHelper\";\nimport { ProjectManager } from \"../project/ProjectManager\";\nimport { ImportContainer } from \"./ImportContainer\";\n\nconst ROOT_SERVICE = \"ODataService\";\n\nconst RESPONSE_TYPES = {\n collection: \"ODataCollectionResponse\",\n model: \"ODataModelResponse\",\n value: \"ODataValueResponse\",\n};\n\nexport interface PropsAndOps extends Required<Pick<ClassDeclarationStructure, \"properties\" | \"methods\">> {}\n\nexport async function generateServices(\n dataModel: DataModel,\n project: ProjectManager,\n version: ODataVersions,\n namingHelper: NamingHelper\n) {\n const generator = new ServiceGenerator(dataModel, project, version, namingHelper);\n return generator.generate();\n}\n\nclass ServiceGenerator {\n constructor(\n private dataModel: DataModel,\n private project: ProjectManager,\n private version: ODataVersions,\n private namingHelper: NamingHelper\n ) {}\n\n public async generate(): Promise<void> {\n const sourceFile = await this.project.createMainServiceFile();\n const serviceName = this.namingHelper.getMainServiceName();\n const container = this.dataModel.getEntityContainer();\n const unboundOperations = [...Object.values(container.functions), ...Object.values(container.actions)];\n\n await this.generateModelServices();\n\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\n importContainer.addFromClientApi(\"ODataHttpClient\");\n importContainer.addFromService(ROOT_SERVICE);\n\n const { properties, methods }: PropsAndOps = deepmerge(\n this.generateMainServiceProperties(container, importContainer),\n this.generateMainServiceOperations(unboundOperations, importContainer)\n );\n\n sourceFile.addClass({\n isExported: true,\n name: serviceName,\n typeParameters: [\"ClientType extends ODataHttpClient\"],\n extends: `${ROOT_SERVICE}<ClientType>`,\n properties /*: [\n {\n scope: Scope.Private,\n name: this.namingHelper.getPrivatePropName(\"name\"),\n type: \"string\",\n initializer: `\"${this.namingHelper.getODataServiceName()}\"`,\n },\n ]*/,\n methods,\n });\n\n sourceFile.addImportDeclarations(importContainer.getImportDeclarations(false));\n }\n\n private generateMainServiceProperties(\n container: EntityContainerModel,\n importContainer: ImportContainer\n ): PropsAndOps {\n const result: PropsAndOps = { properties: [], methods: [] };\n\n Object.values(container.entitySets).forEach(({ name, entityType }) => {\n result.methods.push(this.generateRelatedServiceGetter(name, entityType, importContainer));\n });\n\n Object.values(container.singletons).forEach((singleton) => {\n result.properties.push(this.generateSingletonProp(singleton, importContainer));\n result.methods.push(this.generateSingletonGetter(singleton));\n });\n\n return result;\n }\n\n private generateMainServiceOperations(\n ops: Array<FunctionImportType | ActionImportType>,\n importContainer: ImportContainer\n ): PropsAndOps {\n const result: PropsAndOps = { properties: [], methods: [] };\n\n ops.forEach(({ operation, name }) => {\n result.properties.push(this.generateQOperationProp(operation));\n result.methods.push(this.generateMethod(name, operation, importContainer));\n });\n\n return result;\n }\n\n private generateRelatedServiceGetter(\n propName: string,\n entityType: ModelType,\n importContainer: ImportContainer,\n currentServiceName?: string\n ): OptionalKind<MethodDeclarationStructure> {\n const idName = entityType.idModelName;\n const idFunctionName = entityType.qIdFunctionName;\n const serviceName = this.namingHelper.getServiceName(entityType.name);\n const collectionName = this.namingHelper.getCollectionServiceName(entityType.name);\n\n importContainer.addFromClientApi(\"ODataHttpClient\");\n importContainer.addGeneratedModel(idName);\n importContainer.addGeneratedQObject(idFunctionName);\n // make sure to not falsely import self-referential stuff\n if (!currentServiceName || currentServiceName !== serviceName) {\n importContainer.addGeneratedService(serviceName, collectionName, serviceName);\n }\n\n return {\n scope: Scope.Public,\n name: this.namingHelper.getRelatedServiceGetter(propName),\n parameters: [\n {\n name: \"id\",\n type: `${idName} | undefined`,\n hasQuestionToken: true,\n },\n ],\n overloads: [\n {\n parameters: [],\n returnType: `${collectionName}<ClientType>`,\n },\n {\n parameters: [\n {\n name: \"id\",\n type: idName,\n },\n ],\n returnType: `${serviceName}<ClientType>`,\n },\n ],\n statements: [\n `const fieldName = \"${propName}\";`,\n 'return typeof id === \"undefined\" || id === null',\n `? new ${collectionName}(this.client, this.getPath(), fieldName)`,\n `: new ${serviceName}(this.client, this.getPath(), new ${idFunctionName}(fieldName).buildUrl(id));`,\n ],\n };\n }\n\n private generateSingletonProp(\n singleton: SingletonType,\n importContainer: ImportContainer\n ): OptionalKind<PropertyDeclarationStructure> {\n const { name, entityType } = singleton;\n const type = this.namingHelper.getServiceName(entityType.name);\n\n importContainer.addGeneratedService(this.namingHelper.getServiceName(entityType.name), type);\n\n return {\n scope: Scope.Private,\n name: this.namingHelper.getPrivatePropName(name),\n type: `${type}<ClientType>`,\n hasQuestionToken: true,\n };\n }\n\n private generateQOperationProp = (operation: OperationType) => {\n return {\n scope: Scope.Private,\n name: this.namingHelper.getPrivatePropName(operation.qName),\n type: operation.qName,\n hasQuestionToken: true,\n };\n };\n\n private generateSingletonGetter(singleton: SingletonType): OptionalKind<MethodDeclarationStructure> {\n const { name, odataName, entityType } = singleton;\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(name);\n const serviceType = this.namingHelper.getServiceName(entityType.name);\n\n return {\n scope: Scope.Public,\n name: this.namingHelper.getRelatedServiceGetter(name),\n statements: [\n `if(!${propName}) {`,\n // prettier-ignore\n ` ${propName} = new ${serviceType}(this.client, this.getPath(), \"${odataName}\")`,\n \"}\",\n `return ${propName}`,\n ],\n };\n }\n\n private getVersionSuffix() {\n return this.version === ODataVersions.V2 ? \"V2\" : \"V4\";\n }\n\n private async generateEntityTypeService(\n model: ComplexType,\n serviceName: string,\n serviceFile: SourceFile,\n importContainer: ImportContainer\n ) {\n const entityServiceType = \"EntityTypeService\" + this.getVersionSuffix();\n\n const editableModelName = model.editableName;\n const qObjectName = firstCharLowerCase(model.qName);\n const operations = this.dataModel.getOperationTypeByBinding(model.name);\n const props = [...model.baseProps, ...model.props];\n\n importContainer.addFromService(entityServiceType);\n importContainer.addFromClientApi(\"ODataHttpClient\");\n importContainer.addGeneratedModel(model.name, editableModelName);\n importContainer.addGeneratedQObject(model.qName, qObjectName);\n\n const { properties, methods }: PropsAndOps = deepmerge(\n this.generateServiceProperties(serviceName, props, importContainer),\n this.generateServiceOperations(operations, importContainer)\n );\n\n // generate EntityTypeService\n serviceFile.addClass({\n isExported: true,\n name: serviceName,\n typeParameters: [\"ClientType extends ODataHttpClient\"],\n extends: entityServiceType + `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}>`,\n ctors: [\n {\n parameters: [\n { name: \"client\", type: \"ClientType\" },\n { name: \"basePath\", type: \"string\" },\n { name: \"name\", type: \"string\" },\n ],\n statements: [`super(client, basePath, name, ${qObjectName});`],\n },\n ],\n properties,\n methods,\n });\n }\n\n private generateServiceProperties(\n serviceName: string,\n props: Array<PropertyModel>,\n importContainer: ImportContainer\n ): PropsAndOps {\n const collectionServiceType = \"CollectionService\" + this.getVersionSuffix();\n const result: PropsAndOps = { properties: [], methods: [] };\n\n props.forEach((prop) => {\n if ((prop.dataType === DataTypes.ModelType && !prop.isCollection) || prop.dataType === DataTypes.ComplexType) {\n result.properties.push(this.generateModelProp(prop, collectionServiceType, serviceName, importContainer));\n result.methods.push(this.generateModelPropGetter(prop, collectionServiceType));\n } else if (prop.isCollection) {\n // collection of entity types\n if (prop.dataType === DataTypes.ModelType) {\n const entityType = this.dataModel.getModel(prop.type);\n result.methods.push(this.generateRelatedServiceGetter(prop.name, entityType, importContainer, serviceName));\n }\n // collection of primitive or complex types\n else {\n result.properties.push(this.generatePrimitiveCollectionProp(prop, collectionServiceType, importContainer));\n result.methods.push(this.generatePrimitiveCollectionGetter(prop, collectionServiceType));\n }\n }\n });\n\n return result;\n }\n\n private generateServiceOperations(operations: Array<OperationType>, importContainer: ImportContainer): PropsAndOps {\n const result: PropsAndOps = { properties: [], methods: [] };\n\n operations.forEach((operation) => {\n result.properties.push(this.generateQOperationProp(operation));\n result.methods.push(this.generateMethod(operation.name, operation, importContainer));\n });\n\n return result;\n }\n\n private generateModelProp(\n prop: PropertyModel,\n collectionServiceType: string,\n serviceName: string,\n importContainer: ImportContainer\n ): PropertyDeclarationStructure {\n const complexType = this.dataModel.getComplexType(prop.type);\n const key = this.namingHelper.getServiceName(prop.type);\n let propModelType = prop.isCollection ? this.namingHelper.getCollectionServiceName(prop.type) : key;\n\n if (prop.isCollection && complexType) {\n const editableName = complexType.editableName;\n importContainer.addFromService(collectionServiceType);\n importContainer.addGeneratedModel(complexType.name, editableName);\n importContainer.addGeneratedQObject(complexType.qName, firstCharLowerCase(complexType.qName));\n propModelType = `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${editableName}>`;\n } else {\n // don't include imports for this type\n if (serviceName !== key) {\n importContainer.addGeneratedService(key, propModelType);\n }\n\n propModelType = `${propModelType}<ClientType>`;\n }\n\n return {\n scope: Scope.Private,\n name: this.namingHelper.getPrivatePropName(prop.name),\n type: propModelType,\n hasQuestionToken: true,\n } as PropertyDeclarationStructure;\n }\n\n private generatePrimitiveCollectionProp(\n prop: PropertyModel,\n collectionServiceType: string,\n importContainer: ImportContainer\n ): OptionalKind<PropertyDeclarationStructure> {\n const isEnum = prop.dataType === DataTypes.EnumType;\n const type = isEnum ? `EnumCollection<${prop.type}>` : `${upperCaseFirst(prop.type)}Collection`;\n const qType = isEnum ? \"QEnumCollection\" : `Q${type}`;\n const collectionType = `${collectionServiceType}<ClientType, ${type}, ${qType}>`;\n\n if (!prop.qObject) {\n throw new Error(\"Illegal State: [qObject] must be provided for Collection types!\");\n }\n\n importContainer.addFromService(collectionServiceType);\n importContainer.addFromQObject(prop.qObject, firstCharLowerCase(prop.qObject));\n if (isEnum) {\n importContainer.addGeneratedModel(prop.type);\n importContainer.addFromQObject(\"EnumCollection\");\n } else {\n importContainer.addFromQObject(type);\n }\n\n return {\n scope: Scope.Private,\n name: this.namingHelper.getPrivatePropName(prop.name),\n type: `${collectionType}`,\n hasQuestionToken: true,\n };\n }\n\n private generateModelPropGetter(\n prop: PropertyModel,\n collectionServiceType: string\n ): OptionalKind<MethodDeclarationStructure> {\n const complexType = this.dataModel.getComplexType(prop.type);\n const isComplexCollection = prop.isCollection && complexType;\n const type = isComplexCollection\n ? collectionServiceType\n : prop.isCollection\n ? this.namingHelper.getCollectionServiceName(prop.type)\n : this.namingHelper.getServiceName(prop.type);\n const typeWithGenerics = isComplexCollection\n ? `${collectionServiceType}<ClientType, ${complexType.name}, ${complexType.qName}, ${complexType.editableName}>`\n : `${type}<ClientType>`;\n\n const privateSrvProp = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\n\n return {\n scope: Scope.Public,\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\n returnType: typeWithGenerics,\n statements: [\n `if(!${privateSrvProp}) {`,\n // prettier-ignore\n ` ${privateSrvProp} = new ${type}(this.client, this.getPath(), \"${prop.odataName}\"${isComplexCollection ? `, ${firstCharLowerCase(complexType.qName)}`: \"\"})`,\n \"}\",\n `return ${privateSrvProp}`,\n ],\n };\n }\n\n private generatePrimitiveCollectionGetter(\n prop: PropertyModel,\n collectionServiceType: string\n ): OptionalKind<MethodDeclarationStructure> {\n const propName = \"this.\" + this.namingHelper.getPrivatePropName(prop.name);\n return {\n scope: Scope.Public,\n name: this.namingHelper.getRelatedServiceGetter(prop.name),\n statements: [\n `if(!${propName}) {`,\n // prettier-ignore\n ` ${propName} = new ${collectionServiceType}(this.client, this.getPath(), \"${prop.odataName}\", ${firstCharLowerCase(prop.qObject!)})`,\n \"}\",\n `return ${propName}`,\n ],\n };\n }\n\n private async generateEntityCollectionService(\n model: ModelType,\n serviceFile: SourceFile,\n importContainer: ImportContainer\n ) {\n const entitySetServiceType = \"EntitySetService\" + this.getVersionSuffix();\n const editableModelName = model.editableName;\n const qObjectName = firstCharLowerCase(model.qName);\n\n importContainer.addFromService(entitySetServiceType);\n importContainer.addGeneratedModel(model.idModelName);\n importContainer.addGeneratedQObject(model.qIdFunctionName);\n\n const collectionOperations = this.dataModel.getOperationTypeByBinding(`Collection(${model.name})`);\n\n const { properties, methods } = this.generateServiceOperations(collectionOperations, importContainer);\n\n serviceFile.addClass({\n isExported: true,\n name: this.namingHelper.getCollectionServiceName(model.name),\n typeParameters: [\"ClientType extends ODataHttpClient\"],\n extends:\n entitySetServiceType +\n `<ClientType, ${model.name}, ${editableModelName}, ${model.qName}, ${model.idModelName}>`,\n ctors: [\n {\n parameters: [\n { name: \"client\", type: \"ClientType\" },\n { name: \"basePath\", type: \"string\" },\n { name: \"name\", type: \"string\" },\n ],\n statements: [`super(client, basePath, name, ${qObjectName}, new ${model.qIdFunctionName}(name));`],\n },\n ],\n properties,\n methods,\n });\n }\n\n private async generateModelServices() {\n // build service file for each entity, consisting of EntityTypeService & EntityCollectionService\n for (const model of this.dataModel.getModels()) {\n const serviceName = this.namingHelper.getServiceName(model.name);\n const serviceFile = await this.project.createServiceFile(serviceName);\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\n\n // entity type service\n await this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\n\n // entity collection service\n await this.generateEntityCollectionService(model, serviceFile, importContainer);\n\n serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));\n }\n\n // build service file for complex types\n for (const model of this.dataModel.getComplexTypes()) {\n const serviceName = this.namingHelper.getServiceName(model.name);\n const serviceFile = await this.project.createServiceFile(serviceName);\n const importContainer = new ImportContainer(this.namingHelper.getFileNames());\n\n // entity type service\n await this.generateEntityTypeService(model, serviceName, serviceFile, importContainer);\n serviceFile.addImportDeclarations(importContainer.getImportDeclarations(true));\n }\n }\n\n private generateMethod(\n name: string,\n operation: OperationType,\n importContainer: ImportContainer\n ): OptionalKind<MethodDeclarationStructure> {\n const isFunc = operation.type === OperationTypes.Function;\n const odataType = operation.returnType?.isCollection\n ? RESPONSE_TYPES.collection + this.getVersionSuffix()\n : operation.returnType?.dataType === DataTypes.PrimitiveType\n ? RESPONSE_TYPES.value + this.getVersionSuffix()\n : RESPONSE_TYPES.model + this.getVersionSuffix();\n const returnType = operation.returnType;\n const requestConfigParam = {\n name: \"requestConfig\",\n hasQuestionToken: true,\n type: \"ODataHttpClientConfig<ClientType>\",\n };\n const hasParams = operation.parameters.length > 0;\n\n // importing dependencies\n importContainer.addFromClientApi(\"ODataHttpClientConfig\", \"ODataResponse\");\n importContainer.addFromCore(odataType);\n if (returnType?.type) {\n if ([DataTypes.EnumType, DataTypes.ModelType, DataTypes.ComplexType].includes(returnType.dataType)) {\n importContainer.addGeneratedModel(returnType.type);\n }\n }\n importContainer.addGeneratedQObject(operation.qName);\n if (hasParams) {\n importContainer.addGeneratedModel(operation.paramsModelName);\n }\n\n const qOpProp = \"this.\" + this.namingHelper.getPrivatePropName(operation.qName);\n\n return {\n scope: Scope.Public,\n isAsync: true,\n name,\n parameters: hasParams\n ? [{ name: \"params\", type: operation.paramsModelName }, requestConfigParam]\n : [requestConfigParam],\n returnType: `ODataResponse<${odataType}<${returnType?.type || \"void\"}>>`,\n statements: [\n `if(!${qOpProp}) {`,\n ` ${qOpProp} = new ${operation.qName}()`,\n \"}\",\n\n `const url = this.addFullPath(${qOpProp}.buildUrl(${isFunc && hasParams ? \"params\" : \"\"}));`,\n `${returnType ? \"const response = await \" : \"return\"} this.client.${\n !isFunc\n ? // actions: since V4\n `post(url, ${hasParams ? `${qOpProp}.convertUserParams(params)` : \"{}\"}, ${requestConfigParam.name})`\n : operation.usePost\n ? // V2 POST => BUT values are still query params, they are not part of the request body\n `post(url, undefined, ${requestConfigParam.name})`\n : // functions: since V2\n `get(url, ${requestConfigParam.name})`\n };`,\n returnType ? `return ${qOpProp}.convertResponse(response);` : \"\",\n ],\n };\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odata2ts/odata2ts",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -45,9 +45,9 @@
45
45
  "cli"
46
46
  ],
47
47
  "peerDependencies": {
48
- "@odata2ts/odata-client-api": "^0.6.3",
49
- "@odata2ts/odata-query-objects": "^0.17.3",
50
- "@odata2ts/odata-service": "^0.13.9"
48
+ "@odata2ts/http-client-api": "^0.1.0",
49
+ "@odata2ts/odata-query-objects": "^0.18.0",
50
+ "@odata2ts/odata-service": "^0.15.0"
51
51
  },
52
52
  "dependencies": {
53
53
  "@odata2ts/converter-api": "^0.1.2",
@@ -71,9 +71,9 @@
71
71
  },
72
72
  "devDependencies": {
73
73
  "@odata2ts/converter-v2-to-v4": "^0.1.4",
74
- "@odata2ts/odata-client-api": "^0.6.3",
75
- "@odata2ts/odata-query-objects": "^0.17.3",
76
- "@odata2ts/odata-service": "^0.13.9",
74
+ "@odata2ts/http-client-api": "^0.1.0",
75
+ "@odata2ts/odata-query-objects": "^0.18.0",
76
+ "@odata2ts/odata-service": "^0.15.0",
77
77
  "@types/fs-extra": "^9.0.13",
78
78
  "@types/jest": "^27.4.1",
79
79
  "@types/node": "^17.0.23",
@@ -87,6 +87,6 @@
87
87
  "typescript": "^4.9.4"
88
88
  },
89
89
  "types": "./lib/index.d.ts",
90
- "gitHead": "f58b15c1d3239f3a16f56aec2811fa4071b0789e",
90
+ "gitHead": "a3d6457b87ce8c9ec42772c8a5fd02b4246a2e37",
91
91
  "readme": "README.md"
92
92
  }