@odata2ts/odata2ts 0.31.1 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/lib/FactoryFunctionModel.d.ts +1 -1
- package/lib/FactoryFunctionModel.js.map +1 -1
- package/lib/OptionModel.d.ts +46 -61
- package/lib/OptionModel.js.map +1 -1
- package/lib/TypeModel.d.ts +10 -0
- package/lib/TypeModel.js +17 -0
- package/lib/TypeModel.js.map +1 -0
- package/lib/app.js +13 -0
- package/lib/app.js.map +1 -1
- package/lib/cli.js +1 -1
- package/lib/cli.js.map +1 -1
- package/lib/data-model/DataModel.d.ts +8 -4
- package/lib/data-model/DataModel.js +14 -8
- package/lib/data-model/DataModel.js.map +1 -1
- package/lib/data-model/DataModelDigestion.d.ts +3 -0
- package/lib/data-model/DataModelDigestion.js +69 -45
- package/lib/data-model/DataModelDigestion.js.map +1 -1
- package/lib/data-model/DataModelDigestionV2.js +10 -9
- package/lib/data-model/DataModelDigestionV2.js.map +1 -1
- package/lib/data-model/DataModelDigestionV4.js +31 -17
- package/lib/data-model/DataModelDigestionV4.js.map +1 -1
- package/lib/data-model/DataTypeModel.d.ts +1 -0
- package/lib/data-model/DataTypeModel.js.map +1 -1
- package/lib/data-model/NamingHelper.d.ts +1 -0
- package/lib/data-model/NamingHelper.js +5 -0
- package/lib/data-model/NamingHelper.js.map +1 -1
- package/lib/data-model/ServiceConfigHelper.d.ts +14 -17
- package/lib/data-model/ServiceConfigHelper.js +58 -72
- package/lib/data-model/ServiceConfigHelper.js.map +1 -1
- package/lib/data-model/validation/NameValidator.d.ts +28 -0
- package/lib/data-model/validation/NameValidator.js +80 -0
- package/lib/data-model/validation/NameValidator.js.map +1 -0
- package/lib/defaultConfig.js +2 -2
- package/lib/defaultConfig.js.map +1 -1
- package/lib/generator/ModelGenerator.js +1 -1
- package/lib/generator/ModelGenerator.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceConfigHelper.js","sourceRoot":"","sources":["../../src/data-model/ServiceConfigHelper.ts"],"names":[],"mappings":";;;;AAEA,2CAAgE;AAMhE,MAAM,iBAAiB,GAAG,mDAAmD,CAAC;AAC9E,MAAM,yBAAyB,GAC7B,wFAAwF,CAAC;AAE3F,MAAa,mBAAmB;IAQ9B,YAAY,OAAyB;QAP7B,gBAAW,GAAG,IAAI,GAAG,EAAqC,CAAC;QAC3D,kBAAa,GAAG,IAAI,GAAG,EAAmC,CAAC;QAC3D,qBAAgB,GAAG,IAAI,GAAG,EAAsC,CAAC;QACjE,gBAAW,GAA+C,EAAE,CAAC;QAC7D,kBAAa,GAA6C,EAAE,CAAC;QAC7D,qBAAgB,GAAgD,EAAE,CAAC;QAuDpE,yBAAoB,GAAG,CAAC,IAAY,EAA8B,EAAE;YACzE,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAE1C,OAAO,UAAU,IAAI,MAAM,CAAC,CAAC,iCAAM,MAAM,GAAK,UAAU,EAAG,CAAC,CAAC,UAAU,IAAI,MAAM,CAAC;QACpF,CAAC,CAAC;QAwDK,2BAAsB,GAAG,CAAC,SAA6B,EAAE,IAAY,EAAgC,EAAE;YAC5G,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YACxD,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YAEtD,OAAO,SAAS,IAAI,KAAK,CAAC,CAAC,iCAAM,KAAK,GAAK,SAAS,EAAG,CAAC,CAAC,SAAS,IAAI,KAAK,CAAC;QAC9E,CAAC,CAAC;QA2DK,8BAAyB,GAA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C;QACxC,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB;aACrC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;aACzC,GAAG,CAAC,CAAC,EAAwC,EAAE,EAAE;gBAA5C,CAAC,MAAM,UAAiC,EAA/B,EAAE,IAAI,EAAE,UAAU,OAAY,EAAP,KAAK,sBAA5B,sBAA8B,CAAF;YAAQ,OAAA,iBACjD,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,IACpE,KAAK,EACR,CAAA;SAAA,CAAC,CAAC;QAEN,OAAO,CAAC,UAAU,CAAC,MAAM;YACvB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,UAAU,CAAC,MAAM,CAAmB,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;gBACnD,uCAAY,MAAM,GAAK,IAAI,EAAG;YAChC,CAAC,EAAE,EAAE,CAAC,CAAC;IACb,CAAC;CAQF;AAhMD,kDAgMC","sourcesContent":["import { DigestionOptions } from \"../FactoryFunctionModel\";\r\nimport { EntityGenerationOptions, OperationGenerationOptions, PropertyGenerationOptions } from \"../OptionModel\";\r\nimport { NamespaceWithAlias, withNamespace } from \"./DataModel\";\r\n\r\nexport interface ConfiguredProp extends Omit<PropertyGenerationOptions, \"name\"> {}\r\nexport interface ConfiguredEntity extends Omit<EntityGenerationOptions, \"name\"> {}\r\nexport interface ConfiguredOperation extends Omit<OperationGenerationOptions, \"name\"> {}\r\n\r\nconst EXCEPTION_NO_NAME = \"No value for required attribute [name] specified!\";\r\nconst EXCEPTION_WRONG_NAME_TYPE =\r\n \"Wrong type for attribute [name]! You have to supply either a plain string or a RegExp.\";\r\n\r\nexport class ServiceConfigHelper {\r\n private propMapping = new Map<string, PropertyGenerationOptions>();\r\n private entityMapping = new Map<string, EntityGenerationOptions>();\r\n private operationMapping = new Map<string, OperationGenerationOptions>();\r\n private propRegExps: Array<[RegExp, PropertyGenerationOptions]> = [];\r\n private entityRegExps: Array<[RegExp, EntityGenerationOptions]> = [];\r\n private operationRegExps: Array<[RegExp, OperationGenerationOptions]> = [];\r\n\r\n constructor(options: DigestionOptions) {\r\n this.evaluateProps(options);\r\n this.evaluateEntities(options);\r\n this.evaluateOperations(options);\r\n }\r\n\r\n private evaluateProps(options: DigestionOptions) {\r\n options.propertiesByName.forEach((prop) => {\r\n if (!prop.name) {\r\n throw new Error(EXCEPTION_NO_NAME);\r\n }\r\n switch (typeof prop.name) {\r\n case \"string\":\r\n // TODO: check for existing prop.name and throw?\r\n this.propMapping.set(prop.name, prop);\r\n break;\r\n case \"object\":\r\n const { source, ignoreCase } = prop.name as RegExp;\r\n if (!source) {\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n this.propRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), prop]);\r\n break;\r\n default:\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n });\r\n }\r\n\r\n private getPropByName(nameToMap: string): ConfiguredProp | undefined {\r\n const stringProp = this.propMapping.get(nameToMap);\r\n if (!stringProp) {\r\n return;\r\n }\r\n const { name, ...attrs } = stringProp;\r\n return { ...attrs };\r\n }\r\n\r\n private getPropByRegExp(nameToMap: string): ConfiguredProp | undefined {\r\n const resultList = this.propRegExps\r\n .filter(([regExp]) => regExp.test(nameToMap))\r\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\r\n mappedName: mappedName ? nameToMap.replace(regExp, mappedName) : undefined,\r\n ...attrs,\r\n }));\r\n\r\n return !resultList.length\r\n ? undefined\r\n : resultList.reduce<ConfiguredProp>((result, prop) => {\r\n return { ...result, ...prop };\r\n }, {});\r\n }\r\n\r\n public findPropConfigByName = (name: string): ConfiguredProp | undefined => {\r\n const stringProp = this.getPropByName(name);\r\n const reProp = this.getPropByRegExp(name);\r\n\r\n return stringProp && reProp ? { ...reProp, ...stringProp } : stringProp || reProp;\r\n };\r\n\r\n private evaluateEntities(options: DigestionOptions) {\r\n options.entitiesByName.forEach((ent) => {\r\n if (!ent.name) {\r\n throw new Error(EXCEPTION_NO_NAME);\r\n }\r\n switch (typeof ent.name) {\r\n case \"string\":\r\n // TODO: check for existing prop.name and throw?\r\n this.entityMapping.set(ent.name, ent);\r\n break;\r\n case \"object\":\r\n const { source, ignoreCase } = ent.name as RegExp;\r\n if (!source) {\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n this.entityRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), ent]);\r\n break;\r\n default:\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n });\r\n }\r\n\r\n // get entity config by name matching: simple name or fully qualified name (alias also supported)\r\n private getEntityByName(namespace: NamespaceWithAlias, nameToMap: string): ConfiguredEntity | undefined {\r\n const [ns, alias] = namespace;\r\n\r\n const config =\r\n this.entityMapping.get(withNamespace(ns, nameToMap)) ||\r\n (alias ? this.entityMapping.get(withNamespace(alias, nameToMap)) : undefined) ||\r\n this.entityMapping.get(nameToMap);\r\n if (!config) {\r\n return;\r\n }\r\n const { name, ...attrs } = config;\r\n return { ...attrs };\r\n }\r\n\r\n private getEntityByRegExp([mainNs, alias]: NamespaceWithAlias, nameToMap: string): ConfiguredEntity | undefined {\r\n const fqName = `${mainNs}.${nameToMap}`;\r\n const resultList = this.entityRegExps\r\n .filter(([regExp]) => regExp.test(fqName))\r\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\r\n mappedName: mappedName ? fqName.replace(regExp, mappedName) : undefined,\r\n ...attrs,\r\n }));\r\n\r\n return !resultList.length\r\n ? undefined\r\n : resultList.reduce<ConfiguredEntity>((result, prop) => {\r\n return { ...result, ...prop };\r\n }, {});\r\n }\r\n\r\n public findEntityConfigByName = (namespace: NamespaceWithAlias, name: string): ConfiguredEntity | undefined => {\r\n const stringEnt = this.getEntityByName(namespace, name);\r\n const reEnt = this.getEntityByRegExp(namespace, name);\r\n\r\n return stringEnt && reEnt ? { ...reEnt, ...stringEnt } : stringEnt || reEnt;\r\n };\r\n\r\n private evaluateOperations(options: DigestionOptions) {\r\n options.operationsByName.forEach((op) => {\r\n if (!op.name) {\r\n throw new Error(EXCEPTION_NO_NAME);\r\n }\r\n switch (typeof op.name) {\r\n case \"string\":\r\n // TODO: check for existing operation name and throw?\r\n this.operationMapping.set(op.name, op);\r\n break;\r\n case \"object\":\r\n const { source, ignoreCase } = op.name as RegExp;\r\n if (!source) {\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n this.operationRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), op]);\r\n break;\r\n default:\r\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\r\n }\r\n });\r\n }\r\n\r\n // get entity config by name matching: simple name or fully qualified name (alias also supported)\r\n private getOperationByName(namespace: NamespaceWithAlias, nameToMap: string): ConfiguredOperation | undefined {\r\n const [ns, alias] = namespace;\r\n\r\n const config =\r\n this.operationMapping.get(withNamespace(ns, nameToMap)) ||\r\n (alias ? this.operationMapping.get(withNamespace(alias, nameToMap)) : undefined) ||\r\n this.operationMapping.get(nameToMap);\r\n if (!config) {\r\n return;\r\n }\r\n const { name, ...attrs } = config;\r\n return { ...attrs };\r\n }\r\n\r\n private getOperationByRegExp(\r\n [mainNs, alias]: NamespaceWithAlias,\r\n nameToMap: string\r\n ): ConfiguredOperation | undefined {\r\n const fqName = `${mainNs}.${nameToMap}`;\r\n const resultList = this.operationRegExps\r\n .filter(([regExp]) => regExp.test(fqName))\r\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\r\n mappedName: mappedName ? fqName.replace(regExp, mappedName) : undefined,\r\n ...attrs,\r\n }));\r\n\r\n return !resultList.length\r\n ? undefined\r\n : resultList.reduce<ConfiguredEntity>((result, prop) => {\r\n return { ...result, ...prop };\r\n }, {});\r\n }\r\n\r\n public findOperationConfigByName = (namespace: NamespaceWithAlias, name: string): ConfiguredOperation | undefined => {\r\n const stringEnt = this.getOperationByName(namespace, name);\r\n const reEnt = this.getOperationByRegExp(namespace, name);\r\n\r\n return stringEnt && reEnt ? { ...reEnt, ...stringEnt } : stringEnt || reEnt;\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ServiceConfigHelper.js","sourceRoot":"","sources":["../../src/data-model/ServiceConfigHelper.ts"],"names":[],"mappings":";;;;AAQA,4CAAyC;AACzC,2CAAgE;AAMhE,MAAM,iBAAiB,GAAG,mDAAmD,CAAC;AAC9E,MAAM,yBAAyB,GAC7B,wFAAwF,CAAC;AAO3F,SAAS,aAAa;IACpB,OAAO;QACL,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,EAAE;KACZ,CAAC;AACJ,CAAC;AAED,MAAa,mBAAmB;IAc9B,YAAY,OAAyB;QAb7B,gBAAW,GAAG,IAAI,GAAG,EAAqC,CAAC;QAC3D,gBAAW,GAA+C,EAAE,CAAC;QAC7D,YAAO,GAAG;YAChB,CAAC,qBAAS,CAAC,GAAG,CAAC,EAAE,aAAa,EAAgC;YAC9D,CAAC,qBAAS,CAAC,UAAU,CAAC,EAAE,aAAa,EAA+B;YACpE,CAAC,qBAAS,CAAC,WAAW,CAAC,EAAE,aAAa,EAAgC;YACtE,CAAC,qBAAS,CAAC,QAAQ,CAAC,EAAE,aAAa,EAAgC;YACnE,CAAC,qBAAS,CAAC,aAAa,CAAC,EAAE,aAAa,EAAgC;YACxE,CAAC,qBAAS,CAAC,mBAAmB,CAAC,EAAE,aAAa,EAAgC;YAC9E,CAAC,qBAAS,CAAC,SAAS,CAAC,EAAE,aAAa,EAAgC;YACpE,CAAC,qBAAS,CAAC,SAAS,CAAC,EAAE,aAAa,EAAgC;SACrE,CAAC;QAsDK,yBAAoB,GAAG,CAAC,IAAY,EAA8B,EAAE;YACzE,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,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,EAAE,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC;CACF;AA/LD,kDA+LC","sourcesContent":["import { DigestionOptions } from \"../FactoryFunctionModel\";\nimport {\n ComplexTypeGenerationOptions,\n EntityTypeGenerationOptions,\n GenericTypeGenerationOptions,\n PropertyGenerationOptions,\n TypeBasedGenerationOptions,\n} from \"../OptionModel\";\nimport { TypeModel } from \"../TypeModel\";\nimport { NamespaceWithAlias, withNamespace } from \"./DataModel\";\n\nexport type WithoutName<T> = Omit<T, \"name\">;\n\nexport interface ConfiguredProp extends WithoutName<PropertyGenerationOptions> {}\n\nconst EXCEPTION_NO_NAME = \"No value for required attribute [name] specified!\";\nconst EXCEPTION_WRONG_NAME_TYPE =\n \"Wrong type for attribute [name]! You have to supply either a plain string or a RegExp.\";\n\ninterface MappingType<T> {\n names: Record<string, T>;\n regExps: Array<[RegExp, GenericTypeGenerationOptions]>;\n}\n\nfunction createMapping<T>(): MappingType<T> {\n return {\n names: {},\n regExps: [],\n };\n}\n\nexport class ServiceConfigHelper {\n private propMapping = new Map<string, PropertyGenerationOptions>();\n private propRegExps: Array<[RegExp, PropertyGenerationOptions]> = [];\n private mapping = {\n [TypeModel.Any]: createMapping<GenericTypeGenerationOptions>(),\n [TypeModel.EntityType]: createMapping<EntityTypeGenerationOptions>(),\n [TypeModel.ComplexType]: createMapping<ComplexTypeGenerationOptions>(),\n [TypeModel.EnumType]: createMapping<GenericTypeGenerationOptions>(),\n [TypeModel.OperationType]: createMapping<GenericTypeGenerationOptions>(),\n [TypeModel.OperationImportType]: createMapping<GenericTypeGenerationOptions>(),\n [TypeModel.EntitySet]: createMapping<GenericTypeGenerationOptions>(),\n [TypeModel.Singleton]: createMapping<GenericTypeGenerationOptions>(),\n };\n\n constructor(options: DigestionOptions) {\n this.evaluateProps(options);\n this.evaluateEntities(options);\n }\n\n private evaluateProps(options: DigestionOptions) {\n options.propertiesByName.forEach((prop) => {\n if (!prop.name) {\n throw new Error(EXCEPTION_NO_NAME);\n }\n switch (typeof prop.name) {\n case \"string\":\n // TODO: check for existing prop.name and throw?\n this.propMapping.set(prop.name, prop);\n break;\n case \"object\":\n const { source, ignoreCase } = prop.name as RegExp;\n if (!source) {\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n this.propRegExps.push([new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\"), prop]);\n break;\n default:\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n });\n }\n\n private getPropByName(nameToMap: string): ConfiguredProp | undefined {\n const stringProp = this.propMapping.get(nameToMap);\n if (!stringProp) {\n return;\n }\n const { name, ...attrs } = stringProp;\n return { ...attrs };\n }\n\n private getPropByRegExp(nameToMap: string): ConfiguredProp | undefined {\n const resultList = this.propRegExps\n .filter(([regExp]) => regExp.test(nameToMap))\n .map(([regExp, { name, mappedName, ...attrs }]) => ({\n mappedName: mappedName ? nameToMap.replace(regExp, mappedName) : undefined,\n ...attrs,\n }));\n\n return !resultList.length\n ? undefined\n : resultList.reduce<ConfiguredProp>((result, prop) => {\n return { ...result, ...prop };\n }, {});\n }\n\n public findPropConfigByName = (name: string): ConfiguredProp | undefined => {\n const stringProp = this.getPropByName(name);\n const reProp = this.getPropByRegExp(name);\n\n return stringProp && reProp ? { ...reProp, ...stringProp } : stringProp || reProp;\n };\n\n private evaluateEntities(options: DigestionOptions) {\n options.byTypeAndName.forEach((ent) => {\n if (!ent.name) {\n throw new Error(EXCEPTION_NO_NAME);\n }\n\n const mapping = this.mapping[ent.type];\n switch (typeof ent.name) {\n case \"string\":\n // TODO: check for existing prop.name and throw?\n mapping.names[ent.name] = ent;\n break;\n case \"object\":\n const { source, ignoreCase } = ent.name as RegExp;\n if (!source) {\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n const regExp = new RegExp(`^${source}$`, ignoreCase ? \"i\" : \"\");\n mapping.regExps.push(\n // @ts-ignore: too generic\n [regExp, ent]\n );\n break;\n default:\n throw new Error(EXCEPTION_WRONG_NAME_TYPE);\n }\n });\n }\n\n // get entity config by name matching: simple name or fully qualified name (alias also supported)\n private getByName<T extends TypeBasedGenerationOptions>(\n mapping: Record<string, TypeBasedGenerationOptions>,\n namespace: NamespaceWithAlias,\n nameToMap: string\n ) {\n const [ns, alias] = namespace;\n const hayStack = { ...this.mapping.Any.names, ...mapping };\n\n const config =\n hayStack[withNamespace(ns, nameToMap)] ||\n (alias ? hayStack[withNamespace(alias, nameToMap)] : undefined) ||\n hayStack[nameToMap];\n if (!config) {\n return;\n }\n const { name, type, ...attrs } = config;\n return { ...attrs };\n }\n\n private getByRegExp(mapping: Array<[RegExp, any]>, [mainNs, alias]: NamespaceWithAlias, nameToMap: string) {\n const fqName = `${mainNs}.${nameToMap}`;\n const hayStack = [...this.mapping.Any.regExps, ...mapping];\n\n const resultList = hayStack\n .filter(([regExp, config]) => regExp.test(fqName))\n .map(([regExp, { name, mappedName, type, ...attrs }]) => ({\n mappedName: mappedName ? fqName.replace(regExp, mappedName) : undefined,\n ...attrs,\n }));\n\n return !resultList.length\n ? undefined\n : resultList.reduce((result, prop) => {\n return { ...result, ...prop };\n }, {});\n }\n\n private findConfig<T extends TypeBasedGenerationOptions>(\n mapping: MappingType<T>,\n namespace: NamespaceWithAlias,\n name: string\n ) {\n const stringEnt = this.getByName(mapping.names, namespace, name);\n const reEnt = this.getByRegExp(mapping.regExps, namespace, name);\n\n return stringEnt && reEnt ? { ...reEnt, ...stringEnt } : stringEnt || reEnt;\n }\n\n public findEntityTypeConfig(\n namespace: NamespaceWithAlias,\n name: string\n ): WithoutName<EntityTypeGenerationOptions> | undefined {\n return this.findConfig<EntityTypeGenerationOptions>(this.mapping.EntityType, namespace, name);\n }\n public findComplexTypeConfig(\n namespace: NamespaceWithAlias,\n name: string\n ): WithoutName<ComplexTypeGenerationOptions> | undefined {\n return this.findConfig(this.mapping.ComplexType, namespace, name);\n }\n public findEnumTypeConfig(\n namespace: NamespaceWithAlias,\n name: string\n ): WithoutName<GenericTypeGenerationOptions> | undefined {\n return this.findConfig(this.mapping.EnumType, namespace, name);\n }\n\n public findOperationTypeConfig(\n namespace: NamespaceWithAlias,\n name: string\n ): WithoutName<GenericTypeGenerationOptions> | undefined {\n return this.findConfig(this.mapping.OperationType, namespace, name);\n }\n\n public findOperationImportConfig(\n namespace: string,\n name: string\n ): WithoutName<GenericTypeGenerationOptions> | undefined {\n return this.findConfig(this.mapping.OperationImportType, [namespace], name);\n }\n\n public findEntitySetConfig(namespace: string, name: string): WithoutName<GenericTypeGenerationOptions> | undefined {\n return this.findConfig(this.mapping.EntitySet, [namespace], name);\n }\n\n public findSingletonConfig(namespace: string, name: string): WithoutName<GenericTypeGenerationOptions> | undefined {\n return this.findConfig(this.mapping.Singleton, [namespace], name);\n }\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ConfigFileOptions } from "../../OptionModel";
|
|
2
|
+
import { TypeModel } from "../../TypeModel";
|
|
3
|
+
export interface ValidationError {
|
|
4
|
+
fqName: string;
|
|
5
|
+
type: TypeModel;
|
|
6
|
+
renamedTo?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface NameValidatorOptions extends Pick<ConfigFileOptions, "disableAutomaticNameClashResolution"> {
|
|
9
|
+
}
|
|
10
|
+
export declare class NameValidator {
|
|
11
|
+
private options;
|
|
12
|
+
private entityContainer;
|
|
13
|
+
private store;
|
|
14
|
+
private errors;
|
|
15
|
+
constructor(options?: NameValidatorOptions);
|
|
16
|
+
private addToError;
|
|
17
|
+
private addToTypes;
|
|
18
|
+
private addToEntityContainer;
|
|
19
|
+
addEntityType(fqName: string, name: string): string;
|
|
20
|
+
addComplexType(fqName: string, name: string): string;
|
|
21
|
+
addEnumType(fqName: string, name: string): string;
|
|
22
|
+
addUnboundOperationType(fqName: string, name: string): string;
|
|
23
|
+
addBoundOperationType(bindingName: string, fqName: string, name: string): string;
|
|
24
|
+
addOperationImportType(fqName: string, name: string): string;
|
|
25
|
+
addEntitySet(fqName: string, name: string): string;
|
|
26
|
+
addSingleton(fqName: string, name: string): string;
|
|
27
|
+
validate(): Map<string, ValidationError[]>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NameValidator = void 0;
|
|
4
|
+
const TypeModel_1 = require("../../TypeModel");
|
|
5
|
+
class NameValidator {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
this.entityContainer = new Map();
|
|
9
|
+
this.store = new Map();
|
|
10
|
+
this.errors = new Map();
|
|
11
|
+
}
|
|
12
|
+
addToError(name, hit, validationObject) {
|
|
13
|
+
var _a;
|
|
14
|
+
const existingErrors = this.errors.get(name);
|
|
15
|
+
if (existingErrors) {
|
|
16
|
+
if (!this.options.disableAutomaticNameClashResolution) {
|
|
17
|
+
validationObject.renamedTo = `${name}${existingErrors.length + 1}`;
|
|
18
|
+
}
|
|
19
|
+
existingErrors.push(validationObject);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
if (!this.options.disableAutomaticNameClashResolution) {
|
|
23
|
+
validationObject.renamedTo = `${name}2`;
|
|
24
|
+
}
|
|
25
|
+
this.errors.set(name, [hit, validationObject]);
|
|
26
|
+
}
|
|
27
|
+
return (_a = validationObject.renamedTo) !== null && _a !== void 0 ? _a : name;
|
|
28
|
+
}
|
|
29
|
+
addToTypes(fqName, name, type) {
|
|
30
|
+
const validationObject = { type, fqName };
|
|
31
|
+
const hit = this.store.get(name);
|
|
32
|
+
if (hit) {
|
|
33
|
+
return this.addToError(name, hit, validationObject);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.store.set(name, validationObject);
|
|
37
|
+
return name;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
addToEntityContainer(fqName, name, type) {
|
|
41
|
+
const validationObject = { type, fqName };
|
|
42
|
+
const hit = this.entityContainer.get(name);
|
|
43
|
+
if (hit) {
|
|
44
|
+
return this.addToError(name, hit, validationObject);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.entityContainer.set(name, validationObject);
|
|
48
|
+
return name;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
addEntityType(fqName, name) {
|
|
52
|
+
return this.addToTypes(fqName, name, TypeModel_1.TypeModel.EntityType);
|
|
53
|
+
}
|
|
54
|
+
addComplexType(fqName, name) {
|
|
55
|
+
return this.addToTypes(fqName, name, TypeModel_1.TypeModel.ComplexType);
|
|
56
|
+
}
|
|
57
|
+
addEnumType(fqName, name) {
|
|
58
|
+
return this.addToTypes(fqName, name, TypeModel_1.TypeModel.EnumType);
|
|
59
|
+
}
|
|
60
|
+
addUnboundOperationType(fqName, name) {
|
|
61
|
+
return this.addToTypes(fqName, name, TypeModel_1.TypeModel.OperationType);
|
|
62
|
+
}
|
|
63
|
+
addBoundOperationType(bindingName, fqName, name) {
|
|
64
|
+
return this.addToTypes(`${bindingName}_${fqName}`, name, TypeModel_1.TypeModel.OperationType);
|
|
65
|
+
}
|
|
66
|
+
addOperationImportType(fqName, name) {
|
|
67
|
+
return this.addToEntityContainer(fqName, name, TypeModel_1.TypeModel.OperationImportType);
|
|
68
|
+
}
|
|
69
|
+
addEntitySet(fqName, name) {
|
|
70
|
+
return this.addToEntityContainer(fqName, name, TypeModel_1.TypeModel.EntitySet);
|
|
71
|
+
}
|
|
72
|
+
addSingleton(fqName, name) {
|
|
73
|
+
return this.addToEntityContainer(fqName, name, TypeModel_1.TypeModel.Singleton);
|
|
74
|
+
}
|
|
75
|
+
validate() {
|
|
76
|
+
return this.errors;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.NameValidator = NameValidator;
|
|
80
|
+
//# sourceMappingURL=NameValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NameValidator.js","sourceRoot":"","sources":["../../../src/data-model/validation/NameValidator.ts"],"names":[],"mappings":";;;AACA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a,CAAC,CAAC;IACpF,CAAC;IACM,sBAAsB,CAAC,MAAc,EAAE,IAAY;QACxD,OAAO,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,EAAE,qBAAS,CAAC,mBAAmB,CAAC,CAAC;IAChF,CAAC;IACM,YAAY,CAAC,MAAc,EAAE,IAAY;QAC9C,OAAO,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,EAAE,qBAAS,CAAC,SAAS,CAAC,CAAC;IACtE,CAAC;IACM,YAAY,CAAC,MAAc,EAAE,IAAY;QAC9C,OAAO,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,EAAE,qBAAS,CAAC,SAAS,CAAC,CAAC;IACtE,CAAC;IAEM,QAAQ;QACb,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAzED,sCAyEC","sourcesContent":["import { ConfigFileOptions } from \"../../OptionModel\";\nimport { TypeModel } from \"../../TypeModel\";\n\nexport interface ValidationError {\n fqName: string;\n type: TypeModel;\n renamedTo?: string;\n}\n\nexport interface NameValidatorOptions extends Pick<ConfigFileOptions, \"disableAutomaticNameClashResolution\"> {}\n\nexport class NameValidator {\n private entityContainer = new Map<string, ValidationError>();\n private store = new Map<string, ValidationError>();\n private errors = new Map<string, ValidationError[]>();\n\n constructor(private options: NameValidatorOptions = {}) {}\n\n private addToError(name: string, hit: ValidationError, validationObject: ValidationError) {\n const existingErrors = this.errors.get(name);\n if (existingErrors) {\n if (!this.options.disableAutomaticNameClashResolution) {\n validationObject.renamedTo = `${name}${existingErrors.length + 1}`;\n }\n existingErrors.push(validationObject);\n } else {\n if (!this.options.disableAutomaticNameClashResolution) {\n validationObject.renamedTo = `${name}2`;\n }\n this.errors.set(name, [hit, validationObject]);\n }\n return validationObject.renamedTo ?? name;\n }\n\n private addToTypes(fqName: string, name: string, type: TypeModel): string {\n const validationObject: ValidationError = { type, fqName };\n const hit = this.store.get(name);\n if (hit) {\n return this.addToError(name, hit, validationObject);\n } else {\n this.store.set(name, validationObject);\n return name;\n }\n }\n\n private addToEntityContainer(fqName: string, name: string, type: TypeModel): string {\n const validationObject: ValidationError = { type, fqName };\n const hit = this.entityContainer.get(name);\n if (hit) {\n return this.addToError(name, hit, validationObject);\n } else {\n this.entityContainer.set(name, validationObject);\n return name;\n }\n }\n\n public addEntityType(fqName: string, name: string) {\n return this.addToTypes(fqName, name, TypeModel.EntityType);\n }\n public addComplexType(fqName: string, name: string) {\n return this.addToTypes(fqName, name, TypeModel.ComplexType);\n }\n public addEnumType(fqName: string, name: string) {\n return this.addToTypes(fqName, name, TypeModel.EnumType);\n }\n public addUnboundOperationType(fqName: string, name: string) {\n return this.addToTypes(fqName, name, TypeModel.OperationType);\n }\n public addBoundOperationType(bindingName: string, fqName: string, name: string) {\n return this.addToTypes(`${bindingName}_${fqName}`, name, TypeModel.OperationType);\n }\n public addOperationImportType(fqName: string, name: string) {\n return this.addToEntityContainer(fqName, name, TypeModel.OperationImportType);\n }\n public addEntitySet(fqName: string, name: string) {\n return this.addToEntityContainer(fqName, name, TypeModel.EntitySet);\n }\n public addSingleton(fqName: string, name: string) {\n return this.addToEntityContainer(fqName, name, TypeModel.Singleton);\n }\n\n public validate() {\n return this.errors;\n }\n}\n"]}
|
package/lib/defaultConfig.js
CHANGED
|
@@ -26,6 +26,7 @@ const defaultConfig = {
|
|
|
26
26
|
allowRenaming: false,
|
|
27
27
|
v2ModelsWithExtraResultsWrapping: false,
|
|
28
28
|
v4BigNumberAsString: false,
|
|
29
|
+
disableAutomaticNameClashResolution: false,
|
|
29
30
|
naming: {
|
|
30
31
|
models: {
|
|
31
32
|
namingStrategy: NamingModel_1.NamingStrategies.PASCAL_CASE,
|
|
@@ -94,8 +95,7 @@ const defaultConfig = {
|
|
|
94
95
|
},
|
|
95
96
|
},
|
|
96
97
|
propertiesByName: [],
|
|
97
|
-
|
|
98
|
-
operationsByName: [],
|
|
98
|
+
byTypeAndName: [],
|
|
99
99
|
};
|
|
100
100
|
const { models, queryObjects, services } = defaultConfig.naming;
|
|
101
101
|
const minimalNamingConfig = {
|
package/lib/defaultConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultConfig.js","sourceRoot":"","sources":["../src/defaultConfig.ts"],"names":[],"mappings":";;;;AAAA,kEAAkC;AAElC,+CAA+D;AAC/D,+CAA6D;AAG7D;;GAEG;AACH,MAAM,aAAa,GAAyB;IAC1C,eAAe,EAAE,EAAE;IACnB,WAAW,EAAE,KAAK;IAClB,IAAI,EAAE,mBAAK,CAAC,GAAG;IACf,QAAQ,EAAE,uBAAS,CAAC,MAAM;IAC1B,KAAK,EAAE,KAAK;IACZ,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,eAAe;IACzB,UAAU,EAAE,EAAE;IACd,kBAAkB,EAAE,KAAK;IACzB,YAAY,EAAE,KAAK;IACnB,cAAc,EAAE,KAAK;IACrB,YAAY,EAAE,KAAK;IACnB,+BAA+B,EAAE,KAAK;IACtC,qBAAqB,EAAE,KAAK;IAC5B,aAAa,EAAE,KAAK;IACpB,gCAAgC,EAAE,KAAK;IACvC,mBAAmB,EAAE,KAAK;IAC1B,MAAM,EAAE;QACN,MAAM,EAAE;YACN,cAAc,EAAE,8BAAgB,CAAC,WAAW;YAC5C,kBAAkB,EAAE,8BAAgB,CAAC,UAAU;YAC/C,cAAc,EAAE;gBACd,MAAM,EAAE,UAAU;gBAClB,MAAM,EAAE,EAAE;gBACV,gBAAgB,EAAE,IAAI;aACvB;YACD,QAAQ,EAAE;gBACR,MAAM,EAAE,EAAE;gBACV,MAAM,EAAE,IAAI;gBACZ,gBAAgB,EAAE,IAAI;aACvB;YACD,oBAAoB,EAAE;gBACpB,MAAM,EAAE,EAAE;gBACV,MAAM,EAAE,QAAQ;gBAChB,gBAAgB,EAAE,IAAI;aACvB;YACD,QAAQ,EAAE;gBACR,cAAc,EAAE,8BAAgB,CAAC,WAAW;gBAC5C,MAAM,EAAE,EAAE;gB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;IACjD,OAAO,IAAA,mBAAS,EAAC,WAAW,EAAE,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC;AACjE,CAAC;AAHD,4CAGC","sourcesContent":["import deepmerge from \"deepmerge\";\r\n\r\nimport { NameSettings, NamingStrategies } from \"./NamingModel\";\r\nimport { EmitModes, Modes, RunOptions } from \"./OptionModel\";\r\n\r\nexport type DefaultConfiguration = Omit<RunOptions, \"sourceUrl\" | \"source\" | \"output\" | \"serviceName\">;\r\n/**\r\n * The default configuration.\r\n */\r\nconst defaultConfig: DefaultConfiguration = {\r\n sourceUrlConfig: {},\r\n refreshFile: false,\r\n mode: Modes.all,\r\n emitMode: EmitModes.js_dts,\r\n debug: false,\r\n prettier: false,\r\n tsconfig: \"tsconfig.json\",\r\n converters: [],\r\n skipEditableModels: false,\r\n skipIdModels: false,\r\n skipOperations: false,\r\n skipComments: false,\r\n enablePrimitivePropertyServices: false,\r\n disableAutoManagedKey: false,\r\n allowRenaming: false,\r\n v2ModelsWithExtraResultsWrapping: false,\r\n v4BigNumberAsString: false,\r\n disableAutomaticNameClashResolution: false,\r\n naming: {\r\n models: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\r\n editableModels: {\r\n prefix: \"Editable\",\r\n suffix: \"\",\r\n applyModelNaming: true,\r\n },\r\n idModels: {\r\n prefix: \"\",\r\n suffix: \"Id\",\r\n applyModelNaming: true,\r\n },\r\n operationParamModels: {\r\n prefix: \"\",\r\n suffix: \"Params\",\r\n applyModelNaming: true,\r\n },\r\n fileName: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n prefix: \"\",\r\n suffix: \"Model\",\r\n },\r\n },\r\n queryObjects: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n propNamingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"Q\",\r\n suffix: \"\",\r\n idFunctions: {\r\n prefix: \"\",\r\n suffix: \"Id\",\r\n },\r\n fileName: {\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n prefix: \"Q\",\r\n suffix: \"\",\r\n },\r\n },\r\n services: {\r\n prefix: \"\",\r\n suffix: \"Service\",\r\n namingStrategy: NamingStrategies.PASCAL_CASE,\r\n main: {\r\n applyServiceNaming: true,\r\n },\r\n collection: {\r\n prefix: \"\",\r\n suffix: \"Collection\",\r\n applyServiceNaming: true,\r\n },\r\n operations: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n },\r\n relatedServiceGetter: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"\",\r\n suffix: \"\",\r\n },\r\n privateProps: {\r\n namingStrategy: NamingStrategies.CAMEL_CASE,\r\n prefix: \"_\",\r\n suffix: \"\",\r\n },\r\n },\r\n },\r\n propertiesByName: [],\r\n byTypeAndName: [],\r\n};\r\n\r\nconst { models, queryObjects, services } = defaultConfig.naming;\r\nconst minimalNamingConfig: NameSettings = {\r\n models: {\r\n fileName: {\r\n prefix: models.fileName.prefix,\r\n suffix: models.fileName.suffix,\r\n },\r\n idModels: {\r\n applyModelNaming: true,\r\n prefix: models.idModels.prefix,\r\n suffix: models.idModels.suffix,\r\n },\r\n editableModels: {\r\n applyModelNaming: true,\r\n prefix: models.editableModels.prefix,\r\n suffix: models.editableModels.suffix,\r\n },\r\n operationParamModels: {\r\n applyModelNaming: true,\r\n prefix: models.operationParamModels.prefix,\r\n suffix: models.operationParamModels.suffix,\r\n },\r\n },\r\n queryObjects: {\r\n prefix: queryObjects.prefix,\r\n suffix: queryObjects.suffix,\r\n fileName: {\r\n prefix: queryObjects.fileName.prefix,\r\n suffix: queryObjects.fileName.suffix,\r\n },\r\n idFunctions: {\r\n prefix: queryObjects.idFunctions.prefix,\r\n suffix: queryObjects.idFunctions.suffix,\r\n },\r\n },\r\n services: {\r\n prefix: services.prefix,\r\n suffix: services.suffix,\r\n main: {\r\n applyServiceNaming: true,\r\n },\r\n collection: {\r\n applyServiceNaming: true,\r\n prefix: services.collection.prefix,\r\n suffix: services.collection.suffix,\r\n },\r\n privateProps: {\r\n prefix: services.privateProps.prefix,\r\n suffix: services.privateProps.suffix,\r\n },\r\n relatedServiceGetter: {\r\n prefix: services.relatedServiceGetter.prefix,\r\n suffix: services.relatedServiceGetter.suffix,\r\n },\r\n },\r\n};\r\n\r\n/**\r\n * Creates a defensive copy of the default config.\r\n */\r\nexport function getDefaultConfig(): DefaultConfiguration {\r\n return deepmerge(defaultConfig, {});\r\n}\r\n\r\n/**\r\n * Creates a defensive copy of the minimal config: minimal in respect to naming.\r\n */\r\nexport function getMinimalConfig(): DefaultConfiguration {\r\n const { naming, ...passThrough } = defaultConfig;\r\n return deepmerge(passThrough, { naming: minimalNamingConfig });\r\n}\r\n"]}
|
|
@@ -69,7 +69,7 @@ class ModelGenerator {
|
|
|
69
69
|
docs: this.options.skipComments ? undefined : [this.generatePropDoc(p, model)],
|
|
70
70
|
};
|
|
71
71
|
}),
|
|
72
|
-
extends: model.
|
|
72
|
+
extends: model.finalBaseClass ? [this.namingHelper.getModelName(model.finalBaseClass)] : undefined,
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
generatePropDoc(prop, model) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelGenerator.js","sourceRoot":"","sources":["../../src/generator/ModelGenerator.ts"],"names":[],"mappings":";;;AACA,uCAAmF;AAMnF,uDAAoD;AAE7C,MAAM,cAAc,GAAiC,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;IACpH,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAC5F,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB;AAEF,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C,M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AAC,CAAC,CAAC,EAAE,EAAE;gBACzC,OAAO;oBACL,IAAI,EAAE,CAAC,CAAC,IAAI;oBACZ,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;oBACzB,gBAAgB,EAAE,CAAC,CAAC,CAAC,QAAQ;iBAC9B,CAAC;YACJ,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { JSDocStructure, OptionalKind, SourceFile, StructureKind } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport { ComplexType, DataTypes, ModelType, OperationType, PropertyModel } from \"../data-model/DataTypeModel\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\r\nimport { ImportContainer } from \"./ImportContainer\";\r\n\r\nexport const generateModels: EntityBasedGeneratorFunction = (dataModel, sourceFile, version, options, namingHelper) => {\r\n const generator = new ModelGenerator(dataModel, sourceFile, version, options, namingHelper);\r\n return generator.generate();\r\n};\r\n\r\nconst DEFERRED_CONTENT = \"DeferredContent\";\r\n\r\nclass ModelGenerator {\r\n private importContainer!: ImportContainer;\r\n\r\n constructor(\r\n private dataModel: DataModel,\r\n private sourceFile: SourceFile,\r\n private version: ODataVersions,\r\n private options: GeneratorFunctionOptions,\r\n private namingHelper: NamingHelper\r\n ) {}\r\n\r\n public generate(): void {\r\n this.importContainer = new ImportContainer(this.namingHelper.getFileNames());\r\n\r\n this.generateEnums();\r\n this.generateModels();\r\n if (!this.options.skipOperations) {\r\n this.generateUnboundOperationParams();\r\n }\r\n }\r\n\r\n private generateEnums() {\r\n this.dataModel.getEnums().forEach((et) => {\r\n this.sourceFile.addEnum({\r\n name: et.name,\r\n isExported: true,\r\n members: et.members.map((mem) => ({ name: mem, initializer: `\"${mem}\"` })),\r\n });\r\n });\r\n }\r\n\r\n private generateModels() {\r\n this.dataModel.getEntityTypes().forEach((model) => {\r\n this.generateModel(model);\r\n if (!this.options.skipIdModels) {\r\n this.generateIdModel(model);\r\n }\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(model);\r\n }\r\n if (!this.options.skipOperations) {\r\n this.generateBoundOperationParams(model.fqName);\r\n }\r\n });\r\n this.dataModel.getComplexTypes().forEach((model) => {\r\n this.generateModel(model);\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(model);\r\n }\r\n });\r\n\r\n this.sourceFile.addImportDeclarations(this.importContainer.getImportDeclarations());\r\n }\r\n\r\n private generateModel(model: ComplexType | ModelType) {\r\n this.sourceFile.addInterface({\r\n name: model.name,\r\n isExported: true,\r\n properties: model.props.map((p) => {\r\n const isEntity = p.dataType == DataTypes.ModelType;\r\n return {\r\n name: p.name,\r\n type: this.getPropType(p),\r\n // props for entities or entity collections are not added in V4 if not explicitly expanded\r\n hasQuestionToken: this.dataModel.isV4() && isEntity,\r\n docs: this.options.skipComments ? undefined : [this.generatePropDoc(p, model)],\r\n };\r\n }),\r\n extends: model.baseClasses.map((bc) => this.namingHelper.getModelName(bc)),\r\n });\r\n }\r\n\r\n private generatePropDoc(prop: PropertyModel, model: ComplexType | ModelType): OptionalKind<JSDocStructure> {\r\n const isKeyProp = (model as ModelType).keyNames?.includes(prop.odataName);\r\n const baseAttribs: Array<string> = [];\r\n if (isKeyProp) {\r\n baseAttribs.push(\"**Key Property**: This is a key property used to identify the entity.\");\r\n }\r\n if (prop.managed) {\r\n baseAttribs.push(\"**Managed**: This property is managed on the server side and cannot be edited.\");\r\n }\r\n if (prop.converters?.length) {\r\n baseAttribs.push(`**Applied Converters**: ${prop.converters.map((c) => c.converterId).join(\",\")}.`);\r\n }\r\n\r\n const attributeTable: Array<[string, string]> = [\r\n [\"Name\", prop.odataName],\r\n [\"Type\", prop.odataType],\r\n ];\r\n if (prop.required) {\r\n attributeTable.push([\"Nullable\", \"false\"]);\r\n }\r\n\r\n const description =\r\n (baseAttribs ? baseAttribs.join(\"<br/>\") + \"\\n\\n\" : \"\") +\r\n \"OData Attributes:\\n\" +\r\n \"|Attribute Name | Attribute Value |\\n| --- | ---|\\n\" +\r\n attributeTable.map((row) => `| ${row[0]} | \\`${row[1]}\\` |`).join(\"\\n\");\r\n\r\n return { kind: StructureKind.JSDoc, description };\r\n }\r\n\r\n private getPropType(prop: PropertyModel): string {\r\n const isEntity = prop.dataType == DataTypes.ModelType;\r\n\r\n // V2 entity special: deferred content\r\n let suffix = \"\";\r\n if (isEntity && this.dataModel.isV2()) {\r\n this.importContainer.addFromCore(DEFERRED_CONTENT);\r\n suffix = ` | ${DEFERRED_CONTENT}`;\r\n }\r\n // custom types which require type imports => possible via converters\r\n else if (prop.typeModule) {\r\n this.importContainer.addCustomType(prop.typeModule, prop.type);\r\n }\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n const type = `Array<${prop.type}>`;\r\n if (this.dataModel.isV2() && this.options.v2ModelsWithExtraResultsWrapping) {\r\n return `{ results: ${type} }` + suffix;\r\n } else {\r\n return type + suffix;\r\n }\r\n }\r\n\r\n // primitive, enum & complex types\r\n return prop.type + (prop.required ? \"\" : \" | null\") + suffix;\r\n }\r\n\r\n private generateIdModel(model: ModelType) {\r\n if (!model.generateId) {\r\n return;\r\n }\r\n const singleType = model.keys.length === 1 ? `${model.keys[0].type} | ` : \"\";\r\n const keyTypes = model.keys.map((keyProp) => `${keyProp.name}: ${this.getPropType(keyProp)}`).join(\",\");\r\n const type = `${singleType}{${keyTypes}}`;\r\n\r\n this.sourceFile.addTypeAlias({\r\n name: model.idModelName,\r\n isExported: true,\r\n type,\r\n });\r\n }\r\n\r\n private generateEditableModel(model: ComplexType) {\r\n const entityTypes = [DataTypes.ModelType, DataTypes.ComplexType];\r\n const allProps = [...model.baseProps, ...model.props].filter((p) => !p.managed);\r\n\r\n const requiredProps = allProps\r\n .filter((p) => p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const optionalProps = allProps\r\n .filter((p) => !p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const complexProps = allProps.filter((p) => p.dataType === DataTypes.ComplexType);\r\n\r\n const extendsClause = [\r\n requiredProps ? `Pick<${model.name}, ${requiredProps}>` : null,\r\n optionalProps ? `Partial<Pick<${model.name}, ${optionalProps}>>` : null,\r\n ].filter((e): e is string => !!e);\r\n\r\n this.sourceFile.addInterface({\r\n name: model.editableName,\r\n isExported: true,\r\n extends: extendsClause,\r\n properties: !complexProps\r\n ? undefined\r\n : complexProps.map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getEditablePropType(p),\r\n // optional props don't need to be specified in editable model\r\n // also, entities would require deep insert func => we make it optional for now\r\n hasQuestionToken: !p.required || p.dataType === DataTypes.ModelType,\r\n };\r\n }),\r\n });\r\n }\r\n\r\n private getEditablePropType(prop: PropertyModel): string {\r\n const type =\r\n prop.dataType === DataTypes.ModelType\r\n ? this.dataModel.getEntityType(prop.fqType)!.editableName\r\n : prop.dataType === DataTypes.ComplexType\r\n ? this.dataModel.getComplexType(prop.fqType)!.editableName\r\n : prop.type;\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n return `Array<${type}>`;\r\n }\r\n\r\n // primitive, enum & complex types\r\n return type + (prop.required ? \"\" : \" | null\");\r\n }\r\n\r\n private generateUnboundOperationParams() {\r\n this.dataModel.getUnboundOperationTypes().forEach((operation) => {\r\n this.generateOperationParams(operation);\r\n });\r\n }\r\n\r\n private generateBoundOperationParams(entityName: string) {\r\n [\r\n ...this.dataModel.getEntityTypeOperations(entityName),\r\n ...this.dataModel.getEntitySetOperations(entityName),\r\n ].forEach((operation) => {\r\n this.generateOperationParams(operation);\r\n });\r\n }\r\n\r\n private generateOperationParams(operation: OperationType) {\r\n if (!operation.parameters.length) {\r\n return;\r\n }\r\n this.sourceFile.addInterface({\r\n name: operation.paramsModelName,\r\n isExported: true,\r\n properties: operation.parameters.map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getPropType(p),\r\n hasQuestionToken: !p.required,\r\n };\r\n }),\r\n });\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ModelGenerator.js","sourceRoot":"","sources":["../../src/generator/ModelGenerator.ts"],"names":[],"mappings":";;;AACA,uCAAmF;AAMnF,uDAAoD;AAE7C,MAAM,cAAc,GAAiC,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;IACpH,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAC5F,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB;AAEF,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C,MAAM,cAAc;IAGlB,YACU,SAAoB,EACpB,UAAsB,EACtB,OAAsB,EACtB,OAAiC,EACjC,YAA0B;QAJ1B,cAAS,GAAT,SAAS,CAAW;QACpB,eAAU,GAAV,UAAU,CAAY;QACtB,YAAO,GAAP,OAAO,CAAe;QACtB,YAAO,GAAP,OAAO,CAA0B;QACjC,iBAAY,GAAZ,YAAY,CAAc;IACjC,CAAC;IAEG,QAAQ;QACb,IAAI,CAAC,eAAe,GAAG,IAAI,iCAAe,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC;QAE7E,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE;YAChC,IAAI,CAAC,8BAA8B,EAAE,CAAC;SACvC;IACH,CAAC;IAEO,aAAa;QACnB,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;YACvC,IAAI,C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C,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,4BAA4B,CAAC,UAAkB;QACrD;YACE,GAAG,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC,UAAU,CAAC;YACrD,GAAG,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,UAAU,CAAC;SACrD,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;YACtB,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,uBAAuB,CAAC,SAAwB;QACtD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE;YAChC,OAAO;SACR;QACD,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;YAC3B,IAAI,EAAE,SAAS,CAAC,eAAe;YAC/B,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;gBACzC,OAAO;oBACL,IAAI,EAAE,CAAC,CAAC,IAAI;oBACZ,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;oBACzB,gBAAgB,EAAE,CAAC,CAAC,CAAC,QAAQ;iBAC9B,CAAC;YACJ,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\nimport { JSDocStructure, OptionalKind, SourceFile, StructureKind } from \"ts-morph\";\n\nimport { DataModel } from \"../data-model/DataModel\";\nimport { ComplexType, DataTypes, ModelType, OperationType, PropertyModel } from \"../data-model/DataTypeModel\";\nimport { NamingHelper } from \"../data-model/NamingHelper\";\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\nimport { ImportContainer } from \"./ImportContainer\";\n\nexport const generateModels: EntityBasedGeneratorFunction = (dataModel, sourceFile, version, options, namingHelper) => {\n const generator = new ModelGenerator(dataModel, sourceFile, version, options, namingHelper);\n return generator.generate();\n};\n\nconst DEFERRED_CONTENT = \"DeferredContent\";\n\nclass ModelGenerator {\n private importContainer!: ImportContainer;\n\n constructor(\n private dataModel: DataModel,\n private sourceFile: SourceFile,\n private version: ODataVersions,\n private options: GeneratorFunctionOptions,\n private namingHelper: NamingHelper\n ) {}\n\n public generate(): void {\n this.importContainer = new ImportContainer(this.namingHelper.getFileNames());\n\n this.generateEnums();\n this.generateModels();\n if (!this.options.skipOperations) {\n this.generateUnboundOperationParams();\n }\n }\n\n private generateEnums() {\n this.dataModel.getEnums().forEach((et) => {\n this.sourceFile.addEnum({\n name: et.name,\n isExported: true,\n members: et.members.map((mem) => ({ name: mem, initializer: `\"${mem}\"` })),\n });\n });\n }\n\n private generateModels() {\n this.dataModel.getEntityTypes().forEach((model) => {\n this.generateModel(model);\n if (!this.options.skipIdModels) {\n this.generateIdModel(model);\n }\n if (!this.options.skipEditableModels) {\n this.generateEditableModel(model);\n }\n if (!this.options.skipOperations) {\n this.generateBoundOperationParams(model.fqName);\n }\n });\n this.dataModel.getComplexTypes().forEach((model) => {\n this.generateModel(model);\n if (!this.options.skipEditableModels) {\n this.generateEditableModel(model);\n }\n });\n\n this.sourceFile.addImportDeclarations(this.importContainer.getImportDeclarations());\n }\n\n private generateModel(model: ComplexType | ModelType) {\n this.sourceFile.addInterface({\n name: model.name,\n isExported: true,\n properties: model.props.map((p) => {\n const isEntity = p.dataType == DataTypes.ModelType;\n return {\n name: p.name,\n type: this.getPropType(p),\n // props for entities or entity collections are not added in V4 if not explicitly expanded\n hasQuestionToken: this.dataModel.isV4() && isEntity,\n docs: this.options.skipComments ? undefined : [this.generatePropDoc(p, model)],\n };\n }),\n extends: model.finalBaseClass ? [this.namingHelper.getModelName(model.finalBaseClass)] : undefined,\n });\n }\n\n private generatePropDoc(prop: PropertyModel, model: ComplexType | ModelType): OptionalKind<JSDocStructure> {\n const isKeyProp = (model as ModelType).keyNames?.includes(prop.odataName);\n const baseAttribs: Array<string> = [];\n if (isKeyProp) {\n baseAttribs.push(\"**Key Property**: This is a key property used to identify the entity.\");\n }\n if (prop.managed) {\n baseAttribs.push(\"**Managed**: This property is managed on the server side and cannot be edited.\");\n }\n if (prop.converters?.length) {\n baseAttribs.push(`**Applied Converters**: ${prop.converters.map((c) => c.converterId).join(\",\")}.`);\n }\n\n const attributeTable: Array<[string, string]> = [\n [\"Name\", prop.odataName],\n [\"Type\", prop.odataType],\n ];\n if (prop.required) {\n attributeTable.push([\"Nullable\", \"false\"]);\n }\n\n const description =\n (baseAttribs ? baseAttribs.join(\"<br/>\") + \"\\n\\n\" : \"\") +\n \"OData Attributes:\\n\" +\n \"|Attribute Name | Attribute Value |\\n| --- | ---|\\n\" +\n attributeTable.map((row) => `| ${row[0]} | \\`${row[1]}\\` |`).join(\"\\n\");\n\n return { kind: StructureKind.JSDoc, description };\n }\n\n private getPropType(prop: PropertyModel): string {\n const isEntity = prop.dataType == DataTypes.ModelType;\n\n // V2 entity special: deferred content\n let suffix = \"\";\n if (isEntity && this.dataModel.isV2()) {\n this.importContainer.addFromCore(DEFERRED_CONTENT);\n suffix = ` | ${DEFERRED_CONTENT}`;\n }\n // custom types which require type imports => possible via converters\n else if (prop.typeModule) {\n this.importContainer.addCustomType(prop.typeModule, prop.type);\n }\n\n // Collections\n if (prop.isCollection) {\n const type = `Array<${prop.type}>`;\n if (this.dataModel.isV2() && this.options.v2ModelsWithExtraResultsWrapping) {\n return `{ results: ${type} }` + suffix;\n } else {\n return type + suffix;\n }\n }\n\n // primitive, enum & complex types\n return prop.type + (prop.required ? \"\" : \" | null\") + suffix;\n }\n\n private generateIdModel(model: ModelType) {\n if (!model.generateId) {\n return;\n }\n const singleType = model.keys.length === 1 ? `${model.keys[0].type} | ` : \"\";\n const keyTypes = model.keys.map((keyProp) => `${keyProp.name}: ${this.getPropType(keyProp)}`).join(\",\");\n const type = `${singleType}{${keyTypes}}`;\n\n this.sourceFile.addTypeAlias({\n name: model.idModelName,\n isExported: true,\n type,\n });\n }\n\n private generateEditableModel(model: ComplexType) {\n const entityTypes = [DataTypes.ModelType, DataTypes.ComplexType];\n const allProps = [...model.baseProps, ...model.props].filter((p) => !p.managed);\n\n const requiredProps = allProps\n .filter((p) => p.required && !entityTypes.includes(p.dataType))\n .map((p) => `\"${p.name}\"`)\n .join(\" | \");\n const optionalProps = allProps\n .filter((p) => !p.required && !entityTypes.includes(p.dataType))\n .map((p) => `\"${p.name}\"`)\n .join(\" | \");\n const complexProps = allProps.filter((p) => p.dataType === DataTypes.ComplexType);\n\n const extendsClause = [\n requiredProps ? `Pick<${model.name}, ${requiredProps}>` : null,\n optionalProps ? `Partial<Pick<${model.name}, ${optionalProps}>>` : null,\n ].filter((e): e is string => !!e);\n\n this.sourceFile.addInterface({\n name: model.editableName,\n isExported: true,\n extends: extendsClause,\n properties: !complexProps\n ? undefined\n : complexProps.map((p) => {\n return {\n name: p.name,\n type: this.getEditablePropType(p),\n // optional props don't need to be specified in editable model\n // also, entities would require deep insert func => we make it optional for now\n hasQuestionToken: !p.required || p.dataType === DataTypes.ModelType,\n };\n }),\n });\n }\n\n private getEditablePropType(prop: PropertyModel): string {\n const type =\n prop.dataType === DataTypes.ModelType\n ? this.dataModel.getEntityType(prop.fqType)!.editableName\n : prop.dataType === DataTypes.ComplexType\n ? this.dataModel.getComplexType(prop.fqType)!.editableName\n : prop.type;\n\n // Collections\n if (prop.isCollection) {\n return `Array<${type}>`;\n }\n\n // primitive, enum & complex types\n return type + (prop.required ? \"\" : \" | null\");\n }\n\n private generateUnboundOperationParams() {\n this.dataModel.getUnboundOperationTypes().forEach((operation) => {\n this.generateOperationParams(operation);\n });\n }\n\n private generateBoundOperationParams(entityName: string) {\n [\n ...this.dataModel.getEntityTypeOperations(entityName),\n ...this.dataModel.getEntitySetOperations(entityName),\n ].forEach((operation) => {\n this.generateOperationParams(operation);\n });\n }\n\n private generateOperationParams(operation: OperationType) {\n if (!operation.parameters.length) {\n return;\n }\n this.sourceFile.addInterface({\n name: operation.paramsModelName,\n isExported: true,\n properties: operation.parameters.map((p) => {\n return {\n name: p.name,\n type: this.getPropType(p),\n hasQuestionToken: !p.required,\n };\n }),\n });\n }\n}\n"]}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -4,4 +4,5 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
tslib_1.__exportStar(require("./OptionModel"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./NamingModel"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./defaultConfig"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./TypeModel"), exports);
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,wDAA8B;AAC9B,0DAAgC","sourcesContent":["export * from \"./OptionModel\";\r\nexport * from \"./NamingModel\";\r\nexport * from \"./defaultConfig\";\r\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,wDAA8B;AAC9B,0DAAgC;AAChC,sDAA4B","sourcesContent":["export * from \"./OptionModel\";\r\nexport * from \"./NamingModel\";\r\nexport * from \"./defaultConfig\";\r\nexport * from \"./TypeModel\";\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@odata2ts/odata2ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"clean": "rimraf lib build",
|
|
18
18
|
"clean-v2": "rimraf build/v2",
|
|
19
19
|
"clean-v4": "rimraf build/v4",
|
|
20
|
+
"clear-cache": "jest --clearCache",
|
|
20
21
|
"compile": "tsc",
|
|
21
22
|
"compile-fixtures": "tsc -p ./tsconfig.fixture.json",
|
|
22
23
|
"dev": "yarn generate trippin odata",
|
|
@@ -87,6 +88,6 @@
|
|
|
87
88
|
"typescript": "^5.1.3"
|
|
88
89
|
},
|
|
89
90
|
"types": "./lib/index.d.ts",
|
|
90
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "2665219ea257fa0e7c40d6693d6de3db3fb1e1b8",
|
|
91
92
|
"readme": "README.md"
|
|
92
93
|
}
|