@odata2ts/odata2ts 0.31.1 → 0.33.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/lib/FactoryFunctionModel.d.ts +1 -1
  3. package/lib/FactoryFunctionModel.js.map +1 -1
  4. package/lib/OptionModel.d.ts +46 -61
  5. package/lib/OptionModel.js.map +1 -1
  6. package/lib/TypeModel.d.ts +10 -0
  7. package/lib/TypeModel.js +17 -0
  8. package/lib/TypeModel.js.map +1 -0
  9. package/lib/app.js +25 -2
  10. package/lib/app.js.map +1 -1
  11. package/lib/cli.js +1 -1
  12. package/lib/cli.js.map +1 -1
  13. package/lib/data-model/DataModel.d.ts +8 -4
  14. package/lib/data-model/DataModel.js +14 -8
  15. package/lib/data-model/DataModel.js.map +1 -1
  16. package/lib/data-model/DataModelDigestion.d.ts +4 -0
  17. package/lib/data-model/DataModelDigestion.js +106 -59
  18. package/lib/data-model/DataModelDigestion.js.map +1 -1
  19. package/lib/data-model/DataModelDigestionV2.js +10 -9
  20. package/lib/data-model/DataModelDigestionV2.js.map +1 -1
  21. package/lib/data-model/DataModelDigestionV4.js +31 -17
  22. package/lib/data-model/DataModelDigestionV4.js.map +1 -1
  23. package/lib/data-model/DataTypeModel.d.ts +3 -0
  24. package/lib/data-model/DataTypeModel.js.map +1 -1
  25. package/lib/data-model/NamingHelper.d.ts +1 -0
  26. package/lib/data-model/NamingHelper.js +5 -0
  27. package/lib/data-model/NamingHelper.js.map +1 -1
  28. package/lib/data-model/ServiceConfigHelper.d.ts +14 -17
  29. package/lib/data-model/ServiceConfigHelper.js +58 -72
  30. package/lib/data-model/ServiceConfigHelper.js.map +1 -1
  31. package/lib/data-model/edmx/ODataEdmxModelBase.d.ts +2 -0
  32. package/lib/data-model/edmx/ODataEdmxModelBase.js.map +1 -1
  33. package/lib/data-model/validation/NameValidator.d.ts +28 -0
  34. package/lib/data-model/validation/NameValidator.js +80 -0
  35. package/lib/data-model/validation/NameValidator.js.map +1 -0
  36. package/lib/defaultConfig.js +2 -2
  37. package/lib/defaultConfig.js.map +1 -1
  38. package/lib/generator/ModelGenerator.js +4 -7
  39. package/lib/generator/ModelGenerator.js.map +1 -1
  40. package/lib/generator/QueryObjectGenerator.js +14 -14
  41. package/lib/generator/QueryObjectGenerator.js.map +1 -1
  42. package/lib/generator/ServiceGenerator.js +66 -66
  43. package/lib/generator/ServiceGenerator.js.map +1 -1
  44. package/lib/index.d.ts +1 -0
  45. package/lib/index.js +1 -0
  46. package/lib/index.js.map +1 -1
  47. package/lib/project/ProjectManager.js +5 -4
  48. package/lib/project/ProjectManager.js.map +1 -1
  49. package/package.json +3 -2
