@bufbuild/protoc-gen-es 1.5.1 → 1.6.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 +17 -4
- package/dist/cjs/package.json +4 -4
- package/dist/cjs/src/declaration.js +7 -7
- package/dist/cjs/src/javascript.js +8 -8
- package/dist/cjs/src/typescript.js +9 -9
- package/package.json +4 -4
- package/src/declaration.ts +7 -9
- package/src/javascript.ts +8 -10
- package/src/typescript.ts +9 -11
package/README.md
CHANGED
|
@@ -98,12 +98,25 @@ By default, [protoc-gen-es](https://www.npmjs.com/package/@bufbuild/protoc-gen-e
|
|
|
98
98
|
uses a `.js` file extensions in import paths, even in TypeScript files.
|
|
99
99
|
|
|
100
100
|
This is unintuitive, but necessary for [ECMAScript modules in Node.js](https://www.typescriptlang.org/docs/handbook/esm-node.html).
|
|
101
|
-
Unfortunately, not all bundlers and tools have caught up yet, and Deno
|
|
102
|
-
requires `.ts`. With this plugin option, you can replace `.js` extensions
|
|
101
|
+
Unfortunately, not all bundlers and tools have caught up yet, and Deno
|
|
102
|
+
requires `.ts`. With this plugin option, you can replace `.js` extensions
|
|
103
103
|
in import paths with the given value. For example, set
|
|
104
104
|
|
|
105
|
-
- `import_extension=none` to remove the `.js` extension
|
|
106
|
-
- `import_extension=.ts` to replace the `.js` extension with `.ts
|
|
105
|
+
- `import_extension=none` to remove the `.js` extension.
|
|
106
|
+
- `import_extension=.ts` to replace the `.js` extension with `.ts`.
|
|
107
|
+
|
|
108
|
+
### `js_import_style`
|
|
109
|
+
|
|
110
|
+
By default, [protoc-gen-es](https://www.npmjs.com/package/@bufbuild/protoc-gen-es)
|
|
111
|
+
(and all other plugins based on [@bufbuild/protoplugin](https://www.npmjs.com/package/@bufbuild/protoplugin))
|
|
112
|
+
generate ECMAScript `import` and `export` statements. For use cases where
|
|
113
|
+
CommonJS is difficult to avoid, this option can be used to generate CommonJS
|
|
114
|
+
`require()` calls.
|
|
115
|
+
|
|
116
|
+
Possible values:
|
|
117
|
+
- `js_import_style=module` generate ECMAScript `import` / `export` statements -
|
|
118
|
+
the default behavior.
|
|
119
|
+
- `js_import_style=legacy_commonjs` generate CommonJS `require()` calls.
|
|
107
120
|
|
|
108
121
|
|
|
109
122
|
### `keep_empty_files=true`
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoc-gen-es",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
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.
|
|
24
|
-
"@bufbuild/protoplugin": "1.
|
|
23
|
+
"@bufbuild/protobuf": "^1.6.0",
|
|
24
|
+
"@bufbuild/protoplugin": "1.6.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@bufbuild/protobuf": "1.
|
|
27
|
+
"@bufbuild/protobuf": "1.6.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependenciesMeta": {
|
|
30
30
|
"@bufbuild/protobuf": {
|
|
@@ -32,13 +32,13 @@ function generateDts(schema) {
|
|
|
32
32
|
exports.generateDts = generateDts;
|
|
33
33
|
// prettier-ignore
|
|
34
34
|
function generateEnum(schema, f, enumeration) {
|
|
35
|
-
f.print(
|
|
35
|
+
f.print(f.jsDoc(enumeration));
|
|
36
36
|
f.print("export declare enum ", enumeration, " {");
|
|
37
37
|
for (const value of enumeration.values) {
|
|
38
38
|
if (enumeration.values.indexOf(value) > 0) {
|
|
39
39
|
f.print();
|
|
40
40
|
}
|
|
41
|
-
f.print(
|
|
41
|
+
f.print(f.jsDoc(value, " "));
|
|
42
42
|
f.print(" ", (0, ecmascript_1.localName)(value), " = ", value.number, ",");
|
|
43
43
|
}
|
|
44
44
|
f.print("}");
|
|
@@ -48,7 +48,7 @@ function generateEnum(schema, f, enumeration) {
|
|
|
48
48
|
function generateMessage(schema, f, message) {
|
|
49
49
|
const protoN = (0, editions_js_1.getNonEditionRuntime)(schema, message.file);
|
|
50
50
|
const { PartialMessage, FieldList, Message, PlainMessage, BinaryReadOptions, JsonReadOptions, JsonValue } = schema.runtime;
|
|
51
|
-
f.print(
|
|
51
|
+
f.print(f.jsDoc(message));
|
|
52
52
|
f.print("export declare class ", message, " extends ", Message, "<", message, "> {");
|
|
53
53
|
for (const member of message.members) {
|
|
54
54
|
switch (member.kind) {
|
|
@@ -65,7 +65,7 @@ function generateMessage(schema, f, message) {
|
|
|
65
65
|
f.print();
|
|
66
66
|
generateWktMethods(schema, f, message);
|
|
67
67
|
f.print(" static readonly runtime: typeof ", protoN, ";");
|
|
68
|
-
f.print(' static readonly typeName = ',
|
|
68
|
+
f.print(' static readonly typeName = ', f.string(message.typeName), ';');
|
|
69
69
|
f.print(" static readonly fields: ", FieldList, ";");
|
|
70
70
|
// In case we start supporting options, we have to surface them here
|
|
71
71
|
//f.print(" static readonly options: { readonly [extensionName: string]: ", rt.JsonValue, " } = {};")
|
|
@@ -90,13 +90,13 @@ function generateMessage(schema, f, message) {
|
|
|
90
90
|
}
|
|
91
91
|
// prettier-ignore
|
|
92
92
|
function generateOneof(schema, f, oneof) {
|
|
93
|
-
f.print(
|
|
93
|
+
f.print(f.jsDoc(oneof, " "));
|
|
94
94
|
f.print(" ", (0, ecmascript_1.localName)(oneof), ": {");
|
|
95
95
|
for (const field of oneof.fields) {
|
|
96
96
|
if (oneof.fields.indexOf(field) > 0) {
|
|
97
97
|
f.print(` } | {`);
|
|
98
98
|
}
|
|
99
|
-
f.print(
|
|
99
|
+
f.print(f.jsDoc(field, " "));
|
|
100
100
|
const { typing } = (0, ecmascript_1.getFieldTyping)(field, f);
|
|
101
101
|
f.print(` value: `, typing, `;`);
|
|
102
102
|
f.print(` case: "`, (0, ecmascript_1.localName)(field), `";`);
|
|
@@ -104,7 +104,7 @@ function generateOneof(schema, f, oneof) {
|
|
|
104
104
|
f.print(` } | { case: undefined; value?: undefined };`);
|
|
105
105
|
}
|
|
106
106
|
function generateField(schema, f, field) {
|
|
107
|
-
f.print(
|
|
107
|
+
f.print(f.jsDoc(field, " "));
|
|
108
108
|
const e = [];
|
|
109
109
|
e.push(" ", (0, ecmascript_1.localName)(field));
|
|
110
110
|
const { typing, optional } = (0, ecmascript_1.getFieldTyping)(field, f);
|
|
@@ -34,19 +34,19 @@ exports.generateJs = generateJs;
|
|
|
34
34
|
// prettier-ignore
|
|
35
35
|
function generateEnum(schema, f, enumeration) {
|
|
36
36
|
const protoN = (0, editions_js_1.getNonEditionRuntime)(schema, enumeration.file);
|
|
37
|
-
f.print(
|
|
38
|
-
f.print("
|
|
37
|
+
f.print(f.jsDoc(enumeration));
|
|
38
|
+
f.print(f.exportDecl("const", enumeration), " = ", protoN, ".makeEnum(");
|
|
39
39
|
f.print(` "`, enumeration.typeName, `",`);
|
|
40
40
|
f.print(` [`);
|
|
41
41
|
if (enumeration.sharedPrefix === undefined) {
|
|
42
42
|
for (const value of enumeration.values) {
|
|
43
|
-
f.print(" {no: ", value.number, ", name: ",
|
|
43
|
+
f.print(" {no: ", value.number, ", name: ", f.string(value.name), "},");
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
47
|
for (const value of enumeration.values) {
|
|
48
48
|
const localName = value.name.substring(enumeration.sharedPrefix.length);
|
|
49
|
-
f.print(" {no: ", value.number, ", name: ",
|
|
49
|
+
f.print(" {no: ", value.number, ", name: ", f.string(value.name), ", localName: ", f.string(localName), "},");
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
f.print(` ],`);
|
|
@@ -56,9 +56,9 @@ function generateEnum(schema, f, enumeration) {
|
|
|
56
56
|
// prettier-ignore
|
|
57
57
|
function generateMessage(schema, f, message) {
|
|
58
58
|
const protoN = (0, editions_js_1.getNonEditionRuntime)(schema, message.file);
|
|
59
|
-
f.print(
|
|
60
|
-
f.print("
|
|
61
|
-
f.print(` `,
|
|
59
|
+
f.print(f.jsDoc(message));
|
|
60
|
+
f.print(f.exportDecl("const", message), " = ", protoN, ".makeMessageType(");
|
|
61
|
+
f.print(` `, f.string(message.typeName), `,`);
|
|
62
62
|
if (message.fields.length == 0) {
|
|
63
63
|
f.print(" [],");
|
|
64
64
|
}
|
|
@@ -74,7 +74,7 @@ function generateMessage(schema, f, message) {
|
|
|
74
74
|
.makeMessageType(message.typeName, []).name;
|
|
75
75
|
if (needsLocalName) {
|
|
76
76
|
// local name is not inferrable from the type name, we need to provide it
|
|
77
|
-
f.print(` {localName: `,
|
|
77
|
+
f.print(` {localName: `, f.string((0, ecmascript_1.localName)(message)), `},`);
|
|
78
78
|
}
|
|
79
79
|
f.print(");");
|
|
80
80
|
f.print();
|
|
@@ -35,13 +35,13 @@ exports.generateTs = generateTs;
|
|
|
35
35
|
// prettier-ignore
|
|
36
36
|
function generateEnum(schema, f, enumeration) {
|
|
37
37
|
const protoN = (0, editions_js_1.getNonEditionRuntime)(schema, enumeration.file);
|
|
38
|
-
f.print(
|
|
39
|
-
f.print("
|
|
38
|
+
f.print(f.jsDoc(enumeration));
|
|
39
|
+
f.print(f.exportDecl("enum", enumeration), " {");
|
|
40
40
|
for (const value of enumeration.values) {
|
|
41
41
|
if (enumeration.values.indexOf(value) > 0) {
|
|
42
42
|
f.print();
|
|
43
43
|
}
|
|
44
|
-
f.print(
|
|
44
|
+
f.print(f.jsDoc(value, " "));
|
|
45
45
|
f.print(" ", (0, ecmascript_1.localName)(value), " = ", value.number, ",");
|
|
46
46
|
}
|
|
47
47
|
f.print("}");
|
|
@@ -57,8 +57,8 @@ function generateEnum(schema, f, enumeration) {
|
|
|
57
57
|
function generateMessage(schema, f, message) {
|
|
58
58
|
const protoN = (0, editions_js_1.getNonEditionRuntime)(schema, message.file);
|
|
59
59
|
const { PartialMessage, FieldList, Message, PlainMessage, BinaryReadOptions, JsonReadOptions, JsonValue } = schema.runtime;
|
|
60
|
-
f.print(
|
|
61
|
-
f.print("
|
|
60
|
+
f.print(f.jsDoc(message));
|
|
61
|
+
f.print(f.exportDecl("class", message), " extends ", Message, "<", message, "> {");
|
|
62
62
|
for (const member of message.members) {
|
|
63
63
|
switch (member.kind) {
|
|
64
64
|
case "oneof":
|
|
@@ -77,7 +77,7 @@ function generateMessage(schema, f, message) {
|
|
|
77
77
|
f.print();
|
|
78
78
|
generateWktMethods(schema, f, message);
|
|
79
79
|
f.print(" static readonly runtime: typeof ", protoN, " = ", protoN, ";");
|
|
80
|
-
f.print(' static readonly typeName = ',
|
|
80
|
+
f.print(' static readonly typeName = ', f.string(message.typeName), ';');
|
|
81
81
|
f.print(" static readonly fields: ", FieldList, " = ", protoN, ".util.newFieldList(() => [");
|
|
82
82
|
for (const field of message.fields) {
|
|
83
83
|
(0, javascript_js_1.generateFieldInfo)(schema, f, field);
|
|
@@ -114,13 +114,13 @@ function generateMessage(schema, f, message) {
|
|
|
114
114
|
}
|
|
115
115
|
// prettier-ignore
|
|
116
116
|
function generateOneof(schema, f, oneof) {
|
|
117
|
-
f.print(
|
|
117
|
+
f.print(f.jsDoc(oneof, " "));
|
|
118
118
|
f.print(" ", (0, ecmascript_1.localName)(oneof), ": {");
|
|
119
119
|
for (const field of oneof.fields) {
|
|
120
120
|
if (oneof.fields.indexOf(field) > 0) {
|
|
121
121
|
f.print(` } | {`);
|
|
122
122
|
}
|
|
123
|
-
f.print(
|
|
123
|
+
f.print(f.jsDoc(field, " "));
|
|
124
124
|
const { typing } = (0, ecmascript_1.getFieldTyping)(field, f);
|
|
125
125
|
f.print(` value: `, typing, `;`);
|
|
126
126
|
f.print(` case: "`, (0, ecmascript_1.localName)(field), `";`);
|
|
@@ -128,7 +128,7 @@ function generateOneof(schema, f, oneof) {
|
|
|
128
128
|
f.print(` } | { case: undefined; value?: undefined } = { case: undefined };`);
|
|
129
129
|
}
|
|
130
130
|
function generateField(schema, f, field) {
|
|
131
|
-
f.print(
|
|
131
|
+
f.print(f.jsDoc(field, " "));
|
|
132
132
|
const e = [];
|
|
133
133
|
e.push(" ", (0, ecmascript_1.localName)(field));
|
|
134
134
|
const { defaultValue, typingInferrable } = (0, ecmascript_1.getFieldIntrinsicDefaultValue)(field);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoc-gen-es",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
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.
|
|
24
|
-
"@bufbuild/protoplugin": "1.
|
|
23
|
+
"@bufbuild/protobuf": "^1.6.0",
|
|
24
|
+
"@bufbuild/protoplugin": "1.6.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@bufbuild/protobuf": "1.
|
|
27
|
+
"@bufbuild/protobuf": "1.6.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependenciesMeta": {
|
|
30
30
|
"@bufbuild/protobuf": {
|
package/src/declaration.ts
CHANGED
|
@@ -25,9 +25,7 @@ import type {
|
|
|
25
25
|
} from "@bufbuild/protoplugin/ecmascript";
|
|
26
26
|
import {
|
|
27
27
|
getFieldTyping,
|
|
28
|
-
literalString,
|
|
29
28
|
localName,
|
|
30
|
-
makeJsDoc,
|
|
31
29
|
reifyWkt,
|
|
32
30
|
} from "@bufbuild/protoplugin/ecmascript";
|
|
33
31
|
import { getNonEditionRuntime } from "./editions.js";
|
|
@@ -48,13 +46,13 @@ export function generateDts(schema: Schema) {
|
|
|
48
46
|
|
|
49
47
|
// prettier-ignore
|
|
50
48
|
function generateEnum(schema: Schema, f: GeneratedFile, enumeration: DescEnum) {
|
|
51
|
-
f.print(
|
|
49
|
+
f.print(f.jsDoc(enumeration));
|
|
52
50
|
f.print("export declare enum ", enumeration, " {");
|
|
53
51
|
for (const value of enumeration.values) {
|
|
54
52
|
if (enumeration.values.indexOf(value) > 0) {
|
|
55
53
|
f.print();
|
|
56
54
|
}
|
|
57
|
-
f.print(
|
|
55
|
+
f.print(f.jsDoc(value, " "));
|
|
58
56
|
f.print(" ", localName(value), " = ", value.number, ",");
|
|
59
57
|
}
|
|
60
58
|
f.print("}");
|
|
@@ -73,7 +71,7 @@ function generateMessage(schema: Schema, f: GeneratedFile, message: DescMessage)
|
|
|
73
71
|
JsonReadOptions,
|
|
74
72
|
JsonValue
|
|
75
73
|
} = schema.runtime;
|
|
76
|
-
f.print(
|
|
74
|
+
f.print(f.jsDoc(message));
|
|
77
75
|
f.print("export declare class ", message, " extends ", Message, "<", message, "> {");
|
|
78
76
|
for (const member of message.members) {
|
|
79
77
|
switch (member.kind) {
|
|
@@ -90,7 +88,7 @@ function generateMessage(schema: Schema, f: GeneratedFile, message: DescMessage)
|
|
|
90
88
|
f.print();
|
|
91
89
|
generateWktMethods(schema, f, message);
|
|
92
90
|
f.print(" static readonly runtime: typeof ", protoN, ";");
|
|
93
|
-
f.print(' static readonly typeName = ',
|
|
91
|
+
f.print(' static readonly typeName = ', f.string(message.typeName), ';');
|
|
94
92
|
f.print(" static readonly fields: ", FieldList, ";");
|
|
95
93
|
// In case we start supporting options, we have to surface them here
|
|
96
94
|
//f.print(" static readonly options: { readonly [extensionName: string]: ", rt.JsonValue, " } = {};")
|
|
@@ -116,13 +114,13 @@ function generateMessage(schema: Schema, f: GeneratedFile, message: DescMessage)
|
|
|
116
114
|
|
|
117
115
|
// prettier-ignore
|
|
118
116
|
function generateOneof(schema: Schema, f: GeneratedFile, oneof: DescOneof) {
|
|
119
|
-
f.print(
|
|
117
|
+
f.print(f.jsDoc(oneof, " "));
|
|
120
118
|
f.print(" ", localName(oneof), ": {");
|
|
121
119
|
for (const field of oneof.fields) {
|
|
122
120
|
if (oneof.fields.indexOf(field) > 0) {
|
|
123
121
|
f.print(` } | {`);
|
|
124
122
|
}
|
|
125
|
-
f.print(
|
|
123
|
+
f.print(f.jsDoc(field, " "));
|
|
126
124
|
const { typing } = getFieldTyping(field, f);
|
|
127
125
|
f.print(` value: `, typing, `;`);
|
|
128
126
|
f.print(` case: "`, localName(field), `";`);
|
|
@@ -131,7 +129,7 @@ function generateOneof(schema: Schema, f: GeneratedFile, oneof: DescOneof) {
|
|
|
131
129
|
}
|
|
132
130
|
|
|
133
131
|
function generateField(schema: Schema, f: GeneratedFile, field: DescField) {
|
|
134
|
-
f.print(
|
|
132
|
+
f.print(f.jsDoc(field, " "));
|
|
135
133
|
const e: Printable = [];
|
|
136
134
|
e.push(" ", localName(field));
|
|
137
135
|
const { typing, optional } = getFieldTyping(field, f);
|
package/src/javascript.ts
CHANGED
|
@@ -27,9 +27,7 @@ import type {
|
|
|
27
27
|
} from "@bufbuild/protoplugin/ecmascript";
|
|
28
28
|
import {
|
|
29
29
|
getFieldExplicitDefaultValue,
|
|
30
|
-
literalString,
|
|
31
30
|
localName,
|
|
32
|
-
makeJsDoc,
|
|
33
31
|
reifyWkt,
|
|
34
32
|
} from "@bufbuild/protoplugin/ecmascript";
|
|
35
33
|
import { getNonEditionRuntime } from "./editions.js";
|
|
@@ -51,18 +49,18 @@ export function generateJs(schema: Schema) {
|
|
|
51
49
|
// prettier-ignore
|
|
52
50
|
function generateEnum(schema: Schema, f: GeneratedFile, enumeration: DescEnum) {
|
|
53
51
|
const protoN = getNonEditionRuntime(schema, enumeration.file);
|
|
54
|
-
f.print(
|
|
55
|
-
f.print("
|
|
52
|
+
f.print(f.jsDoc(enumeration));
|
|
53
|
+
f.print(f.exportDecl("const", enumeration), " = ", protoN, ".makeEnum(")
|
|
56
54
|
f.print(` "`, enumeration.typeName, `",`)
|
|
57
55
|
f.print(` [`)
|
|
58
56
|
if (enumeration.sharedPrefix === undefined) {
|
|
59
57
|
for (const value of enumeration.values) {
|
|
60
|
-
f.print(" {no: ", value.number, ", name: ",
|
|
58
|
+
f.print(" {no: ", value.number, ", name: ", f.string(value.name), "},")
|
|
61
59
|
}
|
|
62
60
|
} else {
|
|
63
61
|
for (const value of enumeration.values) {
|
|
64
62
|
const localName = value.name.substring(enumeration.sharedPrefix.length);
|
|
65
|
-
f.print(" {no: ", value.number, ", name: ",
|
|
63
|
+
f.print(" {no: ", value.number, ", name: ", f.string(value.name), ", localName: ", f.string(localName), "},")
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
66
|
f.print(` ],`)
|
|
@@ -73,9 +71,9 @@ function generateEnum(schema: Schema, f: GeneratedFile, enumeration: DescEnum) {
|
|
|
73
71
|
// prettier-ignore
|
|
74
72
|
function generateMessage(schema: Schema, f: GeneratedFile, message: DescMessage) {
|
|
75
73
|
const protoN = getNonEditionRuntime(schema, message.file);
|
|
76
|
-
f.print(
|
|
77
|
-
f.print("
|
|
78
|
-
f.print(` `,
|
|
74
|
+
f.print(f.jsDoc(message));
|
|
75
|
+
f.print(f.exportDecl("const", message), " = ", protoN, ".makeMessageType(")
|
|
76
|
+
f.print(` `, f.string(message.typeName), `,`)
|
|
79
77
|
if (message.fields.length == 0) {
|
|
80
78
|
f.print(" [],")
|
|
81
79
|
} else {
|
|
@@ -90,7 +88,7 @@ function generateMessage(schema: Schema, f: GeneratedFile, message: DescMessage)
|
|
|
90
88
|
.makeMessageType(message.typeName, []).name;
|
|
91
89
|
if (needsLocalName) {
|
|
92
90
|
// local name is not inferrable from the type name, we need to provide it
|
|
93
|
-
f.print(` {localName: `,
|
|
91
|
+
f.print(` {localName: `, f.string(localName(message)), `},`)
|
|
94
92
|
}
|
|
95
93
|
f.print(");")
|
|
96
94
|
f.print()
|
package/src/typescript.ts
CHANGED
|
@@ -27,9 +27,7 @@ import type {
|
|
|
27
27
|
import {
|
|
28
28
|
getFieldIntrinsicDefaultValue,
|
|
29
29
|
getFieldTyping,
|
|
30
|
-
literalString,
|
|
31
30
|
localName,
|
|
32
|
-
makeJsDoc,
|
|
33
31
|
reifyWkt,
|
|
34
32
|
} from "@bufbuild/protoplugin/ecmascript";
|
|
35
33
|
import { generateFieldInfo } from "./javascript.js";
|
|
@@ -52,13 +50,13 @@ export function generateTs(schema: Schema) {
|
|
|
52
50
|
// prettier-ignore
|
|
53
51
|
function generateEnum(schema: Schema, f: GeneratedFile, enumeration: DescEnum) {
|
|
54
52
|
const protoN = getNonEditionRuntime(schema, enumeration.file);
|
|
55
|
-
f.print(
|
|
56
|
-
f.print("
|
|
53
|
+
f.print(f.jsDoc(enumeration));
|
|
54
|
+
f.print(f.exportDecl("enum", enumeration), " {");
|
|
57
55
|
for (const value of enumeration.values) {
|
|
58
56
|
if (enumeration.values.indexOf(value) > 0) {
|
|
59
57
|
f.print();
|
|
60
58
|
}
|
|
61
|
-
f.print(
|
|
59
|
+
f.print(f.jsDoc(value, " "));
|
|
62
60
|
f.print(" ", localName(value), " = ", value.number, ",");
|
|
63
61
|
}
|
|
64
62
|
f.print("}");
|
|
@@ -83,8 +81,8 @@ function generateMessage(schema: Schema, f: GeneratedFile, message: DescMessage)
|
|
|
83
81
|
JsonReadOptions,
|
|
84
82
|
JsonValue
|
|
85
83
|
} = schema.runtime;
|
|
86
|
-
f.print(
|
|
87
|
-
f.print("
|
|
84
|
+
f.print(f.jsDoc(message));
|
|
85
|
+
f.print(f.exportDecl("class", message), " extends ", Message, "<", message, "> {");
|
|
88
86
|
for (const member of message.members) {
|
|
89
87
|
switch (member.kind) {
|
|
90
88
|
case "oneof":
|
|
@@ -103,7 +101,7 @@ function generateMessage(schema: Schema, f: GeneratedFile, message: DescMessage)
|
|
|
103
101
|
f.print();
|
|
104
102
|
generateWktMethods(schema, f, message);
|
|
105
103
|
f.print(" static readonly runtime: typeof ", protoN, " = ", protoN, ";");
|
|
106
|
-
f.print(' static readonly typeName = ',
|
|
104
|
+
f.print(' static readonly typeName = ', f.string(message.typeName), ';');
|
|
107
105
|
f.print(" static readonly fields: ", FieldList, " = ", protoN, ".util.newFieldList(() => [");
|
|
108
106
|
for (const field of message.fields) {
|
|
109
107
|
generateFieldInfo(schema, f, field);
|
|
@@ -141,13 +139,13 @@ function generateMessage(schema: Schema, f: GeneratedFile, message: DescMessage)
|
|
|
141
139
|
|
|
142
140
|
// prettier-ignore
|
|
143
141
|
function generateOneof(schema: Schema, f: GeneratedFile, oneof: DescOneof) {
|
|
144
|
-
f.print(
|
|
142
|
+
f.print(f.jsDoc(oneof, " "));
|
|
145
143
|
f.print(" ", localName(oneof), ": {");
|
|
146
144
|
for (const field of oneof.fields) {
|
|
147
145
|
if (oneof.fields.indexOf(field) > 0) {
|
|
148
146
|
f.print(` } | {`);
|
|
149
147
|
}
|
|
150
|
-
f.print(
|
|
148
|
+
f.print(f.jsDoc(field, " "));
|
|
151
149
|
const { typing } = getFieldTyping(field, f);
|
|
152
150
|
f.print(` value: `, typing, `;`);
|
|
153
151
|
f.print(` case: "`, localName(field), `";`);
|
|
@@ -156,7 +154,7 @@ function generateOneof(schema: Schema, f: GeneratedFile, oneof: DescOneof) {
|
|
|
156
154
|
}
|
|
157
155
|
|
|
158
156
|
function generateField(schema: Schema, f: GeneratedFile, field: DescField) {
|
|
159
|
-
f.print(
|
|
157
|
+
f.print(f.jsDoc(field, " "));
|
|
160
158
|
const e: Printable = [];
|
|
161
159
|
e.push(" ", localName(field));
|
|
162
160
|
const { defaultValue, typingInferrable } =
|