ts-proto 1.115.3 → 1.115.4

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.115.4](https://github.com/stephenh/ts-proto/compare/v1.115.3...v1.115.4) (2022-06-05)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Struct wrap/unwrap snake case [#579](https://github.com/stephenh/ts-proto/issues/579) ([#588](https://github.com/stephenh/ts-proto/issues/588)) ([33f89bf](https://github.com/stephenh/ts-proto/commit/33f89bfcf0d5d9e64a6fd360eaefc140055e9291))
7
+
1
8
  ## [1.115.3](https://github.com/stephenh/ts-proto/compare/v1.115.2...v1.115.3) (2022-06-03)
2
9
 
3
10
 
package/build/main.js CHANGED
@@ -87,8 +87,16 @@ function generateFile(ctx, fileDesc) {
87
87
  if (options.outputPartialMethods) {
88
88
  staticMembers.push(generateFromPartial(ctx, fullName, message));
89
89
  }
90
- staticMembers.push(...generateWrap(ctx, fullTypeName));
91
- staticMembers.push(...generateUnwrap(ctx, fullTypeName));
90
+ const structFieldNames = {
91
+ nullValue: case_1.maybeSnakeToCamel('null_value', ctx.options),
92
+ numberValue: case_1.maybeSnakeToCamel('number_value', ctx.options),
93
+ stringValue: case_1.maybeSnakeToCamel('string_value', ctx.options),
94
+ boolValue: case_1.maybeSnakeToCamel('bool_value', ctx.options),
95
+ structValue: case_1.maybeSnakeToCamel('struct_value', ctx.options),
96
+ listValue: case_1.maybeSnakeToCamel('list_value', ctx.options),
97
+ };
98
+ staticMembers.push(...generateWrap(ctx, fullTypeName, structFieldNames));
99
+ staticMembers.push(...generateUnwrap(ctx, fullTypeName, structFieldNames));
92
100
  chunks.push(ts_poet_1.code `
93
101
  export const ${ts_poet_1.def(fullName)} = {
94
102
  ${ts_poet_1.joinCode(staticMembers, { on: ',\n\n' })}
@@ -1405,7 +1413,7 @@ function generateFromPartial(ctx, fullName, messageDesc) {
1405
1413
  chunks.push(ts_poet_1.code `}`);
1406
1414
  return ts_poet_1.joinCode(chunks, { on: '\n' });
1407
1415
  }
1408
- function generateWrap(ctx, fullProtoTypeName) {
1416
+ function generateWrap(ctx, fullProtoTypeName, fieldNames) {
1409
1417
  const chunks = [];
1410
1418
  if (types_1.isStructTypeName(fullProtoTypeName)) {
1411
1419
  chunks.push(ts_poet_1.code `wrap(object: {[key: string]: any} | undefined): Struct {
@@ -1424,17 +1432,17 @@ function generateWrap(ctx, fullProtoTypeName) {
1424
1432
  const result = createBaseValue();
1425
1433
 
1426
1434
  if (value === null) {
1427
- result.kind = {$case: 'nullValue', nullValue: NullValue.NULL_VALUE};
1435
+ result.kind = {$case: '${fieldNames.nullValue}', ${fieldNames.nullValue}: NullValue.NULL_VALUE};
1428
1436
  } else if (typeof value === 'boolean') {
1429
- result.kind = {$case: 'boolValue', boolValue: value};
1437
+ result.kind = {$case: '${fieldNames.boolValue}', ${fieldNames.boolValue}: value};
1430
1438
  } else if (typeof value === 'number') {
1431
- result.kind = {$case: 'numberValue', numberValue: value};
1439
+ result.kind = {$case: '${fieldNames.numberValue}', ${fieldNames.numberValue}: value};
1432
1440
  } else if (typeof value === 'string') {
1433
- result.kind = {$case: 'stringValue', stringValue: value};
1441
+ result.kind = {$case: '${fieldNames.stringValue}', ${fieldNames.stringValue}: value};
1434
1442
  } else if (Array.isArray(value)) {
1435
- result.kind = {$case: 'listValue', listValue: value};
1443
+ result.kind = {$case: '${fieldNames.listValue}', ${fieldNames.listValue}: value};
1436
1444
  } else if (typeof value === 'object') {
1437
- result.kind = {$case: 'structValue', structValue: value};
1445
+ result.kind = {$case: '${fieldNames.structValue}', ${fieldNames.structValue}: value};
1438
1446
  } else if (typeof value !== 'undefined') {
1439
1447
  throw new Error('Unsupported any value type: ' + typeof value);
1440
1448
  }
@@ -1447,17 +1455,17 @@ function generateWrap(ctx, fullProtoTypeName) {
1447
1455
  const result = createBaseValue();
1448
1456
 
1449
1457
  if (value === null) {
1450
- result.nullValue = NullValue.NULL_VALUE;
1458
+ result.${fieldNames.nullValue} = NullValue.NULL_VALUE;
1451
1459
  } else if (typeof value === 'boolean') {
1452
- result.boolValue = value;
1460
+ result.${fieldNames.boolValue} = value;
1453
1461
  } else if (typeof value === 'number') {
1454
- result.numberValue = value;
1462
+ result.${fieldNames.numberValue} = value;
1455
1463
  } else if (typeof value === 'string') {
1456
- result.stringValue = value;
1464
+ result.${fieldNames.stringValue} = value;
1457
1465
  } else if (Array.isArray(value)) {
1458
- result.listValue = value;
1466
+ result.${fieldNames.listValue} = value;
1459
1467
  } else if (typeof value === 'object') {
1460
- result.structValue = value;
1468
+ result.${fieldNames.structValue} = value;
1461
1469
  } else if (typeof value !== 'undefined') {
1462
1470
  throw new Error('Unsupported any value type: ' + typeof value);
1463
1471
  }
@@ -1482,7 +1490,7 @@ function generateWrap(ctx, fullProtoTypeName) {
1482
1490
  }
1483
1491
  return chunks;
1484
1492
  }
1485
- function generateUnwrap(ctx, fullProtoTypeName) {
1493
+ function generateUnwrap(ctx, fullProtoTypeName, fieldNames) {
1486
1494
  const chunks = [];
1487
1495
  if (types_1.isStructTypeName(fullProtoTypeName)) {
1488
1496
  chunks.push(ts_poet_1.code `unwrap(message: Struct): {[key: string]: any} {
@@ -1496,18 +1504,18 @@ function generateUnwrap(ctx, fullProtoTypeName) {
1496
1504
  if (types_1.isAnyValueTypeName(fullProtoTypeName)) {
1497
1505
  if (ctx.options.oneof === options_1.OneofOption.UNIONS) {
1498
1506
  chunks.push(ts_poet_1.code `unwrap(message: Value): string | number | boolean | Object | null | Array<any> | undefined {
1499
- if (message.kind?.$case === 'nullValue') {
1507
+ if (message.kind?.$case === '${fieldNames.nullValue}') {
1500
1508
  return null;
1501
- } else if (message.kind?.$case === 'numberValue') {
1502
- return message.kind?.numberValue;
1503
- } else if (message.kind?.$case === 'stringValue') {
1504
- return message.kind?.stringValue;
1505
- } else if (message.kind?.$case === 'boolValue') {
1506
- return message.kind?.boolValue;
1507
- } else if (message.kind?.$case === 'structValue') {
1508
- return message.kind?.structValue;
1509
- } else if (message.kind?.$case === 'listValue') {
1510
- return message.kind?.listValue;
1509
+ } else if (message.kind?.$case === '${fieldNames.numberValue}') {
1510
+ return message.kind?.${fieldNames.numberValue};
1511
+ } else if (message.kind?.$case === '${fieldNames.stringValue}') {
1512
+ return message.kind?.${fieldNames.stringValue};
1513
+ } else if (message.kind?.$case === '${fieldNames.boolValue}') {
1514
+ return message.kind?.${fieldNames.boolValue};
1515
+ } else if (message.kind?.$case === '${fieldNames.structValue}') {
1516
+ return message.kind?.${fieldNames.structValue};
1517
+ } else if (message.kind?.$case === '${fieldNames.listValue}') {
1518
+ return message.kind?.${fieldNames.listValue};
1511
1519
  } else {
1512
1520
  return undefined;
1513
1521
  }
@@ -1515,17 +1523,17 @@ function generateUnwrap(ctx, fullProtoTypeName) {
1515
1523
  }
1516
1524
  else {
1517
1525
  chunks.push(ts_poet_1.code `unwrap(message: Value): string | number | boolean | Object | null | Array<any> | undefined {
1518
- if (message?.stringValue !== undefined) {
1519
- return message.stringValue;
1520
- } else if (message?.numberValue !== undefined) {
1521
- return message.numberValue;
1522
- } else if (message?.boolValue !== undefined) {
1523
- return message.boolValue;
1524
- } else if (message?.structValue !== undefined) {
1525
- return message.structValue;
1526
- } else if (message?.listValue !== undefined) {
1527
- return message.listValue;
1528
- } else if (message?.nullValue !== undefined) {
1526
+ if (message?.${fieldNames.stringValue} !== undefined) {
1527
+ return message.${fieldNames.stringValue};
1528
+ } else if (message?.${fieldNames.numberValue} !== undefined) {
1529
+ return message.${fieldNames.numberValue};
1530
+ } else if (message?.${fieldNames.boolValue} !== undefined) {
1531
+ return message.${fieldNames.boolValue};
1532
+ } else if (message?.${fieldNames.structValue} !== undefined) {
1533
+ return message.${fieldNames.structValue};
1534
+ } else if (message?.${fieldNames.listValue} !== undefined) {
1535
+ return message.${fieldNames.listValue};
1536
+ } else if (message?.${fieldNames.nullValue} !== undefined) {
1529
1537
  return null;
1530
1538
  }
1531
1539
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.115.3",
3
+ "version": "1.115.4",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",