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 +7 -0
- package/README.markdown +5 -2
- package/build/main.js +44 -36
- package/package.json +1 -1
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=
|
|
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 =
|
|
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
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
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
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
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
|
-
|
|
1411
|
+
const result = createBaseListValue();
|
|
1412
|
+
|
|
1413
|
+
result.values = value ?? [];
|
|
1414
|
+
|
|
1415
|
+
return result;
|
|
1408
1416
|
}`);
|
|
1409
1417
|
}
|
|
1410
1418
|
return chunks;
|