@@ -1 +1 @@
1
- {"version":3,"file":"DataModel.js","sourceRoot":"","sources":["../../src/data-model/DataModel.ts"],"names":[],"mappings":";;;AAGA,mDAayB;AAazB,SAAgB,aAAa,CAAC,EAAU,EAAE,IAAY;IACpD,oHAAoH;IACpH,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACrC,CAAC;AAHD,sCAGC;AAED,MAAa,SAAS;IA0BpB,YACE,UAAqC,EAC7B,OAAqB,EAC7B,aAAoC,IAAI,GAAG,EAAE;QADrC,YAAO,GAAP,OAAO,CAAc;QAzBvB,WAAM,GAAG,IAAI,GAAG,EAA8C,CAAC;QACvE;;;WAGG;QACK,0BAAqB,GAAG,IAAI,GAAG,EAAyB,CAAC;QACjE;;;;WAIG;QACK,8BAAyB,GAAG,IAAI,GAAG,EAAgC,CAAC;QAC5E;;;;WAIG;QACK,wCAAmC,GAAG,IAAI,GAAG,EAAgC,CAAC;QAE9E,oBAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC5C,YAAO,GAA2B,EAAE,CAAC;QACrC,cAAS,GAAyB,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS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M,CAAC,CAAC;gBAC1B,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAChC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACpB;QACH,CAAC;QAED,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,KAAK,CAAC,KAAK,CAAC,CAAC;SACd;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA/OD,8BA+OC","sourcesContent":["import { MappedConverterChains } from \"@odata2ts/converter-runtime\";\r\nimport { ODataTypesV2, ODataTypesV4 } from \"@odata2ts/odata-core\";\r\n\r\nimport {\r\n ActionImportType,\r\n ComplexType,\r\n DataTypes,\r\n EntityContainerModel,\r\n EntitySetType,\r\n EnumType,\r\n FunctionImportType,\r\n ModelType,\r\n ODataVersion,\r\n OperationType,\r\n PropertyModel,\r\n SingletonType,\r\n} from \"./DataTypeModel\";\r\n\r\nexport interface ProjectFiles {\r\n model: string;\r\n qObject: string;\r\n service: string;\r\n}\r\n\r\n/**\r\n * Each namespace is represented as tuple: 1. the namespace 2. the alias, if any.\r\n */\r\nexport type NamespaceWithAlias = [string, string?];\r\n\r\nexport function withNamespace(ns: string, name: string) {\r\n // this supports the edge case of an empty string as namespace which isn't really valid according to spec (see CSDL)\r\n return ns ? `${ns}.${name}` : name;\r\n}\r\n\r\nexport class DataModel {\r\n private readonly converters: MappedConverterChains;\r\n\r\n private models = new Map<string, ModelType | ComplexType | EnumType>();\r\n /**\r\n * Stores unbound operations by their fully qualified name.\r\n * @private\r\n */\r\n private unboundOperationTypes = new Map<string, OperationType>();\r\n /**\r\n * Stores operations bound to an entity type by the fully qualified name of the binding entity, e.g.\r\n * \"Trippin.Person\".\r\n * @private\r\n */\r\n private entityBoundOperationTypes = new Map<string, Array<OperationType>>();\r\n /**\r\n * Stores operations bound to an entity collection by the fully qualified name of the binding entity, e.g.\r\n * \"Trippin.Person\".\r\n * @private\r\n */\r\n private entityCollectionBoundOperationTypes = new Map<string, Array<OperationType>>();\r\n private readonly namespace2Alias: { [ns: string]: string };\r\n private typeDefinitions = new Map<string, string>();\r\n private aliases: Record<string, string> = {};\r\n private container: EntityContainerModel = { entitySets: {}, singletons: {}, functions: {}, actions: {} };\r\n\r\n constructor(\r\n namespaces: Array<NamespaceWithAlias>,\r\n private version: ODataVersion,\r\n converters: MappedConverterChains = new Map()\r\n ) {\r\n this.converters = converters;\r\n this.namespace2Alias = namespaces.reduce<Record<string, string>>((col, [ns, alias]) => {\r\n if (alias) {\r\n col[ns] = alias;\r\n }\r\n return col;\r\n }, {});\r\n }\r\n\r\n /**\r\n * OData version: 2.0 or 4.0.\r\n * @returns\r\n */\r\n public getODataVersion() {\r\n return this.version;\r\n }\r\n\r\n public isV2() {\r\n return this.version === ODataVersion.V2;\r\n }\r\n\r\n public isV4() {\r\n return this.version === ODataVersion.V4;\r\n }\r\n\r\n private retrieveType<T>(fqName: string, haystack: Map<string, T>): T | undefined {\r\n return haystack.get(fqName) || (this.aliases[fqName] ? haystack.get(this.aliases[fqName]) : undefined);\r\n }\r\n\r\n private addAlias(namespace: string, name: string) {\r\n const alias = this.namespace2Alias[namespace];\r\n if (alias) {\r\n this.aliases[withNamespace(alias, name)] = withNamespace(namespace, name);\r\n }\r\n }\r\n\r\n public addTypeDefinition(namespace: string, name: string, type: string) {\r\n const fqName = withNamespace(namespace, name);\r\n this.typeDefinitions.set(fqName, type);\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n public getPrimitiveType(fqName: string): string | undefined {\r\n return this.retrieveType(fqName, this.typeDefinitions);\r\n }\r\n\r\n public getModel(fqName: string) {\r\n return this.retrieveType(fqName, this.models);\r\n }\r\n\r\n public addEntityType(namespace: string, name: string, model: Omit<ModelType, \"dataType\">) {\r\n const fqName = withNamespace(namespace, name);\r\n this.models.set(fqName, { ...model, dataType: DataTypes.ModelType });\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n /**\r\n * Get a specific model by its fully qualified name.\r\n *\r\n * @param fqName the fully qualified name of the entity\r\n * @returns the model type\r\n */\r\n public getEntityType(fqName: string) {\r\n return this.retrieveType(fqName, this.models) as ModelType;\r\n }\r\n\r\n /**\r\n * Retrieve all known EntityType models from the EDMX model.\r\n *\r\n * @returns list of model types\r\n */\r\n public getEntityTypes() {\r\n const ets = [...this.models.values()].filter((m): m is ModelType => m.dataType === DataTypes.ModelType);\r\n return this.sortModelsByInheritance(ets);\r\n }\r\n\r\n public addComplexType(namespace: string, name: string, model: Omit<ComplexType, \"dataType\">) {\r\n const fqName = withNamespace(namespace, name);\r\n this.models.set(fqName, { ...model, dataType: DataTypes.ComplexType });\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n /**\r\n * Get a specific model by its fully qualified name.\r\n *\r\n * @param fqName the final model name that is generated\r\n * @returns the model type\r\n */\r\n public getComplexType(fqName: string) {\r\n return this.retrieveType(fqName, this.models) as ComplexType;\r\n }\r\n\r\n /**\r\n * Retrieve all known ComplexType models from the EDMX model.\r\n *\r\n * @returns list of model types\r\n */\r\n public getComplexTypes() {\r\n const types = [...this.models.values()].filter((m): m is ComplexType => m.dataType === DataTypes.ComplexType);\r\n return this.sortModelsByInheritance(types);\r\n }\r\n\r\n public addEnum(namespace: string, name: string, type: Omit<EnumType, \"dataType\">) {\r\n const fqName = withNamespace(namespace, name);\r\n this.models.set(fqName, { ...type, dataType: DataTypes.EnumType });\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n /**\r\n * Get list of all known enums, i.e. EnumType nodes from the EDMX model.\r\n * @returns list of enum types\r\n */\r\n public getEnums() {\r\n return [...this.models.values()].filter((m): m is EnumType => m.dataType === DataTypes.EnumType);\r\n }\r\n\r\n public addUnboundOperationType(namespace: string, operationType: OperationType) {\r\n this.unboundOperationTypes.set(operationType.fqName, operationType);\r\n this.addAlias(namespace, operationType.odataName);\r\n }\r\n\r\n public getUnboundOperationTypes(): Array<OperationType> {\r\n return [...this.unboundOperationTypes.values()];\r\n }\r\n\r\n public getUnboundOperationType(fqOpName: string): OperationType | undefined {\r\n return this.retrieveType(fqOpName, this.unboundOperationTypes);\r\n }\r\n\r\n public addBoundOperationType(namespace: string, bindingProp: PropertyModel, operationType: OperationType) {\r\n const fqEntityType = bindingProp.fqType;\r\n\r\n const store = bindingProp.isCollection ? this.entityCollectionBoundOperationTypes : this.entityBoundOperationTypes;\r\n const list = store.get(fqEntityType);\r\n if (list) {\r\n list.push(operationType);\r\n } else {\r\n store.set(fqEntityType, [operationType]);\r\n }\r\n }\r\n\r\n public getEntityTypeOperations(fqEntityName: string): Array<OperationType> {\r\n const operations = this.retrieveType(fqEntityName, this.entityBoundOperationTypes);\r\n return operations || [];\r\n }\r\n\r\n public getEntitySetOperations(fqEntityName: string): Array<OperationType> {\r\n const operations = this.retrieveType(fqEntityName, this.entityCollectionBoundOperationTypes);\r\n return operations || [];\r\n }\r\n\r\n public addAction(name: string, action: ActionImportType) {\r\n this.container.actions[name] = action;\r\n }\r\n\r\n public addFunction(name: string, func: FunctionImportType) {\r\n this.container.functions[name] = func;\r\n }\r\n\r\n public addSingleton(name: string, singleton: SingletonType) {\r\n this.container.singletons[name] = singleton;\r\n }\r\n\r\n public addEntitySet(name: string, entitySet: EntitySetType) {\r\n this.container.entitySets[name] = entitySet;\r\n }\r\n\r\n public getEntityContainer() {\r\n return this.container;\r\n }\r\n\r\n public getConverter(dataType: ODataTypesV2 | ODataTypesV4 | string) {\r\n return this.converters.get(dataType);\r\n }\r\n\r\n private sortModelsByInheritance<Type extends Omit<ComplexType, \"dataType\">>(models: Array<Type>): Array<Type> {\r\n // recursively visit all models and sort them by inheritance such that base classes\r\n // are always before derived classes\r\n const sorted: Array<Type> = [];\r\n const visitedModels = new Set<string>();\r\n const inProgressModels = new Set<string>();\r\n\r\n function visit(model: Type) {\r\n const fqName = model.fqName;\r\n if (inProgressModels.has(fqName)) {\r\n throw new Error(`Cyclic inheritance detected for model \"${fqName}\"!`);\r\n }\r\n\r\n if (!visitedModels.has(fqName)) {\r\n inProgressModels.add(fqName);\r\n\r\n for (const baseClassName of model.baseClasses) {\r\n const baseClass = models.find((e) => e.fqName === baseClassName);\r\n if (baseClass) {\r\n visit(baseClass);\r\n }\r\n }\r\n visitedModels.add(fqName);\r\n inProgressModels.delete(fqName);\r\n sorted.push(model);\r\n }\r\n }\r\n\r\n for (const model of models) {\r\n visit(model);\r\n }\r\n return sorted;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"DataModel.js","sourceRoot":"","sources":["../../src/data-model/DataModel.ts"],"names":[],"mappings":";;;AAGA,mDAayB;AAczB,SAAgB,aAAa,CAAC,EAAU,EAAE,IAAY;IACpD,oHAAoH;IACpH,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACrC,CAAC;AAHD,sCAGC;AAED,MAAa,SAAS;IA2BpB,YACE,UAAqC,EAC7B,OAAqB,EAC7B,aAAoC,IAAI,GAAG,EAAE;QADrC,YAAO,GAAP,OAAO,CAAc;QAzBvB,WAAM,GAAG,IAAI,GAAG,EAA8C,CAAC;QACvE;;;WAGG;QACK,0BAAqB,GAAG,IAAI,GAAG,EAAyB,CAAC;QACjE;;;;WAIG;QACK,8BAAyB,GAAG,IAAI,GAAG,EAAgC,CAAC;QAC5E;;;;WAIG;QACK,wCAAmC,GAAG,IAAI,GAAG,EAAgC,CAAC;QAE9E,oBAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC5C,YAAO,GAA2B,EAAE,CAAC;QACrC,cAAS,GAAyB,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAOvG,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC,MAAM,CAAyB,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE;YACpF,IAAI,KAAK,EAAE;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M,CAAC;IAChB,CAAC;IAEM,iBAAiB,CAAC,GAAmC;QAC1D,IAAI,CAAC,cAAc,GAAG,GAAG,CAAC;IAC5B,CAAC;IAEM,iBAAiB;QACtB,OAAO,IAAI,CAAC,cAAe,CAAC;IAC9B,CAAC;CACF;AA3PD,8BA2PC","sourcesContent":["import { MappedConverterChains } from \"@odata2ts/converter-runtime\";\r\nimport { ODataTypesV2, ODataTypesV4 } from \"@odata2ts/odata-core\";\r\n\r\nimport {\r\n ActionImportType,\r\n ComplexType,\r\n DataTypes,\r\n EntityContainerModel,\r\n EntitySetType,\r\n EnumType,\r\n FunctionImportType,\r\n ModelType,\r\n ODataVersion,\r\n OperationType,\r\n PropertyModel,\r\n SingletonType,\r\n} from \"./DataTypeModel\";\r\nimport { ValidationError } from \"./validation/NameValidator\";\r\n\r\nexport interface ProjectFiles {\r\n model: string;\r\n qObject: string;\r\n service: string;\r\n}\r\n\r\n/**\r\n * Each namespace is represented as tuple: 1. the namespace 2. the alias, if any.\r\n */\r\nexport type NamespaceWithAlias = [string, string?];\r\n\r\nexport function withNamespace(ns: string, name: string) {\r\n // this supports the edge case of an empty string as namespace which isn't really valid according to spec (see CSDL)\r\n return ns ? `${ns}.${name}` : name;\r\n}\r\n\r\nexport class DataModel {\r\n private readonly converters: MappedConverterChains;\r\n private nameValidation: Map<string, ValidationError[]> | undefined;\r\n\r\n private models = new Map<string, ModelType | ComplexType | EnumType>();\r\n /**\r\n * Stores unbound operations by their fully qualified name.\r\n * @private\r\n */\r\n private unboundOperationTypes = new Map<string, OperationType>();\r\n /**\r\n * Stores operations bound to an entity type by the fully qualified name of the binding entity, e.g.\r\n * \"Trippin.Person\".\r\n * @private\r\n */\r\n private entityBoundOperationTypes = new Map<string, Array<OperationType>>();\r\n /**\r\n * Stores operations bound to an entity collection by the fully qualified name of the binding entity, e.g.\r\n * \"Trippin.Person\".\r\n * @private\r\n */\r\n private entityCollectionBoundOperationTypes = new Map<string, Array<OperationType>>();\r\n private readonly namespace2Alias: { [ns: string]: string };\r\n private typeDefinitions = new Map<string, string>();\r\n private aliases: Record<string, string> = {};\r\n private container: EntityContainerModel = { entitySets: {}, singletons: {}, functions: {}, actions: {} };\r\n\r\n constructor(\r\n namespaces: Array<NamespaceWithAlias>,\r\n private version: ODataVersion,\r\n converters: MappedConverterChains = new Map()\r\n ) {\r\n this.converters = converters;\r\n this.namespace2Alias = namespaces.reduce<Record<string, string>>((col, [ns, alias]) => {\r\n if (alias) {\r\n col[ns] = alias;\r\n }\r\n return col;\r\n }, {});\r\n }\r\n\r\n /**\r\n * OData version: 2.0 or 4.0.\r\n * @returns\r\n */\r\n public getODataVersion() {\r\n return this.version;\r\n }\r\n\r\n public isV2() {\r\n return this.version === ODataVersion.V2;\r\n }\r\n\r\n public isV4() {\r\n return this.version === ODataVersion.V4;\r\n }\r\n\r\n private retrieveType<T>(fqName: string, haystack: Map<string, T>): T | undefined {\r\n return haystack.get(fqName) || (this.aliases[fqName] ? haystack.get(this.aliases[fqName]) : undefined);\r\n }\r\n\r\n private addAlias(namespace: string, name: string) {\r\n const alias = this.namespace2Alias[namespace];\r\n if (alias) {\r\n this.aliases[withNamespace(alias, name)] = withNamespace(namespace, name);\r\n }\r\n }\r\n\r\n public addTypeDefinition(namespace: string, name: string, type: string) {\r\n const fqName = withNamespace(namespace, name);\r\n this.typeDefinitions.set(fqName, type);\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n public getPrimitiveType(fqName: string): string | undefined {\r\n return this.retrieveType(fqName, this.typeDefinitions);\r\n }\r\n\r\n public getModel(fqName: string) {\r\n return this.retrieveType(fqName, this.models);\r\n }\r\n\r\n public addEntityType(namespace: string, name: string, model: Omit<ModelType, \"dataType\">) {\r\n const fqName = withNamespace(namespace, name);\r\n\r\n this.models.set(fqName, { ...model, dataType: DataTypes.ModelType });\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n /**\r\n * Get a specific model by its fully qualified name.\r\n *\r\n * @param fqName the fully qualified name of the entity\r\n * @returns the model type\r\n */\r\n public getEntityType(fqName: string) {\r\n return this.retrieveType(fqName, this.models) as ModelType;\r\n }\r\n\r\n /**\r\n * Retrieve all known EntityType models from the EDMX model.\r\n *\r\n * @returns list of model types\r\n */\r\n public getEntityTypes() {\r\n const ets = [...this.models.values()].filter((m): m is ModelType => m.dataType === DataTypes.ModelType);\r\n return this.sortModelsByInheritance(ets);\r\n }\r\n\r\n public addComplexType(namespace: string, name: string, model: Omit<ComplexType, \"dataType\">) {\r\n const fqName = withNamespace(namespace, name);\r\n\r\n this.models.set(fqName, { ...model, dataType: DataTypes.ComplexType });\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n /**\r\n * Get a specific model by its fully qualified name.\r\n *\r\n * @param fqName the final model name that is generated\r\n * @returns the model type\r\n */\r\n public getComplexType(fqName: string) {\r\n return this.retrieveType(fqName, this.models) as ComplexType;\r\n }\r\n\r\n /**\r\n * Retrieve all known ComplexType models from the EDMX model.\r\n *\r\n * @returns list of model types\r\n */\r\n public getComplexTypes() {\r\n const types = [...this.models.values()].filter((m): m is ComplexType => m.dataType === DataTypes.ComplexType);\r\n return this.sortModelsByInheritance(types);\r\n }\r\n\r\n public addEnum(namespace: string, name: string, type: Omit<EnumType, \"dataType\">) {\r\n const fqName = withNamespace(namespace, name);\r\n\r\n this.models.set(fqName, { ...type, dataType: DataTypes.EnumType });\r\n this.addAlias(namespace, name);\r\n }\r\n\r\n /**\r\n * Get list of all known enums, i.e. EnumType nodes from the EDMX model.\r\n * @returns list of enum types\r\n */\r\n public getEnums() {\r\n return [...this.models.values()].filter((m): m is EnumType => m.dataType === DataTypes.EnumType);\r\n }\r\n\r\n public addUnboundOperationType(namespace: string, operationType: OperationType) {\r\n this.unboundOperationTypes.set(operationType.fqName, operationType);\r\n this.addAlias(namespace, operationType.odataName);\r\n }\r\n\r\n public getUnboundOperationTypes(): Array<OperationType> {\r\n return [...this.unboundOperationTypes.values()];\r\n }\r\n\r\n public getUnboundOperationType(fqOpName: string): OperationType | undefined {\r\n return this.retrieveType(fqOpName, this.unboundOperationTypes);\r\n }\r\n\r\n public addBoundOperationType(namespace: string, bindingProp: PropertyModel, operationType: OperationType) {\r\n const fqEntityType = bindingProp.fqType;\r\n\r\n const store = bindingProp.isCollection ? this.entityCollectionBoundOperationTypes : this.entityBoundOperationTypes;\r\n const list = store.get(fqEntityType);\r\n if (list) {\r\n list.push(operationType);\r\n } else {\r\n store.set(fqEntityType, [operationType]);\r\n }\r\n }\r\n\r\n public getEntityTypeOperations(fqEntityName: string): Array<OperationType> {\r\n const operations = this.retrieveType(fqEntityName, this.entityBoundOperationTypes);\r\n return operations || [];\r\n }\r\n\r\n public getEntitySetOperations(fqEntityName: string): Array<OperationType> {\r\n const operations = this.retrieveType(fqEntityName, this.entityCollectionBoundOperationTypes);\r\n return operations || [];\r\n }\r\n\r\n public addAction(fqName: string, action: ActionImportType) {\r\n this.container.actions[fqName] = action;\r\n }\r\n\r\n public addFunction(fqName: string, func: FunctionImportType) {\r\n this.container.functions[fqName] = func;\r\n }\r\n\r\n public addSingleton(fqName: string, singleton: SingletonType) {\r\n this.container.singletons[fqName] = singleton;\r\n }\r\n\r\n public addEntitySet(fqName: string, entitySet: EntitySetType) {\r\n this.container.entitySets[fqName] = entitySet;\r\n }\r\n\r\n public getEntityContainer() {\r\n return this.container;\r\n }\r\n\r\n public getConverter(dataType: ODataTypesV2 | ODataTypesV4 | string) {\r\n return this.converters.get(dataType);\r\n }\r\n\r\n private sortModelsByInheritance<Type extends Omit<ComplexType, \"dataType\">>(models: Array<Type>): Array<Type> {\r\n // recursively visit all models and sort them by inheritance such that base classes\r\n // are always before derived classes\r\n const sorted: Array<Type> = [];\r\n const visitedModels = new Set<string>();\r\n const inProgressModels = new Set<string>();\r\n\r\n function visit(model: Type) {\r\n const fqName = model.fqName;\r\n if (inProgressModels.has(fqName)) {\r\n throw new Error(`Cyclic inheritance detected for model \"${fqName}\"!`);\r\n }\r\n\r\n if (!visitedModels.has(fqName)) {\r\n inProgressModels.add(fqName);\r\n\r\n for (const baseClassName of model.baseClasses) {\r\n const baseClass = models.find((e) => e.fqName === baseClassName);\r\n if (baseClass) {\r\n visit(baseClass);\r\n }\r\n }\r\n visitedModels.add(fqName);\r\n inProgressModels.delete(fqName);\r\n sorted.push(model);\r\n }\r\n }\r\n\r\n for (const model of models) {\r\n visit(model);\r\n }\r\n return sorted;\r\n }\r\n\r\n public setNameValidation(map: Map<string, ValidationError[]>) {\r\n this.nameValidation = map;\r\n }\r\n\r\n public getNameValidation() {\r\n return this.nameValidation!;\r\n }\r\n}\r\n"]}
@@ -8,6 +8,7 @@ import { SchemaV3 } from "./edmx/ODataEdmxModelV3";
8
8
  import { SchemaV4 } from "./edmx/ODataEdmxModelV4";
