@bufbuild/protoplugin 1.8.0 → 2.0.0-alpha.1

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.
Files changed (79) hide show
  1. package/dist/cjs/create-es-plugin.d.ts +8 -12
  2. package/dist/cjs/create-es-plugin.js +15 -13
  3. package/dist/cjs/ecmascript/file-preamble.js +8 -7
  4. package/dist/cjs/ecmascript/generated-file.d.ts +19 -20
  5. package/dist/cjs/ecmascript/generated-file.js +95 -108
  6. package/dist/cjs/ecmascript/import-path.d.ts +0 -6
  7. package/dist/cjs/ecmascript/import-path.js +1 -22
  8. package/dist/cjs/ecmascript/import-symbol.d.ts +1 -3
  9. package/dist/cjs/ecmascript/import-symbol.js +3 -5
  10. package/dist/cjs/ecmascript/index.d.ts +3 -16
  11. package/dist/cjs/ecmascript/index.js +3 -29
  12. package/dist/cjs/ecmascript/jsdoc.d.ts +2 -13
  13. package/dist/cjs/ecmascript/jsdoc.js +23 -31
  14. package/dist/cjs/ecmascript/names.d.ts +4 -0
  15. package/dist/cjs/ecmascript/names.js +119 -0
  16. package/dist/cjs/ecmascript/parameter.d.ts +3 -3
  17. package/dist/cjs/ecmascript/parameter.js +2 -2
  18. package/dist/cjs/ecmascript/printable.d.ts +36 -0
  19. package/dist/cjs/ecmascript/runtime-imports.d.ts +12 -23
  20. package/dist/cjs/ecmascript/runtime-imports.js +28 -29
  21. package/dist/cjs/ecmascript/safe-identifier.d.ts +6 -0
  22. package/dist/cjs/ecmascript/safe-identifier.js +90 -0
  23. package/dist/cjs/ecmascript/schema.d.ts +10 -9
  24. package/dist/cjs/ecmascript/schema.js +64 -20
  25. package/dist/cjs/ecmascript/transpile.js +1 -1
  26. package/dist/cjs/index.d.ts +2 -6
  27. package/dist/cjs/index.js +6 -1
  28. package/dist/cjs/plugin.d.ts +1 -1
  29. package/dist/cjs/run-node.js +4 -3
  30. package/dist/cjs/source-code-info.d.ts +18 -0
  31. package/dist/cjs/source-code-info.js +259 -0
  32. package/dist/esm/create-es-plugin.d.ts +8 -12
  33. package/dist/esm/create-es-plugin.js +15 -13
  34. package/dist/esm/ecmascript/file-preamble.js +5 -4
  35. package/dist/esm/ecmascript/generated-file.d.ts +19 -20
  36. package/dist/esm/ecmascript/generated-file.js +97 -110
  37. package/dist/esm/ecmascript/import-path.d.ts +0 -6
  38. package/dist/esm/ecmascript/import-path.js +0 -20
  39. package/dist/esm/ecmascript/import-symbol.d.ts +1 -3
  40. package/dist/esm/ecmascript/import-symbol.js +3 -5
  41. package/dist/esm/ecmascript/index.d.ts +3 -16
  42. package/dist/esm/ecmascript/index.js +1 -18
  43. package/dist/esm/ecmascript/jsdoc.d.ts +2 -13
  44. package/dist/esm/ecmascript/jsdoc.js +20 -29
  45. package/dist/esm/ecmascript/names.d.ts +4 -0
  46. package/dist/esm/ecmascript/names.js +113 -0
  47. package/dist/esm/ecmascript/parameter.d.ts +3 -3
  48. package/dist/esm/ecmascript/parameter.js +2 -2
  49. package/dist/esm/ecmascript/printable.d.ts +36 -0
  50. package/dist/esm/ecmascript/{opaque-printables.js → printable.js} +1 -1
  51. package/dist/esm/ecmascript/runtime-imports.d.ts +12 -23
  52. package/dist/esm/ecmascript/runtime-imports.js +28 -29
  53. package/dist/esm/ecmascript/safe-identifier.d.ts +6 -0
  54. package/dist/esm/ecmascript/safe-identifier.js +86 -0
  55. package/dist/esm/ecmascript/schema.d.ts +10 -9
  56. package/dist/esm/ecmascript/schema.js +66 -22
  57. package/dist/esm/ecmascript/transpile.js +1 -1
  58. package/dist/esm/index.d.ts +2 -6
  59. package/dist/esm/index.js +1 -0
  60. package/dist/esm/plugin.d.ts +1 -1
  61. package/dist/esm/run-node.js +4 -3
  62. package/dist/esm/source-code-info.d.ts +18 -0
  63. package/dist/esm/source-code-info.js +252 -0
  64. package/package.json +4 -4
  65. package/dist/cjs/ecmascript/legacy-custom-options.d.ts +0 -40
  66. package/dist/cjs/ecmascript/legacy-custom-options.js +0 -121
  67. package/dist/cjs/ecmascript/legacy-gencommon.d.ts +0 -26
  68. package/dist/cjs/ecmascript/legacy-gencommon.js +0 -237
  69. package/dist/cjs/ecmascript/opaque-printables.d.ts +0 -26
  70. package/dist/cjs/ecmascript/reify-wkt.d.ts +0 -100
  71. package/dist/cjs/ecmascript/reify-wkt.js +0 -170
  72. package/dist/esm/ecmascript/legacy-custom-options.d.ts +0 -40
  73. package/dist/esm/ecmascript/legacy-custom-options.js +0 -115
  74. package/dist/esm/ecmascript/legacy-gencommon.d.ts +0 -26
  75. package/dist/esm/ecmascript/legacy-gencommon.js +0 -230
  76. package/dist/esm/ecmascript/opaque-printables.d.ts +0 -26
  77. package/dist/esm/ecmascript/reify-wkt.d.ts +0 -100
  78. package/dist/esm/ecmascript/reify-wkt.js +0 -166
  79. /package/dist/cjs/ecmascript/{opaque-printables.js → printable.js} +0 -0
