ts-proto 1.100.1 → 1.102.2

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 CHANGED
@@ -1,3 +1,31 @@
1
+ ## [1.102.2](https://github.com/stephenh/ts-proto/compare/v1.102.1...v1.102.2) (2022-01-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Have snakeToCamel leave existing mixed case. ([#482](https://github.com/stephenh/ts-proto/issues/482)) ([c0bf0fc](https://github.com/stephenh/ts-proto/commit/c0bf0fc13da70e2bde923cd1746119d2e7ac4b2f)), closes [#478](https://github.com/stephenh/ts-proto/issues/478)
7
+
8
+ ## [1.102.1](https://github.com/stephenh/ts-proto/compare/v1.102.0...v1.102.1) (2022-01-19)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * 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)
14
+
15
+ # [1.102.0](https://github.com/stephenh/ts-proto/compare/v1.101.0...v1.102.0) (2022-01-18)
16
+
17
+
18
+ ### Features
19
+
20
+ * enable unknown fields for descriptor protos ([#479](https://github.com/stephenh/ts-proto/issues/479)) ([824c996](https://github.com/stephenh/ts-proto/commit/824c9962cd98dc0f9093e8909e3028d900094c54))
21
+
22
+ # [1.101.0](https://github.com/stephenh/ts-proto/compare/v1.100.1...v1.101.0) (2022-01-15)
23
+
24
+
25
+ ### Features
26
+
27
+ * add support for unknown fields ([#473](https://github.com/stephenh/ts-proto/issues/473)) ([3bb9472](https://github.com/stephenh/ts-proto/commit/3bb9472943cf2e698b013487c7370a76576b68b6))
28
+
1
29
  ## [1.100.1](https://github.com/stephenh/ts-proto/compare/v1.100.0...v1.100.1) (2022-01-10)
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.:
package/build/case.js CHANGED
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.camelCase = exports.capitalize = exports.camelToSnake = exports.maybeSnakeToCamel = void 0;
4
4
  function maybeSnakeToCamel(s, options) {
5
5
  if (options.snakeToCamel.includes('keys') && s.includes('_')) {
6
+ const hasLowerCase = !!s.match(/[a-z]/);
6
7
  return s
7
8
  .split('_')
8
9
  .map((word, i) => {
9
10
  if (i === 0) {
10
11
  // if first symbol is "_" then skip it
11
- return word ? word[0] + word.substring(1).toLowerCase() : '';
12
+ return word ? word[0] + (hasLowerCase ? word.substring(1) : word.substring(1).toLowerCase()) : '';
12
13
  }
13
14
  else {
14
15
  return capitalize(word.toLowerCase());
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
- chunks.push(ts_poet_1.code `
655
- default:
656
- reader.skipType(tag & 7);
657
- break;
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
@@ -63,6 +63,7 @@ function defaultOptions() {
63
63
  onlyTypes: false,
64
64
  emitImportedFiles: true,
65
65
  useExactTypes: true,
66
+ unknownFields: false,
66
67
  };
67
68
  }
68
69
  exports.defaultOptions = defaultOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.100.1",
3
+ "version": "1.102.2",
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": "^1.2.1"
67
+ "ts-proto-descriptors": "1.3.1"
68
68
  }
69
69
  }