From 063fd29974e0e917ad69cd5a158ee233edb5e019 Mon Sep 17 00:00:00 2001 From: Alexander Konotop Date: Wed, 20 Dec 2023 23:40:17 +0200 Subject: [PATCH] fix: Fix generating wrong web-rpc implementation for wrapper-type method arg (#978) * Fix generating wrong web-rpc implementation for wrapper-type method arguments * Improve grpc-web tests to cover wrapper-containing rpc definitions * Fix proto/rpc method naming misprint * Add changed example.ts. --------- Co-authored-by: Stephen Haberman --- integration/grpc-web/example.bin | Bin 3278 -> 8011 bytes integration/grpc-web/example.proto | 3 +- integration/grpc-web/example.ts | 30 + .../grpc-web/google/protobuf/wrappers.ts | 661 ++++++++++++++++++ src/generate-grpc-web.ts | 2 +- 5 files changed, 694 insertions(+), 2 deletions(-) create mode 100644 integration/grpc-web/google/protobuf/wrappers.ts diff --git a/integration/grpc-web/example.bin b/integration/grpc-web/example.bin index 72f331cf3e1bc492cb01c75424a58d5c31f7426c..5de3fbf9b8a5c28e33668e0b5fba21b19a3c9788 100644 GIT binary patch literal 8011 zcmbtYOLyDIl?FkGB1@7@LGHB7W6KqF(w5y4CChEO{pd;ffMs-KQU*yYN)|1Mge0U% zf+j$#)tk&Yvz=ct%lQ{Gi)`})aalCVJMZ&>vCL57+?K@ z%~gZZao2m}c1NChgU!67hvgJct)(0(tgbTlq8qr;B|7?qj@^%TzP>~!9qS-i>nbH9 zRzfi7Jlwv-(M+tP99^ok5G(zX<;p?Oy~Iy8R)L>JH1zwYmnh|8B>*a4L|%A_&b-no z|67VJwS!*qJ$lOv2a5lFnydZPA08-;)1d42Pm96ubUatl#lQLSeFjJ#KM96CH)6aJ3@(QL=~=|Lx3<1f2Hftq zi=3CbT`tB#KJ-Fw_|EGT89$4nLHKlYv*W$=@+kQ0ba#<=5k{17v6 zJc|6F&)t59k3tV{co>X^ZBM*8_WSPeLf{J5`MDpR@n9(a2P5F@1s(syZ@c7Sox4Mi zBXZA=BCo@-4&M14JVa-1gdfVT+YQb!<-8sAJ3bkOWCTB6^c0Zj@BVwhLLQ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|!Ije-Q+w;nw@-8>U)8E7xsioC*apf6fl$M@V^&m1?qqUU6s)nqYobgHc zq=Hmoun`thrJyQR#$d&=%$5f%c9=(ASV+ADTwE+MC#`DAWA-GtrsF7AGdxT^V9kPM z45B3?wiK|I!xXSqm`y#JJUl{Csg>1jah>d2(^xw=+wD`-y2Gs@u&=}WpfK3s)==2j z;ns>0cDXeKu&%?Xb(dSi1J*@p#7MNZx+iY-F*L?{979u#KJSCTzCQ1R!eF2GL1AB? zkGOk*15OVCY~V18G2ry@fF%QtkN0cU&^?ZhKXe>b8@k6ya6|Vvh!G!OOFI6@VRY3I zA0Hk~^6`DE$Knp96MS+$#>U**r`8jW0fBuJ-Uo%j3CDoKz6r#0c>XWNcN, metadata?: grpc.Metadata): Promise; Update(request: DeepPartial, metadata?: grpc.Metadata): Promise; Delete(request: DeepPartial, metadata?: grpc.Metadata): Promise; + Uppercase(request: DeepPartial, metadata?: grpc.Metadata): Promise; } export class DashAPICredsClientImpl implements DashAPICreds { @@ -836,6 +838,7 @@ export class DashAPICredsClientImpl implements DashAPICreds { this.Create = this.Create.bind(this); this.Update = this.Update.bind(this); this.Delete = this.Delete.bind(this); + this.Uppercase = this.Uppercase.bind(this); } Create(request: DeepPartial, metadata?: grpc.Metadata): Promise { @@ -849,6 +852,10 @@ export class DashAPICredsClientImpl implements DashAPICreds { Delete(request: DeepPartial, metadata?: grpc.Metadata): Promise { return this.rpc.unary(DashAPICredsDeleteDesc, DashAPICredsDeleteReq.fromPartial(request), metadata); } + + Uppercase(request: DeepPartial, metadata?: grpc.Metadata): Promise { + return this.rpc.unary(DashAPICredsUppercaseDesc, StringValue.fromPartial(request), metadata); + } } export const DashAPICredsDesc = { serviceName: "rpx.DashAPICreds" }; @@ -922,6 +929,29 @@ export const DashAPICredsDeleteDesc: UnaryMethodDefinitionish = { } as any, }; +export const DashAPICredsUppercaseDesc: UnaryMethodDefinitionish = { + methodName: "Uppercase", + service: DashAPICredsDesc, + requestStream: false, + responseStream: false, + requestType: { + serializeBinary() { + return StringValue.encode(this).finish(); + }, + } as any, + responseType: { + deserializeBinary(data: Uint8Array) { + const value = StringValue.decode(data); + return { + ...value, + toObject() { + return value; + }, + }; + }, + } as any, +}; + interface UnaryMethodDefinitionishR extends grpc.UnaryMethodDefinition { requestStream: any; responseStream: any; diff --git a/integration/grpc-web/google/protobuf/wrappers.ts b/integration/grpc-web/google/protobuf/wrappers.ts new file mode 100644 index 000000000..6aa1a51cc --- /dev/null +++ b/integration/grpc-web/google/protobuf/wrappers.ts @@ -0,0 +1,661 @@ +/* eslint-disable */ +import * as _m0 from "protobufjs/minimal"; +import Long = require("long"); + +export const protobufPackage = "google.protobuf"; + +/** + * Wrapper message for `double`. + * + * The JSON representation for `DoubleValue` is JSON number. + */ +export interface DoubleValue { + /** The double value. */ + value: number; +} + +/** + * Wrapper message for `float`. + * + * The JSON representation for `FloatValue` is JSON number. + */ +export interface FloatValue { + /** The float value. */ + value: number; +} + +/** + * Wrapper message for `int64`. + * + * The JSON representation for `Int64Value` is JSON string. + */ +export interface Int64Value { + /** The int64 value. */ + value: number; +} + +/** + * Wrapper message for `uint64`. + * + * The JSON representation for `UInt64Value` is JSON string. + */ +export interface UInt64Value { + /** The uint64 value. */ + value: number; +} + +/** + * Wrapper message for `int32`. + * + * The JSON representation for `Int32Value` is JSON number. + */ +export interface Int32Value { + /** The int32 value. */ + value: number; +} + +/** + * Wrapper message for `uint32`. + * + * The JSON representation for `UInt32Value` is JSON number. + */ +export interface UInt32Value { + /** The uint32 value. */ + value: number; +} + +/** + * Wrapper message for `bool`. + * + * The JSON representation for `BoolValue` is JSON `true` and `false`. + */ +export interface BoolValue { + /** The bool value. */ + value: boolean; +} + +/** + * Wrapper message for `string`. + * + * The JSON representation for `StringValue` is JSON string. + */ +export interface StringValue { + /** The string value. */ + value: string; +} + +/** + * Wrapper message for `bytes`. + * + * The JSON representation for `BytesValue` is JSON string. + */ +export interface BytesValue { + /** The bytes value. */ + value: Uint8Array; +} + +function createBaseDoubleValue(): DoubleValue { + return { value: 0 }; +} + +export const DoubleValue = { + encode(message: DoubleValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== 0) { + writer.uint32(9).double(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): DoubleValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseDoubleValue(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 9) { + break; + } + + message.value = reader.double(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): DoubleValue { + return { value: isSet(object.value) ? globalThis.Number(object.value) : 0 }; + }, + + toJSON(message: DoubleValue): unknown { + const obj: any = {}; + if (message.value !== 0) { + obj.value = message.value; + } + return obj; + }, + + create, I>>(base?: I): DoubleValue { + return DoubleValue.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): DoubleValue { + const message = createBaseDoubleValue(); + message.value = object.value ?? 0; + return message; + }, +}; + +function createBaseFloatValue(): FloatValue { + return { value: 0 }; +} + +export const FloatValue = { + encode(message: FloatValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== 0) { + writer.uint32(13).float(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): FloatValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseFloatValue(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 13) { + break; + } + + message.value = reader.float(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): FloatValue { + return { value: isSet(object.value) ? globalThis.Number(object.value) : 0 }; + }, + + toJSON(message: FloatValue): unknown { + const obj: any = {}; + if (message.value !== 0) { + obj.value = message.value; + } + return obj; + }, + + create, I>>(base?: I): FloatValue { + return FloatValue.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): FloatValue { + const message = createBaseFloatValue(); + message.value = object.value ?? 0; + return message; + }, +}; + +function createBaseInt64Value(): Int64Value { + return { value: 0 }; +} + +export const Int64Value = { + encode(message: Int64Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== 0) { + writer.uint32(8).int64(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Int64Value { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseInt64Value(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break; + } + + message.value = longToNumber(reader.int64() as Long); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): Int64Value { + return { value: isSet(object.value) ? globalThis.Number(object.value) : 0 }; + }, + + toJSON(message: Int64Value): unknown { + const obj: any = {}; + if (message.value !== 0) { + obj.value = Math.round(message.value); + } + return obj; + }, + + create, I>>(base?: I): Int64Value { + return Int64Value.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): Int64Value { + const message = createBaseInt64Value(); + message.value = object.value ?? 0; + return message; + }, +}; + +function createBaseUInt64Value(): UInt64Value { + return { value: 0 }; +} + +export const UInt64Value = { + encode(message: UInt64Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== 0) { + writer.uint32(8).uint64(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): UInt64Value { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseUInt64Value(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break; + } + + message.value = longToNumber(reader.uint64() as Long); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): UInt64Value { + return { value: isSet(object.value) ? globalThis.Number(object.value) : 0 }; + }, + + toJSON(message: UInt64Value): unknown { + const obj: any = {}; + if (message.value !== 0) { + obj.value = Math.round(message.value); + } + return obj; + }, + + create, I>>(base?: I): UInt64Value { + return UInt64Value.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): UInt64Value { + const message = createBaseUInt64Value(); + message.value = object.value ?? 0; + return message; + }, +}; + +function createBaseInt32Value(): Int32Value { + return { value: 0 }; +} + +export const Int32Value = { + encode(message: Int32Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== 0) { + writer.uint32(8).int32(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Int32Value { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseInt32Value(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break; + } + + message.value = reader.int32(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): Int32Value { + return { value: isSet(object.value) ? globalThis.Number(object.value) : 0 }; + }, + + toJSON(message: Int32Value): unknown { + const obj: any = {}; + if (message.value !== 0) { + obj.value = Math.round(message.value); + } + return obj; + }, + + create, I>>(base?: I): Int32Value { + return Int32Value.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): Int32Value { + const message = createBaseInt32Value(); + message.value = object.value ?? 0; + return message; + }, +}; + +function createBaseUInt32Value(): UInt32Value { + return { value: 0 }; +} + +export const UInt32Value = { + encode(message: UInt32Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== 0) { + writer.uint32(8).uint32(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): UInt32Value { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseUInt32Value(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break; + } + + message.value = reader.uint32(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): UInt32Value { + return { value: isSet(object.value) ? globalThis.Number(object.value) : 0 }; + }, + + toJSON(message: UInt32Value): unknown { + const obj: any = {}; + if (message.value !== 0) { + obj.value = Math.round(message.value); + } + return obj; + }, + + create, I>>(base?: I): UInt32Value { + return UInt32Value.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): UInt32Value { + const message = createBaseUInt32Value(); + message.value = object.value ?? 0; + return message; + }, +}; + +function createBaseBoolValue(): BoolValue { + return { value: false }; +} + +export const BoolValue = { + encode(message: BoolValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value === true) { + writer.uint32(8).bool(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): BoolValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseBoolValue(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break; + } + + message.value = reader.bool(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): BoolValue { + return { value: isSet(object.value) ? globalThis.Boolean(object.value) : false }; + }, + + toJSON(message: BoolValue): unknown { + const obj: any = {}; + if (message.value === true) { + obj.value = message.value; + } + return obj; + }, + + create, I>>(base?: I): BoolValue { + return BoolValue.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): BoolValue { + const message = createBaseBoolValue(); + message.value = object.value ?? false; + return message; + }, +}; + +function createBaseStringValue(): StringValue { + return { value: "" }; +} + +export const StringValue = { + encode(message: StringValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value !== "") { + writer.uint32(10).string(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): StringValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseStringValue(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + + message.value = reader.string(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): StringValue { + return { value: isSet(object.value) ? globalThis.String(object.value) : "" }; + }, + + toJSON(message: StringValue): unknown { + const obj: any = {}; + if (message.value !== "") { + obj.value = message.value; + } + return obj; + }, + + create, I>>(base?: I): StringValue { + return StringValue.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): StringValue { + const message = createBaseStringValue(); + message.value = object.value ?? ""; + return message; + }, +}; + +function createBaseBytesValue(): BytesValue { + return { value: new Uint8Array(0) }; +} + +export const BytesValue = { + encode(message: BytesValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.value.length !== 0) { + writer.uint32(10).bytes(message.value); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): BytesValue { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseBytesValue(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + + message.value = reader.bytes(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): BytesValue { + return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; + }, + + toJSON(message: BytesValue): unknown { + const obj: any = {}; + if (message.value.length !== 0) { + obj.value = base64FromBytes(message.value); + } + return obj; + }, + + create, I>>(base?: I): BytesValue { + return BytesValue.fromPartial(base ?? ({} as any)); + }, + fromPartial, I>>(object: I): BytesValue { + const message = createBaseBytesValue(); + message.value = object.value ?? new Uint8Array(0); + return message; + }, +}; + +function bytesFromBase64(b64: string): Uint8Array { + if (globalThis.Buffer) { + return Uint8Array.from(globalThis.Buffer.from(b64, "base64")); + } else { + const bin = globalThis.atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; + } +} + +function base64FromBytes(arr: Uint8Array): string { + if (globalThis.Buffer) { + return globalThis.Buffer.from(arr).toString("base64"); + } else { + const bin: string[] = []; + arr.forEach((byte) => { + bin.push(globalThis.String.fromCharCode(byte)); + }); + return globalThis.btoa(bin.join("")); + } +} + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; + +export type DeepPartial = T extends Builtin ? T + : T extends globalThis.Array ? globalThis.Array> + : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; + +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P + : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +function longToNumber(long: Long): number { + if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) { + throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER"); + } + return long.toNumber(); +} + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any; + _m0.configure(); +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined; +} diff --git a/src/generate-grpc-web.ts b/src/generate-grpc-web.ts index 6bbe4f09b..7328b8025 100644 --- a/src/generate-grpc-web.ts +++ b/src/generate-grpc-web.ts @@ -50,7 +50,7 @@ function generateRpcMethod(ctx: Context, serviceDesc: ServiceDescriptorProto, me assertInstanceOf(methodDesc, FormattedMethodDescriptor); const { options } = ctx; const { useAbortSignal } = options; - const requestMessage = rawRequestType(ctx, methodDesc); + const requestMessage = requestType(ctx, methodDesc, false); const inputType = requestType(ctx, methodDesc, true); const returns = responsePromiseOrObservable(ctx, methodDesc);