ts-proto 2.15.1 → 2.15.3
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/src/generate-services.js +2 -2
- package/build/src/main.d.ts +1 -1
- package/build/src/main.js +48 -21
- package/package.json +1 -1
|
@@ -339,10 +339,10 @@ function generateCachingRpcMethod(ctx, fileDesc, serviceDesc, methodDesc) {
|
|
|
339
339
|
function generateRpcType(ctx, hasStreamingMethods) {
|
|
340
340
|
const { options } = ctx;
|
|
341
341
|
const metadata = options.metadataType ? (0, ts_poet_1.imp)(options.metadataType) : (0, ts_poet_1.imp)("t:Metadata@@grpc/grpc-js");
|
|
342
|
-
const metadataType = metadata.symbol;
|
|
343
342
|
const maybeContext = options.context ? "<Context>" : "";
|
|
344
343
|
const maybeContextParam = options.context ? "ctx: Context," : "";
|
|
345
|
-
|
|
344
|
+
// Use the import itself, so it is added even if no method of the service refers to it.
|
|
345
|
+
const maybeMetadataParam = options.metadataType || options.addGrpcMetadata ? (0, ts_poet_1.code) `metadata?: ${metadata},` : "";
|
|
346
346
|
const maybeAbortSignalParam = options.useAbortSignal ? "abortSignal?: AbortSignal," : "";
|
|
347
347
|
const methods = [[(0, ts_poet_1.code) `request`, (0, ts_poet_1.code) `Uint8Array`, (0, ts_poet_1.code) `Promise<Uint8Array>`]];
|
|
348
348
|
const additionalMethods = [];
|
package/build/src/main.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ declare function makeDeepPartial(options: Options, longs: ReturnType<typeof make
|
|
|
24
24
|
Exact: ConditionalOutput;
|
|
25
25
|
};
|
|
26
26
|
declare function makeMessageFns(options: Options, deepPartial: ReturnType<typeof makeDeepPartial>, extension: ReturnType<typeof makeExtensionClass>): {
|
|
27
|
-
MessageFns: ConditionalOutput;
|
|
27
|
+
MessageFns: ConditionalOutput | undefined;
|
|
28
28
|
ExtensionFns: ConditionalOutput;
|
|
29
29
|
ExtensionHolder: ConditionalOutput;
|
|
30
30
|
StructWrapperFns: ConditionalOutput;
|
package/build/src/main.js
CHANGED
|
@@ -88,14 +88,15 @@ function generateFile(ctx, fileDesc) {
|
|
|
88
88
|
(0, visit_1.visit)(fileDesc, sourceInfo, (fullName, message, _sInfo, fullProtoTypeName) => {
|
|
89
89
|
const fullTypeName = (0, utils_1.maybePrefixPackage)(fileDesc, fullProtoTypeName);
|
|
90
90
|
const outputWrapAndUnwrap = (0, generate_struct_wrappers_1.isWrapperType)(fullTypeName);
|
|
91
|
-
// Only decode, fromPartial, and wrap use the createBase method
|
|
91
|
+
// Only decode, fromPartial, and wrap use the createBase method. The deep `Value.wrap`
|
|
92
|
+
// generated for NestJS builds its result without it.
|
|
92
93
|
if ((options.outputEncodeMethods &&
|
|
93
94
|
options.outputEncodeMethods !== "encode-no-creation" &&
|
|
94
95
|
options.outputEncodeMethods !== "encode-only" &&
|
|
95
96
|
(options.outputDecodeIncludeTypes === "" ||
|
|
96
97
|
new RegExp(options.outputDecodeIncludeTypes).test(fullTypeName))) ||
|
|
97
98
|
options.outputPartialMethods ||
|
|
98
|
-
outputWrapAndUnwrap) {
|
|
99
|
+
(outputWrapAndUnwrap && !(options.nestJs && (0, types_1.isAnyValueTypeName)(fullTypeName)))) {
|
|
99
100
|
chunks.push(generateBaseInstanceFactory(ctx, fullName, message, fullTypeName));
|
|
100
101
|
}
|
|
101
102
|
const staticMembers = [];
|
|
@@ -172,7 +173,10 @@ function generateFile(ctx, fileDesc) {
|
|
|
172
173
|
const messageFnsTypeParameters = [fullName, hasTypeMember && `'${fullTypeName}'`]
|
|
173
174
|
.filter((p) => !!p)
|
|
174
175
|
.join(", ");
|
|
175
|
-
const interfaces = [
|
|
176
|
+
const interfaces = [];
|
|
177
|
+
if (utils.MessageFns) {
|
|
178
|
+
interfaces.push((0, ts_poet_1.code) `${utils.MessageFns}<${messageFnsTypeParameters}>`);
|
|
179
|
+
}
|
|
176
180
|
if (options.outputEncodeMethods &&
|
|
177
181
|
options.outputExtensions &&
|
|
178
182
|
options.unknownFields &&
|
|
@@ -601,11 +605,15 @@ function makeMessageFns(options, deepPartial, extension) {
|
|
|
601
605
|
}
|
|
602
606
|
}
|
|
603
607
|
const maybeExport = options.exportCommonSymbols ? "export" : "";
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
608
|
+
// Without any common members, e.g. with only the NestJS wrappers, the interface
|
|
609
|
+
// would be empty and its type parameter unused, so it is not generated at all.
|
|
610
|
+
const MessageFns = commonStaticMembers.length > 0
|
|
611
|
+
? (0, ts_poet_1.conditionalOutput)("MessageFns", (0, ts_poet_1.code) `
|
|
612
|
+
${maybeExport} interface MessageFns<T${hasTypeMember ? ", V extends string" : ""}> {
|
|
613
|
+
${(0, ts_poet_1.joinCode)(commonStaticMembers, { on: "\n" })}
|
|
614
|
+
}
|
|
615
|
+
`)
|
|
616
|
+
: undefined;
|
|
609
617
|
const ExtensionFns = (0, ts_poet_1.conditionalOutput)("ExtensionFns", (0, ts_poet_1.code) `
|
|
610
618
|
${maybeExport} interface ExtensionFns<T> {
|
|
611
619
|
${(0, ts_poet_1.joinCode)(extensionStaticMembers, { on: "\n" })}
|
|
@@ -1892,6 +1900,27 @@ function generateExtension(ctx, message, extension) {
|
|
|
1892
1900
|
extensionInfo: (0, ts_poet_1.joinCode)(chunks, { on: "\n" }),
|
|
1893
1901
|
};
|
|
1894
1902
|
}
|
|
1903
|
+
/** Converts the JSON of a wrapper type, such as `google.protobuf.Int64Value`, to the unwrapped value. */
|
|
1904
|
+
function valueTypeFromJson(ctx, field, from) {
|
|
1905
|
+
const { options } = ctx;
|
|
1906
|
+
const valueType = (0, types_1.valueTypeName)(ctx, field.typeName);
|
|
1907
|
+
if ((0, types_1.isLongValueType)(field) && options.forceLong === options_1.LongOption.LONG) {
|
|
1908
|
+
return (0, ts_poet_1.code) `${(0, case_1.capitalize)(valueType.toCodeString([]))}.fromValue(${from})`;
|
|
1909
|
+
}
|
|
1910
|
+
else if ((0, types_1.isLongValueType)(field) && options.forceLong === options_1.LongOption.BIGINT) {
|
|
1911
|
+
return (0, ts_poet_1.code) `BigInt(${from})`;
|
|
1912
|
+
}
|
|
1913
|
+
else if ((0, types_1.isBytesValueType)(field)) {
|
|
1914
|
+
return (0, ts_poet_1.code) `new ${(0, case_1.capitalize)(valueType.toCodeString([]))}(${from})`;
|
|
1915
|
+
}
|
|
1916
|
+
else {
|
|
1917
|
+
return (0, ts_poet_1.code) `${(0, case_1.capitalize)(valueType.toCodeString([]))}(${from})`;
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
/** Whether `field` is a 64-bit wrapper type unwrapped to a `Long` or `bigint`, which JSON writes as a string. */
|
|
1921
|
+
function isLongValueTypeAsObject(options, field) {
|
|
1922
|
+
return (0, types_1.isLongValueType)(field) && (options.forceLong === options_1.LongOption.LONG || options.forceLong === options_1.LongOption.BIGINT);
|
|
1923
|
+
}
|
|
1895
1924
|
/**
|
|
1896
1925
|
* Creates a function to decode a message from JSON.
|
|
1897
1926
|
*
|
|
@@ -2034,19 +2063,7 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
|
|
|
2034
2063
|
return (0, ts_poet_1.code) `[...${from}]`;
|
|
2035
2064
|
}
|
|
2036
2065
|
else if ((0, types_1.isValueType)(ctx, field)) {
|
|
2037
|
-
|
|
2038
|
-
if ((0, types_1.isLongValueType)(field) && options.forceLong === options_1.LongOption.LONG) {
|
|
2039
|
-
return (0, ts_poet_1.code) `${(0, case_1.capitalize)(valueType.toCodeString([]))}.fromValue(${from})`;
|
|
2040
|
-
}
|
|
2041
|
-
else if ((0, types_1.isLongValueType)(field) && options.forceLong === options_1.LongOption.BIGINT) {
|
|
2042
|
-
return (0, ts_poet_1.code) `BigInt(${from})`;
|
|
2043
|
-
}
|
|
2044
|
-
else if ((0, types_1.isBytesValueType)(field)) {
|
|
2045
|
-
return (0, ts_poet_1.code) `new ${(0, case_1.capitalize)(valueType.toCodeString([]))}(${from})`;
|
|
2046
|
-
}
|
|
2047
|
-
else {
|
|
2048
|
-
return (0, ts_poet_1.code) `${(0, case_1.capitalize)(valueType.toCodeString([]))}(${from})`;
|
|
2049
|
-
}
|
|
2066
|
+
return valueTypeFromJson(ctx, field, from);
|
|
2050
2067
|
}
|
|
2051
2068
|
else if ((0, types_1.isMessage)(field)) {
|
|
2052
2069
|
if ((0, types_1.isRepeated)(field) && (0, types_1.isMapType)(ctx, messageDesc, field)) {
|
|
@@ -2089,6 +2106,9 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
|
|
|
2089
2106
|
options.useDate === options_1.DateOption.TIMESTAMP)) {
|
|
2090
2107
|
return (0, ts_poet_1.code) `${utils.fromJsonTimestamp}(${from})`;
|
|
2091
2108
|
}
|
|
2109
|
+
else if ((0, types_1.isLongValueType)(valueField)) {
|
|
2110
|
+
return valueTypeFromJson(ctx, valueField, from);
|
|
2111
|
+
}
|
|
2092
2112
|
else if ((0, types_1.isValueType)(ctx, valueField)) {
|
|
2093
2113
|
return (0, ts_poet_1.code) `${from} as ${valueType}`;
|
|
2094
2114
|
}
|
|
@@ -2488,6 +2508,10 @@ function generateToJson(ctx, fullName, fullProtobufTypeName, messageDesc) {
|
|
|
2488
2508
|
else if ((0, types_1.isFloatingPoint)(valueType)) {
|
|
2489
2509
|
return (0, ts_poet_1.code) `${utils.floatToJson}(${from})`;
|
|
2490
2510
|
}
|
|
2511
|
+
else if (isLongValueTypeAsObject(options, valueType)) {
|
|
2512
|
+
// Map values of wrapper types are declared `| undefined`.
|
|
2513
|
+
return (0, ts_poet_1.code) `${from}?.toString()`;
|
|
2514
|
+
}
|
|
2491
2515
|
else if ((0, types_1.isScalar)(valueType) || (0, types_1.isValueType)(ctx, valueType)) {
|
|
2492
2516
|
return (0, ts_poet_1.code) `${from}`;
|
|
2493
2517
|
}
|
|
@@ -2513,6 +2537,9 @@ function generateToJson(ctx, fullName, fullProtobufTypeName, messageDesc) {
|
|
|
2513
2537
|
else if ((0, types_1.isBytes)(field)) {
|
|
2514
2538
|
return (0, ts_poet_1.code) `${utils.base64FromBytes}(${from})`;
|
|
2515
2539
|
}
|
|
2540
|
+
else if (isLongValueTypeAsObject(options, field)) {
|
|
2541
|
+
return (0, ts_poet_1.code) `${from}.toString()`;
|
|
2542
|
+
}
|
|
2516
2543
|
else if ((0, types_1.isLong)(field) && (0, types_1.isJsTypeFieldOption)(options, field)) {
|
|
2517
2544
|
const fieldType = (0, types_1.getFieldOptionsJsType)(field, ctx.options) ?? field.type;
|
|
2518
2545
|
if (!fieldType) {
|