ts-proto 1.174.0 → 1.175.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/README.markdown CHANGED
@@ -432,6 +432,8 @@ Generated code will be placed in the Gradle build directory.
432
432
 
433
433
  - With `--ts_proto_opt=useMongoObjectId=true`, fields of a type called ObjectId where the message is constructed to have on field called value that is a string will be mapped to type `mongodb.ObjectId` in the generated types. This will require your project to install the mongodb npm package. See [ObjectId](#objectid) for more details.
434
434
 
435
+ - With `--ts_proto_opt=annotateFilesWithVersion=false`, the generated files will not contain the versions of `protoc` and `ts-proto` used to generate the file. This option is normally set to `true`, such that files list the versions used.
436
+
435
437
  - With `--ts_proto_opt=outputSchema=true`, meta typings will be generated that can later be used in other code generators.
436
438
 
437
439
  - With `--ts_proto_opt=outputTypeAnnotations=true`, each message will be given a `$type` field containing its fully-qualified name. You can use `--ts_proto_opt=outputTypeAnnotations=static-only` to omit it from the `interface` declaration, or `--ts_proto_opt=outputTypeAnnotations=optional` to make it an optional property on the `interface` definition. The latter option may be useful if you want to use the `$type` field for runtime type checking on responses from a server.
@@ -787,9 +789,7 @@ The following helper types may make it easier to work with the types generated f
787
789
  type OneOfCases<T> = T extends { $case: infer U extends string } ? U : never;
788
790
 
789
791
  /** Extracts a union of all the value types from a oneOf field */
790
- type OneOfValues<T> = T extends { $case: infer U extends string; [key: string]: unknown }
791
- ? T[U]
792
- : never;
792
+ type OneOfValues<T> = T extends { $case: infer U extends string; [key: string]: unknown } ? T[U] : never;
793
793
 
794
794
  /** Extracts the specific type of a oneOf case based on its field name */
795
795
  type OneOfCase<T, K extends OneOfCases<T>> = T extends {
@@ -95,6 +95,7 @@ export type Options = {
95
95
  disableProto2Optionals: boolean;
96
96
  disableProto2DefaultValues: boolean;
97
97
  useNullAsOptional: boolean;
98
+ annotateFilesWithVersion: boolean;
98
99
  };
99
100
  export declare function defaultOptions(): Options;
100
101
  export declare function optionsFromParameter(parameter: string | undefined): Options;
package/build/options.js CHANGED
@@ -102,6 +102,7 @@ function defaultOptions() {
102
102
  disableProto2Optionals: false,
103
103
  disableProto2DefaultValues: false,
104
104
  useNullAsOptional: false,
105
+ annotateFilesWithVersion: true,
105
106
  };
106
107
  }
107
108
  exports.defaultOptions = defaultOptions;
@@ -252,10 +253,12 @@ function getTsPoetOpts(options, tsProtoVersion, protocVersion, fileName) {
252
253
  // Comment block at the top of every source file, since these comments require specific
253
254
  // syntax incompatible with ts-poet, we will hard-code the string and prepend to the
254
255
  // generator output.
255
- prefix: `// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
256
+ prefix: `// Code generated by protoc-gen-ts_proto. DO NOT EDIT.${options.annotateFilesWithVersion
257
+ ? `
256
258
  // versions:
257
259
  // protoc-gen-ts_proto ${tsProtoVersion}
258
- // protoc ${protocVersion}
260
+ // protoc ${protocVersion}`
261
+ : ""}
259
262
  ${fileName ? `// source: ${fileName}` : ""}
260
263
 
261
264
  /* eslint-disable */`,
package/build/schema.js CHANGED
@@ -188,13 +188,30 @@ function encodedOptionsToOptions(ctx, extendee, encodedOptions) {
188
188
  for (const key in encodedOptions) {
189
189
  const value = encodedOptions[key];
190
190
  const extension = extensionCache[extendee][parseInt(key, 10) >>> 3];
191
- resultOptions.push(getExtensionValue(ctx, extension, value));
191
+ if (shouldAddOptionDefinition(ctx, extension)) {
192
+ // todo: we should be able to create an option definition ALWAYS, however,
193
+ // we currently cannot do that because the if the extension is a sub-message
194
+ // (and thus, not just a straightforward value), we don't have an JSON object
195
+ // representation of the option - just it's encoded value. Our approach in
196
+ // getExtensionValue is to decode the encoded value into a message, but this
197
+ // Message.decode(...) method is not always included in the generated code.
198
+ // We should fix this so that we can always create an option definition by
199
+ // somehow premptively decoding the encoded value and then inserting it into
200
+ // the option defintion.
201
+ // please refer to inteegration/options-types-only to see this in action
202
+ resultOptions.push(getExtensionValue(ctx, extension, value));
203
+ }
192
204
  }
193
205
  if (resultOptions.length == 0) {
194
206
  return undefined;
195
207
  }
196
208
  return (0, ts_poet_1.code) `{${(0, ts_poet_1.joinCode)(resultOptions, { on: "," })}}`;
197
209
  }
210
+ function shouldAddOptionDefinition(ctx, extension) {
211
+ return (extension.type !== ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_MESSAGE ||
212
+ ctx.options.outputEncodeMethods === true ||
213
+ ctx.options.outputEncodeMethods == "decode-only");
214
+ }
198
215
  function resolveMessageOptions(ctx, message) {
199
216
  const fieldsOptions = [];
200
217
  message.field.forEach((field) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.174.0",
3
+ "version": "1.175.1",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",