ts-proto 1.123.0 → 1.125.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/CHANGELOG.md +21 -0
- package/README.markdown +3 -1
- package/build/main.js +4 -0
- package/build/options.js +5 -0
- package/build/plugin.js +4 -4
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
# [1.125.0](https://github.com/stephenh/ts-proto/compare/v1.124.0...v1.125.0) (2022-09-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* omit optional fields in base instance ([#669](https://github.com/stephenh/ts-proto/issues/669)) ([47b60aa](https://github.com/stephenh/ts-proto/commit/47b60aab95533542cf762f152138f7ab4234de88))
|
|
7
|
+
|
|
8
|
+
# [1.124.0](https://github.com/stephenh/ts-proto/compare/v1.123.1...v1.124.0) (2022-09-03)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* Bump ts poet for dprint perf increase ([#668](https://github.com/stephenh/ts-proto/issues/668)) ([961d388](https://github.com/stephenh/ts-proto/commit/961d388fa7dc7cb25fbe700526cbd481f3a48ae1))
|
|
14
|
+
|
|
15
|
+
## [1.123.1](https://github.com/stephenh/ts-proto/compare/v1.123.0...v1.123.1) (2022-08-27)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* Bump ts-poet to use @dprint/typescript. ([#662](https://github.com/stephenh/ts-proto/issues/662)) ([84b64f4](https://github.com/stephenh/ts-proto/commit/84b64f4219f96199e8722678354430fbf00cebba))
|
|
21
|
+
|
|
1
22
|
# [1.123.0](https://github.com/stephenh/ts-proto/compare/v1.122.0...v1.123.0) (2022-08-27)
|
|
2
23
|
|
|
3
24
|
|
package/README.markdown
CHANGED
|
@@ -448,6 +448,8 @@ Generated code will be placed in the Gradle build directory.
|
|
|
448
448
|
|
|
449
449
|
- With `--ts_proto_opt=useNumericEnumForJson=true`, the JSON converter (`toJSON`) will encode enum values as int, rather than a string literal.
|
|
450
450
|
|
|
451
|
+
- With `--ts_proto_opt=initializeFieldsAsUndefined=false`, all optional field initializers will be omited from the generated base instances.
|
|
452
|
+
|
|
451
453
|
### NestJS Support
|
|
452
454
|
|
|
453
455
|
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).
|
|
@@ -482,7 +484,7 @@ const sendRequest: RpcImpl = (service, method, data) => {
|
|
|
482
484
|
// Conventionally in gRPC, the request path looks like
|
|
483
485
|
// "package.names.ServiceName/MethodName",
|
|
484
486
|
// we therefore construct such a string
|
|
485
|
-
const path =
|
|
487
|
+
const path = `/${service}/${method}`;
|
|
486
488
|
|
|
487
489
|
return new Promise((resolve, reject) => {
|
|
488
490
|
// makeUnaryRequest transmits the result (and error) with a callback
|
package/build/main.js
CHANGED
|
@@ -549,6 +549,7 @@ function generateOneofProperty(ctx, messageDesc, oneofIndex, sourceInfo) {
|
|
|
549
549
|
}
|
|
550
550
|
// Create a function that constructs 'base' instance with default values for decode to use as a prototype
|
|
551
551
|
function generateBaseInstanceFactory(ctx, fullName, messageDesc, fullTypeName) {
|
|
552
|
+
const { options } = ctx;
|
|
552
553
|
const fields = [];
|
|
553
554
|
// When oneof=unions, we generate a single property with an ADT per `oneof` clause.
|
|
554
555
|
const processedOneofs = new Set();
|
|
@@ -562,6 +563,9 @@ function generateBaseInstanceFactory(ctx, fullName, messageDesc, fullTypeName) {
|
|
|
562
563
|
}
|
|
563
564
|
continue;
|
|
564
565
|
}
|
|
566
|
+
if (!options.initializeFieldsAsUndefined && (0, types_1.isOptionalProperty)(field, messageDesc.options, options)) {
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
565
569
|
const name = (0, case_1.maybeSnakeToCamel)(field.name, ctx.options);
|
|
566
570
|
const val = (0, types_1.isWithinOneOf)(field)
|
|
567
571
|
? "undefined"
|
package/build/options.js
CHANGED
|
@@ -71,6 +71,7 @@ function defaultOptions() {
|
|
|
71
71
|
usePrototypeForDefaults: false,
|
|
72
72
|
useJsonWireFormat: false,
|
|
73
73
|
useNumericEnumForJson: false,
|
|
74
|
+
initializeFieldsAsUndefined: true,
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
77
|
exports.defaultOptions = defaultOptions;
|
|
@@ -147,6 +148,9 @@ function optionsFromParameter(parameter) {
|
|
|
147
148
|
options.useDate = DateOption.STRING;
|
|
148
149
|
}
|
|
149
150
|
}
|
|
151
|
+
if (options.nestJs) {
|
|
152
|
+
options.initializeFieldsAsUndefined = false;
|
|
153
|
+
}
|
|
150
154
|
return options;
|
|
151
155
|
}
|
|
152
156
|
exports.optionsFromParameter = optionsFromParameter;
|
|
@@ -168,6 +172,7 @@ function parseParameter(parameter) {
|
|
|
168
172
|
function getTsPoetOpts(_options) {
|
|
169
173
|
const imports = ["protobufjs/minimal" + _options.importSuffix];
|
|
170
174
|
return {
|
|
175
|
+
prefix: `/* eslint-disable */`,
|
|
171
176
|
dprintOptions: { preferSingleLine: true, lineWidth: 120 },
|
|
172
177
|
...(_options.esModuleInterop ? { forceDefaultImport: imports } : { forceModuleImport: imports }),
|
|
173
178
|
};
|
package/build/plugin.js
CHANGED
|
@@ -20,16 +20,16 @@ async function main() {
|
|
|
20
20
|
const filesToGenerate = options.emitImportedFiles ? request.protoFile : (0, utils_1.protoFilesToGenerate)(request);
|
|
21
21
|
const files = await Promise.all(filesToGenerate.map(async (file) => {
|
|
22
22
|
const [path, code] = (0, main_1.generateFile)(ctx, file);
|
|
23
|
-
const
|
|
24
|
-
return { name: path, content
|
|
23
|
+
const content = code.toString({ ...(0, options_1.getTsPoetOpts)(options), path });
|
|
24
|
+
return { name: path, content };
|
|
25
25
|
}));
|
|
26
26
|
if (options.outputTypeRegistry) {
|
|
27
27
|
const utils = (0, main_1.makeUtils)(options);
|
|
28
28
|
const ctx = { options, typeMap, utils };
|
|
29
29
|
const path = "typeRegistry.ts";
|
|
30
30
|
const code = (0, generate_type_registry_1.generateTypeRegistry)(ctx);
|
|
31
|
-
const
|
|
32
|
-
files.push({ name: path, content
|
|
31
|
+
const content = code.toString({ ...(0, options_1.getTsPoetOpts)(options), path });
|
|
32
|
+
files.push({ name: path, content });
|
|
33
33
|
}
|
|
34
34
|
const response = ts_proto_descriptors_1.CodeGeneratorResponse.fromPartial({
|
|
35
35
|
file: files,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-proto",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.125.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/plugin.js",
|
|
6
6
|
"repository": "github:stephenh/ts-proto",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"dataloader": "^1.4.0",
|
|
68
68
|
"object-hash": "^1.3.1",
|
|
69
69
|
"protobufjs": "^6.11.3",
|
|
70
|
-
"ts-poet": "^
|
|
70
|
+
"ts-poet": "^6.1.0",
|
|
71
71
|
"ts-proto-descriptors": "1.7.1"
|
|
72
72
|
}
|
|
73
73
|
}
|