ts-proto 1.169.0 → 1.170.0
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/build/main.js +1 -1
- package/build/types.js +7 -2
- 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
|
});
|
package/build/main.js
CHANGED
|
@@ -895,7 +895,7 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
895
895
|
const initializerNecessary = !options.initializeFieldsAsUndefined &&
|
|
896
896
|
(0, types_1.isOptionalProperty)(field, messageDesc.options, options, currentFile.isProto3Syntax);
|
|
897
897
|
if ((0, types_1.isRepeated)(field)) {
|
|
898
|
-
const maybeNonNullAssertion = ctx.options.useOptionals === "all" ? "!" : "";
|
|
898
|
+
const maybeNonNullAssertion = ctx.options.useOptionals === "all" || ctx.options.useOptionals === "deprecatedOnly" ? "!" : "";
|
|
899
899
|
const mapType = (0, types_1.detectMapType)(ctx, messageDesc, field);
|
|
900
900
|
if (mapType) {
|
|
901
901
|
// We need a unique const within the `cast` statement
|
package/build/types.js
CHANGED
|
@@ -330,15 +330,20 @@ function isScalar(field) {
|
|
|
330
330
|
}
|
|
331
331
|
exports.isScalar = isScalar;
|
|
332
332
|
// When useOptionals='messages', non-scalar fields are translated into optional
|
|
333
|
-
// properties.
|
|
333
|
+
// properties.
|
|
334
|
+
// When useOptionals='all', all fields are translated into
|
|
335
|
+
// optional properties, with the exception of map Entry key/values, which must
|
|
336
|
+
// always be present.
|
|
337
|
+
// When useOptionals='deprecatedOnly', all deprecated fields are translated into
|
|
334
338
|
// optional properties, with the exception of map Entry key/values, which must
|
|
335
339
|
// always be present.
|
|
336
340
|
// OneOf fields are always optional, whenever oneof=unions option not in use.
|
|
337
341
|
function isOptionalProperty(field, messageOptions, options, isProto3Syntax) {
|
|
338
342
|
const optionalMessages = options.useOptionals === true || options.useOptionals === "messages" || options.useOptionals === "all";
|
|
339
343
|
const optionalAll = options.useOptionals === "all";
|
|
344
|
+
const deprecatedOnly = options.useOptionals === "deprecatedOnly" && field.options && field.options.deprecated;
|
|
340
345
|
return ((optionalMessages && isMessage(field) && !isRepeated(field)) ||
|
|
341
|
-
(optionalAll && !(messageOptions === null || messageOptions === void 0 ? void 0 : messageOptions.mapEntry)) ||
|
|
346
|
+
((optionalAll || deprecatedOnly) && !(messageOptions === null || messageOptions === void 0 ? void 0 : messageOptions.mapEntry)) ||
|
|
342
347
|
// file is proto2, we have enabled proto2 optionals, and the field itself is optional
|
|
343
348
|
(!isProto3Syntax &&
|
|
344
349
|
field.label === ts_proto_descriptors_1.FieldDescriptorProto_Label.LABEL_OPTIONAL &&
|