diff --git a/src/generate-services.ts b/src/generate-services.ts index ec9a6a9b5..7a8b760df 100644 --- a/src/generate-services.ts +++ b/src/generate-services.ts @@ -72,15 +72,11 @@ export function generateService( params.push(code`metadata?: grpc.Metadata`); } else if (options.addGrpcMetadata) { const Metadata = imp("Metadata@@grpc/grpc-js"); - const q = options.addNestjsRestParameter ? "" : "?"; - params.push(code`metadata${q}: ${Metadata}`); + params.push(code`metadata?: ${Metadata}`); } else if (options.metadataType) { const Metadata = imp(options.metadataType); params.push(code`metadata?: ${Metadata}`); } - if (options.addNestjsRestParameter) { - params.push(code`...rest: any`); - } chunks.push( code`${methodDesc.formattedName}(${joinCode(params, { on: "," })}): ${responsePromiseOrObservable( @@ -117,9 +113,11 @@ function generateRegularRpcMethod(ctx: Context, methodDesc: MethodDescriptorProt const params = [ ...(options.context ? [code`ctx: Context`] : []), code`request: ${inputType}`, + ...(options.addGrpcMetadata ? [code`metadata?: Metadata`] : []), ...(options.useAbortSignal ? [code`abortSignal?: AbortSignal`] : []), ]; const maybeCtx = options.context ? "ctx," : ""; + const maybeMetadata = options.addGrpcMetadata ? "metadata," : ""; const maybeAbortSignal = options.useAbortSignal ? "abortSignal || undefined," : ""; let encode = code`${rawInputType}.encode(request).finish()`; @@ -169,6 +167,7 @@ function generateRegularRpcMethod(ctx: Context, methodDesc: MethodDescriptorProt this.service, "${methodDesc.name}", data, + ${maybeMetadata} ${maybeAbortSignal} ); return ${decode}; @@ -335,6 +334,7 @@ export function generateRpcType(ctx: Context, hasStreamingMethods: boolean): Cod const { options } = ctx; const maybeContext = options.context ? "" : ""; const maybeContextParam = options.context ? "ctx: Context," : ""; + const maybeMetadataParam = options.addGrpcMetadata ? `metadata?: Metadata,` : ""; const maybeAbortSignalParam = options.useAbortSignal ? "abortSignal?: AbortSignal," : ""; const methods = [[code`request`, code`Uint8Array`, code`Promise`]]; if (hasStreamingMethods) { @@ -356,6 +356,7 @@ export function generateRpcType(ctx: Context, hasStreamingMethods: boolean): Cod service: string, method: string, data: ${method[1]}, + ${maybeMetadataParam} ${maybeAbortSignalParam} ): ${method[2]};`); });