@bufbuild/protobuf 2.2.5 → 2.4.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/clone.js +4 -6
- package/dist/cjs/codegenv1/boot.js +1 -1
- package/dist/cjs/codegenv1/embed.js +0 -1
- package/dist/cjs/codegenv1/file.js +1 -1
- package/dist/cjs/codegenv1/symbols.js +4 -1
- package/dist/cjs/create.js +0 -1
- package/dist/cjs/equals.js +2 -1
- package/dist/cjs/extensions.js +1 -1
- package/dist/cjs/from-binary.js +5 -3
- package/dist/cjs/from-json.js +8 -10
- package/dist/cjs/proto-int64.js +4 -1
- package/dist/cjs/reflect/guard.js +2 -1
- package/dist/cjs/reflect/index.d.ts +1 -0
- package/dist/cjs/reflect/index.js +1 -0
- package/dist/cjs/reflect/names.d.ts +8 -0
- package/dist/cjs/reflect/names.js +28 -0
- package/dist/cjs/reflect/nested-types.d.ts +23 -0
- package/dist/cjs/reflect/nested-types.js +40 -0
- package/dist/cjs/reflect/path.d.ts +107 -0
- package/dist/cjs/reflect/path.js +376 -0
- package/dist/cjs/reflect/reflect-check.js +3 -3
- package/dist/cjs/reflect/reflect-types.d.ts +1 -1
- package/dist/cjs/reflect/reflect.js +9 -7
- package/dist/cjs/reflect/scalar.js +4 -5
- package/dist/cjs/reflect/unsafe.d.ts +3 -6
- package/dist/cjs/reflect/unsafe.js +11 -10
- package/dist/cjs/registry.js +24 -30
- package/dist/cjs/to-binary.js +1 -1
- package/dist/cjs/to-json.d.ts +6 -0
- package/dist/cjs/to-json.js +16 -18
- package/dist/cjs/wire/base64-encoding.js +4 -3
- package/dist/cjs/wire/binary-encoding.js +7 -6
- package/dist/cjs/wire/text-encoding.js +1 -1
- package/dist/cjs/wire/text-format.js +3 -4
- package/dist/cjs/wire/varint.js +0 -1
- package/dist/cjs/wkt/gen/google/protobuf/cpp_features_pb.d.ts +89 -0
- package/dist/cjs/wkt/gen/google/protobuf/cpp_features_pb.js +60 -0
- package/dist/cjs/wkt/gen/google/protobuf/go_features_pb.d.ts +122 -0
- package/dist/cjs/wkt/gen/google/protobuf/go_features_pb.js +90 -0
- package/dist/cjs/wkt/gen/google/protobuf/java_features_pb.d.ts +113 -0
- package/dist/cjs/wkt/gen/google/protobuf/java_features_pb.js +67 -0
- package/dist/cjs/wkt/index.d.ts +4 -1
- package/dist/cjs/wkt/index.js +4 -1
- package/dist/esm/clone.js +4 -6
- package/dist/esm/codegenv1/boot.js +1 -1
- package/dist/esm/codegenv1/embed.js +0 -1
- package/dist/esm/codegenv1/file.js +1 -1
- package/dist/esm/codegenv1/symbols.js +4 -1
- package/dist/esm/create.js +0 -2
- package/dist/esm/equals.js +2 -1
- package/dist/esm/extensions.js +1 -1
- package/dist/esm/from-binary.js +5 -3
- package/dist/esm/from-json.js +8 -10
- package/dist/esm/proto-int64.js +4 -1
- package/dist/esm/reflect/guard.js +2 -1
- package/dist/esm/reflect/index.d.ts +1 -0
- package/dist/esm/reflect/index.js +1 -0
- package/dist/esm/reflect/names.d.ts +8 -0
- package/dist/esm/reflect/names.js +27 -0
- package/dist/esm/reflect/nested-types.d.ts +23 -0
- package/dist/esm/reflect/nested-types.js +39 -0
- package/dist/esm/reflect/path.d.ts +107 -0
- package/dist/esm/reflect/path.js +369 -0
- package/dist/esm/reflect/reflect-check.js +3 -3
- package/dist/esm/reflect/reflect-types.d.ts +1 -1
- package/dist/esm/reflect/reflect-types.js +0 -1
- package/dist/esm/reflect/reflect.js +9 -7
- package/dist/esm/reflect/scalar.js +4 -5
- package/dist/esm/reflect/unsafe.d.ts +3 -6
- package/dist/esm/reflect/unsafe.js +11 -10
- package/dist/esm/registry.js +24 -30
- package/dist/esm/to-binary.js +1 -1
- package/dist/esm/to-json.d.ts +6 -0
- package/dist/esm/to-json.js +16 -18
- package/dist/esm/wire/base64-encoding.js +4 -3
- package/dist/esm/wire/binary-encoding.js +7 -6
- package/dist/esm/wire/text-encoding.js +1 -1
- package/dist/esm/wire/text-format.js +3 -4
- package/dist/esm/wire/varint.js +0 -1
- package/dist/esm/wkt/gen/google/protobuf/cpp_features_pb.d.ts +89 -0
- package/dist/esm/wkt/gen/google/protobuf/cpp_features_pb.js +57 -0
- package/dist/esm/wkt/gen/google/protobuf/go_features_pb.d.ts +122 -0
- package/dist/esm/wkt/gen/google/protobuf/go_features_pb.js +87 -0
- package/dist/esm/wkt/gen/google/protobuf/java_features_pb.d.ts +113 -0
- package/dist/esm/wkt/gen/google/protobuf/java_features_pb.js +64 -0
- package/dist/esm/wkt/index.d.ts +4 -1
- package/dist/esm/wkt/index.js +4 -1
- package/package.json +9 -24
package/dist/cjs/clone.js
CHANGED
|
@@ -30,24 +30,22 @@ function cloneReflect(i) {
|
|
|
30
30
|
continue;
|
|
31
31
|
}
|
|
32
32
|
switch (f.fieldKind) {
|
|
33
|
-
default: {
|
|
34
|
-
o.set(f, cloneSingular(f, i.get(f)));
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
33
|
case "list":
|
|
38
|
-
// eslint-disable-next-line no-case-declarations
|
|
39
34
|
const list = o.get(f);
|
|
40
35
|
for (const item of i.get(f)) {
|
|
41
36
|
list.add(cloneSingular(f, item));
|
|
42
37
|
}
|
|
43
38
|
break;
|
|
44
39
|
case "map":
|
|
45
|
-
// eslint-disable-next-line no-case-declarations
|
|
46
40
|
const map = o.get(f);
|
|
47
41
|
for (const entry of i.get(f).entries()) {
|
|
48
42
|
map.set(entry[0], cloneSingular(f, entry[1]));
|
|
49
43
|
}
|
|
50
44
|
break;
|
|
45
|
+
default: {
|
|
46
|
+
o.set(f, cloneSingular(f, i.get(f)));
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
51
|
const unknown = i.getUnknown();
|
|
@@ -29,7 +29,7 @@ function boot(boot) {
|
|
|
29
29
|
const root = bootFileDescriptorProto(boot);
|
|
30
30
|
root.messageType.forEach(restore_json_names_js_1.restoreJsonNames);
|
|
31
31
|
const reg = (0, registry_js_1.createFileRegistry)(root, () => undefined);
|
|
32
|
-
// non-null assertion because we just created the registry from the file we look up
|
|
32
|
+
// biome-ignore lint/style/noNonNullAssertion: non-null assertion because we just created the registry from the file we look up
|
|
33
33
|
return reg.getFile(root.name);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
@@ -235,7 +235,6 @@ function createEnumDescriptorBoot(proto) {
|
|
|
235
235
|
* Assert that condition is truthy or throw error.
|
|
236
236
|
*/
|
|
237
237
|
function assert(condition) {
|
|
238
|
-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we want the implicit conversion to boolean
|
|
239
238
|
if (!condition) {
|
|
240
239
|
throw new Error();
|
|
241
240
|
}
|
|
@@ -30,6 +30,6 @@ function fileDesc(b64, imports) {
|
|
|
30
30
|
root.messageType.forEach(restore_json_names_js_1.restoreJsonNames);
|
|
31
31
|
root.dependency = (_a = imports === null || imports === void 0 ? void 0 : imports.map((f) => f.proto.name)) !== null && _a !== void 0 ? _a : [];
|
|
32
32
|
const reg = (0, registry_js_1.createFileRegistry)(root, (protoFileName) => imports === null || imports === void 0 ? void 0 : imports.find((f) => f.proto.name === protoFileName));
|
|
33
|
-
// non-null assertion because we just created the registry from the file we look up
|
|
33
|
+
// biome-ignore lint/style/noNonNullAssertion: non-null assertion because we just created the registry from the file we look up
|
|
34
34
|
return reg.getFile(root.name);
|
|
35
35
|
}
|
|
@@ -25,10 +25,13 @@ exports.wktPublicImportPaths = {
|
|
|
25
25
|
"google/protobuf/compiler/plugin.proto": exports.packageName + "/wkt",
|
|
26
26
|
"google/protobuf/any.proto": exports.packageName + "/wkt",
|
|
27
27
|
"google/protobuf/api.proto": exports.packageName + "/wkt",
|
|
28
|
+
"google/protobuf/cpp_features.proto": exports.packageName + "/wkt",
|
|
28
29
|
"google/protobuf/descriptor.proto": exports.packageName + "/wkt",
|
|
29
30
|
"google/protobuf/duration.proto": exports.packageName + "/wkt",
|
|
30
31
|
"google/protobuf/empty.proto": exports.packageName + "/wkt",
|
|
31
32
|
"google/protobuf/field_mask.proto": exports.packageName + "/wkt",
|
|
33
|
+
"google/protobuf/go_features.proto": exports.packageName + "/wkt",
|
|
34
|
+
"google/protobuf/java_features.proto": exports.packageName + "/wkt",
|
|
32
35
|
"google/protobuf/source_context.proto": exports.packageName + "/wkt",
|
|
33
36
|
"google/protobuf/struct.proto": exports.packageName + "/wkt",
|
|
34
37
|
"google/protobuf/timestamp.proto": exports.packageName + "/wkt",
|
|
@@ -38,7 +41,7 @@ exports.wktPublicImportPaths = {
|
|
|
38
41
|
/**
|
|
39
42
|
* @private
|
|
40
43
|
*/
|
|
41
|
-
//
|
|
44
|
+
// biome-ignore format: want this to read well
|
|
42
45
|
exports.symbols = {
|
|
43
46
|
isMessage: { typeOnly: false, bootstrapWktFrom: "../../is-message.js", from: exports.packageName },
|
|
44
47
|
Message: { typeOnly: true, bootstrapWktFrom: "../../types.js", from: exports.packageName },
|
package/dist/cjs/create.js
CHANGED
|
@@ -64,7 +64,6 @@ function initMessage(messageDesc, message, init) {
|
|
|
64
64
|
else {
|
|
65
65
|
field = member;
|
|
66
66
|
}
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- no need to convert enum
|
|
68
67
|
switch (field.fieldKind) {
|
|
69
68
|
case "message":
|
|
70
69
|
value = toMessage(field, value);
|
package/dist/cjs/equals.js
CHANGED
|
@@ -165,7 +165,8 @@ function unknownEquals(a, b, registry) {
|
|
|
165
165
|
return false;
|
|
166
166
|
}
|
|
167
167
|
for (let i = 0; i < unknownA.length; i++) {
|
|
168
|
-
const a = unknownA[i]
|
|
168
|
+
const a = unknownA[i];
|
|
169
|
+
const b = unknownB[i];
|
|
169
170
|
if (a.no != b.no) {
|
|
170
171
|
return false;
|
|
171
172
|
}
|
package/dist/cjs/extensions.js
CHANGED
|
@@ -151,7 +151,7 @@ function createExtensionContainer(extension, value) {
|
|
|
151
151
|
() => {
|
|
152
152
|
const value = container[localName];
|
|
153
153
|
if (value === undefined) {
|
|
154
|
-
// Only message fields are undefined, rest will have a zero value.
|
|
154
|
+
// biome-ignore lint/style/noNonNullAssertion: Only message fields are undefined, rest will have a zero value.
|
|
155
155
|
const desc = extension.message;
|
|
156
156
|
if ((0, wrappers_js_1.isWrapperDesc)(desc)) {
|
|
157
157
|
return (0, scalar_js_1.scalarZeroValue)(desc.fields[0].scalar, desc.fields[0].longAsString);
|
package/dist/cjs/from-binary.js
CHANGED
|
@@ -59,7 +59,8 @@ function mergeFromBinary(schema, target, bytes, options) {
|
|
|
59
59
|
function readMessage(message, reader, options, delimited, lengthOrDelimitedFieldNo) {
|
|
60
60
|
var _a;
|
|
61
61
|
const end = delimited ? reader.len : reader.pos + lengthOrDelimitedFieldNo;
|
|
62
|
-
let fieldNo
|
|
62
|
+
let fieldNo;
|
|
63
|
+
let wireType;
|
|
63
64
|
const unknownFields = (_a = message.getUnknown()) !== null && _a !== void 0 ? _a : [];
|
|
64
65
|
while (reader.pos < end) {
|
|
65
66
|
[fieldNo, wireType] = reader.tag();
|
|
@@ -78,7 +79,7 @@ function readMessage(message, reader, options, delimited, lengthOrDelimitedField
|
|
|
78
79
|
}
|
|
79
80
|
if (delimited) {
|
|
80
81
|
if (wireType != binary_encoding_js_1.WireType.EndGroup || fieldNo !== lengthOrDelimitedFieldNo) {
|
|
81
|
-
throw new Error(
|
|
82
|
+
throw new Error("invalid end group tag");
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
if (unknownFields.length > 0) {
|
|
@@ -110,7 +111,8 @@ function readField(message, reader, field, wireType, options) {
|
|
|
110
111
|
// Read a map field, expecting key field = 1, value field = 2
|
|
111
112
|
function readMapEntry(reader, map, options) {
|
|
112
113
|
const field = map.field();
|
|
113
|
-
let key
|
|
114
|
+
let key;
|
|
115
|
+
let val;
|
|
114
116
|
const end = reader.pos + reader.uint32();
|
|
115
117
|
while (reader.pos < end) {
|
|
116
118
|
const [fieldNo] = reader.tag();
|
package/dist/cjs/from-json.js
CHANGED
|
@@ -19,7 +19,6 @@ exports.fromJson = fromJson;
|
|
|
19
19
|
exports.mergeFromJson = mergeFromJson;
|
|
20
20
|
exports.enumFromJson = enumFromJson;
|
|
21
21
|
exports.isEnumJson = isEnumJson;
|
|
22
|
-
/* eslint-disable no-case-declarations,@typescript-eslint/restrict-template-expressions */
|
|
23
22
|
const descriptors_js_1 = require("./descriptors.js");
|
|
24
23
|
const proto_int64_js_1 = require("./proto-int64.js");
|
|
25
24
|
const create_js_1 = require("./create.js");
|
|
@@ -104,7 +103,7 @@ function mergeFromJson(schema, target, json, options) {
|
|
|
104
103
|
function enumFromJson(descEnum, json) {
|
|
105
104
|
const val = readEnum(descEnum, json, false, false);
|
|
106
105
|
if (val === tokenIgnoredUnknownEnum) {
|
|
107
|
-
throw new Error(`cannot decode ${
|
|
106
|
+
throw new Error(`cannot decode ${descEnum} from JSON: ${(0, reflect_check_js_1.formatVal)(json)}`);
|
|
108
107
|
}
|
|
109
108
|
return val;
|
|
110
109
|
}
|
|
@@ -147,6 +146,7 @@ function readMessage(msg, json, opts) {
|
|
|
147
146
|
let extension = undefined;
|
|
148
147
|
if (jsonKey.startsWith("[") &&
|
|
149
148
|
jsonKey.endsWith("]") &&
|
|
149
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: no
|
|
150
150
|
(extension = (_a = opts.registry) === null || _a === void 0 ? void 0 : _a.getExtension(jsonKey.substring(1, jsonKey.length - 1))) &&
|
|
151
151
|
extension.extendee.typeName === msg.desc.typeName) {
|
|
152
152
|
const [container, field, get] = (0, extensions_js_1.createExtensionContainer)(extension);
|
|
@@ -276,7 +276,6 @@ function readEnum(desc, json, ignoreUnknownFields, nullAsZeroValue) {
|
|
|
276
276
|
}
|
|
277
277
|
return nullAsZeroValue ? desc.values[0].number : tokenNull;
|
|
278
278
|
}
|
|
279
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
280
279
|
switch (typeof json) {
|
|
281
280
|
case "number":
|
|
282
281
|
if (Number.isInteger(json)) {
|
|
@@ -305,7 +304,6 @@ function scalarFromJson(field, json, nullAsZeroValue) {
|
|
|
305
304
|
}
|
|
306
305
|
// int64, sfixed64, sint64, fixed64, uint64: Reflect supports string and number.
|
|
307
306
|
// string, bool: Supported by reflect.
|
|
308
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
309
307
|
switch (field.scalar) {
|
|
310
308
|
// float, double: JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity".
|
|
311
309
|
// Either numbers or strings are accepted. Exponent notation is also accepted.
|
|
@@ -318,11 +316,11 @@ function scalarFromJson(field, json, nullAsZeroValue) {
|
|
|
318
316
|
if (json === "-Infinity")
|
|
319
317
|
return Number.NEGATIVE_INFINITY;
|
|
320
318
|
if (typeof json == "number") {
|
|
321
|
-
if (isNaN(json)) {
|
|
319
|
+
if (Number.isNaN(json)) {
|
|
322
320
|
// NaN must be encoded with string constants
|
|
323
321
|
throw new error_js_1.FieldError(field, "unexpected NaN number");
|
|
324
322
|
}
|
|
325
|
-
if (!isFinite(json)) {
|
|
323
|
+
if (!Number.isFinite(json)) {
|
|
326
324
|
// Infinity must be encoded with string constants
|
|
327
325
|
throw new error_js_1.FieldError(field, "unexpected infinite number");
|
|
328
326
|
}
|
|
@@ -338,7 +336,7 @@ function scalarFromJson(field, json, nullAsZeroValue) {
|
|
|
338
336
|
break;
|
|
339
337
|
}
|
|
340
338
|
const float = Number(json);
|
|
341
|
-
if (!isFinite(float)) {
|
|
339
|
+
if (!Number.isFinite(float)) {
|
|
342
340
|
// Infinity and NaN must be encoded with string constants
|
|
343
341
|
break;
|
|
344
342
|
}
|
|
@@ -379,7 +377,6 @@ function scalarFromJson(field, json, nullAsZeroValue) {
|
|
|
379
377
|
function mapKeyFromJson(type, json) {
|
|
380
378
|
switch (type) {
|
|
381
379
|
case descriptors_js_1.ScalarType.BOOL:
|
|
382
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
383
380
|
switch (json) {
|
|
384
381
|
case "true":
|
|
385
382
|
return true;
|
|
@@ -497,11 +494,12 @@ function anyFromJson(any, json, opts) {
|
|
|
497
494
|
const msg = (0, reflect_js_1.reflect)(desc);
|
|
498
495
|
if (typeName.startsWith("google.protobuf.") &&
|
|
499
496
|
Object.prototype.hasOwnProperty.call(json, "value")) {
|
|
500
|
-
const value = json
|
|
497
|
+
const value = json.value;
|
|
501
498
|
readMessage(msg, value, opts);
|
|
502
499
|
}
|
|
503
500
|
else {
|
|
504
501
|
const copy = Object.assign({}, json);
|
|
502
|
+
// biome-ignore lint/performance/noDelete: <explanation>
|
|
505
503
|
delete copy["@type"];
|
|
506
504
|
readMessage(msg, copy, opts);
|
|
507
505
|
}
|
|
@@ -516,7 +514,7 @@ function timestampFromJson(timestamp, json) {
|
|
|
516
514
|
throw new Error(`cannot decode message ${timestamp.$typeName} from JSON: invalid RFC 3339 string`);
|
|
517
515
|
}
|
|
518
516
|
const ms = Date.parse(
|
|
519
|
-
//
|
|
517
|
+
// biome-ignore format: want this to read well
|
|
520
518
|
matches[1] + "-" + matches[2] + "-" + matches[3] + "T" + matches[4] + ":" + matches[5] + ":" + matches[6] + (matches[8] ? matches[8] : "Z"));
|
|
521
519
|
if (Number.isNaN(ms)) {
|
|
522
520
|
throw new Error(`cannot decode message ${timestamp.$typeName} from JSON: invalid RFC 3339 string`);
|
package/dist/cjs/proto-int64.js
CHANGED
|
@@ -31,7 +31,10 @@ function makeInt64Support() {
|
|
|
31
31
|
typeof process.env != "object" ||
|
|
32
32
|
process.env.BUF_BIGINT_DISABLE !== "1");
|
|
33
33
|
if (ok) {
|
|
34
|
-
const MIN = BigInt("-9223372036854775808")
|
|
34
|
+
const MIN = BigInt("-9223372036854775808");
|
|
35
|
+
const MAX = BigInt("9223372036854775807");
|
|
36
|
+
const UMIN = BigInt("0");
|
|
37
|
+
const UMAX = BigInt("18446744073709551615");
|
|
35
38
|
return {
|
|
36
39
|
zero: BigInt(0),
|
|
37
40
|
supported: true,
|
|
@@ -38,7 +38,8 @@ function isReflectList(arg, field) {
|
|
|
38
38
|
"field" in arg &&
|
|
39
39
|
typeof arg.field == "function") {
|
|
40
40
|
if (field !== undefined) {
|
|
41
|
-
const a = field
|
|
41
|
+
const a = field;
|
|
42
|
+
const b = arg.field();
|
|
42
43
|
return (a.listKind == b.listKind &&
|
|
43
44
|
a.scalar === b.scalar &&
|
|
44
45
|
((_a = a.message) === null || _a === void 0 ? void 0 : _a.typeName) === ((_b = b.message) === null || _b === void 0 ? void 0 : _b.typeName) &&
|
|
@@ -34,6 +34,7 @@ __exportStar(require("./nested-types.js"), exports);
|
|
|
34
34
|
__exportStar(require("./reflect.js"), exports);
|
|
35
35
|
__exportStar(require("./reflect-types.js"), exports);
|
|
36
36
|
__exportStar(require("./scalar.js"), exports);
|
|
37
|
+
__exportStar(require("./path.js"), exports);
|
|
37
38
|
var guard_js_1 = require("./guard.js");
|
|
38
39
|
Object.defineProperty(exports, "isReflectList", { enumerable: true, get: function () { return guard_js_1.isReflectList; } });
|
|
39
40
|
Object.defineProperty(exports, "isReflectMap", { enumerable: true, get: function () { return guard_js_1.isReflectMap; } });
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import type { AnyDesc } from "../descriptors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Return a fully-qualified name for a Protobuf descriptor.
|
|
4
|
+
* For a file descriptor, return the original file path.
|
|
5
|
+
*
|
|
6
|
+
* See https://protobuf.com/docs/language-spec#fully-qualified-names
|
|
7
|
+
*/
|
|
8
|
+
export declare function qualifiedName(desc: AnyDesc): string;
|
|
1
9
|
/**
|
|
2
10
|
* Converts snake_case to protoCamelCase according to the convention
|
|
3
11
|
* used by protoc to convert a field name to a JSON name.
|
|
@@ -13,8 +13,36 @@
|
|
|
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.qualifiedName = qualifiedName;
|
|
16
17
|
exports.protoCamelCase = protoCamelCase;
|
|
17
18
|
exports.safeObjectProperty = safeObjectProperty;
|
|
19
|
+
/**
|
|
20
|
+
* Return a fully-qualified name for a Protobuf descriptor.
|
|
21
|
+
* For a file descriptor, return the original file path.
|
|
22
|
+
*
|
|
23
|
+
* See https://protobuf.com/docs/language-spec#fully-qualified-names
|
|
24
|
+
*/
|
|
25
|
+
function qualifiedName(desc) {
|
|
26
|
+
switch (desc.kind) {
|
|
27
|
+
case "field":
|
|
28
|
+
case "oneof":
|
|
29
|
+
case "rpc":
|
|
30
|
+
return desc.parent.typeName + "." + desc.name;
|
|
31
|
+
case "enum_value": {
|
|
32
|
+
const p = desc.parent.parent
|
|
33
|
+
? desc.parent.parent.typeName
|
|
34
|
+
: desc.parent.file.proto.package;
|
|
35
|
+
return p + (p.length > 0 ? "." : "") + desc.name;
|
|
36
|
+
}
|
|
37
|
+
case "service":
|
|
38
|
+
case "message":
|
|
39
|
+
case "enum":
|
|
40
|
+
case "extension":
|
|
41
|
+
return desc.typeName;
|
|
42
|
+
case "file":
|
|
43
|
+
return desc.proto.name;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
18
46
|
/**
|
|
19
47
|
* Converts snake_case to protoCamelCase according to the convention
|
|
20
48
|
* used by protoc to convert a field name to a JSON name.
|
|
@@ -4,6 +4,29 @@ import type { AnyDesc, DescEnum, DescExtension, DescFile, DescMessage, DescServi
|
|
|
4
4
|
* and enumerations, extensions and messages nested in messages.
|
|
5
5
|
*/
|
|
6
6
|
export declare function nestedTypes(desc: DescFile | DescMessage): Iterable<DescMessage | DescEnum | DescExtension | DescService>;
|
|
7
|
+
/**
|
|
8
|
+
* Iterate over types referenced by fields of the given message.
|
|
9
|
+
*
|
|
10
|
+
* For example:
|
|
11
|
+
*
|
|
12
|
+
* ```proto
|
|
13
|
+
* syntax="proto3";
|
|
14
|
+
*
|
|
15
|
+
* message Example {
|
|
16
|
+
* Msg singular = 1;
|
|
17
|
+
* repeated Level list = 2;
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* message Msg {}
|
|
21
|
+
*
|
|
22
|
+
* enum Level {
|
|
23
|
+
* LEVEL_UNSPECIFIED = 0;
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* The message Example references the message Msg, and the enum Level.
|
|
28
|
+
*/
|
|
29
|
+
export declare function usedTypes(descMessage: DescMessage): Iterable<DescMessage | DescEnum>;
|
|
7
30
|
/**
|
|
8
31
|
* Returns the ancestors of a given Protobuf element, up to the file.
|
|
9
32
|
*/
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.nestedTypes = nestedTypes;
|
|
17
|
+
exports.usedTypes = usedTypes;
|
|
17
18
|
exports.parentTypes = parentTypes;
|
|
18
19
|
/**
|
|
19
20
|
* Iterate over all types - enumerations, extensions, services, messages -
|
|
@@ -40,6 +41,45 @@ function* nestedTypes(desc) {
|
|
|
40
41
|
break;
|
|
41
42
|
}
|
|
42
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Iterate over types referenced by fields of the given message.
|
|
46
|
+
*
|
|
47
|
+
* For example:
|
|
48
|
+
*
|
|
49
|
+
* ```proto
|
|
50
|
+
* syntax="proto3";
|
|
51
|
+
*
|
|
52
|
+
* message Example {
|
|
53
|
+
* Msg singular = 1;
|
|
54
|
+
* repeated Level list = 2;
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* message Msg {}
|
|
58
|
+
*
|
|
59
|
+
* enum Level {
|
|
60
|
+
* LEVEL_UNSPECIFIED = 0;
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* The message Example references the message Msg, and the enum Level.
|
|
65
|
+
*/
|
|
66
|
+
function usedTypes(descMessage) {
|
|
67
|
+
return usedTypesInternal(descMessage, new Set());
|
|
68
|
+
}
|
|
69
|
+
function* usedTypesInternal(descMessage, seen) {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
for (const field of descMessage.fields) {
|
|
72
|
+
const ref = (_b = (_a = field.enum) !== null && _a !== void 0 ? _a : field.message) !== null && _b !== void 0 ? _b : undefined;
|
|
73
|
+
if (!ref || seen.has(ref.typeName)) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
seen.add(ref.typeName);
|
|
77
|
+
yield ref;
|
|
78
|
+
if (ref.kind == "message") {
|
|
79
|
+
yield* usedTypesInternal(ref, seen);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
43
83
|
/**
|
|
44
84
|
* Returns the ancestors of a given Protobuf element, up to the file.
|
|
45
85
|
*/
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type DescExtension, type DescField, type DescMessage, type DescOneof } from "../descriptors.js";
|
|
2
|
+
import type { Registry } from "../registry.js";
|
|
3
|
+
/**
|
|
4
|
+
* A path to a (nested) member of a Protobuf message, such as a field, oneof,
|
|
5
|
+
* extension, list element, or map entry.
|
|
6
|
+
*
|
|
7
|
+
* Note that we may add additional types to this union in the future to support
|
|
8
|
+
* more use cases.
|
|
9
|
+
*/
|
|
10
|
+
export type Path = (DescField | DescExtension | DescOneof | {
|
|
11
|
+
kind: "list_sub";
|
|
12
|
+
index: number;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "map_sub";
|
|
15
|
+
key: string | number | bigint | boolean;
|
|
16
|
+
})[];
|
|
17
|
+
/**
|
|
18
|
+
* Builds a Path.
|
|
19
|
+
*/
|
|
20
|
+
export type PathBuilder = {
|
|
21
|
+
/**
|
|
22
|
+
* The root message of the path.
|
|
23
|
+
*/
|
|
24
|
+
readonly schema: DescMessage;
|
|
25
|
+
/**
|
|
26
|
+
* Add field access.
|
|
27
|
+
*
|
|
28
|
+
* Throws an InvalidPathError if the field cannot be added to the path.
|
|
29
|
+
*/
|
|
30
|
+
field(field: DescField): PathBuilder;
|
|
31
|
+
/**
|
|
32
|
+
* Access a oneof.
|
|
33
|
+
*
|
|
34
|
+
* Throws an InvalidPathError if the oneof cannot be added to the path.
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
oneof(oneof: DescOneof): PathBuilder;
|
|
38
|
+
/**
|
|
39
|
+
* Access an extension.
|
|
40
|
+
*
|
|
41
|
+
* Throws an InvalidPathError if the extension cannot be added to the path.
|
|
42
|
+
*/
|
|
43
|
+
extension(extension: DescExtension): PathBuilder;
|
|
44
|
+
/**
|
|
45
|
+
* Access a list field by index.
|
|
46
|
+
*
|
|
47
|
+
* Throws an InvalidPathError if the list access cannot be added to the path.
|
|
48
|
+
*/
|
|
49
|
+
list(index: number): PathBuilder;
|
|
50
|
+
/**
|
|
51
|
+
* Access a map field by key.
|
|
52
|
+
*
|
|
53
|
+
* Throws an InvalidPathError if the map access cannot be added to the path.
|
|
54
|
+
*/
|
|
55
|
+
map(key: string | number | bigint | boolean): PathBuilder;
|
|
56
|
+
/**
|
|
57
|
+
* Append a path.
|
|
58
|
+
*
|
|
59
|
+
* Throws an InvalidPathError if the path cannot be added.
|
|
60
|
+
*/
|
|
61
|
+
add(path: Path | PathBuilder): PathBuilder;
|
|
62
|
+
/**
|
|
63
|
+
* Return the path.
|
|
64
|
+
*/
|
|
65
|
+
toPath(): Path;
|
|
66
|
+
/**
|
|
67
|
+
* Create a copy of this builder.
|
|
68
|
+
*/
|
|
69
|
+
clone(): PathBuilder;
|
|
70
|
+
/**
|
|
71
|
+
* Get the current container - a list, map, or message.
|
|
72
|
+
*/
|
|
73
|
+
getLeft(): DescMessage | (DescField & {
|
|
74
|
+
fieldKind: "list";
|
|
75
|
+
}) | (DescField & {
|
|
76
|
+
fieldKind: "map";
|
|
77
|
+
}) | undefined;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Create a PathBuilder.
|
|
81
|
+
*/
|
|
82
|
+
export declare function buildPath(schema: DescMessage): PathBuilder;
|
|
83
|
+
/**
|
|
84
|
+
* Parse a Path from a string.
|
|
85
|
+
*
|
|
86
|
+
* Throws an InvalidPathError if the path is invalid.
|
|
87
|
+
*
|
|
88
|
+
* Note that a Registry must be provided via the options argument to parse
|
|
89
|
+
* paths that refer to an extension.
|
|
90
|
+
*/
|
|
91
|
+
export declare function parsePath(schema: DescMessage, path: string, options?: {
|
|
92
|
+
registry?: Registry;
|
|
93
|
+
}): Path;
|
|
94
|
+
/**
|
|
95
|
+
* Stringify a path.
|
|
96
|
+
*/
|
|
97
|
+
export declare function pathToString(path: Path): string;
|
|
98
|
+
/**
|
|
99
|
+
* InvalidPathError is thrown for invalid Paths, for example during parsing from
|
|
100
|
+
* a string, or when a new Path is built.
|
|
101
|
+
*/
|
|
102
|
+
export declare class InvalidPathError extends Error {
|
|
103
|
+
name: string;
|
|
104
|
+
readonly schema: DescMessage;
|
|
105
|
+
readonly path: Path | string;
|
|
106
|
+
constructor(schema: DescMessage, message: string, path: string | Path);
|
|
107
|
+
}
|