@@ -0,0 +1,252 @@
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 { isFieldSet } from "@bufbuild/protobuf";
15
+ import { ScalarType, protoCamelCase } from "@bufbuild/protobuf/reflect";
16
+ import { Edition, FieldDescriptorProto_Label, FieldDescriptorProto_Type, FieldDescriptorProtoDesc, FieldOptions_JSType, FieldOptionsDesc, SourceCodeInfo_LocationDesc, } from "@bufbuild/protobuf/wkt";
17
+ /**
18
+ * Get comments on the package element in the protobuf source.
19
+ */
20
+ export function getPackageComments(desc) {
21
+ return findComments(desc.proto.sourceCodeInfo, [
22
+ FieldNumber.FileDescriptorProto_Package,
23
+ ]);
24
+ }
25
+ /**
26
+ * Get comments on the syntax element in the protobuf source.
27
+ */
28
+ export function getSyntaxComments(desc) {
29
+ return findComments(desc.proto.sourceCodeInfo, [
30
+ FieldNumber.FileDescriptorProto_Syntax,
31
+ ]);
32
+ }
33
+ /**
34
+ * Get comments on the element in the protobuf source.
35
+ */
36
+ export function getComments(desc) {
37
+ let path = [];
38
+ let file;
39
+ switch (desc.kind) {
40
+ case "enum":
41
+ path = desc.parent
42
+ ? [
43
+ ...getComments(desc.parent).sourcePath,
44
+ FieldNumber.DescriptorProto_EnumType,
45
+ desc.parent.proto.enumType.indexOf(desc.proto),
46
+ ]
47
+ : [
48
+ FieldNumber.FileDescriptorProto_EnumType,
49
+ desc.file.proto.enumType.indexOf(desc.proto),
50
+ ];
51
+ file = desc.file;
52
+ break;
53
+ case "oneof":
54
+ path = [
55
+ ...getComments(desc.parent).sourcePath,
56
+ FieldNumber.DescriptorProto_OneofDecl,
57
+ desc.parent.proto.oneofDecl.indexOf(desc.proto),
58
+ ];
59
+ file = desc.parent.file;
60
+ break;
61
+ case "message":
62
+ path = desc.parent
63
+ ? [
64
+ ...getComments(desc.parent).sourcePath,
65
+ FieldNumber.DescriptorProto_NestedType,
66
+ desc.parent.proto.nestedType.indexOf(desc.proto),
67
+ ]
68
+ : [
69
+ FieldNumber.FileDescriptorProto_MessageType,
70
+ desc.file.proto.messageType.indexOf(desc.proto),
71
+ ];
72
+ file = desc.file;
73
+ break;
74
+ case "enum_value":
75
+ path = [
76
+ ...getComments(desc.parent).sourcePath,
77
+ FieldNumber.EnumDescriptorProto_Value,
78
+ desc.parent.proto.value.indexOf(desc.proto),
79
+ ];
80
+ file = desc.parent.file;
81
+ break;
82
+ case "field":
83
+ path = [
84
+ ...getComments(desc.parent).sourcePath,
85
+ FieldNumber.DescriptorProto_Field,
86
+ desc.parent.proto.field.indexOf(desc.proto),
87
+ ];
88
+ file = desc.parent.file;
89
+ break;
90
+ case "extension":
91
+ path = desc.parent
92
+ ? [
93
+ ...getComments(desc.parent).sourcePath,
94
+ FieldNumber.DescriptorProto_Extension,
95
+ desc.parent.proto.extension.indexOf(desc.proto),
96
+ ]
97
+ : [
98
+ FieldNumber.FileDescriptorProto_Extension,
99
+ desc.file.proto.extension.indexOf(desc.proto),
100
+ ];
101
+ file = desc.file;
102
+ break;
103
+ case "service":
104
+ path = [
105
+ FieldNumber.FileDescriptorProto_Service,
106
+ desc.file.proto.service.indexOf(desc.proto),
107
+ ];
108
+ file = desc.file;
109
+ break;
110
+ case "rpc":
111
+ path = [
112
+ ...getComments(desc.parent).sourcePath,
113
+ FieldNumber.ServiceDescriptorProto_Method,
114
+ desc.parent.proto.method.indexOf(desc.proto),
115
+ ];
116
+ file = desc.parent.file;
117
+ break;
118
+ }
119
+ return findComments(file.proto.sourceCodeInfo, path);
120
+ }
121
+ /**
122
+ * Return a string that matches the definition of a field in the protobuf
123
+ * source. Does not take custom options into account.
124
+ */
125
+ export function getDeclarationString(desc) {
126
+ var _a;
127
+ if (desc.kind === "enum_value") {
128
+ let str = `${desc.name} = ${desc.number}`;
129
+ if (((_a = desc.proto.options) === null || _a === void 0 ? void 0 : _a.deprecated) === true) {
130
+ str += " [deprecated = true]";
131
+ }
132
+ return str;
133
+ }
134
+ const file = desc.kind === "extension" ? desc.file : desc.parent.file;
135
+ const parts = [];
136
+ function typeName(f) {
137
+ if (f.message) {
138
+ return f.message.typeName;
139
+ }
140
+ if (f.enum) {
141
+ return f.enum.typeName;
142
+ }
143
+ return ScalarType[f.scalar].toLowerCase();
144
+ }
145
+ switch (desc.fieldKind) {
146
+ case "scalar":
147
+ case "enum":
148
+ case "message":
149
+ if (file.edition === Edition.EDITION_PROTO2 &&
150
+ isFieldSet(FieldDescriptorProtoDesc, desc.proto, "label") &&
151
+ desc.proto.label == FieldDescriptorProto_Label.REQUIRED) {
152
+ parts.push("required");
153
+ }
154
+ if (desc.optional) {
155
+ parts.push("optional");
156
+ }
157
+ parts.push(typeName(desc));
158
+ break;
159
+ case "list":
160
+ parts.push("repeated", typeName(desc));
161
+ break;
162
+ case "map": {
163
+ const k = ScalarType[desc.mapKey].toLowerCase();
164
+ const v = typeName(desc);
165
+ parts.push(`map<${k}, ${v}>`);
166
+ break;
167
+ }
168
+ }
169
+ parts.push(desc.name, "=", desc.number.toString());
170
+ const options = [];
171
+ const protoOptions = desc.proto.options;
172
+ if (protoOptions !== undefined &&
173
+ isFieldSet(FieldOptionsDesc, protoOptions, "packed")) {
174
+ options.push(`packed = ${protoOptions.packed.toString()}`);
175
+ }
176
+ if (isFieldSet(FieldDescriptorProtoDesc, desc.proto, "defaultValue")) {
177
+ let defaultValue = desc.proto.defaultValue;
178
+ if (desc.proto.type == FieldDescriptorProto_Type.BYTES ||
179
+ desc.proto.type == FieldDescriptorProto_Type.STRING) {
180
+ defaultValue = '"' + defaultValue.replace('"', '\\"') + '"';
181
+ }
182
+ options.push(`default = ${defaultValue}`);
183
+ }
184
+ if (desc.kind == "field" && desc.jsonName !== protoCamelCase(desc.name)) {
185
+ options.push(`json_name = "${desc.jsonName}"`);
186
+ }
187
+ if (protoOptions !== undefined &&
188
+ isFieldSet(FieldOptionsDesc, protoOptions, "jstype")) {
189
+ options.push(`jstype = ${FieldOptions_JSType[protoOptions.jstype]}`);
190
+ }
191
+ if (protoOptions !== undefined &&
192
+ isFieldSet(FieldOptionsDesc, protoOptions, "deprecated")) {
193
+ options.push(`deprecated = true`);
194
+ }
195
+ if (options.length > 0) {
196
+ parts.push("[" + options.join(", ") + "]");
197
+ }
198
+ return parts.join(" ");
199
+ }
200
+ /**
201
+ * Find comments.
202
+ */
203
+ function findComments(sourceCodeInfo, sourcePath) {
204
+ if (!sourceCodeInfo) {
205
+ return {
206
+ leadingDetached: [],
207
+ sourcePath,
208
+ };
209
+ }
210
+ for (const location of sourceCodeInfo.location) {
211
+ if (location.path.length !== sourcePath.length) {
212
+ continue;
213
+ }
214
+ if (location.path.some((value, index) => sourcePath[index] !== value)) {
215
+ continue;
216
+ }
217
+ return {
218
+ leadingDetached: location.leadingDetachedComments,
219
+ leading: isFieldSet(SourceCodeInfo_LocationDesc, location, "leadingComments")
220
+ ? location.leadingComments
221
+ : undefined,
222
+ trailing: isFieldSet(SourceCodeInfo_LocationDesc, location, "trailingComments")
223
+ ? location.trailingComments
224
+ : undefined,
225
+ sourcePath,
226
+ };
227
+ }
228
+ return {
229
+ leadingDetached: [],
230
+ sourcePath,
231
+ };
232
+ }
233
+ /**
234
+ * The following field numbers are used to find comments in
235
+ * google.protobuf.SourceCodeInfo.
236
+ */
237
+ var FieldNumber;
238
+ (function (FieldNumber) {
239
+ FieldNumber[FieldNumber["FileDescriptorProto_Package"] = 2] = "FileDescriptorProto_Package";
240
+ FieldNumber[FieldNumber["FileDescriptorProto_MessageType"] = 4] = "FileDescriptorProto_MessageType";
241
+ FieldNumber[FieldNumber["FileDescriptorProto_EnumType"] = 5] = "FileDescriptorProto_EnumType";
242
+ FieldNumber[FieldNumber["FileDescriptorProto_Service"] = 6] = "FileDescriptorProto_Service";
243
+ FieldNumber[FieldNumber["FileDescriptorProto_Extension"] = 7] = "FileDescriptorProto_Extension";
244
+ FieldNumber[FieldNumber["FileDescriptorProto_Syntax"] = 12] = "FileDescriptorProto_Syntax";
245
+ FieldNumber[FieldNumber["DescriptorProto_Field"] = 2] = "DescriptorProto_Field";
246
+ FieldNumber[FieldNumber["DescriptorProto_NestedType"] = 3] = "DescriptorProto_NestedType";
247
+ FieldNumber[FieldNumber["DescriptorProto_EnumType"] = 4] = "DescriptorProto_EnumType";
248
+ FieldNumber[FieldNumber["DescriptorProto_Extension"] = 6] = "DescriptorProto_Extension";
249
+ FieldNumber[FieldNumber["DescriptorProto_OneofDecl"] = 8] = "DescriptorProto_OneofDecl";
250
+ FieldNumber[FieldNumber["EnumDescriptorProto_Value"] = 2] = "EnumDescriptorProto_Value";
251
+ FieldNumber[FieldNumber["ServiceDescriptorProto_Method"] = 2] = "ServiceDescriptorProto_Method";
252
+ })(FieldNumber || (FieldNumber = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protoplugin",
3
- "version": "1.8.0",
3
+ "version": "2.0.0-alpha.1",
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": {
@@ -11,8 +11,8 @@
11
11
  "scripts": {
12
12
  "clean": "rm -rf ./dist/*",
13
13
  "build": "npm run build:cjs && npm run build:esm",
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
- "build:esm": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
14
+ "build:cjs": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --verbatimModuleSyntax false --moduleResolution node10 --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
15
+ "build:esm": "../../node_modules/typescript/bin/tsc --project tsconfig.json --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
16
16
  "attw": "attw --pack"
17
17
  },
18
18
  "type": "module",
@@ -36,7 +36,7 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
- "@bufbuild/protobuf": "1.8.0",
39
+ "@bufbuild/protobuf": "2.0.0-alpha.1",
40
40
  "@typescript/vfs": "^1.4.0",
41
41
  "typescript": "4.5.2"
42
42
  },
@@ -1,40 +0,0 @@
1
- import type { AnyDesc } from "@bufbuild/protobuf";
2
- import { Message, MessageType, ScalarType } from "@bufbuild/protobuf";
3
- /**
4
- * @deprecated Please use extensions instead.
5
- *
6
- * Returns the value of a custom option with a scalar type.
7
- *
8
- * If no option is found, returns undefined.
9
- */
10
- export declare function findCustomScalarOption<T extends ScalarType>(desc: AnyDesc, extensionNumber: number, scalarType: T): ScalarValue<T> | undefined;
11
- /**
12
- * @deprecated Please use extensions instead.
13
- *
14
- * Returns the value of a custom message option for the given descriptor and
15
- * extension number.
16
- * The msgType param is then used to deserialize the message for returning to
17
- * the caller.
18
- *
19
- * If no options are found, returns undefined.
20
- *
21
- * If the message option is unable to be read or deserialized, an error will
22
- * be thrown.
23
- */
24
- export declare function findCustomMessageOption<T extends Message<T>>(desc: AnyDesc, extensionNumber: number, msgType: MessageType<T>): T | undefined;
25
- /**
26
- * @deprecated Please use extensions instead.
27
- *
28
- * Returns the value of a custom enum option for the given descriptor and
29
- * extension number.
30
- *
31
- * If no options are found, returns undefined.
32
- */
33
- export declare function findCustomEnumOption(desc: AnyDesc, extensionNumber: number): number | undefined;
34
- /**
35
- * @deprecated Please use extensions instead.
36
- *
37
- * ScalarValue is a conditional type that pairs a ScalarType value with its concrete type.
38
- */
39
- type ScalarValue<T> = T extends ScalarType.STRING ? string : T extends ScalarType.INT32 ? number : T extends ScalarType.UINT32 ? number : T extends ScalarType.UINT32 ? number : T extends ScalarType.SINT32 ? number : T extends ScalarType.FIXED32 ? number : T extends ScalarType.SFIXED32 ? number : T extends ScalarType.FLOAT ? number : T extends ScalarType.DOUBLE ? number : T extends ScalarType.INT64 ? bigint | string : T extends ScalarType.SINT64 ? bigint | string : T extends ScalarType.SFIXED64 ? bigint | string : T extends ScalarType.UINT64 ? bigint | string : T extends ScalarType.FIXED64 ? bigint | string : T extends ScalarType.BOOL ? boolean : T extends ScalarType.BYTES ? Uint8Array : never;
40
- export {};
@@ -1,121 +0,0 @@
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.findCustomEnumOption = exports.findCustomMessageOption = exports.findCustomScalarOption = void 0;
17
- const protobuf_1 = require("@bufbuild/protobuf");
18
- /**
19
- * @deprecated Please use extensions instead.
20
- *
21
- * Returns the value of a custom option with a scalar type.
22
- *
23
- * If no option is found, returns undefined.
24
- */
25
- function findCustomScalarOption(desc, extensionNumber, scalarType) {
26
- const reader = createBinaryReader(desc, extensionNumber);
27
- if (reader) {
28
- switch (scalarType) {
29
- case protobuf_1.ScalarType.INT32:
30
- return reader.int32();
31
- case protobuf_1.ScalarType.UINT32:
32
- return reader.uint32();
33
- case protobuf_1.ScalarType.SINT32:
34
- return reader.sint32();
35
- case protobuf_1.ScalarType.FIXED32:
36
- return reader.fixed32();
37
- case protobuf_1.ScalarType.SFIXED32:
38
- return reader.sfixed32();
39
- case protobuf_1.ScalarType.FLOAT:
40
- return reader.float();
41
- case protobuf_1.ScalarType.DOUBLE:
42
- return reader.double();
43
- case protobuf_1.ScalarType.INT64:
44
- return reader.int64();
45
- case protobuf_1.ScalarType.SINT64:
46
- return reader.sint64();
47
- case protobuf_1.ScalarType.SFIXED64:
48
- return reader.sfixed64();
49
- case protobuf_1.ScalarType.UINT64:
50
- return reader.uint64();
51
- case protobuf_1.ScalarType.FIXED64:
52
- return reader.fixed64();
53
- case protobuf_1.ScalarType.BOOL:
54
- return reader.bool();
55
- case protobuf_1.ScalarType.BYTES:
56
- return reader.bytes();
57
- case protobuf_1.ScalarType.STRING:
58
- return reader.string();
59
- default: {
60
- break;
61
- }
62
- }
63
- }
64
- return undefined;
65
- }
66
- exports.findCustomScalarOption = findCustomScalarOption;
67
- /**
68
- * @deprecated Please use extensions instead.
69
- *
70
- * Returns the value of a custom message option for the given descriptor and
71
- * extension number.
72
- * The msgType param is then used to deserialize the message for returning to
73
- * the caller.
74
- *
75
- * If no options are found, returns undefined.
76
- *
77
- * If the message option is unable to be read or deserialized, an error will
78
- * be thrown.
79
- */
80
- function findCustomMessageOption(desc, extensionNumber, msgType) {
81
- const reader = createBinaryReader(desc, extensionNumber);
82
- if (reader) {
83
- try {
84
- const data = reader.bytes();
85
- return msgType.fromBinary(data);
86
- }
87
- catch (e) {
88
- const innerMessage = e instanceof Error ? e.message : String(e);
89
- throw new Error(`failed to access message option: ${innerMessage}`);
90
- }
91
- }
92
- return undefined;
93
- }
94
- exports.findCustomMessageOption = findCustomMessageOption;
95
- /**
96
- * @deprecated Please use extensions instead.
97
- *
98
- * Returns the value of a custom enum option for the given descriptor and
99
- * extension number.
100
- *
101
- * If no options are found, returns undefined.
102
- */
103
- function findCustomEnumOption(desc, extensionNumber) {
104
- return findCustomScalarOption(desc, extensionNumber, protobuf_1.ScalarType.INT32);
105
- }
106
- exports.findCustomEnumOption = findCustomEnumOption;
107
- /**
108
- * Returns a binary reader for the given descriptor and extension number.
109
- */
110
- function createBinaryReader(desc, extensionNumber) {
111
- const opt = desc.proto.options;
112
- let reader = undefined;
113
- if (opt !== undefined) {
114
- const unknownFields = protobuf_1.proto3.bin.listUnknownFields(opt);
115
- const field = unknownFields.find((f) => f.no === extensionNumber);
116
- if (field) {
117
- reader = new protobuf_1.BinaryReader(field.data);
118
- }
119
- }
120
- return reader;
121
- }
@@ -1,26 +0,0 @@
1
- import type { DescExtension } from "@bufbuild/protobuf";
2
- import { DescField } from "@bufbuild/protobuf";
3
- import type { GeneratedFile, Printable } from "./generated-file.js";
4
- import type { ImportSymbol } from "./import-symbol.js";
5
- /**
6
- * @deprecated Please use GeneratedFile.string() instead
7
- */
8
- export declare function literalString(value: string): string;
9
- /**
10
- * @deprecated
11
- */
12
- export declare function getFieldTyping(field: DescField | DescExtension, file: GeneratedFile): {
13
- typing: Printable;
14
- optional: boolean;
15
- };
16
- /**
17
- * @deprecated
18
- */
19
- export declare function getFieldExplicitDefaultValue(field: DescField | DescExtension, protoInt64Symbol: ImportSymbol): Printable | undefined;
20
- /**
21
- * @deprecated
22
- */
23
- export declare function getFieldIntrinsicDefaultValue(field: DescField): {
24
- defaultValue: Printable | undefined;
25
- typingInferrable: boolean;
26
- };