@bufbuild/protoc-gen-es 2.0.0-beta.2 → 2.0.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.
- package/README.md +46 -64
- package/dist/cjs/package.json +12 -5
- package/dist/cjs/src/protoc-gen-es-plugin.js +33 -37
- package/dist/cjs/src/util.d.ts +0 -1
- package/dist/cjs/src/util.js +3 -8
- package/package.json +12 -5
package/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# @bufbuild/protoc-gen-es
|
|
2
2
|
|
|
3
|
-
The code generator plugin for Protocol Buffers for ECMAScript. Learn more about the project at
|
|
3
|
+
The code generator plugin for Protocol Buffers for ECMAScript. Learn more about the project at
|
|
4
|
+
[github.com/bufbuild/protobuf-es](https://github.com/bufbuild/protobuf-es).
|
|
4
5
|
|
|
5
6
|
## Installation
|
|
6
7
|
|
|
7
|
-
`protoc-gen-es` generates base types
|
|
8
|
-
schema. The generated code requires the runtime library [@bufbuild/protobuf](https://www.npmjs.com/package/@bufbuild/protobuf).
|
|
8
|
+
`protoc-gen-es` generates base types—messages and enumerations—from your Protocol Buffer
|
|
9
|
+
schema. The generated code requires the runtime library [@bufbuild/protobuf](https://www.npmjs.com/package/@bufbuild/protobuf).
|
|
10
|
+
It's compatible with Protocol Buffer compilers like [buf](https://github.com/bufbuild/buf) and [protoc](https://github.com/protocolbuffers/protobuf/releases).
|
|
9
11
|
|
|
10
12
|
To install the plugin and the runtime library, run:
|
|
11
13
|
|
|
@@ -14,8 +16,8 @@ npm install --save-dev @bufbuild/protoc-gen-es
|
|
|
14
16
|
npm install @bufbuild/protobuf
|
|
15
17
|
```
|
|
16
18
|
|
|
17
|
-
We use peer dependencies to ensure that code generator and runtime library are
|
|
18
|
-
compatible with each other. Note that npm installs them automatically, but
|
|
19
|
+
We use peer dependencies to ensure that the code generator and runtime library are
|
|
20
|
+
compatible with each other. Note that npm installs them automatically, but Yarn
|
|
19
21
|
and pnpm do not.
|
|
20
22
|
|
|
21
23
|
## Generating code
|
|
@@ -26,31 +28,30 @@ and pnpm do not.
|
|
|
26
28
|
npm install --save-dev @bufbuild/buf
|
|
27
29
|
```
|
|
28
30
|
|
|
29
|
-
Add a new
|
|
31
|
+
Add a new `buf.gen.yaml` configuration file:
|
|
30
32
|
|
|
31
33
|
```yaml
|
|
32
|
-
# buf.gen
|
|
33
|
-
|
|
34
|
-
version: v1
|
|
34
|
+
# Learn more: https://buf.build/docs/configuration/v2/buf-gen-yaml
|
|
35
|
+
version: v2
|
|
35
36
|
plugins:
|
|
36
37
|
# This will invoke protoc-gen-es and write output to src/gen
|
|
37
|
-
-
|
|
38
|
+
- local: protoc-gen-es
|
|
38
39
|
out: src/gen
|
|
39
40
|
opt:
|
|
40
41
|
# Add more plugin options here
|
|
41
42
|
- target=ts
|
|
42
43
|
```
|
|
43
44
|
|
|
44
|
-
To generate code for all
|
|
45
|
+
To generate code for all Protobuf files within your project, run:
|
|
45
46
|
|
|
46
47
|
```bash
|
|
47
48
|
npx buf generate
|
|
48
49
|
```
|
|
49
50
|
|
|
50
|
-
Note that `buf` can generate from various [inputs](https://
|
|
51
|
-
not just local
|
|
51
|
+
Note that `buf` can generate from various [inputs](https://buf.build/docs/reference/inputs),
|
|
52
|
+
not just local Protobuf files.
|
|
52
53
|
|
|
53
|
-
### With protoc
|
|
54
|
+
### With `protoc`
|
|
54
55
|
|
|
55
56
|
```bash
|
|
56
57
|
PATH=$PATH:$(pwd)/node_modules/.bin \
|
|
@@ -60,13 +61,13 @@ PATH=$PATH:$(pwd)/node_modules/.bin \
|
|
|
60
61
|
a.proto b.proto c.proto
|
|
61
62
|
```
|
|
62
63
|
|
|
63
|
-
Note that
|
|
64
|
-
|
|
64
|
+
Note that `node_modules/.bin` needs to be added to the `$PATH` so that the Protobuf compiler can find the plugin. This
|
|
65
|
+
happens automatically with npm scripts.
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
If you use Yarn, versions v2 and above don't use a `node_modules` directory, so you need to change the variable a
|
|
68
|
+
bit:
|
|
68
69
|
|
|
69
|
-
```
|
|
70
|
+
```shellsession
|
|
70
71
|
PATH=$(dirname $(yarn bin protoc-gen-es)):$PATH
|
|
71
72
|
```
|
|
72
73
|
|
|
@@ -74,69 +75,50 @@ PATH=$(dirname $(yarn bin protoc-gen-es)):$PATH
|
|
|
74
75
|
|
|
75
76
|
### `target`
|
|
76
77
|
|
|
77
|
-
This option controls whether the plugin generates JavaScript, TypeScript,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
Possible values:
|
|
78
|
+
This option controls whether the plugin generates JavaScript, TypeScript, or TypeScript declaration files. Possible
|
|
79
|
+
values:
|
|
81
80
|
|
|
82
|
-
- `target=js
|
|
83
|
-
- `target=ts
|
|
84
|
-
- `target=dts
|
|
81
|
+
- `target=js`: Generates a `_pb.js` file for every `.proto` input file.
|
|
82
|
+
- `target=ts`: Generates a `_pb.ts` file for every `.proto` input file.
|
|
83
|
+
- `target=dts`: Generates a `_pb.d.ts` file for every `.proto` input file.
|
|
85
84
|
|
|
86
|
-
|
|
87
|
-
`target=js+dts`.
|
|
85
|
+
You can pass multiple values by separating them with `+`—for example, `target=js+dts`.
|
|
88
86
|
|
|
89
|
-
By default,
|
|
90
|
-
|
|
91
|
-
bundler configurations. If you prefer to generate TypeScript, use `target=ts`.
|
|
87
|
+
By default, it generates JavaScript and TypeScript declaration files, which produces the smallest code size and is the
|
|
88
|
+
most compatible with various bundler configurations. If you prefer to generate TypeScript, use `target=ts`.
|
|
92
89
|
|
|
93
90
|
### `import_extension`
|
|
94
91
|
|
|
95
|
-
By default,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
Some environments require an import extension. For example, using [ECMAScript modules in Node.js](https://www.typescriptlang.org/docs/handbook/esm-node.html) requires the `.js` extension, and Deno requires `.ts`. With this plugin option, you can add `.js`/`.ts` extensions
|
|
100
|
-
in import paths with the given value. For example, set
|
|
92
|
+
By default, `protoc-gen-es` doesn't add file extensions to import paths. However, some
|
|
93
|
+
environments require an import extension. For example, using ECMAScript modules in Node.js
|
|
94
|
+
requires the `.js` extension, and Deno requires `.ts`. With this plugin option, you can add `.js`/`.ts` extensions in
|
|
95
|
+
import paths with the given value. Possible values:
|
|
101
96
|
|
|
102
|
-
- `import_extension
|
|
103
|
-
- `import_extension
|
|
104
|
-
- `import_extension=
|
|
97
|
+
- `import_extension=none`: Doesn't add an extension. (Default)
|
|
98
|
+
- `import_extension=js`: Adds the `.js` extension.
|
|
99
|
+
- `import_extension=ts`. Adds the `.ts` extension.
|
|
105
100
|
|
|
106
101
|
### `js_import_style`
|
|
107
102
|
|
|
108
|
-
By default,
|
|
109
|
-
|
|
110
|
-
generate ECMAScript `import` and `export` statements. For use cases where
|
|
111
|
-
CommonJS is difficult to avoid, this option can be used to generate CommonJS
|
|
112
|
-
`require()` calls.
|
|
103
|
+
By default, `protoc-gen-es` generates ECMAScript `import` and `export` statements. For use cases where CommonJS is
|
|
104
|
+
difficult to avoid, this option can be used to generate CommonJS `require()` calls. Possible values:
|
|
113
105
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
- `js_import_style=module` generate ECMAScript `import` / `export` statements -
|
|
117
|
-
the default behavior.
|
|
118
|
-
- `js_import_style=legacy_commonjs` generate CommonJS `require()` calls.
|
|
106
|
+
- `js_import_style=module`: Generates ECMAScript `import`/`export` statements. (Default)
|
|
107
|
+
- `js_import_style=legacy_commonjs`: Generates CommonJS `require()` calls.
|
|
119
108
|
|
|
120
109
|
### `keep_empty_files=true`
|
|
121
110
|
|
|
122
|
-
By default,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
empty files, to allow for smooth interoperation with Bazel and similar
|
|
126
|
-
tooling that requires all output files to be declared ahead of time.
|
|
127
|
-
Unless you use Bazel, it is very unlikely that you need this option.
|
|
111
|
+
By default, `protoc-gen-es` omits empty files from the plugin output. This option disables pruning of empty files to
|
|
112
|
+
allow for smooth interoperation with Bazel and similar tooling that requires all output files to be declared ahead of
|
|
113
|
+
time. Unless you use Bazel, you probably don't need this option.
|
|
128
114
|
|
|
129
115
|
### `ts_nocheck=true`
|
|
130
116
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
settings.
|
|
134
|
-
|
|
135
|
-
In case you use compiler settings that yield an error for generated code, you
|
|
136
|
-
can set the plugin option `ts_nocheck=true`. This will generate an annotation at
|
|
117
|
+
`protoc-gen-es` generates valid TypeScript for current versions of the TypeScript compiler with standard settings.
|
|
118
|
+
If you use compiler settings that yield an error for generated code, setting this option generates an annotation at
|
|
137
119
|
the top of each file to skip type checks: `// @ts-nocheck`.
|
|
138
120
|
|
|
139
121
|
### `json_types=true`
|
|
140
122
|
|
|
141
|
-
Generates JSON types for every Protobuf message and enumeration. Calling `toJson()`
|
|
142
|
-
|
|
123
|
+
Generates JSON types for every Protobuf message and enumeration. Calling `toJson()` automatically returns the JSON type
|
|
124
|
+
if available. Learn more about [JSON types](https://github.com/bufbuild/protobuf-es/blob/main/MANUAL.md#json-types).
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoc-gen-es",
|
|
3
|
-
"version": "2.0.0
|
|
4
|
-
"description": "Protocol Buffers code generator for ECMAScript",
|
|
3
|
+
"version": "2.0.0",
|
|
5
4
|
"license": "Apache-2.0",
|
|
5
|
+
"description": "Protocol Buffers code generator for ECMAScript",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"protobuf",
|
|
8
|
+
"schema",
|
|
9
|
+
"typescript",
|
|
10
|
+
"ecmascript",
|
|
11
|
+
"protoc-plugin"
|
|
12
|
+
],
|
|
6
13
|
"repository": {
|
|
7
14
|
"type": "git",
|
|
8
15
|
"url": "https://github.com/bufbuild/protobuf-es.git",
|
|
@@ -23,11 +30,11 @@
|
|
|
23
30
|
},
|
|
24
31
|
"preferUnplugged": true,
|
|
25
32
|
"dependencies": {
|
|
26
|
-
"@bufbuild/protobuf": "^2.0.0
|
|
27
|
-
"@bufbuild/protoplugin": "2.0.0
|
|
33
|
+
"@bufbuild/protobuf": "^2.0.0",
|
|
34
|
+
"@bufbuild/protoplugin": "2.0.0"
|
|
28
35
|
},
|
|
29
36
|
"peerDependencies": {
|
|
30
|
-
"@bufbuild/protobuf": "2.0.0
|
|
37
|
+
"@bufbuild/protobuf": "2.0.0"
|
|
31
38
|
},
|
|
32
39
|
"peerDependenciesMeta": {
|
|
33
40
|
"@bufbuild/protobuf": {
|
|
@@ -54,10 +54,10 @@ function generateTs(schema) {
|
|
|
54
54
|
for (const file of schema.files) {
|
|
55
55
|
const f = schema.generateFile(file.name + "_pb.ts");
|
|
56
56
|
f.preamble(file);
|
|
57
|
-
const {
|
|
57
|
+
const { GenFile } = f.runtime.codegen;
|
|
58
58
|
const fileDesc = f.importSchema(file);
|
|
59
59
|
generateDescDoc(f, file);
|
|
60
|
-
f.print(f.export("const", fileDesc.name), ": ",
|
|
60
|
+
f.print(f.export("const", fileDesc.name), ": ", GenFile, " = ", pure);
|
|
61
61
|
f.print(" ", getFileDescCall(f, file, schema), ";");
|
|
62
62
|
f.print();
|
|
63
63
|
for (const desc of schema.typesInFile(file)) {
|
|
@@ -70,13 +70,13 @@ function generateTs(schema) {
|
|
|
70
70
|
generateDescDoc(f, desc);
|
|
71
71
|
const name = f.importSchema(desc).name;
|
|
72
72
|
const Shape = f.importShape(desc);
|
|
73
|
-
const {
|
|
73
|
+
const { GenMessage, messageDesc } = f.runtime.codegen;
|
|
74
74
|
if (schema.options.jsonTypes) {
|
|
75
75
|
const JsonType = f.importJson(desc);
|
|
76
|
-
f.print(f.export("const", name), ": ",
|
|
76
|
+
f.print(f.export("const", name), ": ", GenMessage, "<", Shape, ", ", JsonType, ">", " = ", pure);
|
|
77
77
|
}
|
|
78
78
|
else {
|
|
79
|
-
f.print(f.export("const", name), ": ",
|
|
79
|
+
f.print(f.export("const", name), ": ", GenMessage, "<", Shape, ">", " = ", pure);
|
|
80
80
|
}
|
|
81
81
|
const call = (0, util_1.functionCall)(messageDesc, [fileDesc, ...(0, codegenv1_1.pathInFileDesc)(desc)]);
|
|
82
82
|
f.print(" ", call, ";");
|
|
@@ -91,13 +91,13 @@ function generateTs(schema) {
|
|
|
91
91
|
generateDescDoc(f, desc);
|
|
92
92
|
const name = f.importSchema(desc).name;
|
|
93
93
|
const Shape = f.importShape(desc);
|
|
94
|
-
const {
|
|
94
|
+
const { GenEnum, enumDesc } = f.runtime.codegen;
|
|
95
95
|
if (schema.options.jsonTypes) {
|
|
96
96
|
const JsonType = f.importJson(desc);
|
|
97
|
-
f.print(f.export("const", name), ": ",
|
|
97
|
+
f.print(f.export("const", name), ": ", GenEnum, "<", Shape, ", ", JsonType, ">", " = ", pure);
|
|
98
98
|
}
|
|
99
99
|
else {
|
|
100
|
-
f.print(f.export("const", name), ": ",
|
|
100
|
+
f.print(f.export("const", name), ": ", GenEnum, "<", Shape, ">", " = ", pure);
|
|
101
101
|
}
|
|
102
102
|
const call = (0, util_1.functionCall)(enumDesc, [fileDesc, ...(0, codegenv1_1.pathInFileDesc)(desc)]);
|
|
103
103
|
f.print(" ", call, ";");
|
|
@@ -105,23 +105,23 @@ function generateTs(schema) {
|
|
|
105
105
|
break;
|
|
106
106
|
}
|
|
107
107
|
case "extension": {
|
|
108
|
-
const {
|
|
108
|
+
const { GenExtension, extDesc } = f.runtime.codegen;
|
|
109
109
|
const name = f.importSchema(desc).name;
|
|
110
110
|
const E = f.importShape(desc.extendee);
|
|
111
111
|
const V = (0, util_1.fieldTypeScriptType)(desc, f.runtime).typing;
|
|
112
112
|
const call = (0, util_1.functionCall)(extDesc, [fileDesc, ...(0, codegenv1_1.pathInFileDesc)(desc)]);
|
|
113
113
|
f.print(f.jsDoc(desc));
|
|
114
|
-
f.print(f.export("const", name), ": ",
|
|
114
|
+
f.print(f.export("const", name), ": ", GenExtension, "<", E, ", ", V, ">", " = ", pure);
|
|
115
115
|
f.print(" ", call, ";");
|
|
116
116
|
f.print();
|
|
117
117
|
break;
|
|
118
118
|
}
|
|
119
119
|
case "service": {
|
|
120
|
-
const {
|
|
120
|
+
const { GenService, serviceDesc } = f.runtime.codegen;
|
|
121
121
|
const name = f.importSchema(desc).name;
|
|
122
122
|
const call = (0, util_1.functionCall)(serviceDesc, [fileDesc, ...(0, codegenv1_1.pathInFileDesc)(desc)]);
|
|
123
123
|
f.print(f.jsDoc(desc));
|
|
124
|
-
f.print(f.export("const", name), ": ",
|
|
124
|
+
f.print(f.export("const", name), ": ", GenService, "<", getServiceShapeExpr(f, desc), "> = ", pure);
|
|
125
125
|
f.print(" ", call, ";");
|
|
126
126
|
f.print();
|
|
127
127
|
break;
|
|
@@ -203,10 +203,10 @@ function generateDts(schema) {
|
|
|
203
203
|
for (const file of schema.files) {
|
|
204
204
|
const f = schema.generateFile(file.name + "_pb.d.ts");
|
|
205
205
|
f.preamble(file);
|
|
206
|
-
const {
|
|
206
|
+
const { GenFile } = f.runtime.codegen;
|
|
207
207
|
const fileDesc = f.importSchema(file);
|
|
208
208
|
generateDescDoc(f, file);
|
|
209
|
-
f.print(f.export("declare const", fileDesc.name), ": ",
|
|
209
|
+
f.print(f.export("declare const", fileDesc.name), ": ", GenFile, ";");
|
|
210
210
|
f.print();
|
|
211
211
|
for (const desc of schema.typesInFile(file)) {
|
|
212
212
|
switch (desc.kind) {
|
|
@@ -217,14 +217,14 @@ function generateDts(schema) {
|
|
|
217
217
|
}
|
|
218
218
|
const name = f.importSchema(desc).name;
|
|
219
219
|
const Shape = f.importShape(desc);
|
|
220
|
-
const {
|
|
220
|
+
const { GenMessage } = f.runtime.codegen;
|
|
221
221
|
generateDescDoc(f, desc);
|
|
222
222
|
if (schema.options.jsonTypes) {
|
|
223
223
|
const JsonType = f.importJson(desc);
|
|
224
|
-
f.print(f.export("declare const", name), ": ",
|
|
224
|
+
f.print(f.export("declare const", name), ": ", GenMessage, "<", Shape, ", ", JsonType, ">", ";");
|
|
225
225
|
}
|
|
226
226
|
else {
|
|
227
|
-
f.print(f.export("declare const", name), ": ",
|
|
227
|
+
f.print(f.export("declare const", name), ": ", GenMessage, "<", Shape, ">", ";");
|
|
228
228
|
}
|
|
229
229
|
f.print();
|
|
230
230
|
break;
|
|
@@ -237,32 +237,32 @@ function generateDts(schema) {
|
|
|
237
237
|
generateDescDoc(f, desc);
|
|
238
238
|
const name = f.importSchema(desc).name;
|
|
239
239
|
const Shape = f.importShape(desc);
|
|
240
|
-
const {
|
|
240
|
+
const { GenEnum } = f.runtime.codegen;
|
|
241
241
|
if (schema.options.jsonTypes) {
|
|
242
242
|
const JsonType = f.importJson(desc);
|
|
243
|
-
f.print(f.export("declare const", name), ": ",
|
|
243
|
+
f.print(f.export("declare const", name), ": ", GenEnum, "<", Shape, ", ", JsonType, ">;");
|
|
244
244
|
}
|
|
245
245
|
else {
|
|
246
|
-
f.print(f.export("declare const", name), ": ",
|
|
246
|
+
f.print(f.export("declare const", name), ": ", GenEnum, "<", Shape, ">;");
|
|
247
247
|
}
|
|
248
248
|
f.print();
|
|
249
249
|
break;
|
|
250
250
|
}
|
|
251
251
|
case "extension": {
|
|
252
|
-
const {
|
|
252
|
+
const { GenExtension } = f.runtime.codegen;
|
|
253
253
|
const name = f.importSchema(desc).name;
|
|
254
254
|
const E = f.importShape(desc.extendee);
|
|
255
255
|
const V = (0, util_1.fieldTypeScriptType)(desc, f.runtime).typing;
|
|
256
256
|
f.print(f.jsDoc(desc));
|
|
257
|
-
f.print(f.export("declare const", name), ": ",
|
|
257
|
+
f.print(f.export("declare const", name), ": ", GenExtension, "<", E, ", ", V, ">;");
|
|
258
258
|
f.print();
|
|
259
259
|
break;
|
|
260
260
|
}
|
|
261
261
|
case "service": {
|
|
262
|
-
const {
|
|
262
|
+
const { GenService } = f.runtime.codegen;
|
|
263
263
|
const name = f.importSchema(desc).name;
|
|
264
264
|
f.print(f.jsDoc(desc));
|
|
265
|
-
f.print(f.export("declare const", name), ": ",
|
|
265
|
+
f.print(f.export("declare const", name), ": ", GenService, "<", getServiceShapeExpr(f, desc), ">;");
|
|
266
266
|
f.print();
|
|
267
267
|
break;
|
|
268
268
|
}
|
|
@@ -316,27 +316,23 @@ function getFileDescCall(f, file, schema) {
|
|
|
316
316
|
}));
|
|
317
317
|
return (0, util_1.functionCall)(fileDesc, [
|
|
318
318
|
f.string(info.base64()),
|
|
319
|
-
|
|
319
|
+
f.array(deps),
|
|
320
320
|
]);
|
|
321
321
|
}
|
|
322
322
|
return (0, util_1.functionCall)(fileDesc, [f.string(info.base64())]);
|
|
323
323
|
}
|
|
324
324
|
// prettier-ignore
|
|
325
325
|
function getServiceShapeExpr(f, service) {
|
|
326
|
-
const p = [];
|
|
327
|
-
function print(...printables) {
|
|
328
|
-
p.push(...printables, "\n");
|
|
329
|
-
}
|
|
330
|
-
print("{");
|
|
326
|
+
const p = ["{\n"];
|
|
331
327
|
for (const method of service.methods) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
328
|
+
p.push(f.jsDoc(method, " "), "\n");
|
|
329
|
+
p.push(" ", method.localName, ": {\n");
|
|
330
|
+
p.push(" methodKind: ", f.string(method.methodKind), ";\n");
|
|
331
|
+
p.push(" input: typeof ", f.importSchema(method.input, true), ";\n");
|
|
332
|
+
p.push(" output: typeof ", f.importSchema(method.output, true), ";\n");
|
|
333
|
+
p.push(" },\n");
|
|
338
334
|
}
|
|
339
|
-
|
|
335
|
+
p.push("}");
|
|
340
336
|
return p;
|
|
341
337
|
}
|
|
342
338
|
// prettier-ignore
|
package/dist/cjs/src/util.d.ts
CHANGED
|
@@ -6,4 +6,3 @@ export declare function fieldTypeScriptType(field: DescField | DescExtension, im
|
|
|
6
6
|
};
|
|
7
7
|
export declare function fieldJsonType(field: DescField | DescExtension): Printable;
|
|
8
8
|
export declare function functionCall(fn: Printable, args: Printable[], typeParams?: Printable[]): Printable;
|
|
9
|
-
export declare function arrayLiteral(elements: Printable[]): Printable;
|
package/dist/cjs/src/util.js
CHANGED
|
@@ -13,7 +13,9 @@
|
|
|
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.
|
|
16
|
+
exports.fieldTypeScriptType = fieldTypeScriptType;
|
|
17
|
+
exports.fieldJsonType = fieldJsonType;
|
|
18
|
+
exports.functionCall = functionCall;
|
|
17
19
|
const protobuf_1 = require("@bufbuild/protobuf");
|
|
18
20
|
const codegenv1_1 = require("@bufbuild/protobuf/codegenv1");
|
|
19
21
|
const wkt_1 = require("@bufbuild/protobuf/wkt");
|
|
@@ -91,7 +93,6 @@ function fieldTypeScriptType(field, imports) {
|
|
|
91
93
|
}
|
|
92
94
|
return { typing, optional };
|
|
93
95
|
}
|
|
94
|
-
exports.fieldTypeScriptType = fieldTypeScriptType;
|
|
95
96
|
function messageFieldTypeScriptType(field, imports) {
|
|
96
97
|
var _a;
|
|
97
98
|
if ((0, wkt_1.isWrapperDesc)(field.message) &&
|
|
@@ -186,7 +187,6 @@ function fieldJsonType(field) {
|
|
|
186
187
|
}
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
|
-
exports.fieldJsonType = fieldJsonType;
|
|
190
190
|
function functionCall(fn, args, typeParams) {
|
|
191
191
|
let tp = [];
|
|
192
192
|
if (typeParams !== undefined && typeParams.length > 0) {
|
|
@@ -194,11 +194,6 @@ function functionCall(fn, args, typeParams) {
|
|
|
194
194
|
}
|
|
195
195
|
return [fn, ...tp, "(", commaSeparate(args), ")"];
|
|
196
196
|
}
|
|
197
|
-
exports.functionCall = functionCall;
|
|
198
|
-
function arrayLiteral(elements) {
|
|
199
|
-
return ["[", commaSeparate(elements), "]"];
|
|
200
|
-
}
|
|
201
|
-
exports.arrayLiteral = arrayLiteral;
|
|
202
197
|
function commaSeparate(elements) {
|
|
203
198
|
const r = [];
|
|
204
199
|
for (let i = 0; i < elements.length; i++) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoc-gen-es",
|
|
3
|
-
"version": "2.0.0
|
|
4
|
-
"description": "Protocol Buffers code generator for ECMAScript",
|
|
3
|
+
"version": "2.0.0",
|
|
5
4
|
"license": "Apache-2.0",
|
|
5
|
+
"description": "Protocol Buffers code generator for ECMAScript",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"protobuf",
|
|
8
|
+
"schema",
|
|
9
|
+
"typescript",
|
|
10
|
+
"ecmascript",
|
|
11
|
+
"protoc-plugin"
|
|
12
|
+
],
|
|
6
13
|
"repository": {
|
|
7
14
|
"type": "git",
|
|
8
15
|
"url": "https://github.com/bufbuild/protobuf-es.git",
|
|
@@ -23,11 +30,11 @@
|
|
|
23
30
|
},
|
|
24
31
|
"preferUnplugged": true,
|
|
25
32
|
"dependencies": {
|
|
26
|
-
"@bufbuild/protobuf": "^2.0.0
|
|
27
|
-
"@bufbuild/protoplugin": "2.0.0
|
|
33
|
+
"@bufbuild/protobuf": "^2.0.0",
|
|
34
|
+
"@bufbuild/protoplugin": "2.0.0"
|
|
28
35
|
},
|
|
29
36
|
"peerDependencies": {
|
|
30
|
-
"@bufbuild/protobuf": "2.0.0
|
|
37
|
+
"@bufbuild/protobuf": "2.0.0"
|
|
31
38
|
},
|
|
32
39
|
"peerDependenciesMeta": {
|
|
33
40
|
"@bufbuild/protobuf": {
|