@aptre/protobuf-es-lite 0.2.7 → 0.2.8
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/.ignore +1 -0
- package/README.md +23 -24
- package/bin/protoc-gen-es-lite +3 -3
- package/dist/binary-encoding.d.ts +420 -0
- package/dist/binary-encoding.js +437 -0
- package/dist/binary.d.ts +35 -2
- package/dist/binary.js +64 -65
- package/dist/codegen-info.d.ts +43 -0
- package/dist/codegen-info.js +72 -0
- package/dist/create-descriptor-set.d.ts +36 -0
- package/dist/create-descriptor-set.js +936 -0
- package/dist/descriptor-set.d.ts +672 -0
- package/dist/{editions.js → descriptor-set.js} +0 -11
- package/dist/enum.d.ts +35 -1
- package/dist/feature-set.d.ts +19 -0
- package/dist/feature-set.js +103 -0
- package/dist/field-wrapper.d.ts +7 -3
- package/dist/field-wrapper.js +30 -1
- package/dist/field.d.ts +8 -19
- package/dist/field.js +15 -117
- package/dist/google/index.d.ts +9 -0
- package/dist/google/index.js +41 -0
- package/dist/google/protobuf/any.pb.d.ts +139 -0
- package/dist/google/protobuf/any.pb.js +42 -0
- package/dist/google/protobuf/api.pb.d.ts +252 -0
- package/dist/google/protobuf/api.pb.js +70 -0
- package/dist/google/protobuf/compiler/plugin.pb.d.ts +240 -0
- package/dist/google/protobuf/compiler/plugin.pb.js +203 -0
- package/dist/google/protobuf/descriptor.pb.d.ts +2132 -0
- package/dist/google/protobuf/descriptor.pb.js +1080 -0
- package/dist/google/protobuf/duration.pb.d.ts +92 -0
- package/dist/google/protobuf/duration.pb.js +42 -0
- package/dist/google/protobuf/empty.pb.d.ts +18 -0
- package/dist/google/protobuf/empty.pb.js +39 -0
- package/dist/google/protobuf/source_context.pb.d.ts +21 -0
- package/dist/google/protobuf/source_context.pb.js +41 -0
- package/dist/google/protobuf/struct.pb.d.ts +121 -0
- package/dist/google/protobuf/struct.pb.js +83 -0
- package/dist/google/protobuf/timestamp.pb.d.ts +121 -0
- package/dist/google/protobuf/timestamp.pb.js +42 -0
- package/dist/google/protobuf/type.pb.d.ts +464 -0
- package/dist/google/protobuf/type.pb.js +338 -0
- package/dist/google/protobuf/wrappers.pb.d.ts +183 -0
- package/dist/google/protobuf/wrappers.pb.js +107 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.js +38 -8
- package/dist/is-message.d.ts +10 -2
- package/dist/is-message.js +74 -3
- package/dist/json.d.ts +68 -1
- package/dist/json.js +57 -81
- package/dist/message.d.ts +30 -61
- package/dist/message.js +61 -20
- package/dist/names.d.ts +43 -0
- package/dist/names.js +276 -0
- package/dist/partial.js +14 -15
- package/dist/proto-base64.d.ts +18 -0
- package/dist/proto-base64.js +128 -0
- package/dist/proto-double.d.ts +5 -0
- package/dist/proto-double.js +29 -0
- package/dist/proto-int64.d.ts +95 -0
- package/dist/proto-int64.js +116 -0
- package/dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.d.ts +1 -0
- package/dist/{protoc-gen-es-lite-plugin.js → protoc-gen-es-lite/protoc-gen-es-lite-plugin.js} +2 -2
- package/dist/{typescript.d.ts → protoc-gen-es-lite/typescript.d.ts} +3 -2
- package/dist/{typescript.js → protoc-gen-es-lite/typescript.js} +46 -34
- package/dist/protoplugin/create-es-plugin.d.ts +83 -0
- package/dist/protoplugin/create-es-plugin.js +119 -0
- package/dist/protoplugin/ecmascript/file-preamble.d.ts +2 -0
- package/dist/protoplugin/ecmascript/file-preamble.js +74 -0
- package/dist/protoplugin/ecmascript/generated-file.d.ts +116 -0
- package/dist/protoplugin/ecmascript/generated-file.js +407 -0
- package/dist/protoplugin/ecmascript/import-path.d.ts +65 -0
- package/dist/protoplugin/ecmascript/import-path.js +156 -0
- package/dist/protoplugin/ecmascript/import-symbol.d.ts +39 -0
- package/dist/protoplugin/ecmascript/import-symbol.js +37 -0
- package/dist/protoplugin/ecmascript/index.d.ts +7 -0
- package/dist/protoplugin/ecmascript/index.js +20 -0
- package/dist/protoplugin/ecmascript/jsdoc.d.ts +14 -0
- package/dist/protoplugin/ecmascript/jsdoc.js +93 -0
- package/dist/protoplugin/ecmascript/opaque-printables.d.ts +27 -0
- package/dist/protoplugin/ecmascript/opaque-printables.js +15 -0
- package/dist/protoplugin/ecmascript/parameter.d.ts +13 -0
- package/dist/protoplugin/ecmascript/parameter.js +161 -0
- package/dist/protoplugin/ecmascript/reify-wkt.d.ts +100 -0
- package/dist/protoplugin/ecmascript/reify-wkt.js +170 -0
- package/dist/protoplugin/ecmascript/runtime-imports.d.ts +6 -0
- package/dist/protoplugin/ecmascript/runtime-imports.js +28 -0
- package/dist/protoplugin/ecmascript/schema.d.ts +43 -0
- package/dist/protoplugin/ecmascript/schema.js +73 -0
- package/dist/protoplugin/ecmascript/target.d.ts +4 -0
- package/dist/protoplugin/ecmascript/target.js +15 -0
- package/dist/protoplugin/ecmascript/transpile.d.ts +2 -0
- package/dist/protoplugin/ecmascript/transpile.js +149 -0
- package/dist/protoplugin/error.d.ts +6 -0
- package/dist/protoplugin/error.js +43 -0
- package/dist/protoplugin/index.d.ts +8 -0
- package/dist/protoplugin/index.js +20 -0
- package/dist/protoplugin/plugin.d.ts +18 -0
- package/dist/protoplugin/plugin.js +15 -0
- package/dist/protoplugin/run-node.d.ts +12 -0
- package/dist/protoplugin/run-node.js +83 -0
- package/dist/scalar.d.ts +53 -1
- package/dist/scalar.js +87 -22
- package/dist/service-type.d.ts +95 -0
- package/dist/service-type.js +53 -0
- package/dist/text-format.d.ts +4 -0
- package/dist/text-format.js +189 -0
- package/dist/type-registry.d.ts +43 -0
- package/dist/type-registry.js +15 -0
- package/dist/unknown.d.ts +1 -1
- package/dist/util.d.ts +2 -2
- package/dist/util.js +46 -44
- package/dist/varint.d.ts +70 -0
- package/dist/varint.js +324 -0
- package/example/example.pb.ts +87 -0
- package/example/example.proto +1 -0
- package/example/tsconfig.json +8 -2
- package/package.json +19 -12
- package/tsconfig.json +4 -4
- package/dist/editions.d.ts +0 -6
- package/dist/protoc-gen-es-lite-plugin.d.ts +0 -1
|
@@ -0,0 +1,37 @@
|
|
|
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.createImportSymbol = void 0;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new import symbol.
|
|
19
|
+
*/
|
|
20
|
+
function createImportSymbol(name, from, typeOnly) {
|
|
21
|
+
const id = `import("${from}").${name}`;
|
|
22
|
+
const s = {
|
|
23
|
+
kind: "es_symbol",
|
|
24
|
+
name,
|
|
25
|
+
from,
|
|
26
|
+
typeOnly: false,
|
|
27
|
+
id,
|
|
28
|
+
toTypeOnly() {
|
|
29
|
+
return {
|
|
30
|
+
...this,
|
|
31
|
+
typeOnly: true,
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
return typeOnly === true ? s.toTypeOnly() : s;
|
|
36
|
+
}
|
|
37
|
+
exports.createImportSymbol = createImportSymbol;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { reifyWkt } from "./reify-wkt.js";
|
|
2
|
+
export type { Target } from "./target.js";
|
|
3
|
+
export type { Schema } from "./schema.js";
|
|
4
|
+
export type { RuntimeImports } from "./runtime-imports.js";
|
|
5
|
+
export type { GeneratedFile, FileInfo, Printable } from "./generated-file.js";
|
|
6
|
+
export type { ImportSymbol } from "./import-symbol.js";
|
|
7
|
+
export { createImportSymbol } from "./import-symbol.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
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.createImportSymbol = exports.reifyWkt = void 0;
|
|
17
|
+
var reify_wkt_js_1 = require("./reify-wkt.js");
|
|
18
|
+
Object.defineProperty(exports, "reifyWkt", { enumerable: true, get: function () { return reify_wkt_js_1.reifyWkt; } });
|
|
19
|
+
var import_symbol_js_1 = require("./import-symbol.js");
|
|
20
|
+
Object.defineProperty(exports, "createImportSymbol", { enumerable: true, get: function () { return import_symbol_js_1.createImportSymbol; } });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AnyDesc, DescFile } from "../../descriptor-set.js";
|
|
2
|
+
export type JSDocBlock = {
|
|
3
|
+
readonly kind: "es_jsdoc";
|
|
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;
|
|
@@ -0,0 +1,93 @@
|
|
|
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.createJsDocBlock = void 0;
|
|
17
|
+
// TODO simplify type JSDocBlock to bring it in line with others in opaque-printables.ts
|
|
18
|
+
function createJsDocBlock(textOrDesc, indentation) {
|
|
19
|
+
const text = typeof textOrDesc == "string" ? textOrDesc : createTextForDesc(textOrDesc);
|
|
20
|
+
return {
|
|
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 ?? "";
|
|
35
|
+
return [`${i}/**\n`, ...lines.map((l) => `${i} *${l}\n`), `${i} */`].join("");
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.createJsDocBlock = createJsDocBlock;
|
|
40
|
+
function createTextForDesc(desc) {
|
|
41
|
+
const comments = desc.getComments();
|
|
42
|
+
let text = "";
|
|
43
|
+
if (comments.leading !== undefined) {
|
|
44
|
+
text += comments.leading;
|
|
45
|
+
if (text.endsWith("\n")) {
|
|
46
|
+
text = text.substring(0, text.length - 1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (comments.trailing !== undefined) {
|
|
50
|
+
if (text.length > 0) {
|
|
51
|
+
text += "\n\n";
|
|
52
|
+
}
|
|
53
|
+
text += comments.trailing;
|
|
54
|
+
if (text.endsWith("\n")) {
|
|
55
|
+
text = text.substring(0, text.length - 1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (text.length > 0) {
|
|
59
|
+
text += "\n\n";
|
|
60
|
+
}
|
|
61
|
+
text = text
|
|
62
|
+
.split("\n")
|
|
63
|
+
.map((line) => (line.startsWith(" ") ? line.substring(1) : line))
|
|
64
|
+
.join("\n");
|
|
65
|
+
switch (desc.kind) {
|
|
66
|
+
case "enum_value":
|
|
67
|
+
text += `@generated from enum value: ${desc.declarationString()};`;
|
|
68
|
+
break;
|
|
69
|
+
case "field":
|
|
70
|
+
text += `@generated from field: ${desc.declarationString()};`;
|
|
71
|
+
break;
|
|
72
|
+
case "extension":
|
|
73
|
+
text += `@generated from extension: ${desc.declarationString()};`;
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
text += `@generated from ${desc.toString()}`;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
let deprecated = desc.deprecated;
|
|
80
|
+
switch (desc.kind) {
|
|
81
|
+
case "enum":
|
|
82
|
+
case "message":
|
|
83
|
+
case "service":
|
|
84
|
+
deprecated = deprecated || (desc.file.proto.options?.deprecated ?? false);
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
if (deprecated) {
|
|
90
|
+
text += "\n@deprecated";
|
|
91
|
+
}
|
|
92
|
+
return text;
|
|
93
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DescEnum, DescExtension, DescMessage } from "../../descriptor-set.js";
|
|
2
|
+
import { LongType, ScalarType } from "../../scalar.js";
|
|
3
|
+
export type LiteralProtoInt64 = {
|
|
4
|
+
readonly kind: "es_proto_int64";
|
|
5
|
+
type: ScalarType.INT64 | ScalarType.SINT64 | ScalarType.SFIXED64 | ScalarType.UINT64 | ScalarType.FIXED64;
|
|
6
|
+
longType: LongType;
|
|
7
|
+
value: bigint | string;
|
|
8
|
+
};
|
|
9
|
+
export type LiteralString = {
|
|
10
|
+
readonly kind: "es_string";
|
|
11
|
+
value: string;
|
|
12
|
+
};
|
|
13
|
+
export type RefDescMessage = {
|
|
14
|
+
readonly kind: "es_ref_message";
|
|
15
|
+
type: DescMessage;
|
|
16
|
+
typeOnly: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type RefDescEnum = {
|
|
19
|
+
readonly kind: "es_ref_enum";
|
|
20
|
+
type: DescEnum;
|
|
21
|
+
typeOnly: boolean;
|
|
22
|
+
};
|
|
23
|
+
export type ExportDeclaration = {
|
|
24
|
+
readonly kind: "es_export_decl";
|
|
25
|
+
declaration: string;
|
|
26
|
+
name: string | DescMessage | DescEnum | DescExtension;
|
|
27
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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 });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Target } from "./target.js";
|
|
2
|
+
import type { RewriteImports } from "./import-path.js";
|
|
3
|
+
export interface ParsedParameter {
|
|
4
|
+
targets: Target[];
|
|
5
|
+
tsNocheck: boolean;
|
|
6
|
+
bootstrapWkt: boolean;
|
|
7
|
+
keepEmptyFiles: boolean;
|
|
8
|
+
rewriteImports: RewriteImports;
|
|
9
|
+
importExtension: string;
|
|
10
|
+
jsImportStyle: "module" | "legacy_commonjs";
|
|
11
|
+
sanitizedParameter: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function parseParameter(parameter: string | undefined, parseExtraOption: ((key: string, value: string) => void) | undefined): ParsedParameter;
|
|
@@ -0,0 +1,161 @@
|
|
|
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.parseParameter = void 0;
|
|
17
|
+
const error_js_1 = require("../error.js");
|
|
18
|
+
function parseParameter(parameter, parseExtraOption) {
|
|
19
|
+
let targets = ["js", "dts"];
|
|
20
|
+
let tsNocheck = true;
|
|
21
|
+
let bootstrapWkt = false;
|
|
22
|
+
let keepEmptyFiles = false;
|
|
23
|
+
const rewriteImports = [];
|
|
24
|
+
let importExtension = ".js";
|
|
25
|
+
let jsImportStyle = "module";
|
|
26
|
+
const rawParameters = [];
|
|
27
|
+
for (const { key, value, raw } of splitParameter(parameter)) {
|
|
28
|
+
// Whether this key/value plugin parameter pair should be
|
|
29
|
+
// printed to the generated file preamble
|
|
30
|
+
let sanitize = false;
|
|
31
|
+
switch (key) {
|
|
32
|
+
case "target":
|
|
33
|
+
targets = [];
|
|
34
|
+
for (const rawTarget of value.split("+")) {
|
|
35
|
+
switch (rawTarget) {
|
|
36
|
+
case "js":
|
|
37
|
+
case "ts":
|
|
38
|
+
case "dts":
|
|
39
|
+
if (targets.indexOf(rawTarget) < 0) {
|
|
40
|
+
targets.push(rawTarget);
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
throw new error_js_1.PluginOptionError(raw);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
value.split("+");
|
|
48
|
+
break;
|
|
49
|
+
case "ts_nocheck":
|
|
50
|
+
switch (value) {
|
|
51
|
+
case "true":
|
|
52
|
+
case "1":
|
|
53
|
+
tsNocheck = true;
|
|
54
|
+
break;
|
|
55
|
+
case "false":
|
|
56
|
+
case "0":
|
|
57
|
+
tsNocheck = false;
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
throw new error_js_1.PluginOptionError(raw);
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
case "bootstrap_wkt":
|
|
64
|
+
switch (value) {
|
|
65
|
+
case "true":
|
|
66
|
+
case "1":
|
|
67
|
+
bootstrapWkt = true;
|
|
68
|
+
break;
|
|
69
|
+
case "false":
|
|
70
|
+
case "0":
|
|
71
|
+
bootstrapWkt = false;
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
throw new error_js_1.PluginOptionError(raw);
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
case "rewrite_imports": {
|
|
78
|
+
const parts = value.split(":");
|
|
79
|
+
if (parts.length !== 2) {
|
|
80
|
+
throw new error_js_1.PluginOptionError(raw, "must be in the form of <pattern>:<target>");
|
|
81
|
+
}
|
|
82
|
+
const [pattern, target] = parts;
|
|
83
|
+
rewriteImports.push({ pattern, target });
|
|
84
|
+
// rewrite_imports can be noisy and is more of an implementation detail
|
|
85
|
+
// so we strip it out of the preamble
|
|
86
|
+
sanitize = true;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
case "import_extension": {
|
|
90
|
+
importExtension = value === "none" ? "" : value;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
case "js_import_style":
|
|
94
|
+
switch (value) {
|
|
95
|
+
case "module":
|
|
96
|
+
jsImportStyle = value;
|
|
97
|
+
break;
|
|
98
|
+
case "legacy_commonjs":
|
|
99
|
+
jsImportStyle = value;
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
throw new error_js_1.PluginOptionError(raw);
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
case "keep_empty_files": {
|
|
106
|
+
switch (value) {
|
|
107
|
+
case "true":
|
|
108
|
+
case "1":
|
|
109
|
+
keepEmptyFiles = true;
|
|
110
|
+
break;
|
|
111
|
+
case "false":
|
|
112
|
+
case "0":
|
|
113
|
+
keepEmptyFiles = false;
|
|
114
|
+
break;
|
|
115
|
+
default:
|
|
116
|
+
throw new error_js_1.PluginOptionError(raw);
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
default:
|
|
121
|
+
if (parseExtraOption === undefined) {
|
|
122
|
+
throw new error_js_1.PluginOptionError(raw);
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
parseExtraOption(key, value);
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
throw new error_js_1.PluginOptionError(raw, e);
|
|
129
|
+
}
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
if (!sanitize) {
|
|
133
|
+
rawParameters.push(raw);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const sanitizedParameter = rawParameters.join(",");
|
|
137
|
+
return {
|
|
138
|
+
targets,
|
|
139
|
+
tsNocheck,
|
|
140
|
+
bootstrapWkt,
|
|
141
|
+
rewriteImports,
|
|
142
|
+
importExtension,
|
|
143
|
+
jsImportStyle,
|
|
144
|
+
keepEmptyFiles,
|
|
145
|
+
sanitizedParameter,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
exports.parseParameter = parseParameter;
|
|
149
|
+
function splitParameter(parameter) {
|
|
150
|
+
if (parameter == undefined) {
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
return parameter.split(",").map((raw) => {
|
|
154
|
+
const i = raw.indexOf("=");
|
|
155
|
+
return {
|
|
156
|
+
key: i === -1 ? raw : raw.substring(0, i),
|
|
157
|
+
value: i === -1 ? "" : raw.substring(i + 1),
|
|
158
|
+
raw,
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { DescField, DescMessage, DescOneof } from "../../descriptor-set.js";
|
|
2
|
+
type DescWkt = {
|
|
3
|
+
typeName: "google.protobuf.Any";
|
|
4
|
+
typeUrl: DescField;
|
|
5
|
+
value: DescField;
|
|
6
|
+
} | {
|
|
7
|
+
typeName: "google.protobuf.Timestamp";
|
|
8
|
+
seconds: DescField;
|
|
9
|
+
nanos: DescField;
|
|
10
|
+
} | {
|
|
11
|
+
typeName: "google.protobuf.Duration";
|
|
12
|
+
seconds: DescField;
|
|
13
|
+
nanos: DescField;
|
|
14
|
+
} | {
|
|
15
|
+
typeName: "google.protobuf.Struct";
|
|
16
|
+
fields: DescField & {
|
|
17
|
+
fieldKind: "map";
|
|
18
|
+
};
|
|
19
|
+
} | {
|
|
20
|
+
typeName: "google.protobuf.Value";
|
|
21
|
+
kind: DescOneof;
|
|
22
|
+
nullValue: DescField & {
|
|
23
|
+
fieldKind: "enum";
|
|
24
|
+
};
|
|
25
|
+
numberValue: DescField;
|
|
26
|
+
stringValue: DescField;
|
|
27
|
+
boolValue: DescField;
|
|
28
|
+
structValue: DescField & {
|
|
29
|
+
fieldKind: "message";
|
|
30
|
+
};
|
|
31
|
+
listValue: DescField & {
|
|
32
|
+
fieldKind: "message";
|
|
33
|
+
};
|
|
34
|
+
} | {
|
|
35
|
+
typeName: "google.protobuf.ListValue";
|
|
36
|
+
values: DescField & {
|
|
37
|
+
fieldKind: "message";
|
|
38
|
+
};
|
|
39
|
+
} | {
|
|
40
|
+
typeName: "google.protobuf.FieldMask";
|
|
41
|
+
paths: DescField;
|
|
42
|
+
} | {
|
|
43
|
+
typeName: "google.protobuf.DoubleValue";
|
|
44
|
+
value: DescField & {
|
|
45
|
+
fieldKind: "scalar";
|
|
46
|
+
};
|
|
47
|
+
} | {
|
|
48
|
+
typeName: "google.protobuf.FloatValue";
|
|
49
|
+
value: DescField & {
|
|
50
|
+
fieldKind: "scalar";
|
|
51
|
+
};
|
|
52
|
+
} | {
|
|
53
|
+
typeName: "google.protobuf.Int64Value";
|
|
54
|
+
value: DescField & {
|
|
55
|
+
fieldKind: "scalar";
|
|
56
|
+
};
|
|
57
|
+
} | {
|
|
58
|
+
typeName: "google.protobuf.UInt64Value";
|
|
59
|
+
value: DescField & {
|
|
60
|
+
fieldKind: "scalar";
|
|
61
|
+
};
|
|
62
|
+
} | {
|
|
63
|
+
typeName: "google.protobuf.Int32Value";
|
|
64
|
+
value: DescField & {
|
|
65
|
+
fieldKind: "scalar";
|
|
66
|
+
};
|
|
67
|
+
} | {
|
|
68
|
+
typeName: "google.protobuf.UInt32Value";
|
|
69
|
+
value: DescField & {
|
|
70
|
+
fieldKind: "scalar";
|
|
71
|
+
};
|
|
72
|
+
} | {
|
|
73
|
+
typeName: "google.protobuf.BoolValue";
|
|
74
|
+
value: DescField & {
|
|
75
|
+
fieldKind: "scalar";
|
|
76
|
+
};
|
|
77
|
+
} | {
|
|
78
|
+
typeName: "google.protobuf.StringValue";
|
|
79
|
+
value: DescField & {
|
|
80
|
+
fieldKind: "scalar";
|
|
81
|
+
};
|
|
82
|
+
} | {
|
|
83
|
+
typeName: "google.protobuf.BytesValue";
|
|
84
|
+
value: DescField & {
|
|
85
|
+
fieldKind: "scalar";
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Reifies a given DescMessage into a more concrete object representing its
|
|
90
|
+
* respective well-known type. The returned object will contain properties
|
|
91
|
+
* representing the WKT's defined fields.
|
|
92
|
+
*
|
|
93
|
+
* Useful during code generation when immediate access to a particular field
|
|
94
|
+
* is needed without having to search the object's typename and DescField list.
|
|
95
|
+
*
|
|
96
|
+
* Returns undefined if the WKT cannot be completely constructed via the
|
|
97
|
+
* DescMessage.
|
|
98
|
+
*/
|
|
99
|
+
export declare function reifyWkt(message: DescMessage): DescWkt | undefined;
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,170 @@
|
|
|
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.reifyWkt = void 0;
|
|
17
|
+
const scalar_js_1 = require("../../scalar.js");
|
|
18
|
+
/**
|
|
19
|
+
* Reifies a given DescMessage into a more concrete object representing its
|
|
20
|
+
* respective well-known type. The returned object will contain properties
|
|
21
|
+
* representing the WKT's defined fields.
|
|
22
|
+
*
|
|
23
|
+
* Useful during code generation when immediate access to a particular field
|
|
24
|
+
* is needed without having to search the object's typename and DescField list.
|
|
25
|
+
*
|
|
26
|
+
* Returns undefined if the WKT cannot be completely constructed via the
|
|
27
|
+
* DescMessage.
|
|
28
|
+
*/
|
|
29
|
+
function reifyWkt(message) {
|
|
30
|
+
switch (message.typeName) {
|
|
31
|
+
case "google.protobuf.Any": {
|
|
32
|
+
const typeUrl = message.fields.find((f) => f.number == 1 &&
|
|
33
|
+
f.fieldKind == "scalar" &&
|
|
34
|
+
f.scalar === scalar_js_1.ScalarType.STRING);
|
|
35
|
+
const value = message.fields.find((f) => f.number == 2 &&
|
|
36
|
+
f.fieldKind == "scalar" &&
|
|
37
|
+
f.scalar === scalar_js_1.ScalarType.BYTES);
|
|
38
|
+
if (typeUrl && value) {
|
|
39
|
+
return {
|
|
40
|
+
typeName: message.typeName,
|
|
41
|
+
typeUrl,
|
|
42
|
+
value,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "google.protobuf.Timestamp": {
|
|
48
|
+
const seconds = message.fields.find((f) => f.number == 1 &&
|
|
49
|
+
f.fieldKind == "scalar" &&
|
|
50
|
+
f.scalar === scalar_js_1.ScalarType.INT64);
|
|
51
|
+
const nanos = message.fields.find((f) => f.number == 2 &&
|
|
52
|
+
f.fieldKind == "scalar" &&
|
|
53
|
+
f.scalar === scalar_js_1.ScalarType.INT32);
|
|
54
|
+
if (seconds && nanos) {
|
|
55
|
+
return {
|
|
56
|
+
typeName: message.typeName,
|
|
57
|
+
seconds,
|
|
58
|
+
nanos,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case "google.protobuf.Duration": {
|
|
64
|
+
const seconds = message.fields.find((f) => f.number == 1 &&
|
|
65
|
+
f.fieldKind == "scalar" &&
|
|
66
|
+
f.scalar === scalar_js_1.ScalarType.INT64);
|
|
67
|
+
const nanos = message.fields.find((f) => f.number == 2 &&
|
|
68
|
+
f.fieldKind == "scalar" &&
|
|
69
|
+
f.scalar === scalar_js_1.ScalarType.INT32);
|
|
70
|
+
if (seconds && nanos) {
|
|
71
|
+
return {
|
|
72
|
+
typeName: message.typeName,
|
|
73
|
+
seconds,
|
|
74
|
+
nanos,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case "google.protobuf.Struct": {
|
|
80
|
+
const fields = message.fields.find((f) => f.number == 1 && !f.repeated);
|
|
81
|
+
if (fields?.fieldKind !== "map" ||
|
|
82
|
+
fields.mapValue.kind !== "message" ||
|
|
83
|
+
fields.mapValue.message.typeName !== "google.protobuf.Value") {
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
return { typeName: message.typeName, fields };
|
|
87
|
+
}
|
|
88
|
+
case "google.protobuf.Value": {
|
|
89
|
+
const kind = message.oneofs.find((o) => o.name === "kind");
|
|
90
|
+
const nullValue = message.fields.find((f) => f.number == 1 && f.oneof === kind);
|
|
91
|
+
if (nullValue?.fieldKind !== "enum" ||
|
|
92
|
+
nullValue.enum.typeName !== "google.protobuf.NullValue") {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const numberValue = message.fields.find((f) => f.number == 2 &&
|
|
96
|
+
f.fieldKind == "scalar" &&
|
|
97
|
+
f.scalar === scalar_js_1.ScalarType.DOUBLE &&
|
|
98
|
+
f.oneof === kind);
|
|
99
|
+
const stringValue = message.fields.find((f) => f.number == 3 &&
|
|
100
|
+
f.fieldKind == "scalar" &&
|
|
101
|
+
f.scalar === scalar_js_1.ScalarType.STRING &&
|
|
102
|
+
f.oneof === kind);
|
|
103
|
+
const boolValue = message.fields.find((f) => f.number == 4 &&
|
|
104
|
+
f.fieldKind == "scalar" &&
|
|
105
|
+
f.scalar === scalar_js_1.ScalarType.BOOL &&
|
|
106
|
+
f.oneof === kind);
|
|
107
|
+
const structValue = message.fields.find((f) => f.number == 5 && f.oneof === kind);
|
|
108
|
+
if (structValue?.fieldKind !== "message" ||
|
|
109
|
+
structValue.message.typeName !== "google.protobuf.Struct") {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
const listValue = message.fields.find((f) => f.number == 6 && f.oneof === kind);
|
|
113
|
+
if (listValue?.fieldKind !== "message" ||
|
|
114
|
+
listValue.message.typeName !== "google.protobuf.ListValue") {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
if (kind && numberValue && stringValue && boolValue) {
|
|
118
|
+
return {
|
|
119
|
+
typeName: message.typeName,
|
|
120
|
+
kind,
|
|
121
|
+
nullValue,
|
|
122
|
+
numberValue,
|
|
123
|
+
stringValue,
|
|
124
|
+
boolValue,
|
|
125
|
+
structValue,
|
|
126
|
+
listValue,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case "google.protobuf.ListValue": {
|
|
132
|
+
const values = message.fields.find((f) => f.number == 1 && f.repeated);
|
|
133
|
+
if (values?.fieldKind != "message" ||
|
|
134
|
+
values.message.typeName !== "google.protobuf.Value") {
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
return { typeName: message.typeName, values };
|
|
138
|
+
}
|
|
139
|
+
case "google.protobuf.FieldMask": {
|
|
140
|
+
const paths = message.fields.find((f) => f.number == 1 &&
|
|
141
|
+
f.fieldKind == "scalar" &&
|
|
142
|
+
f.scalar === scalar_js_1.ScalarType.STRING &&
|
|
143
|
+
f.repeated);
|
|
144
|
+
if (paths) {
|
|
145
|
+
return { typeName: message.typeName, paths };
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case "google.protobuf.DoubleValue":
|
|
150
|
+
case "google.protobuf.FloatValue":
|
|
151
|
+
case "google.protobuf.Int64Value":
|
|
152
|
+
case "google.protobuf.UInt64Value":
|
|
153
|
+
case "google.protobuf.Int32Value":
|
|
154
|
+
case "google.protobuf.UInt32Value":
|
|
155
|
+
case "google.protobuf.BoolValue":
|
|
156
|
+
case "google.protobuf.StringValue":
|
|
157
|
+
case "google.protobuf.BytesValue": {
|
|
158
|
+
const value = message.fields.find((f) => f.number == 1 && f.name == "value");
|
|
159
|
+
if (!value) {
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
if (value.fieldKind !== "scalar") {
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
return { typeName: message.typeName, value };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
exports.reifyWkt = reifyWkt;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ImportSymbol } from "./import-symbol.js";
|
|
2
|
+
import type { RuntimeSymbolName } from "../../codegen-info.js";
|
|
3
|
+
export type RuntimeImports = {
|
|
4
|
+
[K in RuntimeSymbolName]: ImportSymbol;
|
|
5
|
+
};
|
|
6
|
+
export declare function createRuntimeImports(bootstrapWkt: boolean): RuntimeImports;
|