From 2a5fe835a6dd8e9cad8b3fcc1093c3aa55b29f75 Mon Sep 17 00:00:00 2001 From: Kanro Date: Wed, 9 Sep 2020 16:10:07 +0800 Subject: [PATCH] :bug: Use arrow function to fix 'this' issue (#10) * :bug: Use arrow function to fix 'this' issue * :bookmark: v0.0.1-alpha.11 --- lerna.json | 2 +- packages/sisyphus-cli/package-lock.json | 2 +- packages/sisyphus-cli/package.json | 4 ++-- packages/sisyphus-core/package-lock.json | 2 +- packages/sisyphus-core/package.json | 2 +- packages/sisyphus-core/src/transcoding.ts | 6 +++--- packages/sisyphus-generator/package.json | 4 ++-- packages/sisyphus-generator/src/generator/service.ts | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lerna.json b/lerna.json index 97e950f..667ceb9 100644 --- a/lerna.json +++ b/lerna.json @@ -2,5 +2,5 @@ "packages": [ "packages/*" ], - "version": "0.0.1-alpha.10" + "version": "0.0.1-alpha.11" } diff --git a/packages/sisyphus-cli/package-lock.json b/packages/sisyphus-cli/package-lock.json index 875819d..8953006 100644 --- a/packages/sisyphus-cli/package-lock.json +++ b/packages/sisyphus-cli/package-lock.json @@ -1,6 +1,6 @@ { "name": "@sisyphus.js/cli", - "version": "0.0.1-alpha.10", + "version": "0.0.1-alpha.11", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/sisyphus-cli/package.json b/packages/sisyphus-cli/package.json index 73efa1d..230365e 100644 --- a/packages/sisyphus-cli/package.json +++ b/packages/sisyphus-cli/package.json @@ -1,6 +1,6 @@ { "name": "@sisyphus.js/cli", - "version": "0.0.1-alpha.10", + "version": "0.0.1-alpha.11", "description": "Protobuf generator cli for sisyphus project", "author": "Kanro ", "bugs": { @@ -24,7 +24,7 @@ "build": "tsc" }, "dependencies": { - "@sisyphus.js/generator": "^0.0.1-alpha.10", + "@sisyphus.js/generator": "^0.0.1-alpha.11", "commander": "^6.0.0" }, "devDependencies": { diff --git a/packages/sisyphus-core/package-lock.json b/packages/sisyphus-core/package-lock.json index c628827..53deb66 100644 --- a/packages/sisyphus-core/package-lock.json +++ b/packages/sisyphus-core/package-lock.json @@ -1,6 +1,6 @@ { "name": "@sisyphus.js/core", - "version": "0.0.1-alpha.10", + "version": "0.0.1-alpha.11", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/sisyphus-core/package.json b/packages/sisyphus-core/package.json index a8705d1..2169391 100644 --- a/packages/sisyphus-core/package.json +++ b/packages/sisyphus-core/package.json @@ -1,6 +1,6 @@ { "name": "@sisyphus.js/core", - "version": "0.0.1-alpha.10", + "version": "0.0.1-alpha.11", "description": "Protobuf runtime for sisyphus project on js platform", "author": "Kanro ", "bugs": { diff --git a/packages/sisyphus-core/src/transcoding.ts b/packages/sisyphus-core/src/transcoding.ts index df331cb..26601e9 100644 --- a/packages/sisyphus-core/src/transcoding.ts +++ b/packages/sisyphus-core/src/transcoding.ts @@ -1,6 +1,6 @@ import {Message, MessageConstructor} from "./message" import {IRpcConfig, IRpcImpl} from "./client" -import {Method, Type} from "protobufjs" +import {Method, Type, util} from "protobufjs" import {GrpcStatusError} from "./error"; export interface IHttpRule { @@ -75,7 +75,7 @@ function getField(message: any, field: string | string[]): any { } for (let string of field) { - message = message[string] + message = message[util.camelCase(string)] } return message } @@ -86,7 +86,7 @@ function getFieldInfo(type: Type, field: string | string[]): Type | null { } for (let string of field) { - type = type.fields[string].resolvedType + type = type.fields[util.camelCase(string)].resolvedType if (!type) return null } diff --git a/packages/sisyphus-generator/package.json b/packages/sisyphus-generator/package.json index 1607aa1..c818631 100644 --- a/packages/sisyphus-generator/package.json +++ b/packages/sisyphus-generator/package.json @@ -1,6 +1,6 @@ { "name": "@sisyphus.js/generator", - "version": "0.0.1-alpha.10", + "version": "0.0.1-alpha.11", "description": "Protobuf generator for sisyphus project on js platform", "author": "Kanro ", "bugs": { @@ -21,7 +21,7 @@ "build": "tsc" }, "dependencies": { - "@sisyphus.js/core": "^0.0.1-alpha.10", + "@sisyphus.js/core": "^0.0.1-alpha.11", "change-case": "^4.1.1", "protobufjs": "^6.10.1" }, diff --git a/packages/sisyphus-generator/src/generator/service.ts b/packages/sisyphus-generator/src/generator/service.ts index c4ba50b..18008bd 100644 --- a/packages/sisyphus-generator/src/generator/service.ts +++ b/packages/sisyphus-generator/src/generator/service.ts @@ -40,7 +40,7 @@ export class ServiceSpec implements GeneratorSpec { if (method.comment != null) { b.appendLn(normalizeComment(method.comment)) } - b.beginBlock(`async ${method.name}(input: ${this.file.typename(method.resolvedRequestType)}, metadata?: { [k: string]: string }): Promise<${this.file.classname(method.resolvedResponseType)}>`) + b.beginBlock(`${method.name} = async (input: ${this.file.typename(method.resolvedRequestType)}, metadata?: { [k: string]: string }): Promise<${this.file.classname(method.resolvedResponseType)}> =>`) b.appendLn(`return await this.$call(this.$service.methods["${method.name}"], input, metadata)`) b.endBlock() }