ts-proto 1.169.0 → 1.169.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/generate-services.js +13 -5
- package/package.json +1 -1
|
@@ -42,15 +42,15 @@ function generateService(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
42
42
|
// We have to use grpc.Metadata where grpc will come from @improbable-eng
|
|
43
43
|
params.push((0, ts_poet_1.code) `metadata?: grpc.Metadata`);
|
|
44
44
|
}
|
|
45
|
-
else if (options.addGrpcMetadata) {
|
|
46
|
-
const Metadata = (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
|
|
47
|
-
const q = options.addNestjsRestParameter ? "" : "?";
|
|
48
|
-
params.push((0, ts_poet_1.code) `metadata${q}: ${Metadata}`);
|
|
49
|
-
}
|
|
50
45
|
else if (options.metadataType) {
|
|
46
|
+
// custom `metadataType` has precedence over `addGrpcMetadata` that injects Metadata from grpc-js
|
|
51
47
|
const Metadata = (0, ts_poet_1.imp)(options.metadataType);
|
|
52
48
|
params.push((0, ts_poet_1.code) `metadata?: ${Metadata}`);
|
|
53
49
|
}
|
|
50
|
+
else if (options.addGrpcMetadata) {
|
|
51
|
+
const Metadata = (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
|
|
52
|
+
params.push((0, ts_poet_1.code) `metadata?: ${Metadata}`);
|
|
53
|
+
}
|
|
54
54
|
if (options.useAbortSignal) {
|
|
55
55
|
params.push((0, ts_poet_1.code) `abortSignal?: AbortSignal`);
|
|
56
56
|
}
|
|
@@ -80,12 +80,15 @@ function generateRegularRpcMethod(ctx, methodDesc) {
|
|
|
80
80
|
const rawInputType = (0, types_1.rawRequestType)(ctx, methodDesc, { keepValueType: true });
|
|
81
81
|
const inputType = (0, types_1.requestType)(ctx, methodDesc);
|
|
82
82
|
const rawOutputType = (0, types_1.responseType)(ctx, methodDesc, { keepValueType: true });
|
|
83
|
+
const metadataType = options.metadataType ? (0, ts_poet_1.imp)(options.metadataType) : (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
|
|
83
84
|
const params = [
|
|
84
85
|
...(options.context ? [(0, ts_poet_1.code) `ctx: Context`] : []),
|
|
85
86
|
(0, ts_poet_1.code) `request: ${inputType}`,
|
|
87
|
+
...(options.metadataType || options.addGrpcMetadata ? [(0, ts_poet_1.code) `metadata?: ${metadataType}`] : []),
|
|
86
88
|
...(options.useAbortSignal ? [(0, ts_poet_1.code) `abortSignal?: AbortSignal`] : []),
|
|
87
89
|
];
|
|
88
90
|
const maybeCtx = options.context ? "ctx," : "";
|
|
91
|
+
const maybeMetadata = options.addGrpcMetadata ? "metadata," : "";
|
|
89
92
|
const maybeAbortSignal = options.useAbortSignal ? "abortSignal || undefined," : "";
|
|
90
93
|
let errorHandler;
|
|
91
94
|
if (options.rpcErrorHandler) {
|
|
@@ -156,6 +159,7 @@ function generateRegularRpcMethod(ctx, methodDesc) {
|
|
|
156
159
|
this.service,
|
|
157
160
|
"${methodDesc.name}",
|
|
158
161
|
data,
|
|
162
|
+
${maybeMetadata}
|
|
159
163
|
${maybeAbortSignal}
|
|
160
164
|
);
|
|
161
165
|
return ${returnStatement};
|
|
@@ -330,8 +334,11 @@ function generateCachingRpcMethod(ctx, fileDesc, serviceDesc, methodDesc) {
|
|
|
330
334
|
*/
|
|
331
335
|
function generateRpcType(ctx, hasStreamingMethods) {
|
|
332
336
|
const { options } = ctx;
|
|
337
|
+
const metadata = options.metadataType ? (0, ts_poet_1.imp)(options.metadataType) : (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
|
|
338
|
+
const metadataType = metadata.symbol;
|
|
333
339
|
const maybeContext = options.context ? "<Context>" : "";
|
|
334
340
|
const maybeContextParam = options.context ? "ctx: Context," : "";
|
|
341
|
+
const maybeMetadataParam = options.metadataType || options.addGrpcMetadata ? `metadata?: ${metadataType},` : "";
|
|
335
342
|
const maybeAbortSignalParam = options.useAbortSignal ? "abortSignal?: AbortSignal," : "";
|
|
336
343
|
const methods = [[(0, ts_poet_1.code) `request`, (0, ts_poet_1.code) `Uint8Array`, (0, ts_poet_1.code) `Promise<Uint8Array>`]];
|
|
337
344
|
const additionalMethods = [];
|
|
@@ -363,6 +370,7 @@ function generateRpcType(ctx, hasStreamingMethods) {
|
|
|
363
370
|
service: string,
|
|
364
371
|
method: string,
|
|
365
372
|
data: ${method[1]},
|
|
373
|
+
${maybeMetadataParam}
|
|
366
374
|
${maybeAbortSignalParam}
|
|
367
375
|
): ${method[2]};`);
|
|
368
376
|
});
|