@bufbuild/protoc-gen-es 1.6.0 → 1.7.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protoc-gen-es",
3
- "version": "1.6.0",
3
+ "version": "1.7.1",
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": "^1.6.0",
24
- "@bufbuild/protoplugin": "1.6.0"
23
+ "@bufbuild/protobuf": "^1.7.1",
24
+ "@bufbuild/protoplugin": "1.7.1"
25
25
  },
26
26
  "peerDependencies": {
27
- "@bufbuild/protobuf": "1.6.0"
27
+ "@bufbuild/protobuf": "1.7.1"
28
28
  },
29
29
  "peerDependenciesMeta": {
30
30
  "@bufbuild/protobuf": {
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -26,7 +26,10 @@ function generateDts(schema) {
26
26
  for (const message of file.messages) {
27
27
  generateMessage(schema, f, message);
28
28
  }
29
- // We do not generate anything for services, and we do not support extensions at this time
29
+ for (const extension of file.extensions) {
30
+ generateExtension(schema, f, extension);
31
+ }
32
+ // We do not generate anything for services
30
33
  }
31
34
  }
32
35
  exports.generateDts = generateDts;
@@ -86,7 +89,9 @@ function generateMessage(schema, f, message) {
86
89
  for (const nestedMessage of message.nestedMessages) {
87
90
  generateMessage(schema, f, nestedMessage);
88
91
  }
89
- // We do not support extensions at this time
92
+ for (const nestedExtension of message.nestedExtensions) {
93
+ generateExtension(schema, f, nestedExtension);
94
+ }
90
95
  }
91
96
  // prettier-ignore
92
97
  function generateOneof(schema, f, oneof) {
@@ -118,6 +123,13 @@ function generateField(schema, f, field) {
118
123
  f.print(e);
119
124
  }
120
125
  // prettier-ignore
126
+ function generateExtension(schema, f, ext) {
127
+ const { typing } = (0, ecmascript_1.getFieldTyping)(ext, f);
128
+ f.print(f.jsDoc(ext));
129
+ f.print(f.exportDecl("declare const", ext), ": ", schema.runtime.Extension, "<", ext.extendee, ", ", typing, ">;");
130
+ f.print();
131
+ }
132
+ // prettier-ignore
121
133
  function generateWktMethods(schema, f, message) {
122
134
  const ref = (0, ecmascript_1.reifyWkt)(message);
123
135
  if (ref === undefined) {
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.generateFieldInfo = exports.generateJs = void 0;
16
+ exports.getFieldInfoLiteral = exports.generateFieldInfo = exports.generateJs = void 0;
17
17
  const protobuf_1 = require("@bufbuild/protobuf");
18
18
  const ecmascript_1 = require("@bufbuild/protoplugin/ecmascript");
19
19
  const editions_js_1 = require("./editions.js");
@@ -27,7 +27,10 @@ function generateJs(schema) {
27
27
  for (const message of file.messages) {
28
28
  generateMessage(schema, f, message);
29
29
  }
30
- // We do not generate anything for services, and we do not support extensions at this time
30
+ for (const extension of file.extensions) {
31
+ generateExtension(schema, f, extension);
32
+ }
33
+ // We do not generate anything for services
31
34
  }
32
35
  }
33
36
  exports.generateJs = generateJs;
@@ -86,15 +89,25 @@ function generateMessage(schema, f, message) {
86
89
  for (const nestedMessage of message.nestedMessages) {
87
90
  generateMessage(schema, f, nestedMessage);
88
91
  }
89
- // We do not support extensions at this time
92
+ for (const nestedExtension of message.nestedExtensions) {
93
+ generateExtension(schema, f, nestedExtension);
94
+ }
90
95
  }
91
96
  // prettier-ignore
92
97
  function generateFieldInfo(schema, f, field) {
93
- const protoN = (0, editions_js_1.getNonEditionRuntime)(schema, field.parent.file);
98
+ f.print(" ", getFieldInfoLiteral(schema, field), ",");
99
+ }
100
+ exports.generateFieldInfo = generateFieldInfo;
101
+ // prettier-ignore
102
+ function getFieldInfoLiteral(schema, field) {
103
+ const protoN = (0, editions_js_1.getNonEditionRuntime)(schema, field.kind == "extension" ? field.file : field.parent.file);
94
104
  const e = [];
95
- e.push(" { no: ", field.number, `, name: "`, field.name, `", `);
96
- if (field.jsonName !== undefined) {
97
- e.push(`jsonName: "`, field.jsonName, `", `);
105
+ e.push("{ no: ", field.number, `, `);
106
+ if (field.kind == "field") {
107
+ e.push(`name: "`, field.name, `", `);
108
+ if (field.jsonName !== undefined) {
109
+ e.push(`jsonName: "`, field.jsonName, `", `);
110
+ }
98
111
  }
99
112
  switch (field.fieldKind) {
100
113
  case "scalar":
@@ -147,10 +160,26 @@ function generateFieldInfo(schema, f, field) {
147
160
  if (typeof lastE == "string" && lastE.endsWith(", ")) {
148
161
  e[e.length - 1] = lastE.substring(0, lastE.length - 2);
149
162
  }
150
- e.push(" },");
151
- f.print(...e);
163
+ e.push(" }");
164
+ return e;
165
+ }
166
+ exports.getFieldInfoLiteral = getFieldInfoLiteral;
167
+ // prettier-ignore
168
+ function generateExtension(schema, f, ext) {
169
+ const protoN = (0, editions_js_1.getNonEditionRuntime)(schema, ext.file);
170
+ f.print(f.jsDoc(ext));
171
+ f.print(f.exportDecl("const", ext), " = ", protoN, ".makeExtension(");
172
+ f.print(" ", f.string(ext.typeName), ", ");
173
+ f.print(" ", ext.extendee, ", ");
174
+ if (ext.fieldKind == "scalar") {
175
+ f.print(" ", getFieldInfoLiteral(schema, ext), ",");
176
+ }
177
+ else {
178
+ f.print(" () => (", getFieldInfoLiteral(schema, ext), "),");
179
+ }
180
+ f.print(");");
181
+ f.print();
152
182
  }
153
- exports.generateFieldInfo = generateFieldInfo;
154
183
  // prettier-ignore
155
184
  function generateWktMethods(schema, f, message) {
156
185
  var _a;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -28,7 +28,10 @@ function generateTs(schema) {
28
28
  for (const message of file.messages) {
29
29
  generateMessage(schema, f, message);
30
30
  }
31
- // We do not generate anything for services, and we do not support extensions at this time
31
+ for (const extension of file.extensions) {
32
+ generateExtension(schema, f, extension);
33
+ }
34
+ // We do not generate anything for services
32
35
  }
33
36
  }
34
37
  exports.generateTs = generateTs;
@@ -110,7 +113,9 @@ function generateMessage(schema, f, message) {
110
113
  for (const nestedMessage of message.nestedMessages) {
111
114
  generateMessage(schema, f, nestedMessage);
112
115
  }
113
- // We do not support extensions at this time
116
+ for (const nestedExtension of message.nestedExtensions) {
117
+ generateExtension(schema, f, nestedExtension);
118
+ }
114
119
  }
115
120
  // prettier-ignore
116
121
  function generateOneof(schema, f, oneof) {
@@ -146,6 +151,23 @@ function generateField(schema, f, field) {
146
151
  f.print(e);
147
152
  }
148
153
  // prettier-ignore
154
+ function generateExtension(schema, f, ext) {
155
+ const protoN = (0, editions_js_1.getNonEditionRuntime)(schema, ext.file);
156
+ const { typing } = (0, ecmascript_1.getFieldTyping)(ext, f);
157
+ f.print(f.jsDoc(ext));
158
+ f.print(f.exportDecl("const", ext), " = ", protoN, ".makeExtension<", ext.extendee, ", ", typing, ">(");
159
+ f.print(" ", f.string(ext.typeName), ", ");
160
+ f.print(" ", ext.extendee, ", ");
161
+ if (ext.fieldKind == "scalar") {
162
+ f.print(" ", (0, javascript_js_1.getFieldInfoLiteral)(schema, ext), ",");
163
+ }
164
+ else {
165
+ f.print(" () => (", (0, javascript_js_1.getFieldInfoLiteral)(schema, ext), "),");
166
+ }
167
+ f.print(");");
168
+ f.print();
169
+ }
170
+ // prettier-ignore
149
171
  function generateWktMethods(schema, f, message) {
150
172
  var _a;
151
173
  const ref = (0, ecmascript_1.reifyWkt)(message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protoc-gen-es",
3
- "version": "1.6.0",
3
+ "version": "1.7.1",
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": "^1.6.0",
24
- "@bufbuild/protoplugin": "1.6.0"
23
+ "@bufbuild/protobuf": "^1.7.1",
24
+ "@bufbuild/protoplugin": "1.7.1"
25
25
  },
26
26
  "peerDependencies": {
27
- "@bufbuild/protobuf": "1.6.0"
27
+ "@bufbuild/protobuf": "1.7.1"
28
28
  },
29
29
  "peerDependenciesMeta": {
30
30
  "@bufbuild/protobuf": {
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ import type {
18
18
  DescMessage,
19
19
  DescOneof,
20
20
  } from "@bufbuild/protobuf";
21
+ import { DescExtension } from "@bufbuild/protobuf";
21
22
  import type {
22
23
  GeneratedFile,
23
24
  Printable,
@@ -40,7 +41,10 @@ export function generateDts(schema: Schema) {
40
41
  for (const message of file.messages) {
41
42
  generateMessage(schema, f, message);
42
43
  }
43
- // We do not generate anything for services, and we do not support extensions at this time
44
+ for (const extension of file.extensions) {
45
+ generateExtension(schema, f, extension);
46
+ }
47
+ // We do not generate anything for services
44
48
  }
45
49
  }
46
50
 
@@ -109,7 +113,9 @@ function generateMessage(schema: Schema, f: GeneratedFile, message: DescMessage)
109
113
  for (const nestedMessage of message.nestedMessages) {
110
114
  generateMessage(schema, f, nestedMessage);
111
115
  }
112
- // We do not support extensions at this time
116
+ for (const nestedExtension of message.nestedExtensions) {
117
+ generateExtension(schema, f, nestedExtension);
118
+ }
113
119
  }
114
120
 
115
121
  // prettier-ignore
@@ -142,6 +148,18 @@ function generateField(schema: Schema, f: GeneratedFile, field: DescField) {
142
148
  f.print(e);
143
149
  }
144
150
 
151
+ // prettier-ignore
152
+ function generateExtension(
153
+ schema: Schema,
154
+ f: GeneratedFile,
155
+ ext: DescExtension,
156
+ ) {
157
+ const { typing } = getFieldTyping(ext, f);
158
+ f.print(f.jsDoc(ext));
159
+ f.print(f.exportDecl("declare const", ext), ": ", schema.runtime.Extension, "<", ext.extendee, ", ", typing, ">;");
160
+ f.print();
161
+ }
162
+
145
163
  // prettier-ignore
146
164
  function generateWktMethods(schema: Schema, f: GeneratedFile, message: DescMessage) {
147
165
  const ref = reifyWkt(message);
package/src/editions.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
package/src/javascript.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -12,7 +12,12 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
 
15
- import type { DescEnum, DescField, DescMessage } from "@bufbuild/protobuf";
15
+ import type {
16
+ DescEnum,
17
+ DescExtension,
18
+ DescField,
19
+ DescMessage,
20
+ } from "@bufbuild/protobuf";
16
21
  import {
17
22
  FieldDescriptorProto_Type,
18
23
  LongType,
@@ -42,7 +47,10 @@ export function generateJs(schema: Schema) {
42
47
  for (const message of file.messages) {
43
48
  generateMessage(schema, f, message);
44
49
  }
45
- // We do not generate anything for services, and we do not support extensions at this time
50
+ for (const extension of file.extensions) {
51
+ generateExtension(schema, f, extension);
52
+ }
53
+ // We do not generate anything for services
46
54
  }
47
55
  }
48
56
 
@@ -100,22 +108,32 @@ function generateMessage(schema: Schema, f: GeneratedFile, message: DescMessage)
100
108
  for (const nestedMessage of message.nestedMessages) {
101
109
  generateMessage(schema, f, nestedMessage);
102
110
  }
103
- // We do not support extensions at this time
111
+ for (const nestedExtension of message.nestedExtensions) {
112
+ generateExtension(schema, f, nestedExtension);
113
+ }
114
+ }
115
+
116
+ // prettier-ignore
117
+ export function generateFieldInfo(schema: Schema, f: GeneratedFile, field: DescField | DescExtension) {
118
+ f.print(" ", getFieldInfoLiteral(schema, field), ",");
104
119
  }
105
120
 
106
121
  // prettier-ignore
107
- export function generateFieldInfo(schema: Schema, f: GeneratedFile, field: DescField) {
108
- const protoN = getNonEditionRuntime(schema, field.parent.file);
122
+ export function getFieldInfoLiteral(schema: Schema, field: DescField | DescExtension): Printable {
123
+ const protoN = getNonEditionRuntime(schema, field.kind == "extension" ? field.file : field.parent.file);
109
124
  const e: Printable = [];
110
- e.push(" { no: ", field.number, `, name: "`, field.name, `", `);
111
- if (field.jsonName !== undefined) {
112
- e.push(`jsonName: "`, field.jsonName, `", `);
125
+ e.push("{ no: ", field.number, `, `);
126
+ if (field.kind == "field") {
127
+ e.push(`name: "`, field.name, `", `);
128
+ if (field.jsonName !== undefined) {
129
+ e.push(`jsonName: "`, field.jsonName, `", `);
130
+ }
113
131
  }
114
132
  switch (field.fieldKind) {
115
133
  case "scalar":
116
134
  e.push(`kind: "scalar", T: `, field.scalar, ` /* ScalarType.`, ScalarType[field.scalar], ` */, `);
117
135
  if (field.longType != LongType.BIGINT) {
118
- e.push(`L: `, field.longType, ` /* LongType.`, LongType[field.longType], ` */, `);
136
+ e.push(`L: `, field.longType, ` /* LongType.`, LongType[field.longType], ` */, `);
119
137
  }
120
138
  break;
121
139
  case "map":
@@ -162,8 +180,28 @@ export function generateFieldInfo(schema: Schema, f: GeneratedFile, field: DescF
162
180
  if (typeof lastE == "string" && lastE.endsWith(", ")) {
163
181
  e[e.length - 1] = lastE.substring(0, lastE.length - 2);
164
182
  }
165
- e.push(" },");
166
- f.print(...e);
183
+ e.push(" }");
184
+ return e;
185
+ }
186
+
187
+ // prettier-ignore
188
+ function generateExtension(
189
+ schema: Schema,
190
+ f: GeneratedFile,
191
+ ext: DescExtension,
192
+ ) {
193
+ const protoN = getNonEditionRuntime(schema, ext.file);
194
+ f.print(f.jsDoc(ext));
195
+ f.print(f.exportDecl("const", ext), " = ", protoN, ".makeExtension(");
196
+ f.print(" ", f.string(ext.typeName), ", ");
197
+ f.print(" ", ext.extendee, ", ");
198
+ if (ext.fieldKind == "scalar") {
199
+ f.print(" ", getFieldInfoLiteral(schema, ext), ",");
200
+ } else {
201
+ f.print(" () => (", getFieldInfoLiteral(schema, ext), "),");
202
+ }
203
+ f.print(");");
204
+ f.print();
167
205
  }
168
206
 
169
207
  // prettier-ignore
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
package/src/typescript.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -14,6 +14,7 @@
14
14
 
15
15
  import type {
16
16
  DescEnum,
17
+ DescExtension,
17
18
  DescField,
18
19
  DescMessage,
19
20
  DescOneof,
@@ -30,7 +31,7 @@ import {
30
31
  localName,
31
32
  reifyWkt,
32
33
  } from "@bufbuild/protoplugin/ecmascript";
33
- import { generateFieldInfo } from "./javascript.js";
34
+ import { generateFieldInfo, getFieldInfoLiteral } from "./javascript.js";
34
35
  import { getNonEditionRuntime } from "./editions.js";
35
36
 
36
37
  export function generateTs(schema: Schema) {
@@ -43,7 +44,10 @@ export function generateTs(schema: Schema) {
43
44
  for (const message of file.messages) {
44
45
  generateMessage(schema, f, message);
45
46
  }
46
- // We do not generate anything for services, and we do not support extensions at this time
47
+ for (const extension of file.extensions) {
48
+ generateExtension(schema, f, extension);
49
+ }
50
+ // We do not generate anything for services
47
51
  }
48
52
  }
49
53
 
@@ -134,7 +138,9 @@ function generateMessage(schema: Schema, f: GeneratedFile, message: DescMessage)
134
138
  for (const nestedMessage of message.nestedMessages) {
135
139
  generateMessage(schema, f, nestedMessage);
136
140
  }
137
- // We do not support extensions at this time
141
+ for (const nestedExtension of message.nestedExtensions) {
142
+ generateExtension(schema, f, nestedExtension);
143
+ }
138
144
  }
139
145
 
140
146
  // prettier-ignore
@@ -172,6 +178,27 @@ function generateField(schema: Schema, f: GeneratedFile, field: DescField) {
172
178
  f.print(e);
173
179
  }
174
180
 
181
+ // prettier-ignore
182
+ function generateExtension(
183
+ schema: Schema,
184
+ f: GeneratedFile,
185
+ ext: DescExtension,
186
+ ) {
187
+ const protoN = getNonEditionRuntime(schema, ext.file);
188
+ const { typing } = getFieldTyping(ext, f);
189
+ f.print(f.jsDoc(ext));
190
+ f.print(f.exportDecl("const", ext), " = ", protoN, ".makeExtension<", ext.extendee, ", ", typing, ">(");
191
+ f.print(" ", f.string(ext.typeName), ", ");
192
+ f.print(" ", ext.extendee, ", ");
193
+ if (ext.fieldKind == "scalar") {
194
+ f.print(" ", getFieldInfoLiteral(schema, ext), ",");
195
+ } else {
196
+ f.print(" () => (", getFieldInfoLiteral(schema, ext), "),");
197
+ }
198
+ f.print(");");
199
+ f.print();
200
+ }
201
+
175
202
  // prettier-ignore
176
203
  function generateWktMethods(schema: Schema, f: GeneratedFile, message: DescMessage) {
177
204
  const ref = reifyWkt(message);