ts-proto 1.106.2 → 1.107.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 CHANGED
@@ -1,3 +1,10 @@
1
+ # [1.107.0](https://github.com/stephenh/ts-proto/compare/v1.106.2...v1.107.0) (2022-03-04)
2
+
3
+
4
+ ### Features
5
+
6
+ * Allow simultaneous services and generic service definitions ([#512](https://github.com/stephenh/ts-proto/issues/512)) ([680831e](https://github.com/stephenh/ts-proto/commit/680831e76f1a4ceb4337442a157d7e702cb14bfc))
7
+
1
8
  ## [1.106.2](https://github.com/stephenh/ts-proto/compare/v1.106.1...v1.106.2) (2022-02-27)
2
9
 
3
10
 
package/README.markdown CHANGED
@@ -362,6 +362,8 @@ Generated code will be placed in the Gradle build directory.
362
362
 
363
363
  - With `--ts_proto_opt=outputServices=generic-definitions`, ts-proto will output generic (framework-agnostic) service definitions. These definitions contain descriptors for each method with links to request and response types, which allows to generate server and client stubs at runtime, and also generate strong types for them at compile time. An example of a library that uses this approach is [nice-grpc](https://github.com/deeplay-io/nice-grpc).
364
364
 
365
+ - With `--ts_proto_opt=outputServices=generic-definitions,outputServices=default`, ts-proto will output both generic definitions and interfaces. This is useful if you want to rely on the interfaces, but also have some reflection capabilities at runtime.
366
+
365
367
  - With `--ts_proto_opt=outputServices=false`, or `=none`, ts-proto will output NO service definitions.
366
368
 
367
369
  - With `--ts_proto_opt=emitImportedFiles=false`, ts-proto will not emit `google/protobuf/*` files unless you explicit add files to `protoc` like this
package/build/main.js CHANGED
@@ -118,29 +118,34 @@ function generateFile(ctx, fileDesc) {
118
118
  }
119
119
  chunks.push(ts_poet_1.code `export const ${serviceConstName} = "${serviceDesc.name}";`);
120
120
  }
121
- else if (options.outputServices === options_1.ServiceOption.GRPC) {
122
- chunks.push(generate_grpc_js_1.generateGrpcJsService(ctx, fileDesc, sInfo, serviceDesc));
123
- }
124
- else if (options.outputServices === options_1.ServiceOption.GENERIC) {
125
- chunks.push(generate_generic_service_definition_1.generateGenericServiceDefinition(ctx, fileDesc, sInfo, serviceDesc));
126
- }
127
- else if (options.outputServices === options_1.ServiceOption.DEFAULT) {
128
- // This service could be Twirp or grpc-web or JSON (maybe). So far all of their
129
- // interfaces are fairly similar so we share the same service interface.
130
- chunks.push(generate_services_1.generateService(ctx, fileDesc, sInfo, serviceDesc));
131
- if (options.outputClientImpl === true) {
132
- chunks.push(generate_services_1.generateServiceClientImpl(ctx, fileDesc, serviceDesc));
133
- }
134
- else if (options.outputClientImpl === 'grpc-web') {
135
- chunks.push(generate_grpc_web_1.generateGrpcClientImpl(ctx, fileDesc, serviceDesc));
136
- chunks.push(generate_grpc_web_1.generateGrpcServiceDesc(fileDesc, serviceDesc));
137
- serviceDesc.method.forEach((method) => {
138
- chunks.push(generate_grpc_web_1.generateGrpcMethodDesc(ctx, serviceDesc, method));
139
- if (method.serverStreaming) {
140
- hasServerStreamingMethods = true;
121
+ else {
122
+ const uniqueServices = [...new Set(options.outputServices)].sort();
123
+ uniqueServices.forEach((outputService) => {
124
+ if (outputService === options_1.ServiceOption.GRPC) {
125
+ chunks.push(generate_grpc_js_1.generateGrpcJsService(ctx, fileDesc, sInfo, serviceDesc));
126
+ }
127
+ else if (outputService === options_1.ServiceOption.GENERIC) {
128
+ chunks.push(generate_generic_service_definition_1.generateGenericServiceDefinition(ctx, fileDesc, sInfo, serviceDesc));
129
+ }
130
+ else if (outputService === options_1.ServiceOption.DEFAULT) {
131
+ // This service could be Twirp or grpc-web or JSON (maybe). So far all of their
132
+ // interfaces are fairly similar so we share the same service interface.
133
+ chunks.push(generate_services_1.generateService(ctx, fileDesc, sInfo, serviceDesc));
134
+ if (options.outputClientImpl === true) {
135
+ chunks.push(generate_services_1.generateServiceClientImpl(ctx, fileDesc, serviceDesc));
141
136
  }
142
- });
143
- }
137
+ else if (options.outputClientImpl === 'grpc-web') {
138
+ chunks.push(generate_grpc_web_1.generateGrpcClientImpl(ctx, fileDesc, serviceDesc));
139
+ chunks.push(generate_grpc_web_1.generateGrpcServiceDesc(fileDesc, serviceDesc));
140
+ serviceDesc.method.forEach((method) => {
141
+ chunks.push(generate_grpc_web_1.generateGrpcMethodDesc(ctx, serviceDesc, method));
142
+ if (method.serverStreaming) {
143
+ hasServerStreamingMethods = true;
144
+ }
145
+ });
146
+ }
147
+ }
148
+ });
144
149
  }
145
150
  serviceDesc.method.forEach((methodDesc, index) => {
146
151
  if (methodDesc.serverStreaming || methodDesc.clientStreaming) {
@@ -148,7 +153,9 @@ function generateFile(ctx, fileDesc) {
148
153
  }
149
154
  });
150
155
  });
151
- if (options.outputServices === options_1.ServiceOption.DEFAULT && options.outputClientImpl && fileDesc.service.length > 0) {
156
+ if (options.outputServices.includes(options_1.ServiceOption.DEFAULT) &&
157
+ options.outputClientImpl &&
158
+ fileDesc.service.length > 0) {
152
159
  if (options.outputClientImpl === true) {
153
160
  chunks.push(generate_services_1.generateRpcType(ctx, hasStreamingMethods));
154
161
  }
package/build/options.js CHANGED
@@ -51,7 +51,7 @@ function defaultOptions() {
51
51
  constEnums: false,
52
52
  enumsAsLiterals: false,
53
53
  outputClientImpl: true,
54
- outputServices: ServiceOption.DEFAULT,
54
+ outputServices: [],
55
55
  returnObservable: false,
56
56
  addGrpcMetadata: false,
57
57
  addNestjsRestParameter: false,
@@ -95,7 +95,14 @@ function optionsFromParameter(parameter) {
95
95
  }
96
96
  // Treat outputServices=false as NONE
97
97
  if (options.outputServices === false) {
98
- options.outputServices = ServiceOption.NONE;
98
+ options.outputServices = [ServiceOption.NONE];
99
+ }
100
+ // Existing type-coercion inside parseParameter leaves a little to be desired.
101
+ if (typeof options.outputServices == 'string') {
102
+ options.outputServices = [options.outputServices];
103
+ }
104
+ if (options.outputServices.length == 0) {
105
+ options.outputServices = [ServiceOption.DEFAULT];
99
106
  }
100
107
  if (options.useDate === true) {
101
108
  // Treat useDate=true as DATE
package/build/utils.js CHANGED
@@ -137,7 +137,7 @@ class FormattedMethodDescriptor {
137
137
  */
138
138
  static formatName(methodName, options) {
139
139
  let result = methodName;
140
- if (options.lowerCaseServiceMethods || options.outputServices === options_1.ServiceOption.GRPC) {
140
+ if (options.lowerCaseServiceMethods || options.outputServices.includes(options_1.ServiceOption.GRPC)) {
141
141
  result = case_1.camelCase(result);
142
142
  }
143
143
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.106.2",
3
+ "version": "1.107.0",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",