ts-proto 2.2.6 → 2.3.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.
@@ -10,13 +10,13 @@ const CallOptions = (0, ts_poet_1.imp)("t:CallOptions@@grpc/grpc-js");
10
10
  const ChannelCredentials = (0, ts_poet_1.imp)("ChannelCredentials@@grpc/grpc-js");
11
11
  const ClientOptions = (0, ts_poet_1.imp)("t:ClientOptions@@grpc/grpc-js");
12
12
  const Client = (0, ts_poet_1.imp)("Client@@grpc/grpc-js");
13
- const ClientDuplexStream = (0, ts_poet_1.imp)("ClientDuplexStream@@grpc/grpc-js");
14
- const ClientReadableStream = (0, ts_poet_1.imp)("ClientReadableStream@@grpc/grpc-js");
13
+ const ClientDuplexStream = (0, ts_poet_1.imp)("t:ClientDuplexStream@@grpc/grpc-js");
14
+ const ClientReadableStream = (0, ts_poet_1.imp)("t:ClientReadableStream@@grpc/grpc-js");
15
15
  const ClientUnaryCall = (0, ts_poet_1.imp)("t:ClientUnaryCall@@grpc/grpc-js");
16
- const ClientWritableStream = (0, ts_poet_1.imp)("ClientWritableStream@@grpc/grpc-js");
17
- const handleBidiStreamingCall = (0, ts_poet_1.imp)("handleBidiStreamingCall@@grpc/grpc-js");
18
- const handleClientStreamingCall = (0, ts_poet_1.imp)("handleClientStreamingCall@@grpc/grpc-js");
19
- const handleServerStreamingCall = (0, ts_poet_1.imp)("handleServerStreamingCall@@grpc/grpc-js");
16
+ const ClientWritableStream = (0, ts_poet_1.imp)("t:ClientWritableStream@@grpc/grpc-js");
17
+ const handleBidiStreamingCall = (0, ts_poet_1.imp)("t:handleBidiStreamingCall@@grpc/grpc-js");
18
+ const handleClientStreamingCall = (0, ts_poet_1.imp)("t:handleClientStreamingCall@@grpc/grpc-js");
19
+ const handleServerStreamingCall = (0, ts_poet_1.imp)("t:handleServerStreamingCall@@grpc/grpc-js");
20
20
  const handleUnaryCall = (0, ts_poet_1.imp)("t:handleUnaryCall@@grpc/grpc-js");
21
21
  const UntypedServiceImplementation = (0, ts_poet_1.imp)("t:UntypedServiceImplementation@@grpc/grpc-js");
22
22
  const makeGenericClientConstructor = (0, ts_poet_1.imp)("makeGenericClientConstructor@@grpc/grpc-js");
package/build/src/main.js CHANGED
@@ -836,36 +836,27 @@ function generateInterfaceDeclaration(ctx, fullName, messageDesc, sourceInfo, fu
836
836
  }
837
837
  function generateOneofProperty(ctx, messageDesc, oneofIndex, sourceInfo) {
838
838
  const { options } = ctx;
839
- const fields = messageDesc.field.filter((field) => (0, types_1.isWithinOneOf)(field) && field.oneofIndex === oneofIndex);
839
+ const fields = messageDesc.field
840
+ .map((field, index) => ({ index, field }))
841
+ .filter((item) => (0, types_1.isWithinOneOf)(item.field) && item.field.oneofIndex === oneofIndex);
840
842
  const mbReadonly = maybeReadonly(options);
841
- const unionType = (0, ts_poet_1.joinCode)(fields.map((f) => {
842
- let fieldName = (0, case_1.maybeSnakeToCamel)(f.name, options);
843
- let typeName = (0, types_1.toTypeName)(ctx, messageDesc, f);
843
+ const info = sourceInfo.lookup(sourceInfo_1.Fields.message.oneof_decl, oneofIndex);
844
+ let outerComments = [];
845
+ (0, utils_1.maybeAddComment)(options, info, outerComments);
846
+ const unionType = (0, ts_poet_1.joinCode)(fields.flatMap((f) => {
847
+ const fieldInfo = sourceInfo.lookup(sourceInfo_1.Fields.message.field, f.index);
848
+ let fieldName = (0, case_1.maybeSnakeToCamel)(f.field.name, options);
849
+ let typeName = (0, types_1.toTypeName)(ctx, messageDesc, f.field);
844
850
  let valueName = (0, utils_1.oneofValueName)(fieldName, options);
845
- return (0, ts_poet_1.code) `{ ${mbReadonly}$case: '${fieldName}', ${mbReadonly}${valueName}: ${typeName} }`;
846
- }), { on: " | " });
851
+ let fieldComments = [];
852
+ (0, utils_1.maybeAddComment)(options, fieldInfo, fieldComments);
853
+ const combinedComments = fieldComments.join("\n");
854
+ return (0, ts_poet_1.code) `| // \n ${combinedComments} { ${mbReadonly}$case: '${fieldName}', ${mbReadonly}${valueName}: ${typeName} }`;
855
+ }));
847
856
  const name = (0, case_1.maybeSnakeToCamel)(messageDesc.oneofDecl[oneofIndex].name, options);
848
- return (0, ts_poet_1.code) `${mbReadonly}${name}?: ${unionType} | ${(0, utils_1.nullOrUndefined)(options)},`;
849
- /*
850
- // Ideally we'd put the comments for each oneof field next to the anonymous
851
- // type we've created in the type union above, but ts-poet currently lacks
852
- // that ability. For now just concatenate all comments into one big one.
853
- let comments: Array<string> = [];
854
- const info = sourceInfo.lookup(Fields.message.oneof_decl, oneofIndex);
855
- maybeAddComment(options, info, (text) => comments.push(text));
856
- messageDesc.field.forEach((field, index) => {
857
- if (!isWithinOneOf(field) || field.oneofIndex !== oneofIndex) {
858
- return;
859
- }
860
- const info = sourceInfo.lookup(Fields.message.field, index);
861
- const name = maybeSnakeToCamel(field.name, options);
862
- maybeAddComment(options, info, (text) => comments.push(name + '\n' + text));
857
+ return (0, ts_poet_1.joinCode)([...outerComments, (0, ts_poet_1.code) `${mbReadonly}${name}?:`, unionType, (0, ts_poet_1.code) `| ${(0, utils_1.nullOrUndefined)(options)},`], {
858
+ on: "\n",
863
859
  });
864
- if (comments.length) {
865
- prop = prop.addJavadoc(comments.join('\n'));
866
- }
867
- return prop;
868
- */
869
860
  }
870
861
  // Create a function that constructs 'base' instance with default values for decode to use as a prototype
871
862
  function generateBaseInstanceFactory(ctx, fullName, messageDesc, fullTypeName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "2.2.6",
3
+ "version": "2.3.0",
4
4
  "description": "",
5
5
  "main": "build/src/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",