@bufbuild/protobuf 0.1.1 → 0.2.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.
- package/dist/cjs/codegen-info.js +2 -0
- package/dist/cjs/create-descriptor-set.js +18 -18
- package/dist/cjs/create-registry-from-desc.js +5 -5
- package/dist/cjs/google/protobuf/any_pb.js +3 -0
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/private/field-wrapper.js +1 -1
- package/dist/cjs/private/names.js +1 -4
- package/dist/cjs/private/reify-wkt.js +170 -0
- package/dist/esm/codegen-info.js +2 -0
- package/dist/esm/create-descriptor-set.js +18 -18
- package/dist/esm/create-registry-from-desc.js +5 -5
- package/dist/esm/google/protobuf/any_pb.js +3 -0
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/private/field-wrapper.js +1 -1
- package/dist/esm/private/names.js +1 -4
- package/dist/esm/private/reify-wkt.js +166 -0
- package/dist/types/codegen-info.d.ts +2 -0
- package/dist/types/descriptor-set.d.ts +14 -4
- package/dist/types/index.d.ts +1 -1
- package/dist/types/private/reify-wkt.d.ts +100 -0
- package/package.json +1 -1
package/dist/cjs/codegen-info.js
CHANGED
|
@@ -17,10 +17,12 @@ exports.codegenInfo = void 0;
|
|
|
17
17
|
const names_js_1 = require("./private/names.js");
|
|
18
18
|
const field_wrapper_js_1 = require("./private/field-wrapper.js");
|
|
19
19
|
const scalars_js_1 = require("./private/scalars.js");
|
|
20
|
+
const reify_wkt_js_1 = require("./private/reify-wkt.js");
|
|
20
21
|
const packageName = "@bufbuild/protobuf";
|
|
21
22
|
exports.codegenInfo = {
|
|
22
23
|
packageName,
|
|
23
24
|
localName: names_js_1.localName,
|
|
25
|
+
reifyWkt: reify_wkt_js_1.reifyWkt,
|
|
24
26
|
getUnwrappedFieldType: field_wrapper_js_1.getUnwrappedFieldType,
|
|
25
27
|
scalarDefaultValue: scalars_js_1.scalarDefaultValue,
|
|
26
28
|
// prettier-ignore
|
|
@@ -440,24 +440,24 @@ function newField(proto, file, parent, oneof, cart) {
|
|
|
440
440
|
const mapEntry = cart.mapEntries.get(trimLeadingDot(proto.typeName));
|
|
441
441
|
if (mapEntry !== undefined) {
|
|
442
442
|
(0, assert_js_1.assert)(repeated, `invalid FieldDescriptorProto: expected map entry to be repeated`);
|
|
443
|
-
return Object.assign(Object.assign(Object.assign({}, common), { kind: "
|
|
443
|
+
return Object.assign(Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "map", repeated: false }), getMapFieldTypes(mapEntry));
|
|
444
444
|
}
|
|
445
445
|
const message = cart.messages.get(trimLeadingDot(proto.typeName));
|
|
446
446
|
(0, assert_js_1.assert)(message !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
|
|
447
|
-
return Object.assign(Object.assign({}, common), { kind: "
|
|
447
|
+
return Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "message", repeated,
|
|
448
448
|
message });
|
|
449
449
|
}
|
|
450
450
|
case descriptor_pb_js_1.FieldDescriptorProto_Type.ENUM: {
|
|
451
451
|
(0, assert_js_1.assert)(proto.typeName, `invalid FieldDescriptorProto: missing type_name`);
|
|
452
452
|
const e = cart.enums.get(trimLeadingDot(proto.typeName));
|
|
453
453
|
(0, assert_js_1.assert)(e !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
|
|
454
|
-
return Object.assign(Object.assign({}, common), { kind: "
|
|
454
|
+
return Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "enum", getDefaultValue,
|
|
455
455
|
repeated, enum: e });
|
|
456
456
|
}
|
|
457
457
|
default: {
|
|
458
458
|
const scalar = fieldTypeToScalarType[proto.type];
|
|
459
459
|
(0, assert_js_1.assert)(scalar, `invalid FieldDescriptorProto: unknown type ${proto.type}`);
|
|
460
|
-
return Object.assign(Object.assign({}, common), { kind: "
|
|
460
|
+
return Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "scalar", getDefaultValue,
|
|
461
461
|
repeated,
|
|
462
462
|
scalar });
|
|
463
463
|
}
|
|
@@ -472,7 +472,7 @@ function newExtension(proto, file, parent, cart) {
|
|
|
472
472
|
undefined, cart);
|
|
473
473
|
const extendee = cart.messages.get(trimLeadingDot(proto.extendee));
|
|
474
474
|
(0, assert_js_1.assert)(extendee, `invalid FieldDescriptorProto: extendee ${proto.extendee} not found`);
|
|
475
|
-
return Object.assign(Object.assign({}, field), { typeName: makeTypeName(proto, parent, file), parent,
|
|
475
|
+
return Object.assign(Object.assign({}, field), { kind: "extension", typeName: makeTypeName(proto, parent, file), parent,
|
|
476
476
|
file,
|
|
477
477
|
extendee,
|
|
478
478
|
toString() {
|
|
@@ -541,18 +541,18 @@ function getMapFieldTypes(mapEntry) {
|
|
|
541
541
|
mapKey !== field_js_1.ScalarType.DOUBLE, `invalid DescriptorProto: map entry ${mapEntry.toString()} has unexpected key type ${(_b = keyField.proto.type) !== null && _b !== void 0 ? _b : -1}`);
|
|
542
542
|
const valueField = mapEntry.fields.find((f) => f.proto.number === 2);
|
|
543
543
|
(0, assert_js_1.assert)(valueField, `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing value field`);
|
|
544
|
-
switch (valueField.
|
|
545
|
-
case "
|
|
544
|
+
switch (valueField.fieldKind) {
|
|
545
|
+
case "scalar":
|
|
546
546
|
return {
|
|
547
547
|
mapKey,
|
|
548
548
|
mapValue: Object.assign(Object.assign({}, valueField), { kind: "scalar" }),
|
|
549
549
|
};
|
|
550
|
-
case "
|
|
550
|
+
case "message":
|
|
551
551
|
return {
|
|
552
552
|
mapKey,
|
|
553
553
|
mapValue: Object.assign(Object.assign({}, valueField), { kind: "message" }),
|
|
554
554
|
};
|
|
555
|
-
case "
|
|
555
|
+
case "enum":
|
|
556
556
|
return {
|
|
557
557
|
mapKey,
|
|
558
558
|
mapValue: Object.assign(Object.assign({}, valueField), { kind: "enum" }),
|
|
@@ -711,23 +711,23 @@ function declarationString() {
|
|
|
711
711
|
if (this.optional) {
|
|
712
712
|
parts.push("optional");
|
|
713
713
|
}
|
|
714
|
-
const file = "
|
|
714
|
+
const file = this.kind === "extension" ? this.file : this.parent.file;
|
|
715
715
|
if (file.syntax == "proto2" &&
|
|
716
716
|
this.proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.REQUIRED) {
|
|
717
717
|
parts.push("required");
|
|
718
718
|
}
|
|
719
719
|
let type;
|
|
720
|
-
switch (this.
|
|
721
|
-
case "
|
|
720
|
+
switch (this.fieldKind) {
|
|
721
|
+
case "scalar":
|
|
722
722
|
type = field_js_1.ScalarType[this.scalar].toLowerCase();
|
|
723
723
|
break;
|
|
724
|
-
case "
|
|
724
|
+
case "enum":
|
|
725
725
|
type = this.enum.typeName;
|
|
726
726
|
break;
|
|
727
|
-
case "
|
|
727
|
+
case "message":
|
|
728
728
|
type = this.message.typeName;
|
|
729
729
|
break;
|
|
730
|
-
case "
|
|
730
|
+
case "map": {
|
|
731
731
|
const k = field_js_1.ScalarType[this.mapKey].toLowerCase();
|
|
732
732
|
let v;
|
|
733
733
|
switch (this.mapValue.kind) {
|
|
@@ -777,13 +777,13 @@ function getDefaultValue() {
|
|
|
777
777
|
if (d === undefined) {
|
|
778
778
|
return undefined;
|
|
779
779
|
}
|
|
780
|
-
switch (this.
|
|
781
|
-
case "
|
|
780
|
+
switch (this.fieldKind) {
|
|
781
|
+
case "enum": {
|
|
782
782
|
const enumValue = this.enum.values.find((v) => v.name === d);
|
|
783
783
|
(0, assert_js_1.assert)(enumValue, `cannot parse ${this.toString()} default value: ${d}`);
|
|
784
784
|
return enumValue.number;
|
|
785
785
|
}
|
|
786
|
-
case "
|
|
786
|
+
case "scalar":
|
|
787
787
|
switch (this.scalar) {
|
|
788
788
|
case field_js_1.ScalarType.STRING:
|
|
789
789
|
return d;
|
|
@@ -161,17 +161,17 @@ function createRegistryFromDescriptors(input, replaceWkt = true) {
|
|
|
161
161
|
}
|
|
162
162
|
exports.createRegistryFromDescriptors = createRegistryFromDescriptors;
|
|
163
163
|
function makeFieldInfo(desc, resolver) {
|
|
164
|
-
switch (desc.
|
|
165
|
-
case "
|
|
164
|
+
switch (desc.fieldKind) {
|
|
165
|
+
case "map":
|
|
166
166
|
return makeMapFieldInfo(desc, resolver);
|
|
167
|
-
case "
|
|
167
|
+
case "message":
|
|
168
168
|
return makeMessageFieldInfo(desc, resolver);
|
|
169
|
-
case "
|
|
169
|
+
case "enum": {
|
|
170
170
|
const fi = makeEnumFieldInfo(desc, resolver);
|
|
171
171
|
fi.default = desc.getDefaultValue();
|
|
172
172
|
return fi;
|
|
173
173
|
}
|
|
174
|
-
case "
|
|
174
|
+
case "scalar": {
|
|
175
175
|
const fi = makeScalarFieldInfo(desc);
|
|
176
176
|
fi.default = desc.getDefaultValue();
|
|
177
177
|
return fi;
|
|
@@ -170,6 +170,9 @@ class Any extends message_js_1.Message {
|
|
|
170
170
|
if (json === null || Array.isArray(json) || typeof json != "object") {
|
|
171
171
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: expected object but got ${json === null ? "null" : Array.isArray(json) ? "array" : typeof json}`);
|
|
172
172
|
}
|
|
173
|
+
if (Object.keys(json).length == 0) {
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
173
176
|
const typeUrl = json["@type"];
|
|
174
177
|
if (typeof typeUrl != "string" || typeUrl == "") {
|
|
175
178
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: "@type" is empty`);
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
|
|
17
|
-
// @generated by protoc-gen-es v0.
|
|
17
|
+
// @generated by protoc-gen-es v0.2.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
18
18
|
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
|
|
19
19
|
/* eslint-disable */
|
|
20
20
|
const proto3_js_1 = require("../../proto3.js");
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0;
|
|
17
|
-
// @generated by protoc-gen-es v0.
|
|
17
|
+
// @generated by protoc-gen-es v0.2.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
18
18
|
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
|
|
19
19
|
/* eslint-disable */
|
|
20
20
|
const proto3_js_1 = require("../../proto3.js");
|
|
@@ -24,10 +24,7 @@ exports.findEnumSharedPrefix = exports.fieldJsonName = exports.localOneofName =
|
|
|
24
24
|
*/
|
|
25
25
|
function localName(desc) {
|
|
26
26
|
switch (desc.kind) {
|
|
27
|
-
case "
|
|
28
|
-
case "message_field":
|
|
29
|
-
case "map_field":
|
|
30
|
-
case "scalar_field":
|
|
27
|
+
case "field":
|
|
31
28
|
return localFieldName(desc.name, desc.oneof !== undefined);
|
|
32
29
|
case "oneof":
|
|
33
30
|
return localOneofName(desc.name);
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021-2022 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 field_js_1 = require("../field.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 === field_js_1.ScalarType.STRING);
|
|
35
|
+
const value = message.fields.find((f) => f.number == 2 &&
|
|
36
|
+
f.fieldKind == "scalar" &&
|
|
37
|
+
f.scalar === field_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 === field_js_1.ScalarType.INT64);
|
|
51
|
+
const nanos = message.fields.find((f) => f.number == 2 &&
|
|
52
|
+
f.fieldKind == "scalar" &&
|
|
53
|
+
f.scalar === field_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 === field_js_1.ScalarType.INT64);
|
|
67
|
+
const nanos = message.fields.find((f) => f.number == 2 &&
|
|
68
|
+
f.fieldKind == "scalar" &&
|
|
69
|
+
f.scalar === field_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 === null || fields === void 0 ? void 0 : 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 === null || nullValue === void 0 ? void 0 : 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 === field_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 === field_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 === field_js_1.ScalarType.BOOL &&
|
|
106
|
+
f.oneof === kind);
|
|
107
|
+
const structValue = message.fields.find((f) => f.number == 5 && f.oneof === kind);
|
|
108
|
+
if ((structValue === null || structValue === void 0 ? void 0 : 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 === null || listValue === void 0 ? void 0 : 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 === null || values === void 0 ? void 0 : 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 === field_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;
|
package/dist/esm/codegen-info.js
CHANGED
|
@@ -14,10 +14,12 @@
|
|
|
14
14
|
import { localName } from "./private/names.js";
|
|
15
15
|
import { getUnwrappedFieldType } from "./private/field-wrapper.js";
|
|
16
16
|
import { scalarDefaultValue } from "./private/scalars.js";
|
|
17
|
+
import { reifyWkt } from "./private/reify-wkt.js";
|
|
17
18
|
const packageName = "@bufbuild/protobuf";
|
|
18
19
|
export const codegenInfo = {
|
|
19
20
|
packageName,
|
|
20
21
|
localName,
|
|
22
|
+
reifyWkt,
|
|
21
23
|
getUnwrappedFieldType,
|
|
22
24
|
scalarDefaultValue,
|
|
23
25
|
// prettier-ignore
|
|
@@ -436,24 +436,24 @@ function newField(proto, file, parent, oneof, cart) {
|
|
|
436
436
|
const mapEntry = cart.mapEntries.get(trimLeadingDot(proto.typeName));
|
|
437
437
|
if (mapEntry !== undefined) {
|
|
438
438
|
assert(repeated, `invalid FieldDescriptorProto: expected map entry to be repeated`);
|
|
439
|
-
return Object.assign(Object.assign(Object.assign({}, common), { kind: "
|
|
439
|
+
return Object.assign(Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "map", repeated: false }), getMapFieldTypes(mapEntry));
|
|
440
440
|
}
|
|
441
441
|
const message = cart.messages.get(trimLeadingDot(proto.typeName));
|
|
442
442
|
assert(message !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
|
|
443
|
-
return Object.assign(Object.assign({}, common), { kind: "
|
|
443
|
+
return Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "message", repeated,
|
|
444
444
|
message });
|
|
445
445
|
}
|
|
446
446
|
case FieldDescriptorProto_Type.ENUM: {
|
|
447
447
|
assert(proto.typeName, `invalid FieldDescriptorProto: missing type_name`);
|
|
448
448
|
const e = cart.enums.get(trimLeadingDot(proto.typeName));
|
|
449
449
|
assert(e !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
|
|
450
|
-
return Object.assign(Object.assign({}, common), { kind: "
|
|
450
|
+
return Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "enum", getDefaultValue,
|
|
451
451
|
repeated, enum: e });
|
|
452
452
|
}
|
|
453
453
|
default: {
|
|
454
454
|
const scalar = fieldTypeToScalarType[proto.type];
|
|
455
455
|
assert(scalar, `invalid FieldDescriptorProto: unknown type ${proto.type}`);
|
|
456
|
-
return Object.assign(Object.assign({}, common), { kind: "
|
|
456
|
+
return Object.assign(Object.assign({}, common), { kind: "field", fieldKind: "scalar", getDefaultValue,
|
|
457
457
|
repeated,
|
|
458
458
|
scalar });
|
|
459
459
|
}
|
|
@@ -468,7 +468,7 @@ function newExtension(proto, file, parent, cart) {
|
|
|
468
468
|
undefined, cart);
|
|
469
469
|
const extendee = cart.messages.get(trimLeadingDot(proto.extendee));
|
|
470
470
|
assert(extendee, `invalid FieldDescriptorProto: extendee ${proto.extendee} not found`);
|
|
471
|
-
return Object.assign(Object.assign({}, field), { typeName: makeTypeName(proto, parent, file), parent,
|
|
471
|
+
return Object.assign(Object.assign({}, field), { kind: "extension", typeName: makeTypeName(proto, parent, file), parent,
|
|
472
472
|
file,
|
|
473
473
|
extendee,
|
|
474
474
|
toString() {
|
|
@@ -537,18 +537,18 @@ function getMapFieldTypes(mapEntry) {
|
|
|
537
537
|
mapKey !== ScalarType.DOUBLE, `invalid DescriptorProto: map entry ${mapEntry.toString()} has unexpected key type ${(_b = keyField.proto.type) !== null && _b !== void 0 ? _b : -1}`);
|
|
538
538
|
const valueField = mapEntry.fields.find((f) => f.proto.number === 2);
|
|
539
539
|
assert(valueField, `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing value field`);
|
|
540
|
-
switch (valueField.
|
|
541
|
-
case "
|
|
540
|
+
switch (valueField.fieldKind) {
|
|
541
|
+
case "scalar":
|
|
542
542
|
return {
|
|
543
543
|
mapKey,
|
|
544
544
|
mapValue: Object.assign(Object.assign({}, valueField), { kind: "scalar" }),
|
|
545
545
|
};
|
|
546
|
-
case "
|
|
546
|
+
case "message":
|
|
547
547
|
return {
|
|
548
548
|
mapKey,
|
|
549
549
|
mapValue: Object.assign(Object.assign({}, valueField), { kind: "message" }),
|
|
550
550
|
};
|
|
551
|
-
case "
|
|
551
|
+
case "enum":
|
|
552
552
|
return {
|
|
553
553
|
mapKey,
|
|
554
554
|
mapValue: Object.assign(Object.assign({}, valueField), { kind: "enum" }),
|
|
@@ -706,23 +706,23 @@ function declarationString() {
|
|
|
706
706
|
if (this.optional) {
|
|
707
707
|
parts.push("optional");
|
|
708
708
|
}
|
|
709
|
-
const file = "
|
|
709
|
+
const file = this.kind === "extension" ? this.file : this.parent.file;
|
|
710
710
|
if (file.syntax == "proto2" &&
|
|
711
711
|
this.proto.label === FieldDescriptorProto_Label.REQUIRED) {
|
|
712
712
|
parts.push("required");
|
|
713
713
|
}
|
|
714
714
|
let type;
|
|
715
|
-
switch (this.
|
|
716
|
-
case "
|
|
715
|
+
switch (this.fieldKind) {
|
|
716
|
+
case "scalar":
|
|
717
717
|
type = ScalarType[this.scalar].toLowerCase();
|
|
718
718
|
break;
|
|
719
|
-
case "
|
|
719
|
+
case "enum":
|
|
720
720
|
type = this.enum.typeName;
|
|
721
721
|
break;
|
|
722
|
-
case "
|
|
722
|
+
case "message":
|
|
723
723
|
type = this.message.typeName;
|
|
724
724
|
break;
|
|
725
|
-
case "
|
|
725
|
+
case "map": {
|
|
726
726
|
const k = ScalarType[this.mapKey].toLowerCase();
|
|
727
727
|
let v;
|
|
728
728
|
switch (this.mapValue.kind) {
|
|
@@ -772,13 +772,13 @@ function getDefaultValue() {
|
|
|
772
772
|
if (d === undefined) {
|
|
773
773
|
return undefined;
|
|
774
774
|
}
|
|
775
|
-
switch (this.
|
|
776
|
-
case "
|
|
775
|
+
switch (this.fieldKind) {
|
|
776
|
+
case "enum": {
|
|
777
777
|
const enumValue = this.enum.values.find((v) => v.name === d);
|
|
778
778
|
assert(enumValue, `cannot parse ${this.toString()} default value: ${d}`);
|
|
779
779
|
return enumValue.number;
|
|
780
780
|
}
|
|
781
|
-
case "
|
|
781
|
+
case "scalar":
|
|
782
782
|
switch (this.scalar) {
|
|
783
783
|
case ScalarType.STRING:
|
|
784
784
|
return d;
|
|
@@ -157,17 +157,17 @@ export function createRegistryFromDescriptors(input, replaceWkt = true) {
|
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
159
|
function makeFieldInfo(desc, resolver) {
|
|
160
|
-
switch (desc.
|
|
161
|
-
case "
|
|
160
|
+
switch (desc.fieldKind) {
|
|
161
|
+
case "map":
|
|
162
162
|
return makeMapFieldInfo(desc, resolver);
|
|
163
|
-
case "
|
|
163
|
+
case "message":
|
|
164
164
|
return makeMessageFieldInfo(desc, resolver);
|
|
165
|
-
case "
|
|
165
|
+
case "enum": {
|
|
166
166
|
const fi = makeEnumFieldInfo(desc, resolver);
|
|
167
167
|
fi.default = desc.getDefaultValue();
|
|
168
168
|
return fi;
|
|
169
169
|
}
|
|
170
|
-
case "
|
|
170
|
+
case "scalar": {
|
|
171
171
|
const fi = makeScalarFieldInfo(desc);
|
|
172
172
|
fi.default = desc.getDefaultValue();
|
|
173
173
|
return fi;
|
|
@@ -167,6 +167,9 @@ export class Any extends Message {
|
|
|
167
167
|
if (json === null || Array.isArray(json) || typeof json != "object") {
|
|
168
168
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: expected object but got ${json === null ? "null" : Array.isArray(json) ? "array" : typeof json}`);
|
|
169
169
|
}
|
|
170
|
+
if (Object.keys(json).length == 0) {
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
170
173
|
const typeUrl = json["@type"];
|
|
171
174
|
if (typeof typeUrl != "string" || typeUrl == "") {
|
|
172
175
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: "@type" is empty`);
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
// @generated by protoc-gen-es v0.
|
|
14
|
+
// @generated by protoc-gen-es v0.2.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
15
15
|
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
|
|
16
16
|
/* eslint-disable */
|
|
17
17
|
import { proto3 } from "../../proto3.js";
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
// @generated by protoc-gen-es v0.
|
|
14
|
+
// @generated by protoc-gen-es v0.2.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
15
15
|
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
|
|
16
16
|
/* eslint-disable */
|
|
17
17
|
import { proto3 } from "../../proto3.js";
|
|
@@ -21,10 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
export function localName(desc) {
|
|
23
23
|
switch (desc.kind) {
|
|
24
|
-
case "
|
|
25
|
-
case "message_field":
|
|
26
|
-
case "map_field":
|
|
27
|
-
case "scalar_field":
|
|
24
|
+
case "field":
|
|
28
25
|
return localFieldName(desc.name, desc.oneof !== undefined);
|
|
29
26
|
case "oneof":
|
|
30
27
|
return localOneofName(desc.name);
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// Copyright 2021-2022 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 { ScalarType } from "../field.js";
|
|
15
|
+
/**
|
|
16
|
+
* Reifies a given DescMessage into a more concrete object representing its
|
|
17
|
+
* respective well-known type. The returned object will contain properties
|
|
18
|
+
* representing the WKT's defined fields.
|
|
19
|
+
*
|
|
20
|
+
* Useful during code generation when immediate access to a particular field
|
|
21
|
+
* is needed without having to search the object's typename and DescField list.
|
|
22
|
+
*
|
|
23
|
+
* Returns undefined if the WKT cannot be completely constructed via the
|
|
24
|
+
* DescMessage.
|
|
25
|
+
*/
|
|
26
|
+
export function reifyWkt(message) {
|
|
27
|
+
switch (message.typeName) {
|
|
28
|
+
case "google.protobuf.Any": {
|
|
29
|
+
const typeUrl = message.fields.find((f) => f.number == 1 &&
|
|
30
|
+
f.fieldKind == "scalar" &&
|
|
31
|
+
f.scalar === ScalarType.STRING);
|
|
32
|
+
const value = message.fields.find((f) => f.number == 2 &&
|
|
33
|
+
f.fieldKind == "scalar" &&
|
|
34
|
+
f.scalar === ScalarType.BYTES);
|
|
35
|
+
if (typeUrl && value) {
|
|
36
|
+
return {
|
|
37
|
+
typeName: message.typeName,
|
|
38
|
+
typeUrl,
|
|
39
|
+
value,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case "google.protobuf.Timestamp": {
|
|
45
|
+
const seconds = message.fields.find((f) => f.number == 1 &&
|
|
46
|
+
f.fieldKind == "scalar" &&
|
|
47
|
+
f.scalar === ScalarType.INT64);
|
|
48
|
+
const nanos = message.fields.find((f) => f.number == 2 &&
|
|
49
|
+
f.fieldKind == "scalar" &&
|
|
50
|
+
f.scalar === ScalarType.INT32);
|
|
51
|
+
if (seconds && nanos) {
|
|
52
|
+
return {
|
|
53
|
+
typeName: message.typeName,
|
|
54
|
+
seconds,
|
|
55
|
+
nanos,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case "google.protobuf.Duration": {
|
|
61
|
+
const seconds = message.fields.find((f) => f.number == 1 &&
|
|
62
|
+
f.fieldKind == "scalar" &&
|
|
63
|
+
f.scalar === ScalarType.INT64);
|
|
64
|
+
const nanos = message.fields.find((f) => f.number == 2 &&
|
|
65
|
+
f.fieldKind == "scalar" &&
|
|
66
|
+
f.scalar === ScalarType.INT32);
|
|
67
|
+
if (seconds && nanos) {
|
|
68
|
+
return {
|
|
69
|
+
typeName: message.typeName,
|
|
70
|
+
seconds,
|
|
71
|
+
nanos,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case "google.protobuf.Struct": {
|
|
77
|
+
const fields = message.fields.find((f) => f.number == 1 && !f.repeated);
|
|
78
|
+
if ((fields === null || fields === void 0 ? void 0 : fields.fieldKind) !== "map" ||
|
|
79
|
+
fields.mapValue.kind !== "message" ||
|
|
80
|
+
fields.mapValue.message.typeName !== "google.protobuf.Value") {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
return { typeName: message.typeName, fields };
|
|
84
|
+
}
|
|
85
|
+
case "google.protobuf.Value": {
|
|
86
|
+
const kind = message.oneofs.find((o) => o.name === "kind");
|
|
87
|
+
const nullValue = message.fields.find((f) => f.number == 1 && f.oneof === kind);
|
|
88
|
+
if ((nullValue === null || nullValue === void 0 ? void 0 : nullValue.fieldKind) !== "enum" ||
|
|
89
|
+
nullValue.enum.typeName !== "google.protobuf.NullValue") {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
const numberValue = message.fields.find((f) => f.number == 2 &&
|
|
93
|
+
f.fieldKind == "scalar" &&
|
|
94
|
+
f.scalar === ScalarType.DOUBLE &&
|
|
95
|
+
f.oneof === kind);
|
|
96
|
+
const stringValue = message.fields.find((f) => f.number == 3 &&
|
|
97
|
+
f.fieldKind == "scalar" &&
|
|
98
|
+
f.scalar === ScalarType.STRING &&
|
|
99
|
+
f.oneof === kind);
|
|
100
|
+
const boolValue = message.fields.find((f) => f.number == 4 &&
|
|
101
|
+
f.fieldKind == "scalar" &&
|
|
102
|
+
f.scalar === ScalarType.BOOL &&
|
|
103
|
+
f.oneof === kind);
|
|
104
|
+
const structValue = message.fields.find((f) => f.number == 5 && f.oneof === kind);
|
|
105
|
+
if ((structValue === null || structValue === void 0 ? void 0 : structValue.fieldKind) !== "message" ||
|
|
106
|
+
structValue.message.typeName !== "google.protobuf.Struct") {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
const listValue = message.fields.find((f) => f.number == 6 && f.oneof === kind);
|
|
110
|
+
if ((listValue === null || listValue === void 0 ? void 0 : listValue.fieldKind) !== "message" ||
|
|
111
|
+
listValue.message.typeName !== "google.protobuf.ListValue") {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
if (kind && numberValue && stringValue && boolValue) {
|
|
115
|
+
return {
|
|
116
|
+
typeName: message.typeName,
|
|
117
|
+
kind,
|
|
118
|
+
nullValue,
|
|
119
|
+
numberValue,
|
|
120
|
+
stringValue,
|
|
121
|
+
boolValue,
|
|
122
|
+
structValue,
|
|
123
|
+
listValue,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case "google.protobuf.ListValue": {
|
|
129
|
+
const values = message.fields.find((f) => f.number == 1 && f.repeated);
|
|
130
|
+
if ((values === null || values === void 0 ? void 0 : values.fieldKind) != "message" ||
|
|
131
|
+
values.message.typeName !== "google.protobuf.Value") {
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
return { typeName: message.typeName, values };
|
|
135
|
+
}
|
|
136
|
+
case "google.protobuf.FieldMask": {
|
|
137
|
+
const paths = message.fields.find((f) => f.number == 1 &&
|
|
138
|
+
f.fieldKind == "scalar" &&
|
|
139
|
+
f.scalar === ScalarType.STRING &&
|
|
140
|
+
f.repeated);
|
|
141
|
+
if (paths) {
|
|
142
|
+
return { typeName: message.typeName, paths };
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case "google.protobuf.DoubleValue":
|
|
147
|
+
case "google.protobuf.FloatValue":
|
|
148
|
+
case "google.protobuf.Int64Value":
|
|
149
|
+
case "google.protobuf.UInt64Value":
|
|
150
|
+
case "google.protobuf.Int32Value":
|
|
151
|
+
case "google.protobuf.UInt32Value":
|
|
152
|
+
case "google.protobuf.BoolValue":
|
|
153
|
+
case "google.protobuf.StringValue":
|
|
154
|
+
case "google.protobuf.BytesValue": {
|
|
155
|
+
const value = message.fields.find((f) => f.number == 1 && f.name == "value");
|
|
156
|
+
if (!value) {
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
if (value.fieldKind !== "scalar") {
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
return { typeName: message.typeName, value };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { localName } from "./private/names.js";
|
|
2
2
|
import { getUnwrappedFieldType } from "./private/field-wrapper.js";
|
|
3
3
|
import { scalarDefaultValue } from "./private/scalars.js";
|
|
4
|
+
import { reifyWkt } from "./private/reify-wkt.js";
|
|
4
5
|
interface CodegenInfo {
|
|
5
6
|
readonly packageName: string;
|
|
6
7
|
readonly localName: typeof localName;
|
|
@@ -8,6 +9,7 @@ interface CodegenInfo {
|
|
|
8
9
|
readonly getUnwrappedFieldType: typeof getUnwrappedFieldType;
|
|
9
10
|
readonly wktSourceFiles: readonly string[];
|
|
10
11
|
readonly scalarDefaultValue: typeof scalarDefaultValue;
|
|
12
|
+
readonly reifyWkt: typeof reifyWkt;
|
|
11
13
|
}
|
|
12
14
|
declare type RuntimeSymbolName = "proto2" | "proto3" | "Message" | "PartialMessage" | "PlainMessage" | "FieldList" | "MessageType" | "BinaryReadOptions" | "BinaryWriteOptions" | "JsonReadOptions" | "JsonWriteOptions" | "JsonValue" | "JsonObject" | "protoInt64" | "ScalarType" | "MethodKind" | "MethodIdempotency";
|
|
13
15
|
declare type RuntimeSymbolInfo = {
|
|
@@ -8,6 +8,10 @@ import type { MethodIdempotency, MethodKind } from "./service-type.js";
|
|
|
8
8
|
* When protobuf sources are compiled, each file is parsed into a
|
|
9
9
|
* google.protobuf.FileDescriptorProto. Those messages describe all parts
|
|
10
10
|
* of the source file that are required to generate code for them.
|
|
11
|
+
*
|
|
12
|
+
* DescriptorSet resolves references between the descriptors, hides
|
|
13
|
+
* implementation details like synthetic map entry messages, and provides
|
|
14
|
+
* simple access to comments.
|
|
11
15
|
*/
|
|
12
16
|
export interface DescriptorSet {
|
|
13
17
|
/**
|
|
@@ -34,6 +38,10 @@ export interface DescriptorSet {
|
|
|
34
38
|
*/
|
|
35
39
|
readonly extensions: ReadonlyMap<string, DescExtension>;
|
|
36
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* A union of all descriptors, discriminated by a `kind` property.
|
|
43
|
+
*/
|
|
44
|
+
export declare type AnyDesc = DescFile | DescEnum | DescEnumValue | DescMessage | DescField | DescExtension | DescOneof | DescService | DescMethod;
|
|
37
45
|
/**
|
|
38
46
|
* Describes a protobuf source file.
|
|
39
47
|
*/
|
|
@@ -232,6 +240,7 @@ export interface DescMessage {
|
|
|
232
240
|
* Describes a field declaration in a protobuf source file.
|
|
233
241
|
*/
|
|
234
242
|
export declare type DescField = DescFieldCommon & (DescFieldScalar | DescFieldMessage | DescFieldEnum | DescFieldMap) & {
|
|
243
|
+
kind: "field";
|
|
235
244
|
/**
|
|
236
245
|
* The message this field is declared on.
|
|
237
246
|
*/
|
|
@@ -241,6 +250,7 @@ export declare type DescField = DescFieldCommon & (DescFieldScalar | DescFieldMe
|
|
|
241
250
|
* Describes an extension in a protobuf source file.
|
|
242
251
|
*/
|
|
243
252
|
export declare type DescExtension = DescFieldCommon & (DescFieldScalar | DescFieldMessage | DescFieldEnum | DescFieldMap) & {
|
|
253
|
+
kind: "extension";
|
|
244
254
|
/**
|
|
245
255
|
* The fully qualified name of the extension.
|
|
246
256
|
*/
|
|
@@ -311,7 +321,7 @@ interface DescFieldCommon {
|
|
|
311
321
|
toString(): string;
|
|
312
322
|
}
|
|
313
323
|
interface DescFieldScalar {
|
|
314
|
-
readonly
|
|
324
|
+
readonly fieldKind: "scalar";
|
|
315
325
|
/**
|
|
316
326
|
* Is the field repeated?
|
|
317
327
|
*/
|
|
@@ -343,7 +353,7 @@ interface DescFieldScalar {
|
|
|
343
353
|
getDefaultValue(): number | boolean | string | bigint | Uint8Array | undefined;
|
|
344
354
|
}
|
|
345
355
|
interface DescFieldMessage {
|
|
346
|
-
readonly
|
|
356
|
+
readonly fieldKind: "message";
|
|
347
357
|
/**
|
|
348
358
|
* Is the field repeated?
|
|
349
359
|
*/
|
|
@@ -370,7 +380,7 @@ interface DescFieldMessage {
|
|
|
370
380
|
readonly mapValue: undefined;
|
|
371
381
|
}
|
|
372
382
|
interface DescFieldEnum {
|
|
373
|
-
readonly
|
|
383
|
+
readonly fieldKind: "enum";
|
|
374
384
|
/**
|
|
375
385
|
* Is the field repeated?
|
|
376
386
|
*/
|
|
@@ -402,7 +412,7 @@ interface DescFieldEnum {
|
|
|
402
412
|
getDefaultValue(): number | boolean | string | bigint | Uint8Array | undefined;
|
|
403
413
|
}
|
|
404
414
|
interface DescFieldMap {
|
|
405
|
-
readonly
|
|
415
|
+
readonly fieldKind: "map";
|
|
406
416
|
/**
|
|
407
417
|
* Is the field repeated?
|
|
408
418
|
*/
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
|
|
|
15
15
|
export type { IBinaryReader, IBinaryWriter } from "./binary-encoding.js";
|
|
16
16
|
export type { BinaryFormat, BinaryWriteOptions, BinaryReadOptions, } from "./binary-format.js";
|
|
17
17
|
export { JsonFormat, JsonObject, JsonValue, JsonReadOptions, JsonWriteOptions, JsonWriteStringOptions, } from "./json-format.js";
|
|
18
|
-
export { DescriptorSet, DescFile, DescEnum, DescEnumValue, DescMessage, DescOneof, DescField, DescService, DescMethod, DescExtension, DescComments, } from "./descriptor-set.js";
|
|
18
|
+
export { DescriptorSet, AnyDesc, DescFile, DescEnum, DescEnumValue, DescMessage, DescOneof, DescField, DescService, DescMethod, DescExtension, DescComments, } from "./descriptor-set.js";
|
|
19
19
|
export { createDescriptorSet } from "./create-descriptor-set.js";
|
|
20
20
|
export { IMessageTypeRegistry } from "./type-registry.js";
|
|
21
21
|
export { createRegistry } from "./create-registry.js";
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { DescField, DescMessage, DescOneof } from "../descriptor-set.js";
|
|
2
|
+
declare 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 {};
|
package/package.json
CHANGED