@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
|
@@ -13,34 +13,8 @@
|
|
|
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.
|
|
17
|
-
const protobuf_1 = require("@bufbuild/protobuf");
|
|
18
|
-
const jsdoc_js_1 = require("./jsdoc.js");
|
|
19
|
-
var reify_wkt_js_1 = require("./reify-wkt.js");
|
|
20
|
-
Object.defineProperty(exports, "reifyWkt", { enumerable: true, get: function () { return reify_wkt_js_1.reifyWkt; } });
|
|
16
|
+
exports.safeIdentifier = exports.createImportSymbol = void 0;
|
|
21
17
|
var import_symbol_js_1 = require("./import-symbol.js");
|
|
22
18
|
Object.defineProperty(exports, "createImportSymbol", { enumerable: true, get: function () { return import_symbol_js_1.createImportSymbol; } });
|
|
23
|
-
|
|
24
|
-
|
|
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; } });
|
|
33
|
-
/**
|
|
34
|
-
* @deprecated Please use GeneratedFile.jsDoc() instead
|
|
35
|
-
*/
|
|
36
|
-
function makeJsDoc(desc, indentation = "") {
|
|
37
|
-
return (0, jsdoc_js_1.createJsDocBlock)(desc, indentation).toString();
|
|
38
|
-
}
|
|
39
|
-
exports.makeJsDoc = makeJsDoc;
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated Please use GeneratedFile.jsDoc() instead
|
|
42
|
-
*/
|
|
43
|
-
function createJsDocBlock(text, indentation = "") {
|
|
44
|
-
return (0, jsdoc_js_1.createJsDocBlock)(text, indentation).toString();
|
|
45
|
-
}
|
|
46
|
-
exports.createJsDocBlock = createJsDocBlock;
|
|
19
|
+
var safe_identifier_js_1 = require("./safe-identifier.js");
|
|
20
|
+
Object.defineProperty(exports, "safeIdentifier", { enumerable: true, get: function () { return safe_identifier_js_1.safeIdentifier; } });
|
|
@@ -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;
|
|
@@ -13,33 +13,11 @@
|
|
|
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.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
kind: "es_jsdoc",
|
|
22
|
-
text,
|
|
23
|
-
indentation,
|
|
24
|
-
toString() {
|
|
25
|
-
if (text.trim().length == 0) {
|
|
26
|
-
return "";
|
|
27
|
-
}
|
|
28
|
-
let lines = text.split("\n");
|
|
29
|
-
if (lines.length === 0) {
|
|
30
|
-
return "";
|
|
31
|
-
}
|
|
32
|
-
lines = lines.map((l) => l.split("*/").join("*\\/"));
|
|
33
|
-
lines = lines.map((l) => (l.length > 0 ? " " + l : l));
|
|
34
|
-
const i = indentation !== null && indentation !== void 0 ? indentation : "";
|
|
35
|
-
return [`${i}/**\n`, ...lines.map((l) => `${i} *${l}\n`), `${i} */`].join("");
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
exports.createJsDocBlock = createJsDocBlock;
|
|
40
|
-
function createTextForDesc(desc) {
|
|
41
|
-
var _a, _b;
|
|
42
|
-
const comments = desc.getComments();
|
|
16
|
+
exports.formatJsDocBlock = exports.createJsDocTextFromDesc = void 0;
|
|
17
|
+
const source_code_info_js_1 = require("../source-code-info.js");
|
|
18
|
+
const reflect_1 = require("@bufbuild/protobuf/reflect");
|
|
19
|
+
function createJsDocTextFromDesc(desc) {
|
|
20
|
+
const comments = (0, source_code_info_js_1.getComments)(desc);
|
|
43
21
|
let text = "";
|
|
44
22
|
if (comments.leading !== undefined) {
|
|
45
23
|
text += comments.leading;
|
|
@@ -65,26 +43,37 @@ function createTextForDesc(desc) {
|
|
|
65
43
|
.join("\n");
|
|
66
44
|
switch (desc.kind) {
|
|
67
45
|
case "enum_value":
|
|
68
|
-
text += `@generated from enum value: ${
|
|
46
|
+
text += `@generated from enum value: ${(0, source_code_info_js_1.getDeclarationString)(desc)};`;
|
|
69
47
|
break;
|
|
70
48
|
case "field":
|
|
71
|
-
text += `@generated from field: ${
|
|
49
|
+
text += `@generated from field: ${(0, source_code_info_js_1.getDeclarationString)(desc)};`;
|
|
72
50
|
break;
|
|
73
51
|
case "extension":
|
|
74
|
-
text += `@generated from extension: ${
|
|
52
|
+
text += `@generated from extension: ${(0, source_code_info_js_1.getDeclarationString)(desc)};`;
|
|
53
|
+
break;
|
|
54
|
+
case "message":
|
|
55
|
+
case "enum": {
|
|
56
|
+
text += `@generated from ${desc.toString()}`;
|
|
57
|
+
const featureOptions = (0, source_code_info_js_1.getFeatureOptionStrings)(desc);
|
|
58
|
+
if (featureOptions.length > 0) {
|
|
59
|
+
text += `\n@generated with ${featureOptions.length > 1 ? "options" : "option"} ${featureOptions.join(", ")}`;
|
|
60
|
+
}
|
|
75
61
|
break;
|
|
62
|
+
}
|
|
76
63
|
default:
|
|
77
64
|
text += `@generated from ${desc.toString()}`;
|
|
78
65
|
break;
|
|
79
66
|
}
|
|
80
|
-
let deprecated
|
|
67
|
+
let deprecated;
|
|
81
68
|
switch (desc.kind) {
|
|
82
|
-
case "
|
|
83
|
-
case "
|
|
84
|
-
case "
|
|
85
|
-
deprecated =
|
|
69
|
+
case "field":
|
|
70
|
+
case "enum_value":
|
|
71
|
+
case "rpc":
|
|
72
|
+
deprecated = desc.deprecated;
|
|
86
73
|
break;
|
|
87
74
|
default:
|
|
75
|
+
deprecated =
|
|
76
|
+
desc.deprecated || (0, reflect_1.parentTypes)(desc).some((d) => d.deprecated);
|
|
88
77
|
break;
|
|
89
78
|
}
|
|
90
79
|
if (deprecated) {
|
|
@@ -92,3 +81,18 @@ function createTextForDesc(desc) {
|
|
|
92
81
|
}
|
|
93
82
|
return text;
|
|
94
83
|
}
|
|
84
|
+
exports.createJsDocTextFromDesc = createJsDocTextFromDesc;
|
|
85
|
+
function formatJsDocBlock(text, indentation) {
|
|
86
|
+
if (text.trim().length == 0) {
|
|
87
|
+
return "";
|
|
88
|
+
}
|
|
89
|
+
let lines = text.split("\n");
|
|
90
|
+
if (lines.length === 0) {
|
|
91
|
+
return "";
|
|
92
|
+
}
|
|
93
|
+
lines = lines.map((l) => l.split("*/").join("*\\/"));
|
|
94
|
+
lines = lines.map((l) => (l.length > 0 ? " " + l : l));
|
|
95
|
+
const i = indentation !== null && indentation !== void 0 ? indentation : "";
|
|
96
|
+
return [`${i}/**\n`, ...lines.map((l) => `${i} *${l}\n`), `${i} */`].join("");
|
|
97
|
+
}
|
|
98
|
+
exports.formatJsDocBlock = formatJsDocBlock;
|
|
@@ -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;
|
|
@@ -0,0 +1,119 @@
|
|
|
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.localShapeName = exports.localDescName = exports.generateFilePath = void 0;
|
|
17
|
+
const codegenv1_1 = require("@bufbuild/protobuf/codegenv1");
|
|
18
|
+
const reflect_1 = require("@bufbuild/protobuf/reflect");
|
|
19
|
+
const safe_identifier_js_1 = require("./safe-identifier.js");
|
|
20
|
+
function generateFilePath(file, bootstrapWkt, filesToGenerate) {
|
|
21
|
+
// Well-known types are published with the runtime package. We usually want
|
|
22
|
+
// the generated code to import them from the runtime package, with the
|
|
23
|
+
// following exceptions:
|
|
24
|
+
// 1. We are bootstrapping the runtime package via the plugin option
|
|
25
|
+
// "bootstrap_wkt". In that case, we cannot refer to the runtime package
|
|
26
|
+
// itself.
|
|
27
|
+
// 2. We were explicitly asked to generate the well-known type.
|
|
28
|
+
const wktFrom = codegenv1_1.wktPublicImportPaths[file.proto.name];
|
|
29
|
+
if (wktFrom !== undefined &&
|
|
30
|
+
!bootstrapWkt &&
|
|
31
|
+
!filesToGenerate.find((f) => f.name === file.name)) {
|
|
32
|
+
return wktFrom;
|
|
33
|
+
}
|
|
34
|
+
return "./" + file.name + "_pb.js";
|
|
35
|
+
}
|
|
36
|
+
exports.generateFilePath = generateFilePath;
|
|
37
|
+
function localDescName(desc) {
|
|
38
|
+
const file = desc.kind == "file" ? desc : desc.file;
|
|
39
|
+
const { descNames } = allNames(file);
|
|
40
|
+
const name = descNames.get(desc);
|
|
41
|
+
if (name === undefined) {
|
|
42
|
+
throw new Error(`unable to determine unique identifier for ${desc.toString()}`);
|
|
43
|
+
}
|
|
44
|
+
return name;
|
|
45
|
+
}
|
|
46
|
+
exports.localDescName = localDescName;
|
|
47
|
+
function localShapeName(desc) {
|
|
48
|
+
const { shapeNames } = allNames(desc.file);
|
|
49
|
+
const name = shapeNames.get(desc);
|
|
50
|
+
if (name === undefined) {
|
|
51
|
+
throw new Error(`unable to determine unique identifier for ${desc.toString()}`);
|
|
52
|
+
}
|
|
53
|
+
return name;
|
|
54
|
+
}
|
|
55
|
+
exports.localShapeName = localShapeName;
|
|
56
|
+
function idealDescName(desc, i) {
|
|
57
|
+
const escape = i === 0 ? "" : i === 1 ? "$" : `$${i - 1}`;
|
|
58
|
+
switch (desc.kind) {
|
|
59
|
+
case "file":
|
|
60
|
+
return ((0, safe_identifier_js_1.safeIdentifier)("fileDesc_" + desc.name.replace(/[^a-zA-Z0-9_]+/g, "_")) + escape);
|
|
61
|
+
case "enum":
|
|
62
|
+
return baseName(desc) + "Desc" + escape;
|
|
63
|
+
case "message":
|
|
64
|
+
return baseName(desc) + "Desc" + escape;
|
|
65
|
+
case "extension":
|
|
66
|
+
return baseName(desc) + escape;
|
|
67
|
+
case "service":
|
|
68
|
+
return baseName(desc) + escape;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function idealShapeName(desc, i) {
|
|
72
|
+
const escape = i === 0 ? "" : i === 1 ? "$" : `$${i - 1}`;
|
|
73
|
+
return baseName(desc) + escape;
|
|
74
|
+
}
|
|
75
|
+
function baseName(desc) {
|
|
76
|
+
const pkg = desc.file.proto.package;
|
|
77
|
+
const offset = pkg.length > 0 ? pkg.length + 1 : 0;
|
|
78
|
+
const name = desc.typeName.substring(offset).replace(/\./g, "_");
|
|
79
|
+
return (0, safe_identifier_js_1.safeIdentifier)(name);
|
|
80
|
+
}
|
|
81
|
+
function allNames(file) {
|
|
82
|
+
const taken = new Set();
|
|
83
|
+
const shapeNames = new Map();
|
|
84
|
+
const descNames = new Map();
|
|
85
|
+
for (const desc of [file, ...(0, reflect_1.nestedTypes)(file)]) {
|
|
86
|
+
switch (desc.kind) {
|
|
87
|
+
case "enum":
|
|
88
|
+
case "message": {
|
|
89
|
+
let descName;
|
|
90
|
+
let shapeName;
|
|
91
|
+
for (let i = 0;; i++) {
|
|
92
|
+
descName = idealDescName(desc, i);
|
|
93
|
+
shapeName = idealShapeName(desc, i);
|
|
94
|
+
if (!taken.has(descName) && !taken.has(shapeName)) {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
taken.add(descName);
|
|
99
|
+
taken.add(shapeName);
|
|
100
|
+
descNames.set(desc, descName);
|
|
101
|
+
shapeNames.set(desc, shapeName);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
default: {
|
|
105
|
+
let descName;
|
|
106
|
+
for (let i = 0;; i++) {
|
|
107
|
+
descName = idealDescName(desc, i);
|
|
108
|
+
if (!taken.has(descName)) {
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
taken.add(descName);
|
|
113
|
+
descNames.set(desc, descName);
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return { shapeNames, descNames };
|
|
119
|
+
}
|
|
@@ -10,4 +10,4 @@ export interface ParsedParameter {
|
|
|
10
10
|
jsImportStyle: "module" | "legacy_commonjs";
|
|
11
11
|
sanitizedParameter: string;
|
|
12
12
|
}
|
|
13
|
-
export declare function parseParameter(parameter: string
|
|
13
|
+
export declare function parseParameter(parameter: string, parseExtraOption: ((key: string, value: string) => void) | undefined): ParsedParameter;
|
|
@@ -17,11 +17,11 @@ exports.parseParameter = void 0;
|
|
|
17
17
|
const error_js_1 = require("../error.js");
|
|
18
18
|
function parseParameter(parameter, parseExtraOption) {
|
|
19
19
|
let targets = ["js", "dts"];
|
|
20
|
-
let tsNocheck =
|
|
20
|
+
let tsNocheck = false;
|
|
21
21
|
let bootstrapWkt = false;
|
|
22
22
|
let keepEmptyFiles = false;
|
|
23
23
|
const rewriteImports = [];
|
|
24
|
-
let importExtension = "
|
|
24
|
+
let importExtension = "";
|
|
25
25
|
let jsImportStyle = "module";
|
|
26
26
|
const rawParameters = [];
|
|
27
27
|
for (const { key, value, raw } of splitParameter(parameter)) {
|
|
@@ -147,7 +147,7 @@ function parseParameter(parameter, parseExtraOption) {
|
|
|
147
147
|
}
|
|
148
148
|
exports.parseParameter = parseParameter;
|
|
149
149
|
function splitParameter(parameter) {
|
|
150
|
-
if (parameter ==
|
|
150
|
+
if (parameter.length == 0) {
|
|
151
151
|
return [];
|
|
152
152
|
}
|
|
153
153
|
return parameter.split(",").map((raw) => {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { DescEnum, DescExtension, DescFile, DescMessage, DescService } from "@bufbuild/protobuf";
|
|
2
|
+
import { ScalarType, LongType } from "@bufbuild/protobuf/reflect";
|
|
3
|
+
import type { ImportSymbol } from "./import-symbol.js";
|
|
4
|
+
/**
|
|
5
|
+
* All types that can be passed to GeneratedFile.print()
|
|
6
|
+
*/
|
|
7
|
+
export type Printable = string | number | boolean | bigint | Uint8Array | ImportSymbol | ExportStatement | JSDocBlock | LiteralString | LiteralProtoInt64 | DescImport | ShapeImport | Printable[];
|
|
8
|
+
export type ExportStatement = {
|
|
9
|
+
kind: "es_export_stmt";
|
|
10
|
+
name: string;
|
|
11
|
+
declaration?: string;
|
|
12
|
+
};
|
|
13
|
+
export type LiteralProtoInt64 = {
|
|
14
|
+
readonly kind: "es_proto_int64";
|
|
15
|
+
type: ScalarType.INT64 | ScalarType.SINT64 | ScalarType.SFIXED64 | ScalarType.UINT64 | ScalarType.FIXED64;
|
|
16
|
+
longType: LongType;
|
|
17
|
+
value: bigint | string;
|
|
18
|
+
};
|
|
19
|
+
export type LiteralString = {
|
|
20
|
+
readonly kind: "es_string";
|
|
21
|
+
value: string;
|
|
22
|
+
};
|
|
23
|
+
export type DescImport = {
|
|
24
|
+
readonly kind: "es_desc_ref";
|
|
25
|
+
desc: DescMessage | DescEnum | DescExtension | DescService | DescFile;
|
|
26
|
+
typeOnly?: boolean;
|
|
27
|
+
};
|
|
28
|
+
export type ShapeImport = {
|
|
29
|
+
readonly kind: "es_shape_ref";
|
|
30
|
+
desc: DescMessage | DescEnum;
|
|
31
|
+
};
|
|
32
|
+
export type JSDocBlock = {
|
|
33
|
+
readonly kind: "es_jsdoc";
|
|
34
|
+
text: string;
|
|
35
|
+
indentation?: string;
|
|
36
|
+
};
|
|
@@ -1,25 +1,14 @@
|
|
|
1
1
|
import type { ImportSymbol } from "./import-symbol.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
proto3: ImportSymbol;
|
|
5
|
-
Message: ImportSymbol;
|
|
6
|
-
PartialMessage: ImportSymbol;
|
|
7
|
-
PlainMessage: ImportSymbol;
|
|
8
|
-
FieldList: ImportSymbol;
|
|
9
|
-
MessageType: ImportSymbol;
|
|
10
|
-
Extension: ImportSymbol;
|
|
11
|
-
BinaryReadOptions: ImportSymbol;
|
|
12
|
-
BinaryWriteOptions: ImportSymbol;
|
|
13
|
-
JsonReadOptions: ImportSymbol;
|
|
14
|
-
JsonWriteOptions: ImportSymbol;
|
|
15
|
-
JsonValue: ImportSymbol;
|
|
16
|
-
JsonObject: ImportSymbol;
|
|
17
|
-
protoDouble: ImportSymbol;
|
|
18
|
-
protoInt64: ImportSymbol;
|
|
19
|
-
ScalarType: ImportSymbol;
|
|
20
|
-
LongType: ImportSymbol;
|
|
21
|
-
MethodKind: ImportSymbol;
|
|
22
|
-
MethodIdempotency: ImportSymbol;
|
|
23
|
-
IMessageTypeRegistry: ImportSymbol;
|
|
24
|
-
}
|
|
2
|
+
import { symbols } from "@bufbuild/protobuf/codegenv1";
|
|
3
|
+
export type RuntimeImports = mapRecord<typeof symbols>;
|
|
25
4
|
export declare function createRuntimeImports(bootstrapWkt: boolean): RuntimeImports;
|
|
5
|
+
type mapRecord<T extends Record<string, unknown>> = {
|
|
6
|
+
[P in keyof T]: T[P] extends symbolInfo ? ImportSymbol : T[P] extends Record<string, unknown> ? mapRecord<T[P]> : never;
|
|
7
|
+
};
|
|
8
|
+
declare function mapRecord<T extends Record<string, unknown>>(record: T, bootstrapWkt: boolean): mapRecord<T>;
|
|
9
|
+
type symbolInfo = {
|
|
10
|
+
readonly typeOnly: boolean;
|
|
11
|
+
readonly from: string;
|
|
12
|
+
readonly bootstrapWktFrom: string;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -15,36 +15,35 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.createRuntimeImports = void 0;
|
|
17
17
|
const import_symbol_js_1 = require("./import-symbol.js");
|
|
18
|
-
const
|
|
18
|
+
const codegenv1_1 = require("@bufbuild/protobuf/codegenv1");
|
|
19
19
|
function createRuntimeImports(bootstrapWkt) {
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
proto2: infoToSymbol("proto2", bootstrapWkt),
|
|
23
|
-
proto3: infoToSymbol("proto3", bootstrapWkt),
|
|
24
|
-
Message: infoToSymbol("Message", bootstrapWkt),
|
|
25
|
-
PartialMessage: infoToSymbol("PartialMessage", bootstrapWkt),
|
|
26
|
-
PlainMessage: infoToSymbol("PlainMessage", bootstrapWkt),
|
|
27
|
-
FieldList: infoToSymbol("FieldList", bootstrapWkt),
|
|
28
|
-
MessageType: infoToSymbol("MessageType", bootstrapWkt),
|
|
29
|
-
Extension: infoToSymbol("Extension", bootstrapWkt),
|
|
30
|
-
BinaryReadOptions: infoToSymbol("BinaryReadOptions", bootstrapWkt),
|
|
31
|
-
BinaryWriteOptions: infoToSymbol("BinaryWriteOptions", bootstrapWkt),
|
|
32
|
-
JsonReadOptions: infoToSymbol("JsonReadOptions", bootstrapWkt),
|
|
33
|
-
JsonWriteOptions: infoToSymbol("JsonWriteOptions", bootstrapWkt),
|
|
34
|
-
JsonValue: infoToSymbol("JsonValue", bootstrapWkt),
|
|
35
|
-
JsonObject: infoToSymbol("JsonObject", bootstrapWkt),
|
|
36
|
-
protoDouble: infoToSymbol("protoDouble", bootstrapWkt),
|
|
37
|
-
protoInt64: infoToSymbol("protoInt64", bootstrapWkt),
|
|
38
|
-
ScalarType: infoToSymbol("ScalarType", bootstrapWkt),
|
|
39
|
-
LongType: infoToSymbol("LongType", bootstrapWkt),
|
|
40
|
-
MethodKind: infoToSymbol("MethodKind", bootstrapWkt),
|
|
41
|
-
MethodIdempotency: infoToSymbol("MethodIdempotency", bootstrapWkt),
|
|
42
|
-
IMessageTypeRegistry: infoToSymbol("IMessageTypeRegistry", bootstrapWkt),
|
|
43
|
-
};
|
|
20
|
+
return mapRecord(codegenv1_1.symbols, bootstrapWkt);
|
|
44
21
|
}
|
|
45
22
|
exports.createRuntimeImports = createRuntimeImports;
|
|
46
|
-
function
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
23
|
+
function mapRecord(record, bootstrapWkt) {
|
|
24
|
+
const result = Object.create(null);
|
|
25
|
+
for (const [key, value] of Object.entries(record)) {
|
|
26
|
+
if (isSymbolInfo(value)) {
|
|
27
|
+
result[key] = (0, import_symbol_js_1.createImportSymbol)(key, bootstrapWkt ? value.bootstrapWktFrom : value.from, value.typeOnly);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
result[key] = mapRecord(record[key], bootstrapWkt);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
function isSymbolInfo(arg) {
|
|
36
|
+
if (typeof arg != "object" || arg === null) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const wantNames = [
|
|
40
|
+
"typeOnly",
|
|
41
|
+
"from",
|
|
42
|
+
"bootstrapWktFrom",
|
|
43
|
+
];
|
|
44
|
+
const gotNames = Object.getOwnPropertyNames(arg);
|
|
45
|
+
if (gotNames.length !== wantNames.length) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return wantNames.every((w) => gotNames.includes(w));
|
|
50
49
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
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.safeIdentifier = void 0;
|
|
17
|
+
/**
|
|
18
|
+
* Names that cannot be used for identifiers, such as class names,
|
|
19
|
+
* but _can_ be used for object properties.
|
|
20
|
+
*/
|
|
21
|
+
const reservedIdentifiers = new Set([
|
|
22
|
+
// ECMAScript 2015 keywords
|
|
23
|
+
"break",
|
|
24
|
+
"case",
|
|
25
|
+
"catch",
|
|
26
|
+
"class",
|
|
27
|
+
"const",
|
|
28
|
+
"continue",
|
|
29
|
+
"debugger",
|
|
30
|
+
"default",
|
|
31
|
+
"delete",
|
|
32
|
+
"do",
|
|
33
|
+
"else",
|
|
34
|
+
"export",
|
|
35
|
+
"extends",
|
|
36
|
+
"false",
|
|
37
|
+
"finally",
|
|
38
|
+
"for",
|
|
39
|
+
"function",
|
|
40
|
+
"if",
|
|
41
|
+
"import",
|
|
42
|
+
"in",
|
|
43
|
+
"instanceof",
|
|
44
|
+
"new",
|
|
45
|
+
"null",
|
|
46
|
+
"return",
|
|
47
|
+
"super",
|
|
48
|
+
"switch",
|
|
49
|
+
"this",
|
|
50
|
+
"throw",
|
|
51
|
+
"true",
|
|
52
|
+
"try",
|
|
53
|
+
"typeof",
|
|
54
|
+
"var",
|
|
55
|
+
"void",
|
|
56
|
+
"while",
|
|
57
|
+
"with",
|
|
58
|
+
"yield",
|
|
59
|
+
// ECMAScript 2015 future reserved keywords
|
|
60
|
+
"enum",
|
|
61
|
+
"implements",
|
|
62
|
+
"interface",
|
|
63
|
+
"let",
|
|
64
|
+
"package",
|
|
65
|
+
"private",
|
|
66
|
+
"protected",
|
|
67
|
+
"public",
|
|
68
|
+
"static",
|
|
69
|
+
// Class name cannot be 'Object' when targeting ES5 with module CommonJS
|
|
70
|
+
"Object",
|
|
71
|
+
// TypeScript keywords that cannot be used for types (as opposed to variables)
|
|
72
|
+
"bigint",
|
|
73
|
+
"number",
|
|
74
|
+
"boolean",
|
|
75
|
+
"string",
|
|
76
|
+
"object",
|
|
77
|
+
// Identifiers reserved for the runtime, so we can generate legible code
|
|
78
|
+
"globalThis",
|
|
79
|
+
"Uint8Array",
|
|
80
|
+
"Partial",
|
|
81
|
+
]);
|
|
82
|
+
/**
|
|
83
|
+
* Escapes names that are reserved identifiers in ECMAScript, TypeScript.
|
|
84
|
+
*
|
|
85
|
+
* Also see safeObjectProperty() from @bufbuild/protoplugin/reflect.
|
|
86
|
+
*/
|
|
87
|
+
function safeIdentifier(name) {
|
|
88
|
+
return reservedIdentifiers.has(name) ? name + "$" : name;
|
|
89
|
+
}
|
|
90
|
+
exports.safeIdentifier = safeIdentifier;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { DescEnum, DescExtension, DescFile, DescMessage, DescService } from "@bufbuild/protobuf";
|
|
2
|
+
import type { CodeGeneratorRequest } from "@bufbuild/protobuf/wkt";
|
|
3
|
+
import { Edition } from "@bufbuild/protobuf/wkt";
|
|
3
4
|
import type { FileInfo, GeneratedFile } from "./generated-file.js";
|
|
4
|
-
import type { RuntimeImports } from "./runtime-imports.js";
|
|
5
5
|
import type { Target } from "./target.js";
|
|
6
6
|
import type { ParsedParameter } from "./parameter.js";
|
|
7
7
|
/**
|
|
@@ -21,14 +21,15 @@ export interface Schema {
|
|
|
21
21
|
* The plugin option `target`. A code generator should support all targets.
|
|
22
22
|
*/
|
|
23
23
|
readonly targets: readonly Target[];
|
|
24
|
-
/**
|
|
25
|
-
* Provides some symbols from the runtime library @bufbuild/protobuf.
|
|
26
|
-
*/
|
|
27
|
-
readonly runtime: RuntimeImports;
|
|
28
24
|
/**
|
|
29
25
|
* Generate a new file with the given name.
|
|
30
26
|
*/
|
|
31
27
|
generateFile(name: string): GeneratedFile;
|
|
28
|
+
/**
|
|
29
|
+
* List all types in a file (including messages, enumerations, and extensions
|
|
30
|
+
* nested in messages).
|
|
31
|
+
*/
|
|
32
|
+
typesInFile(file: DescFile): Iterable<DescMessage | DescEnum | DescExtension | DescService>;
|
|
32
33
|
/**
|
|
33
34
|
* The original google.protobuf.compiler.CodeGeneratorRequest.
|
|
34
35
|
*/
|
|
@@ -38,5 +39,5 @@ interface SchemaController extends Schema {
|
|
|
38
39
|
getFileInfo: () => FileInfo[];
|
|
39
40
|
prepareGenerate(target: Target): void;
|
|
40
41
|
}
|
|
41
|
-
export declare function createSchema(request: CodeGeneratorRequest, parameter: ParsedParameter, pluginName: string, pluginVersion: string,
|
|
42
|
+
export declare function createSchema(request: CodeGeneratorRequest, parameter: ParsedParameter, pluginName: string, pluginVersion: string, minimumEdition: Edition, maximumEdition: Edition): SchemaController;
|
|
42
43
|
export {};
|