@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
|
@@ -11,67 +11,26 @@
|
|
|
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,
|
|
15
|
-
const { localName, getUnwrappedFieldType,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
builder.push("\n");
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
writeLeadingComments(file.getSyntaxComments());
|
|
36
|
-
builder.push(`// @generated by ${pluginName} ${pluginVersion}`);
|
|
37
|
-
if (parameter !== "") {
|
|
38
|
-
builder.push(` with parameter "${parameter}"`);
|
|
39
|
-
}
|
|
40
|
-
builder.push("\n");
|
|
41
|
-
builder.push(`// @generated from file ${file.name}.proto (`);
|
|
42
|
-
if (file.proto.package !== undefined) {
|
|
43
|
-
builder.push(`package ${file.proto.package}, `);
|
|
44
|
-
}
|
|
45
|
-
switch (file.edition) {
|
|
46
|
-
case Edition.EDITION_PROTO2:
|
|
47
|
-
builder.push(`syntax proto2)\n`);
|
|
48
|
-
break;
|
|
49
|
-
case Edition.EDITION_PROTO3:
|
|
50
|
-
builder.push(`syntax proto3)\n`);
|
|
51
|
-
break;
|
|
52
|
-
default: {
|
|
53
|
-
const editionString = Edition[file.edition];
|
|
54
|
-
if (typeof editionString == "string") {
|
|
55
|
-
const e = editionString.replace("EDITION_", "").toLowerCase();
|
|
56
|
-
builder.push(`edition ${e})\n`);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
builder.push(`unknown edition\n`);
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
builder.push("/* eslint-disable */\n");
|
|
65
|
-
if (tsNoCheck) {
|
|
66
|
-
builder.push("// @ts-nocheck\n");
|
|
67
|
-
}
|
|
68
|
-
builder.push("\n");
|
|
69
|
-
writeLeadingComments(file.getPackageComments());
|
|
70
|
-
return trimSuffix(builder.join(""), "\n");
|
|
14
|
+
import { codegenInfo, LongType, ScalarType, } from "@bufbuild/protobuf";
|
|
15
|
+
const { localName, getUnwrappedFieldType, scalarZeroValue } = codegenInfo;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Please use GeneratedFile.string() instead
|
|
18
|
+
*/
|
|
19
|
+
export function literalString(value) {
|
|
20
|
+
return ('"' +
|
|
21
|
+
value
|
|
22
|
+
.split("\\")
|
|
23
|
+
.join("\\\\")
|
|
24
|
+
.split('"')
|
|
25
|
+
.join('\\"')
|
|
26
|
+
.split("\r")
|
|
27
|
+
.join("\\r")
|
|
28
|
+
.split("\n")
|
|
29
|
+
.join("\\n") +
|
|
30
|
+
'"');
|
|
71
31
|
}
|
|
72
32
|
/**
|
|
73
|
-
*
|
|
74
|
-
* and whether the property should be optional.
|
|
33
|
+
* @deprecated
|
|
75
34
|
*/
|
|
76
35
|
export function getFieldTyping(field, file) {
|
|
77
36
|
const typing = [];
|
|
@@ -133,40 +92,9 @@ export function getFieldTyping(field, file) {
|
|
|
133
92
|
}
|
|
134
93
|
return { typing, optional };
|
|
135
94
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return "string";
|
|
140
|
-
case ScalarType.BOOL:
|
|
141
|
-
return "boolean";
|
|
142
|
-
case ScalarType.UINT64:
|
|
143
|
-
case ScalarType.SFIXED64:
|
|
144
|
-
case ScalarType.FIXED64:
|
|
145
|
-
case ScalarType.SINT64:
|
|
146
|
-
case ScalarType.INT64:
|
|
147
|
-
if (longType === LongType.STRING) {
|
|
148
|
-
return "string";
|
|
149
|
-
}
|
|
150
|
-
return "bigint";
|
|
151
|
-
case ScalarType.BYTES:
|
|
152
|
-
return "Uint8Array";
|
|
153
|
-
default:
|
|
154
|
-
return "number";
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
export function literalString(value) {
|
|
158
|
-
return ('"' +
|
|
159
|
-
value
|
|
160
|
-
.split("\\")
|
|
161
|
-
.join("\\\\")
|
|
162
|
-
.split('"')
|
|
163
|
-
.join('\\"')
|
|
164
|
-
.split("\r")
|
|
165
|
-
.join("\\r")
|
|
166
|
-
.split("\n")
|
|
167
|
-
.join("\\n") +
|
|
168
|
-
'"');
|
|
169
|
-
}
|
|
95
|
+
/**
|
|
96
|
+
* @deprecated
|
|
97
|
+
*/
|
|
170
98
|
export function getFieldExplicitDefaultValue(field, protoInt64Symbol) {
|
|
171
99
|
switch (field.fieldKind) {
|
|
172
100
|
case "enum": {
|
|
@@ -222,6 +150,9 @@ export function getFieldExplicitDefaultValue(field, protoInt64Symbol) {
|
|
|
222
150
|
}
|
|
223
151
|
return undefined;
|
|
224
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* @deprecated
|
|
155
|
+
*/
|
|
225
156
|
export function getFieldIntrinsicDefaultValue(field) {
|
|
226
157
|
if (field.repeated) {
|
|
227
158
|
return {
|
|
@@ -257,8 +188,7 @@ export function getFieldIntrinsicDefaultValue(field) {
|
|
|
257
188
|
defaultValue = literalString("");
|
|
258
189
|
}
|
|
259
190
|
else {
|
|
260
|
-
|
|
261
|
-
defaultValue = scalarDefaultValue(field.scalar, field.longType);
|
|
191
|
+
defaultValue = scalarZeroValue(field.scalar, field.longType);
|
|
262
192
|
if (typeof defaultValue === "string") {
|
|
263
193
|
defaultValue = literalString(defaultValue);
|
|
264
194
|
}
|
|
@@ -274,3 +204,27 @@ export function getFieldIntrinsicDefaultValue(field) {
|
|
|
274
204
|
typingInferrable,
|
|
275
205
|
};
|
|
276
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* @deprecated
|
|
209
|
+
*/
|
|
210
|
+
function scalarTypeScriptType(type, longType) {
|
|
211
|
+
switch (type) {
|
|
212
|
+
case ScalarType.STRING:
|
|
213
|
+
return "string";
|
|
214
|
+
case ScalarType.BOOL:
|
|
215
|
+
return "boolean";
|
|
216
|
+
case ScalarType.UINT64:
|
|
217
|
+
case ScalarType.SFIXED64:
|
|
218
|
+
case ScalarType.FIXED64:
|
|
219
|
+
case ScalarType.SINT64:
|
|
220
|
+
case ScalarType.INT64:
|
|
221
|
+
if (longType === LongType.STRING) {
|
|
222
|
+
return "string";
|
|
223
|
+
}
|
|
224
|
+
return "bigint";
|
|
225
|
+
case ScalarType.BYTES:
|
|
226
|
+
return "Uint8Array";
|
|
227
|
+
default:
|
|
228
|
+
return "number";
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -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,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
2
|
//
|
|
4
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -12,13 +11,4 @@
|
|
|
12
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
12
|
// See the License for the specific language governing permissions and
|
|
14
13
|
// limitations under the License.
|
|
15
|
-
|
|
16
|
-
exports.createExportDeclaration = void 0;
|
|
17
|
-
function createExportDeclaration(declaration, name) {
|
|
18
|
-
return {
|
|
19
|
-
kind: "es_export_decl",
|
|
20
|
-
declaration,
|
|
21
|
-
name,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
exports.createExportDeclaration = createExportDeclaration;
|
|
14
|
+
export {};
|
|
@@ -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.
|
|
@@ -16,7 +16,7 @@ import { createGeneratedFile } from "./generated-file.js";
|
|
|
16
16
|
import { createRuntimeImports } from "./runtime-imports.js";
|
|
17
17
|
import { createImportSymbol } from "./import-symbol.js";
|
|
18
18
|
import { deriveImportPath, makeImportPath, rewriteImportPath, } from "./import-path.js";
|
|
19
|
-
import { makeFilePreamble } from "./
|
|
19
|
+
import { makeFilePreamble } from "./file-preamble.js";
|
|
20
20
|
export function createSchema(request, parameter, pluginName, pluginVersion, featureSetDefaults) {
|
|
21
21
|
const descriptorSet = createDescriptorSet(request.protoFile, {
|
|
22
22
|
featureSetDefaults,
|
package/dist/esm/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/esm/error.js
CHANGED
|
@@ -17,6 +17,7 @@ export class PluginOptionError extends Error {
|
|
|
17
17
|
super(detail.length > 0
|
|
18
18
|
? `invalid option "${option}": ${detail}`
|
|
19
19
|
: `invalid option "${option}"`);
|
|
20
|
+
this.name = "PluginOptionError";
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
export function reasonToString(reason) {
|
|
@@ -28,3 +29,9 @@ export function reasonToString(reason) {
|
|
|
28
29
|
}
|
|
29
30
|
return String(reason);
|
|
30
31
|
}
|
|
32
|
+
export function isPluginOptionError(arg) {
|
|
33
|
+
if (!(arg instanceof Error)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return arg.name === "PluginOptionError";
|
|
37
|
+
}
|
package/dist/esm/run-node.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
import { CodeGeneratorRequest } from "@bufbuild/protobuf";
|
|
15
|
-
import {
|
|
15
|
+
import { isPluginOptionError, reasonToString } from "./error.js";
|
|
16
16
|
/**
|
|
17
17
|
* Run a plugin with Node.js.
|
|
18
18
|
*
|
|
@@ -43,7 +43,7 @@ export function runNodeJs(plugin) {
|
|
|
43
43
|
})
|
|
44
44
|
.then(() => process.exit(0))
|
|
45
45
|
.catch((reason) => {
|
|
46
|
-
const message = reason
|
|
46
|
+
const message = isPluginOptionError(reason)
|
|
47
47
|
? reason.message
|
|
48
48
|
: reasonToString(reason);
|
|
49
49
|
process.stderr.write(`${plugin.name}: ${message}\n`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protoplugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"license": "(Apache-2.0 AND BSD-3-Clause)",
|
|
5
5
|
"description": "Helps to create your own Protocol Buffers code generators.",
|
|
6
6
|
"repository": {
|
|
@@ -10,10 +10,9 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"clean": "rm -rf ./dist/*",
|
|
13
|
-
"build": "npm run build:cjs && npm run build:esm
|
|
13
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
14
14
|
"build:cjs": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
|
|
15
15
|
"build:esm": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
|
|
16
|
-
"build:proxy": "node ../../scripts/gen-esm-proxy.mjs . ecmascript",
|
|
17
16
|
"attw": "attw --pack"
|
|
18
17
|
},
|
|
19
18
|
"type": "module",
|
|
@@ -21,20 +20,10 @@
|
|
|
21
20
|
"main": "./dist/cjs/index.js",
|
|
22
21
|
"exports": {
|
|
23
22
|
".": {
|
|
24
|
-
"node": {
|
|
25
|
-
"import": "./dist/proxy/index.js",
|
|
26
|
-
"require": "./dist/cjs/index.js"
|
|
27
|
-
},
|
|
28
|
-
"module": "./dist/esm/index.js",
|
|
29
23
|
"import": "./dist/esm/index.js",
|
|
30
24
|
"require": "./dist/cjs/index.js"
|
|
31
25
|
},
|
|
32
26
|
"./ecmascript": {
|
|
33
|
-
"node": {
|
|
34
|
-
"import": "./dist/proxy/ecmascript/index.js",
|
|
35
|
-
"require": "./dist/cjs/ecmascript/index.js"
|
|
36
|
-
},
|
|
37
|
-
"module": "./dist/esm/ecmascript/index.js",
|
|
38
27
|
"import": "./dist/esm/ecmascript/index.js",
|
|
39
28
|
"require": "./dist/cjs/ecmascript/index.js"
|
|
40
29
|
}
|
|
@@ -47,7 +36,7 @@
|
|
|
47
36
|
}
|
|
48
37
|
},
|
|
49
38
|
"dependencies": {
|
|
50
|
-
"@bufbuild/protobuf": "1.
|
|
39
|
+
"@bufbuild/protobuf": "1.8.0",
|
|
51
40
|
"@typescript/vfs": "^1.4.0",
|
|
52
41
|
"typescript": "4.5.2"
|
|
53
42
|
},
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { DescEnum, DescExtension, DescMessage } from "@bufbuild/protobuf";
|
|
2
|
-
export type ExportDeclaration = {
|
|
3
|
-
readonly kind: "es_export_decl";
|
|
4
|
-
declaration: string;
|
|
5
|
-
name: string | DescMessage | DescEnum | DescExtension;
|
|
6
|
-
};
|
|
7
|
-
export declare function createExportDeclaration(declaration: string, name: ExportDeclaration["name"]): ExportDeclaration;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { DescEnum, DescExtension, DescMessage } from "@bufbuild/protobuf";
|
|
2
|
-
export type ExportDeclaration = {
|
|
3
|
-
readonly kind: "es_export_decl";
|
|
4
|
-
declaration: string;
|
|
5
|
-
name: string | DescMessage | DescEnum | DescExtension;
|
|
6
|
-
};
|
|
7
|
-
export declare function createExportDeclaration(declaration: string, name: ExportDeclaration["name"]): ExportDeclaration;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../cjs/ecmascript/index.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../cjs/ecmascript/index.js";
|
package/dist/proxy/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../cjs/index.js";
|
package/dist/proxy/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../cjs/index.js";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|