@bufbuild/protobuf 0.0.6 → 0.0.9
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/README.md +34 -4
- package/dist/cjs/binary-encoding.js +2 -2
- package/dist/cjs/codegen-info.js +60 -0
- package/dist/cjs/create-descriptor-set.js +952 -0
- package/dist/cjs/create-registry-from-desc.js +376 -0
- package/dist/cjs/create-registry.js +75 -0
- package/dist/cjs/descriptor-set.js +0 -458
- package/dist/cjs/google/protobuf/any_pb.js +4 -2
- package/dist/cjs/google/protobuf/duration_pb.js +1 -1
- package/dist/cjs/google/protobuf/struct_pb.js +2 -2
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/index.js +17 -7
- package/dist/cjs/{descriptor-registry.js → legacy-descriptor-registry.js} +35 -69
- package/dist/cjs/legacy-descriptor-set.js +453 -0
- package/dist/cjs/legacy-type-registry.js +104 -0
- package/dist/cjs/message.js +2 -1
- package/dist/cjs/private/binary-format-common.js +4 -3
- package/dist/cjs/private/binary-format-proto2.js +3 -6
- package/dist/cjs/private/binary-format-proto3.js +2 -5
- package/dist/cjs/private/enum.js +22 -31
- package/dist/cjs/private/field-wrapper.js +30 -1
- package/dist/cjs/private/field.js +1 -1
- package/dist/cjs/private/json-format-common.js +6 -5
- package/dist/cjs/private/message-type.js +2 -1
- package/dist/cjs/private/names.js +168 -29
- package/dist/cjs/proto-int64.js +1 -1
- package/dist/cjs/proto2.js +7 -9
- package/dist/cjs/proto3.js +10 -13
- package/dist/cjs/type-registry.js +0 -87
- package/dist/esm/binary-encoding.js +2 -2
- package/dist/esm/codegen-info.js +57 -0
- package/dist/esm/create-descriptor-set.js +947 -0
- package/dist/esm/create-registry-from-desc.js +371 -0
- package/dist/esm/create-registry.js +71 -0
- package/dist/esm/descriptor-set.js +1 -456
- package/dist/esm/google/protobuf/any_pb.js +4 -2
- package/dist/esm/google/protobuf/duration_pb.js +1 -1
- package/dist/esm/google/protobuf/struct_pb.js +2 -2
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/index.js +9 -3
- package/dist/esm/{descriptor-registry.js → legacy-descriptor-registry.js} +33 -67
- package/dist/esm/legacy-descriptor-set.js +449 -0
- package/dist/esm/legacy-type-registry.js +100 -0
- package/dist/esm/message.js +2 -1
- package/dist/esm/private/binary-format-common.js +4 -3
- package/dist/esm/private/binary-format-proto2.js +3 -6
- package/dist/esm/private/binary-format-proto3.js +2 -5
- package/dist/esm/private/enum.js +22 -31
- package/dist/esm/private/field-wrapper.js +28 -0
- package/dist/esm/private/field.js +2 -2
- package/dist/esm/private/json-format-common.js +6 -5
- package/dist/esm/private/message-type.js +2 -1
- package/dist/esm/private/names.js +163 -24
- package/dist/esm/proto-int64.js +1 -1
- package/dist/esm/proto2.js +8 -10
- package/dist/esm/proto3.js +11 -14
- package/dist/esm/type-registry.js +1 -85
- package/dist/types/codegen-info.d.ts +19 -0
- package/dist/types/create-descriptor-set.d.ts +16 -0
- package/dist/types/create-registry-from-desc.d.ts +49 -0
- package/dist/types/create-registry.d.ts +8 -0
- package/dist/types/descriptor-set.d.ts +554 -108
- package/dist/types/enum.d.ts +9 -5
- package/dist/types/index.d.ts +9 -3
- package/dist/types/{descriptor-registry.d.ts → legacy-descriptor-registry.d.ts} +8 -6
- package/dist/types/legacy-descriptor-set.d.ts +152 -0
- package/dist/types/legacy-type-registry.d.ts +44 -0
- package/dist/types/private/enum.d.ts +4 -8
- package/dist/types/private/field-wrapper.d.ts +7 -0
- package/dist/types/private/message-type.d.ts +1 -4
- package/dist/types/private/names.d.ts +26 -8
- package/dist/types/private/proto-runtime.d.ts +2 -2
- package/dist/types/private/util.d.ts +1 -6
- package/dist/types/type-registry.d.ts +0 -38
- package/package.json +4 -3
|
@@ -13,461 +13,3 @@
|
|
|
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.DescriptorSet = void 0;
|
|
17
|
-
const descriptor_pb_js_1 = require("./google/protobuf/descriptor_pb.js");
|
|
18
|
-
const assert_js_1 = require("./private/assert.js");
|
|
19
|
-
const field_js_1 = require("./field.js");
|
|
20
|
-
const service_type_js_1 = require("./service-type.js");
|
|
21
|
-
/**
|
|
22
|
-
* DescriptorSet wraps a set of google.protobuf.FileDescriptorProto,
|
|
23
|
-
* asserting basic expectations and providing hierarchical information.
|
|
24
|
-
*
|
|
25
|
-
* Note that all types are kept by their fully qualified type name
|
|
26
|
-
* with a leading dot.
|
|
27
|
-
*/
|
|
28
|
-
class DescriptorSet {
|
|
29
|
-
constructor() {
|
|
30
|
-
this.enums = {};
|
|
31
|
-
this.messages = {};
|
|
32
|
-
this.services = {};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* May raise an error on invalid descriptors.
|
|
36
|
-
*/
|
|
37
|
-
add(...files) {
|
|
38
|
-
for (const file of files) {
|
|
39
|
-
newFile(file, this);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
listEnums() {
|
|
43
|
-
return Object.values(this.enums).filter(isDefined);
|
|
44
|
-
}
|
|
45
|
-
listMessages() {
|
|
46
|
-
return Object.values(this.messages).filter(isDefined);
|
|
47
|
-
}
|
|
48
|
-
listServices() {
|
|
49
|
-
return Object.values(this.services).filter(isDefined);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.DescriptorSet = DescriptorSet;
|
|
53
|
-
function isDefined(v) {
|
|
54
|
-
return v !== undefined;
|
|
55
|
-
}
|
|
56
|
-
const fieldTypeToScalarType = {
|
|
57
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.DOUBLE]: field_js_1.ScalarType.DOUBLE,
|
|
58
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.FLOAT]: field_js_1.ScalarType.FLOAT,
|
|
59
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.INT64]: field_js_1.ScalarType.INT64,
|
|
60
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.UINT64]: field_js_1.ScalarType.UINT64,
|
|
61
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.INT32]: field_js_1.ScalarType.INT32,
|
|
62
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED64]: field_js_1.ScalarType.FIXED64,
|
|
63
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED32]: field_js_1.ScalarType.FIXED32,
|
|
64
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.BOOL]: field_js_1.ScalarType.BOOL,
|
|
65
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.STRING]: field_js_1.ScalarType.STRING,
|
|
66
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP]: undefined,
|
|
67
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.MESSAGE]: undefined,
|
|
68
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.BYTES]: field_js_1.ScalarType.BYTES,
|
|
69
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.UINT32]: field_js_1.ScalarType.UINT32,
|
|
70
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.ENUM]: undefined,
|
|
71
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED32]: field_js_1.ScalarType.SFIXED32,
|
|
72
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED64]: field_js_1.ScalarType.SFIXED64,
|
|
73
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.SINT32]: field_js_1.ScalarType.SINT32,
|
|
74
|
-
[descriptor_pb_js_1.FieldDescriptorProto_Type.SINT64]: field_js_1.ScalarType.SINT64,
|
|
75
|
-
};
|
|
76
|
-
function newFile(proto, ds) {
|
|
77
|
-
(0, assert_js_1.assert)(proto.name, `missing file descriptor name`);
|
|
78
|
-
if (proto.syntax !== undefined && proto.syntax !== "proto3") {
|
|
79
|
-
throw new Error(`invalid descriptor: unsupported syntax: ${proto.syntax}`);
|
|
80
|
-
}
|
|
81
|
-
const file = {
|
|
82
|
-
proto,
|
|
83
|
-
syntax: proto.syntax === "proto3" ? "proto3" : "proto2",
|
|
84
|
-
name: proto.name.endsWith(".proto")
|
|
85
|
-
? proto.name.substring(-".proto".length)
|
|
86
|
-
: proto.name,
|
|
87
|
-
toString() {
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
|
|
89
|
-
return `file ${this.proto.name}`;
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
for (const messageType of proto.messageType) {
|
|
93
|
-
newMessage(messageType, undefined, file, ds);
|
|
94
|
-
}
|
|
95
|
-
for (const enumType of proto.enumType) {
|
|
96
|
-
newEnum(enumType, undefined, file, ds);
|
|
97
|
-
}
|
|
98
|
-
for (const extension of proto.extension) {
|
|
99
|
-
newExtension(extension, undefined, file, ds);
|
|
100
|
-
}
|
|
101
|
-
for (const service of proto.service) {
|
|
102
|
-
newService(service, file, ds);
|
|
103
|
-
}
|
|
104
|
-
return file;
|
|
105
|
-
}
|
|
106
|
-
function newEnum(proto, parent, file, us) {
|
|
107
|
-
(0, assert_js_1.assert)(proto.name, `invalid descriptor: missing enum descriptor name`);
|
|
108
|
-
let protoTypeName;
|
|
109
|
-
if (parent) {
|
|
110
|
-
protoTypeName = `${parent.protoTypeName}.${proto.name}`;
|
|
111
|
-
}
|
|
112
|
-
else if (file.proto.package !== undefined) {
|
|
113
|
-
protoTypeName = `.${file.proto.package}.${proto.name}`;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
protoTypeName = `.${proto.name}`;
|
|
117
|
-
}
|
|
118
|
-
const values = [];
|
|
119
|
-
const enumT = {
|
|
120
|
-
proto,
|
|
121
|
-
file,
|
|
122
|
-
parent,
|
|
123
|
-
name: proto.name,
|
|
124
|
-
protoTypeName,
|
|
125
|
-
typeName: protoTypeName.startsWith(".")
|
|
126
|
-
? protoTypeName.substring(1)
|
|
127
|
-
: protoTypeName,
|
|
128
|
-
values,
|
|
129
|
-
toString() {
|
|
130
|
-
return `enum ${this.typeName}`;
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
us.enums[enumT.protoTypeName] = enumT;
|
|
134
|
-
for (const value of proto.value) {
|
|
135
|
-
values.push(newEnumValue(value, enumT));
|
|
136
|
-
}
|
|
137
|
-
return enumT;
|
|
138
|
-
}
|
|
139
|
-
function newEnumValue(proto, parent) {
|
|
140
|
-
(0, assert_js_1.assert)(proto.name, `invalid descriptor: missing enum value descriptor name`);
|
|
141
|
-
(0, assert_js_1.assert)(proto.number !== undefined, `invalid descriptor: missing enum value descriptor number`);
|
|
142
|
-
return {
|
|
143
|
-
proto,
|
|
144
|
-
name: proto.name,
|
|
145
|
-
number: proto.number,
|
|
146
|
-
parent,
|
|
147
|
-
toString() {
|
|
148
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
|
|
149
|
-
return `enum value ${this.parent.typeName}.${this.proto.name}`;
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
function newMessage(proto, parent, file, us) {
|
|
154
|
-
(0, assert_js_1.assert)(proto.name, `invalid descriptor: missing name`);
|
|
155
|
-
const nestedMessages = [];
|
|
156
|
-
const fields = [];
|
|
157
|
-
const oneofs = [];
|
|
158
|
-
const nestedEnums = [];
|
|
159
|
-
const nestedExtensions = [];
|
|
160
|
-
let protoTypeName;
|
|
161
|
-
if (parent) {
|
|
162
|
-
protoTypeName = `${parent.protoTypeName}.${proto.name}`;
|
|
163
|
-
}
|
|
164
|
-
else if (file.proto.package !== undefined) {
|
|
165
|
-
protoTypeName = `.${file.proto.package}.${proto.name}`;
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
protoTypeName = `.${proto.name}`;
|
|
169
|
-
}
|
|
170
|
-
const message = {
|
|
171
|
-
proto,
|
|
172
|
-
file,
|
|
173
|
-
parent,
|
|
174
|
-
name: proto.name,
|
|
175
|
-
typeName: protoTypeName.startsWith(".")
|
|
176
|
-
? protoTypeName.substring(1)
|
|
177
|
-
: protoTypeName,
|
|
178
|
-
protoTypeName,
|
|
179
|
-
fields,
|
|
180
|
-
oneofs,
|
|
181
|
-
nestedEnums,
|
|
182
|
-
nestedMessages,
|
|
183
|
-
nestedExtensions,
|
|
184
|
-
toString() {
|
|
185
|
-
return `message ${this.typeName}`;
|
|
186
|
-
},
|
|
187
|
-
};
|
|
188
|
-
us.messages[message.protoTypeName] = message;
|
|
189
|
-
for (const nestedType of proto.nestedType) {
|
|
190
|
-
nestedMessages.push(newMessage(nestedType, message, file, us));
|
|
191
|
-
}
|
|
192
|
-
for (const oneofDecl of proto.oneofDecl) {
|
|
193
|
-
oneofs.push(newOneof(oneofDecl, message, file));
|
|
194
|
-
}
|
|
195
|
-
for (const field of proto.field) {
|
|
196
|
-
let oneof = undefined;
|
|
197
|
-
if (field.oneofIndex !== undefined) {
|
|
198
|
-
oneof = oneofs[field.oneofIndex];
|
|
199
|
-
(0, assert_js_1.assert)(oneof, `invalid descriptor: oneof declaration index ${field.oneofIndex} specified by field #${field.number ?? -1} not found`);
|
|
200
|
-
}
|
|
201
|
-
fields.push(newField(field, message, oneof));
|
|
202
|
-
}
|
|
203
|
-
for (const enumType of proto.enumType) {
|
|
204
|
-
nestedEnums.push(newEnum(enumType, message, file, us));
|
|
205
|
-
}
|
|
206
|
-
for (const extension of proto.extension) {
|
|
207
|
-
nestedExtensions.push(newExtension(extension, message, file, us));
|
|
208
|
-
}
|
|
209
|
-
return message;
|
|
210
|
-
}
|
|
211
|
-
function newField(proto, parent, oneof) {
|
|
212
|
-
(0, assert_js_1.assert)(proto.name, `invalid descriptor: missing name`);
|
|
213
|
-
(0, assert_js_1.assert)(proto.number, `invalid descriptor: missing number`);
|
|
214
|
-
(0, assert_js_1.assert)(proto.type, `invalid descriptor: missing type`);
|
|
215
|
-
let optional = false;
|
|
216
|
-
let packed = proto.options?.packed === true;
|
|
217
|
-
switch (parent.file.syntax) {
|
|
218
|
-
case "proto2":
|
|
219
|
-
optional =
|
|
220
|
-
oneof === undefined &&
|
|
221
|
-
proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.OPTIONAL;
|
|
222
|
-
break;
|
|
223
|
-
case "proto3":
|
|
224
|
-
optional = proto.proto3Optional === true;
|
|
225
|
-
switch (proto.type) {
|
|
226
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.DOUBLE:
|
|
227
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.FLOAT:
|
|
228
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.INT64:
|
|
229
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.UINT64:
|
|
230
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.INT32:
|
|
231
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED64:
|
|
232
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED32:
|
|
233
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.UINT32:
|
|
234
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED32:
|
|
235
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED64:
|
|
236
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.SINT32:
|
|
237
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.SINT64:
|
|
238
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.BOOL:
|
|
239
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.ENUM:
|
|
240
|
-
// From the proto3 language guide:
|
|
241
|
-
// > In proto3, repeated fields of scalar numeric types are packed by default.
|
|
242
|
-
// This information is incomplete - according to the conformance tests, BOOL
|
|
243
|
-
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
244
|
-
// are not packed by default, which makes sense because they are length-delimited.
|
|
245
|
-
packed = true;
|
|
246
|
-
break;
|
|
247
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.STRING:
|
|
248
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP:
|
|
249
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.MESSAGE:
|
|
250
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.BYTES:
|
|
251
|
-
(0, assert_js_1.assert)(!packed, `invalid descriptor: ${descriptor_pb_js_1.FieldDescriptorProto_Type[proto.type]} cannot be packed`);
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
const field = {
|
|
257
|
-
proto,
|
|
258
|
-
name: proto.name,
|
|
259
|
-
number: proto.number,
|
|
260
|
-
type: proto.type,
|
|
261
|
-
parent,
|
|
262
|
-
oneof: proto.proto3Optional === true ? undefined : oneof,
|
|
263
|
-
optional,
|
|
264
|
-
packed,
|
|
265
|
-
toString() {
|
|
266
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
|
|
267
|
-
return `field ${parent.typeName}.${proto.name}`;
|
|
268
|
-
},
|
|
269
|
-
resolve(us) {
|
|
270
|
-
return resolveField(this, us);
|
|
271
|
-
},
|
|
272
|
-
};
|
|
273
|
-
if (oneof) {
|
|
274
|
-
oneof.fields.push(field);
|
|
275
|
-
}
|
|
276
|
-
return field;
|
|
277
|
-
}
|
|
278
|
-
function resolveField(u, us) {
|
|
279
|
-
const repeated = u.proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.REPEATED;
|
|
280
|
-
switch (u.type) {
|
|
281
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.MESSAGE:
|
|
282
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP: {
|
|
283
|
-
(0, assert_js_1.assert)(u.proto.typeName, `invalid descriptor: ${u.toString()} has type ${descriptor_pb_js_1.FieldDescriptorProto_Type[u.type]}, but type_name is unset`);
|
|
284
|
-
const refMessage = us.messages[u.proto.typeName];
|
|
285
|
-
(0, assert_js_1.assert)(refMessage, `invalid descriptor: cannot find type_name "${u.proto.typeName}" specified by ${u.toString()}`);
|
|
286
|
-
if (refMessage.proto.options?.mapEntry !== undefined) {
|
|
287
|
-
return {
|
|
288
|
-
...u,
|
|
289
|
-
repeated: false,
|
|
290
|
-
scalarType: undefined,
|
|
291
|
-
message: undefined,
|
|
292
|
-
enum: undefined,
|
|
293
|
-
map: resolveMap(refMessage, us),
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
return {
|
|
297
|
-
...u,
|
|
298
|
-
repeated,
|
|
299
|
-
scalarType: undefined,
|
|
300
|
-
message: refMessage,
|
|
301
|
-
enum: undefined,
|
|
302
|
-
map: undefined,
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
case descriptor_pb_js_1.FieldDescriptorProto_Type.ENUM: {
|
|
306
|
-
(0, assert_js_1.assert)(u.proto.typeName, `invalid descriptor: ${u.toString()} has type ${descriptor_pb_js_1.FieldDescriptorProto_Type[u.type]}, but type_name is unset`);
|
|
307
|
-
const refEnum = us.enums[u.proto.typeName];
|
|
308
|
-
(0, assert_js_1.assert)(refEnum, `invalid descriptor: cannot find type_name "${u.proto.typeName}" specified by ${u.toString()}`);
|
|
309
|
-
return {
|
|
310
|
-
...u,
|
|
311
|
-
repeated,
|
|
312
|
-
scalarType: undefined,
|
|
313
|
-
message: undefined,
|
|
314
|
-
enum: refEnum,
|
|
315
|
-
map: undefined,
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
default: {
|
|
319
|
-
const scalarType = fieldTypeToScalarType[u.type];
|
|
320
|
-
(0, assert_js_1.assert)(scalarType, `invalid descriptor: unable to convert google.protobuf.FieldDescriptorProto.Type ${descriptor_pb_js_1.FieldDescriptorProto_Type[u.type]} to ScalarType`);
|
|
321
|
-
return {
|
|
322
|
-
...u,
|
|
323
|
-
repeated,
|
|
324
|
-
scalarType,
|
|
325
|
-
message: undefined,
|
|
326
|
-
enum: undefined,
|
|
327
|
-
map: undefined,
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
function resolveMap(mapEntry, us) {
|
|
333
|
-
(0, assert_js_1.assert)(mapEntry.proto.options?.mapEntry, `invalid descriptor: expected ${mapEntry.toString()} to be a map entry`);
|
|
334
|
-
(0, assert_js_1.assert)(mapEntry.fields.length === 2, `invalid descriptor: map entry ${mapEntry.toString()} has ${mapEntry.fields.length} fields`);
|
|
335
|
-
const uKeyField = mapEntry.fields.find((f) => f.proto.number === 1);
|
|
336
|
-
(0, assert_js_1.assert)(uKeyField, `invalid descriptor: map entry ${mapEntry.toString()} is missing key field`);
|
|
337
|
-
const keyField = resolveField(uKeyField, us);
|
|
338
|
-
(0, assert_js_1.assert)(keyField.scalarType !== undefined &&
|
|
339
|
-
keyField.scalarType !== field_js_1.ScalarType.BYTES &&
|
|
340
|
-
keyField.scalarType !== field_js_1.ScalarType.FLOAT &&
|
|
341
|
-
keyField.scalarType !== field_js_1.ScalarType.DOUBLE, `invalid descriptor: map entry ${mapEntry.toString()} has unexpected key type ${descriptor_pb_js_1.FieldDescriptorProto_Type[keyField.type]}`);
|
|
342
|
-
const uValueField = mapEntry.fields.find((f) => f.proto.number === 2);
|
|
343
|
-
(0, assert_js_1.assert)(uValueField, `invalid descriptor: map entry ${mapEntry.toString()} is missing value field`);
|
|
344
|
-
const valueField = resolveField(uValueField, us);
|
|
345
|
-
if (valueField.scalarType !== undefined) {
|
|
346
|
-
return {
|
|
347
|
-
key: keyField.scalarType,
|
|
348
|
-
value: {
|
|
349
|
-
scalarType: valueField.scalarType,
|
|
350
|
-
enum: undefined,
|
|
351
|
-
message: undefined,
|
|
352
|
-
},
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
if (valueField.enum !== undefined) {
|
|
356
|
-
return {
|
|
357
|
-
key: keyField.scalarType,
|
|
358
|
-
value: { scalar: undefined, enum: valueField.enum, message: undefined },
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
if (valueField.message !== undefined) {
|
|
362
|
-
return {
|
|
363
|
-
key: keyField.scalarType,
|
|
364
|
-
value: {
|
|
365
|
-
scalar: undefined,
|
|
366
|
-
enum: undefined,
|
|
367
|
-
message: valueField.message,
|
|
368
|
-
},
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
throw new Error(`invalid descriptor: map entry ${mapEntry.toString()} has unexpected value type ${descriptor_pb_js_1.FieldDescriptorProto_Type[keyField.type]}`);
|
|
372
|
-
}
|
|
373
|
-
function newOneof(proto, parent, file) {
|
|
374
|
-
(0, assert_js_1.assert)(proto.name, `invalid descriptor: missing oneof descriptor name`);
|
|
375
|
-
return {
|
|
376
|
-
proto,
|
|
377
|
-
parent,
|
|
378
|
-
file,
|
|
379
|
-
fields: [],
|
|
380
|
-
name: proto.name,
|
|
381
|
-
toString() {
|
|
382
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
|
|
383
|
-
return `oneof ${parent.typeName}.${proto.name}`;
|
|
384
|
-
},
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
function newExtension(proto, parent, file, us // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
388
|
-
) {
|
|
389
|
-
(0, assert_js_1.assert)(proto.name, `invalid descriptor: missing field descriptor name`);
|
|
390
|
-
return {
|
|
391
|
-
proto,
|
|
392
|
-
file,
|
|
393
|
-
parent,
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
function newService(proto, file, us) {
|
|
397
|
-
(0, assert_js_1.assert)(proto.name, `invalid descriptor: missing service descriptor name`);
|
|
398
|
-
let protoTypeName;
|
|
399
|
-
if (file.proto.package !== undefined) {
|
|
400
|
-
protoTypeName = `.${file.proto.package}.${proto.name}`;
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
protoTypeName = `.${proto.name}`;
|
|
404
|
-
}
|
|
405
|
-
const methods = [];
|
|
406
|
-
const service = {
|
|
407
|
-
proto,
|
|
408
|
-
file,
|
|
409
|
-
typeName: protoTypeName.startsWith(".")
|
|
410
|
-
? protoTypeName.substring(1)
|
|
411
|
-
: protoTypeName,
|
|
412
|
-
protoTypeName,
|
|
413
|
-
methods,
|
|
414
|
-
toString() {
|
|
415
|
-
return `service ${this.typeName}`;
|
|
416
|
-
},
|
|
417
|
-
};
|
|
418
|
-
for (const method of proto.method) {
|
|
419
|
-
methods.push(newMethod(method, service));
|
|
420
|
-
}
|
|
421
|
-
us.services[service.protoTypeName] = service;
|
|
422
|
-
return service;
|
|
423
|
-
}
|
|
424
|
-
function newMethod(proto, parent) {
|
|
425
|
-
(0, assert_js_1.assert)(proto.name, `invalid descriptor: missing method descriptor name`);
|
|
426
|
-
(0, assert_js_1.assert)(proto.inputType, `invalid descriptor: missing method input type`);
|
|
427
|
-
(0, assert_js_1.assert)(proto.outputType, `invalid descriptor: missing method output type`);
|
|
428
|
-
let kind;
|
|
429
|
-
if (proto.clientStreaming === true && proto.serverStreaming === true) {
|
|
430
|
-
kind = service_type_js_1.MethodKind.BiDiStreaming;
|
|
431
|
-
}
|
|
432
|
-
else if (proto.clientStreaming === true) {
|
|
433
|
-
kind = service_type_js_1.MethodKind.ClientStreaming;
|
|
434
|
-
}
|
|
435
|
-
else if (proto.serverStreaming === true) {
|
|
436
|
-
kind = service_type_js_1.MethodKind.ServerStreaming;
|
|
437
|
-
}
|
|
438
|
-
else {
|
|
439
|
-
kind = service_type_js_1.MethodKind.Unary;
|
|
440
|
-
}
|
|
441
|
-
let idempotency;
|
|
442
|
-
switch (proto.options?.idempotencyLevel) {
|
|
443
|
-
case descriptor_pb_js_1.MethodOptions_IdempotencyLevel.IDEMPOTENT:
|
|
444
|
-
idempotency = service_type_js_1.MethodIdempotency.Idempotent;
|
|
445
|
-
break;
|
|
446
|
-
case descriptor_pb_js_1.MethodOptions_IdempotencyLevel.NO_SIDE_EFFECTS:
|
|
447
|
-
idempotency = service_type_js_1.MethodIdempotency.NoSideEffects;
|
|
448
|
-
break;
|
|
449
|
-
case descriptor_pb_js_1.MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN:
|
|
450
|
-
case undefined:
|
|
451
|
-
idempotency = undefined;
|
|
452
|
-
break;
|
|
453
|
-
}
|
|
454
|
-
const inputTypeName = proto.inputType.startsWith(".")
|
|
455
|
-
? proto.inputType.substring(1)
|
|
456
|
-
: proto.inputType;
|
|
457
|
-
const outputTypeName = proto.outputType.startsWith(".")
|
|
458
|
-
? proto.outputType.substring(1)
|
|
459
|
-
: proto.outputType;
|
|
460
|
-
return {
|
|
461
|
-
proto,
|
|
462
|
-
parent,
|
|
463
|
-
name: proto.name,
|
|
464
|
-
kind,
|
|
465
|
-
idempotency,
|
|
466
|
-
inputTypeName,
|
|
467
|
-
outputTypeName,
|
|
468
|
-
toString() {
|
|
469
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
|
|
470
|
-
return `rpc ${this.parent.typeName}.${proto.name}`;
|
|
471
|
-
},
|
|
472
|
-
};
|
|
473
|
-
}
|
|
@@ -148,11 +148,12 @@ class Any extends message_js_1.Message {
|
|
|
148
148
|
proto3_js_1.proto3.util.initPartial(data, this);
|
|
149
149
|
}
|
|
150
150
|
toJson(options) {
|
|
151
|
+
var _a;
|
|
151
152
|
if (this.typeUrl === "") {
|
|
152
153
|
return {};
|
|
153
154
|
}
|
|
154
155
|
const typeName = this.typeUrlToName(this.typeUrl);
|
|
155
|
-
const messageType = options
|
|
156
|
+
const messageType = (_a = options === null || options === void 0 ? void 0 : options.typeRegistry) === null || _a === void 0 ? void 0 : _a.findMessage(typeName);
|
|
156
157
|
if (!messageType) {
|
|
157
158
|
throw new Error(`cannot encode message google.protobuf.Any to JSON: "${this.typeUrl}" is not in the type registry`);
|
|
158
159
|
}
|
|
@@ -165,6 +166,7 @@ class Any extends message_js_1.Message {
|
|
|
165
166
|
return json;
|
|
166
167
|
}
|
|
167
168
|
fromJson(json, options) {
|
|
169
|
+
var _a;
|
|
168
170
|
if (json === null || Array.isArray(json) || typeof json != "object") {
|
|
169
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}`);
|
|
170
172
|
}
|
|
@@ -172,7 +174,7 @@ class Any extends message_js_1.Message {
|
|
|
172
174
|
if (typeof typeUrl != "string" || typeUrl == "") {
|
|
173
175
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: "@type" is empty`);
|
|
174
176
|
}
|
|
175
|
-
const typeName = this.typeUrlToName(typeUrl), messageType = options
|
|
177
|
+
const typeName = this.typeUrlToName(typeUrl), messageType = (_a = options === null || options === void 0 ? void 0 : options.typeRegistry) === null || _a === void 0 ? void 0 : _a.findMessage(typeName);
|
|
176
178
|
if (!messageType) {
|
|
177
179
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: ${typeUrl} is not in the type registry`);
|
|
178
180
|
}
|
|
@@ -121,7 +121,7 @@ class Duration extends message_js_1.Message {
|
|
|
121
121
|
if (typeof match[2] == "string") {
|
|
122
122
|
const nanosStr = match[2] + "0".repeat(9 - match[2].length);
|
|
123
123
|
this.nanos = parseInt(nanosStr);
|
|
124
|
-
if (longSeconds <
|
|
124
|
+
if (longSeconds < proto_int64_js_1.protoInt64.zero) {
|
|
125
125
|
this.nanos = -this.nanos;
|
|
126
126
|
}
|
|
127
127
|
}
|
|
@@ -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.0.
|
|
17
|
+
// @generated by protoc-gen-es v0.0.9 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");
|
|
@@ -129,7 +129,7 @@ class Value extends message_js_1.Message {
|
|
|
129
129
|
return this.kind.value;
|
|
130
130
|
case "structValue":
|
|
131
131
|
case "listValue":
|
|
132
|
-
return this.kind.value.toJson({
|
|
132
|
+
return this.kind.value.toJson(Object.assign(Object.assign({}, options), { emitDefaultValues: true }));
|
|
133
133
|
}
|
|
134
134
|
throw new Error("google.protobuf.Value must have a value");
|
|
135
135
|
}
|
|
@@ -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.0.
|
|
17
|
+
// @generated by protoc-gen-es v0.0.9 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");
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,7 +27,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
27
27
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.
|
|
30
|
+
exports.TypeRegistry = exports.LegacyDescriptorSet = exports.LegacyDescriptorRegistry = exports.createRegistryFromDescriptors = exports.createRegistry = exports.createDescriptorSet = exports.BinaryReader = exports.BinaryWriter = exports.WireType = exports.MethodIdempotency = exports.MethodKind = exports.ScalarType = exports.Message = exports.codegenInfo = exports.protoBase64 = exports.protoInt64 = exports.proto2 = exports.proto3 = void 0;
|
|
31
31
|
var proto3_js_1 = require("./proto3.js");
|
|
32
32
|
Object.defineProperty(exports, "proto3", { enumerable: true, get: function () { return proto3_js_1.proto3; } });
|
|
33
33
|
var proto2_js_1 = require("./proto2.js");
|
|
@@ -36,6 +36,8 @@ var proto_int64_js_1 = require("./proto-int64.js");
|
|
|
36
36
|
Object.defineProperty(exports, "protoInt64", { enumerable: true, get: function () { return proto_int64_js_1.protoInt64; } });
|
|
37
37
|
var proto_base64_js_1 = require("./proto-base64.js");
|
|
38
38
|
Object.defineProperty(exports, "protoBase64", { enumerable: true, get: function () { return proto_base64_js_1.protoBase64; } });
|
|
39
|
+
var codegen_info_js_1 = require("./codegen-info.js");
|
|
40
|
+
Object.defineProperty(exports, "codegenInfo", { enumerable: true, get: function () { return codegen_info_js_1.codegenInfo; } });
|
|
39
41
|
var message_js_1 = require("./message.js");
|
|
40
42
|
Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return message_js_1.Message; } });
|
|
41
43
|
var field_js_1 = require("./field.js");
|
|
@@ -43,17 +45,25 @@ Object.defineProperty(exports, "ScalarType", { enumerable: true, get: function (
|
|
|
43
45
|
var service_type_js_1 = require("./service-type.js");
|
|
44
46
|
Object.defineProperty(exports, "MethodKind", { enumerable: true, get: function () { return service_type_js_1.MethodKind; } });
|
|
45
47
|
Object.defineProperty(exports, "MethodIdempotency", { enumerable: true, get: function () { return service_type_js_1.MethodIdempotency; } });
|
|
46
|
-
var type_registry_js_1 = require("./type-registry.js");
|
|
47
|
-
Object.defineProperty(exports, "TypeRegistry", { enumerable: true, get: function () { return type_registry_js_1.TypeRegistry; } });
|
|
48
|
-
var descriptor_registry_js_1 = require("./descriptor-registry.js");
|
|
49
|
-
Object.defineProperty(exports, "DescriptorRegistry", { enumerable: true, get: function () { return descriptor_registry_js_1.DescriptorRegistry; } });
|
|
50
|
-
var descriptor_set_js_1 = require("./descriptor-set.js");
|
|
51
|
-
Object.defineProperty(exports, "DescriptorSet", { enumerable: true, get: function () { return descriptor_set_js_1.DescriptorSet; } });
|
|
52
48
|
var binary_encoding_js_1 = require("./binary-encoding.js");
|
|
53
49
|
Object.defineProperty(exports, "WireType", { enumerable: true, get: function () { return binary_encoding_js_1.WireType; } });
|
|
54
50
|
Object.defineProperty(exports, "BinaryWriter", { enumerable: true, get: function () { return binary_encoding_js_1.BinaryWriter; } });
|
|
55
51
|
Object.defineProperty(exports, "BinaryReader", { enumerable: true, get: function () { return binary_encoding_js_1.BinaryReader; } });
|
|
56
52
|
var json_format_js_1 = require("./json-format.js");
|
|
53
|
+
var descriptor_set_js_1 = require("./descriptor-set.js");
|
|
54
|
+
var create_descriptor_set_js_1 = require("./create-descriptor-set.js");
|
|
55
|
+
Object.defineProperty(exports, "createDescriptorSet", { enumerable: true, get: function () { return create_descriptor_set_js_1.createDescriptorSet; } });
|
|
56
|
+
var type_registry_js_1 = require("./type-registry.js");
|
|
57
|
+
var create_registry_js_1 = require("./create-registry.js");
|
|
58
|
+
Object.defineProperty(exports, "createRegistry", { enumerable: true, get: function () { return create_registry_js_1.createRegistry; } });
|
|
59
|
+
var create_registry_from_desc_js_1 = require("./create-registry-from-desc.js");
|
|
60
|
+
Object.defineProperty(exports, "createRegistryFromDescriptors", { enumerable: true, get: function () { return create_registry_from_desc_js_1.createRegistryFromDescriptors; } });
|
|
61
|
+
var legacy_descriptor_registry_js_1 = require("./legacy-descriptor-registry.js");
|
|
62
|
+
Object.defineProperty(exports, "LegacyDescriptorRegistry", { enumerable: true, get: function () { return legacy_descriptor_registry_js_1.LegacyDescriptorRegistry; } });
|
|
63
|
+
var legacy_descriptor_set_js_1 = require("./legacy-descriptor-set.js");
|
|
64
|
+
Object.defineProperty(exports, "LegacyDescriptorSet", { enumerable: true, get: function () { return legacy_descriptor_set_js_1.LegacyDescriptorSet; } });
|
|
65
|
+
var legacy_type_registry_js_1 = require("./legacy-type-registry.js");
|
|
66
|
+
Object.defineProperty(exports, "TypeRegistry", { enumerable: true, get: function () { return legacy_type_registry_js_1.TypeRegistry; } });
|
|
57
67
|
// ideally, we would export these types with sub-path exports:
|
|
58
68
|
__exportStar(require("./google/protobuf/compiler/plugin_pb.js"), exports);
|
|
59
69
|
__exportStar(require("./google/protobuf/api_pb.js"), exports);
|