ts-proto 1.100.0 → 1.102.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/CHANGELOG.md +28 -0
- package/README.markdown +2 -0
- package/build/generate-grpc-js.js +5 -2
- package/build/main.js +35 -6
- package/build/options.js +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## [1.102.1](https://github.com/stephenh/ts-proto/compare/v1.102.0...v1.102.1) (2022-01-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Pin ts-proto-descriptors to 1.3.1. ([#481](https://github.com/stephenh/ts-proto/issues/481)) ([6f362bf](https://github.com/stephenh/ts-proto/commit/6f362bfd3517a6bcb440d65e7ac63cd2b0bcc293)), closes [#480](https://github.com/stephenh/ts-proto/issues/480)
|
|
7
|
+
|
|
8
|
+
# [1.102.0](https://github.com/stephenh/ts-proto/compare/v1.101.0...v1.102.0) (2022-01-18)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* enable unknown fields for descriptor protos ([#479](https://github.com/stephenh/ts-proto/issues/479)) ([824c996](https://github.com/stephenh/ts-proto/commit/824c9962cd98dc0f9093e8909e3028d900094c54))
|
|
14
|
+
|
|
15
|
+
# [1.101.0](https://github.com/stephenh/ts-proto/compare/v1.100.1...v1.101.0) (2022-01-15)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* add support for unknown fields ([#473](https://github.com/stephenh/ts-proto/issues/473)) ([3bb9472](https://github.com/stephenh/ts-proto/commit/3bb9472943cf2e698b013487c7370a76576b68b6))
|
|
21
|
+
|
|
22
|
+
## [1.100.1](https://github.com/stephenh/ts-proto/compare/v1.100.0...v1.100.1) (2022-01-10)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* respect generateClientImpl=false in grpc-js ([#471](https://github.com/stephenh/ts-proto/issues/471)) ([#472](https://github.com/stephenh/ts-proto/issues/472)) ([2f389f2](https://github.com/stephenh/ts-proto/commit/2f389f243ef11d8d58c32ce37c371aba2cdf294e))
|
|
28
|
+
|
|
1
29
|
# [1.100.0](https://github.com/stephenh/ts-proto/compare/v1.99.0...v1.100.0) (2022-01-09)
|
|
2
30
|
|
|
3
31
|
|
package/README.markdown
CHANGED
|
@@ -374,6 +374,8 @@ Generated code will be placed in the Gradle build directory.
|
|
|
374
374
|
|
|
375
375
|
The default behavior is `useExactTypes=true`, which makes `fromPartial` use Exact type for its argument to make TypeScript reject any unknown properties.
|
|
376
376
|
|
|
377
|
+
- With `--ts_proto_opt=unknownFields=true`, all unknown fields will be parsed and output as arrays of buffers.
|
|
378
|
+
|
|
377
379
|
### Only Types
|
|
378
380
|
|
|
379
381
|
If you're looking for `ts-proto` to generate only types for your Protobuf types then passing all three of `outputEncodeMethods`, `outputJsonMethods`, and `outputClientImpl` as `false` is probably what you want, i.e.:
|
|
@@ -27,11 +27,14 @@ const ServiceError = ts_poet_1.imp('ServiceError@@grpc/grpc-js');
|
|
|
27
27
|
* `@grpc/grpc-js` library.
|
|
28
28
|
*/
|
|
29
29
|
function generateGrpcJsService(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
30
|
+
const { options } = ctx;
|
|
30
31
|
const chunks = [];
|
|
31
32
|
chunks.push(generateServiceDefinition(ctx, fileDesc, sourceInfo, serviceDesc));
|
|
32
33
|
chunks.push(generateServerStub(ctx, sourceInfo, serviceDesc));
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
if (options.outputClientImpl) {
|
|
35
|
+
chunks.push(generateClientStub(ctx, sourceInfo, serviceDesc));
|
|
36
|
+
chunks.push(generateClientConstructor(fileDesc, serviceDesc));
|
|
37
|
+
}
|
|
35
38
|
return ts_poet_1.joinCode(chunks, { on: '\n\n' });
|
|
36
39
|
}
|
|
37
40
|
exports.generateGrpcJsService = generateGrpcJsService;
|
package/build/main.js
CHANGED
|
@@ -547,6 +547,9 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
547
547
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
548
548
|
const message = createBase${fullName}();
|
|
549
549
|
`);
|
|
550
|
+
if (options.unknownFields) {
|
|
551
|
+
chunks.push(ts_poet_1.code `(message as any)._unknownFields = {}`);
|
|
552
|
+
}
|
|
550
553
|
// start the tag loop
|
|
551
554
|
chunks.push(ts_poet_1.code `
|
|
552
555
|
while (reader.pos < end) {
|
|
@@ -651,11 +654,22 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
651
654
|
}
|
|
652
655
|
chunks.push(ts_poet_1.code `break;`);
|
|
653
656
|
});
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
657
|
+
if (options.unknownFields) {
|
|
658
|
+
chunks.push(ts_poet_1.code `
|
|
659
|
+
default:
|
|
660
|
+
const startPos = reader.pos;
|
|
661
|
+
reader.skipType(tag & 7);
|
|
662
|
+
(message as any)._unknownFields[tag] = [...((message as any)._unknownFields[tag] || []), reader.buf.slice(startPos, reader.pos)];
|
|
663
|
+
break;
|
|
664
|
+
`);
|
|
665
|
+
}
|
|
666
|
+
else {
|
|
667
|
+
chunks.push(ts_poet_1.code `
|
|
668
|
+
default:
|
|
669
|
+
reader.skipType(tag & 7);
|
|
670
|
+
break;
|
|
671
|
+
`);
|
|
672
|
+
}
|
|
659
673
|
// and then wrap up the switch/while/return
|
|
660
674
|
chunks.push(ts_poet_1.code `}`);
|
|
661
675
|
chunks.push(ts_poet_1.code `}`);
|
|
@@ -672,7 +686,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
672
686
|
// create the basic function declaration
|
|
673
687
|
chunks.push(ts_poet_1.code `
|
|
674
688
|
encode(
|
|
675
|
-
${messageDesc.field.length > 0 ? 'message' : '_'}: ${fullName},
|
|
689
|
+
${messageDesc.field.length > 0 || options.unknownFields ? 'message' : '_'}: ${fullName},
|
|
676
690
|
writer: ${Writer} = ${Writer}.create(),
|
|
677
691
|
): ${Writer} {
|
|
678
692
|
`);
|
|
@@ -837,6 +851,21 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
837
851
|
chunks.push(ts_poet_1.code `${writeSnippet(`message.${fieldName}`)};`);
|
|
838
852
|
}
|
|
839
853
|
});
|
|
854
|
+
if (options.unknownFields) {
|
|
855
|
+
chunks.push(ts_poet_1.code `if ('_unknownFields' in message) {
|
|
856
|
+
for (const key of Object.keys(message['_unknownFields'])) {
|
|
857
|
+
const values = message['_unknownFields'][key] as Uint8Array[];
|
|
858
|
+
for (const value of values) {
|
|
859
|
+
writer.uint32(parseInt(key, 10));
|
|
860
|
+
(writer as any)['_push'](
|
|
861
|
+
(val: Uint8Array, buf: Buffer, pos: number) => buf.set(val, pos),
|
|
862
|
+
value.length,
|
|
863
|
+
value
|
|
864
|
+
);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}`);
|
|
868
|
+
}
|
|
840
869
|
chunks.push(ts_poet_1.code `return writer;`);
|
|
841
870
|
chunks.push(ts_poet_1.code `}`);
|
|
842
871
|
return ts_poet_1.joinCode(chunks, { on: '\n' });
|
package/build/options.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-proto",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.102.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/plugin.js",
|
|
6
6
|
"repository": "github:stephenh/ts-proto",
|
|
@@ -64,6 +64,6 @@
|
|
|
64
64
|
"object-hash": "^1.3.1",
|
|
65
65
|
"protobufjs": "^6.8.8",
|
|
66
66
|
"ts-poet": "^4.5.0",
|
|
67
|
-
"ts-proto-descriptors": "
|
|
67
|
+
"ts-proto-descriptors": "1.3.1"
|
|
68
68
|
}
|
|
69
69
|
}
|