ts-proto 1.166.3 → 1.167.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/README.markdown +3 -1
- package/build/enums.js +2 -2
- package/build/generate-generic-service-definition.js +2 -2
- package/build/generate-grpc-js.js +4 -4
- package/build/generate-nestjs.js +4 -4
- package/build/generate-nice-grpc.js +2 -2
- package/build/generate-services.js +2 -2
- package/build/generate-struct-wrappers.js +3 -3
- package/build/main.js +15 -15
- package/build/options.js +1 -0
- package/build/utils.js +4 -1
- package/package.json +1 -1
package/README.markdown
CHANGED
|
@@ -539,7 +539,9 @@ Generated code will be placed in the Gradle build directory.
|
|
|
539
539
|
|
|
540
540
|
This will disable `exportCommonSymbols` to avoid name collisions on the common symbols.
|
|
541
541
|
|
|
542
|
-
- With `--emitDefaultValues=json-methods`, the generated toJSON method will emit scalars like `0` and `""` as json fields.
|
|
542
|
+
- With `--ts_proto_opt=emitDefaultValues=json-methods`, the generated toJSON method will emit scalars like `0` and `""` as json fields.
|
|
543
|
+
|
|
544
|
+
- With `--ts_proto_opt=comments=false`, comments won't be copied from the proto files to the generated code.
|
|
543
545
|
|
|
544
546
|
### NestJS Support
|
|
545
547
|
|
package/build/enums.js
CHANGED
|
@@ -11,7 +11,7 @@ function generateEnum(ctx, fullName, enumDesc, sourceInfo) {
|
|
|
11
11
|
const { options } = ctx;
|
|
12
12
|
const chunks = [];
|
|
13
13
|
let unrecognizedEnum = { present: false };
|
|
14
|
-
(0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = enumDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
14
|
+
(0, utils_1.maybeAddComment)(options, sourceInfo, chunks, (_a = enumDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
15
15
|
if (options.enumsAsLiterals) {
|
|
16
16
|
chunks.push((0, ts_poet_1.code) `export const ${(0, ts_poet_1.def)(fullName)} = {`);
|
|
17
17
|
}
|
|
@@ -27,7 +27,7 @@ function generateEnum(ctx, fullName, enumDesc, sourceInfo) {
|
|
|
27
27
|
if (valueDesc.number === options.unrecognizedEnumValue) {
|
|
28
28
|
unrecognizedEnum = { present: true, name: memberName };
|
|
29
29
|
}
|
|
30
|
-
(0, utils_1.maybeAddComment)(info, chunks, (_a = valueDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated, `${memberName} - `);
|
|
30
|
+
(0, utils_1.maybeAddComment)(options, info, chunks, (_a = valueDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated, `${memberName} - `);
|
|
31
31
|
chunks.push((0, ts_poet_1.code) `${memberName} ${delimiter} ${options.stringEnums ? `"${valueName}"` : valueDesc.number.toString()},`);
|
|
32
32
|
});
|
|
33
33
|
if (options.unrecognizedEnum && !unrecognizedEnum.present) {
|
|
@@ -13,7 +13,7 @@ const utils_1 = require("./utils");
|
|
|
13
13
|
function generateGenericServiceDefinition(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
14
14
|
var _a, _b, _c;
|
|
15
15
|
const chunks = [];
|
|
16
|
-
(0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
16
|
+
(0, utils_1.maybeAddComment)(ctx.options, sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
17
17
|
// Service definition type
|
|
18
18
|
const name = (0, ts_poet_1.def)(`${serviceDesc.name}Definition`);
|
|
19
19
|
chunks.push((0, ts_poet_1.code) `
|
|
@@ -31,7 +31,7 @@ function generateGenericServiceDefinition(ctx, fileDesc, sourceInfo, serviceDesc
|
|
|
31
31
|
`);
|
|
32
32
|
for (const [index, methodDesc] of serviceDesc.method.entries()) {
|
|
33
33
|
const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
|
|
34
|
-
(0, utils_1.maybeAddComment)(info, chunks, (_c = methodDesc.options) === null || _c === void 0 ? void 0 : _c.deprecated);
|
|
34
|
+
(0, utils_1.maybeAddComment)(ctx.options, info, chunks, (_c = methodDesc.options) === null || _c === void 0 ? void 0 : _c.deprecated);
|
|
35
35
|
chunks.push((0, ts_poet_1.code) `
|
|
36
36
|
${(0, case_1.uncapitalize)(methodDesc.name)}: ${generateMethodDefinition(ctx, methodDesc)},
|
|
37
37
|
`);
|
|
@@ -41,7 +41,7 @@ exports.generateGrpcJsService = generateGrpcJsService;
|
|
|
41
41
|
function generateServiceDefinition(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
42
42
|
var _a, _b;
|
|
43
43
|
const chunks = [];
|
|
44
|
-
(0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
44
|
+
(0, utils_1.maybeAddComment)(ctx.options, sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
45
45
|
// Service definition type
|
|
46
46
|
const name = (0, ts_poet_1.def)(`${serviceDesc.name}Service`);
|
|
47
47
|
chunks.push((0, ts_poet_1.code) `
|
|
@@ -56,7 +56,7 @@ function generateServiceDefinition(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
56
56
|
const inputType = (0, types_1.messageToTypeName)(ctx, methodDesc.inputType);
|
|
57
57
|
const outputType = (0, types_1.messageToTypeName)(ctx, methodDesc.outputType);
|
|
58
58
|
const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
|
|
59
|
-
(0, utils_1.maybeAddComment)(info, chunks, (_b = methodDesc.options) === null || _b === void 0 ? void 0 : _b.deprecated);
|
|
59
|
+
(0, utils_1.maybeAddComment)(ctx.options, info, chunks, (_b = methodDesc.options) === null || _b === void 0 ? void 0 : _b.deprecated);
|
|
60
60
|
const inputEncoder = (0, encode_1.generateEncoder)(ctx, methodDesc.inputType);
|
|
61
61
|
const outputEncoder = (0, encode_1.generateEncoder)(ctx, methodDesc.outputType);
|
|
62
62
|
const inputDecoder = (0, encode_1.generateDecoder)(ctx, methodDesc.inputType);
|
|
@@ -87,7 +87,7 @@ function generateServerStub(ctx, sourceInfo, serviceDesc) {
|
|
|
87
87
|
const inputType = (0, types_1.messageToTypeName)(ctx, methodDesc.inputType);
|
|
88
88
|
const outputType = (0, types_1.messageToTypeName)(ctx, methodDesc.outputType);
|
|
89
89
|
const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
|
|
90
|
-
(0, utils_1.maybeAddComment)(info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
90
|
+
(0, utils_1.maybeAddComment)(ctx.options, info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
91
91
|
const callType = methodDesc.clientStreaming
|
|
92
92
|
? methodDesc.serverStreaming
|
|
93
93
|
? handleBidiStreamingCall
|
|
@@ -111,7 +111,7 @@ function generateClientStub(ctx, sourceInfo, serviceDesc) {
|
|
|
111
111
|
const inputType = (0, types_1.messageToTypeName)(ctx, methodDesc.inputType);
|
|
112
112
|
const outputType = (0, types_1.messageToTypeName)(ctx, methodDesc.outputType);
|
|
113
113
|
const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
|
|
114
|
-
(0, utils_1.maybeAddComment)(info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
114
|
+
(0, utils_1.maybeAddComment)(ctx.options, info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
115
115
|
const responseCallback = (0, ts_poet_1.code) `(error: ${ServiceError} | null, response: ${outputType}) => void`;
|
|
116
116
|
if (methodDesc.clientStreaming) {
|
|
117
117
|
if (methodDesc.serverStreaming) {
|
package/build/generate-nestjs.js
CHANGED
|
@@ -11,7 +11,7 @@ function generateNestjsServiceController(ctx, fileDesc, sourceInfo, serviceDesc)
|
|
|
11
11
|
const { options } = ctx;
|
|
12
12
|
const chunks = [];
|
|
13
13
|
const Metadata = (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
|
|
14
|
-
(0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
14
|
+
(0, utils_1.maybeAddComment)(options, sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
15
15
|
const t = options.context ? `<${main_1.contextTypeVar}>` : "";
|
|
16
16
|
chunks.push((0, ts_poet_1.code) `
|
|
17
17
|
export interface ${serviceDesc.name}Controller${t} {
|
|
@@ -20,7 +20,7 @@ function generateNestjsServiceController(ctx, fileDesc, sourceInfo, serviceDesc)
|
|
|
20
20
|
var _a;
|
|
21
21
|
(0, utils_1.assertInstanceOf)(methodDesc, utils_1.FormattedMethodDescriptor);
|
|
22
22
|
const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
|
|
23
|
-
(0, utils_1.maybeAddComment)(info, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
23
|
+
(0, utils_1.maybeAddComment)(options, info, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
24
24
|
const params = [];
|
|
25
25
|
if (options.context) {
|
|
26
26
|
params.push((0, ts_poet_1.code) `ctx: Context`);
|
|
@@ -74,7 +74,7 @@ function generateNestjsServiceClient(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
74
74
|
const { options } = ctx;
|
|
75
75
|
const chunks = [];
|
|
76
76
|
const Metadata = (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
|
|
77
|
-
(0, utils_1.maybeAddComment)(sourceInfo, chunks);
|
|
77
|
+
(0, utils_1.maybeAddComment)(options, sourceInfo, chunks);
|
|
78
78
|
const t = options.context ? `<${main_1.contextTypeVar}>` : ``;
|
|
79
79
|
chunks.push((0, ts_poet_1.code) `
|
|
80
80
|
export interface ${serviceDesc.name}Client${t} {
|
|
@@ -98,7 +98,7 @@ function generateNestjsServiceClient(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
98
98
|
// Return observable since nestjs client always returns an Observable
|
|
99
99
|
const returns = (0, types_1.responseObservable)(ctx, methodDesc);
|
|
100
100
|
const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
|
|
101
|
-
(0, utils_1.maybeAddComment)(info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
101
|
+
(0, utils_1.maybeAddComment)(options, info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
102
102
|
chunks.push((0, ts_poet_1.code) `
|
|
103
103
|
${methodDesc.formattedName}(
|
|
104
104
|
${(0, ts_poet_1.joinCode)(params, { on: "," })}
|
|
@@ -32,7 +32,7 @@ function generateServerStub(ctx, sourceInfo, serviceDesc) {
|
|
|
32
32
|
}
|
|
33
33
|
const ServerStreamingMethodResult = ctx.utils.NiceGrpcServerStreamingMethodResult;
|
|
34
34
|
const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
|
|
35
|
-
(0, utils_1.maybeAddComment)(info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
35
|
+
(0, utils_1.maybeAddComment)(ctx.options, info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
36
36
|
if (methodDesc.clientStreaming) {
|
|
37
37
|
if (methodDesc.serverStreaming) {
|
|
38
38
|
// bidi streaming
|
|
@@ -89,7 +89,7 @@ function generateClientStub(ctx, sourceInfo, serviceDesc) {
|
|
|
89
89
|
}
|
|
90
90
|
const outputType = (0, types_1.messageToTypeName)(ctx, methodDesc.outputType, { keepValueType: true });
|
|
91
91
|
const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
|
|
92
|
-
(0, utils_1.maybeAddComment)(info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
92
|
+
(0, utils_1.maybeAddComment)(ctx.options, info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
93
93
|
if (methodDesc.clientStreaming) {
|
|
94
94
|
if (methodDesc.serverStreaming) {
|
|
95
95
|
// bidi streaming
|
|
@@ -20,14 +20,14 @@ function generateService(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
20
20
|
var _a;
|
|
21
21
|
const { options } = ctx;
|
|
22
22
|
const chunks = [];
|
|
23
|
-
(0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
23
|
+
(0, utils_1.maybeAddComment)(options, sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
24
24
|
const maybeTypeVar = options.context ? `<${main_1.contextTypeVar}>` : "";
|
|
25
25
|
chunks.push((0, ts_poet_1.code) `export interface ${(0, ts_poet_1.def)(serviceDesc.name)}${maybeTypeVar} {`);
|
|
26
26
|
serviceDesc.method.forEach((methodDesc, index) => {
|
|
27
27
|
var _a;
|
|
28
28
|
(0, utils_1.assertInstanceOf)(methodDesc, utils_1.FormattedMethodDescriptor);
|
|
29
29
|
const info = sourceInfo.lookup(sourceInfo_1.Fields.service.method, index);
|
|
30
|
-
(0, utils_1.maybeAddComment)(info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
30
|
+
(0, utils_1.maybeAddComment)(options, info, chunks, (_a = methodDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
31
31
|
const params = [];
|
|
32
32
|
if (options.context) {
|
|
33
33
|
params.push((0, ts_poet_1.code) `ctx: Context`);
|
|
@@ -51,7 +51,7 @@ function generateWrapDeep(ctx, fullProtoTypeName, fieldNames) {
|
|
|
51
51
|
} else if (typeof value === 'object') {
|
|
52
52
|
result.${fieldNames.structValue} = Struct.wrap(value);
|
|
53
53
|
} else if (typeof value !== 'undefined') {
|
|
54
|
-
throw new Error('Unsupported any value type: ' + typeof value);
|
|
54
|
+
throw new ${ctx.utils.globalThis}.Error('Unsupported any value type: ' + typeof value);
|
|
55
55
|
}
|
|
56
56
|
return result;
|
|
57
57
|
}`);
|
|
@@ -178,7 +178,7 @@ function generateWrapShallow(ctx, fullProtoTypeName, fieldNames) {
|
|
|
178
178
|
} else if (typeof value === 'object') {
|
|
179
179
|
result.kind = {$case: '${fieldNames.structValue}', ${fieldNames.structValue}: value};
|
|
180
180
|
} else if (typeof value !== 'undefined') {
|
|
181
|
-
throw new Error('Unsupported any value type: ' + typeof value);
|
|
181
|
+
throw new ${ctx.utils.globalThis}.Error('Unsupported any value type: ' + typeof value);
|
|
182
182
|
}
|
|
183
183
|
return result;
|
|
184
184
|
}`);
|
|
@@ -199,7 +199,7 @@ function generateWrapShallow(ctx, fullProtoTypeName, fieldNames) {
|
|
|
199
199
|
} else if (typeof value === 'object') {
|
|
200
200
|
result.${fieldNames.structValue} = value;
|
|
201
201
|
} else if (typeof value !== 'undefined') {
|
|
202
|
-
throw new Error('Unsupported any value type: ' + typeof value);
|
|
202
|
+
throw new ${ctx.utils.globalThis}.Error('Unsupported any value type: ' + typeof value);
|
|
203
203
|
}
|
|
204
204
|
return result;
|
|
205
205
|
}`);
|
package/build/main.js
CHANGED
|
@@ -52,7 +52,7 @@ function generateFile(ctx, fileDesc) {
|
|
|
52
52
|
// Syntax, unlike most fields, is not repeated and thus does not use an index
|
|
53
53
|
const sourceInfo = sourceInfo_1.default.fromDescriptor(fileDesc);
|
|
54
54
|
const headerComment = sourceInfo.lookup(sourceInfo_1.Fields.file.syntax, undefined);
|
|
55
|
-
(0, utils_1.maybeAddComment)(headerComment, chunks, (_a = fileDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
55
|
+
(0, utils_1.maybeAddComment)(options, headerComment, chunks, (_a = fileDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
56
56
|
// Apply formatting to methods here, so they propagate globally
|
|
57
57
|
for (let svc of fileDesc.service) {
|
|
58
58
|
for (let i = 0; i < svc.method.length; i++) {
|
|
@@ -283,7 +283,7 @@ function makeUtils(options) {
|
|
|
283
283
|
...makeNiceGrpcServerStreamingMethodResult(),
|
|
284
284
|
...makeGrpcWebErrorClass(bytes),
|
|
285
285
|
...makeExtensionClass(options),
|
|
286
|
-
...makeAssertionUtils(),
|
|
286
|
+
...makeAssertionUtils(bytes),
|
|
287
287
|
};
|
|
288
288
|
}
|
|
289
289
|
exports.makeUtils = makeUtils;
|
|
@@ -611,10 +611,10 @@ function makeExtensionClass(options) {
|
|
|
611
611
|
`);
|
|
612
612
|
return { Extension };
|
|
613
613
|
}
|
|
614
|
-
function makeAssertionUtils() {
|
|
614
|
+
function makeAssertionUtils(bytes) {
|
|
615
615
|
const fail = (0, ts_poet_1.conditionalOutput)("fail", (0, ts_poet_1.code) `
|
|
616
616
|
function fail(message?: string): never {
|
|
617
|
-
throw new Error(message ?? "Failed");
|
|
617
|
+
throw new ${bytes.globalThis}.Error(message ?? "Failed");
|
|
618
618
|
}
|
|
619
619
|
`);
|
|
620
620
|
return { fail };
|
|
@@ -624,7 +624,7 @@ function generateInterfaceDeclaration(ctx, fullName, messageDesc, sourceInfo, fu
|
|
|
624
624
|
var _a;
|
|
625
625
|
const { options } = ctx;
|
|
626
626
|
const chunks = [];
|
|
627
|
-
(0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = messageDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
627
|
+
(0, utils_1.maybeAddComment)(options, sourceInfo, chunks, (_a = messageDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
628
628
|
// interface name should be defined to avoid import collisions
|
|
629
629
|
chunks.push((0, ts_poet_1.code) `export interface ${(0, ts_poet_1.def)(fullName)} {`);
|
|
630
630
|
if ((0, options_1.addTypeToMessages)(options)) {
|
|
@@ -643,7 +643,7 @@ function generateInterfaceDeclaration(ctx, fullName, messageDesc, sourceInfo, fu
|
|
|
643
643
|
return;
|
|
644
644
|
}
|
|
645
645
|
const info = sourceInfo.lookup(sourceInfo_1.Fields.message.field, index);
|
|
646
|
-
(0, utils_1.maybeAddComment)(info, chunks, (_a = fieldDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
646
|
+
(0, utils_1.maybeAddComment)(options, info, chunks, (_a = fieldDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
647
647
|
const fieldKey = (0, utils_1.safeAccessor)((0, utils_1.getFieldName)(fieldDesc, options));
|
|
648
648
|
const isOptional = (0, types_1.isOptionalProperty)(fieldDesc, messageDesc.options, options);
|
|
649
649
|
const type = (0, types_1.toTypeName)(ctx, messageDesc, fieldDesc, isOptional);
|
|
@@ -672,14 +672,14 @@ function generateOneofProperty(ctx, messageDesc, oneofIndex, sourceInfo) {
|
|
|
672
672
|
// that ability. For now just concatenate all comments into one big one.
|
|
673
673
|
let comments: Array<string> = [];
|
|
674
674
|
const info = sourceInfo.lookup(Fields.message.oneof_decl, oneofIndex);
|
|
675
|
-
maybeAddComment(info, (text) => comments.push(text));
|
|
675
|
+
maybeAddComment(options, info, (text) => comments.push(text));
|
|
676
676
|
messageDesc.field.forEach((field, index) => {
|
|
677
677
|
if (!isWithinOneOf(field) || field.oneofIndex !== oneofIndex) {
|
|
678
678
|
return;
|
|
679
679
|
}
|
|
680
680
|
const info = sourceInfo.lookup(Fields.message.field, index);
|
|
681
681
|
const name = maybeSnakeToCamel(field.name, options);
|
|
682
|
-
maybeAddComment(info, (text) => comments.push(name + '\n' + text));
|
|
682
|
+
maybeAddComment(options, info, (text) => comments.push(name + '\n' + text));
|
|
683
683
|
});
|
|
684
684
|
if (comments.length) {
|
|
685
685
|
prop = prop.addJavadoc(comments.join('\n'));
|
|
@@ -987,13 +987,13 @@ function getEncodeWriteSnippet(ctx, field) {
|
|
|
987
987
|
case "sint64":
|
|
988
988
|
case "sfixed64":
|
|
989
989
|
return (place) => (0, ts_poet_1.code) `if (BigInt.asIntN(64, ${place}) !== ${place}) {
|
|
990
|
-
throw new Error('value provided for field ${place} of type ${fieldType} too large');
|
|
990
|
+
throw new ${utils.globalThis}.Error('value provided for field ${place} of type ${fieldType} too large');
|
|
991
991
|
}
|
|
992
992
|
writer.uint32(${tag}).${(0, types_1.toReaderCall)(field)}(${place}.toString())`;
|
|
993
993
|
case "uint64":
|
|
994
994
|
case "fixed64":
|
|
995
995
|
return (place) => (0, ts_poet_1.code) `if (BigInt.asUintN(64, ${place}) !== ${place}) {
|
|
996
|
-
throw new Error('value provided for field ${place} of type ${fieldType} too large');
|
|
996
|
+
throw new ${utils.globalThis}.Error('value provided for field ${place} of type ${fieldType} too large');
|
|
997
997
|
}
|
|
998
998
|
writer.uint32(${tag}).${(0, types_1.toReaderCall)(field)}(${place}.toString())`;
|
|
999
999
|
default:
|
|
@@ -1156,7 +1156,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1156
1156
|
writer.uint32(${tag}).fork();
|
|
1157
1157
|
for (const v of ${messageProperty}) {
|
|
1158
1158
|
if (BigInt.asIntN(64, v) !== v) {
|
|
1159
|
-
throw new Error('a value provided in array field ${fieldName} of type ${fieldType} is too large');
|
|
1159
|
+
throw new ${utils.globalThis}.Error('a value provided in array field ${fieldName} of type ${fieldType} is too large');
|
|
1160
1160
|
}
|
|
1161
1161
|
writer.${(0, types_1.toReaderCall)(field)}(${rhs("v")});
|
|
1162
1162
|
}
|
|
@@ -1169,8 +1169,8 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1169
1169
|
writer.uint32(${tag}).fork();
|
|
1170
1170
|
for (const v of ${messageProperty}) {
|
|
1171
1171
|
if (BigInt.asUintN(64, v) !== v) {
|
|
1172
|
-
throw new Error('a value provided in array field ${fieldName} of type ${fieldType} is too large');
|
|
1173
|
-
}
|
|
1172
|
+
throw new ${utils.globalThis}.Error('a value provided in array field ${fieldName} of type ${fieldType} is too large');
|
|
1173
|
+
}
|
|
1174
1174
|
writer.${(0, types_1.toReaderCall)(field)}(${rhs("v")});
|
|
1175
1175
|
}
|
|
1176
1176
|
writer.ldelim();
|
|
@@ -1921,14 +1921,14 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
1921
1921
|
chunks.push((0, ts_poet_1.code) `
|
|
1922
1922
|
create<I extends ${utils.Exact}<${utils.DeepPartial}<${fullName}>, I>>(base?: I): ${fullName} {
|
|
1923
1923
|
return ${fullName}.fromPartial(base ?? ({} as any));
|
|
1924
|
-
},
|
|
1924
|
+
},
|
|
1925
1925
|
`);
|
|
1926
1926
|
}
|
|
1927
1927
|
else {
|
|
1928
1928
|
chunks.push((0, ts_poet_1.code) `
|
|
1929
1929
|
create(base?: ${utils.DeepPartial}<${fullName}>): ${fullName} {
|
|
1930
1930
|
return ${fullName}.fromPartial(base ?? {});
|
|
1931
|
-
},
|
|
1931
|
+
},
|
|
1932
1932
|
`);
|
|
1933
1933
|
}
|
|
1934
1934
|
// create the fromPartial function declaration
|
package/build/options.js
CHANGED
package/build/utils.js
CHANGED
|
@@ -79,7 +79,10 @@ exports.upperFirst = upperFirst;
|
|
|
79
79
|
// Since we don't know what form the comment originally took, it may contain closing block comments.
|
|
80
80
|
const CloseComment = /\*\//g;
|
|
81
81
|
/** Removes potentially harmful characters from comments and pushes it into chunks. */
|
|
82
|
-
function maybeAddComment(desc, chunks, deprecated, prefix = "") {
|
|
82
|
+
function maybeAddComment(options, desc, chunks, deprecated, prefix = "") {
|
|
83
|
+
if (!options.comments) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
83
86
|
let lines = [];
|
|
84
87
|
if (desc.leadingComments || desc.trailingComments) {
|
|
85
88
|
let content = (desc.leadingComments || desc.trailingComments || "").replace(CloseComment, "* /").trim();
|