@odata2ts/odata2ts 0.36.3 → 0.38.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 +28 -0
- package/lib/FactoryFunctionModel.d.ts +7 -7
- package/lib/FactoryFunctionModel.js +1 -2
- package/lib/FactoryFunctionModel.js.map +1 -1
- package/lib/NamingModel.js +2 -5
- package/lib/NamingModel.js.map +1 -1
- package/lib/OptionModel.d.ts +7 -2
- package/lib/OptionModel.js +4 -7
- package/lib/OptionModel.js.map +1 -1
- package/lib/TypeModel.js +2 -5
- package/lib/TypeModel.js.map +1 -1
- package/lib/app.d.ts +2 -2
- package/lib/app.js +23 -27
- package/lib/app.js.map +1 -1
- package/lib/cli/cli.d.ts +1 -0
- package/lib/cli/cli.js +27 -0
- package/lib/cli/cli.js.map +1 -0
- package/lib/cli/index.d.ts +4 -0
- package/lib/cli/index.js +5 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/cli/processCliArgs.d.ts +2 -0
- package/lib/cli/processCliArgs.js +57 -0
- package/lib/cli/processCliArgs.js.map +1 -0
- package/lib/cli/processConfigFile.d.ts +2 -0
- package/lib/cli/processConfigFile.js +24 -0
- package/lib/cli/processConfigFile.js.map +1 -0
- package/lib/cli/serviceGenerationRun.d.ts +2 -0
- package/lib/cli/serviceGenerationRun.js +77 -0
- package/lib/cli/serviceGenerationRun.js.map +1 -0
- package/lib/data-model/DataModel.d.ts +2 -2
- package/lib/data-model/DataModel.js +5 -10
- package/lib/data-model/DataModel.js.map +1 -1
- package/lib/data-model/DataModelDigestion.d.ts +10 -10
- package/lib/data-model/DataModelDigestion.js +27 -27
- package/lib/data-model/DataModelDigestion.js.map +1 -1
- package/lib/data-model/DataModelDigestionV2.d.ts +2 -2
- package/lib/data-model/DataModelDigestionV2.js +27 -31
- package/lib/data-model/DataModelDigestionV2.js.map +1 -1
- package/lib/data-model/DataModelDigestionV4.d.ts +2 -2
- package/lib/data-model/DataModelDigestionV4.js +33 -37
- package/lib/data-model/DataModelDigestionV4.js.map +1 -1
- package/lib/data-model/DataTypeModel.d.ts +5 -2
- package/lib/data-model/DataTypeModel.js +2 -5
- package/lib/data-model/DataTypeModel.js.map +1 -1
- package/lib/data-model/NamingHelper.d.ts +2 -2
- package/lib/data-model/NamingHelper.js +12 -19
- package/lib/data-model/NamingHelper.js.map +1 -1
- package/lib/data-model/ServiceConfigHelper.d.ts +3 -3
- package/lib/data-model/ServiceConfigHelper.js +18 -22
- package/lib/data-model/ServiceConfigHelper.js.map +1 -1
- package/lib/data-model/edmx/ODataEdmxModelBase.js +1 -2
- package/lib/data-model/edmx/ODataEdmxModelV3.d.ts +1 -1
- package/lib/data-model/edmx/ODataEdmxModelV3.js +1 -2
- package/lib/data-model/edmx/ODataEdmxModelV3.js.map +1 -1
- package/lib/data-model/edmx/ODataEdmxModelV4.d.ts +1 -1
- package/lib/data-model/edmx/ODataEdmxModelV4.js +1 -2
- package/lib/data-model/edmx/ODataEdmxModelV4.js.map +1 -1
- package/lib/data-model/validation/NameClashValidator.d.ts +5 -4
- package/lib/data-model/validation/NameClashValidator.js +16 -18
- package/lib/data-model/validation/NameClashValidator.js.map +1 -1
- package/lib/data-model/validation/NameValidator.d.ts +3 -2
- package/lib/data-model/validation/NameValidator.js +1 -2
- package/lib/data-model/validation/NameValidator.js.map +1 -1
- package/lib/data-model/validation/NoopValidator.d.ts +4 -3
- package/lib/data-model/validation/NoopValidator.js +5 -9
- package/lib/data-model/validation/NoopValidator.js.map +1 -1
- package/lib/defaultConfig.d.ts +1 -1
- package/lib/defaultConfig.js +22 -26
- package/lib/defaultConfig.js.map +1 -1
- package/lib/download/downloadMetadata.d.ts +1 -1
- package/lib/download/downloadMetadata.js +6 -10
- package/lib/download/downloadMetadata.js.map +1 -1
- package/lib/download/index.d.ts +2 -2
- package/lib/download/index.js +2 -7
- package/lib/download/index.js.map +1 -1
- package/lib/download/storeMetadata.js +15 -17
- package/lib/download/storeMetadata.js.map +1 -1
- package/lib/evaluateConfig.d.ts +1 -1
- package/lib/evaluateConfig.js +14 -18
- package/lib/evaluateConfig.js.map +1 -1
- package/lib/generator/ImportContainer.d.ts +3 -3
- package/lib/generator/ImportContainer.js +40 -27
- package/lib/generator/ImportContainer.js.map +1 -1
- package/lib/generator/ImportedNameValidator.js +1 -5
- package/lib/generator/ImportedNameValidator.js.map +1 -1
- package/lib/generator/ModelGenerator.d.ts +1 -1
- package/lib/generator/ModelGenerator.js +13 -13
- package/lib/generator/ModelGenerator.js.map +1 -1
- package/lib/generator/QueryObjectGenerator.d.ts +1 -1
- package/lib/generator/QueryObjectGenerator.js +41 -31
- package/lib/generator/QueryObjectGenerator.js.map +1 -1
- package/lib/generator/ServiceGenerator.d.ts +5 -5
- package/lib/generator/ServiceGenerator.js +62 -65
- package/lib/generator/ServiceGenerator.js.map +1 -1
- package/lib/generator/import/ImportObjects.d.ts +3 -1
- package/lib/generator/import/ImportObjects.js +14 -15
- package/lib/generator/import/ImportObjects.js.map +1 -1
- package/lib/generator/index.d.ts +3 -3
- package/lib/generator/index.js +3 -9
- package/lib/generator/index.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.js +4 -7
- package/lib/index.js.map +1 -1
- package/lib/project/FileHandler.d.ts +3 -3
- package/lib/project/FileHandler.js +12 -16
- package/lib/project/FileHandler.js.map +1 -1
- package/lib/project/ProjectManager.d.ts +5 -5
- package/lib/project/ProjectManager.js +25 -32
- package/lib/project/ProjectManager.js.map +1 -1
- package/lib/project/TsMorphHelper.d.ts +1 -1
- package/lib/project/TsMorphHelper.js +21 -22
- package/lib/project/TsMorphHelper.js.map +1 -1
- package/lib/project/formatter/BaseFormatter.d.ts +1 -1
- package/lib/project/formatter/BaseFormatter.js +1 -5
- package/lib/project/formatter/BaseFormatter.js.map +1 -1
- package/lib/project/formatter/FileFormatter.js +1 -2
- package/lib/project/formatter/NoopFormatter.d.ts +1 -1
- package/lib/project/formatter/NoopFormatter.js +5 -9
- package/lib/project/formatter/NoopFormatter.js.map +1 -1
- package/lib/project/formatter/PrettierFormatter.d.ts +1 -1
- package/lib/project/formatter/PrettierFormatter.js +20 -25
- package/lib/project/formatter/PrettierFormatter.js.map +1 -1
- package/lib/project/formatter/index.d.ts +1 -1
- package/lib/project/formatter/index.js +6 -10
- package/lib/project/formatter/index.js.map +1 -1
- package/lib/project/logger/logFilePath.js +4 -9
- package/lib/project/logger/logFilePath.js.map +1 -1
- package/lib/run-cli.js +2 -4
- package/lib/run-cli.js.map +1 -1
- package/package.json +55 -64
- package/lib/cli.d.ts +0 -3
- package/lib/cli.js +0 -176
- package/lib/cli.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportContainer.js","sourceRoot":"","sources":["../../src/generator/ImportContainer.ts"],"names":[],"mappings":";;;;AAAA,wDAAwB;AAExB,qDAAqD;AAKrD,0DAQgC;AAChC,mEAAgE;AAOhE;;;;;;;GAOG;AACH,MAAa,eAAe;IAoB1B,YACY,IAAY,EACZ,QAAgB,EAChB,SAAoB,EACpB,aAAkE,EACzD,qBAA8B,EACvC,aAAwC;QALxC,SAAI,GAAJ,IAAI,CAAQ;QACZ,aAAQ,GAAR,QAAQ,CAAQ;QAChB,cAAS,GAAT,SAAS,CAAW;QACpB,kBAAa,GAAb,aAAa,CAAqD;QACzD,0BAAqB,GAArB,qBAAqB,CAAS;QACvC,kBAAa,GAAb,aAAa,CAA2B;QAxBpD,uDAAuD;QAC/C,gBAAW,GAAG;YACpB,OAAO,EAAE,IAAI,GAAG,EAA+B;YAC/C,QAAQ,EAAE,IAAI,GAAG,EAA+B;SACjD,CAAC;QACF,iCAAiC;QACzB,oBAAe,GAAG;YACxB,OAAO,EAAE,IAAI,GAAG,EAA+B;YAC/C,QAAQ,EAAE,IAAI,GAAG,EAA+B;SACjD,CAAC;QAEM,SAAI,GAAwB;YAClC,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,QAAQ,EAAE,IAA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YAAY,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,UAAU,CAAC,cAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAClF,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC;IAC5E,CAAC;CACF;AA1ND,0CA0NC","sourcesContent":["import path from \"path\";\r\n\r\nimport { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { ImportDeclarationStructure, OptionalKind } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport { ComplexType } from \"../data-model/DataTypeModel\";\r\nimport {\r\n ClientApiImports,\r\n CoreImports,\r\n LIB_MODULES,\r\n QueryObjectImports,\r\n ServiceImports,\r\n VERSIONED_CORE_IMPORTS,\r\n VERSIONED_SERVICE_IMPORTS,\r\n} from \"./import/ImportObjects\";\r\nimport { ImportedNameValidator } from \"./ImportedNameValidator\";\r\n\r\ntype ImportContainerType = Record<\r\n keyof typeof LIB_MODULES,\r\n { regular: Map<string, string>; typeOnly: Map<string, string> }\r\n>;\r\n\r\n/**\r\n * Handles all the import statements for a given file.\r\n *\r\n * Features a renaming mechanism, so that when the import name conflicts with an existing import a new\r\n * name is generated and returned.\r\n *\r\n * Map<string,string>\r\n */\r\nexport class ImportContainer {\r\n private readonly importedNameValidator: ImportedNameValidator;\r\n // mapping of a custom defined type to a primitive type\r\n private customTypes = {\r\n regular: new Map<string, Map<string, string>>(),\r\n typeOnly: new Map<string, Map<string, string>>(),\r\n };\r\n // imports to generated artefacts\r\n private internalImports = {\r\n regular: new Map<string, Map<string, string>>(),\r\n typeOnly: new Map<string, Map<string, string>>(),\r\n };\r\n\r\n private libs: ImportContainerType = {\r\n core: { regular: new Map(), typeOnly: new Map() },\r\n qObject: { regular: new Map(), typeOnly: new Map() },\r\n clientApi: { regular: new Map(), typeOnly: new Map() },\r\n service: { regular: new Map(), typeOnly: new Map() },\r\n };\r\n\r\n constructor(\r\n protected path: string,\r\n protected fileName: string,\r\n protected dataModel: DataModel,\r\n protected mainFileNames: { model: string; qObject: string; service: string },\r\n protected readonly bundledFileGeneration: boolean,\r\n protected reservedNames: Array<string> | undefined\r\n ) {\r\n this.importedNameValidator = new ImportedNameValidator(reservedNames);\r\n }\r\n\r\n public addCoreLib(odataVersion: ODataVersions, coreLib: CoreImports) {\r\n const isVersioned = VERSIONED_CORE_IMPORTS.includes(coreLib);\r\n const name = CoreImports[coreLib] + (isVersioned ? ODataVersions[odataVersion] : \"\");\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.core, name);\r\n\r\n // TODO: currently only types are imported, however enums could potentially be imported too\r\n this.libs.core.typeOnly.set(name, importName);\r\n\r\n return importName;\r\n }\r\n\r\n private addFromQObject(name: string, typeOnlyImport = false) {\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.qObject, name);\r\n\r\n const imports = typeOnlyImport ? this.libs.qObject.typeOnly : this.libs.qObject.regular;\r\n imports.set(name, importName);\r\n\r\n return importName;\r\n }\r\n\r\n public addQObject(qObject: QueryObjectImports | string) {\r\n return this.addFromQObject(qObject);\r\n }\r\n\r\n public addQObjectType(qObject: string) {\r\n return this.addFromQObject(qObject, true);\r\n }\r\n\r\n public addClientApi(clientApi: ClientApiImports) {\r\n const name = ClientApiImports[clientApi];\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.clientApi, name);\r\n\r\n // complete client api consists only of types\r\n this.libs.clientApi.typeOnly.set(name, importName);\r\n return importName;\r\n }\r\n\r\n public addServiceObject(odataVersion: ODataVersions, serviceObject: ServiceImports) {\r\n const isVersioned = VERSIONED_SERVICE_IMPORTS.includes(serviceObject);\r\n const name = ServiceImports[serviceObject] + (isVersioned ? ODataVersions[odataVersion] : \"\");\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.service, name);\r\n\r\n // only regular imports for the service package\r\n this.libs.service.regular.set(name, importName);\r\n return importName;\r\n }\r\n\r\n public addCustomType(moduleName: string, typeName: string, isTypeOnly: boolean = false) {\r\n const importName = this.importedNameValidator.validateName(moduleName, typeName);\r\n const imports = isTypeOnly ? this.customTypes.typeOnly : this.customTypes.regular;\r\n let importList = imports.get(moduleName);\r\n if (!importList) {\r\n importList = new Map();\r\n imports.set(moduleName, importList);\r\n }\r\n\r\n importList.set(typeName, importName);\r\n return importName;\r\n }\r\n\r\n private pathAndFile(filePath: string, fileName: string) {\r\n return filePath ? `${filePath}/${fileName}` : fileName;\r\n }\r\n\r\n private isDifferentFile(filePath: string, fileName: string) {\r\n return this.pathAndFile(this.path, this.fileName) !== this.pathAndFile(filePath, fileName);\r\n }\r\n\r\n private addGeneratedImport(folderPath: string, fileName: string, name: string, isTypeOnly = false): string {\r\n // imports are only relevant for different files\r\n if (!this.isDifferentFile(folderPath, fileName)) {\r\n return name;\r\n }\r\n\r\n const moduleName = this.pathAndFile(folderPath, fileName);\r\n const importName = this.importedNameValidator.validateName(moduleName, name);\r\n const imports = isTypeOnly ? this.internalImports.typeOnly : this.internalImports.regular;\r\n\r\n const importList = imports.get(moduleName) || new Map<string, string>();\r\n importList.set(name, importName);\r\n imports.set(moduleName, importList);\r\n\r\n return importName;\r\n }\r\n\r\n public addGeneratedModel(fqName: string, name: string): string {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.model, name, true);\r\n } else {\r\n const model = this.dataModel.getModel(fqName) as ComplexType | undefined;\r\n if (!model && fqName !== \"\") {\r\n throw new Error(`Cannot find model by its fully qualified name: ${fqName}!`);\r\n }\r\n\r\n const folderPath = model ? model.folderPath : \"\";\r\n const modelName = model ? model.modelName : this.mainFileNames.model;\r\n return this.addGeneratedImport(folderPath, modelName, name, true);\r\n }\r\n }\r\n\r\n public addGeneratedQObject(fqName: string, name: string, isTypeOnly = false) {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.qObject, name, isTypeOnly);\r\n } else {\r\n const model = this.dataModel.getModel(fqName) as ComplexType | undefined;\r\n if (!model && fqName !== \"\") {\r\n throw new Error(`Cannot find q-object by its fully qualified name: ${fqName}!`);\r\n }\r\n\r\n const folderPath = model ? model.folderPath : \"\";\r\n const qName = model ? model.qName : this.mainFileNames!.qObject;\r\n return this.addGeneratedImport(folderPath, qName, name, isTypeOnly);\r\n }\r\n }\r\n\r\n public addGeneratedService(fqName: string, name: string) {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.service, name);\r\n } else {\r\n const model = this.dataModel.getModel(fqName) as ComplexType;\r\n return this.addGeneratedImport(model.folderPath, model.serviceName, name);\r\n }\r\n }\r\n\r\n private createImportDecl(\r\n module: string,\r\n toImport: Map<string, string>,\r\n isTypeOnly = false\r\n ): OptionalKind<ImportDeclarationStructure> {\r\n return {\r\n namedImports: this.getNamedImports(toImport),\r\n moduleSpecifier: module,\r\n isTypeOnly,\r\n };\r\n }\r\n\r\n public getImportDeclarations(): Array<OptionalKind<ImportDeclarationStructure>> {\r\n return [\r\n ...Object.entries(this.libs).reduce<Array<OptionalKind<ImportDeclarationStructure>>>(\r\n (result, [moduleName, toImport]) => {\r\n const module = LIB_MODULES[moduleName as keyof typeof LIB_MODULES];\r\n if (toImport.typeOnly.size) {\r\n result.push(this.createImportDecl(module, toImport.typeOnly, true));\r\n }\r\n if (toImport.regular.size) {\r\n result.push(this.createImportDecl(module, toImport.regular));\r\n }\r\n return result;\r\n },\r\n []\r\n ),\r\n ...[...this.customTypes.typeOnly]\r\n .filter(([moduleName, toImport]) => toImport.size > 0)\r\n .map(([moduleName, toImport]) => {\r\n return this.createImportDecl(moduleName, toImport, true);\r\n }),\r\n ...[...this.customTypes.regular]\r\n .filter(([moduleName, toImport]) => toImport.size > 0)\r\n .map(([moduleName, toImport]) => {\r\n return this.createImportDecl(moduleName, toImport);\r\n }),\r\n ...[...this.internalImports.typeOnly]\r\n .filter(([_, toImport]) => toImport.size > 0)\r\n .map(([key, toImport]) => {\r\n const module = this.getModuleSpecifier(key);\r\n return this.createImportDecl(module, toImport, true);\r\n }),\r\n ...[...this.internalImports.regular]\r\n .filter(([_, toImport]) => toImport.size > 0)\r\n .map(([key, toImport]) => {\r\n const module = this.getModuleSpecifier(key);\r\n return this.createImportDecl(module, toImport);\r\n }),\r\n ];\r\n }\r\n\r\n private getNamedImports(toImport: Map<string, string>): Array<{ name: string; alias: string | undefined }> {\r\n return [...toImport.entries()].map(([name, alias]) => ({\r\n name,\r\n alias: alias !== name ? alias : undefined,\r\n }));\r\n }\r\n\r\n private getModuleSpecifier(filePath: string): string {\r\n const relativePath = path.relative(this.path, filePath).replaceAll(path.sep, \"/\");\r\n return !relativePath.startsWith(\".\") ? \"./\" + relativePath : relativePath;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ImportContainer.js","sourceRoot":"","sources":["../../src/generator/ImportContainer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,WAAW,EAEX,cAAc,EACd,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAOnE;;;;;;;GAOG;AACH,MAAM,OAAO,eAAe;IAoB1B,YACY,IAAY,EACZ,QAAgB,EAChB,SAAoB,EACpB,aAAkE,EACzD,qBAA8B,EACvC,aAAwC;QALxC,SAAI,GAAJ,IAAI,CAAQ;QACZ,aAAQ,GAAR,QAAQ,CAAQ;QAChB,cAAS,GAAT,SAAS,CAAW;QACpB,kBAAa,GAAb,aAAa,CAAqD;QACzD,0BAAqB,GAArB,qBAAqB,CAAS;QACvC,kBAAa,GAAb,aAAa,CAA2B;QAxBpD,uDAAuD;QAC/C,gBAAW,GAAG;YAC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CAAC,YAAY,CAAC;IAC5E,CAAC;CACF","sourcesContent":["import path from \"path\";\r\nimport { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { ImportDeclarationStructure, OptionalKind } from \"ts-morph\";\r\nimport { DataModel } from \"../data-model/DataModel.js\";\r\nimport { ComplexType } from \"../data-model/DataTypeModel.js\";\r\nimport {\r\n ClientApiImports,\r\n CoreImports,\r\n LIB_MODULES,\r\n QueryObjectImports,\r\n ServiceImports,\r\n VERSIONED_CORE_IMPORTS,\r\n VERSIONED_SERVICE_IMPORTS,\r\n} from \"./import/ImportObjects.js\";\r\nimport { ImportedNameValidator } from \"./ImportedNameValidator.js\";\r\n\r\ntype ImportContainerType = Record<\r\n keyof typeof LIB_MODULES,\r\n { regular: Map<string, string>; typeOnly: Map<string, string> }\r\n>;\r\n\r\n/**\r\n * Handles all the import statements for a given file.\r\n *\r\n * Features a renaming mechanism, so that when the import name conflicts with an existing import a new\r\n * name is generated and returned.\r\n *\r\n * Map<string,string>\r\n */\r\nexport class ImportContainer {\r\n private readonly importedNameValidator: ImportedNameValidator;\r\n // mapping of a custom defined type to a primitive type\r\n private customTypes = {\r\n regular: new Map<string, Map<string, string>>(),\r\n typeOnly: new Map<string, Map<string, string>>(),\r\n };\r\n // imports to generated artefacts\r\n private internalImports = {\r\n regular: new Map<string, Map<string, string>>(),\r\n typeOnly: new Map<string, Map<string, string>>(),\r\n };\r\n\r\n private libs: ImportContainerType = {\r\n core: { regular: new Map(), typeOnly: new Map() },\r\n qObject: { regular: new Map(), typeOnly: new Map() },\r\n clientApi: { regular: new Map(), typeOnly: new Map() },\r\n service: { regular: new Map(), typeOnly: new Map() },\r\n };\r\n\r\n constructor(\r\n protected path: string,\r\n protected fileName: string,\r\n protected dataModel: DataModel,\r\n protected mainFileNames: { model: string; qObject: string; service: string },\r\n protected readonly bundledFileGeneration: boolean,\r\n protected reservedNames: Array<string> | undefined,\r\n ) {\r\n this.importedNameValidator = new ImportedNameValidator(reservedNames);\r\n }\r\n\r\n public addCoreLib(odataVersion: ODataVersions, coreLib: CoreImports) {\r\n const isVersioned = VERSIONED_CORE_IMPORTS.includes(coreLib);\r\n const name = CoreImports[coreLib] + (isVersioned ? ODataVersions[odataVersion] : \"\");\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.core, name);\r\n\r\n // TODO: currently only types are imported, however enums could potentially be imported too\r\n this.libs.core.typeOnly.set(name, importName);\r\n\r\n return importName;\r\n }\r\n\r\n private addFromQObject(name: string, typeOnlyImport = false) {\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.qObject, name);\r\n\r\n const imports = this.libs.qObject;\r\n if (typeOnlyImport) {\r\n if (!imports.regular.has(name)) {\r\n imports.typeOnly.set(name, importName);\r\n }\r\n } else {\r\n if (imports.typeOnly.has(name)) {\r\n imports.typeOnly.delete(name);\r\n }\r\n imports.regular.set(name, importName);\r\n }\r\n\r\n return importName;\r\n }\r\n\r\n public addQObject(qObject: QueryObjectImports | string) {\r\n return this.addFromQObject(qObject);\r\n }\r\n\r\n public addQObjectType(qObject: string) {\r\n return this.addFromQObject(qObject, true);\r\n }\r\n\r\n public addClientApi(clientApi: ClientApiImports) {\r\n const name = ClientApiImports[clientApi];\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.clientApi, name);\r\n\r\n // complete client api consists only of types\r\n this.libs.clientApi.typeOnly.set(name, importName);\r\n return importName;\r\n }\r\n\r\n public addServiceObject(odataVersion: ODataVersions, serviceObject: ServiceImports) {\r\n const isVersioned = VERSIONED_SERVICE_IMPORTS.includes(serviceObject);\r\n const name = ServiceImports[serviceObject] + (isVersioned ? ODataVersions[odataVersion] : \"\");\r\n const importName = this.importedNameValidator.validateName(LIB_MODULES.service, name);\r\n\r\n // only regular imports for the service package\r\n this.libs.service.regular.set(name, importName);\r\n return importName;\r\n }\r\n\r\n // TODO: make sure that regular imports win over additional typeOnly imports\r\n public addCustomType(moduleName: string, typeName: string, isTypeOnly: boolean = false) {\r\n const importName = this.importedNameValidator.validateName(moduleName, typeName);\r\n const imports = isTypeOnly ? this.customTypes.typeOnly : this.customTypes.regular;\r\n let importList = imports.get(moduleName);\r\n if (!importList) {\r\n importList = new Map();\r\n imports.set(moduleName, importList);\r\n }\r\n\r\n importList.set(typeName, importName);\r\n return importName;\r\n }\r\n\r\n private pathAndFile(filePath: string, fileName: string) {\r\n return filePath ? `${filePath}/${fileName}` : fileName;\r\n }\r\n\r\n private isDifferentFile(filePath: string, fileName: string) {\r\n return this.pathAndFile(this.path, this.fileName) !== this.pathAndFile(filePath, fileName);\r\n }\r\n\r\n private addGeneratedImport(folderPath: string, fileName: string, name: string, isTypeOnly = false): string {\r\n // imports are only relevant for different files\r\n if (!this.isDifferentFile(folderPath, fileName)) {\r\n return name;\r\n }\r\n\r\n const moduleName = this.pathAndFile(folderPath, fileName);\r\n const importName = this.importedNameValidator.validateName(moduleName, name);\r\n const imports = isTypeOnly ? this.internalImports.typeOnly : this.internalImports.regular;\r\n\r\n if (isTypeOnly && this.internalImports.regular.get(moduleName)?.has(name)) {\r\n return importName;\r\n }\r\n if (!isTypeOnly && this.internalImports.typeOnly.get(moduleName)?.has(name)) {\r\n this.internalImports.typeOnly.get(moduleName)?.delete(name);\r\n }\r\n\r\n const importList = imports.get(moduleName) || new Map<string, string>();\r\n importList.set(name, importName);\r\n imports.set(moduleName, importList);\r\n\r\n return importName;\r\n }\r\n\r\n public addGeneratedModel(fqName: string, name: string, isTypeOnly = true): string {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.model, name, isTypeOnly);\r\n } else {\r\n const model = this.dataModel.getModel(fqName) as ComplexType | undefined;\r\n if (!model && fqName !== \"\") {\r\n throw new Error(`Cannot find model by its fully qualified name: ${fqName}!`);\r\n }\r\n\r\n const folderPath = model ? model.folderPath : \"\";\r\n const modelName = model ? model.modelName : this.mainFileNames.model;\r\n return this.addGeneratedImport(folderPath, modelName, name, isTypeOnly);\r\n }\r\n }\r\n\r\n public addGeneratedQObject(fqName: string, name: string, isTypeOnly = false) {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.qObject, name, isTypeOnly);\r\n } else {\r\n const model = this.dataModel.getModel(fqName) as ComplexType | undefined;\r\n if (!model && fqName !== \"\") {\r\n throw new Error(`Cannot find q-object by its fully qualified name: ${fqName}!`);\r\n }\r\n\r\n const folderPath = model ? model.folderPath : \"\";\r\n const qName = model ? model.qName : this.mainFileNames!.qObject;\r\n return this.addGeneratedImport(folderPath, qName, name, isTypeOnly);\r\n }\r\n }\r\n\r\n public addGeneratedService(fqName: string, name: string) {\r\n if (this.bundledFileGeneration) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.service, name);\r\n } else {\r\n const model = this.dataModel.getModel(fqName) as ComplexType;\r\n return this.addGeneratedImport(model.folderPath, model.serviceName, name);\r\n }\r\n }\r\n\r\n private createImportDecl(\r\n module: string,\r\n toImport: Map<string, string>,\r\n isTypeOnly = false,\r\n ): OptionalKind<ImportDeclarationStructure> {\r\n return {\r\n namedImports: this.getNamedImports(toImport),\r\n moduleSpecifier: module,\r\n isTypeOnly,\r\n };\r\n }\r\n\r\n public getImportDeclarations(): Array<OptionalKind<ImportDeclarationStructure>> {\r\n return [\r\n ...Object.entries(this.libs).reduce<Array<OptionalKind<ImportDeclarationStructure>>>(\r\n (result, [moduleName, toImport]) => {\r\n const module = LIB_MODULES[moduleName as keyof typeof LIB_MODULES];\r\n if (toImport.typeOnly.size) {\r\n result.push(this.createImportDecl(module, toImport.typeOnly, true));\r\n }\r\n if (toImport.regular.size) {\r\n result.push(this.createImportDecl(module, toImport.regular));\r\n }\r\n return result;\r\n },\r\n [],\r\n ),\r\n ...[...this.customTypes.typeOnly]\r\n .filter(([moduleName, toImport]) => toImport.size > 0)\r\n .map(([moduleName, toImport]) => {\r\n return this.createImportDecl(moduleName, toImport, true);\r\n }),\r\n ...[...this.customTypes.regular]\r\n .filter(([moduleName, toImport]) => toImport.size > 0)\r\n .map(([moduleName, toImport]) => {\r\n return this.createImportDecl(moduleName, toImport);\r\n }),\r\n ...[...this.internalImports.typeOnly]\r\n .filter(([_, toImport]) => toImport.size > 0)\r\n .map(([key, toImport]) => {\r\n const module = this.getModuleSpecifier(key);\r\n return this.createImportDecl(module, toImport, true);\r\n }),\r\n ...[...this.internalImports.regular]\r\n .filter(([_, toImport]) => toImport.size > 0)\r\n .map(([key, toImport]) => {\r\n const module = this.getModuleSpecifier(key);\r\n return this.createImportDecl(module, toImport);\r\n }),\r\n ];\r\n }\r\n\r\n private getNamedImports(toImport: Map<string, string>): Array<{ name: string; alias: string | undefined }> {\r\n return [...toImport.entries()].map(([name, alias]) => ({\r\n name,\r\n alias: alias !== name ? alias : undefined,\r\n }));\r\n }\r\n\r\n private getModuleSpecifier(filePath: string): string {\r\n const relativePath = path.relative(this.path, filePath).replaceAll(path.sep, \"/\");\r\n return !relativePath.startsWith(\".\") ? \"./\" + relativePath : relativePath;\r\n }\r\n}\r\n"]}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImportedNameValidator = void 0;
|
|
4
|
-
class ImportedNameValidator {
|
|
1
|
+
export class ImportedNameValidator {
|
|
5
2
|
constructor(reservedNames) {
|
|
6
3
|
this.importedNames = new Map();
|
|
7
4
|
reservedNames === null || reservedNames === void 0 ? void 0 : reservedNames.forEach((rn) => {
|
|
@@ -22,5 +19,4 @@ class ImportedNameValidator {
|
|
|
22
19
|
return result;
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
exports.ImportedNameValidator = ImportedNameValidator;
|
|
26
22
|
//# sourceMappingURL=ImportedNameValidator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportedNameValidator.js","sourceRoot":"","sources":["../../src/generator/ImportedNameValidator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ImportedNameValidator.js","sourceRoot":"","sources":["../../src/generator/ImportedNameValidator.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,qBAAqB;IAGhC,YAAmB,aAAyC;QAFpD,kBAAa,GAAG,IAAI,GAAG,EAAkC,CAAC;QAGhE,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;YAC5B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,YAAY,CAAC,SAAiB,EAAE,IAAY;;QACjD,MAAM,UAAU,GAAG,MAAA,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,mCAAI,EAAE,CAAC;QACtD,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;QAEtC,IAAI,OAAO,EAAE;YACX,OAAO,OAAO,CAAC;SAChB;QAED,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC;QACtD,MAAM,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,cAAc,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAEnE,UAAU,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;QAC/B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAEzC,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["export class ImportedNameValidator {\r\n private importedNames = new Map<string, Record<string, string>>();\r\n\r\n public constructor(reservedNames?: Array<string> | undefined) {\r\n reservedNames?.forEach((rn) => {\r\n this.importedNames.set(rn, { [\"_\"]: rn });\r\n });\r\n }\r\n\r\n public validateName(qualifier: string, name: string): string {\r\n const qualifiers = this.importedNames.get(name) ?? {};\r\n const hitName = qualifiers[qualifier];\r\n\r\n if (hitName) {\r\n return hitName;\r\n }\r\n\r\n const qualifiersSize = Object.keys(qualifiers).length;\r\n const result = qualifiersSize ? `${name}_${qualifiersSize}` : name;\r\n\r\n qualifiers[qualifier] = result;\r\n this.importedNames.set(name, qualifiers);\r\n\r\n return result;\r\n }\r\n}\r\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EntityBasedGeneratorFunction } from "../FactoryFunctionModel";
|
|
1
|
+
import { EntityBasedGeneratorFunction } from "../FactoryFunctionModel.js";
|
|
2
2
|
export declare const generateModels: EntityBasedGeneratorFunction;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const ts_morph_1 = require("ts-morph");
|
|
6
|
-
const ImportObjects_1 = require("./import/ImportObjects");
|
|
7
|
-
const generateModels = (project, dataModel, version, options, namingHelper) => {
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { StructureKind } from "ts-morph";
|
|
3
|
+
import { CoreImports } from "./import/ImportObjects.js";
|
|
4
|
+
export const generateModels = (project, dataModel, version, options, namingHelper) => {
|
|
8
5
|
const generator = new ModelGenerator(project, dataModel, version, options, namingHelper);
|
|
9
6
|
return generator.generate();
|
|
10
7
|
};
|
|
11
|
-
exports.generateModels = generateModels;
|
|
12
8
|
class ModelGenerator {
|
|
13
9
|
constructor(project, dataModel, version, options, namingHelper) {
|
|
14
10
|
this.project = project;
|
|
@@ -18,7 +14,7 @@ class ModelGenerator {
|
|
|
18
14
|
this.namingHelper = namingHelper;
|
|
19
15
|
}
|
|
20
16
|
generate() {
|
|
21
|
-
return
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
18
|
this.project.initModels();
|
|
23
19
|
const promises = [
|
|
24
20
|
...this.generateEnums(),
|
|
@@ -35,10 +31,14 @@ class ModelGenerator {
|
|
|
35
31
|
generateEnums() {
|
|
36
32
|
return this.dataModel.getEnums().map((et) => {
|
|
37
33
|
const file = this.project.createOrGetModelFile(et.folderPath, et.modelName);
|
|
34
|
+
const isNumeric = this.options.numericEnums;
|
|
38
35
|
file.getFile().addEnum({
|
|
39
36
|
name: et.modelName,
|
|
40
37
|
isExported: true,
|
|
41
|
-
members: et.members.map((mem) => ({
|
|
38
|
+
members: et.members.map((mem) => ({
|
|
39
|
+
name: mem.name,
|
|
40
|
+
initializer: isNumeric ? String(mem.value) : `"${mem.name}"`,
|
|
41
|
+
})),
|
|
42
42
|
});
|
|
43
43
|
return this.project.finalizeFile(file);
|
|
44
44
|
});
|
|
@@ -134,13 +134,13 @@ class ModelGenerator {
|
|
|
134
134
|
"OData Attributes:\n" +
|
|
135
135
|
"|Attribute Name | Attribute Value |\n| --- | ---|\n" +
|
|
136
136
|
attributeTable.map((row) => `| ${row[0]} | \`${row[1]}\` |`).join("\n");
|
|
137
|
-
return { kind:
|
|
137
|
+
return { kind: StructureKind.JSDoc, description };
|
|
138
138
|
}
|
|
139
139
|
getPropType(imports, prop) {
|
|
140
140
|
// V2 entity special: deferred content
|
|
141
141
|
let suffix = "";
|
|
142
142
|
if (this.dataModel.isV2() && prop.dataType == "ModelType" /* DataTypes.ModelType */) {
|
|
143
|
-
const defContent = imports.addCoreLib(this.version,
|
|
143
|
+
const defContent = imports.addCoreLib(this.version, CoreImports.DeferredContent);
|
|
144
144
|
suffix = ` | ${defContent}`;
|
|
145
145
|
}
|
|
146
146
|
let typeName;
|
|
@@ -224,7 +224,7 @@ class ModelGenerator {
|
|
|
224
224
|
return editableType + (prop.required ? "" : " | null");
|
|
225
225
|
}
|
|
226
226
|
generateUnboundOperationParams() {
|
|
227
|
-
return
|
|
227
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
228
228
|
const unboundOps = this.dataModel.getUnboundOperationTypes();
|
|
229
229
|
const reservedNames = unboundOps.map((op) => op.paramsModelName);
|
|
230
230
|
const file = this.project.createOrGetMainModelFile(reservedNames);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelGenerator.js","sourceRo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import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { JSDocStructure, OptionalKind, StructureKind } from \"ts-morph\";\r\n\r\nimport { DataModel } from \"../data-model/DataModel\";\r\nimport { ComplexType, DataTypes, EntityType, OperationType, PropertyModel } from \"../data-model/DataTypeModel\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper\";\r\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel\";\r\nimport { FileHandler } from \"../project/FileHandler\";\r\nimport { ProjectManager } from \"../project/ProjectManager\";\r\nimport { CoreImports } from \"./import/ImportObjects\";\r\nimport { ImportContainer } from \"./ImportContainer\";\r\n\r\nexport const generateModels: EntityBasedGeneratorFunction = (\r\n project: ProjectManager,\r\n dataModel,\r\n version,\r\n options,\r\n namingHelper\r\n) => {\r\n const generator = new ModelGenerator(project, dataModel, version, options, namingHelper);\r\n return generator.generate();\r\n};\r\n\r\nclass ModelGenerator {\r\n constructor(\r\n private project: ProjectManager,\r\n private dataModel: DataModel,\r\n private version: ODataVersions,\r\n private options: GeneratorFunctionOptions,\r\n private namingHelper: NamingHelper\r\n ) {}\r\n\r\n public async generate(): Promise<void> {\r\n this.project.initModels();\r\n\r\n const promises: Array<Promise<void>> = [\r\n ...this.generateEnums(),\r\n ...this.generateEntityTypeModels(),\r\n ...this.generateComplexTypeModels(),\r\n ];\r\n\r\n if (!this.options.skipOperations) {\r\n promises.push(this.generateUnboundOperationParams());\r\n }\r\n\r\n await Promise.all(promises);\r\n\r\n return this.project.finalizeModels();\r\n }\r\n\r\n private generateEnums() {\r\n return this.dataModel.getEnums().map((et) => {\r\n const file = this.project.createOrGetModelFile(et.folderPath, et.modelName);\r\n\r\n file.getFile().addEnum({\r\n name: et.modelName,\r\n isExported: true,\r\n members: et.members.map((mem) => ({ name: mem, initializer: `\"${mem}\"` })),\r\n });\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateEntityTypeModels() {\r\n return this.dataModel.getEntityTypes().map((model) => {\r\n const file = this.project.createOrGetModelFile(model.folderPath, model.modelName, [\r\n model.modelName,\r\n model.id.modelName,\r\n model.editableName,\r\n ]);\r\n\r\n // query model\r\n this.generateModel(file, model);\r\n\r\n // key model\r\n if (!this.options.skipIdModels && model.generateId) {\r\n this.generateIdModel(file, model);\r\n }\r\n\r\n // editable model\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(file, model);\r\n }\r\n\r\n // param models for bound operations\r\n if (!this.options.skipOperations) {\r\n [\r\n ...this.dataModel.getEntityTypeOperations(model.fqName),\r\n ...this.dataModel.getEntitySetOperations(model.fqName),\r\n ].forEach((operation) => {\r\n this.generateOperationParams(file, operation);\r\n });\r\n }\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateComplexTypeModels() {\r\n return this.dataModel.getComplexTypes().map((model) => {\r\n const file = this.project.createOrGetModelFile(model.folderPath, model.modelName, [\r\n model.modelName,\r\n model.editableName,\r\n ]);\r\n\r\n // query model\r\n this.generateModel(file, model);\r\n\r\n // editable model\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(file, model);\r\n }\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateModel(file: FileHandler, model: ComplexType | EntityType) {\r\n const imports = file.getImports();\r\n let extendsClause = undefined;\r\n if (model.finalBaseClass) {\r\n const modelName = imports.addGeneratedModel(\r\n model.baseClasses[0],\r\n this.namingHelper.getModelName(model.finalBaseClass)\r\n );\r\n extendsClause = [modelName];\r\n }\r\n\r\n file.getFile().addInterface({\r\n name: model.modelName,\r\n isExported: true,\r\n properties: model.props.map((p) => {\r\n const isEntity = p.dataType == DataTypes.ModelType;\r\n return {\r\n name: p.name,\r\n type: this.getPropType(file.getImports(), p),\r\n // props for entities or entity collections are not added in V4 if not explicitly expanded\r\n hasQuestionToken: this.dataModel.isV4() && isEntity,\r\n docs: this.options.skipComments ? undefined : [this.generatePropDoc(p, model)],\r\n };\r\n }),\r\n extends: extendsClause,\r\n });\r\n }\r\n\r\n private generatePropDoc(prop: PropertyModel, model: ComplexType | EntityType): OptionalKind<JSDocStructure> {\r\n const isKeyProp = (model as EntityType).keyNames?.includes(prop.odataName);\r\n const baseAttribs: Array<string> = [];\r\n if (isKeyProp) {\r\n baseAttribs.push(\"**Key Property**: This is a key property used to identify the entity.\");\r\n }\r\n if (prop.managed) {\r\n baseAttribs.push(\"**Managed**: This property is managed on the server side and cannot be edited.\");\r\n }\r\n if (prop.converters?.length) {\r\n baseAttribs.push(`**Applied Converters**: ${prop.converters.map((c) => c.converterId).join(\",\")}.`);\r\n }\r\n\r\n const attributeTable: Array<[string, string]> = [\r\n [\"Name\", prop.odataName],\r\n [\"Type\", prop.odataType],\r\n ];\r\n if (prop.required) {\r\n attributeTable.push([\"Nullable\", \"false\"]);\r\n }\r\n\r\n const description =\r\n (baseAttribs ? baseAttribs.join(\"<br/>\") + \"\\n\\n\" : \"\") +\r\n \"OData Attributes:\\n\" +\r\n \"|Attribute Name | Attribute Value |\\n| --- | ---|\\n\" +\r\n attributeTable.map((row) => `| ${row[0]} | \\`${row[1]}\\` |`).join(\"\\n\");\r\n\r\n return { kind: StructureKind.JSDoc, description };\r\n }\r\n\r\n private getPropType(imports: ImportContainer, prop: PropertyModel): string {\r\n // V2 entity special: deferred content\r\n let suffix = \"\";\r\n if (this.dataModel.isV2() && prop.dataType == DataTypes.ModelType) {\r\n const defContent = imports.addCoreLib(this.version, CoreImports.DeferredContent);\r\n suffix = ` | ${defContent}`;\r\n }\r\n\r\n let typeName: string;\r\n if (prop.dataType === DataTypes.PrimitiveType) {\r\n // custom types which require type imports => possible via converters\r\n typeName = prop.typeModule ? imports.addCustomType(prop.typeModule, prop.type, true) : prop.type;\r\n } else {\r\n typeName = imports.addGeneratedModel(prop.fqType, prop.type);\r\n }\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n const type = `Array<${typeName}>`;\r\n if (this.dataModel.isV2() && this.options.v2ModelsWithExtraResultsWrapping) {\r\n return `{ results: ${type} }` + suffix;\r\n } else {\r\n return type + suffix;\r\n }\r\n }\r\n\r\n // primitive, enum & complex types\r\n return typeName + (prop.required ? \"\" : \" | null\") + suffix;\r\n }\r\n\r\n private generateIdModel(file: FileHandler, model: EntityType) {\r\n const singleType = model.keys.length === 1 ? `${model.keys[0].type} | ` : \"\";\r\n const keyTypes = model.keys\r\n .map((keyProp) => `${keyProp.name}: ${this.getPropType(file.getImports(), keyProp)}`)\r\n .join(\",\");\r\n const type = `${singleType}{${keyTypes}}`;\r\n\r\n file.getFile().addTypeAlias({\r\n name: model.id.modelName,\r\n isExported: true,\r\n type,\r\n });\r\n }\r\n\r\n private generateEditableModel(file: FileHandler, model: ComplexType) {\r\n const entityTypes = [DataTypes.ModelType, DataTypes.ComplexType];\r\n const allProps = [...model.baseProps, ...model.props].filter((p) => !p.managed);\r\n\r\n const requiredProps = allProps\r\n .filter((p) => p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const optionalProps = allProps\r\n .filter((p) => !p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const complexProps = allProps.filter((p) => p.dataType === DataTypes.ComplexType);\r\n\r\n const extendsClause = [\r\n requiredProps ? `Pick<${model.modelName}, ${requiredProps}>` : null,\r\n optionalProps ? `Partial<Pick<${model.modelName}, ${optionalProps}>>` : null,\r\n ].filter((e): e is string => !!e);\r\n\r\n file.getFile().addInterface({\r\n name: model.editableName,\r\n isExported: true,\r\n extends: extendsClause,\r\n properties: !complexProps\r\n ? undefined\r\n : complexProps.map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getEditablePropType(file.getImports(), p),\r\n // optional props don't need to be specified in editable model\r\n // also, entities would require deep insert func => we make it optional for now\r\n hasQuestionToken: !p.required || p.dataType === DataTypes.ModelType,\r\n };\r\n }),\r\n });\r\n }\r\n\r\n private getEditablePropType(imports: ImportContainer, prop: PropertyModel): string {\r\n const isModelType = [DataTypes.ModelType, DataTypes.ComplexType].includes(prop.dataType);\r\n\r\n let editableType = prop.type;\r\n if (isModelType) {\r\n const editName = this.dataModel.getComplexType(prop.fqType)!.editableName;\r\n editableType = imports.addGeneratedModel(prop.fqType, editName);\r\n }\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n return `Array<${editableType}>`;\r\n }\r\n\r\n // primitive, enum & complex types\r\n return editableType + (prop.required ? \"\" : \" | null\");\r\n }\r\n\r\n private async generateUnboundOperationParams() {\r\n const unboundOps = this.dataModel.getUnboundOperationTypes();\r\n const reservedNames = unboundOps.map((op) => op.paramsModelName);\r\n const file = this.project.createOrGetMainModelFile(reservedNames);\r\n\r\n unboundOps.forEach((operation) => {\r\n this.generateOperationParams(file, operation);\r\n });\r\n }\r\n\r\n private generateOperationParams(file: FileHandler, operation: OperationType) {\r\n const paramSets = [operation.parameters, ...(operation.overrides ?? [])].filter((pSet) => !!pSet.length);\r\n\r\n // standard: one interface for parameters\r\n if (paramSets.length === 1) {\r\n file.getFile().addInterface({\r\n name: operation.paramsModelName,\r\n isExported: true,\r\n properties: paramSets[0].map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getPropType(file.getImports(), p),\r\n hasQuestionToken: !p.required,\r\n };\r\n }),\r\n });\r\n }\r\n // function overload: one type with intersections of different param models\r\n else if (paramSets.length > 1) {\r\n file.getFile().addTypeAlias({\r\n name: operation.paramsModelName,\r\n isExported: true,\r\n type: (writer) => {\r\n paramSets.forEach((pSet, index) => {\r\n writer.block(() => {\r\n pSet.forEach((param, index) => {\r\n const paramType = this.getPropType(file.getImports(), param);\r\n writer.write(`${param.name}${param.required ? \"\" : \"?\"}: ${paramType}`);\r\n if (index < pSet.length - 1) {\r\n writer.write(\",\");\r\n }\r\n });\r\n });\r\n if (index < paramSets.length - 1) {\r\n writer.write(\" | \");\r\n }\r\n });\r\n },\r\n });\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ModelGenerator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AC;wBACL,CAAC,CAAC,CAAC;wBACH,IAAI,KAAK,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;4BAChC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;yBACrB;oBACH,CAAC,CAAC,CAAC;gBACL,CAAC;aACF,CAAC,CAAC;SACJ;IACH,CAAC;CACF","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\nimport { JSDocStructure, OptionalKind, StructureKind } from \"ts-morph\";\r\nimport { DataModel } from \"../data-model/DataModel.js\";\r\nimport { ComplexType, DataTypes, EntityType, OperationType, PropertyModel } from \"../data-model/DataTypeModel.js\";\r\nimport { NamingHelper } from \"../data-model/NamingHelper.js\";\r\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel.js\";\r\nimport { FileHandler } from \"../project/FileHandler.js\";\r\nimport { ProjectManager } from \"../project/ProjectManager.js\";\r\nimport { CoreImports } from \"./import/ImportObjects.js\";\r\nimport { ImportContainer } from \"./ImportContainer.js\";\r\n\r\nexport const generateModels: EntityBasedGeneratorFunction = (\r\n project: ProjectManager,\r\n dataModel,\r\n version,\r\n options,\r\n namingHelper,\r\n) => {\r\n const generator = new ModelGenerator(project, dataModel, version, options, namingHelper);\r\n return generator.generate();\r\n};\r\n\r\nclass ModelGenerator {\r\n constructor(\r\n private project: ProjectManager,\r\n private dataModel: DataModel,\r\n private version: ODataVersions,\r\n private options: GeneratorFunctionOptions,\r\n private namingHelper: NamingHelper,\r\n ) {}\r\n\r\n public async generate(): Promise<void> {\r\n this.project.initModels();\r\n\r\n const promises: Array<Promise<void>> = [\r\n ...this.generateEnums(),\r\n ...this.generateEntityTypeModels(),\r\n ...this.generateComplexTypeModels(),\r\n ];\r\n\r\n if (!this.options.skipOperations) {\r\n promises.push(this.generateUnboundOperationParams());\r\n }\r\n\r\n await Promise.all(promises);\r\n\r\n return this.project.finalizeModels();\r\n }\r\n\r\n private generateEnums() {\r\n return this.dataModel.getEnums().map((et) => {\r\n const file = this.project.createOrGetModelFile(et.folderPath, et.modelName);\r\n\r\n const isNumeric = this.options.numericEnums;\r\n file.getFile().addEnum({\r\n name: et.modelName,\r\n isExported: true,\r\n members: et.members.map((mem) => ({\r\n name: mem.name,\r\n initializer: isNumeric ? String(mem.value) : `\"${mem.name}\"`,\r\n })),\r\n });\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateEntityTypeModels() {\r\n return this.dataModel.getEntityTypes().map((model) => {\r\n const file = this.project.createOrGetModelFile(model.folderPath, model.modelName, [\r\n model.modelName,\r\n model.id.modelName,\r\n model.editableName,\r\n ]);\r\n\r\n // query model\r\n this.generateModel(file, model);\r\n\r\n // key model\r\n if (!this.options.skipIdModels && model.generateId) {\r\n this.generateIdModel(file, model);\r\n }\r\n\r\n // editable model\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(file, model);\r\n }\r\n\r\n // param models for bound operations\r\n if (!this.options.skipOperations) {\r\n [\r\n ...this.dataModel.getEntityTypeOperations(model.fqName),\r\n ...this.dataModel.getEntitySetOperations(model.fqName),\r\n ].forEach((operation) => {\r\n this.generateOperationParams(file, operation);\r\n });\r\n }\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateComplexTypeModels() {\r\n return this.dataModel.getComplexTypes().map((model) => {\r\n const file = this.project.createOrGetModelFile(model.folderPath, model.modelName, [\r\n model.modelName,\r\n model.editableName,\r\n ]);\r\n\r\n // query model\r\n this.generateModel(file, model);\r\n\r\n // editable model\r\n if (!this.options.skipEditableModels) {\r\n this.generateEditableModel(file, model);\r\n }\r\n\r\n return this.project.finalizeFile(file);\r\n });\r\n }\r\n\r\n private generateModel(file: FileHandler, model: ComplexType | EntityType) {\r\n const imports = file.getImports();\r\n let extendsClause = undefined;\r\n if (model.finalBaseClass) {\r\n const modelName = imports.addGeneratedModel(\r\n model.baseClasses[0],\r\n this.namingHelper.getModelName(model.finalBaseClass),\r\n );\r\n extendsClause = [modelName];\r\n }\r\n\r\n file.getFile().addInterface({\r\n name: model.modelName,\r\n isExported: true,\r\n properties: model.props.map((p) => {\r\n const isEntity = p.dataType == DataTypes.ModelType;\r\n return {\r\n name: p.name,\r\n type: this.getPropType(file.getImports(), p),\r\n // props for entities or entity collections are not added in V4 if not explicitly expanded\r\n hasQuestionToken: this.dataModel.isV4() && isEntity,\r\n docs: this.options.skipComments ? undefined : [this.generatePropDoc(p, model)],\r\n };\r\n }),\r\n extends: extendsClause,\r\n });\r\n }\r\n\r\n private generatePropDoc(prop: PropertyModel, model: ComplexType | EntityType): OptionalKind<JSDocStructure> {\r\n const isKeyProp = (model as EntityType).keyNames?.includes(prop.odataName);\r\n const baseAttribs: Array<string> = [];\r\n if (isKeyProp) {\r\n baseAttribs.push(\"**Key Property**: This is a key property used to identify the entity.\");\r\n }\r\n if (prop.managed) {\r\n baseAttribs.push(\"**Managed**: This property is managed on the server side and cannot be edited.\");\r\n }\r\n if (prop.converters?.length) {\r\n baseAttribs.push(`**Applied Converters**: ${prop.converters.map((c) => c.converterId).join(\",\")}.`);\r\n }\r\n\r\n const attributeTable: Array<[string, string]> = [\r\n [\"Name\", prop.odataName],\r\n [\"Type\", prop.odataType],\r\n ];\r\n if (prop.required) {\r\n attributeTable.push([\"Nullable\", \"false\"]);\r\n }\r\n\r\n const description =\r\n (baseAttribs ? baseAttribs.join(\"<br/>\") + \"\\n\\n\" : \"\") +\r\n \"OData Attributes:\\n\" +\r\n \"|Attribute Name | Attribute Value |\\n| --- | ---|\\n\" +\r\n attributeTable.map((row) => `| ${row[0]} | \\`${row[1]}\\` |`).join(\"\\n\");\r\n\r\n return { kind: StructureKind.JSDoc, description };\r\n }\r\n\r\n private getPropType(imports: ImportContainer, prop: PropertyModel): string {\r\n // V2 entity special: deferred content\r\n let suffix = \"\";\r\n if (this.dataModel.isV2() && prop.dataType == DataTypes.ModelType) {\r\n const defContent = imports.addCoreLib(this.version, CoreImports.DeferredContent);\r\n suffix = ` | ${defContent}`;\r\n }\r\n\r\n let typeName: string;\r\n if (prop.dataType === DataTypes.PrimitiveType) {\r\n // custom types which require type imports => possible via converters\r\n typeName = prop.typeModule ? imports.addCustomType(prop.typeModule, prop.type, true) : prop.type;\r\n } else {\r\n typeName = imports.addGeneratedModel(prop.fqType, prop.type);\r\n }\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n const type = `Array<${typeName}>`;\r\n if (this.dataModel.isV2() && this.options.v2ModelsWithExtraResultsWrapping) {\r\n return `{ results: ${type} }` + suffix;\r\n } else {\r\n return type + suffix;\r\n }\r\n }\r\n\r\n // primitive, enum & complex types\r\n return typeName + (prop.required ? \"\" : \" | null\") + suffix;\r\n }\r\n\r\n private generateIdModel(file: FileHandler, model: EntityType) {\r\n const singleType = model.keys.length === 1 ? `${model.keys[0].type} | ` : \"\";\r\n const keyTypes = model.keys\r\n .map((keyProp) => `${keyProp.name}: ${this.getPropType(file.getImports(), keyProp)}`)\r\n .join(\",\");\r\n const type = `${singleType}{${keyTypes}}`;\r\n\r\n file.getFile().addTypeAlias({\r\n name: model.id.modelName,\r\n isExported: true,\r\n type,\r\n });\r\n }\r\n\r\n private generateEditableModel(file: FileHandler, model: ComplexType) {\r\n const entityTypes = [DataTypes.ModelType, DataTypes.ComplexType];\r\n const allProps = [...model.baseProps, ...model.props].filter((p) => !p.managed);\r\n\r\n const requiredProps = allProps\r\n .filter((p) => p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const optionalProps = allProps\r\n .filter((p) => !p.required && !entityTypes.includes(p.dataType))\r\n .map((p) => `\"${p.name}\"`)\r\n .join(\" | \");\r\n const complexProps = allProps.filter((p) => p.dataType === DataTypes.ComplexType);\r\n\r\n const extendsClause = [\r\n requiredProps ? `Pick<${model.modelName}, ${requiredProps}>` : null,\r\n optionalProps ? `Partial<Pick<${model.modelName}, ${optionalProps}>>` : null,\r\n ].filter((e): e is string => !!e);\r\n\r\n file.getFile().addInterface({\r\n name: model.editableName,\r\n isExported: true,\r\n extends: extendsClause,\r\n properties: !complexProps\r\n ? undefined\r\n : complexProps.map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getEditablePropType(file.getImports(), p),\r\n // optional props don't need to be specified in editable model\r\n // also, entities would require deep insert func => we make it optional for now\r\n hasQuestionToken: !p.required || p.dataType === DataTypes.ModelType,\r\n };\r\n }),\r\n });\r\n }\r\n\r\n private getEditablePropType(imports: ImportContainer, prop: PropertyModel): string {\r\n const isModelType = [DataTypes.ModelType, DataTypes.ComplexType].includes(prop.dataType);\r\n\r\n let editableType = prop.type;\r\n if (isModelType) {\r\n const editName = this.dataModel.getComplexType(prop.fqType)!.editableName;\r\n editableType = imports.addGeneratedModel(prop.fqType, editName);\r\n }\r\n\r\n // Collections\r\n if (prop.isCollection) {\r\n return `Array<${editableType}>`;\r\n }\r\n\r\n // primitive, enum & complex types\r\n return editableType + (prop.required ? \"\" : \" | null\");\r\n }\r\n\r\n private async generateUnboundOperationParams() {\r\n const unboundOps = this.dataModel.getUnboundOperationTypes();\r\n const reservedNames = unboundOps.map((op) => op.paramsModelName);\r\n const file = this.project.createOrGetMainModelFile(reservedNames);\r\n\r\n unboundOps.forEach((operation) => {\r\n this.generateOperationParams(file, operation);\r\n });\r\n }\r\n\r\n private generateOperationParams(file: FileHandler, operation: OperationType) {\r\n const paramSets = [operation.parameters, ...(operation.overrides ?? [])].filter((pSet) => !!pSet.length);\r\n\r\n // standard: one interface for parameters\r\n if (paramSets.length === 1) {\r\n file.getFile().addInterface({\r\n name: operation.paramsModelName,\r\n isExported: true,\r\n properties: paramSets[0].map((p) => {\r\n return {\r\n name: p.name,\r\n type: this.getPropType(file.getImports(), p),\r\n hasQuestionToken: !p.required,\r\n };\r\n }),\r\n });\r\n }\r\n // function overload: one type with intersections of different param models\r\n else if (paramSets.length > 1) {\r\n file.getFile().addTypeAlias({\r\n name: operation.paramsModelName,\r\n isExported: true,\r\n type: (writer) => {\r\n paramSets.forEach((pSet, index) => {\r\n writer.block(() => {\r\n pSet.forEach((param, index) => {\r\n const paramType = this.getPropType(file.getImports(), param);\r\n writer.write(`${param.name}${param.required ? \"\" : \"?\"}: ${paramType}`);\r\n if (index < pSet.length - 1) {\r\n writer.write(\",\");\r\n }\r\n });\r\n });\r\n if (index < paramSets.length - 1) {\r\n writer.write(\" | \");\r\n }\r\n });\r\n },\r\n });\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EntityBasedGeneratorFunction } from "../FactoryFunctionModel";
|
|
1
|
+
import { EntityBasedGeneratorFunction } from "../FactoryFunctionModel.js";
|
|
2
2
|
export declare const generateQueryObjects: EntityBasedGeneratorFunction;
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const processors_1 = require("xml2js/lib/processors");
|
|
8
|
-
const ImportObjects_1 = require("./import/ImportObjects");
|
|
9
|
-
const generateQueryObjects = (project, dataModel, version, options, namingHelper) => {
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { ODataVersions } from "@odata2ts/odata-core";
|
|
3
|
+
import { Scope, VariableDeclarationKind } from "ts-morph";
|
|
4
|
+
import { firstCharLowerCase } from "xml2js/lib/processors.js";
|
|
5
|
+
import { QueryObjectImports } from "./import/ImportObjects.js";
|
|
6
|
+
export const generateQueryObjects = (project, dataModel, version, options, namingHelper) => {
|
|
10
7
|
const generator = new QueryObjectGenerator(project, dataModel, version, options, namingHelper);
|
|
11
8
|
return generator.generate();
|
|
12
9
|
};
|
|
13
|
-
exports.generateQueryObjects = generateQueryObjects;
|
|
14
10
|
class QueryObjectGenerator {
|
|
15
11
|
constructor(project, dataModel, version, options, namingHelper) {
|
|
16
12
|
this.project = project;
|
|
@@ -20,7 +16,7 @@ class QueryObjectGenerator {
|
|
|
20
16
|
this.namingHelper = namingHelper;
|
|
21
17
|
}
|
|
22
18
|
generate() {
|
|
23
|
-
return
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
20
|
this.project.initQObjects();
|
|
25
21
|
// process EntityType & ComplexType
|
|
26
22
|
const promises = [...this.generateEntityTypes(), ...this.generateComplexTypes()];
|
|
@@ -36,7 +32,7 @@ class QueryObjectGenerator {
|
|
|
36
32
|
return this.dataModel.getEntityTypes().map((model) => {
|
|
37
33
|
const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [
|
|
38
34
|
model.qName,
|
|
39
|
-
|
|
35
|
+
firstCharLowerCase(model.qName),
|
|
40
36
|
model.id.qName,
|
|
41
37
|
]);
|
|
42
38
|
// q object
|
|
@@ -61,7 +57,7 @@ class QueryObjectGenerator {
|
|
|
61
57
|
return this.dataModel.getComplexTypes().map((model) => {
|
|
62
58
|
const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [
|
|
63
59
|
model.qName,
|
|
64
|
-
|
|
60
|
+
firstCharLowerCase(model.qName),
|
|
65
61
|
]);
|
|
66
62
|
this.generateModel(file, model);
|
|
67
63
|
return this.project.finalizeFile(file);
|
|
@@ -79,7 +75,7 @@ class QueryObjectGenerator {
|
|
|
79
75
|
extendsClause = imports.addGeneratedQObject(baseClass, baseModel.qName);
|
|
80
76
|
}
|
|
81
77
|
else {
|
|
82
|
-
extendsClause = imports.addQObject(
|
|
78
|
+
extendsClause = imports.addQObject(QueryObjectImports.QueryObject);
|
|
83
79
|
}
|
|
84
80
|
file.getFile().addClass({
|
|
85
81
|
name: model.qName,
|
|
@@ -89,11 +85,11 @@ class QueryObjectGenerator {
|
|
|
89
85
|
properties: this.generateQueryObjectProps(file.getImports(), model.props),
|
|
90
86
|
});
|
|
91
87
|
file.getFile().addVariableStatement({
|
|
92
|
-
declarationKind:
|
|
88
|
+
declarationKind: VariableDeclarationKind.Const,
|
|
93
89
|
isExported: true,
|
|
94
90
|
declarations: [
|
|
95
91
|
{
|
|
96
|
-
name:
|
|
92
|
+
name: firstCharLowerCase(model.qName),
|
|
97
93
|
initializer: `new ${model.qName}()`,
|
|
98
94
|
},
|
|
99
95
|
],
|
|
@@ -104,14 +100,24 @@ class QueryObjectGenerator {
|
|
|
104
100
|
const { odataName } = prop;
|
|
105
101
|
const name = this.namingHelper.getQPropName(prop.name);
|
|
106
102
|
const isModelType = prop.dataType === "ModelType" /* DataTypes.ModelType */ || prop.dataType === "ComplexType" /* DataTypes.ComplexType */;
|
|
103
|
+
const isEnumType = prop.dataType === "EnumType" /* DataTypes.EnumType */;
|
|
104
|
+
const isNumericEnum = this.options.numericEnums;
|
|
107
105
|
let qPathInit;
|
|
108
106
|
// factor in collections
|
|
109
107
|
if (prop.isCollection) {
|
|
110
|
-
const qPath = importContainer.addQObject(isModelType
|
|
108
|
+
const qPath = importContainer.addQObject(isModelType
|
|
109
|
+
? QueryObjectImports.QEntityCollectionPath
|
|
110
|
+
: isEnumType
|
|
111
|
+
? isNumericEnum
|
|
112
|
+
? QueryObjectImports.QNumericEnumCollectionPath
|
|
113
|
+
: QueryObjectImports.QEnumCollectionPath
|
|
114
|
+
: QueryObjectImports.QCollectionPath);
|
|
111
115
|
const qObject = isModelType
|
|
112
116
|
? importContainer.addGeneratedQObject(prop.fqType, prop.qObject)
|
|
113
|
-
:
|
|
114
|
-
|
|
117
|
+
: isEnumType
|
|
118
|
+
? importContainer.addGeneratedModel(prop.fqType, prop.type, false)
|
|
119
|
+
: importContainer.addQObject(prop.qObject);
|
|
120
|
+
qPathInit = `new ${qPath}(this.withPrefix("${odataName}"), ${isEnumType ? qObject : `() => ${qObject}`})`;
|
|
115
121
|
}
|
|
116
122
|
else {
|
|
117
123
|
// add import for data type
|
|
@@ -120,6 +126,10 @@ class QueryObjectGenerator {
|
|
|
120
126
|
const qObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject);
|
|
121
127
|
qPathInit = `new ${qPath}(this.withPrefix("${odataName}"), () => ${qObject})`;
|
|
122
128
|
}
|
|
129
|
+
else if (isEnumType) {
|
|
130
|
+
const qObject = importContainer.addGeneratedModel(prop.fqType, prop.type, false);
|
|
131
|
+
qPathInit = `new ${qPath}(this.withPrefix("${odataName}"), ${qObject})`;
|
|
132
|
+
}
|
|
123
133
|
else {
|
|
124
134
|
let converterStmt = this.generateConverterStmt(importContainer, prop.converters);
|
|
125
135
|
qPathInit = `new ${qPath}(this.withPrefix("${odataName}")${converterStmt ? `, ${converterStmt}` : ""})`;
|
|
@@ -127,7 +137,7 @@ class QueryObjectGenerator {
|
|
|
127
137
|
}
|
|
128
138
|
return {
|
|
129
139
|
name,
|
|
130
|
-
scope:
|
|
140
|
+
scope: Scope.Public,
|
|
131
141
|
isReadonly: true,
|
|
132
142
|
initializer: qPathInit,
|
|
133
143
|
};
|
|
@@ -151,7 +161,7 @@ class QueryObjectGenerator {
|
|
|
151
161
|
}
|
|
152
162
|
generateIdFunction(file, model) {
|
|
153
163
|
const importContainer = file.getImports();
|
|
154
|
-
const qFunc = importContainer.addQObject(
|
|
164
|
+
const qFunc = importContainer.addQObject(QueryObjectImports.QId);
|
|
155
165
|
const idModelName = importContainer.addGeneratedModel(model.fqName, model.id.modelName);
|
|
156
166
|
file.getFile().addClass({
|
|
157
167
|
name: model.id.qName,
|
|
@@ -160,7 +170,7 @@ class QueryObjectGenerator {
|
|
|
160
170
|
properties: [
|
|
161
171
|
{
|
|
162
172
|
name: "params",
|
|
163
|
-
scope:
|
|
173
|
+
scope: Scope.Private,
|
|
164
174
|
isReadonly: true,
|
|
165
175
|
initializer: this.getParamInitString(importContainer, model.keys),
|
|
166
176
|
},
|
|
@@ -201,7 +211,7 @@ class QueryObjectGenerator {
|
|
|
201
211
|
return allParams.length === 1 ? allParams[0] : `[${allParams.join(",")}]`;
|
|
202
212
|
}
|
|
203
213
|
generateUnboundOperations() {
|
|
204
|
-
return
|
|
214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
215
|
const unboundOps = this.dataModel.getUnboundOperationTypes();
|
|
206
216
|
const reservedNames = unboundOps.map((op) => op.qName);
|
|
207
217
|
const file = this.project.createOrGetMainQObjectFile(reservedNames);
|
|
@@ -213,12 +223,12 @@ class QueryObjectGenerator {
|
|
|
213
223
|
generateOperation(file, operation, baseFqName) {
|
|
214
224
|
var _a, _b;
|
|
215
225
|
const imports = file.getImports();
|
|
216
|
-
const isV2 = this.version ===
|
|
226
|
+
const isV2 = this.version === ODataVersions.V2;
|
|
217
227
|
const returnType = operation.returnType;
|
|
218
228
|
const hasParams = operation.parameters.length > 0 || ((_a = operation.overrides) === null || _a === void 0 ? void 0 : _a.length);
|
|
219
229
|
const isParamsOptional = !![operation.parameters, ...((_b = operation.overrides) !== null && _b !== void 0 ? _b : [])].find((pSet) => pSet.length === 0);
|
|
220
230
|
// imports
|
|
221
|
-
const qOp = operation.type === "Action" /* OperationTypes.Action */ ?
|
|
231
|
+
const qOp = operation.type === "Action" /* OperationTypes.Action */ ? QueryObjectImports.QAction : QueryObjectImports.QFunction;
|
|
222
232
|
const qOperation = imports.addQObject(qOp);
|
|
223
233
|
const paramModelName = hasParams ? imports.addGeneratedModel(baseFqName, operation.paramsModelName) : undefined;
|
|
224
234
|
let returnTypeOpStmt = "";
|
|
@@ -226,17 +236,17 @@ class QueryObjectGenerator {
|
|
|
226
236
|
const collectionSuffix = returnType.isCollection ? "_COLLECTION" : "";
|
|
227
237
|
if (returnType.dataType === "ComplexType" /* DataTypes.ComplexType */ || returnType.dataType === "ModelType" /* DataTypes.ModelType */) {
|
|
228
238
|
if (returnType.qObject) {
|
|
229
|
-
const opRt = imports.addQObject(
|
|
230
|
-
const rts = imports.addQObject(
|
|
231
|
-
const qComplexParam = imports.addQObject(
|
|
239
|
+
const opRt = imports.addQObject(QueryObjectImports.OperationReturnType);
|
|
240
|
+
const rts = imports.addQObject(QueryObjectImports.ReturnTypes);
|
|
241
|
+
const qComplexParam = imports.addQObject(QueryObjectImports.QComplexParam);
|
|
232
242
|
const returnQName = imports.addGeneratedQObject(returnType.fqType, returnType.qObject);
|
|
233
243
|
returnTypeOpStmt = `new ${opRt}(${rts}.COMPLEX${collectionSuffix}, new ${qComplexParam}("NONE", new ${returnQName}))`;
|
|
234
244
|
}
|
|
235
245
|
}
|
|
236
246
|
// currently, it only makes sense to add the OperationReturnType if a converter is present
|
|
237
247
|
else if (returnType.converters && returnType.qParam) {
|
|
238
|
-
const rtClass = imports.addQObject(
|
|
239
|
-
const rtTypes = imports.addQObject(
|
|
248
|
+
const rtClass = imports.addQObject(QueryObjectImports.OperationReturnType);
|
|
249
|
+
const rtTypes = imports.addQObject(QueryObjectImports.ReturnTypes);
|
|
240
250
|
const qParam = imports.addQObject(returnType.qParam);
|
|
241
251
|
// TODO: some constants with string concat
|
|
242
252
|
const rtKind = `${rtTypes}.VALUE${collectionSuffix}`;
|
|
@@ -253,7 +263,7 @@ class QueryObjectGenerator {
|
|
|
253
263
|
properties: [
|
|
254
264
|
{
|
|
255
265
|
name: "params",
|
|
256
|
-
scope:
|
|
266
|
+
scope: Scope.Private,
|
|
257
267
|
isReadonly: true,
|
|
258
268
|
type: hasParams ? undefined : "[]",
|
|
259
269
|
initializer: this.getParamInitString(imports, operation.parameters, operation.overrides),
|