9
9
  import { NamingHelper } from "./NamingHelper";
10
10
  import { ServiceConfigHelper } from "./ServiceConfigHelper";
11
+ import { NameValidator } from "./validation/NameValidator";
11
12
  export interface TypeModel {
12
13
  outputType: string;
13
14
  qPath: string;
@@ -22,6 +23,7 @@ export declare abstract class Digester<S extends Schema<ET, CT>, ET extends Enti
22
23
  protected static EDM_PREFIX: string;
23
24
  protected readonly dataModel: DataModel;
24
25
  protected readonly serviceConfigHelper: ServiceConfigHelper;
26
+ protected readonly nameValidator: NameValidator;
25
27
  private model2Type;
26
28
  protected constructor(version: ODataVersion, schemas: Array<S>, options: DigestionOptions, namingHelper: NamingHelper, converters?: MappedConverterChains);
27
29
  private collectModelTypes;
@@ -40,9 +42,11 @@ export declare abstract class Digester<S extends Schema<ET, CT>, ET extends Enti
40
42
  private digestEntityTypesAndOperations;
41
43
  private getBaseModel;
42
44
  private addTypeDefinition;
45
+ private addEnum;
43
46
  private addComplexType;
44
47
  private addEntityType;
45
48
  private postProcessModel;
49
+ private postProcessKeys;
46
50
  private collectBaseClassPropsAndKeys;
47
51
  protected mapProp: (p: Property, entityPropConfig?: PropertyGenerationOptions | undefined) => PropertyModel;
48
52
  }
@@ -4,6 +4,13 @@ exports.Digester = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const DataModel_1 = require("./DataModel");
6
6
  const ServiceConfigHelper_1 = require("./ServiceConfigHelper");
