@odata2ts/odata2ts 0.40.1 → 0.40.2
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 +25 -0
- package/lib/FactoryFunctionModel.d.ts +2 -2
- package/lib/FactoryFunctionModel.js.map +1 -1
- package/lib/OptionModel.d.ts +8 -0
- package/lib/OptionModel.js.map +1 -1
- package/lib/data-model/DataModelDigestion.js +23 -5
- package/lib/data-model/DataModelDigestion.js.map +1 -1
- package/lib/data-model/QueryObjectTypes.d.ts +13 -0
- package/lib/data-model/QueryObjectTypes.js +15 -0
- package/lib/data-model/QueryObjectTypes.js.map +1 -0
- package/lib/defaultConfig.js +1 -0
- package/lib/defaultConfig.js.map +1 -1
- package/lib/generator/ImportContainer.d.ts +3 -0
- package/lib/generator/ImportContainer.js +11 -0
- package/lib/generator/ImportContainer.js.map +1 -1
- package/lib/generator/QueryObjectGenerator.js +58 -38
- package/lib/generator/QueryObjectGenerator.js.map +1 -1
- package/lib/generator/ServiceGenerator.js +1 -1
- package/lib/generator/ServiceGenerator.js.map +1 -1
- package/lib/generator/import/ImportObjects.d.ts +0 -6
- package/lib/generator/import/ImportObjects.js +0 -6
- package/lib/generator/import/ImportObjects.js.map +1 -1
- package/lib/project/ProjectManager.js +2 -2
- package/lib/project/ProjectManager.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
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;;;;;;;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C,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SAC1C,CAAC,CAAC,CAAC;IACN,CAAC;IAEO,kBAAkB,CAAC,QAAgB;QACzC,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,UAAU,CAAC,IAAI,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","sourcesContent":["import path from \"path\";\nimport { ODataVersions } from \"@odata2ts/odata-core\";\nimport { ImportDeclarationStructure, OptionalKind } from \"ts-morph\";\nimport { DataModel } from \"../data-model/DataModel.js\";\nimport { ComplexType } from \"../data-model/DataTypeModel.js\";\nimport {\n ClientApiImports,\n CoreImports,\n LIB_MODULES,\n QueryObjectImports,\n ServiceImports,\n VERSIONED_CORE_IMPORTS,\n VERSIONED_SERVICE_IMPORTS,\n} from \"./import/ImportObjects.js\";\nimport { ImportedNameValidator } from \"./ImportedNameValidator.js\";\n\ntype ImportContainerType = Record<\n keyof typeof LIB_MODULES,\n { regular: Map<string, string>; typeOnly: Map<string, string> }\n>;\n\n/**\n * Handles all the import statements for a given file.\n *\n * Features a renaming mechanism, so that when the import name conflicts with an existing import a new\n * name is generated and returned.\n *\n * Map<string,string>\n */\nexport class ImportContainer {\n private readonly importedNameValidator: ImportedNameValidator;\n // mapping of a custom defined type to a primitive type\n private customTypes = {\n regular: new Map<string, Map<string, string>>(),\n typeOnly: new Map<string, Map<string, string>>(),\n };\n // imports to generated artefacts\n private internalImports = {\n regular: new Map<string, Map<string, string>>(),\n typeOnly: new Map<string, Map<string, string>>(),\n };\n\n private libs: ImportContainerType = {\n core: { regular: new Map(), typeOnly: new Map() },\n qObject: { regular: new Map(), typeOnly: new Map() },\n clientApi: { regular: new Map(), typeOnly: new Map() },\n service: { regular: new Map(), typeOnly: new Map() },\n };\n\n constructor(\n protected path: string,\n protected fileName: string,\n protected dataModel: DataModel,\n protected mainFileNames: { model: string; qObject: string; service: string },\n protected readonly bundledFileGeneration: boolean,\n protected reservedNames: Array<string> | undefined,\n ) {\n this.importedNameValidator = new ImportedNameValidator(reservedNames);\n }\n\n public addCoreLib(odataVersion: ODataVersions, coreLib: CoreImports) {\n const isVersioned = VERSIONED_CORE_IMPORTS.includes(coreLib);\n const name = CoreImports[coreLib] + (isVersioned ? ODataVersions[odataVersion] : \"\");\n const importName = this.importedNameValidator.validateName(LIB_MODULES.core, name);\n\n // TODO: currently only types are imported, however enums could potentially be imported too\n this.libs.core.typeOnly.set(name, importName);\n\n return importName;\n }\n\n private addFromQObject(name: string, typeOnlyImport = false) {\n const importName = this.importedNameValidator.validateName(LIB_MODULES.qObject, name);\n\n const imports = this.libs.qObject;\n if (typeOnlyImport) {\n if (!imports.regular.has(name)) {\n imports.typeOnly.set(name, importName);\n }\n } else {\n if (imports.typeOnly.has(name)) {\n imports.typeOnly.delete(name);\n }\n imports.regular.set(name, importName);\n }\n\n return importName;\n }\n\n public addQObject(qObject: QueryObjectImports | string) {\n return this.addFromQObject(qObject);\n }\n\n public addQObjectType(qObject: string) {\n return this.addFromQObject(qObject, true);\n }\n\n public addClientApi(clientApi: ClientApiImports) {\n const name = ClientApiImports[clientApi];\n const importName = this.importedNameValidator.validateName(LIB_MODULES.clientApi, name);\n\n // complete client api consists only of types\n this.libs.clientApi.typeOnly.set(name, importName);\n return importName;\n }\n\n public addServiceObject(odataVersion: ODataVersions, serviceObject: ServiceImports) {\n const isVersioned = VERSIONED_SERVICE_IMPORTS.includes(serviceObject);\n const name = ServiceImports[serviceObject] + (isVersioned ? ODataVersions[odataVersion] : \"\");\n const importName = this.importedNameValidator.validateName(LIB_MODULES.service, name);\n\n // only regular imports for the service package\n this.libs.service.regular.set(name, importName);\n return importName;\n }\n\n // TODO: make sure that regular imports win over additional typeOnly imports\n public addCustomType(moduleName: string, typeName: string, isTypeOnly: boolean = false) {\n const importName = this.importedNameValidator.validateName(moduleName, typeName);\n const imports = isTypeOnly ? this.customTypes.typeOnly : this.customTypes.regular;\n let importList = imports.get(moduleName);\n if (!importList) {\n importList = new Map();\n imports.set(moduleName, importList);\n }\n\n importList.set(typeName, importName);\n return importName;\n }\n\n private pathAndFile(filePath: string, fileName: string) {\n return filePath ? `${filePath}/${fileName}` : fileName;\n }\n\n private isDifferentFile(filePath: string, fileName: string) {\n return this.pathAndFile(this.path, this.fileName) !== this.pathAndFile(filePath, fileName);\n }\n\n private addGeneratedImport(folderPath: string, fileName: string, name: string, isTypeOnly = false): string {\n // imports are only relevant for different files\n if (!this.isDifferentFile(folderPath, fileName)) {\n return name;\n }\n\n const moduleName = this.pathAndFile(folderPath, fileName);\n const importName = this.importedNameValidator.validateName(moduleName, name);\n const imports = isTypeOnly ? this.internalImports.typeOnly : this.internalImports.regular;\n\n if (isTypeOnly && this.internalImports.regular.get(moduleName)?.has(name)) {\n return importName;\n }\n if (!isTypeOnly && this.internalImports.typeOnly.get(moduleName)?.has(name)) {\n this.internalImports.typeOnly.get(moduleName)?.delete(name);\n }\n\n const importList = imports.get(moduleName) || new Map<string, string>();\n importList.set(name, importName);\n imports.set(moduleName, importList);\n\n return importName;\n }\n\n public addGeneratedModel(fqName: string, name: string, isTypeOnly = true): string {\n if (this.bundledFileGeneration) {\n return this.addGeneratedImport(\"\", this.mainFileNames.model, name, isTypeOnly);\n } else {\n const model = this.dataModel.getModel(fqName) as ComplexType | undefined;\n if (!model && fqName !== \"\") {\n throw new Error(`Cannot find model by its fully qualified name: ${fqName}!`);\n }\n\n const folderPath = model ? model.folderPath : \"\";\n const modelName = model ? model.modelName : this.mainFileNames.model;\n return this.addGeneratedImport(folderPath, modelName, name, isTypeOnly);\n }\n }\n\n public addGeneratedQObject(fqName: string, name: string, isTypeOnly = false) {\n if (this.bundledFileGeneration) {\n return this.addGeneratedImport(\"\", this.mainFileNames.qObject, name, isTypeOnly);\n } else {\n const model = this.dataModel.getModel(fqName) as ComplexType | undefined;\n if (!model && fqName !== \"\") {\n throw new Error(`Cannot find q-object by its fully qualified name: ${fqName}!`);\n }\n\n const folderPath = model ? model.folderPath : \"\";\n const qName = model ? model.qName : this.mainFileNames!.qObject;\n return this.addGeneratedImport(folderPath, qName, name, isTypeOnly);\n }\n }\n\n public addGeneratedService(fqName: string, name: string) {\n if (this.bundledFileGeneration) {\n return this.addGeneratedImport(\"\", this.mainFileNames.service, name);\n } else {\n const model = this.dataModel.getModel(fqName) as ComplexType;\n return this.addGeneratedImport(model.folderPath, model.serviceName, name);\n }\n }\n\n private createImportDecl(\n module: string,\n toImport: Map<string, string>,\n isTypeOnly = false,\n ): OptionalKind<ImportDeclarationStructure> {\n return {\n namedImports: this.getNamedImports(toImport),\n moduleSpecifier: module,\n isTypeOnly,\n };\n }\n\n public getImportDeclarations(): Array<OptionalKind<ImportDeclarationStructure>> {\n return [\n ...Object.entries(this.libs).reduce<Array<OptionalKind<ImportDeclarationStructure>>>(\n (result, [moduleName, toImport]) => {\n const module = LIB_MODULES[moduleName as keyof typeof LIB_MODULES];\n if (toImport.typeOnly.size) {\n result.push(this.createImportDecl(module, toImport.typeOnly, true));\n }\n if (toImport.regular.size) {\n result.push(this.createImportDecl(module, toImport.regular));\n }\n return result;\n },\n [],\n ),\n ...[...this.customTypes.typeOnly]\n .filter(([moduleName, toImport]) => toImport.size > 0)\n .map(([moduleName, toImport]) => {\n return this.createImportDecl(moduleName, toImport, true);\n }),\n ...[...this.customTypes.regular]\n .filter(([moduleName, toImport]) => toImport.size > 0)\n .map(([moduleName, toImport]) => {\n return this.createImportDecl(moduleName, toImport);\n }),\n ...[...this.internalImports.typeOnly]\n .filter(([_, toImport]) => toImport.size > 0)\n .map(([key, toImport]) => {\n const module = this.getModuleSpecifier(key);\n return this.createImportDecl(module, toImport, true);\n }),\n ...[...this.internalImports.regular]\n .filter(([_, toImport]) => toImport.size > 0)\n .map(([key, toImport]) => {\n const module = this.getModuleSpecifier(key);\n return this.createImportDecl(module, toImport);\n }),\n ];\n }\n\n private getNamedImports(toImport: Map<string, string>): Array<{ name: string; alias: string | undefined }> {\n return [...toImport.entries()].map(([name, alias]) => ({\n name,\n alias: alias !== name ? alias : undefined,\n }));\n }\n\n private getModuleSpecifier(filePath: string): string {\n const relativePath = path.relative(this.path, filePath).replaceAll(path.sep, \"/\");\n return !relativePath.startsWith(\".\") ? \"./\" + relativePath : relativePath;\n }\n}\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;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,C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AC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YACrD,IAAI;YACJ,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SAC1C,CAAC,CAAC,CAAC;IACN,CAAC;IAEO,kBAAkB,CAAC,QAAgB;QACzC,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,UAAU,CAAC,IAAI,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","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 public addFromMainQObject(name: string, isTypeOnly = false) {\r\n return this.addGeneratedImport(\"\", this.mainFileNames.qObject, name, isTypeOnly);\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 addGeneratedQBaseObject(model: ComplexType, isTypeOnly = false) {\r\n if (!model.qBaseName) {\r\n throw new Error(`Model ${model.fqName} has no base type!`);\r\n }\r\n return this.bundledFileGeneration\r\n ? this.addGeneratedImport(\"\", this.mainFileNames.qObject, model.qBaseName, isTypeOnly)\r\n : this.addGeneratedImport(model.folderPath, model.qBaseName, model.qBaseName, isTypeOnly);\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"]}
|
|
@@ -7,6 +7,7 @@ export const generateQueryObjects = (project, dataModel, version, options, namin
|
|
|
7
7
|
const generator = new QueryObjectGenerator(project, dataModel, version, options, namingHelper);
|
|
8
8
|
return generator.generate();
|
|
9
9
|
};
|
|
10
|
+
const OPTIONS_STATEMENT = "OPTS";
|
|
10
11
|
class QueryObjectGenerator {
|
|
11
12
|
constructor(project, dataModel, version, options, namingHelper) {
|
|
12
13
|
this.project = project;
|
|
@@ -18,6 +19,7 @@ class QueryObjectGenerator {
|
|
|
18
19
|
generate() {
|
|
19
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
21
|
this.project.initQObjects();
|
|
22
|
+
this.generateOptions();
|
|
21
23
|
// process EntityType & ComplexType
|
|
22
24
|
const promises = [...this.generateEntityTypes(), ...this.generateComplexTypes()];
|
|
23
25
|
if (!this.options.skipOperations) {
|
|
@@ -28,6 +30,24 @@ class QueryObjectGenerator {
|
|
|
28
30
|
return this.project.finalizeQObjects();
|
|
29
31
|
});
|
|
30
32
|
}
|
|
33
|
+
generateOptions() {
|
|
34
|
+
const file = this.project.createOrGetMainQObjectFile();
|
|
35
|
+
// for now assume only enableNativeInOperator requires options to be processed
|
|
36
|
+
if (!this.options.enableNativeInOperator) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// for now hardcode enableNativeInOperator
|
|
40
|
+
file.getFile().addVariableStatement({
|
|
41
|
+
declarationKind: VariableDeclarationKind.Const,
|
|
42
|
+
isExported: !this.options.bundledFileGeneration,
|
|
43
|
+
declarations: [
|
|
44
|
+
{
|
|
45
|
+
name: OPTIONS_STATEMENT,
|
|
46
|
+
initializer: `{ nativeIn: true }`,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
31
51
|
generateEntityTypes() {
|
|
32
52
|
return this.dataModel.getEntityTypes().map((model) => {
|
|
33
53
|
const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [
|
|
@@ -63,31 +83,40 @@ class QueryObjectGenerator {
|
|
|
63
83
|
return this.project.finalizeFile(file);
|
|
64
84
|
});
|
|
65
85
|
}
|
|
66
|
-
|
|
67
|
-
const imports = file.getImports();
|
|
68
|
-
const properties = this.generateQueryObjectProps(file.getImports(), model.props);
|
|
69
|
-
let extendsClause;
|
|
86
|
+
getExtendsClauseForQObjects(model, imports) {
|
|
70
87
|
if (model.baseClasses.length) {
|
|
71
88
|
const baseClass = model.baseClasses[0];
|
|
72
89
|
const baseModel = this.dataModel.getModel(baseClass);
|
|
73
90
|
if (!baseModel) {
|
|
74
91
|
throw new Error(`Entity or complex type "${baseClass}" from baseClass attribute not found!`);
|
|
75
92
|
}
|
|
76
|
-
|
|
93
|
+
return imports.addGeneratedQBaseObject(baseModel);
|
|
77
94
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
95
|
+
return imports.addQObject(QueryObjectImports.QueryObject);
|
|
96
|
+
}
|
|
97
|
+
generateModel(file, model) {
|
|
98
|
+
const imports = file.getImports();
|
|
99
|
+
if (!model.qBaseName) {
|
|
83
100
|
file.getFile().addClass({
|
|
101
|
+
name: model.qName,
|
|
102
|
+
isExported: true,
|
|
103
|
+
extends: this.getExtendsClauseForQObjects(model, imports),
|
|
104
|
+
properties: this.generateQueryObjectProps(file.getImports(), model.props),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// base class used for extension needs an own file
|
|
109
|
+
const baseFile = this.project.createOrGetQObjectFile(model.folderPath, model.qBaseName, [model.qBaseName]);
|
|
110
|
+
baseFile.getFile().addClass({
|
|
84
111
|
name: model.qBaseName,
|
|
85
112
|
isExported: true,
|
|
86
|
-
extends:
|
|
87
|
-
properties,
|
|
113
|
+
extends: this.getExtendsClauseForQObjects(model, baseFile.getImports()),
|
|
114
|
+
properties: this.generateQueryObjectProps(baseFile.getImports(), model.props),
|
|
88
115
|
});
|
|
116
|
+
this.project.finalizeFile(baseFile);
|
|
89
117
|
const [props, getAccessors, methods, statements] = Array.from(model.subtypes).reduce((collector, subtype) => {
|
|
90
118
|
const subClass = this.dataModel.getModel(subtype);
|
|
119
|
+
const subClassName = imports.addGeneratedQObject(subClass.fqName, subClass.qName);
|
|
91
120
|
const methodName = `__as${subClass.qName}`;
|
|
92
121
|
const enumerablePropDef = imports.addQObject(QueryObjectImports.ENUMERABLE_PROP_DEFINITION);
|
|
93
122
|
collector[0].push(`"${subClass.fqName}": "${subClass.qName}"`);
|
|
@@ -104,14 +133,14 @@ class QueryObjectGenerator {
|
|
|
104
133
|
collector[2].push({
|
|
105
134
|
name: methodName,
|
|
106
135
|
scope: Scope.Private,
|
|
107
|
-
statements: `return new ${
|
|
136
|
+
statements: `return new ${subClassName}(this.withPrefix("${subClass.fqName}"))`,
|
|
108
137
|
});
|
|
109
138
|
return collector;
|
|
110
139
|
}, [[], [], [], []]);
|
|
111
140
|
file.getFile().addClass({
|
|
112
141
|
name: model.qName,
|
|
113
142
|
isExported: true,
|
|
114
|
-
extends: model
|
|
143
|
+
extends: imports.addGeneratedQBaseObject(model),
|
|
115
144
|
properties: [
|
|
116
145
|
{
|
|
117
146
|
name: "__subtypeMapping",
|
|
@@ -125,14 +154,6 @@ class QueryObjectGenerator {
|
|
|
125
154
|
});
|
|
126
155
|
file.getFile().addStatements(`Object.defineProperties(${model.qName}.prototype, { ${statements.join(",")} });`);
|
|
127
156
|
}
|
|
128
|
-
else {
|
|
129
|
-
file.getFile().addClass({
|
|
130
|
-
name: model.qName,
|
|
131
|
-
isExported: true,
|
|
132
|
-
extends: extendsClause,
|
|
133
|
-
properties: properties,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
157
|
file.getFile().addVariableStatement({
|
|
137
158
|
declarationKind: VariableDeclarationKind.Const,
|
|
138
159
|
isExported: true,
|
|
@@ -145,43 +166,42 @@ class QueryObjectGenerator {
|
|
|
145
166
|
});
|
|
146
167
|
}
|
|
147
168
|
generateQueryObjectProps(importContainer, props) {
|
|
169
|
+
const isEnumType = (prop) => prop.dataType === "EnumType" /* DataTypes.EnumType */;
|
|
170
|
+
const isModelType = (prop) => prop.dataType === "ModelType" /* DataTypes.ModelType */ || prop.dataType === "ComplexType" /* DataTypes.ComplexType */;
|
|
171
|
+
const addOptions = this.options.enableNativeInOperator; // limited to hardcoded enableNativeIn for now
|
|
172
|
+
if (addOptions && props.some((prop) => !prop.isCollection && !isModelType(prop) && !isEnumType(prop))) {
|
|
173
|
+
importContainer.addFromMainQObject(OPTIONS_STATEMENT);
|
|
174
|
+
}
|
|
148
175
|
return props.map((prop) => {
|
|
149
176
|
const { odataName } = prop;
|
|
150
177
|
const name = this.namingHelper.getQPropName(prop.name);
|
|
151
|
-
const isModelType = prop.dataType === "ModelType" /* DataTypes.ModelType */ || prop.dataType === "ComplexType" /* DataTypes.ComplexType */;
|
|
152
|
-
const isEnumType = prop.dataType === "EnumType" /* DataTypes.EnumType */;
|
|
153
|
-
const isNumericEnum = this.options.enumType === "numeric";
|
|
154
178
|
let qPathInit;
|
|
155
179
|
// factor in collections
|
|
156
180
|
if (prop.isCollection) {
|
|
157
|
-
const qPath = importContainer.addQObject(
|
|
158
|
-
|
|
159
|
-
: isEnumType
|
|
160
|
-
? isNumericEnum
|
|
161
|
-
? QueryObjectImports.QNumericEnumCollectionPath
|
|
162
|
-
: QueryObjectImports.QEnumCollectionPath
|
|
163
|
-
: QueryObjectImports.QCollectionPath);
|
|
164
|
-
const qObject = isModelType
|
|
181
|
+
const qPath = importContainer.addQObject(prop.qPath);
|
|
182
|
+
const qObject = isModelType(prop)
|
|
165
183
|
? importContainer.addGeneratedQObject(prop.fqType, prop.qObject)
|
|
166
|
-
: isEnumType
|
|
184
|
+
: isEnumType(prop)
|
|
167
185
|
? importContainer.addGeneratedModel(prop.fqType, prop.type, false)
|
|
168
186
|
: importContainer.addQObject(prop.qObject);
|
|
169
|
-
qPathInit = `new ${qPath}(this.withPrefix("${odataName}"), ${isEnumType ? qObject : `() => ${qObject}`})`;
|
|
187
|
+
qPathInit = `new ${qPath}(this.withPrefix("${odataName}"), ${isEnumType(prop) ? qObject : `() => ${qObject}`})`;
|
|
170
188
|
}
|
|
171
189
|
else {
|
|
172
190
|
// add import for data type
|
|
173
191
|
const qPath = importContainer.addQObject(prop.qPath);
|
|
174
|
-
if (isModelType) {
|
|
192
|
+
if (isModelType(prop)) {
|
|
175
193
|
const qObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject);
|
|
176
194
|
qPathInit = `new ${qPath}(this.withPrefix("${odataName}"), () => ${qObject})`;
|
|
177
195
|
}
|
|
178
|
-
else if (isEnumType) {
|
|
196
|
+
else if (isEnumType(prop)) {
|
|
179
197
|
const qObject = importContainer.addGeneratedModel(prop.fqType, prop.type, false);
|
|
180
198
|
qPathInit = `new ${qPath}(this.withPrefix("${odataName}"), ${qObject})`;
|
|
181
199
|
}
|
|
182
200
|
else {
|
|
183
201
|
let converterStmt = this.generateConverterStmt(importContainer, prop.converters);
|
|
184
|
-
|
|
202
|
+
const addConverter = !!converterStmt;
|
|
203
|
+
converterStmt = converterStmt || "undefined";
|
|
204
|
+
qPathInit = `new ${qPath}(this.withPrefix("${odataName}")${addOptions ? `, ${converterStmt}, ${OPTIONS_STATEMENT}` : addConverter ? `, ${converterStmt}` : ""})`;
|
|
185
205
|
}
|
|
186
206
|
}
|
|
187
207
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryObjectGenerator.js","sourceRoot":"","sources":["../../src/generator/QueryObjectGenerator.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAKL,KAAK,EACL,uBAAuB,GACx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S,CAAC,UAAU,EAAE,SAAS,CAAC,SAAS,CAAC;iBACzF;aACF;YACD,KAAK,EAAE;gBACL;oBACE,UAAU,EAAE;wBACV,UAAU,SAAS,CAAC,SAAS,IAAI,gBAAgB,CAAC,CAAC,CAAC,IAAI,GAAG,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,GACrG,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAChC,GAAG;qBACJ;iBACF;aACF;YACD,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,WAAW;oBACjB,UAAU,EAAE,CAAC,oBAAoB,CAAC;iBACnC;gBACD,+GAA+G;gBAC/G,GAAG,CAAC,SAAS,CAAC,IAAI,6CAA4B,IAAI,CAAC,SAAS;oBAC1D,CAAC,CAAC;wBACE;4BACE,IAAI,EAAE,UAAU;4BAChB,UAAU,EAAE;gCACV;oCACE,IAAI,EAAE,YAAY;oCAClB,WAAW,EAAE,OAAO;iCACrB;6BACF;4BACD,UAAU,EAAE,CAAC,8CAA8C,CAAC;yBACjB;qBAC9C;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\nimport { ODataVersions } from \"@odata2ts/odata-core\";\nimport {\n GetAccessorDeclarationStructure,\n MethodDeclarationStructure,\n OptionalKind,\n PropertyDeclarationStructure,\n Scope,\n VariableDeclarationKind,\n} from \"ts-morph\";\nimport { firstCharLowerCase } from \"xml2js/lib/processors.js\";\nimport { DataModel } from \"../data-model/DataModel.js\";\nimport {\n ComplexType,\n DataTypes,\n EntityType,\n OperationType,\n OperationTypes,\n PropertyModel,\n} from \"../data-model/DataTypeModel.js\";\nimport { NamingHelper } from \"../data-model/NamingHelper.js\";\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel.js\";\nimport { FileHandler } from \"../project/FileHandler.js\";\nimport { ProjectManager } from \"../project/ProjectManager.js\";\nimport { QueryObjectImports } from \"./import/ImportObjects.js\";\nimport { ImportContainer } from \"./ImportContainer.js\";\n\nexport const generateQueryObjects: EntityBasedGeneratorFunction = (\n project,\n dataModel,\n version,\n options,\n namingHelper,\n) => {\n const generator = new QueryObjectGenerator(project, dataModel, version, options, namingHelper);\n return generator.generate();\n};\n\nclass QueryObjectGenerator {\n constructor(\n private project: ProjectManager,\n private dataModel: DataModel,\n private version: ODataVersions,\n private options: GeneratorFunctionOptions,\n private namingHelper: NamingHelper,\n ) {}\n\n public async generate(): Promise<void> {\n this.project.initQObjects();\n\n // process EntityType & ComplexType\n const promises: Array<Promise<void>> = [...this.generateEntityTypes(), ...this.generateComplexTypes()];\n if (!this.options.skipOperations) {\n // process unbound operations\n promises.push(this.generateUnboundOperations());\n }\n\n await Promise.all(promises);\n\n return this.project.finalizeQObjects();\n }\n\n private generateEntityTypes() {\n return this.dataModel.getEntityTypes().map((model) => {\n const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [\n model.qName,\n firstCharLowerCase(model.qName),\n model.id.qName,\n ]);\n\n // q object\n this.generateModel(file, model);\n\n // qId function\n if (!this.options.skipIdModels && model.generateId) {\n this.generateIdFunction(file, model);\n }\n\n // bound q operations\n if (!this.options.skipOperations) {\n [\n ...this.dataModel.getEntityTypeOperations(model.fqName),\n ...this.dataModel.getEntitySetOperations(model.fqName),\n ].forEach((operation) => {\n this.generateOperation(file, operation, model.fqName);\n });\n }\n\n return this.project.finalizeFile(file);\n });\n }\n\n private generateComplexTypes() {\n return this.dataModel.getComplexTypes().map((model) => {\n const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [\n model.qName,\n firstCharLowerCase(model.qName),\n ]);\n\n this.generateModel(file, model);\n\n return this.project.finalizeFile(file);\n });\n }\n\n private generateModel(file: FileHandler, model: ComplexType) {\n const imports = file.getImports();\n const properties = this.generateQueryObjectProps(file.getImports(), model.props);\n\n let extendsClause: string;\n if (model.baseClasses.length) {\n const baseClass = model.baseClasses[0];\n const baseModel = this.dataModel.getModel(baseClass) as ComplexType;\n if (!baseModel) {\n throw new Error(`Entity or complex type \"${baseClass}\" from baseClass attribute not found!`);\n }\n extendsClause = imports.addGeneratedQObject(baseClass, baseModel.qBaseName!);\n } else {\n extendsClause = imports.addQObject(QueryObjectImports.QueryObject);\n }\n\n if (model.qBaseName) {\n // base class which used for extension\n file.getFile().addClass({\n name: model.qBaseName,\n isExported: true,\n extends: extendsClause,\n properties,\n });\n\n const [props, getAccessors, methods, statements] = Array.from(model.subtypes).reduce<\n [\n Array<string>,\n OptionalKind<GetAccessorDeclarationStructure>[],\n OptionalKind<MethodDeclarationStructure>[],\n Array<string>,\n ]\n >(\n (collector, subtype) => {\n const subClass = this.dataModel.getModel(subtype) as ComplexType;\n const methodName = `__as${subClass.qName}`;\n const enumerablePropDef = imports.addQObject(QueryObjectImports.ENUMERABLE_PROP_DEFINITION);\n\n collector[0].push(`\"${subClass.fqName}\": \"${subClass.qName}\"`);\n\n subClass.props.forEach((prop) => {\n const propName = this.namingHelper.getQPropName(prop.name);\n const fqPropName = `${subClass.qName}_${propName}`;\n collector[1].push({\n name: fqPropName,\n scope: Scope.Public,\n statements: `return this.${methodName}().${propName};`,\n });\n collector[3].push(`${fqPropName}: ${enumerablePropDef}`);\n });\n\n collector[2].push({\n name: methodName,\n scope: Scope.Private,\n statements: `return new ${subClass.qName}(this.withPrefix(\"${subClass.fqName}\"))`,\n });\n\n return collector;\n },\n [[], [], [], []],\n );\n\n file.getFile().addClass({\n name: model.qName,\n isExported: true,\n extends: model.qBaseName,\n properties: [\n {\n name: \"__subtypeMapping\",\n scope: Scope.Protected,\n isReadonly: true,\n initializer: `{ ${props.join(\",\")} }`,\n },\n ],\n getAccessors,\n methods,\n });\n\n file.getFile().addStatements(`Object.defineProperties(${model.qName}.prototype, { ${statements.join(\",\")} });`);\n } else {\n file.getFile().addClass({\n name: model.qName,\n isExported: true,\n extends: extendsClause,\n properties: properties,\n });\n }\n\n file.getFile().addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: firstCharLowerCase(model.qName),\n initializer: `new ${model.qName}()`,\n },\n ],\n });\n }\n\n private generateQueryObjectProps(\n importContainer: ImportContainer,\n props: Array<PropertyModel>,\n ): Array<OptionalKind<PropertyDeclarationStructure>> {\n return props.map((prop) => {\n const { odataName } = prop;\n const name = this.namingHelper.getQPropName(prop.name);\n const isModelType = prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType;\n const isEnumType = prop.dataType === DataTypes.EnumType;\n const isNumericEnum = this.options.enumType === \"numeric\";\n\n let qPathInit: string;\n\n // factor in collections\n if (prop.isCollection) {\n const qPath = importContainer.addQObject(\n isModelType\n ? QueryObjectImports.QEntityCollectionPath\n : isEnumType\n ? isNumericEnum\n ? QueryObjectImports.QNumericEnumCollectionPath\n : QueryObjectImports.QEnumCollectionPath\n : QueryObjectImports.QCollectionPath,\n );\n const qObject = isModelType\n ? importContainer.addGeneratedQObject(prop.fqType, prop.qObject!)\n : isEnumType\n ? importContainer.addGeneratedModel(prop.fqType, prop.type, false)\n : importContainer.addQObject(prop.qObject!);\n\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\"), ${isEnumType ? qObject : `() => ${qObject}`})`;\n } else {\n // add import for data type\n const qPath = importContainer.addQObject(prop.qPath);\n if (isModelType) {\n const qObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject!);\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\"), () => ${qObject})`;\n } else if (isEnumType) {\n const qObject = importContainer.addGeneratedModel(prop.fqType, prop.type, false);\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\"), ${qObject})`;\n } else {\n let converterStmt = this.generateConverterStmt(importContainer, prop.converters);\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\")${converterStmt ? `, ${converterStmt}` : \"\"})`;\n }\n }\n\n return {\n name,\n scope: Scope.Public,\n isReadonly: true,\n initializer: qPathInit,\n } as OptionalKind<PropertyDeclarationStructure>;\n });\n }\n\n private generateConverterStmt(importContainer: ImportContainer, converters: Array<ValueConverterImport> | undefined) {\n if (!converters?.length) {\n return undefined;\n }\n const converterIds = converters.map((converter) => {\n return importContainer.addCustomType(converter.package, converter.converterId);\n });\n\n if (converterIds.length === 1) {\n return converterIds[0];\n } else {\n const createChain = importContainer.addCustomType(\"@odata2ts/converter-runtime\", \"createChain\");\n\n const [first, second, ...moreConverters] = converterIds;\n return moreConverters.reduce((stmt, convId) => `${stmt}.chain(${convId})`, `${createChain}(${first}, ${second})`);\n }\n }\n\n private generateIdFunction(file: FileHandler, model: EntityType) {\n const importContainer = file.getImports();\n const qFunc = importContainer.addQObject(QueryObjectImports.QId);\n const idModelName = importContainer.addGeneratedModel(model.fqName, model.id.modelName);\n\n file.getFile().addClass({\n name: model.id.qName,\n isExported: true,\n extends: `${qFunc}<${idModelName}>`,\n properties: [\n {\n name: \"params\",\n scope: Scope.Private,\n isReadonly: true,\n initializer: this.getParamInitString(importContainer, model.keys),\n },\n ],\n methods: [\n {\n name: \"getParams\",\n statements: [\"return this.params\"],\n },\n ],\n });\n }\n\n private getParamInitString(\n importContainer: ImportContainer,\n props: Array<PropertyModel>,\n overloads?: Array<Array<PropertyModel>>,\n ) {\n const allParams = [props, ...(overloads ?? [])].map((paramSet) => {\n const pString = paramSet\n .map((prop) => {\n let complexQParam = \"\";\n if (prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType) {\n const importedQObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject!);\n complexQParam = `, new ${importedQObject}()`;\n }\n\n const qParam = importContainer.addQObject(prop.qParam!);\n const isMappedNameNecessary = prop.odataName !== prop.name;\n const mappedName = isMappedNameNecessary\n ? `\"${prop.name}\"`\n : prop.converters?.length\n ? \"undefined\"\n : undefined;\n const converterStmt = this.generateConverterStmt(importContainer, prop.converters);\n const mappedNameParam = mappedName ? `, ${mappedName}` : \"\";\n const converterParam = converterStmt ? `, ${converterStmt}` : \"\";\n return `new ${qParam}(\"${prop.odataName}\"${complexQParam}${mappedNameParam}${converterParam})`;\n })\n .join(\",\");\n return `[${pString}]`;\n });\n\n return allParams.length === 1 ? allParams[0] : `[${allParams.join(\",\")}]`;\n }\n\n private async generateUnboundOperations() {\n const unboundOps = this.dataModel.getUnboundOperationTypes();\n const reservedNames = unboundOps.map((op) => op.qName);\n const file = this.project.createOrGetMainQObjectFile(reservedNames);\n\n unboundOps.forEach((operation) => {\n this.generateOperation(file, operation, \"\");\n });\n }\n\n private generateOperation(file: FileHandler, operation: OperationType, baseFqName: string) {\n const imports = file.getImports();\n const isV2 = this.version === ODataVersions.V2;\n const returnType = operation.returnType;\n const hasParams = operation.parameters.length > 0 || operation.overrides?.length;\n const isParamsOptional = !![operation.parameters, ...(operation.overrides ?? [])].find((pSet) => pSet.length === 0);\n\n // imports\n const qOp = operation.type === OperationTypes.Action ? QueryObjectImports.QAction : QueryObjectImports.QFunction;\n const qOperation = imports.addQObject(qOp);\n const paramModelName = hasParams ? imports.addGeneratedModel(baseFqName, operation.paramsModelName) : undefined;\n\n let returnTypeOpStmt: string = \"\";\n if (returnType) {\n if (returnType.dataType === DataTypes.ComplexType || returnType.dataType === DataTypes.ModelType) {\n if (returnType.qObject) {\n const opRt = imports.addQObject(QueryObjectImports.OperationReturnType);\n const rts = imports.addQObject(QueryObjectImports.ReturnTypes);\n const rType = returnType.isCollection\n ? \"COLLECTION\"\n : returnType.dataType === DataTypes.ComplexType\n ? \"COMPLEX\"\n : \"ENTITY\";\n const qComplexParam = imports.addQObject(QueryObjectImports.QComplexParam);\n const returnQName = imports.addGeneratedQObject(returnType.fqType, returnType.qObject);\n\n returnTypeOpStmt = `new ${opRt}(${rts}.${rType}, new ${qComplexParam}(\"NONE\", new ${returnQName}))`;\n }\n }\n // currently, it only makes sense to add the OperationReturnType if a converter is present\n else if (returnType.converters && returnType.qParam) {\n const rtClass = imports.addQObject(QueryObjectImports.OperationReturnType);\n const rtTypes = imports.addQObject(QueryObjectImports.ReturnTypes);\n const rType = returnType.isCollection ? \"COLLECTION\" : \"VALUE\";\n const qParam = imports.addQObject(returnType.qParam);\n\n const rtKind = `${rtTypes}.${rType}`;\n\n const converterParam = returnType.converters\n ? \", \" + this.generateConverterStmt(imports, returnType.converters)\n : \"\";\n returnTypeOpStmt = `new ${rtClass}(${rtKind}, new ${qParam}(\"NONE\", undefined${converterParam}))`;\n }\n }\n\n file.getFile().addClass({\n name: operation.qName,\n isExported: true,\n extends: qOperation + (hasParams ? `<${paramModelName}>` : \"\"),\n properties: [\n {\n name: \"params\",\n scope: Scope.Private,\n isReadonly: true,\n type: hasParams ? undefined : \"[]\",\n initializer: this.getParamInitString(imports, operation.parameters, operation.overrides),\n },\n ],\n ctors: [\n {\n statements: [\n `super(\"${operation.odataName}\"${returnTypeOpStmt ? \", \" + returnTypeOpStmt : isV2 ? \", undefined\" : \"\"}${\n isV2 ? \", { v2Mode: true }\" : \"\"\n })`,\n ],\n },\n ],\n methods: [\n {\n name: \"getParams\",\n statements: [\"return this.params\"],\n },\n // functions without params: add an overriding buildUrl() to not force users to have to pass undefined as param\n ...(operation.type === OperationTypes.Function && !hasParams\n ? [\n {\n name: \"buildUrl\",\n parameters: [\n {\n name: \"notEncoded\",\n initializer: \"false\",\n },\n ],\n statements: [\"return super.buildUrl(undefined, notEncoded)\"],\n } as OptionalKind<MethodDeclarationStructure>,\n ]\n : []),\n ],\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"QueryObjectGenerator.js","sourceRoot":"","sources":["../../src/generator/QueryObjectGenerator.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAKL,KAAK,EACL,uBAAuB,GACxB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAc9D,OAAO,EAAE,kB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ClC,WAAW,EAAE,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,SAAS,CAAC,UAAU,EAAE,SAAS,CAAC,SAAS,CAAC;iBACzF;aACF;YACD,KAAK,EAAE;gBACL;oBACE,UAAU,EAAE;wBACV,UAAU,SAAS,CAAC,SAAS,IAAI,gBAAgB,CAAC,CAAC,CAAC,IAAI,GAAG,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,GACrG,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAChC,GAAG;qBACJ;iBACF;aACF;YACD,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,WAAW;oBACjB,UAAU,EAAE,CAAC,oBAAoB,CAAC;iBACnC;gBACD,+GAA+G;gBAC/G,GAAG,CAAC,SAAS,CAAC,IAAI,6CAA4B,IAAI,CAAC,SAAS;oBAC1D,CAAC,CAAC;wBACE;4BACE,IAAI,EAAE,UAAU;4BAChB,UAAU,EAAE;gCACV;oCACE,IAAI,EAAE,YAAY;oCAClB,WAAW,EAAE,OAAO;iCACrB;6BACF;4BACD,UAAU,EAAE,CAAC,8CAA8C,CAAC;yBACjB;qBAC9C;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { ValueConverterImport } from \"@odata2ts/converter-runtime\";\nimport { ODataVersions } from \"@odata2ts/odata-core\";\nimport {\n GetAccessorDeclarationStructure,\n MethodDeclarationStructure,\n OptionalKind,\n PropertyDeclarationStructure,\n Scope,\n VariableDeclarationKind,\n} from \"ts-morph\";\nimport { firstCharLowerCase } from \"xml2js/lib/processors.js\";\nimport { DataModel } from \"../data-model/DataModel.js\";\nimport {\n ComplexType,\n DataTypes,\n EntityType,\n OperationType,\n OperationTypes,\n PropertyModel,\n} from \"../data-model/DataTypeModel.js\";\nimport { NamingHelper } from \"../data-model/NamingHelper.js\";\nimport { EntityBasedGeneratorFunction, GeneratorFunctionOptions } from \"../FactoryFunctionModel.js\";\nimport { FileHandler } from \"../project/FileHandler.js\";\nimport { ProjectManager } from \"../project/ProjectManager.js\";\nimport { QueryObjectImports } from \"./import/ImportObjects.js\";\nimport { ImportContainer } from \"./ImportContainer.js\";\n\nexport const generateQueryObjects: EntityBasedGeneratorFunction = (\n project,\n dataModel,\n version,\n options,\n namingHelper,\n) => {\n const generator = new QueryObjectGenerator(project, dataModel, version, options, namingHelper);\n return generator.generate();\n};\n\nconst OPTIONS_STATEMENT = \"OPTS\";\n\nclass QueryObjectGenerator {\n constructor(\n private project: ProjectManager,\n private dataModel: DataModel,\n private version: ODataVersions,\n private options: GeneratorFunctionOptions,\n private namingHelper: NamingHelper,\n ) {}\n\n public async generate(): Promise<void> {\n this.project.initQObjects();\n\n this.generateOptions();\n\n // process EntityType & ComplexType\n const promises: Array<Promise<void>> = [...this.generateEntityTypes(), ...this.generateComplexTypes()];\n if (!this.options.skipOperations) {\n // process unbound operations\n promises.push(this.generateUnboundOperations());\n }\n\n await Promise.all(promises);\n\n return this.project.finalizeQObjects();\n }\n\n private generateOptions() {\n const file = this.project.createOrGetMainQObjectFile();\n\n // for now assume only enableNativeInOperator requires options to be processed\n if (!this.options.enableNativeInOperator) {\n return;\n }\n\n // for now hardcode enableNativeInOperator\n file.getFile().addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: !this.options.bundledFileGeneration,\n declarations: [\n {\n name: OPTIONS_STATEMENT,\n initializer: `{ nativeIn: true }`,\n },\n ],\n });\n }\n\n private generateEntityTypes() {\n return this.dataModel.getEntityTypes().map((model) => {\n const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [\n model.qName,\n firstCharLowerCase(model.qName),\n model.id.qName,\n ]);\n\n // q object\n this.generateModel(file, model);\n\n // qId function\n if (!this.options.skipIdModels && model.generateId) {\n this.generateIdFunction(file, model);\n }\n\n // bound q operations\n if (!this.options.skipOperations) {\n [\n ...this.dataModel.getEntityTypeOperations(model.fqName),\n ...this.dataModel.getEntitySetOperations(model.fqName),\n ].forEach((operation) => {\n this.generateOperation(file, operation, model.fqName);\n });\n }\n\n return this.project.finalizeFile(file);\n });\n }\n\n private generateComplexTypes() {\n return this.dataModel.getComplexTypes().map((model) => {\n const file = this.project.createOrGetQObjectFile(model.folderPath, model.qName, [\n model.qName,\n firstCharLowerCase(model.qName),\n ]);\n\n this.generateModel(file, model);\n\n return this.project.finalizeFile(file);\n });\n }\n\n private getExtendsClauseForQObjects(model: ComplexType, imports: ImportContainer) {\n if (model.baseClasses.length) {\n const baseClass = model.baseClasses[0];\n const baseModel = this.dataModel.getModel(baseClass) as ComplexType;\n if (!baseModel) {\n throw new Error(`Entity or complex type \"${baseClass}\" from baseClass attribute not found!`);\n }\n return imports.addGeneratedQBaseObject(baseModel);\n }\n\n return imports.addQObject(QueryObjectImports.QueryObject);\n }\n\n private generateModel(file: FileHandler, model: ComplexType) {\n const imports = file.getImports();\n\n if (!model.qBaseName) {\n file.getFile().addClass({\n name: model.qName,\n isExported: true,\n extends: this.getExtendsClauseForQObjects(model, imports),\n properties: this.generateQueryObjectProps(file.getImports(), model.props),\n });\n } else {\n // base class used for extension needs an own file\n const baseFile = this.project.createOrGetQObjectFile(model.folderPath, model.qBaseName, [model.qBaseName]);\n baseFile.getFile().addClass({\n name: model.qBaseName,\n isExported: true,\n extends: this.getExtendsClauseForQObjects(model, baseFile.getImports()),\n properties: this.generateQueryObjectProps(baseFile.getImports(), model.props),\n });\n this.project.finalizeFile(baseFile);\n\n const [props, getAccessors, methods, statements] = Array.from(model.subtypes).reduce<\n [\n Array<string>,\n OptionalKind<GetAccessorDeclarationStructure>[],\n OptionalKind<MethodDeclarationStructure>[],\n Array<string>,\n ]\n >(\n (collector, subtype) => {\n const subClass = this.dataModel.getModel(subtype) as ComplexType;\n const subClassName = imports.addGeneratedQObject(subClass.fqName, subClass.qName);\n const methodName = `__as${subClass.qName}`;\n const enumerablePropDef = imports.addQObject(QueryObjectImports.ENUMERABLE_PROP_DEFINITION);\n\n collector[0].push(`\"${subClass.fqName}\": \"${subClass.qName}\"`);\n\n subClass.props.forEach((prop) => {\n const propName = this.namingHelper.getQPropName(prop.name);\n const fqPropName = `${subClass.qName}_${propName}`;\n collector[1].push({\n name: fqPropName,\n scope: Scope.Public,\n statements: `return this.${methodName}().${propName};`,\n });\n collector[3].push(`${fqPropName}: ${enumerablePropDef}`);\n });\n\n collector[2].push({\n name: methodName,\n scope: Scope.Private,\n statements: `return new ${subClassName}(this.withPrefix(\"${subClass.fqName}\"))`,\n });\n\n return collector;\n },\n [[], [], [], []],\n );\n\n file.getFile().addClass({\n name: model.qName,\n isExported: true,\n extends: imports.addGeneratedQBaseObject(model),\n properties: [\n {\n name: \"__subtypeMapping\",\n scope: Scope.Protected,\n isReadonly: true,\n initializer: `{ ${props.join(\",\")} }`,\n },\n ],\n getAccessors,\n methods,\n });\n\n file.getFile().addStatements(`Object.defineProperties(${model.qName}.prototype, { ${statements.join(\",\")} });`);\n }\n\n file.getFile().addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n isExported: true,\n declarations: [\n {\n name: firstCharLowerCase(model.qName),\n initializer: `new ${model.qName}()`,\n },\n ],\n });\n }\n\n private generateQueryObjectProps(\n importContainer: ImportContainer,\n props: Array<PropertyModel>,\n ): Array<OptionalKind<PropertyDeclarationStructure>> {\n const isEnumType = (prop: PropertyModel) => prop.dataType === DataTypes.EnumType;\n const isModelType = (prop: PropertyModel) =>\n prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType;\n const addOptions = this.options.enableNativeInOperator; // limited to hardcoded enableNativeIn for now\n\n if (addOptions && props.some((prop) => !prop.isCollection && !isModelType(prop) && !isEnumType(prop))) {\n importContainer.addFromMainQObject(OPTIONS_STATEMENT);\n }\n\n return props.map((prop) => {\n const { odataName } = prop;\n const name = this.namingHelper.getQPropName(prop.name);\n\n let qPathInit: string;\n\n // factor in collections\n if (prop.isCollection) {\n const qPath = importContainer.addQObject(prop.qPath);\n const qObject = isModelType(prop)\n ? importContainer.addGeneratedQObject(prop.fqType, prop.qObject!)\n : isEnumType(prop)\n ? importContainer.addGeneratedModel(prop.fqType, prop.type, false)\n : importContainer.addQObject(prop.qObject!);\n\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\"), ${isEnumType(prop) ? qObject : `() => ${qObject}`})`;\n } else {\n // add import for data type\n const qPath = importContainer.addQObject(prop.qPath);\n if (isModelType(prop)) {\n const qObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject!);\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\"), () => ${qObject})`;\n } else if (isEnumType(prop)) {\n const qObject = importContainer.addGeneratedModel(prop.fqType, prop.type, false);\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\"), ${qObject})`;\n } else {\n let converterStmt = this.generateConverterStmt(importContainer, prop.converters);\n const addConverter = !!converterStmt;\n converterStmt = converterStmt || \"undefined\";\n\n qPathInit = `new ${qPath}(this.withPrefix(\"${odataName}\")${\n addOptions ? `, ${converterStmt}, ${OPTIONS_STATEMENT}` : addConverter ? `, ${converterStmt}` : \"\"\n })`;\n }\n }\n\n return {\n name,\n scope: Scope.Public,\n isReadonly: true,\n initializer: qPathInit,\n } as OptionalKind<PropertyDeclarationStructure>;\n });\n }\n\n private generateConverterStmt(importContainer: ImportContainer, converters: Array<ValueConverterImport> | undefined) {\n if (!converters?.length) {\n return undefined;\n }\n const converterIds = converters.map((converter) => {\n return importContainer.addCustomType(converter.package, converter.converterId);\n });\n\n if (converterIds.length === 1) {\n return converterIds[0];\n } else {\n const createChain = importContainer.addCustomType(\"@odata2ts/converter-runtime\", \"createChain\");\n\n const [first, second, ...moreConverters] = converterIds;\n return moreConverters.reduce((stmt, convId) => `${stmt}.chain(${convId})`, `${createChain}(${first}, ${second})`);\n }\n }\n\n private generateIdFunction(file: FileHandler, model: EntityType) {\n const importContainer = file.getImports();\n const qFunc = importContainer.addQObject(QueryObjectImports.QId);\n const idModelName = importContainer.addGeneratedModel(model.fqName, model.id.modelName);\n\n file.getFile().addClass({\n name: model.id.qName,\n isExported: true,\n extends: `${qFunc}<${idModelName}>`,\n properties: [\n {\n name: \"params\",\n scope: Scope.Private,\n isReadonly: true,\n initializer: this.getParamInitString(importContainer, model.keys),\n },\n ],\n methods: [\n {\n name: \"getParams\",\n statements: [\"return this.params\"],\n },\n ],\n });\n }\n\n private getParamInitString(\n importContainer: ImportContainer,\n props: Array<PropertyModel>,\n overloads?: Array<Array<PropertyModel>>,\n ) {\n const allParams = [props, ...(overloads ?? [])].map((paramSet) => {\n const pString = paramSet\n .map((prop) => {\n let complexQParam = \"\";\n if (prop.dataType === DataTypes.ModelType || prop.dataType === DataTypes.ComplexType) {\n const importedQObject = importContainer.addGeneratedQObject(prop.fqType, prop.qObject!);\n complexQParam = `, new ${importedQObject}()`;\n }\n\n const qParam = importContainer.addQObject(prop.qParam!);\n const isMappedNameNecessary = prop.odataName !== prop.name;\n const mappedName = isMappedNameNecessary\n ? `\"${prop.name}\"`\n : prop.converters?.length\n ? \"undefined\"\n : undefined;\n const converterStmt = this.generateConverterStmt(importContainer, prop.converters);\n const mappedNameParam = mappedName ? `, ${mappedName}` : \"\";\n const converterParam = converterStmt ? `, ${converterStmt}` : \"\";\n return `new ${qParam}(\"${prop.odataName}\"${complexQParam}${mappedNameParam}${converterParam})`;\n })\n .join(\",\");\n return `[${pString}]`;\n });\n\n return allParams.length === 1 ? allParams[0] : `[${allParams.join(\",\")}]`;\n }\n\n private async generateUnboundOperations() {\n const unboundOps = this.dataModel.getUnboundOperationTypes();\n const reservedNames = unboundOps.map((op) => op.qName);\n const file = this.project.createOrGetMainQObjectFile(reservedNames);\n\n unboundOps.forEach((operation) => {\n this.generateOperation(file, operation, \"\");\n });\n }\n\n private generateOperation(file: FileHandler, operation: OperationType, baseFqName: string) {\n const imports = file.getImports();\n const isV2 = this.version === ODataVersions.V2;\n const returnType = operation.returnType;\n const hasParams = operation.parameters.length > 0 || operation.overrides?.length;\n const isParamsOptional = !![operation.parameters, ...(operation.overrides ?? [])].find((pSet) => pSet.length === 0);\n\n // imports\n const qOp = operation.type === OperationTypes.Action ? QueryObjectImports.QAction : QueryObjectImports.QFunction;\n const qOperation = imports.addQObject(qOp);\n const paramModelName = hasParams ? imports.addGeneratedModel(baseFqName, operation.paramsModelName) : undefined;\n\n let returnTypeOpStmt: string = \"\";\n if (returnType) {\n if (returnType.dataType === DataTypes.ComplexType || returnType.dataType === DataTypes.ModelType) {\n if (returnType.qObject) {\n const opRt = imports.addQObject(QueryObjectImports.OperationReturnType);\n const rts = imports.addQObject(QueryObjectImports.ReturnTypes);\n const rType = returnType.isCollection\n ? \"COLLECTION\"\n : returnType.dataType === DataTypes.ComplexType\n ? \"COMPLEX\"\n : \"ENTITY\";\n const qComplexParam = imports.addQObject(QueryObjectImports.QComplexParam);\n const returnQName = imports.addGeneratedQObject(returnType.fqType, returnType.qObject);\n\n returnTypeOpStmt = `new ${opRt}(${rts}.${rType}, new ${qComplexParam}(\"NONE\", new ${returnQName}))`;\n }\n }\n // currently, it only makes sense to add the OperationReturnType if a converter is present\n else if (returnType.converters && returnType.qParam) {\n const rtClass = imports.addQObject(QueryObjectImports.OperationReturnType);\n const rtTypes = imports.addQObject(QueryObjectImports.ReturnTypes);\n const rType = returnType.isCollection ? \"COLLECTION\" : \"VALUE\";\n const qParam = imports.addQObject(returnType.qParam);\n\n const rtKind = `${rtTypes}.${rType}`;\n\n const converterParam = returnType.converters\n ? \", \" + this.generateConverterStmt(imports, returnType.converters)\n : \"\";\n returnTypeOpStmt = `new ${rtClass}(${rtKind}, new ${qParam}(\"NONE\", undefined${converterParam}))`;\n }\n }\n\n file.getFile().addClass({\n name: operation.qName,\n isExported: true,\n extends: qOperation + (hasParams ? `<${paramModelName}>` : \"\"),\n properties: [\n {\n name: \"params\",\n scope: Scope.Private,\n isReadonly: true,\n type: hasParams ? undefined : \"[]\",\n initializer: this.getParamInitString(imports, operation.parameters, operation.overrides),\n },\n ],\n ctors: [\n {\n statements: [\n `super(\"${operation.odataName}\"${returnTypeOpStmt ? \", \" + returnTypeOpStmt : isV2 ? \", undefined\" : \"\"}${\n isV2 ? \", { v2Mode: true }\" : \"\"\n })`,\n ],\n },\n ],\n methods: [\n {\n name: \"getParams\",\n statements: [\"return this.params\"],\n },\n // functions without params: add an overriding buildUrl() to not force users to have to pass undefined as param\n ...(operation.type === OperationTypes.Function && !hasParams\n ? [\n {\n name: \"buildUrl\",\n parameters: [\n {\n name: \"notEncoded\",\n initializer: \"false\",\n },\n ],\n statements: [\"return super.buildUrl(undefined, notEncoded)\"],\n } as OptionalKind<MethodDeclarationStructure>,\n ]\n : []),\n ],\n });\n }\n}\n"]}
|
|
@@ -278,7 +278,7 @@ class ServiceGenerator {
|
|
|
278
278
|
const propEnum = this.dataModel.getModel(prop.fqType);
|
|
279
279
|
const propTypeModel = imports.addGeneratedModel(propEnum.fqName, propEnum.modelName, false);
|
|
280
280
|
type = `${imports.addQObjectType(QueryObjectImports.EnumCollection)}<typeof ${propTypeModel}>`;
|
|
281
|
-
qType = `${imports.addQObjectType(
|
|
281
|
+
qType = `${imports.addQObjectType(prop.qObject)}<typeof ${propTypeModel}>`;
|
|
282
282
|
}
|
|
283
283
|
else {
|
|
284
284
|
// TODO refactor string concat
|