@bufbuild/protoc-gen-es 2.0.0-alpha.2 → 2.0.0-alpha.3

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protoc-gen-es",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.3",
4
4
  "description": "Protocol Buffers code generator for ECMAScript",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -20,11 +20,11 @@
20
20
  },
21
21
  "preferUnplugged": true,
22
22
  "dependencies": {
23
- "@bufbuild/protobuf": "^2.0.0-alpha.2",
24
- "@bufbuild/protoplugin": "2.0.0-alpha.2"
23
+ "@bufbuild/protobuf": "^2.0.0-alpha.3",
24
+ "@bufbuild/protoplugin": "2.0.0-alpha.3"
25
25
  },
26
26
  "peerDependencies": {
27
- "@bufbuild/protobuf": "2.0.0-alpha.2"
27
+ "@bufbuild/protobuf": "2.0.0-alpha.3"
28
28
  },
29
29
  "peerDependenciesMeta": {
30
30
  "@bufbuild/protobuf": {
@@ -39,7 +39,7 @@ function generateTs(schema) {
39
39
  const { GenDescFile } = f.runtime.codegen;
40
40
  const fileDesc = f.importDesc(file);
41
41
  generateDescDoc(f, file);
42
- f.print(f.exportDecl("const", fileDesc.name), ": ", GenDescFile, " = ", pure);
42
+ f.print(f.export("const", fileDesc.name), ": ", GenDescFile, " = ", pure);
43
43
  f.print(" ", getFileDescCall(f, file, schema), ";");
44
44
  f.print();
45
45
  for (const desc of schema.typesInFile(file)) {
@@ -51,7 +51,7 @@ function generateTs(schema) {
51
51
  const name = f.importDesc(desc).name;
52
52
  generateDescDoc(f, desc);
53
53
  const call = (0, util_1.functionCall)(messageDesc, [fileDesc, ...(0, codegenv1_1.pathInFileDesc)(desc)]);
54
- f.print(f.exportDecl("const", name), ": ", GenDescMessage, "<", MessageShape, ">", " = ", pure);
54
+ f.print(f.export("const", name), ": ", GenDescMessage, "<", MessageShape, ">", " = ", pure);
55
55
  f.print(" ", call, ";");
56
56
  f.print();
57
57
  break;
@@ -63,7 +63,7 @@ function generateTs(schema) {
63
63
  generateDescDoc(f, desc);
64
64
  const name = f.importDesc(desc).name;
65
65
  const call = (0, util_1.functionCall)(enumDesc, [fileDesc, ...(0, codegenv1_1.pathInFileDesc)(desc)]);
66
- f.print(f.exportDecl("const", name), ": ", GenDescEnum, "<", EnumShape, ">", " = ", pure);
66
+ f.print(f.export("const", name), ": ", GenDescEnum, "<", EnumShape, ">", " = ", pure);
67
67
  f.print(" ", call, ";");
68
68
  f.print();
69
69
  break;
@@ -75,7 +75,7 @@ function generateTs(schema) {
75
75
  const V = (0, util_1.fieldTypeScriptType)(desc).typing;
76
76
  const call = (0, util_1.functionCall)(extDesc, [fileDesc, ...(0, codegenv1_1.pathInFileDesc)(desc)]);
77
77
  f.print(f.jsDoc(desc));
78
- f.print(f.exportDecl("const", name), ": ", GenDescExtension, "<", E, ", ", V, ">", " = ", pure);
78
+ f.print(f.export("const", name), ": ", GenDescExtension, "<", E, ", ", V, ">", " = ", pure);
79
79
  f.print(" ", call, ";");
80
80
  f.print();
81
81
  break;
@@ -85,7 +85,7 @@ function generateTs(schema) {
85
85
  const name = f.importDesc(desc).name;
86
86
  const call = (0, util_1.functionCall)(serviceDesc, [fileDesc, ...(0, codegenv1_1.pathInFileDesc)(desc)]);
87
87
  f.print(f.jsDoc(desc));
88
- f.print(f.exportDecl("const", name), ": ", GenDescService, "<", getServiceShapeExpr(f, desc), "> = ", pure);
88
+ f.print(f.export("const", name), ": ", GenDescService, "<", getServiceShapeExpr(f, desc), "> = ", pure);
89
89
  f.print(" ", call, ";");
90
90
  f.print();
91
91
  break;
@@ -101,7 +101,7 @@ function generateJs(schema) {
101
101
  f.preamble(file);
102
102
  const fileDesc = f.importDesc(file);
103
103
  generateDescDoc(f, file);
104
- f.print(f.exportDecl("const", fileDesc.name), " = ", pure);
104
+ f.print(f.export("const", fileDesc.name), " = ", pure);
105
105
  f.print(" ", getFileDescCall(f, file, schema), ";");
106
106
  f.print();
107
107
  for (const desc of schema.typesInFile(file)) {
@@ -111,7 +111,7 @@ function generateJs(schema) {
111
111
  const name = f.importDesc(desc).name;
112
112
  generateDescDoc(f, desc);
113
113
  const call = (0, util_1.functionCall)(messageDesc, [fileDesc, ...(0, codegenv1_1.pathInFileDesc)(desc)]);
114
- f.print(f.exportDecl("const", name), " = ", pure);
114
+ f.print(f.export("const", name), " = ", pure);
115
115
  f.print(" ", call, ";");
116
116
  f.print();
117
117
  break;
@@ -123,7 +123,7 @@ function generateJs(schema) {
123
123
  generateDescDoc(f, desc);
124
124
  const name = f.importDesc(desc).name;
125
125
  const call = (0, util_1.functionCall)(enumDesc, [fileDesc, ...(0, codegenv1_1.pathInFileDesc)(desc)]);
126
- f.print(f.exportDecl("const", name), " = ", pure);
126
+ f.print(f.export("const", name), " = ", pure);
127
127
  f.print(" ", call, ";");
128
128
  f.print();
129
129
  }
@@ -132,7 +132,7 @@ function generateJs(schema) {
132
132
  f.print(f.jsDoc(desc));
133
133
  const { tsEnum } = f.runtime.codegen;
134
134
  const call = (0, util_1.functionCall)(tsEnum, [f.importDesc(desc)]);
135
- f.print(f.exportDecl("const", f.importShape(desc).name), " = ", pure);
135
+ f.print(f.export("const", f.importShape(desc).name), " = ", pure);
136
136
  f.print(" ", call, ";");
137
137
  f.print();
138
138
  }
@@ -143,7 +143,7 @@ function generateJs(schema) {
143
143
  const name = f.importDesc(desc).name;
144
144
  const call = (0, util_1.functionCall)(extDesc, [fileDesc, ...(0, codegenv1_1.pathInFileDesc)(desc)]);
145
145
  f.print(f.jsDoc(desc));
146
- f.print(f.exportDecl("const", name), " = ", pure);
146
+ f.print(f.export("const", name), " = ", pure);
147
147
  f.print(" ", call, ";");
148
148
  f.print();
149
149
  break;
@@ -153,7 +153,7 @@ function generateJs(schema) {
153
153
  const name = f.importDesc(desc).name;
154
154
  f.print(f.jsDoc(desc));
155
155
  const call = (0, util_1.functionCall)(serviceDesc, [fileDesc, ...(0, codegenv1_1.pathInFileDesc)(desc)]);
156
- f.print(f.exportDecl("const", name), " = ", pure);
156
+ f.print(f.export("const", name), " = ", pure);
157
157
  f.print(" ", call, ";");
158
158
  f.print();
159
159
  break;
@@ -170,7 +170,7 @@ function generateDts(schema) {
170
170
  const { GenDescFile } = f.runtime.codegen;
171
171
  const fileDesc = f.importDesc(file);
172
172
  generateDescDoc(f, file);
173
- f.print(f.exportDecl("declare const", fileDesc.name), ": ", GenDescFile, ";");
173
+ f.print(f.export("declare const", fileDesc.name), ": ", GenDescFile, ";");
174
174
  f.print();
175
175
  for (const desc of schema.typesInFile(file)) {
176
176
  switch (desc.kind) {
@@ -180,7 +180,7 @@ function generateDts(schema) {
180
180
  const MessageShape = f.importShape(desc);
181
181
  const name = f.importDesc(desc).name;
182
182
  generateDescDoc(f, desc);
183
- f.print(f.exportDecl("declare const", name), ": ", GenDescMessage, "<", MessageShape, ">", ";");
183
+ f.print(f.export("declare const", name), ": ", GenDescMessage, "<", MessageShape, ">", ";");
184
184
  f.print();
185
185
  break;
186
186
  }
@@ -190,7 +190,7 @@ function generateDts(schema) {
190
190
  const EnumShape = f.importShape(desc);
191
191
  generateDescDoc(f, desc);
192
192
  const name = f.importDesc(desc).name;
193
- f.print(f.exportDecl("declare const", name), ": ", GenDescEnum, "<", EnumShape, ">;");
193
+ f.print(f.export("declare const", name), ": ", GenDescEnum, "<", EnumShape, ">;");
194
194
  f.print();
195
195
  break;
196
196
  }
@@ -200,7 +200,7 @@ function generateDts(schema) {
200
200
  const E = f.importShape(desc.extendee);
201
201
  const V = (0, util_1.fieldTypeScriptType)(desc).typing;
202
202
  f.print(f.jsDoc(desc));
203
- f.print(f.exportDecl("declare const", name), ": ", GenDescExtension, "<", E, ", ", V, ">;");
203
+ f.print(f.export("declare const", name), ": ", GenDescExtension, "<", E, ", ", V, ">;");
204
204
  f.print();
205
205
  break;
206
206
  }
@@ -208,7 +208,7 @@ function generateDts(schema) {
208
208
  const { GenDescService } = f.runtime.codegen;
209
209
  const name = f.importDesc(desc).name;
210
210
  f.print(f.jsDoc(desc));
211
- f.print(f.exportDecl("declare const", name), ": ", GenDescService, "<", getServiceShapeExpr(f, desc), ">;");
211
+ f.print(f.export("declare const", name), ": ", GenDescService, "<", getServiceShapeExpr(f, desc), ">;");
212
212
  f.print();
213
213
  break;
214
214
  }
@@ -277,9 +277,9 @@ function getServiceShapeExpr(f, service) {
277
277
  for (const method of service.methods) {
278
278
  print(f.jsDoc(method, " "));
279
279
  print(" ", method.localName, ": {");
280
- print(" kind: ", f.string(method.methodKind), ";");
281
- print(" I: ", f.importShape(method.input), ";");
282
- print(" O: ", f.importShape(method.output), ";");
280
+ print(" methodKind: ", f.string(method.methodKind), ";");
281
+ print(" input: typeof ", f.importDesc(method.input, true), ";");
282
+ print(" output: typeof ", f.importDesc(method.output, true), ";");
283
283
  print(" },");
284
284
  }
285
285
  print("}");
@@ -288,7 +288,7 @@ function getServiceShapeExpr(f, service) {
288
288
  // prettier-ignore
289
289
  function generateEnumShape(f, enumeration) {
290
290
  f.print(f.jsDoc(enumeration));
291
- f.print(f.exportDecl("enum", f.importShape(enumeration).name), " {");
291
+ f.print(f.export("enum", f.importShape(enumeration).name), " {");
292
292
  for (const value of enumeration.values) {
293
293
  if (enumeration.values.indexOf(value) > 0) {
294
294
  f.print();
@@ -304,7 +304,7 @@ function generateMessageShape(f, message, target) {
304
304
  const { Message } = f.runtime;
305
305
  const declaration = target == "ts" ? "type" : "declare type";
306
306
  f.print(f.jsDoc(message));
307
- f.print(f.exportDecl(declaration, f.importShape(message).name), " = ", Message, "<", f.string(message.typeName), "> & {");
307
+ f.print(f.export(declaration, f.importShape(message).name), " = ", Message, "<", f.string(message.typeName), "> & {");
308
308
  for (const member of message.members) {
309
309
  switch (member.kind) {
310
310
  case "oneof":
@@ -14,20 +14,21 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.arrayLiteral = exports.functionCall = exports.fieldTypeScriptType = void 0;
17
- const reflect_1 = require("@bufbuild/protobuf/reflect");
17
+ const protobuf_1 = require("@bufbuild/protobuf");
18
+ const codegenv1_1 = require("@bufbuild/protobuf/codegenv1");
18
19
  const wkt_1 = require("@bufbuild/protobuf/wkt");
19
20
  function fieldTypeScriptType(field) {
20
21
  const typing = [];
21
22
  let optional = false;
22
23
  switch (field.fieldKind) {
23
24
  case "scalar":
24
- typing.push((0, reflect_1.scalarTypeScriptType)(field.scalar, field.longType));
25
+ typing.push((0, codegenv1_1.scalarTypeScriptType)(field.scalar, field.longAsString));
25
26
  optional = field.proto.proto3Optional;
26
27
  break;
27
28
  case "message": {
28
29
  if (!field.oneof && (0, wkt_1.isWrapperDesc)(field.message)) {
29
30
  const baseType = field.message.fields[0].scalar;
30
- typing.push((0, reflect_1.scalarTypeScriptType)(baseType, reflect_1.LongType.BIGINT));
31
+ typing.push((0, codegenv1_1.scalarTypeScriptType)(baseType, false));
31
32
  }
32
33
  else {
33
34
  typing.push({
@@ -55,7 +56,7 @@ function fieldTypeScriptType(field) {
55
56
  }, "[]");
56
57
  break;
57
58
  case "scalar":
58
- typing.push((0, reflect_1.scalarTypeScriptType)(field.scalar, field.longType), "[]");
59
+ typing.push((0, codegenv1_1.scalarTypeScriptType)(field.scalar, field.longAsString), "[]");
59
60
  break;
60
61
  case "message": {
61
62
  typing.push({
@@ -69,11 +70,11 @@ function fieldTypeScriptType(field) {
69
70
  case "map": {
70
71
  let keyType;
71
72
  switch (field.mapKey) {
72
- case reflect_1.ScalarType.INT32:
73
- case reflect_1.ScalarType.FIXED32:
74
- case reflect_1.ScalarType.UINT32:
75
- case reflect_1.ScalarType.SFIXED32:
76
- case reflect_1.ScalarType.SINT32:
73
+ case protobuf_1.ScalarType.INT32:
74
+ case protobuf_1.ScalarType.FIXED32:
75
+ case protobuf_1.ScalarType.UINT32:
76
+ case protobuf_1.ScalarType.SFIXED32:
77
+ case protobuf_1.ScalarType.SINT32:
77
78
  keyType = "number";
78
79
  break;
79
80
  default:
@@ -83,7 +84,7 @@ function fieldTypeScriptType(field) {
83
84
  let valueType;
84
85
  switch (field.mapKind) {
85
86
  case "scalar":
86
- valueType = (0, reflect_1.scalarTypeScriptType)(field.scalar, reflect_1.LongType.BIGINT);
87
+ valueType = (0, codegenv1_1.scalarTypeScriptType)(field.scalar, false);
87
88
  break;
88
89
  case "message":
89
90
  valueType = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protoc-gen-es",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.3",
4
4
  "description": "Protocol Buffers code generator for ECMAScript",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -20,11 +20,11 @@
20
20
  },
21
21
  "preferUnplugged": true,
22
22
  "dependencies": {
23
- "@bufbuild/protobuf": "^2.0.0-alpha.2",
24
- "@bufbuild/protoplugin": "2.0.0-alpha.2"
23
+ "@bufbuild/protobuf": "^2.0.0-alpha.3",
24
+ "@bufbuild/protoplugin": "2.0.0-alpha.3"
25
25
  },
26
26
  "peerDependencies": {
27
- "@bufbuild/protobuf": "2.0.0-alpha.2"
27
+ "@bufbuild/protobuf": "2.0.0-alpha.3"
28
28
  },
29
29
  "peerDependenciesMeta": {
30
30
  "@bufbuild/protobuf": {