Skip to content

Commit

Permalink
Generate non-grpc implementations for value-type argument containing …
Browse files Browse the repository at this point in the history
…methods
  • Loading branch information
programmador committed Dec 21, 2023
1 parent 87cfd76 commit 36219d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions integration/wrappers-regression/wrappers-regression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ export class ClockClientImpl implements Clock {
return promise.then((data) => Timestamp.decode(_m0.Reader.create(data)));
}

NowString(request: StringValue): Promise<StringValue> {
const data = StringValue.encode(request).finish();
NowString(request: string | undefined): Promise<StringValue> {
const data = StringValue.encode({ value: request }).finish();
const promise = this.rpc.request(this.service, "NowString", data);
return promise.then((data) => StringValue.decode(_m0.Reader.create(data)));
}

NowStringStream(request: Observable<StringValue>): Observable<StringValue> {
const data = request.pipe(map((request) => StringValue.encode(request).finish()));
const data = request.pipe(map((request) => StringValue.encode({ value: request }).finish()));
const result = this.rpc.bidirectionalStreamingRequest(this.service, "NowStringStream", data);
return result.pipe(map((data) => StringValue.decode(_m0.Reader.create(data))));
}
Expand Down
6 changes: 4 additions & 2 deletions src/generate-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ function generateRegularRpcMethod(ctx: Context, methodDesc: MethodDescriptorProt
const { options } = ctx;
const Reader = impFile(ctx.options, "Reader@protobufjs/minimal");
const rawInputType = rawRequestType(ctx, methodDesc, { keepValueType: true });
const inputType = requestType(ctx, methodDesc);
const isValueType = valueTypeName(ctx, methodDesc.inputType) !== undefined;
const inputType = requestType(ctx, methodDesc, false, !isValueType || methodDesc.clientStreaming);
const rawOutputType = responseType(ctx, methodDesc, { keepValueType: true });

const params = [
Expand All @@ -132,7 +133,8 @@ function generateRegularRpcMethod(ctx: Context, methodDesc: MethodDescriptorProt
`;
}

let encode = code`${rawInputType}.encode(request).finish()`;
const inputValue = isValueType ? '{ value: request }' : 'request';
let encode = code`${rawInputType}.encode(${inputValue}).finish()`;
let beforeRequest;
if (options.rpcBeforeRequest) {
beforeRequest = code`
Expand Down

0 comments on commit 36219d7

Please sign in to comment.