@bufbuild/protoplugin 1.7.2 → 1.8.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/dist/cjs/ecmascript/file-preamble.d.ts +2 -0
- package/dist/cjs/ecmascript/file-preamble.js +74 -0
- package/dist/cjs/ecmascript/generated-file.d.ts +3 -3
- package/dist/cjs/ecmascript/generated-file.js +90 -31
- package/dist/cjs/ecmascript/index.d.ts +2 -6
- package/dist/cjs/ecmascript/index.js +10 -17
- package/dist/cjs/ecmascript/jsdoc.d.ts +6 -0
- package/dist/cjs/ecmascript/jsdoc.js +1 -0
- package/dist/cjs/ecmascript/{gencommon.d.ts → legacy-gencommon.d.ts} +12 -6
- package/dist/cjs/ecmascript/{gencommon.js → legacy-gencommon.js} +50 -98
- package/dist/cjs/ecmascript/opaque-printables.d.ts +26 -0
- package/dist/{esm/ecmascript/export-declaration.js → cjs/ecmascript/opaque-printables.js} +2 -7
- package/dist/cjs/ecmascript/schema.d.ts +1 -1
- package/dist/cjs/ecmascript/schema.js +2 -2
- package/dist/cjs/error.d.ts +2 -0
- package/dist/cjs/error.js +9 -1
- package/dist/cjs/run-node.js +1 -1
- package/dist/esm/ecmascript/file-preamble.d.ts +2 -0
- package/dist/esm/ecmascript/file-preamble.js +70 -0
- package/dist/esm/ecmascript/generated-file.d.ts +3 -3
- package/dist/esm/ecmascript/generated-file.js +90 -31
- package/dist/esm/ecmascript/index.d.ts +2 -6
- package/dist/esm/ecmascript/index.js +2 -9
- package/dist/esm/ecmascript/jsdoc.d.ts +6 -0
- package/dist/esm/ecmascript/jsdoc.js +1 -0
- package/dist/esm/ecmascript/{gencommon.d.ts → legacy-gencommon.d.ts} +12 -6
- package/dist/esm/ecmascript/{gencommon.js → legacy-gencommon.js} +49 -95
- package/dist/esm/ecmascript/opaque-printables.d.ts +26 -0
- package/dist/{cjs/ecmascript/export-declaration.js → esm/ecmascript/opaque-printables.js} +1 -11
- package/dist/esm/ecmascript/schema.d.ts +1 -1
- package/dist/esm/ecmascript/schema.js +1 -1
- package/dist/esm/error.d.ts +2 -0
- package/dist/esm/error.js +7 -0
- package/dist/esm/run-node.js +2 -2
- package/package.json +3 -14
- package/dist/cjs/ecmascript/export-declaration.d.ts +0 -7
- package/dist/esm/ecmascript/export-declaration.d.ts +0 -7
- package/dist/proxy/ecmascript/index.d.ts +0 -1
- package/dist/proxy/ecmascript/index.js +0 -1
- package/dist/proxy/index.d.ts +0 -1
- package/dist/proxy/index.js +0 -1
- /package/dist/cjs/ecmascript/{custom-options.d.ts → legacy-custom-options.d.ts} +0 -0
- /package/dist/cjs/ecmascript/{custom-options.js → legacy-custom-options.js} +0 -0
- /package/dist/esm/ecmascript/{custom-options.d.ts → legacy-custom-options.d.ts} +0 -0
- /package/dist/esm/ecmascript/{custom-options.js → legacy-custom-options.js} +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.makeFilePreamble = void 0;
|
|
17
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
18
|
+
function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsNoCheck) {
|
|
19
|
+
const builder = [];
|
|
20
|
+
const trimSuffix = (str, suffix) => str.endsWith(suffix) ? str.substring(0, str.length - suffix.length) : str;
|
|
21
|
+
const writeLeadingComments = (comments) => {
|
|
22
|
+
for (let comment of comments.leadingDetached) {
|
|
23
|
+
comment = trimSuffix(comment, "\n");
|
|
24
|
+
for (const line of comment.split("\n")) {
|
|
25
|
+
builder.push(`//${line}\n`);
|
|
26
|
+
}
|
|
27
|
+
builder.push("\n");
|
|
28
|
+
}
|
|
29
|
+
if (comments.leading !== undefined) {
|
|
30
|
+
const comment = trimSuffix(comments.leading, "\n");
|
|
31
|
+
for (const line of comment.split("\n")) {
|
|
32
|
+
builder.push(`//${line}\n`);
|
|
33
|
+
}
|
|
34
|
+
builder.push("\n");
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
writeLeadingComments(file.getSyntaxComments());
|
|
38
|
+
builder.push(`// @generated by ${pluginName} ${pluginVersion}`);
|
|
39
|
+
if (parameter !== "") {
|
|
40
|
+
builder.push(` with parameter "${parameter}"`);
|
|
41
|
+
}
|
|
42
|
+
builder.push("\n");
|
|
43
|
+
builder.push(`// @generated from file ${file.name}.proto (`);
|
|
44
|
+
if (file.proto.package !== undefined) {
|
|
45
|
+
builder.push(`package ${file.proto.package}, `);
|
|
46
|
+
}
|
|
47
|
+
switch (file.edition) {
|
|
48
|
+
case protobuf_1.Edition.EDITION_PROTO2:
|
|
49
|
+
builder.push(`syntax proto2)\n`);
|
|
50
|
+
break;
|
|
51
|
+
case protobuf_1.Edition.EDITION_PROTO3:
|
|
52
|
+
builder.push(`syntax proto3)\n`);
|
|
53
|
+
break;
|
|
54
|
+
default: {
|
|
55
|
+
const editionString = protobuf_1.Edition[file.edition];
|
|
56
|
+
if (typeof editionString == "string") {
|
|
57
|
+
const e = editionString.replace("EDITION_", "").toLowerCase();
|
|
58
|
+
builder.push(`edition ${e})\n`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
builder.push(`unknown edition\n`);
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
builder.push("/* eslint-disable */\n");
|
|
67
|
+
if (tsNoCheck) {
|
|
68
|
+
builder.push("// @ts-nocheck\n");
|
|
69
|
+
}
|
|
70
|
+
builder.push("\n");
|
|
71
|
+
writeLeadingComments(file.getPackageComments());
|
|
72
|
+
return trimSuffix(builder.join(""), "\n");
|
|
73
|
+
}
|
|
74
|
+
exports.makeFilePreamble = makeFilePreamble;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AnyDesc, DescEnum, DescExtension, DescFile, DescMessage } from "@bufbuild/protobuf";
|
|
2
2
|
import type { ImportSymbol } from "./import-symbol.js";
|
|
3
3
|
import type { RuntimeImports } from "./runtime-imports.js";
|
|
4
|
-
import type { ExportDeclaration } from "./export-declaration.js";
|
|
5
4
|
import type { JSDocBlock } from "./jsdoc.js";
|
|
5
|
+
import { ExportDeclaration, LiteralProtoInt64, LiteralString, RefDescEnum, RefDescMessage } from "./opaque-printables.js";
|
|
6
6
|
/**
|
|
7
7
|
* All types that can be passed to GeneratedFile.print()
|
|
8
8
|
*/
|
|
9
|
-
export type Printable = string | number | boolean | bigint | Uint8Array | ImportSymbol | ExportDeclaration | JSDocBlock | DescMessage | DescEnum | DescExtension | Printable[];
|
|
9
|
+
export type Printable = string | number | boolean | bigint | Uint8Array | ImportSymbol | ExportDeclaration | JSDocBlock | LiteralString | LiteralProtoInt64 | RefDescMessage | RefDescEnum | DescMessage | DescEnum | DescExtension | Printable[];
|
|
10
10
|
/**
|
|
11
11
|
* FileInfo represents an intermediate type using for transpiling TypeScript internally.
|
|
12
12
|
*/
|
|
@@ -14,10 +14,9 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.createGeneratedFile = void 0;
|
|
17
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
17
18
|
const import_symbol_js_1 = require("./import-symbol.js");
|
|
18
|
-
const gencommon_js_1 = require("./gencommon.js");
|
|
19
19
|
const import_path_js_1 = require("./import-path.js");
|
|
20
|
-
const export_declaration_js_1 = require("./export-declaration.js");
|
|
21
20
|
const jsdoc_js_1 = require("./jsdoc.js");
|
|
22
21
|
function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath, createTypeImport, runtimeImports, createPreamble) {
|
|
23
22
|
let preamble;
|
|
@@ -47,10 +46,15 @@ function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath,
|
|
|
47
46
|
return (0, import_symbol_js_1.createImportSymbol)(name, importPath);
|
|
48
47
|
},
|
|
49
48
|
exportDecl(declaration, name) {
|
|
50
|
-
return
|
|
49
|
+
return {
|
|
50
|
+
kind: "es_export_decl",
|
|
51
|
+
declaration,
|
|
52
|
+
name,
|
|
53
|
+
};
|
|
51
54
|
},
|
|
52
55
|
string(string) {
|
|
53
|
-
|
|
56
|
+
// We do not use LiteralString, which was added later, to maintain backwards compatibility
|
|
57
|
+
return escapeString(string);
|
|
54
58
|
},
|
|
55
59
|
jsDoc(textOrDesc, indentation) {
|
|
56
60
|
return (0, jsdoc_js_1.createJsDocBlock)(textOrDesc, indentation);
|
|
@@ -87,16 +91,16 @@ function elToContent(el, importerPath, rewriteImportPath, legacyCommonJs) {
|
|
|
87
91
|
if (legacyCommonJs) {
|
|
88
92
|
const p = names.map(({ name, alias }) => alias == undefined ? name : `${name}: ${alias}`);
|
|
89
93
|
const what = `{ ${p.join(", ")} }`;
|
|
90
|
-
c.push(`const ${what} = require(${(
|
|
94
|
+
c.push(`const ${what} = require(${escapeString(from)});\n`);
|
|
91
95
|
}
|
|
92
96
|
else {
|
|
93
97
|
const p = names.map(({ name, alias }) => alias == undefined ? name : `${name} as ${alias}`);
|
|
94
98
|
const what = `{ ${p.join(", ")} }`;
|
|
95
99
|
if (typeOnly) {
|
|
96
|
-
c.push(`import type ${what} from ${(
|
|
100
|
+
c.push(`import type ${what} from ${escapeString(from)};\n`);
|
|
97
101
|
}
|
|
98
102
|
else {
|
|
99
|
-
c.push(`import ${what} from ${(
|
|
103
|
+
c.push(`import ${what} from ${escapeString(from)};\n`);
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
106
|
});
|
|
@@ -153,17 +157,17 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
|
|
|
153
157
|
el.push(p);
|
|
154
158
|
break;
|
|
155
159
|
case "number":
|
|
156
|
-
el
|
|
160
|
+
elNumber(el, p, runtimeImports);
|
|
157
161
|
break;
|
|
158
162
|
case "boolean":
|
|
159
163
|
el.push(p.toString());
|
|
160
164
|
break;
|
|
161
165
|
case "bigint":
|
|
162
|
-
el
|
|
166
|
+
elBigint(el, p, runtimeImports);
|
|
163
167
|
break;
|
|
164
168
|
case "object":
|
|
165
169
|
if (p instanceof Uint8Array) {
|
|
166
|
-
el
|
|
170
|
+
elUint8Array(el, p);
|
|
167
171
|
break;
|
|
168
172
|
}
|
|
169
173
|
switch (p.kind) {
|
|
@@ -173,6 +177,12 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
|
|
|
173
177
|
case "es_jsdoc":
|
|
174
178
|
el.push(p.toString());
|
|
175
179
|
break;
|
|
180
|
+
case "es_string":
|
|
181
|
+
el.push(escapeString(p.value));
|
|
182
|
+
break;
|
|
183
|
+
case "es_proto_int64":
|
|
184
|
+
elProtoInt64(el, p, runtimeImports);
|
|
185
|
+
break;
|
|
176
186
|
case "es_export_decl":
|
|
177
187
|
el.push({
|
|
178
188
|
kind: "es_export_stmt",
|
|
@@ -182,6 +192,12 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
|
|
|
182
192
|
: createTypeImport(p.name).name,
|
|
183
193
|
});
|
|
184
194
|
break;
|
|
195
|
+
case "es_ref_message":
|
|
196
|
+
case "es_ref_enum":
|
|
197
|
+
el.push(p.typeOnly
|
|
198
|
+
? createTypeImport(p.type).toTypeOnly()
|
|
199
|
+
: createTypeImport(p.type));
|
|
200
|
+
break;
|
|
185
201
|
case "message":
|
|
186
202
|
case "extension":
|
|
187
203
|
case "enum":
|
|
@@ -311,37 +327,80 @@ function processImports(el, importerPath, rewriteImportPath, makeImportStatement
|
|
|
311
327
|
}
|
|
312
328
|
return symbolToIdentifier;
|
|
313
329
|
}
|
|
314
|
-
function
|
|
330
|
+
function elBigint(el, value, runtimeImports) {
|
|
331
|
+
if (value == protobuf_1.protoInt64.zero) {
|
|
332
|
+
// Loose comparison will match between 0n and 0.
|
|
333
|
+
el.push(runtimeImports.protoInt64, ".zero");
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
el.push(runtimeImports.protoInt64, value > 0 ? ".uParse(" : ".parse(", escapeString(value.toString()), ")");
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function elNumber(el, value, runtimeImports) {
|
|
315
340
|
if (Number.isNaN(value)) {
|
|
316
|
-
|
|
341
|
+
el.push(runtimeImports.protoDouble, ".NaN");
|
|
317
342
|
}
|
|
318
|
-
if (value === Number.POSITIVE_INFINITY) {
|
|
319
|
-
|
|
343
|
+
else if (value === Number.POSITIVE_INFINITY) {
|
|
344
|
+
el.push(runtimeImports.protoDouble, ".POSITIVE_INFINITY");
|
|
320
345
|
}
|
|
321
|
-
if (value === Number.NEGATIVE_INFINITY) {
|
|
322
|
-
|
|
346
|
+
else if (value === Number.NEGATIVE_INFINITY) {
|
|
347
|
+
el.push(runtimeImports.protoDouble, ".NEGATIVE_INFINITY");
|
|
323
348
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
function literalBigint(value, runtimeImports) {
|
|
327
|
-
// Loose comparison will match between 0n and 0.
|
|
328
|
-
if (value == 0) {
|
|
329
|
-
return [runtimeImports.protoInt64, ".zero"];
|
|
349
|
+
else {
|
|
350
|
+
el.push(value.toString(10));
|
|
330
351
|
}
|
|
331
|
-
return [
|
|
332
|
-
runtimeImports.protoInt64,
|
|
333
|
-
value > 0 ? ".uParse(" : ".parse(",
|
|
334
|
-
(0, gencommon_js_1.literalString)(value.toString()),
|
|
335
|
-
")",
|
|
336
|
-
];
|
|
337
352
|
}
|
|
338
|
-
function
|
|
353
|
+
function elUint8Array(el, value) {
|
|
339
354
|
if (value.length === 0) {
|
|
340
|
-
|
|
355
|
+
el.push("new Uint8Array(0)");
|
|
356
|
+
return;
|
|
341
357
|
}
|
|
358
|
+
el.push("new Uint8Array([");
|
|
342
359
|
const strings = [];
|
|
343
360
|
for (const n of value) {
|
|
344
361
|
strings.push("0x" + n.toString(16).toUpperCase().padStart(2, "0"));
|
|
345
362
|
}
|
|
346
|
-
|
|
363
|
+
el.push(strings.join(", "));
|
|
364
|
+
el.push("])");
|
|
365
|
+
}
|
|
366
|
+
function elProtoInt64(el, literal, runtimeImports) {
|
|
367
|
+
switch (literal.longType) {
|
|
368
|
+
case protobuf_1.LongType.STRING:
|
|
369
|
+
el.push(escapeString(literal.value.toString()));
|
|
370
|
+
break;
|
|
371
|
+
case protobuf_1.LongType.BIGINT:
|
|
372
|
+
if (literal.value == protobuf_1.protoInt64.zero) {
|
|
373
|
+
// Loose comparison will match between 0n and 0.
|
|
374
|
+
el.push(runtimeImports.protoInt64, ".zero");
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
switch (literal.type) {
|
|
378
|
+
case protobuf_1.ScalarType.UINT64:
|
|
379
|
+
case protobuf_1.ScalarType.FIXED64:
|
|
380
|
+
el.push(runtimeImports.protoInt64);
|
|
381
|
+
el.push(".uParse(");
|
|
382
|
+
el.push(escapeString(literal.value.toString()));
|
|
383
|
+
el.push(")");
|
|
384
|
+
break;
|
|
385
|
+
default:
|
|
386
|
+
el.push(runtimeImports.protoInt64);
|
|
387
|
+
el.push(".parse(");
|
|
388
|
+
el.push(escapeString(literal.value.toString()));
|
|
389
|
+
el.push(")");
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function escapeString(value) {
|
|
395
|
+
return ('"' +
|
|
396
|
+
value
|
|
397
|
+
.split("\\")
|
|
398
|
+
.join("\\\\")
|
|
399
|
+
.split('"')
|
|
400
|
+
.join('\\"')
|
|
401
|
+
.split("\r")
|
|
402
|
+
.join("\\r")
|
|
403
|
+
.split("\n")
|
|
404
|
+
.join("\\n") +
|
|
405
|
+
'"');
|
|
347
406
|
}
|
|
@@ -8,12 +8,8 @@ export type { GeneratedFile, FileInfo, Printable } from "./generated-file.js";
|
|
|
8
8
|
export type { ImportSymbol } from "./import-symbol.js";
|
|
9
9
|
export { createImportSymbol } from "./import-symbol.js";
|
|
10
10
|
export declare const localName: (desc: import("@bufbuild/protobuf").DescEnum | import("@bufbuild/protobuf").DescMessage | import("@bufbuild/protobuf").DescService | DescExtension | import("@bufbuild/protobuf").DescEnumValue | import("@bufbuild/protobuf").DescField | import("@bufbuild/protobuf").DescOneof | import("@bufbuild/protobuf").DescMethod) => string;
|
|
11
|
-
export { getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, } from "./gencommon.js";
|
|
12
|
-
export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./custom-options.js";
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated Please use GeneratedFile.string() instead
|
|
15
|
-
*/
|
|
16
|
-
export declare function literalString(value: string): string;
|
|
11
|
+
export { getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, literalString, } from "./legacy-gencommon.js";
|
|
12
|
+
export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./legacy-custom-options.js";
|
|
17
13
|
/**
|
|
18
14
|
* @deprecated Please use GeneratedFile.jsDoc() instead
|
|
19
15
|
*/
|
|
@@ -13,30 +13,23 @@
|
|
|
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.createJsDocBlock = exports.makeJsDoc = exports.
|
|
16
|
+
exports.createJsDocBlock = exports.makeJsDoc = exports.findCustomEnumOption = exports.findCustomMessageOption = exports.findCustomScalarOption = exports.literalString = exports.getFieldTyping = exports.getFieldIntrinsicDefaultValue = exports.getFieldExplicitDefaultValue = exports.localName = exports.createImportSymbol = exports.reifyWkt = void 0;
|
|
17
17
|
const protobuf_1 = require("@bufbuild/protobuf");
|
|
18
18
|
const jsdoc_js_1 = require("./jsdoc.js");
|
|
19
|
-
const gencommon_js_1 = require("./gencommon.js");
|
|
20
19
|
var reify_wkt_js_1 = require("./reify-wkt.js");
|
|
21
20
|
Object.defineProperty(exports, "reifyWkt", { enumerable: true, get: function () { return reify_wkt_js_1.reifyWkt; } });
|
|
22
21
|
var import_symbol_js_1 = require("./import-symbol.js");
|
|
23
22
|
Object.defineProperty(exports, "createImportSymbol", { enumerable: true, get: function () { return import_symbol_js_1.createImportSymbol; } });
|
|
24
23
|
exports.localName = protobuf_1.codegenInfo.localName;
|
|
25
|
-
var
|
|
26
|
-
Object.defineProperty(exports, "getFieldExplicitDefaultValue", { enumerable: true, get: function () { return
|
|
27
|
-
Object.defineProperty(exports, "getFieldIntrinsicDefaultValue", { enumerable: true, get: function () { return
|
|
28
|
-
Object.defineProperty(exports, "getFieldTyping", { enumerable: true, get: function () { return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
Object.defineProperty(exports, "
|
|
32
|
-
Object.defineProperty(exports, "
|
|
33
|
-
|
|
34
|
-
* @deprecated Please use GeneratedFile.string() instead
|
|
35
|
-
*/
|
|
36
|
-
function literalString(value) {
|
|
37
|
-
return (0, gencommon_js_1.literalString)(value);
|
|
38
|
-
}
|
|
39
|
-
exports.literalString = literalString;
|
|
24
|
+
var legacy_gencommon_js_1 = require("./legacy-gencommon.js");
|
|
25
|
+
Object.defineProperty(exports, "getFieldExplicitDefaultValue", { enumerable: true, get: function () { return legacy_gencommon_js_1.getFieldExplicitDefaultValue; } });
|
|
26
|
+
Object.defineProperty(exports, "getFieldIntrinsicDefaultValue", { enumerable: true, get: function () { return legacy_gencommon_js_1.getFieldIntrinsicDefaultValue; } });
|
|
27
|
+
Object.defineProperty(exports, "getFieldTyping", { enumerable: true, get: function () { return legacy_gencommon_js_1.getFieldTyping; } });
|
|
28
|
+
Object.defineProperty(exports, "literalString", { enumerable: true, get: function () { return legacy_gencommon_js_1.literalString; } });
|
|
29
|
+
var legacy_custom_options_js_1 = require("./legacy-custom-options.js");
|
|
30
|
+
Object.defineProperty(exports, "findCustomScalarOption", { enumerable: true, get: function () { return legacy_custom_options_js_1.findCustomScalarOption; } });
|
|
31
|
+
Object.defineProperty(exports, "findCustomMessageOption", { enumerable: true, get: function () { return legacy_custom_options_js_1.findCustomMessageOption; } });
|
|
32
|
+
Object.defineProperty(exports, "findCustomEnumOption", { enumerable: true, get: function () { return legacy_custom_options_js_1.findCustomEnumOption; } });
|
|
40
33
|
/**
|
|
41
34
|
* @deprecated Please use GeneratedFile.jsDoc() instead
|
|
42
35
|
*/
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { AnyDesc, DescFile } from "@bufbuild/protobuf";
|
|
2
2
|
export type JSDocBlock = {
|
|
3
3
|
readonly kind: "es_jsdoc";
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated In a future release, we will make this property optional.
|
|
6
|
+
*/
|
|
4
7
|
text: string;
|
|
5
8
|
indentation?: string;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated In a future release, we will remove this method.
|
|
11
|
+
*/
|
|
6
12
|
toString(): string;
|
|
7
13
|
};
|
|
8
14
|
export declare function createJsDocBlock(textOrDesc: string | Exclude<AnyDesc, DescFile>, indentation?: string): JSDocBlock;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.createJsDocBlock = void 0;
|
|
17
|
+
// TODO simplify type JSDocBlock to bring it in line with others in opaque-printables.ts
|
|
17
18
|
function createJsDocBlock(textOrDesc, indentation) {
|
|
18
19
|
const text = typeof textOrDesc == "string" ? textOrDesc : createTextForDesc(textOrDesc);
|
|
19
20
|
return {
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import type { DescExtension } from "@bufbuild/protobuf";
|
|
2
|
-
import { DescField
|
|
2
|
+
import { DescField } from "@bufbuild/protobuf";
|
|
3
3
|
import type { GeneratedFile, Printable } from "./generated-file.js";
|
|
4
4
|
import type { ImportSymbol } from "./import-symbol.js";
|
|
5
|
-
export declare function makeFilePreamble(file: DescFile, pluginName: string, pluginVersion: string, parameter: string, tsNoCheck: boolean): string;
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
8
|
-
|
|
6
|
+
* @deprecated Please use GeneratedFile.string() instead
|
|
7
|
+
*/
|
|
8
|
+
export declare function literalString(value: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated
|
|
9
11
|
*/
|
|
10
12
|
export declare function getFieldTyping(field: DescField | DescExtension, file: GeneratedFile): {
|
|
11
13
|
typing: Printable;
|
|
12
14
|
optional: boolean;
|
|
13
15
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated
|
|
18
|
+
*/
|
|
16
19
|
export declare function getFieldExplicitDefaultValue(field: DescField | DescExtension, protoInt64Symbol: ImportSymbol): Printable | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated
|
|
22
|
+
*/
|
|
17
23
|
export declare function getFieldIntrinsicDefaultValue(field: DescField): {
|
|
18
24
|
defaultValue: Printable | undefined;
|
|
19
25
|
typingInferrable: boolean;
|
|
@@ -13,69 +13,28 @@
|
|
|
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.getFieldIntrinsicDefaultValue = exports.getFieldExplicitDefaultValue = exports.
|
|
16
|
+
exports.getFieldIntrinsicDefaultValue = exports.getFieldExplicitDefaultValue = exports.getFieldTyping = exports.literalString = void 0;
|
|
17
17
|
const protobuf_1 = require("@bufbuild/protobuf");
|
|
18
|
-
const { localName, getUnwrappedFieldType,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
builder.push("\n");
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
writeLeadingComments(file.getSyntaxComments());
|
|
39
|
-
builder.push(`// @generated by ${pluginName} ${pluginVersion}`);
|
|
40
|
-
if (parameter !== "") {
|
|
41
|
-
builder.push(` with parameter "${parameter}"`);
|
|
42
|
-
}
|
|
43
|
-
builder.push("\n");
|
|
44
|
-
builder.push(`// @generated from file ${file.name}.proto (`);
|
|
45
|
-
if (file.proto.package !== undefined) {
|
|
46
|
-
builder.push(`package ${file.proto.package}, `);
|
|
47
|
-
}
|
|
48
|
-
switch (file.edition) {
|
|
49
|
-
case protobuf_1.Edition.EDITION_PROTO2:
|
|
50
|
-
builder.push(`syntax proto2)\n`);
|
|
51
|
-
break;
|
|
52
|
-
case protobuf_1.Edition.EDITION_PROTO3:
|
|
53
|
-
builder.push(`syntax proto3)\n`);
|
|
54
|
-
break;
|
|
55
|
-
default: {
|
|
56
|
-
const editionString = protobuf_1.Edition[file.edition];
|
|
57
|
-
if (typeof editionString == "string") {
|
|
58
|
-
const e = editionString.replace("EDITION_", "").toLowerCase();
|
|
59
|
-
builder.push(`edition ${e})\n`);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
builder.push(`unknown edition\n`);
|
|
63
|
-
}
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
builder.push("/* eslint-disable */\n");
|
|
68
|
-
if (tsNoCheck) {
|
|
69
|
-
builder.push("// @ts-nocheck\n");
|
|
70
|
-
}
|
|
71
|
-
builder.push("\n");
|
|
72
|
-
writeLeadingComments(file.getPackageComments());
|
|
73
|
-
return trimSuffix(builder.join(""), "\n");
|
|
18
|
+
const { localName, getUnwrappedFieldType, scalarZeroValue } = protobuf_1.codegenInfo;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Please use GeneratedFile.string() instead
|
|
21
|
+
*/
|
|
22
|
+
function literalString(value) {
|
|
23
|
+
return ('"' +
|
|
24
|
+
value
|
|
25
|
+
.split("\\")
|
|
26
|
+
.join("\\\\")
|
|
27
|
+
.split('"')
|
|
28
|
+
.join('\\"')
|
|
29
|
+
.split("\r")
|
|
30
|
+
.join("\\r")
|
|
31
|
+
.split("\n")
|
|
32
|
+
.join("\\n") +
|
|
33
|
+
'"');
|
|
74
34
|
}
|
|
75
|
-
exports.
|
|
35
|
+
exports.literalString = literalString;
|
|
76
36
|
/**
|
|
77
|
-
*
|
|
78
|
-
* and whether the property should be optional.
|
|
37
|
+
* @deprecated
|
|
79
38
|
*/
|
|
80
39
|
function getFieldTyping(field, file) {
|
|
81
40
|
const typing = [];
|
|
@@ -138,42 +97,9 @@ function getFieldTyping(field, file) {
|
|
|
138
97
|
return { typing, optional };
|
|
139
98
|
}
|
|
140
99
|
exports.getFieldTyping = getFieldTyping;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return "string";
|
|
145
|
-
case protobuf_1.ScalarType.BOOL:
|
|
146
|
-
return "boolean";
|
|
147
|
-
case protobuf_1.ScalarType.UINT64:
|
|
148
|
-
case protobuf_1.ScalarType.SFIXED64:
|
|
149
|
-
case protobuf_1.ScalarType.FIXED64:
|
|
150
|
-
case protobuf_1.ScalarType.SINT64:
|
|
151
|
-
case protobuf_1.ScalarType.INT64:
|
|
152
|
-
if (longType === protobuf_1.LongType.STRING) {
|
|
153
|
-
return "string";
|
|
154
|
-
}
|
|
155
|
-
return "bigint";
|
|
156
|
-
case protobuf_1.ScalarType.BYTES:
|
|
157
|
-
return "Uint8Array";
|
|
158
|
-
default:
|
|
159
|
-
return "number";
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
exports.scalarTypeScriptType = scalarTypeScriptType;
|
|
163
|
-
function literalString(value) {
|
|
164
|
-
return ('"' +
|
|
165
|
-
value
|
|
166
|
-
.split("\\")
|
|
167
|
-
.join("\\\\")
|
|
168
|
-
.split('"')
|
|
169
|
-
.join('\\"')
|
|
170
|
-
.split("\r")
|
|
171
|
-
.join("\\r")
|
|
172
|
-
.split("\n")
|
|
173
|
-
.join("\\n") +
|
|
174
|
-
'"');
|
|
175
|
-
}
|
|
176
|
-
exports.literalString = literalString;
|
|
100
|
+
/**
|
|
101
|
+
* @deprecated
|
|
102
|
+
*/
|
|
177
103
|
function getFieldExplicitDefaultValue(field, protoInt64Symbol) {
|
|
178
104
|
switch (field.fieldKind) {
|
|
179
105
|
case "enum": {
|
|
@@ -230,6 +156,9 @@ function getFieldExplicitDefaultValue(field, protoInt64Symbol) {
|
|
|
230
156
|
return undefined;
|
|
231
157
|
}
|
|
232
158
|
exports.getFieldExplicitDefaultValue = getFieldExplicitDefaultValue;
|
|
159
|
+
/**
|
|
160
|
+
* @deprecated
|
|
161
|
+
*/
|
|
233
162
|
function getFieldIntrinsicDefaultValue(field) {
|
|
234
163
|
if (field.repeated) {
|
|
235
164
|
return {
|
|
@@ -265,8 +194,7 @@ function getFieldIntrinsicDefaultValue(field) {
|
|
|
265
194
|
defaultValue = literalString("");
|
|
266
195
|
}
|
|
267
196
|
else {
|
|
268
|
-
|
|
269
|
-
defaultValue = scalarDefaultValue(field.scalar, field.longType);
|
|
197
|
+
defaultValue = scalarZeroValue(field.scalar, field.longType);
|
|
270
198
|
if (typeof defaultValue === "string") {
|
|
271
199
|
defaultValue = literalString(defaultValue);
|
|
272
200
|
}
|
|
@@ -283,3 +211,27 @@ function getFieldIntrinsicDefaultValue(field) {
|
|
|
283
211
|
};
|
|
284
212
|
}
|
|
285
213
|
exports.getFieldIntrinsicDefaultValue = getFieldIntrinsicDefaultValue;
|
|
214
|
+
/**
|
|
215
|
+
* @deprecated
|
|
216
|
+
*/
|
|
217
|
+
function scalarTypeScriptType(type, longType) {
|
|
218
|
+
switch (type) {
|
|
219
|
+
case protobuf_1.ScalarType.STRING:
|
|
220
|
+
return "string";
|
|
221
|
+
case protobuf_1.ScalarType.BOOL:
|
|
222
|
+
return "boolean";
|
|
223
|
+
case protobuf_1.ScalarType.UINT64:
|
|
224
|
+
case protobuf_1.ScalarType.SFIXED64:
|
|
225
|
+
case protobuf_1.ScalarType.FIXED64:
|
|
226
|
+
case protobuf_1.ScalarType.SINT64:
|
|
227
|
+
case protobuf_1.ScalarType.INT64:
|
|
228
|
+
if (longType === protobuf_1.LongType.STRING) {
|
|
229
|
+
return "string";
|
|
230
|
+
}
|
|
231
|
+
return "bigint";
|
|
232
|
+
case protobuf_1.ScalarType.BYTES:
|
|
233
|
+
return "Uint8Array";
|
|
234
|
+
default:
|
|
235
|
+
return "number";
|
|
236
|
+
}
|
|
237
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DescEnum, DescExtension, DescMessage, LongType, ScalarType } from "@bufbuild/protobuf";
|
|
2
|
+
export type LiteralProtoInt64 = {
|
|
3
|
+
readonly kind: "es_proto_int64";
|
|
4
|
+
type: ScalarType.INT64 | ScalarType.SINT64 | ScalarType.SFIXED64 | ScalarType.UINT64 | ScalarType.FIXED64;
|
|
5
|
+
longType: LongType;
|
|
6
|
+
value: bigint | string;
|
|
7
|
+
};
|
|
8
|
+
export type LiteralString = {
|
|
9
|
+
readonly kind: "es_string";
|
|
10
|
+
value: string;
|
|
11
|
+
};
|
|
12
|
+
export type RefDescMessage = {
|
|
13
|
+
readonly kind: "es_ref_message";
|
|
14
|
+
type: DescMessage;
|
|
15
|
+
typeOnly: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type RefDescEnum = {
|
|
18
|
+
readonly kind: "es_ref_enum";
|
|
19
|
+
type: DescEnum;
|
|
20
|
+
typeOnly: boolean;
|
|
21
|
+
};
|
|
22
|
+
export type ExportDeclaration = {
|
|
23
|
+
readonly kind: "es_export_decl";
|
|
24
|
+
declaration: string;
|
|
25
|
+
name: string | DescMessage | DescEnum | DescExtension;
|
|
26
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
2
3
|
//
|
|
3
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -11,10 +12,4 @@
|
|
|
11
12
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
13
|
// See the License for the specific language governing permissions and
|
|
13
14
|
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
kind: "es_export_decl",
|
|
17
|
-
declaration,
|
|
18
|
-
name,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -3,7 +3,7 @@ import { FeatureSetDefaults } from "@bufbuild/protobuf";
|
|
|
3
3
|
import type { FileInfo, GeneratedFile } from "./generated-file.js";
|
|
4
4
|
import { RuntimeImports } from "./runtime-imports.js";
|
|
5
5
|
import type { Target } from "./target.js";
|
|
6
|
-
import { ParsedParameter } from "./parameter";
|
|
6
|
+
import { ParsedParameter } from "./parameter.js";
|
|
7
7
|
/**
|
|
8
8
|
* Schema describes the files and types that the plugin is requested to
|
|
9
9
|
* generate.
|