7
+ const NameValidator_1 = require("./validation/NameValidator");
8
+ function ifTrue(value) {
9
+ return value === "true";
10
+ }
11
+ function ifFalse(value) {
12
+ return value === "false";
13
+ }
7
14
  class Digester {
8
15
  constructor(version, schemas, options, namingHelper, converters) {
9
16
  this.version = version;
@@ -12,6 +19,7 @@ class Digester {
12
19
  this.namingHelper = namingHelper;
13
20
  this.model2Type = new Map();
14
21
  this.mapProp = (p, entityPropConfig) => {
22
+ var _a, _b;
15
23
  if (!p.$.Type) {
16
24
  throw new Error(`No type information given for property [${p.$.Name}]!`);
17
25
  }
@@ -31,14 +39,17 @@ class Digester {
31
39
  // EntityType, ComplexType, EnumType
32
40
  if (this.namingHelper.includesServicePrefix(dataType)) {
33
41
  const resultDt = this.model2Type.get(dataType);
42
+ const [dataTypeName, dataTypePrefix] = this.namingHelper.getNameAndServicePrefix(dataType);
43
+ const dataTypeNamespace = [dataTypePrefix];
34
44
  if (!resultDt) {
35
45
  throw new Error(`Couldn't determine model data type for property "${p.$.Name}"! Given data type: "${dataType}".`);
36
46
  }
37
47
  // special handling for enums
38
48
  if (resultDt === "EnumType" /* DataTypes.EnumType */) {
49
+ const enumConfig = this.serviceConfigHelper.findEnumTypeConfig(dataTypeNamespace, dataTypeName);
39
50
  result = {
40
51
  dataType: resultDt,
41
- type: this.namingHelper.getEnumName(dataType),
52
+ type: this.namingHelper.getEnumName((_a = enumConfig === null || enumConfig === void 0 ? void 0 : enumConfig.mappedName) !== null && _a !== void 0 ? _a : dataType),
42
53
  qPath: "QEnumPath",
43
54
  qObject: isCollection ? "QEnumCollection" : undefined,
44
55
  qParam: "QEnumParam",
@@ -46,11 +57,15 @@ class Digester {
46
57
  }
47
58
  // handling of complex & entity types
48
59
  else {
60
+ const entityConfig = resultDt === "ComplexType" /* DataTypes.ComplexType */
61
+ ? this.serviceConfigHelper.findComplexTypeConfig(dataTypeNamespace, dataTypeName)
62
+ : this.serviceConfigHelper.findEntityTypeConfig(dataTypeNamespace, dataTypeName);
63
+ const resultDataType = (_b = entityConfig === null || entityConfig === void 0 ? void 0 : entityConfig.mappedName) !== null && _b !== void 0 ? _b : dataType;
49
64
  result = {
50
65
  dataType: resultDt,
51
- type: this.namingHelper.getModelName(dataType),
66
+ type: this.namingHelper.getModelName(resultDataType),
52
67
  qPath: "QEntityPath",
53
- qObject: this.namingHelper.getQName(dataType),
68
+ qObject: this.namingHelper.getQName(resultDataType),
54
69
  qParam: "QComplexParam",
55
70
  };
56
71
  }
@@ -73,11 +88,12 @@ class Digester {
73
88
  else {
74
89
  throw new Error(`Unknown type [${dataType}]: Not 'Collection(...)', not OData type 'Edm.*', not starting with one of the namespaces!W`);
75
90
  }
76
- return Object.assign({ odataName: p.$.Name, name, odataType: p.$.Type, fqType: dataType, required: p.$.Nullable === "false", isCollection: isCollection, managed: typeof (entityPropConfig === null || entityPropConfig === void 0 ? void 0 : entityPropConfig.managed) !== "undefined" ? entityPropConfig.managed : configProp === null || configProp === void 0 ? void 0 : configProp.managed }, result);
91
+ return Object.assign({ odataName: p.$.Name, name, odataType: p.$.Type, fqType: dataType, required: ifFalse(p.$.Nullable), isCollection: isCollection, managed: typeof (entityPropConfig === null || entityPropConfig === void 0 ? void 0 : entityPropConfig.managed) !== "undefined" ? entityPropConfig.managed : configProp === null || configProp === void 0 ? void 0 : configProp.managed }, result);
77
92
  };
78
93
  const namespaces = schemas.map((s) => [s.$.Namespace, s.$.Alias]);
79
94
  this.dataModel = new DataModel_1.DataModel(namespaces, version, converters);
80
95
  this.serviceConfigHelper = new ServiceConfigHelper_1.ServiceConfigHelper(options);
96
+ this.nameValidator = new NameValidator_1.NameValidator(options);
81
97
  this.collectModelTypes(schemas);
82
98
  }
83
99
  collectModelTypes(schemas) {
@@ -106,6 +122,7 @@ class Digester {
106
122
  this.digestEntityTypesAndOperations();
107
123
  // delegate to version specific entity container digestion
108
124
  this.schemas.forEach((schema) => this.digestEntityContainer(schema));
125
+ this.dataModel.setNameValidation(this.nameValidator.validate());
109
126
  return this.dataModel;
110
127
  });
111
128
  }
@@ -115,18 +132,7 @@ class Digester {
115
132
  // type definitions: alias for primitive types
116
133
  this.addTypeDefinition(schema.$.Namespace, schema.TypeDefinition);
117
134
  // enums
118
- if (schema.EnumType) {
119
- for (const et of schema.EnumType) {
120
- const odataName = et.$.Name;
121
- const fqName = (0, DataModel_1.withNamespace)(ns[0], odataName);
122
- this.dataModel.addEnum(ns[0], odataName, {
123
- fqName,
124
- odataName,
125
- name: this.namingHelper.getEnumName(odataName),
126
- members: et.Member.map((m) => m.$.Name),
127
- });
128
- }
129
- }
135
+ this.addEnum(ns, schema.EnumType);
130
136
  // complex types
131
137
  this.addComplexType(ns, schema.ComplexType);
132
138
  // entity types
@@ -135,13 +141,11 @@ class Digester {
135
141
  this.digestOperations(schema);
136
142
  });
137
143
  this.postProcessModel();
144
+ this.postProcessKeys();
138
145
  }
139
- getBaseModel(namespace, model) {
140
- var _a;
146
+ getBaseModel(entityConfig, model, name, fqName) {
147
+ var _a, _b;
141
148
  const odataName = model.$.Name;
142
- const fqName = (0, DataModel_1.withNamespace)(namespace[0], odataName);
143
- const entityConfig = this.serviceConfigHelper.findEntityConfigByName(namespace, odataName);
144
- const entityName = (entityConfig === null || entityConfig === void 0 ? void 0 : entityConfig.mappedName) || model.$.Name;
145
149
  // map properties respecting the config
146
150
  const props = [...((_a = model.Property) !== null && _a !== void 0 ? _a : []), ...this.getNavigationProps(model)].map((p) => {
147
151
  var _a;
@@ -150,18 +154,26 @@ class Digester {
150
154
  });
151
155
  // support for base types, i.e. extends clause of interfaces
152
156
  const baseClasses = [];
157
+ let finalBaseClass = undefined;
153
158
  if (model.$.BaseType) {
154
159
  baseClasses.push(model.$.BaseType);
160
+ const [baseName, basePrefix] = this.namingHelper.getNameAndServicePrefix(model.$.BaseType);
161
+ const baseConfig = this.serviceConfigHelper.findEntityTypeConfig([basePrefix], baseName) ||
162
+ this.serviceConfigHelper.findComplexTypeConfig([basePrefix], baseName);
163
+ finalBaseClass = (_b = baseConfig === null || baseConfig === void 0 ? void 0 : baseConfig.mappedName) !== null && _b !== void 0 ? _b : baseName;
155
164
  }
156
165
  return {
157
166
  fqName,
158
167
  odataName,
159
- name: this.namingHelper.getModelName(entityName),
160
- qName: this.namingHelper.getQName(entityName),
161
- editableName: this.namingHelper.getEditableModelName(entityName),
168
+ name: this.namingHelper.getModelName(name),
169
+ qName: this.namingHelper.getQName(name),
170
+ editableName: this.namingHelper.getEditableModelName(name),
162
171
  baseClasses,
172
+ finalBaseClass,
163
173
  props,
164
- baseProps: [], // postprocess required
174
+ baseProps: [],
175
+ abstract: ifTrue(model.$.Abstract),
176
+ open: ifTrue(model.$.OpenType),
165
177
  };
166
178
  }
167
179
  addTypeDefinition(ns, types) {
@@ -172,12 +184,32 @@ class Digester {
172
184
  this.dataModel.addTypeDefinition(ns, t.$.Name, t.$.UnderlyingType);
173
185
  }
174
186
  }
187
+ addEnum(namespace, models) {
188
+ if (!models || !models.length) {
189
+ return;
190
+ }
191
+ for (const et of models) {
192
+ const odataName = et.$.Name;
193
+ const fqName = (0, DataModel_1.withNamespace)(namespace[0], odataName);
194
+ const config = this.serviceConfigHelper.findEnumTypeConfig(namespace, odataName);
195
+ const enumName = this.nameValidator.addEnumType(fqName, (config === null || config === void 0 ? void 0 : config.mappedName) || odataName);
196
+ this.dataModel.addEnum(namespace[0], odataName, {
197
+ fqName,
198
+ odataName,
199
+ name: this.namingHelper.getEnumName(enumName),
200
+ members: et.Member.map((m) => m.$.Name),
201
+ });
202
+ }
203
+ }
175
204
  addComplexType(namespace, models) {
176
205
  if (!models || !models.length) {
177
206
  return;
178
207
  }
179
208
  for (const model of models) {
180
- const baseModel = this.getBaseModel(namespace, model);
209
+ const config = this.serviceConfigHelper.findComplexTypeConfig(namespace, model.$.Name);
210
+ const fqName = (0, DataModel_1.withNamespace)(namespace[0], model.$.Name);
211
+ const name = this.nameValidator.addComplexType(fqName, (config === null || config === void 0 ? void 0 : config.mappedName) || model.$.Name);
212
+ const baseModel = this.getBaseModel(config, model, name, fqName);
181
213
  this.dataModel.addComplexType(namespace[0], baseModel.odataName, baseModel);
182
214
  }
183
215
  }
@@ -187,9 +219,10 @@ class Digester {
187
219
  return;
188
220
  }
189
221
  for (const model of models) {
190
- const baseModel = this.getBaseModel(namespace, model);
191
- const entityConfig = this.serviceConfigHelper.findEntityConfigByName(namespace, model.$.Name);
192
- const entityName = (entityConfig === null || entityConfig === void 0 ? void 0 : entityConfig.mappedName) || model.$.Name;
222
+ const entityConfig = this.serviceConfigHelper.findEntityTypeConfig(namespace, model.$.Name);
223
+ const fqName = (0, DataModel_1.withNamespace)(namespace[0], model.$.Name);
224
+ const name = this.nameValidator.addEntityType(fqName, (entityConfig === null || entityConfig === void 0 ? void 0 : entityConfig.mappedName) || model.$.Name);
225
+ const baseModel = this.getBaseModel(entityConfig, model, name, fqName);
193
226
  // key support: we add keys from this entity,
194
227
  // but not keys stemming from base classes (postprocess required)
195
228
  const keyNames = [];
@@ -203,34 +236,43 @@ class Digester {
203
236
  keyNames.push(...propNames);
204
237
  }
205
238
  }
206
- this.dataModel.addEntityType(namespace[0], baseModel.odataName, Object.assign(Object.assign({}, baseModel), { idModelName: this.namingHelper.getIdModelName(entityName), qIdFunctionName: this.namingHelper.getQIdFunctionName(entityName), generateId: true, keyNames: keyNames, keys: [], getKeyUnion: () => keyNames.join(" | ") }));
239
+ this.dataModel.addEntityType(namespace[0], baseModel.odataName, Object.assign(Object.assign({}, baseModel), { idModelName: this.namingHelper.getIdModelName(name), qIdFunctionName: this.namingHelper.getQIdFunctionName(name), generateId: !!keyNames.length, keyNames: keyNames, keys: [], getKeyUnion: () => keyNames.join(" | ") }));
207
240
  }
208
241
  }
209
242
  postProcessModel() {
210
243
  // complex types
211
244
  const complexTypes = this.dataModel.getComplexTypes();
212
- complexTypes.forEach((model) => {
213
- const [baseProps] = this.collectBaseClassPropsAndKeys(model, []);
214
- model.baseProps = baseProps;
245
+ complexTypes.forEach((ct) => {
246
+ const [baseProps, _, baseAttributes] = this.collectBaseClassPropsAndKeys(ct, []);
247
+ const { open } = baseAttributes;
248
+ ct.baseProps = baseProps.map((bp) => (Object.assign({}, bp)));
249
+ if (open) {
250
+ ct.open = true;
251
+ }
215
252
  });
216
253
  // entity types
217
- const modelTypes = this.dataModel.getEntityTypes();
218
- modelTypes.forEach((model) => {
219
- const [baseProps, baseKeys, idName, qIdName] = this.collectBaseClassPropsAndKeys(model, []);
220
- model.baseProps = baseProps;
221
- if (!model.keyNames.length && idName) {
222
- model.idModelName = idName;
223
- model.qIdFunctionName = qIdName;
224
- model.generateId = false;
254
+ const entityTypes = this.dataModel.getEntityTypes();
255
+ entityTypes.forEach((et) => {
256
+ const [baseProps, baseKeys, baseAttributes] = this.collectBaseClassPropsAndKeys(et, []);
257
+ const { idName, qIdName, open } = baseAttributes;
258
+ et.baseProps = baseProps.map((bp) => (Object.assign({}, bp)));
259
+ if (!et.keyNames.length && idName) {
260
+ et.idModelName = idName;
261
+ et.qIdFunctionName = qIdName;
262
+ et.generateId = false;
225
263
  }
226
- model.keyNames.unshift(...baseKeys);
227
- // sanity check: entity types require key specification
228
- if (!model.keyNames.length) {
229
- throw new Error(`Key property is missing from Entity "${model.name}" (${model.odataName})!`);
264
+ if (open) {
265
+ et.open = open;
230
266
  }
231
- const isSingleKey = model.keyNames.length === 1;
232
- const props = [...model.baseProps, ...model.props];
233
- model.keys = model.keyNames.map((keyName) => {
267
+ et.keyNames.unshift(...baseKeys);
268
+ });
269
+ }
270
+ postProcessKeys() {
271
+ const entityTypes = this.dataModel.getEntityTypes();
272
+ entityTypes.forEach((et) => {
273
+ const isSingleKey = et.keyNames.length === 1;
274
+ const props = [...et.baseProps, ...et.props];
275
+ et.keys = et.keyNames.map((keyName) => {
234
276
  const prop = props.find((p) => p.odataName === keyName);
235
277
  if (!prop) {
236
278
  throw new Error(`Key with name [${keyName}] not found in props!`);
@@ -248,33 +290,38 @@ class Digester {
248
290
  throw new Error(`Cyclic inheritance detected for model ${model.fqName}!`);
249
291
  }
250
292
  visitedModels.push(model.fqName);
251
- return model.baseClasses.reduce(([props, keys, idName, qIdName], bc) => {
293
+ return model.baseClasses.reduce(([props, keys, attributes], bc) => {
252
294
  var _a;
253
295
  const baseModel = this.dataModel.getEntityType(bc) || this.dataModel.getComplexType(bc);
254
296
  if (!baseModel) {
255
297
  throw new Error(`BaseModel "${bc}" doesn't exist!`);
256
298
  }
257
- let idNameResult = idName;
258
- let qIdNameResult = qIdName;
299
+ let { idName, qIdName, open } = attributes;
259
300
  // recursive
260
301
  if (baseModel.baseClasses.length) {
261
- const [parentProps, parentKeys, parentIdName, parentQIdName] = this.collectBaseClassPropsAndKeys(baseModel, visitedModels);
302
+ const [parentProps, parentKeys, parentAttributes] = this.collectBaseClassPropsAndKeys(baseModel, visitedModels);
262
303
  props.unshift(...parentProps);
263
304
  keys.unshift(...parentKeys);
264
- if (parentIdName) {
265
- idNameResult = parentIdName;
266
- qIdNameResult = parentQIdName;
305
+ if (parentAttributes === null || parentAttributes === void 0 ? void 0 : parentAttributes.idName) {
306
+ idName = parentAttributes.idName;
307
+ qIdName = parentAttributes.qIdName;
308
+ }
309
+ if (parentAttributes === null || parentAttributes === void 0 ? void 0 : parentAttributes.open) {
310
+ open = true;
267
311
  }
268
312
  }
269
313
  props.push(...baseModel.props);
270
314
  const entityModel = baseModel;
271
315
  if ((_a = entityModel.keyNames) === null || _a === void 0 ? void 0 : _a.length) {
272
316
  keys.push(...entityModel.keyNames.filter((kn) => !keys.includes(kn)));
273
- idNameResult = entityModel.idModelName;
274
- qIdNameResult = entityModel.qIdFunctionName;
317
+ idName = entityModel.idModelName;
318
+ qIdName = entityModel.qIdFunctionName;
319
+ }
320
+ if (baseModel.open) {
321
+ open = true;
275
322
  }
276
- return [props, keys, idNameResult, qIdNameResult];
277
- }, [[], [], "", ""]);
323
+ return [props, keys, { idName, qIdName, open }];
324
+ }, [[], [], { idName: "", qIdName: "", open: false }]);
278
325
  }
279
326
  }
280
327
  exports.Digester = Digester;
@@ -1 +1 @@
1
- {"version":3,"file":"DataModelDigestion.js","sourceRoot":"","sources":["../../src/data-model/DataModelDigestion.ts"],"names":[],"mappings":";;;;AAIA,2CAA2E;AAM3E,+DAA4D;AAS5D,MAAsB,QAAQ;IAQ5B,YACY,OAAqB,EACrB,OAAiB,EACjB,OAAyB,EACzB,YAA0B,EACpC,UAAkC;QAJxB,YAAO,GAAP,OAAO,CAAc;QACrB,YAAO,GAAP,OAAO,CAAU;QACjB,YAAO,GAAP,OAAO,CAAkB;QACzB,iBAAY,GAAZ,YAAY,CAAc;QAN9B,eAAU,GAAG,IAAI,GAAG,EAAqB,CAAC;QA6QxC,YAAO,GAAG,CAAC,CAAW,EAAE,gBAAwD,EAAiB,EAAE;YAC3G,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;gBACb,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;aAC1E;YAED,MAAM,UAAU,GAAG,IAAI,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAC3E,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,UAAU,MAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,UAAU,CAAA,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YACpH,MAAM,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YACvD,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAC;YAEjE,q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AC,WAAW,CAAC;gBACvC,aAAa,GAAG,WAAW,CAAC,eAAe,CAAC;aAC7C;YACD,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;QACpD,CAAC,EACD,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAA0D,CAC1E,CAAC;IACJ,CAAC;;AAjRH,4BAuWC;AAtWkB,mBAAU,GAAG,MAAM,AAAT,CAAU","sourcesContent":["import { MappedConverterChains } from \"@odata2ts/converter-runtime\";\r\n\r\nimport { DigestionOptions } from \"../FactoryFunctionModel\";\r\nimport { PropertyGenerationOptions } from \"../OptionModel\";\r\nimport { DataModel, NamespaceWithAlias, withNamespace } from \"./DataModel\";\r\nimport { ComplexType as ComplexModelType, DataTypes, ModelType, ODataVersion, PropertyModel } from \"./DataTypeModel\";\r\nimport { ComplexType, EntityType, Property, Schema, TypeDefinition } from \"./edmx/ODataEdmxModelBase\";\r\nimport { SchemaV3 } from \"./edmx/ODataEdmxModelV3\";\r\nimport { SchemaV4 } from \"./edmx/ODataEdmxModelV4\";\r\nimport { NamingHelper } from \"./NamingHelper\";\r\nimport { ServiceConfigHelper } from \"./ServiceConfigHelper\";\r\n\r\nexport interface TypeModel {\r\n outputType: string;\r\n qPath: string;\r\n qCollection: string;\r\n qParam: string | undefined;\r\n}\r\n\r\nexport abstract class Digester<S extends Schema<ET, CT>, ET extends EntityType, CT extends ComplexType> {\r\n protected static EDM_PREFIX = \"Edm.\";\r\n\r\n protected readonly dataModel: DataModel;\r\n protected readonly serviceConfigHelper: ServiceConfigHelper;\r\n\r\n private model2Type = new Map<string, DataTypes>();\r\n\r\n protected constructor(\r\n protected version: ODataVersion,\r\n protected schemas: Array<S>,\r\n protected options: DigestionOptions,\r\n protected namingHelper: NamingHelper,\r\n converters?: MappedConverterChains\r\n ) {\r\n const namespaces = schemas.map<NamespaceWithAlias>((s) => [s.$.Namespace, s.$.Alias]);\r\n this.dataModel = new DataModel(namespaces, version, converters);\r\n this.serviceConfigHelper = new ServiceConfigHelper(options);\r\n\r\n this.collectModelTypes(schemas);\r\n }\r\n\r\n private collectModelTypes(schemas: Array<S>) {\r\n schemas.forEach((schema) => {\r\n const { Namespace: ns, Alias: alias } = schema.$;\r\n\r\n schema.EnumType?.forEach((et) => {\r\n this.addModel2Type(ns, alias, et.$.Name, DataTypes.EnumType);\r\n });\r\n schema.ComplexType?.forEach((ct) => {\r\n this.addModel2Type(ns, alias, ct.$.Name, DataTypes.ComplexType);\r\n });\r\n schema.EntityType?.forEach((et) => {\r\n this.addModel2Type(ns, alias, et.$.Name, DataTypes.ModelType);\r\n });\r\n });\r\n }\r\n\r\n private addModel2Type(ns: string, alias: string | undefined, name: string, dt: DataTypes) {\r\n this.model2Type.set(withNamespace(ns, name), dt);\r\n if (alias) {\r\n this.model2Type.set(withNamespace(alias, name), dt);\r\n }\r\n }\r\n\r\n protected abstract getNavigationProps(entityType: ET | ComplexType): Array<Property>;\r\n\r\n protected abstract digestOperations(schema: SchemaV3 | SchemaV4): void;\r\n\r\n protected abstract digestEntityContainer(schema: SchemaV3 | SchemaV4): void;\r\n\r\n /**\r\n * Get essential infos about a given odata type from the version specific service variants.\r\n *\r\n * @param type\r\n * @return tuple of return type, query object, query collection object\r\n */\r\n protected abstract mapODataType(type: string): TypeModel;\r\n\r\n public async digest(): Promise<DataModel> {\r\n this.digestEntityTypesAndOperations();\r\n\r\n // delegate to version specific entity container digestion\r\n this.schemas.forEach((schema) => this.digestEntityContainer(schema));\r\n\r\n return this.dataModel;\r\n }\r\n\r\n private digestEntityTypesAndOperations() {\r\n this.schemas.forEach((schema) => {\r\n const ns: NamespaceWithAlias = [schema.$.Namespace, schema.$.Alias];\r\n\r\n // type definitions: alias for primitive types\r\n this.addTypeDefinition(schema.$.Namespace, schema.TypeDefinition);\r\n\r\n // enums\r\n if (schema.EnumType) {\r\n for (const et of schema.EnumType) {\r\n const odataName = et.$.Name;\r\n const fqName = withNamespace(ns[0], odataName);\r\n this.dataModel.addEnum(ns[0], odataName, {\r\n fqName,\r\n odataName,\r\n name: this.namingHelper.getEnumName(odataName),\r\n members: et.Member.map((m) => m.$.Name),\r\n });\r\n }\r\n }\r\n\r\n // complex types\r\n this.addComplexType(ns, schema.ComplexType);\r\n\r\n // entity types\r\n this.addEntityType(ns, schema.EntityType);\r\n\r\n // V4 only: function & action types\r\n this.digestOperations(schema);\r\n });\r\n\r\n this.postProcessModel();\r\n }\r\n\r\n private getBaseModel(namespace: NamespaceWithAlias, model: ComplexType) {\r\n const odataName = model.$.Name;\r\n const fqName = withNamespace(namespace[0], odataName);\r\n\r\n const entityConfig = this.serviceConfigHelper.findEntityConfigByName(namespace, odataName);\r\n const entityName = entityConfig?.mappedName || model.$.Name;\r\n\r\n // map properties respecting the config\r\n const props = [...(model.Property ?? []), ...this.getNavigationProps(model)].map((p) => {\r\n const epConfig = entityConfig?.properties?.find((ep) => ep.name === p.$.Name);\r\n return this.mapProp(p, epConfig);\r\n });\r\n\r\n // support for base types, i.e. extends clause of interfaces\r\n const baseClasses = [];\r\n if (model.$.BaseType) {\r\n baseClasses.push(model.$.BaseType);\r\n }\r\n\r\n return {\r\n fqName,\r\n odataName,\r\n name: this.namingHelper.getModelName(entityName),\r\n qName: this.namingHelper.getQName(entityName),\r\n editableName: this.namingHelper.getEditableModelName(entityName),\r\n baseClasses,\r\n props,\r\n baseProps: [], // postprocess required\r\n };\r\n }\r\n\r\n private addTypeDefinition(ns: string, types: Array<TypeDefinition> | undefined) {\r\n if (!types || !types.length) {\r\n return;\r\n }\r\n\r\n for (const t of types) {\r\n this.dataModel.addTypeDefinition(ns, t.$.Name, t.$.UnderlyingType);\r\n }\r\n }\r\n\r\n private addComplexType(namespace: NamespaceWithAlias, models: Array<ComplexType> | undefined) {\r\n if (!models || !models.length) {\r\n return;\r\n }\r\n\r\n for (const model of models) {\r\n const baseModel = this.getBaseModel(namespace, model);\r\n this.dataModel.addComplexType(namespace[0], baseModel.odataName, baseModel);\r\n }\r\n }\r\n\r\n private addEntityType(namespace: NamespaceWithAlias, models: Array<ET> | undefined) {\r\n if (!models || !models.length) {\r\n return;\r\n }\r\n\r\n for (const model of models) {\r\n const baseModel = this.getBaseModel(namespace, model);\r\n const entityConfig = this.serviceConfigHelper.findEntityConfigByName(namespace, model.$.Name);\r\n const entityName = entityConfig?.mappedName || model.$.Name;\r\n\r\n // key support: we add keys from this entity,\r\n // but not keys stemming from base classes (postprocess required)\r\n const keyNames: Array<string> = [];\r\n if (entityConfig?.keys?.length) {\r\n keyNames.push(...entityConfig.keys);\r\n } else {\r\n const entity = model as EntityType;\r\n if (entity.Key && entity.Key.length && entity.Key[0].PropertyRef.length) {\r\n const propNames = entity.Key[0].PropertyRef.map((key) => key.$.Name);\r\n keyNames.push(...propNames);\r\n }\r\n }\r\n\r\n this.dataModel.addEntityType(namespace[0], baseModel.odataName, {\r\n ...baseModel,\r\n idModelName: this.namingHelper.getIdModelName(entityName),\r\n qIdFunctionName: this.namingHelper.getQIdFunctionName(entityName),\r\n generateId: true,\r\n keyNames: keyNames, // postprocess required to include key specs from base classes\r\n keys: [], // postprocess required to include props from base classes\r\n getKeyUnion: () => keyNames.join(\" | \"),\r\n });\r\n }\r\n }\r\n\r\n private postProcessModel() {\r\n // complex types\r\n const complexTypes = this.dataModel.getComplexTypes();\r\n complexTypes.forEach((model) => {\r\n const [baseProps] = this.collectBaseClassPropsAndKeys(model, []);\r\n model.baseProps = baseProps;\r\n });\r\n // entity types\r\n const modelTypes = this.dataModel.getEntityTypes();\r\n modelTypes.forEach((model) => {\r\n const [baseProps, baseKeys, idName, qIdName] = this.collectBaseClassPropsAndKeys(model, []);\r\n model.baseProps = baseProps;\r\n\r\n if (!model.keyNames.length && idName) {\r\n model.idModelName = idName;\r\n model.qIdFunctionName = qIdName;\r\n model.generateId = false;\r\n }\r\n model.keyNames.unshift(...baseKeys);\r\n\r\n // sanity check: entity types require key specification\r\n if (!model.keyNames.length) {\r\n throw new Error(`Key property is missing from Entity \"${model.name}\" (${model.odataName})!`);\r\n }\r\n\r\n const isSingleKey = model.keyNames.length === 1;\r\n const props = [...model.baseProps, ...model.props];\r\n model.keys = model.keyNames.map((keyName) => {\r\n const prop = props.find((p) => p.odataName === keyName);\r\n if (!prop) {\r\n throw new Error(`Key with name [${keyName}] not found in props!`);\r\n }\r\n // automatically set key prop to managed, if this is the only key of the given entity\r\n if (prop.managed === undefined) {\r\n prop.managed = !this.options.disableAutoManagedKey && isSingleKey;\r\n }\r\n return prop;\r\n });\r\n });\r\n }\r\n\r\n private collectBaseClassPropsAndKeys(\r\n model: ComplexModelType,\r\n visitedModels: string[]\r\n ): [Array<PropertyModel>, Array<string>, string, string] {\r\n if (visitedModels.includes(model.fqName)) {\r\n throw new Error(`Cyclic inheritance detected for model ${model.fqName}!`);\r\n }\r\n visitedModels.push(model.fqName);\r\n return model.baseClasses.reduce(\r\n ([props, keys, idName, qIdName], bc) => {\r\n const baseModel = this.dataModel.getEntityType(bc) || this.dataModel.getComplexType(bc);\r\n if (!baseModel) {\r\n throw new Error(`BaseModel \"${bc}\" doesn't exist!`);\r\n }\r\n\r\n let idNameResult = idName;\r\n let qIdNameResult = qIdName;\r\n\r\n // recursive\r\n if (baseModel.baseClasses.length) {\r\n const [parentProps, parentKeys, parentIdName, parentQIdName] = this.collectBaseClassPropsAndKeys(\r\n baseModel,\r\n visitedModels\r\n );\r\n props.unshift(...parentProps);\r\n keys.unshift(...parentKeys);\r\n if (parentIdName) {\r\n idNameResult = parentIdName;\r\n qIdNameResult = parentQIdName;\r\n }\r\n }\r\n\r\n props.push(...baseModel.props);\r\n const entityModel = baseModel as ModelType;\r\n if (entityModel.keyNames?.length) {\r\n keys.push(...entityModel.keyNames.filter((kn) => !keys.includes(kn)));\r\n idNameResult = entityModel.idModelName;\r\n qIdNameResult = entityModel.qIdFunctionName;\r\n }\r\n return [props, keys, idNameResult, qIdNameResult];\r\n },\r\n [[], [], \"\", \"\"] as [Array<PropertyModel>, Array<string>, string, string]\r\n );\r\n }\r\n\r\n protected mapProp = (p: Property, entityPropConfig?: PropertyGenerationOptions | undefined): PropertyModel => {\r\n if (!p.$.Type) {\r\n throw new Error(`No type information given for property [${p.$.Name}]!`);\r\n }\r\n\r\n const configProp = this.serviceConfigHelper.findPropConfigByName(p.$.Name);\r\n const name = this.namingHelper.getModelPropName(entityPropConfig?.mappedName || configProp?.mappedName || p.$.Name);\r\n const isCollection = !!p.$.Type.match(/^Collection\\(/);\r\n let dataType = p.$.Type.replace(/^Collection\\(([^\\)]+)\\)/, \"$1\");\r\n\r\n // support for primitive type mapping\r\n if (this.namingHelper.includesServicePrefix(dataType)) {\r\n const dt = this.dataModel.getPrimitiveType(dataType);\r\n if (dt !== undefined) {\r\n dataType = dt;\r\n }\r\n }\r\n\r\n let result: Pick<PropertyModel, \"dataType\" | \"type\" | \"typeModule\" | \"qPath\" | \"qParam\" | \"qObject\" | \"converters\">;\r\n\r\n // domain object known from service:\r\n // EntityType, ComplexType, EnumType\r\n if (this.namingHelper.includesServicePrefix(dataType)) {\r\n const resultDt = this.model2Type.get(dataType)!;\r\n if (!resultDt) {\r\n throw new Error(\r\n `Couldn't determine model data type for property \"${p.$.Name}\"! Given data type: \"${dataType}\".`\r\n );\r\n }\r\n\r\n // special handling for enums\r\n if (resultDt === DataTypes.EnumType) {\r\n result = {\r\n dataType: resultDt,\r\n type: this.namingHelper.getEnumName(dataType),\r\n qPath: \"QEnumPath\",\r\n qObject: isCollection ? \"QEnumCollection\" : undefined,\r\n qParam: \"QEnumParam\",\r\n };\r\n }\r\n // handling of complex & entity types\r\n else {\r\n result = {\r\n dataType: resultDt,\r\n type: this.namingHelper.getModelName(dataType),\r\n qPath: \"QEntityPath\",\r\n qObject: this.namingHelper.getQName(dataType),\r\n qParam: \"QComplexParam\",\r\n };\r\n }\r\n }\r\n // OData built-in data types\r\n else if (dataType.startsWith(Digester.EDM_PREFIX)) {\r\n const { outputType, qPath, qParam, qCollection } = this.mapODataType(dataType);\r\n const { to, toModule: typeModule, converters } = this.dataModel.getConverter(dataType) || {};\r\n\r\n const type = !to ? outputType : to.startsWith(Digester.EDM_PREFIX) ? this.mapODataType(to).outputType : to;\r\n\r\n result = {\r\n dataType: DataTypes.PrimitiveType,\r\n type,\r\n typeModule,\r\n qPath,\r\n qParam,\r\n qObject: isCollection ? qCollection : undefined,\r\n converters,\r\n };\r\n } else {\r\n throw new Error(\r\n `Unknown type [${dataType}]: Not 'Collection(...)', not OData type 'Edm.*', not starting with one of the namespaces!W`\r\n );\r\n }\r\n\r\n return {\r\n odataName: p.$.Name,\r\n name,\r\n odataType: p.$.Type,\r\n fqType: dataType,\r\n required: p.$.Nullable === \"false\",\r\n isCollection: isCollection,\r\n managed: typeof entityPropConfig?.managed !== \"undefined\" ? entityPropConfig.managed : configProp?.managed,\r\n ...result,\r\n };\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"DataModelDigestion.js","sourceRoot":"","sources":["../../src/data-model/DataModelDigestion.ts"],"names":[],"mappings":";;;;AAIA,2CAA2E;AAM3E,+DAAyE;AACzE,8DAA2D;AAI3D,SAAS,MAAM,CAAC,KAAyB;IACvC,OAAO,KAAK,KAAK,MAAM,CAAC;AAC1B,CAAC;AAED,SAAS,OAAO,CAAC,KAAyB;IACxC,OAAO,KAAK,KAAK,OAAO,CAAC;AAC3B,CAAC;AASD,MAAsB,QAAQ;IAS5B,YACY,OAAqB,EACrB,OAAiB,EACjB,OAAyB,EACzB,YAA0B,EACpC,UAAkC;QAJxB,YAAO,GAAP,OAAO,CAAc;QACrB,YAAO,GAAP,OAAO,CAAU;QACjB,YAAO,GAAP,OAAO,CAAkB;QACzB,iBAAY,GAAZ,YAAY,CAAc;QAN9B,eAAU,GAAG,IAAI,GAAG,EAAqB,CAAC;QAmTxC,YAAO,GAAG,CAAC,CAAW,EAAE,gBAAwD,EAAiB,EAAE;;YAC3G,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;gBACb,MAAM,IAAI,KAA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KAAK,EAAE,CAAmB,CACrE,CAAC;IACJ,CAAC;;AAxTH,4BAsZC;AArZkB,mBAAU,GAAG,MAAM,AAAT,CAAU","sourcesContent":["import { MappedConverterChains } from \"@odata2ts/converter-runtime\";\n\nimport { DigestionOptions } from \"../FactoryFunctionModel\";\nimport { ComplexTypeGenerationOptions, EntityTypeGenerationOptions, PropertyGenerationOptions } from \"../OptionModel\";\nimport { DataModel, NamespaceWithAlias, withNamespace } from \"./DataModel\";\nimport { ComplexType as ComplexModelType, DataTypes, ModelType, ODataVersion, PropertyModel } from \"./DataTypeModel\";\nimport { ComplexType, EntityType, EnumType, Property, Schema, TypeDefinition } from \"./edmx/ODataEdmxModelBase\";\nimport { SchemaV3 } from \"./edmx/ODataEdmxModelV3\";\nimport { SchemaV4 } from \"./edmx/ODataEdmxModelV4\";\nimport { NamingHelper } from \"./NamingHelper\";\nimport { ServiceConfigHelper, WithoutName } from \"./ServiceConfigHelper\";\nimport { NameValidator } from \"./validation/NameValidator\";\n\ntype CollectorTuple = [Array<PropertyModel>, Array<string>, { idName: string; qIdName: string; open: boolean }];\n\nfunction ifTrue(value: string | undefined): boolean {\n return value === \"true\";\n}\n\nfunction ifFalse(value: string | undefined): boolean {\n return value === \"false\";\n}\n\nexport interface TypeModel {\n outputType: string;\n qPath: string;\n qCollection: string;\n qParam: string | undefined;\n}\n\nexport abstract class Digester<S extends Schema<ET, CT>, ET extends EntityType, CT extends ComplexType> {\n protected static EDM_PREFIX = \"Edm.\";\n\n protected readonly dataModel: DataModel;\n protected readonly serviceConfigHelper: ServiceConfigHelper;\n protected readonly nameValidator: NameValidator;\n\n private model2Type = new Map<string, DataTypes>();\n\n protected constructor(\n protected version: ODataVersion,\n protected schemas: Array<S>,\n protected options: DigestionOptions,\n protected namingHelper: NamingHelper,\n converters?: MappedConverterChains\n ) {\n const namespaces = schemas.map<NamespaceWithAlias>((s) => [s.$.Namespace, s.$.Alias]);\n this.dataModel = new DataModel(namespaces, version, converters);\n this.serviceConfigHelper = new ServiceConfigHelper(options);\n this.nameValidator = new NameValidator(options);\n\n this.collectModelTypes(schemas);\n }\n\n private collectModelTypes(schemas: Array<S>) {\n schemas.forEach((schema) => {\n const { Namespace: ns, Alias: alias } = schema.$;\n\n schema.EnumType?.forEach((et) => {\n this.addModel2Type(ns, alias, et.$.Name, DataTypes.EnumType);\n });\n schema.ComplexType?.forEach((ct) => {\n this.addModel2Type(ns, alias, ct.$.Name, DataTypes.ComplexType);\n });\n schema.EntityType?.forEach((et) => {\n this.addModel2Type(ns, alias, et.$.Name, DataTypes.ModelType);\n });\n });\n }\n\n private addModel2Type(ns: string, alias: string | undefined, name: string, dt: DataTypes) {\n this.model2Type.set(withNamespace(ns, name), dt);\n if (alias) {\n this.model2Type.set(withNamespace(alias, name), dt);\n }\n }\n\n protected abstract getNavigationProps(entityType: ET | ComplexType): Array<Property>;\n\n protected abstract digestOperations(schema: SchemaV3 | SchemaV4): void;\n\n protected abstract digestEntityContainer(schema: SchemaV3 | SchemaV4): void;\n\n /**\n * Get essential infos about a given odata type from the version specific service variants.\n *\n * @param type\n * @return tuple of return type, query object, query collection object\n */\n protected abstract mapODataType(type: string): TypeModel;\n\n public async digest(): Promise<DataModel> {\n this.digestEntityTypesAndOperations();\n\n // delegate to version specific entity container digestion\n this.schemas.forEach((schema) => this.digestEntityContainer(schema));\n\n this.dataModel.setNameValidation(this.nameValidator.validate());\n return this.dataModel;\n }\n\n private digestEntityTypesAndOperations() {\n this.schemas.forEach((schema) => {\n const ns: NamespaceWithAlias = [schema.$.Namespace, schema.$.Alias];\n\n // type definitions: alias for primitive types\n this.addTypeDefinition(schema.$.Namespace, schema.TypeDefinition);\n\n // enums\n this.addEnum(ns, schema.EnumType);\n\n // complex types\n this.addComplexType(ns, schema.ComplexType);\n\n // entity types\n this.addEntityType(ns, schema.EntityType);\n\n // V4 only: function & action types\n this.digestOperations(schema);\n });\n\n this.postProcessModel();\n this.postProcessKeys();\n }\n\n private getBaseModel(\n entityConfig: WithoutName<EntityTypeGenerationOptions | ComplexTypeGenerationOptions> | undefined,\n model: ComplexType,\n name: string,\n fqName: string\n ) {\n const odataName = model.$.Name;\n\n // map properties respecting the config\n const props = [...(model.Property ?? []), ...this.getNavigationProps(model)].map((p) => {\n const epConfig = entityConfig?.properties?.find((ep) => ep.name === p.$.Name);\n return this.mapProp(p, epConfig);\n });\n\n // support for base types, i.e. extends clause of interfaces\n const baseClasses = [];\n let finalBaseClass: string | undefined = undefined;\n if (model.$.BaseType) {\n baseClasses.push(model.$.BaseType);\n const [baseName, basePrefix] = this.namingHelper.getNameAndServicePrefix(model.$.BaseType);\n const baseConfig =\n this.serviceConfigHelper.findEntityTypeConfig([basePrefix!], baseName) ||\n this.serviceConfigHelper.findComplexTypeConfig([basePrefix!], baseName);\n finalBaseClass = baseConfig?.mappedName ?? baseName;\n }\n\n return {\n fqName,\n odataName,\n name: this.namingHelper.getModelName(name),\n qName: this.namingHelper.getQName(name),\n editableName: this.namingHelper.getEditableModelName(name),\n baseClasses,\n finalBaseClass,\n props,\n baseProps: [], // postprocess required\n abstract: ifTrue(model.$.Abstract),\n open: ifTrue(model.$.OpenType),\n };\n }\n\n private addTypeDefinition(ns: string, types: Array<TypeDefinition> | undefined) {\n if (!types || !types.length) {\n return;\n }\n\n for (const t of types) {\n this.dataModel.addTypeDefinition(ns, t.$.Name, t.$.UnderlyingType);\n }\n }\n\n private addEnum(namespace: NamespaceWithAlias, models: Array<EnumType> | undefined) {\n if (!models || !models.length) {\n return;\n }\n\n for (const et of models) {\n const odataName = et.$.Name;\n const fqName = withNamespace(namespace[0], odataName);\n const config = this.serviceConfigHelper.findEnumTypeConfig(namespace, odataName);\n const enumName = this.nameValidator.addEnumType(fqName, config?.mappedName || odataName);\n\n this.dataModel.addEnum(namespace[0], odataName, {\n fqName,\n odataName,\n name: this.namingHelper.getEnumName(enumName),\n members: et.Member.map((m) => m.$.Name),\n });\n }\n }\n\n private addComplexType(namespace: NamespaceWithAlias, models: Array<ComplexType> | undefined) {\n if (!models || !models.length) {\n return;\n }\n\n for (const model of models) {\n const config = this.serviceConfigHelper.findComplexTypeConfig(namespace, model.$.Name);\n const fqName = withNamespace(namespace[0], model.$.Name);\n const name = this.nameValidator.addComplexType(fqName, config?.mappedName || model.$.Name);\n const baseModel = this.getBaseModel(config, model, name, fqName);\n this.dataModel.addComplexType(namespace[0], baseModel.odataName, baseModel);\n }\n }\n\n private addEntityType(namespace: NamespaceWithAlias, models: Array<ET> | undefined) {\n if (!models || !models.length) {\n return;\n }\n\n for (const model of models) {\n const entityConfig = this.serviceConfigHelper.findEntityTypeConfig(namespace, model.$.Name);\n const fqName = withNamespace(namespace[0], model.$.Name);\n const name = this.nameValidator.addEntityType(fqName, entityConfig?.mappedName || model.$.Name);\n const baseModel = this.getBaseModel(entityConfig, model, name, fqName);\n\n // key support: we add keys from this entity,\n // but not keys stemming from base classes (postprocess required)\n const keyNames: Array<string> = [];\n if (entityConfig?.keys?.length) {\n keyNames.push(...entityConfig.keys);\n } else {\n const entity = model as EntityType;\n if (entity.Key && entity.Key.length && entity.Key[0].PropertyRef.length) {\n const propNames = entity.Key[0].PropertyRef.map((key) => key.$.Name);\n keyNames.push(...propNames);\n }\n }\n\n this.dataModel.addEntityType(namespace[0], baseModel.odataName, {\n ...baseModel,\n idModelName: this.namingHelper.getIdModelName(name),\n qIdFunctionName: this.namingHelper.getQIdFunctionName(name),\n generateId: !!keyNames.length,\n keyNames: keyNames, // postprocess required to include key specs from base classes\n keys: [], // postprocess required to include props from base classes\n getKeyUnion: () => keyNames.join(\" | \"),\n });\n }\n }\n\n private postProcessModel() {\n // complex types\n const complexTypes = this.dataModel.getComplexTypes();\n complexTypes.forEach((ct) => {\n const [baseProps, _, baseAttributes] = this.collectBaseClassPropsAndKeys(ct, []);\n const { open } = baseAttributes;\n ct.baseProps = baseProps.map((bp) => ({ ...bp }));\n if (open) {\n ct.open = true;\n }\n });\n // entity types\n const entityTypes = this.dataModel.getEntityTypes();\n entityTypes.forEach((et) => {\n const [baseProps, baseKeys, baseAttributes] = this.collectBaseClassPropsAndKeys(et, []);\n const { idName, qIdName, open } = baseAttributes;\n et.baseProps = baseProps.map((bp) => ({ ...bp }));\n\n if (!et.keyNames.length && idName) {\n et.idModelName = idName;\n et.qIdFunctionName = qIdName;\n et.generateId = false;\n }\n if (open) {\n et.open = open;\n }\n et.keyNames.unshift(...baseKeys);\n });\n }\n\n private postProcessKeys() {\n const entityTypes = this.dataModel.getEntityTypes();\n entityTypes.forEach((et) => {\n const isSingleKey = et.keyNames.length === 1;\n const props = [...et.baseProps, ...et.props];\n et.keys = et.keyNames.map((keyName) => {\n const prop = props.find((p) => p.odataName === keyName);\n if (!prop) {\n throw new Error(`Key with name [${keyName}] not found in props!`);\n }\n\n // automatically set key prop to managed, if this is the only key of the given entity\n if (prop.managed === undefined) {\n prop.managed = !this.options.disableAutoManagedKey && isSingleKey;\n }\n\n return prop;\n });\n });\n }\n\n private collectBaseClassPropsAndKeys(model: ComplexModelType, visitedModels: string[]): CollectorTuple {\n if (visitedModels.includes(model.fqName)) {\n throw new Error(`Cyclic inheritance detected for model ${model.fqName}!`);\n }\n visitedModels.push(model.fqName);\n return model.baseClasses.reduce(\n ([props, keys, attributes], bc) => {\n const baseModel = this.dataModel.getEntityType(bc) || this.dataModel.getComplexType(bc);\n if (!baseModel) {\n throw new Error(`BaseModel \"${bc}\" doesn't exist!`);\n }\n\n let { idName, qIdName, open } = attributes;\n\n // recursive\n if (baseModel.baseClasses.length) {\n const [parentProps, parentKeys, parentAttributes] = this.collectBaseClassPropsAndKeys(\n baseModel,\n visitedModels\n );\n props.unshift(...parentProps);\n keys.unshift(...parentKeys);\n if (parentAttributes?.idName) {\n idName = parentAttributes.idName;\n qIdName = parentAttributes.qIdName;\n }\n if (parentAttributes?.open) {\n open = true;\n }\n }\n\n props.push(...baseModel.props);\n const entityModel = baseModel as ModelType;\n if (entityModel.keyNames?.length) {\n keys.push(...entityModel.keyNames.filter((kn) => !keys.includes(kn)));\n idName = entityModel.idModelName;\n qIdName = entityModel.qIdFunctionName;\n }\n if (baseModel.open) {\n open = true;\n }\n return [props, keys, { idName, qIdName, open }];\n },\n [[], [], { idName: \"\", qIdName: \"\", open: false }] as CollectorTuple\n );\n }\n\n protected mapProp = (p: Property, entityPropConfig?: PropertyGenerationOptions | undefined): PropertyModel => {\n if (!p.$.Type) {\n throw new Error(`No type information given for property [${p.$.Name}]!`);\n }\n\n const configProp = this.serviceConfigHelper.findPropConfigByName(p.$.Name);\n const name = this.namingHelper.getModelPropName(entityPropConfig?.mappedName || configProp?.mappedName || p.$.Name);\n const isCollection = !!p.$.Type.match(/^Collection\\(/);\n let dataType = p.$.Type.replace(/^Collection\\(([^\\)]+)\\)/, \"$1\");\n\n // support for primitive type mapping\n if (this.namingHelper.includesServicePrefix(dataType)) {\n const dt = this.dataModel.getPrimitiveType(dataType);\n if (dt !== undefined) {\n dataType = dt;\n }\n }\n\n let result: Pick<PropertyModel, \"dataType\" | \"type\" | \"typeModule\" | \"qPath\" | \"qParam\" | \"qObject\" | \"converters\">;\n\n // domain object known from service:\n // EntityType, ComplexType, EnumType\n if (this.namingHelper.includesServicePrefix(dataType)) {\n const resultDt = this.model2Type.get(dataType)!;\n const [dataTypeName, dataTypePrefix] = this.namingHelper.getNameAndServicePrefix(dataType);\n const dataTypeNamespace: NamespaceWithAlias = [dataTypePrefix!];\n if (!resultDt) {\n throw new Error(\n `Couldn't determine model data type for property \"${p.$.Name}\"! Given data type: \"${dataType}\".`\n );\n }\n\n // special handling for enums\n if (resultDt === DataTypes.EnumType) {\n const enumConfig = this.serviceConfigHelper.findEnumTypeConfig(dataTypeNamespace, dataTypeName);\n result = {\n dataType: resultDt,\n type: this.namingHelper.getEnumName(enumConfig?.mappedName ?? dataType),\n qPath: \"QEnumPath\",\n qObject: isCollection ? \"QEnumCollection\" : undefined,\n qParam: \"QEnumParam\",\n };\n }\n // handling of complex & entity types\n else {\n const entityConfig =\n resultDt === DataTypes.ComplexType\n ? this.serviceConfigHelper.findComplexTypeConfig(dataTypeNamespace, dataTypeName)\n : this.serviceConfigHelper.findEntityTypeConfig(dataTypeNamespace, dataTypeName);\n const resultDataType = entityConfig?.mappedName ?? dataType;\n result = {\n dataType: resultDt,\n type: this.namingHelper.getModelName(resultDataType),\n qPath: \"QEntityPath\",\n qObject: this.namingHelper.getQName(resultDataType),\n qParam: \"QComplexParam\",\n };\n }\n }\n // OData built-in data types\n else if (dataType.startsWith(Digester.EDM_PREFIX)) {\n const { outputType, qPath, qParam, qCollection } = this.mapODataType(dataType);\n const { to, toModule: typeModule, converters } = this.dataModel.getConverter(dataType) || {};\n\n const type = !to ? outputType : to.startsWith(Digester.EDM_PREFIX) ? this.mapODataType(to).outputType : to;\n\n result = {\n dataType: DataTypes.PrimitiveType,\n type,\n typeModule,\n qPath,\n qParam,\n qObject: isCollection ? qCollection : undefined,\n converters,\n };\n } else {\n throw new Error(\n `Unknown type [${dataType}]: Not 'Collection(...)', not OData type 'Edm.*', not starting with one of the namespaces!W`\n );\n }\n\n return {\n odataName: p.$.Name,\n name,\n odataType: p.$.Type,\n fqType: dataType,\n required: ifFalse(p.$.Nullable),\n isCollection: isCollection,\n managed: typeof entityPropConfig?.managed !== \"undefined\" ? entityPropConfig.managed : configProp?.managed,\n ...result,\n };\n };\n}\n"]}
@@ -61,16 +61,15 @@ class DigesterV3 extends DataModelDigestion_1.Digester {
61
61
  digestOperations(schema) { }
62
62
  digestEntityContainer(schema) {
63
63
  var _a, _b;
64
- const namespace = schema.$.Namespace;
65
- const alias = schema.$.Alias;
66
64
  if (schema.EntityContainer && schema.EntityContainer.length) {
67
65
  const container = schema.EntityContainer[0];
66
+ const ecName = container.$.Name;
68
67
  (_a = container.FunctionImport) === null || _a === void 0 ? void 0 : _a.forEach((funcImport) => {
69
68
  var _a, _b, _c, _d;
70
69
  const odataName = funcImport.$.Name;
71
- const fqName = (0, DataModel_1.withNamespace)(namespace, odataName);
72
- const opConfig = this.serviceConfigHelper.findOperationConfigByName([namespace, alias], odataName);
73
- const opName = (opConfig === null || opConfig === void 0 ? void 0 : opConfig.mappedName) || odataName;
70
+ const fqName = (0, DataModel_1.withNamespace)(ecName, odataName);
71
+ const opConfig = this.serviceConfigHelper.findOperationImportConfig(ecName, odataName);
72
+ const opName = this.nameValidator.addOperationImportType(fqName, (opConfig === null || opConfig === void 0 ? void 0 : opConfig.mappedName) || odataName);
74
73
  const name = this.namingHelper.getFunctionName(opName);
75
74
  const usePost = ((_a = funcImport.$["m:HttpMethod"]) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === "POST";
76
75
  const parameters = (_c = (_b = funcImport.Parameter) === null || _b === void 0 ? void 0 : _b.map((p) => this.mapProp(p))) !== null && _c !== void 0 ? _c : [];
@@ -83,7 +82,7 @@ class DigesterV3 extends DataModelDigestion_1.Digester {
83
82
  : undefined;
84
83
  // V2 only knows the FunctionImport element
85
84
  // we generate the data structure for the function here
86
- this.dataModel.addUnboundOperationType(namespace, {
85
+ this.dataModel.addUnboundOperationType(ecName, {
87
86
  fqName,
88
87
  odataName,
89
88
  name,
@@ -103,15 +102,17 @@ class DigesterV3 extends DataModelDigestion_1.Digester {
103
102
  });
104
103
  });
105
104
  (_b = container.EntitySet) === null || _b === void 0 ? void 0 : _b.forEach((entitySet) => {
106
- const name = entitySet.$.Name;
107
- const fqName = (0, DataModel_1.withNamespace)(namespace, name);
105
+ const odataName = entitySet.$.Name;
106
+ const fqName = (0, DataModel_1.withNamespace)(ecName, odataName);
107
+ const config = this.serviceConfigHelper.findEntitySetConfig(ecName, odataName);
108
+ const name = this.nameValidator.addEntitySet(fqName, (config === null || config === void 0 ? void 0 : config.mappedName) || odataName);
108
109
  const entityType = this.dataModel.getEntityType(entitySet.$.EntityType);
109
110
  if (!entityType) {
110
111
  throw new Error(`Entity type "${entitySet.$.EntityType}" not found!`);
111
112
  }
112
113
  this.dataModel.addEntitySet(fqName, {
113
114
  fqName,
114
- odataName: name,
115
+ odataName,
115
116
  name,
116
117
  entityType,
117
118
  });