@bufbuild/protoplugin 1.9.0 → 2.0.0-alpha.2
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/dist/cjs/create-es-plugin.d.ts +7 -11
- package/dist/cjs/create-es-plugin.js +15 -13
- package/dist/cjs/ecmascript/file-preamble.js +11 -7
- package/dist/cjs/ecmascript/generated-file.d.ts +19 -20
- package/dist/cjs/ecmascript/generated-file.js +95 -108
- package/dist/cjs/ecmascript/import-path.d.ts +0 -6
- package/dist/cjs/ecmascript/import-path.js +1 -22
- package/dist/cjs/ecmascript/import-symbol.d.ts +1 -3
- package/dist/cjs/ecmascript/import-symbol.js +3 -5
- package/dist/cjs/ecmascript/index.d.ts +3 -16
- package/dist/cjs/ecmascript/index.js +3 -29
- package/dist/cjs/ecmascript/jsdoc.d.ts +2 -13
- package/dist/cjs/ecmascript/jsdoc.js +39 -35
- package/dist/cjs/ecmascript/names.d.ts +4 -0
- package/dist/cjs/ecmascript/names.js +119 -0
- package/dist/cjs/ecmascript/parameter.d.ts +1 -1
- package/dist/cjs/ecmascript/parameter.js +3 -3
- package/dist/cjs/ecmascript/printable.d.ts +36 -0
- package/dist/cjs/ecmascript/runtime-imports.d.ts +12 -23
- package/dist/cjs/ecmascript/runtime-imports.js +28 -29
- package/dist/cjs/ecmascript/safe-identifier.d.ts +6 -0
- package/dist/cjs/ecmascript/safe-identifier.js +90 -0
- package/dist/cjs/ecmascript/schema.d.ts +9 -8
- package/dist/cjs/ecmascript/schema.js +72 -20
- package/dist/cjs/index.d.ts +1 -5
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/plugin.d.ts +1 -1
- package/dist/cjs/run-node.js +4 -3
- package/dist/cjs/source-code-info.d.ts +23 -0
- package/dist/cjs/source-code-info.js +286 -0
- package/dist/esm/create-es-plugin.d.ts +7 -11
- package/dist/esm/create-es-plugin.js +15 -13
- package/dist/esm/ecmascript/file-preamble.js +8 -4
- package/dist/esm/ecmascript/generated-file.d.ts +19 -20
- package/dist/esm/ecmascript/generated-file.js +97 -110
- package/dist/esm/ecmascript/import-path.d.ts +0 -6
- package/dist/esm/ecmascript/import-path.js +0 -20
- package/dist/esm/ecmascript/import-symbol.d.ts +1 -3
- package/dist/esm/ecmascript/import-symbol.js +3 -5
- package/dist/esm/ecmascript/index.d.ts +3 -16
- package/dist/esm/ecmascript/index.js +1 -18
- package/dist/esm/ecmascript/jsdoc.d.ts +2 -13
- package/dist/esm/ecmascript/jsdoc.js +36 -33
- package/dist/esm/ecmascript/names.d.ts +4 -0
- package/dist/esm/ecmascript/names.js +113 -0
- package/dist/esm/ecmascript/parameter.d.ts +1 -1
- package/dist/esm/ecmascript/parameter.js +3 -3
- package/dist/esm/ecmascript/printable.d.ts +36 -0
- package/dist/esm/ecmascript/{opaque-printables.js → printable.js} +1 -1
- package/dist/esm/ecmascript/runtime-imports.d.ts +12 -23
- package/dist/esm/ecmascript/runtime-imports.js +28 -29
- package/dist/esm/ecmascript/safe-identifier.d.ts +6 -0
- package/dist/esm/ecmascript/safe-identifier.js +86 -0
- package/dist/esm/ecmascript/schema.d.ts +9 -8
- package/dist/esm/ecmascript/schema.js +74 -22
- package/dist/esm/index.d.ts +1 -5
- package/dist/esm/index.js +1 -0
- package/dist/esm/plugin.d.ts +1 -1
- package/dist/esm/run-node.js +4 -3
- package/dist/esm/source-code-info.d.ts +23 -0
- package/dist/esm/source-code-info.js +278 -0
- package/package.json +2 -2
- package/dist/cjs/ecmascript/legacy-custom-options.d.ts +0 -40
- package/dist/cjs/ecmascript/legacy-custom-options.js +0 -121
- package/dist/cjs/ecmascript/legacy-gencommon.d.ts +0 -25
- package/dist/cjs/ecmascript/legacy-gencommon.js +0 -237
- package/dist/cjs/ecmascript/opaque-printables.d.ts +0 -27
- package/dist/cjs/ecmascript/reify-wkt.d.ts +0 -100
- package/dist/cjs/ecmascript/reify-wkt.js +0 -170
- package/dist/esm/ecmascript/legacy-custom-options.d.ts +0 -40
- package/dist/esm/ecmascript/legacy-custom-options.js +0 -115
- package/dist/esm/ecmascript/legacy-gencommon.d.ts +0 -25
- package/dist/esm/ecmascript/legacy-gencommon.js +0 -230
- package/dist/esm/ecmascript/opaque-printables.d.ts +0 -27
- package/dist/esm/ecmascript/reify-wkt.d.ts +0 -100
- package/dist/esm/ecmascript/reify-wkt.js +0 -166
- /package/dist/cjs/ecmascript/{opaque-printables.js → printable.js} +0 -0
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import type { AnyDesc, DescEnum, DescExtension, DescFile, DescMessage } from "@bufbuild/protobuf";
|
|
1
|
+
import type { AnyDesc, DescEnum, DescExtension, DescFile, DescMessage, DescService } from "@bufbuild/protobuf";
|
|
2
2
|
import type { ImportSymbol } from "./import-symbol.js";
|
|
3
|
+
import type { Printable } from "./printable.js";
|
|
3
4
|
import type { RuntimeImports } from "./runtime-imports.js";
|
|
4
|
-
import type { JSDocBlock } from "./jsdoc.js";
|
|
5
|
-
import type { ExportDeclaration, LiteralProtoInt64, LiteralString, RefDescEnum, RefDescMessage } from "./opaque-printables.js";
|
|
6
|
-
/**
|
|
7
|
-
* All types that can be passed to GeneratedFile.print()
|
|
8
|
-
*/
|
|
9
|
-
export type Printable = string | number | boolean | bigint | Uint8Array | ImportSymbol | ExportDeclaration | JSDocBlock | LiteralString | LiteralProtoInt64 | RefDescMessage | RefDescEnum | DescMessage | DescEnum | DescExtension | Printable[];
|
|
10
5
|
/**
|
|
11
6
|
* FileInfo represents an intermediate type using for transpiling TypeScript internally.
|
|
12
7
|
*/
|
|
@@ -49,10 +44,6 @@ export interface GeneratedFile {
|
|
|
49
44
|
* See print(Printable[]) for behavior when printing Printable items.
|
|
50
45
|
*/
|
|
51
46
|
print(fragments: TemplateStringsArray, ...printables: Printable[]): void;
|
|
52
|
-
/**
|
|
53
|
-
* @deprecated Please use createImportSymbol() from @bufbuild/protoplugin/ecmascript instead
|
|
54
|
-
*/
|
|
55
|
-
export(name: string): ImportSymbol;
|
|
56
47
|
/**
|
|
57
48
|
* Create a string literal.
|
|
58
49
|
*/
|
|
@@ -61,13 +52,13 @@ export interface GeneratedFile {
|
|
|
61
52
|
* Create a JSDoc comment block with the given text. Line breaks and white-space
|
|
62
53
|
* stay intact.
|
|
63
54
|
*/
|
|
64
|
-
jsDoc(text: string, indentation?: string):
|
|
55
|
+
jsDoc(text: string, indentation?: string): Printable;
|
|
65
56
|
/**
|
|
66
57
|
* Create a JSDoc comment block for the given message, enumeration, or other
|
|
67
58
|
* descriptor. The comment block will contain the original comments from the
|
|
68
59
|
* protobuf source, and annotations such as `@generated from message MyMessage`.
|
|
69
60
|
*/
|
|
70
|
-
jsDoc(desc: Exclude<AnyDesc, DescFile>, indentation?: string):
|
|
61
|
+
jsDoc(desc: Exclude<AnyDesc, DescFile>, indentation?: string): Printable;
|
|
71
62
|
/**
|
|
72
63
|
* Create a printable export statement. For example:
|
|
73
64
|
*
|
|
@@ -84,11 +75,15 @@ export interface GeneratedFile {
|
|
|
84
75
|
* statement. If the plugin option `js_import_style=legacy_commonjs` is set,
|
|
85
76
|
* exports will automatically be generated for CommonJS.
|
|
86
77
|
*/
|
|
87
|
-
exportDecl(declaration: string, name: string
|
|
78
|
+
exportDecl(declaration: string, name: string): Printable;
|
|
88
79
|
/**
|
|
89
80
|
* Import a message or enumeration generated by protoc-gen-es.
|
|
90
81
|
*/
|
|
91
|
-
|
|
82
|
+
importShape(desc: DescMessage | DescEnum): ImportSymbol;
|
|
83
|
+
/**
|
|
84
|
+
* Import a descriptor generated by protoc-gen-es.
|
|
85
|
+
*/
|
|
86
|
+
importDesc(desc: DescMessage | DescEnum | DescExtension | DescService | DescFile, typeOnly?: boolean): ImportSymbol;
|
|
92
87
|
/**
|
|
93
88
|
* Import any symbol from a file or package.
|
|
94
89
|
*
|
|
@@ -105,12 +100,16 @@ export interface GeneratedFile {
|
|
|
105
100
|
* formulate your own imports and exports based on this property.
|
|
106
101
|
*/
|
|
107
102
|
readonly jsImportStyle: "module" | "legacy_commonjs";
|
|
103
|
+
/**
|
|
104
|
+
* Provides some symbols from the runtime library @bufbuild/protobuf.
|
|
105
|
+
*/
|
|
106
|
+
readonly runtime: RuntimeImports;
|
|
108
107
|
}
|
|
109
108
|
export interface GeneratedFileController extends GeneratedFile {
|
|
110
109
|
getFileInfo(): FileInfo;
|
|
111
110
|
}
|
|
112
|
-
type
|
|
113
|
-
type
|
|
114
|
-
type
|
|
115
|
-
export
|
|
116
|
-
export
|
|
111
|
+
export type ResolveDescImportFn = (desc: DescMessage | DescEnum | DescExtension | DescService | DescFile, typeOnly?: boolean) => ImportSymbol;
|
|
112
|
+
export type ResolveShapeImportFn = (desc: DescMessage | DescEnum) => ImportSymbol;
|
|
113
|
+
export type RewriteImportFn = (path: string) => string;
|
|
114
|
+
export type CreatePreambleFn = (descFile: DescFile) => string;
|
|
115
|
+
export declare function createGeneratedFile(name: string, importPath: string, jsImportStyle: "module" | "legacy_commonjs", rewriteImport: RewriteImportFn, resolveDescImport: ResolveDescImportFn, resolveShapeImport: ResolveShapeImportFn, createPreamble: CreatePreambleFn, runtime: RuntimeImports): GeneratedFileController;
|
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
import {
|
|
14
|
+
import { protoInt64 } from "@bufbuild/protobuf";
|
|
15
|
+
import { LongType, ScalarType } from "@bufbuild/protobuf/reflect";
|
|
15
16
|
import { createImportSymbol } from "./import-symbol.js";
|
|
16
17
|
import { makeImportPathRelative } from "./import-path.js";
|
|
17
|
-
import {
|
|
18
|
-
export function createGeneratedFile(name, importPath, jsImportStyle,
|
|
18
|
+
import { createJsDocTextFromDesc, formatJsDocBlock } from "./jsdoc.js";
|
|
19
|
+
export function createGeneratedFile(name, importPath, jsImportStyle, rewriteImport, resolveDescImport, resolveShapeImport, createPreamble, runtime) {
|
|
19
20
|
let preamble;
|
|
20
21
|
const el = [];
|
|
21
22
|
return {
|
|
@@ -36,38 +37,51 @@ export function createGeneratedFile(name, importPath, jsImportStyle, rewriteImpo
|
|
|
36
37
|
? [printableOrFragments, ...rest]
|
|
37
38
|
: rest;
|
|
38
39
|
}
|
|
39
|
-
printableToEl(
|
|
40
|
+
printableToEl({
|
|
41
|
+
el,
|
|
42
|
+
runtime,
|
|
43
|
+
resolveDescImport,
|
|
44
|
+
resolveShapeImport,
|
|
45
|
+
}, printables);
|
|
40
46
|
el.push("\n");
|
|
41
47
|
},
|
|
42
|
-
export(name) {
|
|
43
|
-
return createImportSymbol(name, importPath);
|
|
44
|
-
},
|
|
45
48
|
exportDecl(declaration, name) {
|
|
46
49
|
return {
|
|
47
|
-
kind: "
|
|
48
|
-
declaration,
|
|
50
|
+
kind: "es_export_stmt",
|
|
49
51
|
name,
|
|
52
|
+
declaration,
|
|
50
53
|
};
|
|
51
54
|
},
|
|
52
55
|
string(string) {
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
return {
|
|
57
|
+
kind: "es_string",
|
|
58
|
+
value: string,
|
|
59
|
+
};
|
|
55
60
|
},
|
|
56
61
|
jsDoc(textOrDesc, indentation) {
|
|
57
|
-
return
|
|
62
|
+
return {
|
|
63
|
+
kind: "es_jsdoc",
|
|
64
|
+
text: typeof textOrDesc == "string"
|
|
65
|
+
? textOrDesc
|
|
66
|
+
: createJsDocTextFromDesc(textOrDesc),
|
|
67
|
+
indentation,
|
|
68
|
+
};
|
|
58
69
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
70
|
+
importDesc(desc, typeOnly = false) {
|
|
71
|
+
return resolveDescImport(desc, typeOnly);
|
|
72
|
+
},
|
|
73
|
+
importShape(desc) {
|
|
74
|
+
return resolveShapeImport(desc);
|
|
75
|
+
},
|
|
76
|
+
import(name, from) {
|
|
77
|
+
return createImportSymbol(name, from);
|
|
65
78
|
},
|
|
66
79
|
jsImportStyle,
|
|
80
|
+
runtime,
|
|
67
81
|
getFileInfo() {
|
|
68
82
|
return {
|
|
69
83
|
name,
|
|
70
|
-
content: elToContent(el, importPath,
|
|
84
|
+
content: elToContent(el, importPath, rewriteImport, jsImportStyle == "legacy_commonjs"),
|
|
71
85
|
preamble,
|
|
72
86
|
};
|
|
73
87
|
},
|
|
@@ -142,10 +156,11 @@ function elToContent(el, importerPath, rewriteImportPath, legacyCommonJs) {
|
|
|
142
156
|
}
|
|
143
157
|
return c.join("");
|
|
144
158
|
}
|
|
145
|
-
function printableToEl(
|
|
159
|
+
function printableToEl(opt, printables) {
|
|
160
|
+
const { el } = opt;
|
|
146
161
|
for (const p of printables) {
|
|
147
162
|
if (Array.isArray(p)) {
|
|
148
|
-
printableToEl(
|
|
163
|
+
printableToEl(opt, p);
|
|
149
164
|
}
|
|
150
165
|
else {
|
|
151
166
|
switch (typeof p) {
|
|
@@ -153,52 +168,88 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
|
|
|
153
168
|
el.push(p);
|
|
154
169
|
break;
|
|
155
170
|
case "number":
|
|
156
|
-
|
|
171
|
+
if (Number.isNaN(p)) {
|
|
172
|
+
el.push("globalThis.NaN");
|
|
173
|
+
}
|
|
174
|
+
else if (p === Number.POSITIVE_INFINITY) {
|
|
175
|
+
el.push("globalThis.Infinity");
|
|
176
|
+
}
|
|
177
|
+
else if (p === Number.NEGATIVE_INFINITY) {
|
|
178
|
+
el.push("-globalThis.Infinity");
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
el.push(p.toString(10));
|
|
182
|
+
}
|
|
157
183
|
break;
|
|
158
184
|
case "boolean":
|
|
159
185
|
el.push(p.toString());
|
|
160
186
|
break;
|
|
161
187
|
case "bigint":
|
|
162
|
-
|
|
188
|
+
if (p == protoInt64.zero) {
|
|
189
|
+
// Loose comparison will match between 0n and 0.
|
|
190
|
+
el.push(opt.runtime.protoInt64, ".zero");
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
el.push(opt.runtime.protoInt64, p > 0 ? ".uParse(" : ".parse(", escapeString(p.toString()), ")");
|
|
194
|
+
}
|
|
163
195
|
break;
|
|
164
196
|
case "object":
|
|
165
197
|
if (p instanceof Uint8Array) {
|
|
166
|
-
|
|
198
|
+
if (p.length === 0) {
|
|
199
|
+
el.push("new Uint8Array(0)");
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
el.push("new Uint8Array([");
|
|
203
|
+
const strings = [];
|
|
204
|
+
for (const n of p) {
|
|
205
|
+
strings.push("0x" + n.toString(16).toUpperCase().padStart(2, "0"));
|
|
206
|
+
}
|
|
207
|
+
el.push(strings.join(", "));
|
|
208
|
+
el.push("])");
|
|
209
|
+
}
|
|
167
210
|
break;
|
|
168
211
|
}
|
|
169
212
|
switch (p.kind) {
|
|
170
213
|
case "es_symbol":
|
|
214
|
+
case "es_export_stmt":
|
|
171
215
|
el.push(p);
|
|
172
216
|
break;
|
|
217
|
+
case "es_desc_ref":
|
|
218
|
+
el.push(opt.resolveDescImport(p.desc, p.typeOnly));
|
|
219
|
+
break;
|
|
220
|
+
case "es_shape_ref":
|
|
221
|
+
el.push(opt.resolveShapeImport(p.desc));
|
|
222
|
+
break;
|
|
173
223
|
case "es_jsdoc":
|
|
174
|
-
el.push(p.
|
|
224
|
+
el.push(formatJsDocBlock(p.text, p.indentation));
|
|
175
225
|
break;
|
|
176
226
|
case "es_string":
|
|
177
227
|
el.push(escapeString(p.value));
|
|
178
228
|
break;
|
|
179
229
|
case "es_proto_int64":
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
el.push(createTypeImport(p));
|
|
230
|
+
switch (p.longType) {
|
|
231
|
+
case LongType.STRING:
|
|
232
|
+
el.push(escapeString(p.value.toString()));
|
|
233
|
+
break;
|
|
234
|
+
case LongType.BIGINT:
|
|
235
|
+
if (p.value == protoInt64.zero) {
|
|
236
|
+
// Loose comparison will match between 0n and 0.
|
|
237
|
+
el.push(opt.runtime.protoInt64, ".zero");
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
switch (p.type) {
|
|
241
|
+
case ScalarType.UINT64:
|
|
242
|
+
case ScalarType.FIXED64:
|
|
243
|
+
el.push(opt.runtime.protoInt64, ".uParse(", escapeString(p.value.toString()), ")");
|
|
244
|
+
break;
|
|
245
|
+
default:
|
|
246
|
+
el.push(opt.runtime.protoInt64, ".parse(", escapeString(p.value.toString()), ")");
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
201
250
|
break;
|
|
251
|
+
default:
|
|
252
|
+
throw `cannot print ${typeof p}`;
|
|
202
253
|
}
|
|
203
254
|
break;
|
|
204
255
|
default:
|
|
@@ -323,70 +374,6 @@ function processImports(el, importerPath, rewriteImportPath, makeImportStatement
|
|
|
323
374
|
}
|
|
324
375
|
return symbolToIdentifier;
|
|
325
376
|
}
|
|
326
|
-
function elBigint(el, value, runtimeImports) {
|
|
327
|
-
if (value == protoInt64.zero) {
|
|
328
|
-
// Loose comparison will match between 0n and 0.
|
|
329
|
-
el.push(runtimeImports.protoInt64, ".zero");
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
el.push(runtimeImports.protoInt64, value > 0 ? ".uParse(" : ".parse(", escapeString(value.toString()), ")");
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
function elNumber(el, value, runtimeImports) {
|
|
336
|
-
if (Number.isNaN(value)) {
|
|
337
|
-
el.push(runtimeImports.protoDouble, ".NaN");
|
|
338
|
-
}
|
|
339
|
-
else if (value === Number.POSITIVE_INFINITY) {
|
|
340
|
-
el.push(runtimeImports.protoDouble, ".POSITIVE_INFINITY");
|
|
341
|
-
}
|
|
342
|
-
else if (value === Number.NEGATIVE_INFINITY) {
|
|
343
|
-
el.push(runtimeImports.protoDouble, ".NEGATIVE_INFINITY");
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
el.push(value.toString(10));
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
function elUint8Array(el, value) {
|
|
350
|
-
if (value.length === 0) {
|
|
351
|
-
el.push("new Uint8Array(0)");
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
el.push("new Uint8Array([");
|
|
355
|
-
const strings = [];
|
|
356
|
-
for (const n of value) {
|
|
357
|
-
strings.push("0x" + n.toString(16).toUpperCase().padStart(2, "0"));
|
|
358
|
-
}
|
|
359
|
-
el.push(strings.join(", "));
|
|
360
|
-
el.push("])");
|
|
361
|
-
}
|
|
362
|
-
function elProtoInt64(el, literal, runtimeImports) {
|
|
363
|
-
switch (literal.longType) {
|
|
364
|
-
case LongType.STRING:
|
|
365
|
-
el.push(escapeString(literal.value.toString()));
|
|
366
|
-
break;
|
|
367
|
-
case LongType.BIGINT:
|
|
368
|
-
if (literal.value == protoInt64.zero) {
|
|
369
|
-
// Loose comparison will match between 0n and 0.
|
|
370
|
-
el.push(runtimeImports.protoInt64, ".zero");
|
|
371
|
-
break;
|
|
372
|
-
}
|
|
373
|
-
switch (literal.type) {
|
|
374
|
-
case ScalarType.UINT64:
|
|
375
|
-
case ScalarType.FIXED64:
|
|
376
|
-
el.push(runtimeImports.protoInt64);
|
|
377
|
-
el.push(".uParse(");
|
|
378
|
-
el.push(escapeString(literal.value.toString()));
|
|
379
|
-
el.push(")");
|
|
380
|
-
break;
|
|
381
|
-
default:
|
|
382
|
-
el.push(runtimeImports.protoInt64);
|
|
383
|
-
el.push(".parse(");
|
|
384
|
-
el.push(escapeString(literal.value.toString()));
|
|
385
|
-
el.push(")");
|
|
386
|
-
break;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
377
|
function escapeString(value) {
|
|
391
378
|
return ('"' +
|
|
392
379
|
value
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { DescFile } from "@bufbuild/protobuf";
|
|
2
1
|
/**
|
|
3
2
|
* A configuration for rewriting import paths, a feature mainly used for
|
|
4
3
|
* remote code generation in the BSR npm registry, which makes it possible
|
|
@@ -44,11 +43,6 @@ export type RewriteImports = {
|
|
|
44
43
|
* to the given import extension.
|
|
45
44
|
*/
|
|
46
45
|
export declare function rewriteImportPath(importPath: string, rewriteImports: RewriteImports, importExtension: string): string;
|
|
47
|
-
/**
|
|
48
|
-
* Returns the import path for files generated by the base type generator
|
|
49
|
-
* protoc-gen-es.
|
|
50
|
-
*/
|
|
51
|
-
export declare function makeImportPath(file: DescFile, bootstrapWkt: boolean, filesToGenerate: DescFile[]): string;
|
|
52
46
|
export declare const relativePathRE: RegExp;
|
|
53
47
|
/**
|
|
54
48
|
* Derives an ECMAScript module import path from a file path. For example,
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
import { codegenInfo } from "@bufbuild/protobuf";
|
|
15
14
|
const cache = new WeakMap();
|
|
16
15
|
/**
|
|
17
16
|
* Apply import rewrites to the given import path, and change all .js extensions
|
|
@@ -81,25 +80,6 @@ function starToRegExp(star) {
|
|
|
81
80
|
r.push("$");
|
|
82
81
|
return new RegExp(r.join(""));
|
|
83
82
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Returns the import path for files generated by the base type generator
|
|
86
|
-
* protoc-gen-es.
|
|
87
|
-
*/
|
|
88
|
-
export function makeImportPath(file, bootstrapWkt, filesToGenerate) {
|
|
89
|
-
// Well-known types are published with the runtime package. We usually want
|
|
90
|
-
// the generated code to import them from the runtime package, with the
|
|
91
|
-
// following exceptions:
|
|
92
|
-
// 1. We are bootstrapping the runtime package via the plugin option
|
|
93
|
-
// "bootstrap_wkt". In that case, we cannot refer to the runtime package
|
|
94
|
-
// itself.
|
|
95
|
-
// 2. We were explicitly asked to generate the well-known type.
|
|
96
|
-
if (!bootstrapWkt &&
|
|
97
|
-
!filesToGenerate.includes(file) &&
|
|
98
|
-
codegenInfo.wktSourceFiles.includes(file.name + ".proto")) {
|
|
99
|
-
return codegenInfo.packageName;
|
|
100
|
-
}
|
|
101
|
-
return "./" + file.name + "_pb.js";
|
|
102
|
-
}
|
|
103
83
|
export const relativePathRE = /^\.{1,2}\//;
|
|
104
84
|
/**
|
|
105
85
|
* Derives an ECMAScript module import path from a file path. For example,
|
|
@@ -29,11 +29,9 @@ export type ImportSymbol = {
|
|
|
29
29
|
/**
|
|
30
30
|
* The unique ID based on name and from, disregarding typeOnly.
|
|
31
31
|
*/
|
|
32
|
-
readonly id:
|
|
32
|
+
readonly id: `import("${string}").${string}`;
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
35
|
* Create a new import symbol.
|
|
36
36
|
*/
|
|
37
37
|
export declare function createImportSymbol(name: string, from: string, typeOnly?: boolean): ImportSymbol;
|
|
38
|
-
type EsSymbolId = string;
|
|
39
|
-
export {};
|
|
@@ -15,16 +15,14 @@
|
|
|
15
15
|
* Create a new import symbol.
|
|
16
16
|
*/
|
|
17
17
|
export function createImportSymbol(name, from, typeOnly) {
|
|
18
|
-
|
|
19
|
-
const s = {
|
|
18
|
+
return {
|
|
20
19
|
kind: "es_symbol",
|
|
21
20
|
name,
|
|
22
21
|
from,
|
|
23
|
-
typeOnly: false,
|
|
24
|
-
id
|
|
22
|
+
typeOnly: typeOnly !== null && typeOnly !== void 0 ? typeOnly : false,
|
|
23
|
+
id: `import("${from}").${name}`,
|
|
25
24
|
toTypeOnly() {
|
|
26
25
|
return Object.assign(Object.assign({}, this), { typeOnly: true });
|
|
27
26
|
},
|
|
28
27
|
};
|
|
29
|
-
return typeOnly === true ? s.toTypeOnly() : s;
|
|
30
28
|
}
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
import type { AnyDesc, DescExtension, DescFile } from "@bufbuild/protobuf";
|
|
2
|
-
import type { Printable } from "./generated-file.js";
|
|
3
|
-
export { reifyWkt } from "./reify-wkt.js";
|
|
4
1
|
export type { Target } from "./target.js";
|
|
5
2
|
export type { Schema } from "./schema.js";
|
|
6
|
-
export type {
|
|
7
|
-
export type { GeneratedFile, FileInfo, Printable } from "./generated-file.js";
|
|
3
|
+
export type { GeneratedFile, FileInfo } from "./generated-file.js";
|
|
8
4
|
export type { ImportSymbol } from "./import-symbol.js";
|
|
9
5
|
export { createImportSymbol } from "./import-symbol.js";
|
|
10
|
-
export
|
|
11
|
-
export {
|
|
12
|
-
export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./legacy-custom-options.js";
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated Please use GeneratedFile.jsDoc() instead
|
|
15
|
-
*/
|
|
16
|
-
export declare function makeJsDoc(desc: Exclude<AnyDesc, DescFile | DescExtension>, indentation?: string): Printable;
|
|
17
|
-
/**
|
|
18
|
-
* @deprecated Please use GeneratedFile.jsDoc() instead
|
|
19
|
-
*/
|
|
20
|
-
export declare function createJsDocBlock(text: string, indentation?: string): Printable;
|
|
6
|
+
export type { Printable } from "./printable.js";
|
|
7
|
+
export { safeIdentifier } from "./safe-identifier.js";
|
|
@@ -11,22 +11,5 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
import { codegenInfo } from "@bufbuild/protobuf";
|
|
15
|
-
import { createJsDocBlock as createJsDocBlockInternal } from "./jsdoc.js";
|
|
16
|
-
export { reifyWkt } from "./reify-wkt.js";
|
|
17
14
|
export { createImportSymbol } from "./import-symbol.js";
|
|
18
|
-
export
|
|
19
|
-
export { getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, literalString, } from "./legacy-gencommon.js";
|
|
20
|
-
export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./legacy-custom-options.js";
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated Please use GeneratedFile.jsDoc() instead
|
|
23
|
-
*/
|
|
24
|
-
export function makeJsDoc(desc, indentation = "") {
|
|
25
|
-
return createJsDocBlockInternal(desc, indentation).toString();
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated Please use GeneratedFile.jsDoc() instead
|
|
29
|
-
*/
|
|
30
|
-
export function createJsDocBlock(text, indentation = "") {
|
|
31
|
-
return createJsDocBlockInternal(text, indentation).toString();
|
|
32
|
-
}
|
|
15
|
+
export { safeIdentifier } from "./safe-identifier.js";
|
|
@@ -1,14 +1,3 @@
|
|
|
1
1
|
import type { AnyDesc, DescFile } from "@bufbuild/protobuf";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated In a future release, we will make this property optional.
|
|
6
|
-
*/
|
|
7
|
-
text: string;
|
|
8
|
-
indentation?: string;
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated In a future release, we will remove this method.
|
|
11
|
-
*/
|
|
12
|
-
toString(): string;
|
|
13
|
-
};
|
|
14
|
-
export declare function createJsDocBlock(textOrDesc: string | Exclude<AnyDesc, DescFile>, indentation?: string): JSDocBlock;
|
|
2
|
+
export declare function createJsDocTextFromDesc(desc: Exclude<AnyDesc, DescFile>): string;
|
|
3
|
+
export declare function formatJsDocBlock(text: string, indentation: string | undefined): string;
|
|
@@ -11,31 +11,10 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
kind: "es_jsdoc",
|
|
19
|
-
text,
|
|
20
|
-
indentation,
|
|
21
|
-
toString() {
|
|
22
|
-
if (text.trim().length == 0) {
|
|
23
|
-
return "";
|
|
24
|
-
}
|
|
25
|
-
let lines = text.split("\n");
|
|
26
|
-
if (lines.length === 0) {
|
|
27
|
-
return "";
|
|
28
|
-
}
|
|
29
|
-
lines = lines.map((l) => l.split("*/").join("*\\/"));
|
|
30
|
-
lines = lines.map((l) => (l.length > 0 ? " " + l : l));
|
|
31
|
-
const i = indentation !== null && indentation !== void 0 ? indentation : "";
|
|
32
|
-
return [`${i}/**\n`, ...lines.map((l) => `${i} *${l}\n`), `${i} */`].join("");
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function createTextForDesc(desc) {
|
|
37
|
-
var _a, _b;
|
|
38
|
-
const comments = desc.getComments();
|
|
14
|
+
import { getComments, getDeclarationString, getFeatureOptionStrings, } from "../source-code-info.js";
|
|
15
|
+
import { parentTypes } from "@bufbuild/protobuf/reflect";
|
|
16
|
+
export function createJsDocTextFromDesc(desc) {
|
|
17
|
+
const comments = getComments(desc);
|
|
39
18
|
let text = "";
|
|
40
19
|
if (comments.leading !== undefined) {
|
|
41
20
|
text += comments.leading;
|
|
@@ -61,26 +40,37 @@ function createTextForDesc(desc) {
|
|
|
61
40
|
.join("\n");
|
|
62
41
|
switch (desc.kind) {
|
|
63
42
|
case "enum_value":
|
|
64
|
-
text += `@generated from enum value: ${desc
|
|
43
|
+
text += `@generated from enum value: ${getDeclarationString(desc)};`;
|
|
65
44
|
break;
|
|
66
45
|
case "field":
|
|
67
|
-
text += `@generated from field: ${desc
|
|
46
|
+
text += `@generated from field: ${getDeclarationString(desc)};`;
|
|
68
47
|
break;
|
|
69
48
|
case "extension":
|
|
70
|
-
text += `@generated from extension: ${desc
|
|
49
|
+
text += `@generated from extension: ${getDeclarationString(desc)};`;
|
|
50
|
+
break;
|
|
51
|
+
case "message":
|
|
52
|
+
case "enum": {
|
|
53
|
+
text += `@generated from ${desc.toString()}`;
|
|
54
|
+
const featureOptions = getFeatureOptionStrings(desc);
|
|
55
|
+
if (featureOptions.length > 0) {
|
|
56
|
+
text += `\n@generated with ${featureOptions.length > 1 ? "options" : "option"} ${featureOptions.join(", ")}`;
|
|
57
|
+
}
|
|
71
58
|
break;
|
|
59
|
+
}
|
|
72
60
|
default:
|
|
73
61
|
text += `@generated from ${desc.toString()}`;
|
|
74
62
|
break;
|
|
75
63
|
}
|
|
76
|
-
let deprecated
|
|
64
|
+
let deprecated;
|
|
77
65
|
switch (desc.kind) {
|
|
78
|
-
case "
|
|
79
|
-
case "
|
|
80
|
-
case "
|
|
81
|
-
deprecated =
|
|
66
|
+
case "field":
|
|
67
|
+
case "enum_value":
|
|
68
|
+
case "rpc":
|
|
69
|
+
deprecated = desc.deprecated;
|
|
82
70
|
break;
|
|
83
71
|
default:
|
|
72
|
+
deprecated =
|
|
73
|
+
desc.deprecated || parentTypes(desc).some((d) => d.deprecated);
|
|
84
74
|
break;
|
|
85
75
|
}
|
|
86
76
|
if (deprecated) {
|
|
@@ -88,3 +78,16 @@ function createTextForDesc(desc) {
|
|
|
88
78
|
}
|
|
89
79
|
return text;
|
|
90
80
|
}
|
|
81
|
+
export function formatJsDocBlock(text, indentation) {
|
|
82
|
+
if (text.trim().length == 0) {
|
|
83
|
+
return "";
|
|
84
|
+
}
|
|
85
|
+
let lines = text.split("\n");
|
|
86
|
+
if (lines.length === 0) {
|
|
87
|
+
return "";
|
|
88
|
+
}
|
|
89
|
+
lines = lines.map((l) => l.split("*/").join("*\\/"));
|
|
90
|
+
lines = lines.map((l) => (l.length > 0 ? " " + l : l));
|
|
91
|
+
const i = indentation !== null && indentation !== void 0 ? indentation : "";
|
|
92
|
+
return [`${i}/**\n`, ...lines.map((l) => `${i} *${l}\n`), `${i} */`].join("");
|
|
93
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DescEnum, DescExtension, DescFile, DescMessage, DescService } from "@bufbuild/protobuf";
|
|
2
|
+
export declare function generateFilePath(file: DescFile, bootstrapWkt: boolean, filesToGenerate: DescFile[]): string;
|
|
3
|
+
export declare function localDescName(desc: DescFile | DescEnum | DescMessage | DescExtension | DescService): string;
|
|
4
|
+
export declare function localShapeName(desc: DescEnum | DescMessage): string;
|