ts-proto 1.104.0 → 1.104.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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.104.1](https://github.com/stephenh/ts-proto/compare/v1.104.0...v1.104.1) (2022-02-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * make struct types play well with type registry ([#503](https://github.com/stephenh/ts-proto/issues/503)) ([d62f854](https://github.com/stephenh/ts-proto/commit/d62f85478011c7eb3dbca196f79b452895406ece))
7
+
1
8
  # [1.104.0](https://github.com/stephenh/ts-proto/compare/v1.103.0...v1.104.0) (2022-01-21)
2
9
 
3
10
 
package/README.markdown CHANGED
@@ -376,6 +376,10 @@ Generated code will be placed in the Gradle build directory.
376
376
 
377
377
  - With `--ts_proto_opt=unknownFields=true`, all unknown fields will be parsed and output as arrays of buffers.
378
378
 
379
+ - With `--ts_proto_opt=onlyTypes=true`, only types will be emitted, and imports for `long` and `protobufjs/minimal` will be excluded.
380
+
381
+ Note: _This is a combination_ of `outputJsonMethods=false,outputEncodeMethods=false,outputClientImpl=false,nestJs=false`
382
+
379
383
  - With `--ts_proto_opt=usePrototypeForDefaults=true`, the generated code will wrap new objects with `Object.create`.
380
384
 
381
385
  This allows code to do hazzer checks to detect when default values have been applied, which due to proto3's behavior of not putting default values on the wire, is typically only useful for interacting with proto2 messages.
@@ -385,10 +389,9 @@ Generated code will be placed in the Gradle build directory.
385
389
  Note that, as indicated, this means Object.keys will not include set-by-default fields, so if you have code that iterates over messages keys in a generic fashion, it will have to also iterate over keys inherited from the prototype.
386
390
 
387
391
  ### Only Types
388
-
389
392
  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.:
390
393
 
391
- `--ts_proto_opt=outputEncodeMethods=false,outputJsonMethods=false,outputClientImpl=false`.
394
+ `--ts_proto_opt=onlyTypes=true`.
392
395
 
393
396
  ### NestJS Support
394
397
 
package/build/main.js CHANGED
@@ -1349,7 +1349,7 @@ function generateWrap(ctx, fullProtoTypeName) {
1349
1349
  const chunks = [];
1350
1350
  if (types_1.isStructTypeName(fullProtoTypeName)) {
1351
1351
  chunks.push(ts_poet_1.code `wrap(object: {[key: string]: any} | undefined): Struct {
1352
- const struct = Struct.fromPartial({});
1352
+ const struct = createBaseStruct();
1353
1353
  if (object !== undefined) {
1354
1354
  Object.keys(object).forEach(key => {
1355
1355
  struct.fields[key] = object[key];
@@ -1361,50 +1361,58 @@ function generateWrap(ctx, fullProtoTypeName) {
1361
1361
  if (types_1.isAnyValueTypeName(fullProtoTypeName)) {
1362
1362
  if (ctx.options.oneof === options_1.OneofOption.UNIONS) {
1363
1363
  chunks.push(ts_poet_1.code `wrap(value: any): Value {
1364
- if (value === null) {
1365
- return {kind: {$case: 'nullValue', nullValue: NullValue.NULL_VALUE}};
1366
- } else if (typeof value === 'boolean') {
1367
- return {kind: {$case: 'boolValue', boolValue: value}};
1368
- } else if (typeof value === 'number') {
1369
- return {kind: {$case: 'numberValue', numberValue: value}};
1370
- } else if (typeof value === 'string') {
1371
- return {kind: {$case: 'stringValue', stringValue: value}};
1372
- } else if (Array.isArray(value)) {
1373
- return {kind: {$case: 'listValue', listValue: value}};
1374
- } else if (typeof value === 'object') {
1375
- return {kind: {$case: 'structValue', structValue: value}};
1376
- } else if (typeof value === 'undefined') {
1377
- return {} as Value;
1378
- } else {
1379
- throw new Error('Unsupported any value type: ' + typeof value);
1380
- }
1364
+ const result = createBaseValue();
1365
+
1366
+ if (value === null) {
1367
+ result.kind = {$case: 'nullValue', nullValue: NullValue.NULL_VALUE};
1368
+ } else if (typeof value === 'boolean') {
1369
+ result.kind = {$case: 'boolValue', boolValue: value};
1370
+ } else if (typeof value === 'number') {
1371
+ result.kind = {$case: 'numberValue', numberValue: value};
1372
+ } else if (typeof value === 'string') {
1373
+ result.kind = {$case: 'stringValue', stringValue: value};
1374
+ } else if (Array.isArray(value)) {
1375
+ result.kind = {$case: 'listValue', listValue: value};
1376
+ } else if (typeof value === 'object') {
1377
+ result.kind = {$case: 'structValue', structValue: value};
1378
+ } else if (typeof value !== 'undefined') {
1379
+ throw new Error('Unsupported any value type: ' + typeof value);
1380
+ }
1381
+
1382
+ return result;
1381
1383
  }`);
1382
1384
  }
1383
1385
  else {
1384
1386
  chunks.push(ts_poet_1.code `wrap(value: any): Value {
1385
- if (value === null) {
1386
- return {nullValue: NullValue.NULL_VALUE} as Value;
1387
- } else if (typeof value === 'boolean') {
1388
- return {boolValue: value} as Value;
1389
- } else if (typeof value === 'number') {
1390
- return {numberValue: value} as Value;
1391
- } else if (typeof value === 'string') {
1392
- return {stringValue: value} as Value;
1393
- } else if (Array.isArray(value)) {
1394
- return {listValue: value} as Value;
1395
- } else if (typeof value === 'object') {
1396
- return {structValue: value} as Value;
1397
- } else if (typeof value === 'undefined') {
1398
- return {} as Value;
1399
- } else {
1400
- throw new Error('Unsupported any value type: ' + typeof value);
1401
- }
1387
+ const result = createBaseValue();
1388
+
1389
+ if (value === null) {
1390
+ result.nullValue = NullValue.NULL_VALUE;
1391
+ } else if (typeof value === 'boolean') {
1392
+ result.boolValue = value;
1393
+ } else if (typeof value === 'number') {
1394
+ result.numberValue = value;
1395
+ } else if (typeof value === 'string') {
1396
+ result.stringValue = value;
1397
+ } else if (Array.isArray(value)) {
1398
+ result.listValue = value;
1399
+ } else if (typeof value === 'object') {
1400
+ result.structValue = value;
1401
+ } else if (typeof value !== 'undefined') {
1402
+ throw new Error('Unsupported any value type: ' + typeof value);
1403
+ }
1404
+
1405
+ return result;
1402
1406
  }`);
1403
1407
  }
1404
1408
  }
1405
1409
  if (types_1.isListValueTypeName(fullProtoTypeName)) {
1406
1410
  chunks.push(ts_poet_1.code `wrap(value: Array<any> | undefined): ListValue {
1407
- return {values: value ?? []};
1411
+ const result = createBaseListValue();
1412
+
1413
+ result.values = value ?? [];
1414
+
1415
+ return result;
1408
1416
  }`);
1409
1417
  }
1410
1418
  return chunks;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.104.0",
3
+ "version": "1.104.1",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",