ts-proto 1.157.1 → 1.158.0
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/README.markdown +3 -1
- package/build/main.js +2 -1
- package/build/options.js +7 -0
- package/package.json +1 -1
package/README.markdown
CHANGED
|
@@ -79,7 +79,7 @@ It will also generate client implementations of `PingService`; currently [Twirp]
|
|
|
79
79
|
- `protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=. ./simple.proto`
|
|
80
80
|
- (Note that the output parameter name, `ts_proto_out`, is named based on the suffix of the plugin's name, i.e. "ts_proto" suffix in the `--plugin=./node_modules/.bin/protoc-gen-ts_proto` parameter becomes the `_out` prefix, per `protoc`'s CLI conventions.)
|
|
81
81
|
- On Windows, use `protoc --plugin=protoc-gen-ts_proto=".\\node_modules\\.bin\\protoc-gen-ts_proto.cmd" --ts_proto_out=. ./simple.proto` (see [#93](https://github.com/stephenh/ts-proto/issues/93))
|
|
82
|
-
- Ensure you're using a modern `protoc
|
|
82
|
+
- Ensure you're using a modern `protoc` (see [installation instructions for your platform](https://grpc.io/docs/protoc-installation/), i.e. `protoc` v`3.0.0` doesn't support the `_opt` flag
|
|
83
83
|
|
|
84
84
|
This will generate `*.ts` source files for the given `*.proto` types.
|
|
85
85
|
|
|
@@ -517,6 +517,8 @@ Generated code will be placed in the Gradle build directory.
|
|
|
517
517
|
|
|
518
518
|
This will disable `exportCommonSymbols` to avoid name collisions on the common symbols.
|
|
519
519
|
|
|
520
|
+
- With `--emitDefaultValues=json-methods`, the generated toJSON method will emit scalars like `0` and `""` as json fields.
|
|
521
|
+
|
|
520
522
|
### NestJS Support
|
|
521
523
|
|
|
522
524
|
We have a great way of working together with [nestjs](https://docs.nestjs.com/microservices/grpc). `ts-proto` generates `interfaces` and `decorators` for you controller, client. For more information see the [nestjs readme](NESTJS.markdown).
|
package/build/main.js
CHANGED
|
@@ -1786,7 +1786,8 @@ function generateToJson(ctx, fullName, fullProtobufTypeName, messageDesc) {
|
|
|
1786
1786
|
`);
|
|
1787
1787
|
}
|
|
1788
1788
|
else {
|
|
1789
|
-
|
|
1789
|
+
let emitDefaultValuesForJson = ctx.options.emitDefaultValues.includes("json-methods");
|
|
1790
|
+
const check = ((0, types_1.isScalar)(field) || (0, types_1.isEnum)(field)) && !((0, types_1.isWithinOneOf)(field) || emitDefaultValuesForJson)
|
|
1790
1791
|
? (0, types_1.notDefaultCheck)(ctx, field, messageDesc.options, `message.${fieldName}`)
|
|
1791
1792
|
: `message.${fieldName} !== undefined`;
|
|
1792
1793
|
chunks.push((0, ts_poet_1.code) `
|
package/build/options.js
CHANGED
|
@@ -37,6 +37,7 @@ function defaultOptions() {
|
|
|
37
37
|
return {
|
|
38
38
|
context: false,
|
|
39
39
|
snakeToCamel: ["json", "keys"],
|
|
40
|
+
emitDefaultValues: [],
|
|
40
41
|
forceLong: LongOption.NUMBER,
|
|
41
42
|
useOptionals: "none",
|
|
42
43
|
useDate: DateOption.DATE,
|
|
@@ -147,6 +148,12 @@ function optionsFromParameter(parameter) {
|
|
|
147
148
|
else if (typeof options.snakeToCamel === "string") {
|
|
148
149
|
options.snakeToCamel = options.snakeToCamel.split("_");
|
|
149
150
|
}
|
|
151
|
+
if (options.emitDefaultValues === "json-methods") {
|
|
152
|
+
options.emitDefaultValues = ["json-methods"];
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
options.emitDefaultValues = [];
|
|
156
|
+
}
|
|
150
157
|
if (options.useJsonWireFormat) {
|
|
151
158
|
if (!options.onlyTypes) {
|
|
152
159
|
// useJsonWireFormat requires onlyTypes=true
|