@bufbuild/protoplugin 1.7.1 → 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 +108 -42
- 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 +108 -42
- 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
|
@@ -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.
|
|
@@ -19,7 +19,7 @@ const generated_file_js_1 = require("./generated-file.js");
|
|
|
19
19
|
const runtime_imports_js_1 = require("./runtime-imports.js");
|
|
20
20
|
const import_symbol_js_1 = require("./import-symbol.js");
|
|
21
21
|
const import_path_js_1 = require("./import-path.js");
|
|
22
|
-
const
|
|
22
|
+
const file_preamble_js_1 = require("./file-preamble.js");
|
|
23
23
|
function createSchema(request, parameter, pluginName, pluginVersion, featureSetDefaults) {
|
|
24
24
|
const descriptorSet = (0, protobuf_1.createDescriptorSet)(request.protoFile, {
|
|
25
25
|
featureSetDefaults,
|
|
@@ -31,7 +31,7 @@ function createSchema(request, parameter, pluginName, pluginVersion, featureSetD
|
|
|
31
31
|
const from = (0, import_path_js_1.makeImportPath)(desc.file, parameter.bootstrapWkt, filesToGenerate);
|
|
32
32
|
return (0, import_symbol_js_1.createImportSymbol)(name, from);
|
|
33
33
|
};
|
|
34
|
-
const createPreamble = (descFile) => (0,
|
|
34
|
+
const createPreamble = (descFile) => (0, file_preamble_js_1.makeFilePreamble)(descFile, pluginName, pluginVersion, parameter.sanitizedParameter, parameter.tsNocheck);
|
|
35
35
|
let target;
|
|
36
36
|
const generatedFiles = [];
|
|
37
37
|
return {
|
package/dist/cjs/error.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export declare class PluginOptionError extends Error {
|
|
2
|
+
name: string;
|
|
2
3
|
constructor(option: string, reason?: unknown);
|
|
3
4
|
}
|
|
4
5
|
export declare function reasonToString(reason: unknown): string;
|
|
6
|
+
export declare function isPluginOptionError(arg: unknown): arg is PluginOptionError;
|
package/dist/cjs/error.js
CHANGED
|
@@ -13,13 +13,14 @@
|
|
|
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.reasonToString = exports.PluginOptionError = void 0;
|
|
16
|
+
exports.isPluginOptionError = exports.reasonToString = exports.PluginOptionError = void 0;
|
|
17
17
|
class PluginOptionError extends Error {
|
|
18
18
|
constructor(option, reason) {
|
|
19
19
|
const detail = reason !== undefined ? reasonToString(reason) : "";
|
|
20
20
|
super(detail.length > 0
|
|
21
21
|
? `invalid option "${option}": ${detail}`
|
|
22
22
|
: `invalid option "${option}"`);
|
|
23
|
+
this.name = "PluginOptionError";
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
exports.PluginOptionError = PluginOptionError;
|
|
@@ -33,3 +34,10 @@ function reasonToString(reason) {
|
|
|
33
34
|
return String(reason);
|
|
34
35
|
}
|
|
35
36
|
exports.reasonToString = reasonToString;
|
|
37
|
+
function isPluginOptionError(arg) {
|
|
38
|
+
if (!(arg instanceof Error)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return arg.name === "PluginOptionError";
|
|
42
|
+
}
|
|
43
|
+
exports.isPluginOptionError = isPluginOptionError;
|
package/dist/cjs/run-node.js
CHANGED
|
@@ -46,7 +46,7 @@ function runNodeJs(plugin) {
|
|
|
46
46
|
})
|
|
47
47
|
.then(() => process.exit(0))
|
|
48
48
|
.catch((reason) => {
|
|
49
|
-
const message =
|
|
49
|
+
const message = (0, error_js_1.isPluginOptionError)(reason)
|
|
50
50
|
? reason.message
|
|
51
51
|
: (0, error_js_1.reasonToString)(reason);
|
|
52
52
|
process.stderr.write(`${plugin.name}: ${message}\n`);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { Edition } from "@bufbuild/protobuf";
|
|
15
|
+
export function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsNoCheck) {
|
|
16
|
+
const builder = [];
|
|
17
|
+
const trimSuffix = (str, suffix) => str.endsWith(suffix) ? str.substring(0, str.length - suffix.length) : str;
|
|
18
|
+
const writeLeadingComments = (comments) => {
|
|
19
|
+
for (let comment of comments.leadingDetached) {
|
|
20
|
+
comment = trimSuffix(comment, "\n");
|
|
21
|
+
for (const line of comment.split("\n")) {
|
|
22
|
+
builder.push(`//${line}\n`);
|
|
23
|
+
}
|
|
24
|
+
builder.push("\n");
|
|
25
|
+
}
|
|
26
|
+
if (comments.leading !== undefined) {
|
|
27
|
+
const comment = trimSuffix(comments.leading, "\n");
|
|
28
|
+
for (const line of comment.split("\n")) {
|
|
29
|
+
builder.push(`//${line}\n`);
|
|
30
|
+
}
|
|
31
|
+
builder.push("\n");
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
writeLeadingComments(file.getSyntaxComments());
|
|
35
|
+
builder.push(`// @generated by ${pluginName} ${pluginVersion}`);
|
|
36
|
+
if (parameter !== "") {
|
|
37
|
+
builder.push(` with parameter "${parameter}"`);
|
|
38
|
+
}
|
|
39
|
+
builder.push("\n");
|
|
40
|
+
builder.push(`// @generated from file ${file.name}.proto (`);
|
|
41
|
+
if (file.proto.package !== undefined) {
|
|
42
|
+
builder.push(`package ${file.proto.package}, `);
|
|
43
|
+
}
|
|
44
|
+
switch (file.edition) {
|
|
45
|
+
case Edition.EDITION_PROTO2:
|
|
46
|
+
builder.push(`syntax proto2)\n`);
|
|
47
|
+
break;
|
|
48
|
+
case Edition.EDITION_PROTO3:
|
|
49
|
+
builder.push(`syntax proto3)\n`);
|
|
50
|
+
break;
|
|
51
|
+
default: {
|
|
52
|
+
const editionString = Edition[file.edition];
|
|
53
|
+
if (typeof editionString == "string") {
|
|
54
|
+
const e = editionString.replace("EDITION_", "").toLowerCase();
|
|
55
|
+
builder.push(`edition ${e})\n`);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
builder.push(`unknown edition\n`);
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
builder.push("/* eslint-disable */\n");
|
|
64
|
+
if (tsNoCheck) {
|
|
65
|
+
builder.push("// @ts-nocheck\n");
|
|
66
|
+
}
|
|
67
|
+
builder.push("\n");
|
|
68
|
+
writeLeadingComments(file.getPackageComments());
|
|
69
|
+
return trimSuffix(builder.join(""), "\n");
|
|
70
|
+
}
|
|
@@ -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
|
*/
|
|
@@ -11,10 +11,9 @@
|
|
|
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 { LongType, protoInt64, ScalarType, } from "@bufbuild/protobuf";
|
|
14
15
|
import { createImportSymbol } from "./import-symbol.js";
|
|
15
|
-
import { literalString } from "./gencommon.js";
|
|
16
16
|
import { makeImportPathRelative } from "./import-path.js";
|
|
17
|
-
import { createExportDeclaration } from "./export-declaration.js";
|
|
18
17
|
import { createJsDocBlock } from "./jsdoc.js";
|
|
19
18
|
export function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath, createTypeImport, runtimeImports, createPreamble) {
|
|
20
19
|
let preamble;
|
|
@@ -44,10 +43,15 @@ export function createGeneratedFile(name, importPath, jsImportStyle, rewriteImpo
|
|
|
44
43
|
return createImportSymbol(name, importPath);
|
|
45
44
|
},
|
|
46
45
|
exportDecl(declaration, name) {
|
|
47
|
-
return
|
|
46
|
+
return {
|
|
47
|
+
kind: "es_export_decl",
|
|
48
|
+
declaration,
|
|
49
|
+
name,
|
|
50
|
+
};
|
|
48
51
|
},
|
|
49
52
|
string(string) {
|
|
50
|
-
|
|
53
|
+
// We do not use LiteralString, which was added later, to maintain backwards compatibility
|
|
54
|
+
return escapeString(string);
|
|
51
55
|
},
|
|
52
56
|
jsDoc(textOrDesc, indentation) {
|
|
53
57
|
return createJsDocBlock(textOrDesc, indentation);
|
|
@@ -83,16 +87,16 @@ function elToContent(el, importerPath, rewriteImportPath, legacyCommonJs) {
|
|
|
83
87
|
if (legacyCommonJs) {
|
|
84
88
|
const p = names.map(({ name, alias }) => alias == undefined ? name : `${name}: ${alias}`);
|
|
85
89
|
const what = `{ ${p.join(", ")} }`;
|
|
86
|
-
c.push(`const ${what} = require(${
|
|
90
|
+
c.push(`const ${what} = require(${escapeString(from)});\n`);
|
|
87
91
|
}
|
|
88
92
|
else {
|
|
89
93
|
const p = names.map(({ name, alias }) => alias == undefined ? name : `${name} as ${alias}`);
|
|
90
94
|
const what = `{ ${p.join(", ")} }`;
|
|
91
95
|
if (typeOnly) {
|
|
92
|
-
c.push(`import type ${what} from ${
|
|
96
|
+
c.push(`import type ${what} from ${escapeString(from)};\n`);
|
|
93
97
|
}
|
|
94
98
|
else {
|
|
95
|
-
c.push(`import ${what} from ${
|
|
99
|
+
c.push(`import ${what} from ${escapeString(from)};\n`);
|
|
96
100
|
}
|
|
97
101
|
}
|
|
98
102
|
});
|
|
@@ -149,17 +153,17 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
|
|
|
149
153
|
el.push(p);
|
|
150
154
|
break;
|
|
151
155
|
case "number":
|
|
152
|
-
el
|
|
156
|
+
elNumber(el, p, runtimeImports);
|
|
153
157
|
break;
|
|
154
158
|
case "boolean":
|
|
155
159
|
el.push(p.toString());
|
|
156
160
|
break;
|
|
157
161
|
case "bigint":
|
|
158
|
-
el
|
|
162
|
+
elBigint(el, p, runtimeImports);
|
|
159
163
|
break;
|
|
160
164
|
case "object":
|
|
161
165
|
if (p instanceof Uint8Array) {
|
|
162
|
-
el
|
|
166
|
+
elUint8Array(el, p);
|
|
163
167
|
break;
|
|
164
168
|
}
|
|
165
169
|
switch (p.kind) {
|
|
@@ -169,6 +173,12 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
|
|
|
169
173
|
case "es_jsdoc":
|
|
170
174
|
el.push(p.toString());
|
|
171
175
|
break;
|
|
176
|
+
case "es_string":
|
|
177
|
+
el.push(escapeString(p.value));
|
|
178
|
+
break;
|
|
179
|
+
case "es_proto_int64":
|
|
180
|
+
elProtoInt64(el, p, runtimeImports);
|
|
181
|
+
break;
|
|
172
182
|
case "es_export_decl":
|
|
173
183
|
el.push({
|
|
174
184
|
kind: "es_export_stmt",
|
|
@@ -178,6 +188,12 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
|
|
|
178
188
|
: createTypeImport(p.name).name,
|
|
179
189
|
});
|
|
180
190
|
break;
|
|
191
|
+
case "es_ref_message":
|
|
192
|
+
case "es_ref_enum":
|
|
193
|
+
el.push(p.typeOnly
|
|
194
|
+
? createTypeImport(p.type).toTypeOnly()
|
|
195
|
+
: createTypeImport(p.type));
|
|
196
|
+
break;
|
|
181
197
|
case "message":
|
|
182
198
|
case "extension":
|
|
183
199
|
case "enum":
|
|
@@ -212,19 +228,26 @@ function processImports(el, importerPath, rewriteImportPath, makeImportStatement
|
|
|
212
228
|
const foreignSymbols = [];
|
|
213
229
|
// Walk through all symbols used and populate the collections above.
|
|
214
230
|
for (const s of el) {
|
|
215
|
-
if (typeof s != "object"
|
|
231
|
+
if (typeof s != "object") {
|
|
216
232
|
continue;
|
|
217
233
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
234
|
+
switch (s.kind) {
|
|
235
|
+
case "es_symbol":
|
|
236
|
+
symbolToIdentifier.set(s.id, s.name);
|
|
237
|
+
if (!s.typeOnly) {
|
|
238
|
+
// a symbol is only type-imported as long as all uses are type-only
|
|
239
|
+
symbolToIsValue.set(s.id, true);
|
|
240
|
+
}
|
|
241
|
+
if (s.from === importerPath) {
|
|
242
|
+
identifiersTaken.add(s.name);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
foreignSymbols.push(s);
|
|
246
|
+
}
|
|
247
|
+
break;
|
|
248
|
+
case "es_export_stmt":
|
|
249
|
+
identifiersTaken.add(s.name);
|
|
250
|
+
break;
|
|
228
251
|
}
|
|
229
252
|
}
|
|
230
253
|
// Walk through all foreign symbols and make their identifiers unique.
|
|
@@ -300,37 +323,80 @@ function processImports(el, importerPath, rewriteImportPath, makeImportStatement
|
|
|
300
323
|
}
|
|
301
324
|
return symbolToIdentifier;
|
|
302
325
|
}
|
|
303
|
-
function
|
|
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) {
|
|
304
336
|
if (Number.isNaN(value)) {
|
|
305
|
-
|
|
337
|
+
el.push(runtimeImports.protoDouble, ".NaN");
|
|
306
338
|
}
|
|
307
|
-
if (value === Number.POSITIVE_INFINITY) {
|
|
308
|
-
|
|
339
|
+
else if (value === Number.POSITIVE_INFINITY) {
|
|
340
|
+
el.push(runtimeImports.protoDouble, ".POSITIVE_INFINITY");
|
|
309
341
|
}
|
|
310
|
-
if (value === Number.NEGATIVE_INFINITY) {
|
|
311
|
-
|
|
342
|
+
else if (value === Number.NEGATIVE_INFINITY) {
|
|
343
|
+
el.push(runtimeImports.protoDouble, ".NEGATIVE_INFINITY");
|
|
312
344
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
function literalBigint(value, runtimeImports) {
|
|
316
|
-
// Loose comparison will match between 0n and 0.
|
|
317
|
-
if (value == 0) {
|
|
318
|
-
return [runtimeImports.protoInt64, ".zero"];
|
|
345
|
+
else {
|
|
346
|
+
el.push(value.toString(10));
|
|
319
347
|
}
|
|
320
|
-
return [
|
|
321
|
-
runtimeImports.protoInt64,
|
|
322
|
-
value > 0 ? ".uParse(" : ".parse(",
|
|
323
|
-
literalString(value.toString()),
|
|
324
|
-
")",
|
|
325
|
-
];
|
|
326
348
|
}
|
|
327
|
-
function
|
|
349
|
+
function elUint8Array(el, value) {
|
|
328
350
|
if (value.length === 0) {
|
|
329
|
-
|
|
351
|
+
el.push("new Uint8Array(0)");
|
|
352
|
+
return;
|
|
330
353
|
}
|
|
354
|
+
el.push("new Uint8Array([");
|
|
331
355
|
const strings = [];
|
|
332
356
|
for (const n of value) {
|
|
333
357
|
strings.push("0x" + n.toString(16).toUpperCase().padStart(2, "0"));
|
|
334
358
|
}
|
|
335
|
-
|
|
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
|
+
function escapeString(value) {
|
|
391
|
+
return ('"' +
|
|
392
|
+
value
|
|
393
|
+
.split("\\")
|
|
394
|
+
.join("\\\\")
|
|
395
|
+
.split('"')
|
|
396
|
+
.join('\\"')
|
|
397
|
+
.split("\r")
|
|
398
|
+
.join("\\r")
|
|
399
|
+
.split("\n")
|
|
400
|
+
.join("\\n") +
|
|
401
|
+
'"');
|
|
336
402
|
}
|
|
@@ -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,18 +13,11 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
import { codegenInfo, } from "@bufbuild/protobuf";
|
|
15
15
|
import { createJsDocBlock as createJsDocBlockInternal } from "./jsdoc.js";
|
|
16
|
-
import { literalString as literalStringInternal } from "./gencommon.js";
|
|
17
16
|
export { reifyWkt } from "./reify-wkt.js";
|
|
18
17
|
export { createImportSymbol } from "./import-symbol.js";
|
|
19
18
|
export const { localName } = codegenInfo;
|
|
20
|
-
export { getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, } from "./gencommon.js";
|
|
21
|
-
export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./custom-options.js";
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated Please use GeneratedFile.string() instead
|
|
24
|
-
*/
|
|
25
|
-
export function literalString(value) {
|
|
26
|
-
return literalStringInternal(value);
|
|
27
|
-
}
|
|
19
|
+
export { getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, literalString, } from "./legacy-gencommon.js";
|
|
20
|
+
export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./legacy-custom-options.js";
|
|
28
21
|
/**
|
|
29
22
|
* @deprecated Please use GeneratedFile.jsDoc() instead
|
|
30
23
|
*/
|
|
@@ -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;
|
|
@@ -11,6 +11,7 @@
|
|
|
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
|
+
// TODO simplify type JSDocBlock to bring it in line with others in opaque-printables.ts
|
|
14
15
|
export function createJsDocBlock(textOrDesc, indentation) {
|
|
15
16
|
const text = typeof textOrDesc == "string" ? textOrDesc : createTextForDesc(textOrDesc);
|
|
16
17
|
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;
|