@r2don/nest-http-interface
Advanced tools
@@ -9,3 +9,4 @@ import * as ts from 'typescript'; | ||
| importSet: Set<string>; | ||
| visit(sourceFile: ts.SourceFile, ctx: ts.TransformationContext, _program: ts.Program): ts.Node; | ||
| typeFormatFlag: number; | ||
| visit(sourceFile: ts.SourceFile, ctx: ts.TransformationContext, program: ts.Program): ts.Node; | ||
| private updateSourceFile; | ||
@@ -12,0 +13,0 @@ private visitMethods; |
@@ -29,8 +29,6 @@ "use strict"; | ||
| const decorators_1 = require("../../decorators"); | ||
| const graphql_exchange_decorator_1 = require("../../decorators/graphql-exchange.decorator"); | ||
| const response_body_decorator_1 = require("../../decorators/response-body.decorator"); | ||
| class HttpInterfaceVisitor { | ||
| constructor() { | ||
| this.HTTP_INTERFACE_DECORATOR = decorators_1.HttpInterface.name; | ||
| this.RESPONSE_BODY_DECORATOR = response_body_decorator_1.ResponseBody.name; | ||
| this.RESPONSE_BODY_DECORATOR = decorators_1.ResponseBody.name; | ||
| this.ALL_EXCHANGE_DECORATORS = [ | ||
@@ -44,3 +42,3 @@ decorators_1.GetExchange.name, | ||
| decorators_1.OptionsExchange.name, | ||
| graphql_exchange_decorator_1.GraphQLExchange.name, | ||
| decorators_1.GraphQLExchange.name, | ||
| ]; | ||
@@ -50,9 +48,14 @@ this.libModuleAlias = 'eager_module_1'; | ||
| this.importSet = new Set(); | ||
| this.typeFormatFlag = ts.TypeFormatFlags.UseTypeOfFunction | | ||
| ts.TypeFormatFlags.NoTruncation | | ||
| ts.TypeFormatFlags.UseFullyQualifiedType | | ||
| ts.TypeFormatFlags.WriteTypeArgumentsOfSignature; | ||
| } | ||
| visit(sourceFile, ctx, _program) { | ||
| visit(sourceFile, ctx, program) { | ||
| this.importSet.clear(); | ||
| const factory = ctx.factory; | ||
| const typeChecker = program.getTypeChecker(); | ||
| const visitNode = (node) => { | ||
| if (this.isHttpInterfaceClass(node)) { | ||
| return this.visitMethods(node, factory); | ||
| return this.visitMethods(node, factory, typeChecker); | ||
| } | ||
@@ -78,3 +81,3 @@ if (ts.isSourceFile(node)) { | ||
| } | ||
| visitMethods(node, factory) { | ||
| visitMethods(node, factory, typeChecker) { | ||
| const updatedMembers = node.members.map((member) => { | ||
@@ -84,3 +87,3 @@ if (!this.isExchangeMethod(member)) { | ||
| } | ||
| return this.appendResponseBodyDecorator(member, factory); | ||
| return this.appendResponseBodyDecorator(member, factory, typeChecker); | ||
| }); | ||
@@ -93,5 +96,5 @@ return factory.updateClassDeclaration(node, node.modifiers, node.name, node.typeParameters, node.heritageClauses, updatedMembers); | ||
| } | ||
| appendResponseBodyDecorator(node, factory) { | ||
| appendResponseBodyDecorator(node, factory, typeChecker) { | ||
| var _a; | ||
| const returnType = this.getReturnTypeAsText(node); | ||
| const returnType = this.getReturnTypeAsText(node, typeChecker); | ||
| if (returnType == null) { | ||
@@ -106,3 +109,3 @@ return node; | ||
| } | ||
| getReturnTypeAsText(node) { | ||
| getReturnTypeAsText(node, typeChecker) { | ||
| var _a; | ||
@@ -121,3 +124,5 @@ if (node.type == null || | ||
| } | ||
| return innerType.typeName.text; | ||
| return typeChecker | ||
| .typeToString(typeChecker.getTypeAtLocation(innerType), undefined, this.typeFormatFlag) | ||
| .replace('import', 'require'); | ||
| } | ||
@@ -124,0 +129,0 @@ getInnerType(node) { |
+3
-3
| { | ||
| "name": "@r2don/nest-http-interface", | ||
| "version": "1.1.4-rc.1", | ||
| "version": "1.1.4-rc.2", | ||
| "description": "HTTP client for Nest framework, inspired by HTTP interface in Spring 6", | ||
@@ -58,4 +58,4 @@ "maintainers": [ | ||
| "peerDependencies": { | ||
| "@nestjs/common": "^8.0.0", | ||
| "@nestjs/core": "^8.0.0", | ||
| "@nestjs/common": "^8.0.0 || ^9.0.0", | ||
| "@nestjs/core": "^8.0.0 || ^9.0.0", | ||
| "class-transformer": "*", | ||
@@ -62,0 +62,0 @@ "reflect-metadata": "*" |
+1
-1
@@ -58,3 +58,3 @@ <p align="center"> | ||
| async request(@PathVariable() id: number): Promise<UserResponse> { | ||
| return imitation(); // this is a mock function to prevent the type error | ||
| return imitation(id); // this is a mock function to prevent the type error | ||
| } | ||
@@ -61,0 +61,0 @@ } |
61450
0.54%1158
0.52%