ts-proto 1.175.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.
Files changed (2) hide show
  1. package/build/schema.js +18 -1
  2. package/package.json +1 -1
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.175.0",
3
+ "version": "1.175.1",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",