@bufbuild/protobuf 1.7.2 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/codegen-info.d.ts +6 -1
- package/dist/cjs/codegen-info.js +4 -3
- package/dist/cjs/create-descriptor-set.js +45 -33
- package/dist/cjs/create-registry-from-desc.js +60 -110
- package/dist/cjs/descriptor-set.d.ts +13 -9
- package/dist/cjs/field.d.ts +25 -51
- package/dist/cjs/field.js +0 -66
- package/dist/cjs/google/protobuf/compiler/plugin_pb.d.ts +18 -0
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +2 -0
- package/dist/cjs/google/protobuf/descriptor_pb.d.ts +33 -33
- package/dist/cjs/google/protobuf/descriptor_pb.js +23 -10
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/google/protobuf/wrappers_pb.js +19 -19
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +6 -4
- package/dist/cjs/is-message.d.ts +22 -0
- package/dist/cjs/is-message.js +52 -0
- package/dist/cjs/json-format.d.ts +1 -2
- package/dist/cjs/private/binary-format.d.ts +7 -0
- package/dist/cjs/private/{binary-format-common.js → binary-format.js} +150 -53
- package/dist/cjs/private/extensions.js +1 -1
- package/dist/cjs/private/feature-set.js +1 -1
- package/dist/cjs/private/field-normalize.d.ts +9 -0
- package/dist/cjs/private/field-normalize.js +69 -0
- package/dist/cjs/private/field-wrapper.d.ts +1 -1
- package/dist/cjs/private/field-wrapper.js +12 -12
- package/dist/cjs/private/field.d.ts +1 -0
- package/dist/cjs/private/field.js +1 -0
- package/dist/cjs/private/json-format.d.ts +2 -0
- package/dist/cjs/private/{json-format-common.js → json-format.js} +261 -170
- package/dist/cjs/private/proto-runtime.d.ts +1 -1
- package/dist/cjs/private/proto-runtime.js +8 -4
- package/dist/cjs/private/reflect.d.ts +9 -0
- package/dist/cjs/private/reflect.js +79 -0
- package/dist/cjs/private/reify-wkt.js +11 -11
- package/dist/cjs/private/scalars.d.ts +9 -18
- package/dist/cjs/private/scalars.js +36 -80
- package/dist/cjs/private/text-format.d.ts +1 -1
- package/dist/cjs/private/text-format.js +17 -17
- package/dist/cjs/private/util-common.js +17 -14
- package/dist/cjs/proto-delimited.js +2 -3
- package/dist/cjs/proto2.js +29 -68
- package/dist/cjs/proto3.js +30 -77
- package/dist/cjs/scalar.d.ts +53 -0
- package/dist/cjs/scalar.js +81 -0
- package/dist/cjs/to-plain-message.js +3 -4
- package/dist/esm/codegen-info.d.ts +6 -1
- package/dist/esm/codegen-info.js +6 -5
- package/dist/esm/create-descriptor-set.js +22 -10
- package/dist/esm/create-registry-from-desc.js +62 -111
- package/dist/esm/descriptor-set.d.ts +13 -9
- package/dist/esm/descriptor-set.js +1 -1
- package/dist/esm/field.d.ts +25 -51
- package/dist/esm/field.js +1 -65
- package/dist/esm/google/protobuf/compiler/plugin_pb.d.ts +18 -0
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +2 -0
- package/dist/esm/google/protobuf/descriptor_pb.d.ts +33 -33
- package/dist/esm/google/protobuf/descriptor_pb.js +23 -10
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/google/protobuf/wrappers_pb.js +1 -1
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/is-message.d.ts +22 -0
- package/dist/esm/is-message.js +48 -0
- package/dist/esm/json-format.d.ts +1 -2
- package/dist/esm/json-format.js +1 -1
- package/dist/esm/private/binary-format.d.ts +7 -0
- package/dist/esm/private/{binary-format-common.js → binary-format.js} +126 -25
- package/dist/esm/private/extensions.js +2 -2
- package/dist/esm/private/feature-set.js +1 -1
- package/dist/esm/private/field-normalize.d.ts +9 -0
- package/dist/esm/private/field-normalize.js +65 -0
- package/dist/esm/private/field-wrapper.d.ts +1 -1
- package/dist/esm/private/field-wrapper.js +3 -2
- package/dist/esm/private/field.d.ts +1 -0
- package/dist/esm/private/field.js +1 -0
- package/dist/esm/private/json-format.d.ts +2 -0
- package/dist/esm/private/{json-format-common.js → json-format.js} +227 -135
- package/dist/esm/private/proto-runtime.d.ts +1 -1
- package/dist/esm/private/proto-runtime.js +8 -4
- package/dist/esm/private/reflect.d.ts +9 -0
- package/dist/esm/private/reflect.js +74 -0
- package/dist/esm/private/reify-wkt.js +1 -1
- package/dist/esm/private/scalars.d.ts +9 -18
- package/dist/esm/private/scalars.js +15 -59
- package/dist/esm/private/text-format.d.ts +1 -1
- package/dist/esm/private/text-format.js +1 -1
- package/dist/esm/private/util-common.js +10 -6
- package/dist/esm/proto-delimited.js +2 -3
- package/dist/esm/proto2.js +29 -68
- package/dist/esm/proto3.js +31 -78
- package/dist/esm/scalar.d.ts +53 -0
- package/dist/esm/scalar.js +78 -0
- package/dist/esm/to-plain-message.js +3 -2
- package/package.json +2 -8
- package/dist/cjs/private/binary-format-common.d.ts +0 -13
- package/dist/cjs/private/binary-format-proto2.d.ts +0 -2
- package/dist/cjs/private/binary-format-proto2.js +0 -91
- package/dist/cjs/private/binary-format-proto3.d.ts +0 -2
- package/dist/cjs/private/binary-format-proto3.js +0 -83
- package/dist/cjs/private/json-format-common.d.ts +0 -9
- package/dist/cjs/private/json-format-proto2.d.ts +0 -2
- package/dist/cjs/private/json-format-proto2.js +0 -103
- package/dist/cjs/private/json-format-proto3.d.ts +0 -2
- package/dist/cjs/private/json-format-proto3.js +0 -94
- package/dist/esm/private/binary-format-common.d.ts +0 -13
- package/dist/esm/private/binary-format-proto2.d.ts +0 -2
- package/dist/esm/private/binary-format-proto2.js +0 -87
- package/dist/esm/private/binary-format-proto3.d.ts +0 -2
- package/dist/esm/private/binary-format-proto3.js +0 -79
- package/dist/esm/private/json-format-common.d.ts +0 -9
- package/dist/esm/private/json-format-proto2.d.ts +0 -2
- package/dist/esm/private/json-format-proto2.js +0 -99
- package/dist/esm/private/json-format-proto3.d.ts +0 -2
- package/dist/esm/private/json-format-proto3.js +0 -90
- package/dist/proxy/index.d.ts +0 -1
- package/dist/proxy/index.js +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { reifyWkt } from "./private/reify-wkt.js";
|
|
2
2
|
import type { DescEnum, DescEnumValue, DescField, DescExtension, DescMessage, DescMethod, DescOneof, DescService } from "./descriptor-set.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { ScalarValue } from "./scalar.js";
|
|
4
|
+
import { LongType, ScalarType } from "./scalar.js";
|
|
4
5
|
interface CodegenInfo {
|
|
5
6
|
/**
|
|
6
7
|
* Name of the runtime library NPM package.
|
|
@@ -10,7 +11,11 @@ interface CodegenInfo {
|
|
|
10
11
|
readonly symbols: Record<RuntimeSymbolName, RuntimeSymbolInfo>;
|
|
11
12
|
readonly getUnwrappedFieldType: (field: DescField | DescExtension) => ScalarType | undefined;
|
|
12
13
|
readonly wktSourceFiles: readonly string[];
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated please use scalarZeroValue instead
|
|
16
|
+
*/
|
|
13
17
|
readonly scalarDefaultValue: (type: ScalarType, longType: LongType) => any;
|
|
18
|
+
readonly scalarZeroValue: <T extends ScalarType, L extends LongType>(type: T, longType: L) => ScalarValue<T, L>;
|
|
14
19
|
/**
|
|
15
20
|
* @deprecated please use reifyWkt from @bufbuild/protoplugin/ecmascript instead
|
|
16
21
|
*/
|
package/dist/cjs/codegen-info.js
CHANGED
|
@@ -24,7 +24,8 @@ exports.codegenInfo = {
|
|
|
24
24
|
localName: names_js_1.localName,
|
|
25
25
|
reifyWkt: reify_wkt_js_1.reifyWkt,
|
|
26
26
|
getUnwrappedFieldType: field_wrapper_js_1.getUnwrappedFieldType,
|
|
27
|
-
scalarDefaultValue: scalars_js_1.
|
|
27
|
+
scalarDefaultValue: scalars_js_1.scalarZeroValue,
|
|
28
|
+
scalarZeroValue: scalars_js_1.scalarZeroValue,
|
|
28
29
|
safeIdentifier: names_js_1.safeIdentifier,
|
|
29
30
|
safeObjectProperty: names_js_1.safeObjectProperty,
|
|
30
31
|
// prettier-ignore
|
|
@@ -45,8 +46,8 @@ exports.codegenInfo = {
|
|
|
45
46
|
JsonObject: { typeOnly: true, privateImportPath: "./json-format.js", publicImportPath: packageName },
|
|
46
47
|
protoDouble: { typeOnly: false, privateImportPath: "./proto-double.js", publicImportPath: packageName },
|
|
47
48
|
protoInt64: { typeOnly: false, privateImportPath: "./proto-int64.js", publicImportPath: packageName },
|
|
48
|
-
ScalarType: { typeOnly: false, privateImportPath: "./
|
|
49
|
-
LongType: { typeOnly: false, privateImportPath: "./
|
|
49
|
+
ScalarType: { typeOnly: false, privateImportPath: "./scalar.js", publicImportPath: packageName },
|
|
50
|
+
LongType: { typeOnly: false, privateImportPath: "./scalar.js", publicImportPath: packageName },
|
|
50
51
|
MethodKind: { typeOnly: false, privateImportPath: "./service-type.js", publicImportPath: packageName },
|
|
51
52
|
MethodIdempotency: { typeOnly: false, privateImportPath: "./service-type.js", publicImportPath: packageName },
|
|
52
53
|
IMessageTypeRegistry: { typeOnly: true, privateImportPath: "./type-registry.js", publicImportPath: packageName },
|
|
@@ -16,11 +16,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
exports.createDescriptorSet = void 0;
|
|
17
17
|
const descriptor_pb_js_1 = require("./google/protobuf/descriptor_pb.js");
|
|
18
18
|
const assert_js_1 = require("./private/assert.js");
|
|
19
|
-
const field_js_1 = require("./field.js");
|
|
20
19
|
const service_type_js_1 = require("./service-type.js");
|
|
21
20
|
const names_js_1 = require("./private/names.js");
|
|
22
21
|
const text_format_js_1 = require("./private/text-format.js");
|
|
23
22
|
const feature_set_js_1 = require("./private/feature-set.js");
|
|
23
|
+
const scalar_js_1 = require("./scalar.js");
|
|
24
|
+
const is_message_js_1 = require("./is-message.js");
|
|
24
25
|
/**
|
|
25
26
|
* Create a DescriptorSet, a convenient interface for working with a set of
|
|
26
27
|
* google.protobuf.FileDescriptorProto.
|
|
@@ -30,39 +31,40 @@ const feature_set_js_1 = require("./private/feature-set.js");
|
|
|
30
31
|
* files in topological order.
|
|
31
32
|
*/
|
|
32
33
|
function createDescriptorSet(input, options) {
|
|
34
|
+
var _a;
|
|
33
35
|
const cart = {
|
|
36
|
+
files: [],
|
|
34
37
|
enums: new Map(),
|
|
35
38
|
messages: new Map(),
|
|
36
39
|
services: new Map(),
|
|
37
40
|
extensions: new Map(),
|
|
38
41
|
mapEntries: new Map(),
|
|
39
42
|
};
|
|
40
|
-
const fileDescriptors = input
|
|
43
|
+
const fileDescriptors = (0, is_message_js_1.isMessage)(input, descriptor_pb_js_1.FileDescriptorSet)
|
|
41
44
|
? input.file
|
|
42
45
|
: input instanceof Uint8Array
|
|
43
46
|
? descriptor_pb_js_1.FileDescriptorSet.fromBinary(input).file
|
|
44
47
|
: input;
|
|
45
48
|
const resolverByEdition = new Map();
|
|
46
|
-
const
|
|
47
|
-
var _a;
|
|
49
|
+
for (const proto of fileDescriptors) {
|
|
48
50
|
const edition = (_a = proto.edition) !== null && _a !== void 0 ? _a : parseFileSyntax(proto.syntax, proto.edition).edition;
|
|
49
51
|
let resolveFeatures = resolverByEdition.get(edition);
|
|
50
52
|
if (resolveFeatures === undefined) {
|
|
51
53
|
resolveFeatures = (0, feature_set_js_1.createFeatureResolver)(edition, options === null || options === void 0 ? void 0 : options.featureSetDefaults, options === null || options === void 0 ? void 0 : options.serializationOptions);
|
|
52
54
|
resolverByEdition.set(edition, resolveFeatures);
|
|
53
55
|
}
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
return
|
|
56
|
+
addFile(proto, cart, resolveFeatures);
|
|
57
|
+
}
|
|
58
|
+
return cart;
|
|
57
59
|
}
|
|
58
60
|
exports.createDescriptorSet = createDescriptorSet;
|
|
59
61
|
/**
|
|
60
62
|
* Create a descriptor for a file.
|
|
61
63
|
*/
|
|
62
|
-
function
|
|
64
|
+
function addFile(proto, cart, resolveFeatures) {
|
|
63
65
|
var _a, _b;
|
|
64
66
|
(0, assert_js_1.assert)(proto.name, `invalid FileDescriptorProto: missing name`);
|
|
65
|
-
const file = Object.assign(Object.assign({ kind: "file", proto, deprecated: (_b = (_a = proto.options) === null || _a === void 0 ? void 0 : _a.deprecated) !== null && _b !== void 0 ? _b : false }, parseFileSyntax(proto.syntax, proto.edition)), { name: proto.name.replace(/\.proto/, ""), enums: [], messages: [], extensions: [], services: [], toString() {
|
|
67
|
+
const file = Object.assign(Object.assign({ kind: "file", proto, deprecated: (_b = (_a = proto.options) === null || _a === void 0 ? void 0 : _a.deprecated) !== null && _b !== void 0 ? _b : false }, parseFileSyntax(proto.syntax, proto.edition)), { name: proto.name.replace(/\.proto/, ""), dependencies: findFileDependencies(proto, cart), enums: [], messages: [], extensions: [], services: [], toString() {
|
|
66
68
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
|
|
67
69
|
return `file ${this.proto.name}`;
|
|
68
70
|
},
|
|
@@ -99,7 +101,7 @@ function newFile(proto, cart, resolveFeatures) {
|
|
|
99
101
|
addExtensions(message, cart, resolveFeatures);
|
|
100
102
|
}
|
|
101
103
|
cart.mapEntries.clear(); // map entries are local to the file, we can safely discard
|
|
102
|
-
|
|
104
|
+
cart.files.push(file);
|
|
103
105
|
}
|
|
104
106
|
/**
|
|
105
107
|
* Create descriptors for extensions, and add them to the message / file,
|
|
@@ -491,8 +493,8 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
|
|
|
491
493
|
return Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "scalar", getDefaultValue,
|
|
492
494
|
repeated,
|
|
493
495
|
scalar, longType: ((_c = proto.options) === null || _c === void 0 ? void 0 : _c.jstype) == descriptor_pb_js_1.FieldOptions_JSType.JS_STRING
|
|
494
|
-
?
|
|
495
|
-
:
|
|
496
|
+
? scalar_js_1.LongType.STRING
|
|
497
|
+
: scalar_js_1.LongType.BIGINT });
|
|
496
498
|
}
|
|
497
499
|
}
|
|
498
500
|
}
|
|
@@ -575,6 +577,16 @@ function parseFileSyntax(syntax, edition) {
|
|
|
575
577
|
edition: e,
|
|
576
578
|
};
|
|
577
579
|
}
|
|
580
|
+
/**
|
|
581
|
+
* Resolve dependencies of FileDescriptorProto to DescFile.
|
|
582
|
+
*/
|
|
583
|
+
function findFileDependencies(proto, cart) {
|
|
584
|
+
return proto.dependency.map((wantName) => {
|
|
585
|
+
const dep = cart.files.find((f) => f.proto.name === wantName);
|
|
586
|
+
(0, assert_js_1.assert)(dep);
|
|
587
|
+
return dep;
|
|
588
|
+
});
|
|
589
|
+
}
|
|
578
590
|
/**
|
|
579
591
|
* Create a fully qualified name for a protobuf type or extension field.
|
|
580
592
|
*
|
|
@@ -619,9 +631,9 @@ function getMapFieldTypes(mapEntry) {
|
|
|
619
631
|
(0, assert_js_1.assert)(keyField, `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing key field`);
|
|
620
632
|
const mapKey = keyField.scalar;
|
|
621
633
|
(0, assert_js_1.assert)(mapKey !== undefined &&
|
|
622
|
-
mapKey !==
|
|
623
|
-
mapKey !==
|
|
624
|
-
mapKey !==
|
|
634
|
+
mapKey !== scalar_js_1.ScalarType.BYTES &&
|
|
635
|
+
mapKey !== scalar_js_1.ScalarType.FLOAT &&
|
|
636
|
+
mapKey !== scalar_js_1.ScalarType.DOUBLE, `invalid DescriptorProto: map entry ${mapEntry.toString()} has unexpected key type ${(_b = keyField.proto.type) !== null && _b !== void 0 ? _b : -1}`);
|
|
625
637
|
const valueField = mapEntry.fields.find((f) => f.proto.number === 2);
|
|
626
638
|
(0, assert_js_1.assert)(valueField, `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing value field`);
|
|
627
639
|
switch (valueField.fieldKind) {
|
|
@@ -737,24 +749,24 @@ function isPackedField(file, parent, proto, resolveFeatures) {
|
|
|
737
749
|
* subset of field types declared by protobuf enum google.protobuf.FieldDescriptorProto.
|
|
738
750
|
*/
|
|
739
751
|
const fieldTypeToScalarType = {
|
|
740
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.DOUBLE]:
|
|
741
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.FLOAT]:
|
|
742
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.INT64]:
|
|
743
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.UINT64]:
|
|
744
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.INT32]:
|
|
745
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED64]:
|
|
746
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED32]:
|
|
747
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.BOOL]:
|
|
748
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.STRING]:
|
|
752
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.DOUBLE]: scalar_js_1.ScalarType.DOUBLE,
|
|
753
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.FLOAT]: scalar_js_1.ScalarType.FLOAT,
|
|
754
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.INT64]: scalar_js_1.ScalarType.INT64,
|
|
755
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.UINT64]: scalar_js_1.ScalarType.UINT64,
|
|
756
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.INT32]: scalar_js_1.ScalarType.INT32,
|
|
757
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED64]: scalar_js_1.ScalarType.FIXED64,
|
|
758
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED32]: scalar_js_1.ScalarType.FIXED32,
|
|
759
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.BOOL]: scalar_js_1.ScalarType.BOOL,
|
|
760
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.STRING]: scalar_js_1.ScalarType.STRING,
|
|
749
761
|
[descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP]: undefined,
|
|
750
762
|
[descriptor_pb_js_1.FieldDescriptorProto_Type.MESSAGE]: undefined,
|
|
751
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.BYTES]:
|
|
752
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.UINT32]:
|
|
763
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.BYTES]: scalar_js_1.ScalarType.BYTES,
|
|
764
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.UINT32]: scalar_js_1.ScalarType.UINT32,
|
|
753
765
|
[descriptor_pb_js_1.FieldDescriptorProto_Type.ENUM]: undefined,
|
|
754
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED32]:
|
|
755
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED64]:
|
|
756
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.SINT32]:
|
|
757
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.SINT64]:
|
|
766
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED32]: scalar_js_1.ScalarType.SFIXED32,
|
|
767
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED64]: scalar_js_1.ScalarType.SFIXED64,
|
|
768
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.SINT32]: scalar_js_1.ScalarType.SINT32,
|
|
769
|
+
[descriptor_pb_js_1.FieldDescriptorProto_Type.SINT64]: scalar_js_1.ScalarType.SINT64,
|
|
758
770
|
};
|
|
759
771
|
/**
|
|
760
772
|
* Find comments.
|
|
@@ -826,7 +838,7 @@ function declarationString() {
|
|
|
826
838
|
let type;
|
|
827
839
|
switch (this.fieldKind) {
|
|
828
840
|
case "scalar":
|
|
829
|
-
type =
|
|
841
|
+
type = scalar_js_1.ScalarType[this.scalar].toLowerCase();
|
|
830
842
|
break;
|
|
831
843
|
case "enum":
|
|
832
844
|
type = this.enum.typeName;
|
|
@@ -835,11 +847,11 @@ function declarationString() {
|
|
|
835
847
|
type = this.message.typeName;
|
|
836
848
|
break;
|
|
837
849
|
case "map": {
|
|
838
|
-
const k =
|
|
850
|
+
const k = scalar_js_1.ScalarType[this.mapKey].toLowerCase();
|
|
839
851
|
let v;
|
|
840
852
|
switch (this.mapValue.kind) {
|
|
841
853
|
case "scalar":
|
|
842
|
-
v =
|
|
854
|
+
v = scalar_js_1.ScalarType[this.mapValue.scalar].toLowerCase();
|
|
843
855
|
break;
|
|
844
856
|
case "enum":
|
|
845
857
|
v = this.mapValue.enum.typeName;
|
|
@@ -17,7 +17,6 @@ exports.createRegistryFromDescriptors = void 0;
|
|
|
17
17
|
const assert_js_1 = require("./private/assert.js");
|
|
18
18
|
const proto3_js_1 = require("./proto3.js");
|
|
19
19
|
const proto2_js_1 = require("./proto2.js");
|
|
20
|
-
const field_js_1 = require("./field.js");
|
|
21
20
|
const names_js_1 = require("./private/names.js");
|
|
22
21
|
const timestamp_pb_js_1 = require("./google/protobuf/timestamp_pb.js");
|
|
23
22
|
const duration_pb_js_1 = require("./google/protobuf/duration_pb.js");
|
|
@@ -29,6 +28,7 @@ const enum_js_1 = require("./private/enum.js");
|
|
|
29
28
|
const wrappers_pb_js_1 = require("./google/protobuf/wrappers_pb.js");
|
|
30
29
|
const descriptor_pb_js_1 = require("./google/protobuf/descriptor_pb.js");
|
|
31
30
|
const create_descriptor_set_js_1 = require("./create-descriptor-set.js");
|
|
31
|
+
const is_message_js_1 = require("./is-message.js");
|
|
32
32
|
// well-known message types with specialized JSON representation
|
|
33
33
|
const wkMessages = [
|
|
34
34
|
any_pb_js_1.Any,
|
|
@@ -64,7 +64,7 @@ const wkEnums = [(0, enum_js_1.getEnumType)(struct_pb_js_1.NullValue)];
|
|
|
64
64
|
* are replaced with their generated counterpart in this package.
|
|
65
65
|
*/
|
|
66
66
|
function createRegistryFromDescriptors(input, replaceWkt = true) {
|
|
67
|
-
const set = input instanceof Uint8Array || input
|
|
67
|
+
const set = input instanceof Uint8Array || (0, is_message_js_1.isMessage)(input, descriptor_pb_js_1.FileDescriptorSet)
|
|
68
68
|
? (0, create_descriptor_set_js_1.createDescriptorSet)(input)
|
|
69
69
|
: input;
|
|
70
70
|
const enums = new Map();
|
|
@@ -121,8 +121,7 @@ function createRegistryFromDescriptors(input, replaceWkt = true) {
|
|
|
121
121
|
});
|
|
122
122
|
messages.set(typeName, type);
|
|
123
123
|
for (const field of desc.fields) {
|
|
124
|
-
|
|
125
|
-
fields.push(fieldInfo);
|
|
124
|
+
fields.push(makeFieldInfo(field, this));
|
|
126
125
|
}
|
|
127
126
|
return type;
|
|
128
127
|
},
|
|
@@ -140,10 +139,8 @@ function createRegistryFromDescriptors(input, replaceWkt = true) {
|
|
|
140
139
|
}
|
|
141
140
|
const methods = {};
|
|
142
141
|
for (const method of desc.methods) {
|
|
143
|
-
const I =
|
|
144
|
-
const O =
|
|
145
|
-
(0, assert_js_1.assert)(I, `message "${method.input.typeName}" for ${method.toString()} not found`);
|
|
146
|
-
(0, assert_js_1.assert)(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);
|
|
142
|
+
const I = resolve(method.input, this, method);
|
|
143
|
+
const O = resolve(method.output, this, method);
|
|
147
144
|
methods[(0, names_js_1.localName)(method)] = {
|
|
148
145
|
name: method.name,
|
|
149
146
|
I,
|
|
@@ -193,8 +190,7 @@ function createRegistryFromDescriptors(input, replaceWkt = true) {
|
|
|
193
190
|
if (!desc) {
|
|
194
191
|
return undefined;
|
|
195
192
|
}
|
|
196
|
-
const extendee =
|
|
197
|
-
(0, assert_js_1.assert)(extendee, `message "${desc.extendee.typeName}" for ${desc.toString()} not found`);
|
|
193
|
+
const extendee = resolve(desc.extendee, this, desc);
|
|
198
194
|
const runtime = desc.file.syntax == "proto3" ? proto3_js_1.proto3 : proto2_js_1.proto2;
|
|
199
195
|
const ext = runtime.makeExtension(typeName, extendee, makeFieldInfo(desc, this));
|
|
200
196
|
extensions.set(typeName, ext);
|
|
@@ -203,112 +199,66 @@ function createRegistryFromDescriptors(input, replaceWkt = true) {
|
|
|
203
199
|
};
|
|
204
200
|
}
|
|
205
201
|
exports.createRegistryFromDescriptors = createRegistryFromDescriptors;
|
|
206
|
-
function makeFieldInfo(desc,
|
|
202
|
+
function makeFieldInfo(desc, registry) {
|
|
203
|
+
var _a;
|
|
204
|
+
const f = {
|
|
205
|
+
kind: desc.fieldKind,
|
|
206
|
+
no: desc.number,
|
|
207
|
+
name: desc.name,
|
|
208
|
+
jsonName: desc.jsonName,
|
|
209
|
+
delimited: desc.proto.type == descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP,
|
|
210
|
+
repeated: desc.repeated,
|
|
211
|
+
packed: desc.packed,
|
|
212
|
+
oneof: (_a = desc.oneof) === null || _a === void 0 ? void 0 : _a.name,
|
|
213
|
+
opt: desc.optional,
|
|
214
|
+
req: desc.proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.REQUIRED,
|
|
215
|
+
};
|
|
207
216
|
switch (desc.fieldKind) {
|
|
208
|
-
case "map":
|
|
217
|
+
case "map": {
|
|
209
218
|
(0, assert_js_1.assert)(desc.kind == "field"); // maps are not allowed for extensions
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
219
|
+
let T;
|
|
220
|
+
switch (desc.mapValue.kind) {
|
|
221
|
+
case "scalar":
|
|
222
|
+
T = desc.mapValue.scalar;
|
|
223
|
+
break;
|
|
224
|
+
case "enum": {
|
|
225
|
+
T = resolve(desc.mapValue.enum, registry, desc);
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
case "message": {
|
|
229
|
+
T = resolve(desc.mapValue.message, registry, desc);
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
f.K = desc.mapKey;
|
|
234
|
+
f.V = {
|
|
235
|
+
kind: desc.mapValue.kind,
|
|
236
|
+
T,
|
|
237
|
+
};
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case "message": {
|
|
241
|
+
f.T = resolve(desc.message, registry, desc);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
213
244
|
case "enum": {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
245
|
+
f.T = resolve(desc.enum, registry, desc);
|
|
246
|
+
f.default = desc.getDefaultValue();
|
|
247
|
+
break;
|
|
217
248
|
}
|
|
218
249
|
case "scalar": {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
250
|
+
f.L = desc.longType;
|
|
251
|
+
f.T = desc.scalar;
|
|
252
|
+
f.default = desc.getDefaultValue();
|
|
253
|
+
break;
|
|
222
254
|
}
|
|
223
255
|
}
|
|
256
|
+
return f;
|
|
224
257
|
}
|
|
225
|
-
function
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
K: field.mapKey,
|
|
232
|
-
};
|
|
233
|
-
if (field.mapValue.message) {
|
|
234
|
-
const messageType = resolver.findMessage(field.mapValue.message.typeName);
|
|
235
|
-
(0, assert_js_1.assert)(messageType, `message "${field.mapValue.message.typeName}" for ${field.toString()} not found`);
|
|
236
|
-
return Object.assign(Object.assign({}, base), { V: {
|
|
237
|
-
kind: "message",
|
|
238
|
-
T: messageType,
|
|
239
|
-
} });
|
|
240
|
-
}
|
|
241
|
-
if (field.mapValue.enum) {
|
|
242
|
-
const enumType = resolver.findEnum(field.mapValue.enum.typeName);
|
|
243
|
-
(0, assert_js_1.assert)(enumType, `enum "${field.mapValue.enum.typeName}" for ${field.toString()} not found`);
|
|
244
|
-
return Object.assign(Object.assign({}, base), { V: {
|
|
245
|
-
kind: "enum",
|
|
246
|
-
T: enumType,
|
|
247
|
-
} });
|
|
248
|
-
}
|
|
249
|
-
return Object.assign(Object.assign({}, base), { V: {
|
|
250
|
-
kind: "scalar",
|
|
251
|
-
T: field.mapValue.scalar,
|
|
252
|
-
} });
|
|
253
|
-
}
|
|
254
|
-
function makeScalarFieldInfo(field) {
|
|
255
|
-
// We are creating _partial_ field info here, so we omit long type bigint,
|
|
256
|
-
// which is the default.
|
|
257
|
-
const longType = field.longType == field_js_1.LongType.STRING
|
|
258
|
-
? { L: field_js_1.LongType.STRING }
|
|
259
|
-
: {};
|
|
260
|
-
const base = Object.assign({ kind: "scalar", no: field.number, name: field.name, jsonName: field.jsonName, T: field.scalar }, longType);
|
|
261
|
-
if (field.repeated) {
|
|
262
|
-
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined, T: field.scalar });
|
|
263
|
-
}
|
|
264
|
-
if (field.oneof) {
|
|
265
|
-
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
266
|
-
}
|
|
267
|
-
if (field.optional) {
|
|
268
|
-
return Object.assign(Object.assign({}, base), { opt: true });
|
|
269
|
-
}
|
|
270
|
-
return base;
|
|
271
|
-
}
|
|
272
|
-
function makeMessageFieldInfo(field, resolver) {
|
|
273
|
-
const messageType = resolver.findMessage(field.message.typeName);
|
|
274
|
-
(0, assert_js_1.assert)(messageType, `message "${field.message.typeName}" for ${field.toString()} not found`);
|
|
275
|
-
const base = {
|
|
276
|
-
kind: "message",
|
|
277
|
-
no: field.number,
|
|
278
|
-
name: field.name,
|
|
279
|
-
jsonName: field.jsonName,
|
|
280
|
-
T: messageType,
|
|
281
|
-
delimited: field.proto.type == descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP,
|
|
282
|
-
};
|
|
283
|
-
if (field.repeated) {
|
|
284
|
-
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
|
285
|
-
}
|
|
286
|
-
if (field.oneof) {
|
|
287
|
-
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
288
|
-
}
|
|
289
|
-
if (field.optional) {
|
|
290
|
-
return Object.assign(Object.assign({}, base), { opt: true });
|
|
291
|
-
}
|
|
292
|
-
return base;
|
|
293
|
-
}
|
|
294
|
-
function makeEnumFieldInfo(field, resolver) {
|
|
295
|
-
const enumType = resolver.findEnum(field.enum.typeName);
|
|
296
|
-
(0, assert_js_1.assert)(enumType, `enum "${field.enum.typeName}" for ${field.toString()} not found`);
|
|
297
|
-
const base = {
|
|
298
|
-
kind: "enum",
|
|
299
|
-
no: field.number,
|
|
300
|
-
name: field.name,
|
|
301
|
-
jsonName: field.jsonName,
|
|
302
|
-
T: enumType,
|
|
303
|
-
};
|
|
304
|
-
if (field.repeated) {
|
|
305
|
-
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
|
306
|
-
}
|
|
307
|
-
if (field.oneof) {
|
|
308
|
-
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
309
|
-
}
|
|
310
|
-
if (field.optional) {
|
|
311
|
-
return Object.assign(Object.assign({}, base), { opt: true });
|
|
312
|
-
}
|
|
313
|
-
return base;
|
|
258
|
+
function resolve(desc, registry, context) {
|
|
259
|
+
const type = desc.kind == "message"
|
|
260
|
+
? registry.findMessage(desc.typeName)
|
|
261
|
+
: registry.findEnum(desc.typeName);
|
|
262
|
+
(0, assert_js_1.assert)(type, `${desc.toString()}" for ${context.toString()} not found`);
|
|
263
|
+
return type;
|
|
314
264
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DescriptorProto, Edition, EnumDescriptorProto, EnumValueDescriptorProto, FieldDescriptorProto, FileDescriptorProto, MethodDescriptorProto, OneofDescriptorProto, ServiceDescriptorProto } from "./google/protobuf/descriptor_pb.js";
|
|
2
|
-
import
|
|
2
|
+
import { LongType, ScalarType } from "./scalar.js";
|
|
3
3
|
import type { MethodIdempotency, MethodKind } from "./service-type.js";
|
|
4
4
|
import type { MergedFeatureSet } from "./private/feature-set.js";
|
|
5
5
|
/**
|
|
@@ -47,7 +47,7 @@ export type AnyDesc = DescFile | DescEnum | DescEnumValue | DescMessage | DescFi
|
|
|
47
47
|
* Describes a protobuf source file.
|
|
48
48
|
*/
|
|
49
49
|
export interface DescFile {
|
|
50
|
-
kind: "file";
|
|
50
|
+
readonly kind: "file";
|
|
51
51
|
/**
|
|
52
52
|
* The syntax specified in the protobuf source.
|
|
53
53
|
*/
|
|
@@ -62,6 +62,10 @@ export interface DescFile {
|
|
|
62
62
|
* For a protobuf file `foo/bar.proto`, this is `foo/bar`.
|
|
63
63
|
*/
|
|
64
64
|
readonly name: string;
|
|
65
|
+
/**
|
|
66
|
+
* Files imported by this file.
|
|
67
|
+
*/
|
|
68
|
+
readonly dependencies: DescFile[];
|
|
65
69
|
/**
|
|
66
70
|
* Top-level enumerations declared in this file.
|
|
67
71
|
* Note that more enumerations might be declared within message declarations.
|
|
@@ -107,7 +111,7 @@ export interface DescFile {
|
|
|
107
111
|
* Describes an enumeration in a protobuf source file.
|
|
108
112
|
*/
|
|
109
113
|
export interface DescEnum {
|
|
110
|
-
kind: "enum";
|
|
114
|
+
readonly kind: "enum";
|
|
111
115
|
/**
|
|
112
116
|
* The fully qualified name of the enumeration. (We omit the leading dot.)
|
|
113
117
|
*/
|
|
@@ -195,7 +199,7 @@ export interface DescEnumValue {
|
|
|
195
199
|
* Describes a message declaration in a protobuf source file.
|
|
196
200
|
*/
|
|
197
201
|
export interface DescMessage {
|
|
198
|
-
kind: "message";
|
|
202
|
+
readonly kind: "message";
|
|
199
203
|
/**
|
|
200
204
|
* The fully qualified name of the message. (We omit the leading dot.)
|
|
201
205
|
*/
|
|
@@ -262,7 +266,7 @@ export interface DescMessage {
|
|
|
262
266
|
* Describes a field declaration in a protobuf source file.
|
|
263
267
|
*/
|
|
264
268
|
export type DescField = DescFieldCommon & (DescFieldScalar | DescFieldMessage | DescFieldEnum | DescFieldMap) & {
|
|
265
|
-
kind: "field";
|
|
269
|
+
readonly kind: "field";
|
|
266
270
|
/**
|
|
267
271
|
* The message this field is declared on.
|
|
268
272
|
*/
|
|
@@ -272,7 +276,7 @@ export type DescField = DescFieldCommon & (DescFieldScalar | DescFieldMessage |
|
|
|
272
276
|
* Describes an extension in a protobuf source file.
|
|
273
277
|
*/
|
|
274
278
|
export type DescExtension = DescFieldCommon & (DescFieldScalar | DescFieldMessage | DescFieldEnum | DescFieldMap) & {
|
|
275
|
-
kind: "extension";
|
|
279
|
+
readonly kind: "extension";
|
|
276
280
|
/**
|
|
277
281
|
* The fully qualified name of the extension.
|
|
278
282
|
*/
|
|
@@ -537,7 +541,7 @@ interface DescFieldMapValueScalar {
|
|
|
537
541
|
* Describes a oneof group in a protobuf source file.
|
|
538
542
|
*/
|
|
539
543
|
export interface DescOneof {
|
|
540
|
-
kind: "oneof";
|
|
544
|
+
readonly kind: "oneof";
|
|
541
545
|
/**
|
|
542
546
|
* The name of the oneof group, as specified in the protobuf source.
|
|
543
547
|
*/
|
|
@@ -574,7 +578,7 @@ export interface DescOneof {
|
|
|
574
578
|
* Describes a service declaration in a protobuf source file.
|
|
575
579
|
*/
|
|
576
580
|
export interface DescService {
|
|
577
|
-
kind: "service";
|
|
581
|
+
readonly kind: "service";
|
|
578
582
|
/**
|
|
579
583
|
* The fully qualified name of the service. (We omit the leading dot.)
|
|
580
584
|
*/
|
|
@@ -613,7 +617,7 @@ export interface DescService {
|
|
|
613
617
|
* Describes an RPC declaration in a protobuf source file.
|
|
614
618
|
*/
|
|
615
619
|
export interface DescMethod {
|
|
616
|
-
kind: "rpc";
|
|
620
|
+
readonly kind: "rpc";
|
|
617
621
|
/**
|
|
618
622
|
* The name of the RPC, as specified in the protobuf source.
|
|
619
623
|
*/
|