ts-proto 1.115.2 → 1.115.5
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 +21 -0
- package/build/main.js +55 -51
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.115.5](https://github.com/stephenh/ts-proto/compare/v1.115.4...v1.115.5) (2022-06-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* remove Long import statement when Long was unused ([#599](https://github.com/stephenh/ts-proto/issues/599)) ([58dc10c](https://github.com/stephenh/ts-proto/commit/58dc10c61ec5a76d4b54ba9eddf34021979dd4aa))
|
|
7
|
+
|
|
8
|
+
## [1.115.4](https://github.com/stephenh/ts-proto/compare/v1.115.3...v1.115.4) (2022-06-05)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* 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))
|
|
14
|
+
|
|
15
|
+
## [1.115.3](https://github.com/stephenh/ts-proto/compare/v1.115.2...v1.115.3) (2022-06-03)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* Fix ts-poet typo in package.json. ([#589](https://github.com/stephenh/ts-proto/issues/589)) ([5211347](https://github.com/stephenh/ts-proto/commit/5211347cb21ac7d117349a32a87c0d017999c44a))
|
|
21
|
+
|
|
1
22
|
## [1.115.2](https://github.com/stephenh/ts-proto/compare/v1.115.1...v1.115.2) (2022-06-03)
|
|
2
23
|
|
|
3
24
|
|
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
|
-
|
|
91
|
-
|
|
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' })}
|
|
@@ -180,9 +188,6 @@ function generateFile(ctx, fileDesc) {
|
|
|
180
188
|
if (v instanceof ConditionalOutput_1.ConditionalOutput) {
|
|
181
189
|
return ts_poet_1.code `${v.ifUsed}`;
|
|
182
190
|
}
|
|
183
|
-
else if (v instanceof ts_poet_1.Code) {
|
|
184
|
-
return v;
|
|
185
|
-
}
|
|
186
191
|
else {
|
|
187
192
|
return ts_poet_1.code ``;
|
|
188
193
|
}
|
|
@@ -229,23 +234,22 @@ function makeLongUtils(options, bytes) {
|
|
|
229
234
|
//
|
|
230
235
|
// I.e there is not an import for long that "just works" in both esModuleInterop and
|
|
231
236
|
// not esModuleInterop.
|
|
232
|
-
const
|
|
237
|
+
const LongImp = options.esModuleInterop ? ts_poet_1.imp('Long=long') : ts_poet_1.imp('Long*long');
|
|
233
238
|
const disclaimer = options.esModuleInterop
|
|
234
239
|
? ''
|
|
235
240
|
: `
|
|
236
241
|
// If you get a compile-error about 'Constructor<Long> and ... have no overlap',
|
|
237
242
|
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.`;
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
: ts_poet_1.code `
|
|
243
|
+
// Instead of exposing `LongImp` directly, let callers think that they are getting the
|
|
244
|
+
// `imp(Long)` but really it is that + our long initialization snippet. This means the
|
|
245
|
+
// initialization code will only be emitted in files that actually use the Long import.
|
|
246
|
+
const Long = ts_poet_1.conditionalOutput('Long', ts_poet_1.code `
|
|
243
247
|
${disclaimer}
|
|
244
|
-
if (${util}.Long !== ${
|
|
245
|
-
${util}.Long = ${
|
|
248
|
+
if (${util}.Long !== ${LongImp}) {
|
|
249
|
+
${util}.Long = ${LongImp} as any;
|
|
246
250
|
${configure}();
|
|
247
251
|
}
|
|
248
|
-
|
|
252
|
+
`);
|
|
249
253
|
// TODO This is unused?
|
|
250
254
|
const numberToLong = ts_poet_1.conditionalOutput('numberToLong', ts_poet_1.code `
|
|
251
255
|
function numberToLong(number: number) {
|
|
@@ -265,7 +269,7 @@ function makeLongUtils(options, bytes) {
|
|
|
265
269
|
return long.toNumber();
|
|
266
270
|
}
|
|
267
271
|
`);
|
|
268
|
-
return { numberToLong, longToNumber, longToString,
|
|
272
|
+
return { numberToLong, longToNumber, longToString, Long };
|
|
269
273
|
}
|
|
270
274
|
function makeByteUtils() {
|
|
271
275
|
const globalThis = ts_poet_1.conditionalOutput('globalThis', ts_poet_1.code `
|
|
@@ -1405,7 +1409,7 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
1405
1409
|
chunks.push(ts_poet_1.code `}`);
|
|
1406
1410
|
return ts_poet_1.joinCode(chunks, { on: '\n' });
|
|
1407
1411
|
}
|
|
1408
|
-
function generateWrap(ctx, fullProtoTypeName) {
|
|
1412
|
+
function generateWrap(ctx, fullProtoTypeName, fieldNames) {
|
|
1409
1413
|
const chunks = [];
|
|
1410
1414
|
if (types_1.isStructTypeName(fullProtoTypeName)) {
|
|
1411
1415
|
chunks.push(ts_poet_1.code `wrap(object: {[key: string]: any} | undefined): Struct {
|
|
@@ -1424,17 +1428,17 @@ function generateWrap(ctx, fullProtoTypeName) {
|
|
|
1424
1428
|
const result = createBaseValue();
|
|
1425
1429
|
|
|
1426
1430
|
if (value === null) {
|
|
1427
|
-
result.kind = {$case: 'nullValue', nullValue: NullValue.NULL_VALUE};
|
|
1431
|
+
result.kind = {$case: '${fieldNames.nullValue}', ${fieldNames.nullValue}: NullValue.NULL_VALUE};
|
|
1428
1432
|
} else if (typeof value === 'boolean') {
|
|
1429
|
-
result.kind = {$case: 'boolValue', boolValue: value};
|
|
1433
|
+
result.kind = {$case: '${fieldNames.boolValue}', ${fieldNames.boolValue}: value};
|
|
1430
1434
|
} else if (typeof value === 'number') {
|
|
1431
|
-
result.kind = {$case: 'numberValue', numberValue: value};
|
|
1435
|
+
result.kind = {$case: '${fieldNames.numberValue}', ${fieldNames.numberValue}: value};
|
|
1432
1436
|
} else if (typeof value === 'string') {
|
|
1433
|
-
result.kind = {$case: 'stringValue', stringValue: value};
|
|
1437
|
+
result.kind = {$case: '${fieldNames.stringValue}', ${fieldNames.stringValue}: value};
|
|
1434
1438
|
} else if (Array.isArray(value)) {
|
|
1435
|
-
result.kind = {$case: 'listValue', listValue: value};
|
|
1439
|
+
result.kind = {$case: '${fieldNames.listValue}', ${fieldNames.listValue}: value};
|
|
1436
1440
|
} else if (typeof value === 'object') {
|
|
1437
|
-
result.kind = {$case: 'structValue', structValue: value};
|
|
1441
|
+
result.kind = {$case: '${fieldNames.structValue}', ${fieldNames.structValue}: value};
|
|
1438
1442
|
} else if (typeof value !== 'undefined') {
|
|
1439
1443
|
throw new Error('Unsupported any value type: ' + typeof value);
|
|
1440
1444
|
}
|
|
@@ -1447,17 +1451,17 @@ function generateWrap(ctx, fullProtoTypeName) {
|
|
|
1447
1451
|
const result = createBaseValue();
|
|
1448
1452
|
|
|
1449
1453
|
if (value === null) {
|
|
1450
|
-
result.nullValue = NullValue.NULL_VALUE;
|
|
1454
|
+
result.${fieldNames.nullValue} = NullValue.NULL_VALUE;
|
|
1451
1455
|
} else if (typeof value === 'boolean') {
|
|
1452
|
-
result.boolValue = value;
|
|
1456
|
+
result.${fieldNames.boolValue} = value;
|
|
1453
1457
|
} else if (typeof value === 'number') {
|
|
1454
|
-
result.numberValue = value;
|
|
1458
|
+
result.${fieldNames.numberValue} = value;
|
|
1455
1459
|
} else if (typeof value === 'string') {
|
|
1456
|
-
result.stringValue = value;
|
|
1460
|
+
result.${fieldNames.stringValue} = value;
|
|
1457
1461
|
} else if (Array.isArray(value)) {
|
|
1458
|
-
result.listValue = value;
|
|
1462
|
+
result.${fieldNames.listValue} = value;
|
|
1459
1463
|
} else if (typeof value === 'object') {
|
|
1460
|
-
result.structValue = value;
|
|
1464
|
+
result.${fieldNames.structValue} = value;
|
|
1461
1465
|
} else if (typeof value !== 'undefined') {
|
|
1462
1466
|
throw new Error('Unsupported any value type: ' + typeof value);
|
|
1463
1467
|
}
|
|
@@ -1482,7 +1486,7 @@ function generateWrap(ctx, fullProtoTypeName) {
|
|
|
1482
1486
|
}
|
|
1483
1487
|
return chunks;
|
|
1484
1488
|
}
|
|
1485
|
-
function generateUnwrap(ctx, fullProtoTypeName) {
|
|
1489
|
+
function generateUnwrap(ctx, fullProtoTypeName, fieldNames) {
|
|
1486
1490
|
const chunks = [];
|
|
1487
1491
|
if (types_1.isStructTypeName(fullProtoTypeName)) {
|
|
1488
1492
|
chunks.push(ts_poet_1.code `unwrap(message: Struct): {[key: string]: any} {
|
|
@@ -1496,18 +1500,18 @@ function generateUnwrap(ctx, fullProtoTypeName) {
|
|
|
1496
1500
|
if (types_1.isAnyValueTypeName(fullProtoTypeName)) {
|
|
1497
1501
|
if (ctx.options.oneof === options_1.OneofOption.UNIONS) {
|
|
1498
1502
|
chunks.push(ts_poet_1.code `unwrap(message: Value): string | number | boolean | Object | null | Array<any> | undefined {
|
|
1499
|
-
if (message.kind?.$case === 'nullValue') {
|
|
1503
|
+
if (message.kind?.$case === '${fieldNames.nullValue}') {
|
|
1500
1504
|
return null;
|
|
1501
|
-
} else if (message.kind?.$case === 'numberValue') {
|
|
1502
|
-
return message.kind
|
|
1503
|
-
} else if (message.kind?.$case === 'stringValue') {
|
|
1504
|
-
return message.kind
|
|
1505
|
-
} else if (message.kind?.$case === 'boolValue') {
|
|
1506
|
-
return message.kind
|
|
1507
|
-
} else if (message.kind?.$case === 'structValue') {
|
|
1508
|
-
return message.kind
|
|
1509
|
-
} else if (message.kind?.$case === 'listValue') {
|
|
1510
|
-
return message.kind
|
|
1505
|
+
} else if (message.kind?.$case === '${fieldNames.numberValue}') {
|
|
1506
|
+
return message.kind?.${fieldNames.numberValue};
|
|
1507
|
+
} else if (message.kind?.$case === '${fieldNames.stringValue}') {
|
|
1508
|
+
return message.kind?.${fieldNames.stringValue};
|
|
1509
|
+
} else if (message.kind?.$case === '${fieldNames.boolValue}') {
|
|
1510
|
+
return message.kind?.${fieldNames.boolValue};
|
|
1511
|
+
} else if (message.kind?.$case === '${fieldNames.structValue}') {
|
|
1512
|
+
return message.kind?.${fieldNames.structValue};
|
|
1513
|
+
} else if (message.kind?.$case === '${fieldNames.listValue}') {
|
|
1514
|
+
return message.kind?.${fieldNames.listValue};
|
|
1511
1515
|
} else {
|
|
1512
1516
|
return undefined;
|
|
1513
1517
|
}
|
|
@@ -1515,17 +1519,17 @@ function generateUnwrap(ctx, fullProtoTypeName) {
|
|
|
1515
1519
|
}
|
|
1516
1520
|
else {
|
|
1517
1521
|
chunks.push(ts_poet_1.code `unwrap(message: Value): string | number | boolean | Object | null | Array<any> | undefined {
|
|
1518
|
-
if (message
|
|
1519
|
-
return message.stringValue;
|
|
1520
|
-
} else if (message
|
|
1521
|
-
return message.numberValue;
|
|
1522
|
-
} else if (message
|
|
1523
|
-
return message.boolValue;
|
|
1524
|
-
} else if (message
|
|
1525
|
-
return message.structValue;
|
|
1526
|
-
} else if (message
|
|
1527
|
-
return message.listValue;
|
|
1528
|
-
} else if (message
|
|
1522
|
+
if (message?.${fieldNames.stringValue} !== undefined) {
|
|
1523
|
+
return message.${fieldNames.stringValue};
|
|
1524
|
+
} else if (message?.${fieldNames.numberValue} !== undefined) {
|
|
1525
|
+
return message.${fieldNames.numberValue};
|
|
1526
|
+
} else if (message?.${fieldNames.boolValue} !== undefined) {
|
|
1527
|
+
return message.${fieldNames.boolValue};
|
|
1528
|
+
} else if (message?.${fieldNames.structValue} !== undefined) {
|
|
1529
|
+
return message.${fieldNames.structValue};
|
|
1530
|
+
} else if (message?.${fieldNames.listValue} !== undefined) {
|
|
1531
|
+
return message.${fieldNames.listValue};
|
|
1532
|
+
} else if (message?.${fieldNames.nullValue} !== undefined) {
|
|
1529
1533
|
return null;
|
|
1530
1534
|
}
|
|
1531
1535
|
return undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-proto",
|
|
3
|
-
"version": "1.115.
|
|
3
|
+
"version": "1.115.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/plugin.js",
|
|
6
6
|
"repository": "github:stephenh/ts-proto",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"dataloader": "^1.4.0",
|
|
67
67
|
"object-hash": "^1.3.1",
|
|
68
68
|
"protobufjs": "^6.11.3",
|
|
69
|
-
"ts-poet": "^
|
|
69
|
+
"ts-poet": "^4.11.0",
|
|
70
70
|
"ts-proto-descriptors": "1.6.0"
|
|
71
71
|
}
|
|
72
72
|
}
|