@bufbuild/protobuf 0.0.8 → 0.1.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/README.md +34 -4
- 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 +270 -0
- package/dist/cjs/create-registry.js +75 -0
- package/dist/cjs/descriptor-set.js +0 -436
- package/dist/cjs/google/protobuf/descriptor_pb.js +2 -2
- package/dist/cjs/google/protobuf/empty_pb.js +0 -1
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/google/varint.js +85 -37
- package/dist/cjs/index.js +11 -7
- 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 -6
- package/dist/cjs/private/names.js +168 -29
- package/dist/cjs/proto-int64.js +23 -40
- package/dist/cjs/proto2.js +2 -2
- package/dist/cjs/proto3.js +2 -2
- package/dist/cjs/type-registry.js +0 -87
- 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 +266 -0
- package/dist/esm/create-registry.js +71 -0
- package/dist/esm/descriptor-set.js +1 -434
- package/dist/esm/google/protobuf/descriptor_pb.js +2 -2
- package/dist/esm/google/protobuf/empty_pb.js +0 -1
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/google/varint.js +81 -34
- package/dist/esm/index.js +6 -3
- 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 -6
- package/dist/esm/private/names.js +163 -24
- package/dist/esm/proto-int64.js +24 -41
- package/dist/esm/proto2.js +3 -3
- package/dist/esm/proto3.js +3 -3
- 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 +15 -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/google/protobuf/descriptor_pb.d.ts +6 -6
- package/dist/types/google/protobuf/empty_pb.d.ts +0 -1
- package/dist/types/google/varint.d.ts +21 -9
- package/dist/types/index.d.ts +6 -3
- package/dist/types/message.d.ts +3 -1
- 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/proto-int64.d.ts +14 -13
- package/dist/types/type-registry.d.ts +0 -38
- package/package.json +6 -10
- package/dist/cjs/descriptor-registry.js +0 -460
- package/dist/esm/descriptor-registry.js +0 -456
- package/dist/protobuf.cjs +0 -2
- package/dist/protobuf.cjs.map +0 -1
- package/dist/protobuf.esm.js +0 -2
- package/dist/protobuf.esm.js.map +0 -1
- package/dist/protobuf.modern.js +0 -2
- package/dist/protobuf.modern.js.map +0 -1
- package/dist/types/descriptor-registry.d.ts +0 -43
|
@@ -11,437 +11,4 @@
|
|
|
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
|
-
|
|
15
|
-
import { assert } from "./private/assert.js";
|
|
16
|
-
import { ScalarType } from "./field.js";
|
|
17
|
-
import { MethodIdempotency, MethodKind } from "./service-type.js";
|
|
18
|
-
/**
|
|
19
|
-
* DescriptorSet wraps a set of google.protobuf.FileDescriptorProto,
|
|
20
|
-
* asserting basic expectations and providing hierarchical information.
|
|
21
|
-
*
|
|
22
|
-
* Note that all types are kept by their fully qualified type name
|
|
23
|
-
* with a leading dot.
|
|
24
|
-
*/
|
|
25
|
-
export class DescriptorSet {
|
|
26
|
-
constructor() {
|
|
27
|
-
this.enums = {};
|
|
28
|
-
this.messages = {};
|
|
29
|
-
this.services = {};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* May raise an error on invalid descriptors.
|
|
33
|
-
*/
|
|
34
|
-
add(...files) {
|
|
35
|
-
for (const file of files) {
|
|
36
|
-
newFile(file, this);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
listEnums() {
|
|
40
|
-
return Object.values(this.enums).filter(isDefined);
|
|
41
|
-
}
|
|
42
|
-
listMessages() {
|
|
43
|
-
return Object.values(this.messages).filter(isDefined);
|
|
44
|
-
}
|
|
45
|
-
listServices() {
|
|
46
|
-
return Object.values(this.services).filter(isDefined);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function isDefined(v) {
|
|
50
|
-
return v !== undefined;
|
|
51
|
-
}
|
|
52
|
-
const fieldTypeToScalarType = {
|
|
53
|
-
[FieldDescriptorProto_Type.DOUBLE]: ScalarType.DOUBLE,
|
|
54
|
-
[FieldDescriptorProto_Type.FLOAT]: ScalarType.FLOAT,
|
|
55
|
-
[FieldDescriptorProto_Type.INT64]: ScalarType.INT64,
|
|
56
|
-
[FieldDescriptorProto_Type.UINT64]: ScalarType.UINT64,
|
|
57
|
-
[FieldDescriptorProto_Type.INT32]: ScalarType.INT32,
|
|
58
|
-
[FieldDescriptorProto_Type.FIXED64]: ScalarType.FIXED64,
|
|
59
|
-
[FieldDescriptorProto_Type.FIXED32]: ScalarType.FIXED32,
|
|
60
|
-
[FieldDescriptorProto_Type.BOOL]: ScalarType.BOOL,
|
|
61
|
-
[FieldDescriptorProto_Type.STRING]: ScalarType.STRING,
|
|
62
|
-
[FieldDescriptorProto_Type.GROUP]: undefined,
|
|
63
|
-
[FieldDescriptorProto_Type.MESSAGE]: undefined,
|
|
64
|
-
[FieldDescriptorProto_Type.BYTES]: ScalarType.BYTES,
|
|
65
|
-
[FieldDescriptorProto_Type.UINT32]: ScalarType.UINT32,
|
|
66
|
-
[FieldDescriptorProto_Type.ENUM]: undefined,
|
|
67
|
-
[FieldDescriptorProto_Type.SFIXED32]: ScalarType.SFIXED32,
|
|
68
|
-
[FieldDescriptorProto_Type.SFIXED64]: ScalarType.SFIXED64,
|
|
69
|
-
[FieldDescriptorProto_Type.SINT32]: ScalarType.SINT32,
|
|
70
|
-
[FieldDescriptorProto_Type.SINT64]: ScalarType.SINT64,
|
|
71
|
-
};
|
|
72
|
-
function newFile(proto, ds) {
|
|
73
|
-
assert(proto.name, `missing file descriptor name`);
|
|
74
|
-
if (proto.syntax !== undefined && proto.syntax !== "proto3") {
|
|
75
|
-
throw new Error(`invalid descriptor: unsupported syntax: ${proto.syntax}`);
|
|
76
|
-
}
|
|
77
|
-
const file = {
|
|
78
|
-
proto,
|
|
79
|
-
syntax: proto.syntax === "proto3" ? "proto3" : "proto2",
|
|
80
|
-
name: proto.name.endsWith(".proto")
|
|
81
|
-
? proto.name.substring(-".proto".length)
|
|
82
|
-
: proto.name,
|
|
83
|
-
toString() {
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
|
|
85
|
-
return `file ${this.proto.name}`;
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
for (const messageType of proto.messageType) {
|
|
89
|
-
newMessage(messageType, undefined, file, ds);
|
|
90
|
-
}
|
|
91
|
-
for (const enumType of proto.enumType) {
|
|
92
|
-
newEnum(enumType, undefined, file, ds);
|
|
93
|
-
}
|
|
94
|
-
for (const extension of proto.extension) {
|
|
95
|
-
newExtension(extension, undefined, file, ds);
|
|
96
|
-
}
|
|
97
|
-
for (const service of proto.service) {
|
|
98
|
-
newService(service, file, ds);
|
|
99
|
-
}
|
|
100
|
-
return file;
|
|
101
|
-
}
|
|
102
|
-
function newEnum(proto, parent, file, us) {
|
|
103
|
-
assert(proto.name, `invalid descriptor: missing enum descriptor name`);
|
|
104
|
-
let protoTypeName;
|
|
105
|
-
if (parent) {
|
|
106
|
-
protoTypeName = `${parent.protoTypeName}.${proto.name}`;
|
|
107
|
-
}
|
|
108
|
-
else if (file.proto.package !== undefined) {
|
|
109
|
-
protoTypeName = `.${file.proto.package}.${proto.name}`;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
protoTypeName = `.${proto.name}`;
|
|
113
|
-
}
|
|
114
|
-
const values = [];
|
|
115
|
-
const enumT = {
|
|
116
|
-
proto,
|
|
117
|
-
file,
|
|
118
|
-
parent,
|
|
119
|
-
name: proto.name,
|
|
120
|
-
protoTypeName,
|
|
121
|
-
typeName: protoTypeName.startsWith(".")
|
|
122
|
-
? protoTypeName.substring(1)
|
|
123
|
-
: protoTypeName,
|
|
124
|
-
values,
|
|
125
|
-
toString() {
|
|
126
|
-
return `enum ${this.typeName}`;
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
us.enums[enumT.protoTypeName] = enumT;
|
|
130
|
-
for (const value of proto.value) {
|
|
131
|
-
values.push(newEnumValue(value, enumT));
|
|
132
|
-
}
|
|
133
|
-
return enumT;
|
|
134
|
-
}
|
|
135
|
-
function newEnumValue(proto, parent) {
|
|
136
|
-
assert(proto.name, `invalid descriptor: missing enum value descriptor name`);
|
|
137
|
-
assert(proto.number !== undefined, `invalid descriptor: missing enum value descriptor number`);
|
|
138
|
-
return {
|
|
139
|
-
proto,
|
|
140
|
-
name: proto.name,
|
|
141
|
-
number: proto.number,
|
|
142
|
-
parent,
|
|
143
|
-
toString() {
|
|
144
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
|
|
145
|
-
return `enum value ${this.parent.typeName}.${this.proto.name}`;
|
|
146
|
-
},
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
function newMessage(proto, parent, file, us) {
|
|
150
|
-
var _a;
|
|
151
|
-
assert(proto.name, `invalid descriptor: missing name`);
|
|
152
|
-
const nestedMessages = [];
|
|
153
|
-
const fields = [];
|
|
154
|
-
const oneofs = [];
|
|
155
|
-
const nestedEnums = [];
|
|
156
|
-
const nestedExtensions = [];
|
|
157
|
-
let protoTypeName;
|
|
158
|
-
if (parent) {
|
|
159
|
-
protoTypeName = `${parent.protoTypeName}.${proto.name}`;
|
|
160
|
-
}
|
|
161
|
-
else if (file.proto.package !== undefined) {
|
|
162
|
-
protoTypeName = `.${file.proto.package}.${proto.name}`;
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
protoTypeName = `.${proto.name}`;
|
|
166
|
-
}
|
|
167
|
-
const message = {
|
|
168
|
-
proto,
|
|
169
|
-
file,
|
|
170
|
-
parent,
|
|
171
|
-
name: proto.name,
|
|
172
|
-
typeName: protoTypeName.startsWith(".")
|
|
173
|
-
? protoTypeName.substring(1)
|
|
174
|
-
: protoTypeName,
|
|
175
|
-
protoTypeName,
|
|
176
|
-
fields,
|
|
177
|
-
oneofs,
|
|
178
|
-
nestedEnums,
|
|
179
|
-
nestedMessages,
|
|
180
|
-
nestedExtensions,
|
|
181
|
-
toString() {
|
|
182
|
-
return `message ${this.typeName}`;
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
us.messages[message.protoTypeName] = message;
|
|
186
|
-
for (const nestedType of proto.nestedType) {
|
|
187
|
-
nestedMessages.push(newMessage(nestedType, message, file, us));
|
|
188
|
-
}
|
|
189
|
-
for (const oneofDecl of proto.oneofDecl) {
|
|
190
|
-
oneofs.push(newOneof(oneofDecl, message, file));
|
|
191
|
-
}
|
|
192
|
-
for (const field of proto.field) {
|
|
193
|
-
let oneof = undefined;
|
|
194
|
-
if (field.oneofIndex !== undefined) {
|
|
195
|
-
oneof = oneofs[field.oneofIndex];
|
|
196
|
-
assert(oneof, `invalid descriptor: oneof declaration index ${field.oneofIndex} specified by field #${(_a = field.number) !== null && _a !== void 0 ? _a : -1} not found`);
|
|
197
|
-
}
|
|
198
|
-
fields.push(newField(field, message, oneof));
|
|
199
|
-
}
|
|
200
|
-
for (const enumType of proto.enumType) {
|
|
201
|
-
nestedEnums.push(newEnum(enumType, message, file, us));
|
|
202
|
-
}
|
|
203
|
-
for (const extension of proto.extension) {
|
|
204
|
-
nestedExtensions.push(newExtension(extension, message, file, us));
|
|
205
|
-
}
|
|
206
|
-
return message;
|
|
207
|
-
}
|
|
208
|
-
function newField(proto, parent, oneof) {
|
|
209
|
-
var _a;
|
|
210
|
-
assert(proto.name, `invalid descriptor: missing name`);
|
|
211
|
-
assert(proto.number, `invalid descriptor: missing number`);
|
|
212
|
-
assert(proto.type, `invalid descriptor: missing type`);
|
|
213
|
-
let optional = false;
|
|
214
|
-
let packed = ((_a = proto.options) === null || _a === void 0 ? void 0 : _a.packed) === true;
|
|
215
|
-
switch (parent.file.syntax) {
|
|
216
|
-
case "proto2":
|
|
217
|
-
optional =
|
|
218
|
-
oneof === undefined &&
|
|
219
|
-
proto.label === FieldDescriptorProto_Label.OPTIONAL;
|
|
220
|
-
break;
|
|
221
|
-
case "proto3":
|
|
222
|
-
optional = proto.proto3Optional === true;
|
|
223
|
-
switch (proto.type) {
|
|
224
|
-
case FieldDescriptorProto_Type.DOUBLE:
|
|
225
|
-
case FieldDescriptorProto_Type.FLOAT:
|
|
226
|
-
case FieldDescriptorProto_Type.INT64:
|
|
227
|
-
case FieldDescriptorProto_Type.UINT64:
|
|
228
|
-
case FieldDescriptorProto_Type.INT32:
|
|
229
|
-
case FieldDescriptorProto_Type.FIXED64:
|
|
230
|
-
case FieldDescriptorProto_Type.FIXED32:
|
|
231
|
-
case FieldDescriptorProto_Type.UINT32:
|
|
232
|
-
case FieldDescriptorProto_Type.SFIXED32:
|
|
233
|
-
case FieldDescriptorProto_Type.SFIXED64:
|
|
234
|
-
case FieldDescriptorProto_Type.SINT32:
|
|
235
|
-
case FieldDescriptorProto_Type.SINT64:
|
|
236
|
-
case FieldDescriptorProto_Type.BOOL:
|
|
237
|
-
case FieldDescriptorProto_Type.ENUM:
|
|
238
|
-
// From the proto3 language guide:
|
|
239
|
-
// > In proto3, repeated fields of scalar numeric types are packed by default.
|
|
240
|
-
// This information is incomplete - according to the conformance tests, BOOL
|
|
241
|
-
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
242
|
-
// are not packed by default, which makes sense because they are length-delimited.
|
|
243
|
-
packed = true;
|
|
244
|
-
break;
|
|
245
|
-
case FieldDescriptorProto_Type.STRING:
|
|
246
|
-
case FieldDescriptorProto_Type.GROUP:
|
|
247
|
-
case FieldDescriptorProto_Type.MESSAGE:
|
|
248
|
-
case FieldDescriptorProto_Type.BYTES:
|
|
249
|
-
assert(!packed, `invalid descriptor: ${FieldDescriptorProto_Type[proto.type]} cannot be packed`);
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
const field = {
|
|
255
|
-
proto,
|
|
256
|
-
name: proto.name,
|
|
257
|
-
number: proto.number,
|
|
258
|
-
type: proto.type,
|
|
259
|
-
parent,
|
|
260
|
-
oneof: proto.proto3Optional === true ? undefined : oneof,
|
|
261
|
-
optional,
|
|
262
|
-
packed,
|
|
263
|
-
toString() {
|
|
264
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
|
|
265
|
-
return `field ${parent.typeName}.${proto.name}`;
|
|
266
|
-
},
|
|
267
|
-
resolve(us) {
|
|
268
|
-
return resolveField(this, us);
|
|
269
|
-
},
|
|
270
|
-
};
|
|
271
|
-
if (oneof) {
|
|
272
|
-
oneof.fields.push(field);
|
|
273
|
-
}
|
|
274
|
-
return field;
|
|
275
|
-
}
|
|
276
|
-
function resolveField(u, us) {
|
|
277
|
-
var _a;
|
|
278
|
-
const repeated = u.proto.label === FieldDescriptorProto_Label.REPEATED;
|
|
279
|
-
switch (u.type) {
|
|
280
|
-
case FieldDescriptorProto_Type.MESSAGE:
|
|
281
|
-
case FieldDescriptorProto_Type.GROUP: {
|
|
282
|
-
assert(u.proto.typeName, `invalid descriptor: ${u.toString()} has type ${FieldDescriptorProto_Type[u.type]}, but type_name is unset`);
|
|
283
|
-
const refMessage = us.messages[u.proto.typeName];
|
|
284
|
-
assert(refMessage, `invalid descriptor: cannot find type_name "${u.proto.typeName}" specified by ${u.toString()}`);
|
|
285
|
-
if (((_a = refMessage.proto.options) === null || _a === void 0 ? void 0 : _a.mapEntry) !== undefined) {
|
|
286
|
-
return Object.assign(Object.assign({}, u), { repeated: false, scalarType: undefined, message: undefined, enum: undefined, map: resolveMap(refMessage, us) });
|
|
287
|
-
}
|
|
288
|
-
return Object.assign(Object.assign({}, u), { repeated, scalarType: undefined, message: refMessage, enum: undefined, map: undefined });
|
|
289
|
-
}
|
|
290
|
-
case FieldDescriptorProto_Type.ENUM: {
|
|
291
|
-
assert(u.proto.typeName, `invalid descriptor: ${u.toString()} has type ${FieldDescriptorProto_Type[u.type]}, but type_name is unset`);
|
|
292
|
-
const refEnum = us.enums[u.proto.typeName];
|
|
293
|
-
assert(refEnum, `invalid descriptor: cannot find type_name "${u.proto.typeName}" specified by ${u.toString()}`);
|
|
294
|
-
return Object.assign(Object.assign({}, u), { repeated, scalarType: undefined, message: undefined, enum: refEnum, map: undefined });
|
|
295
|
-
}
|
|
296
|
-
default: {
|
|
297
|
-
const scalarType = fieldTypeToScalarType[u.type];
|
|
298
|
-
assert(scalarType, `invalid descriptor: unable to convert google.protobuf.FieldDescriptorProto.Type ${FieldDescriptorProto_Type[u.type]} to ScalarType`);
|
|
299
|
-
return Object.assign(Object.assign({}, u), { repeated,
|
|
300
|
-
scalarType, message: undefined, enum: undefined, map: undefined });
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
function resolveMap(mapEntry, us) {
|
|
305
|
-
var _a;
|
|
306
|
-
assert((_a = mapEntry.proto.options) === null || _a === void 0 ? void 0 : _a.mapEntry, `invalid descriptor: expected ${mapEntry.toString()} to be a map entry`);
|
|
307
|
-
assert(mapEntry.fields.length === 2, `invalid descriptor: map entry ${mapEntry.toString()} has ${mapEntry.fields.length} fields`);
|
|
308
|
-
const uKeyField = mapEntry.fields.find((f) => f.proto.number === 1);
|
|
309
|
-
assert(uKeyField, `invalid descriptor: map entry ${mapEntry.toString()} is missing key field`);
|
|
310
|
-
const keyField = resolveField(uKeyField, us);
|
|
311
|
-
assert(keyField.scalarType !== undefined &&
|
|
312
|
-
keyField.scalarType !== ScalarType.BYTES &&
|
|
313
|
-
keyField.scalarType !== ScalarType.FLOAT &&
|
|
314
|
-
keyField.scalarType !== ScalarType.DOUBLE, `invalid descriptor: map entry ${mapEntry.toString()} has unexpected key type ${FieldDescriptorProto_Type[keyField.type]}`);
|
|
315
|
-
const uValueField = mapEntry.fields.find((f) => f.proto.number === 2);
|
|
316
|
-
assert(uValueField, `invalid descriptor: map entry ${mapEntry.toString()} is missing value field`);
|
|
317
|
-
const valueField = resolveField(uValueField, us);
|
|
318
|
-
if (valueField.scalarType !== undefined) {
|
|
319
|
-
return {
|
|
320
|
-
key: keyField.scalarType,
|
|
321
|
-
value: {
|
|
322
|
-
scalarType: valueField.scalarType,
|
|
323
|
-
enum: undefined,
|
|
324
|
-
message: undefined,
|
|
325
|
-
},
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
if (valueField.enum !== undefined) {
|
|
329
|
-
return {
|
|
330
|
-
key: keyField.scalarType,
|
|
331
|
-
value: { scalar: undefined, enum: valueField.enum, message: undefined },
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
if (valueField.message !== undefined) {
|
|
335
|
-
return {
|
|
336
|
-
key: keyField.scalarType,
|
|
337
|
-
value: {
|
|
338
|
-
scalar: undefined,
|
|
339
|
-
enum: undefined,
|
|
340
|
-
message: valueField.message,
|
|
341
|
-
},
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
throw new Error(`invalid descriptor: map entry ${mapEntry.toString()} has unexpected value type ${FieldDescriptorProto_Type[keyField.type]}`);
|
|
345
|
-
}
|
|
346
|
-
function newOneof(proto, parent, file) {
|
|
347
|
-
assert(proto.name, `invalid descriptor: missing oneof descriptor name`);
|
|
348
|
-
return {
|
|
349
|
-
proto,
|
|
350
|
-
parent,
|
|
351
|
-
file,
|
|
352
|
-
fields: [],
|
|
353
|
-
name: proto.name,
|
|
354
|
-
toString() {
|
|
355
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
|
|
356
|
-
return `oneof ${parent.typeName}.${proto.name}`;
|
|
357
|
-
},
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
function newExtension(proto, parent, file, us // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
361
|
-
) {
|
|
362
|
-
assert(proto.name, `invalid descriptor: missing field descriptor name`);
|
|
363
|
-
return {
|
|
364
|
-
proto,
|
|
365
|
-
file,
|
|
366
|
-
parent,
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
function newService(proto, file, us) {
|
|
370
|
-
assert(proto.name, `invalid descriptor: missing service descriptor name`);
|
|
371
|
-
let protoTypeName;
|
|
372
|
-
if (file.proto.package !== undefined) {
|
|
373
|
-
protoTypeName = `.${file.proto.package}.${proto.name}`;
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
protoTypeName = `.${proto.name}`;
|
|
377
|
-
}
|
|
378
|
-
const methods = [];
|
|
379
|
-
const service = {
|
|
380
|
-
proto,
|
|
381
|
-
file,
|
|
382
|
-
typeName: protoTypeName.startsWith(".")
|
|
383
|
-
? protoTypeName.substring(1)
|
|
384
|
-
: protoTypeName,
|
|
385
|
-
protoTypeName,
|
|
386
|
-
methods,
|
|
387
|
-
toString() {
|
|
388
|
-
return `service ${this.typeName}`;
|
|
389
|
-
},
|
|
390
|
-
};
|
|
391
|
-
for (const method of proto.method) {
|
|
392
|
-
methods.push(newMethod(method, service));
|
|
393
|
-
}
|
|
394
|
-
us.services[service.protoTypeName] = service;
|
|
395
|
-
return service;
|
|
396
|
-
}
|
|
397
|
-
function newMethod(proto, parent) {
|
|
398
|
-
var _a;
|
|
399
|
-
assert(proto.name, `invalid descriptor: missing method descriptor name`);
|
|
400
|
-
assert(proto.inputType, `invalid descriptor: missing method input type`);
|
|
401
|
-
assert(proto.outputType, `invalid descriptor: missing method output type`);
|
|
402
|
-
let kind;
|
|
403
|
-
if (proto.clientStreaming === true && proto.serverStreaming === true) {
|
|
404
|
-
kind = MethodKind.BiDiStreaming;
|
|
405
|
-
}
|
|
406
|
-
else if (proto.clientStreaming === true) {
|
|
407
|
-
kind = MethodKind.ClientStreaming;
|
|
408
|
-
}
|
|
409
|
-
else if (proto.serverStreaming === true) {
|
|
410
|
-
kind = MethodKind.ServerStreaming;
|
|
411
|
-
}
|
|
412
|
-
else {
|
|
413
|
-
kind = MethodKind.Unary;
|
|
414
|
-
}
|
|
415
|
-
let idempotency;
|
|
416
|
-
switch ((_a = proto.options) === null || _a === void 0 ? void 0 : _a.idempotencyLevel) {
|
|
417
|
-
case MethodOptions_IdempotencyLevel.IDEMPOTENT:
|
|
418
|
-
idempotency = MethodIdempotency.Idempotent;
|
|
419
|
-
break;
|
|
420
|
-
case MethodOptions_IdempotencyLevel.NO_SIDE_EFFECTS:
|
|
421
|
-
idempotency = MethodIdempotency.NoSideEffects;
|
|
422
|
-
break;
|
|
423
|
-
case MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN:
|
|
424
|
-
case undefined:
|
|
425
|
-
idempotency = undefined;
|
|
426
|
-
break;
|
|
427
|
-
}
|
|
428
|
-
const inputTypeName = proto.inputType.startsWith(".")
|
|
429
|
-
? proto.inputType.substring(1)
|
|
430
|
-
: proto.inputType;
|
|
431
|
-
const outputTypeName = proto.outputType.startsWith(".")
|
|
432
|
-
? proto.outputType.substring(1)
|
|
433
|
-
: proto.outputType;
|
|
434
|
-
return {
|
|
435
|
-
proto,
|
|
436
|
-
parent,
|
|
437
|
-
name: proto.name,
|
|
438
|
-
kind,
|
|
439
|
-
idempotency,
|
|
440
|
-
inputTypeName,
|
|
441
|
-
outputTypeName,
|
|
442
|
-
toString() {
|
|
443
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- we asserted above
|
|
444
|
-
return `rpc ${this.parent.typeName}.${proto.name}`;
|
|
445
|
-
},
|
|
446
|
-
};
|
|
447
|
-
}
|
|
14
|
+
export {};
|
|
@@ -1144,8 +1144,8 @@ UninterpretedOption.fields = proto2.util.newFieldList(() => [
|
|
|
1144
1144
|
* The name of the uninterpreted option. Each string represents a segment in
|
|
1145
1145
|
* a dot-separated name. is_extension is true iff a segment represents an
|
|
1146
1146
|
* extension (denoted with parentheses in options specs in .proto files).
|
|
1147
|
-
* E.g.,{ ["foo", false], ["bar.baz", true], ["
|
|
1148
|
-
* "foo.(bar.baz).
|
|
1147
|
+
* E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents
|
|
1148
|
+
* "foo.(bar.baz).moo".
|
|
1149
1149
|
*
|
|
1150
1150
|
* @generated from message google.protobuf.UninterpretedOption.NamePart
|
|
1151
1151
|
*/
|
|
@@ -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.0
|
|
14
|
+
// @generated by protoc-gen-es v0.1.0 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.0
|
|
14
|
+
// @generated by protoc-gen-es v0.1.0 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";
|
|
@@ -107,22 +107,20 @@ export function varint64write(lo, hi, bytes) {
|
|
|
107
107
|
bytes.push((hi >>> 31) & 0x01);
|
|
108
108
|
}
|
|
109
109
|
// constants for binary math
|
|
110
|
-
const TWO_PWR_32_DBL =
|
|
110
|
+
const TWO_PWR_32_DBL = 0x100000000;
|
|
111
111
|
/**
|
|
112
112
|
* Parse decimal string of 64 bit integer value as two JS numbers.
|
|
113
113
|
*
|
|
114
|
-
*
|
|
115
|
-
* [0]: minus sign?
|
|
116
|
-
* [1]: low bits
|
|
117
|
-
* [2]: high bits
|
|
114
|
+
* Copyright 2008 Google Inc. All rights reserved.
|
|
118
115
|
*
|
|
119
|
-
*
|
|
116
|
+
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
|
|
120
117
|
*/
|
|
121
|
-
export function
|
|
118
|
+
export function int64FromString(dec) {
|
|
122
119
|
// Check for minus sign.
|
|
123
|
-
|
|
124
|
-
if (minus)
|
|
120
|
+
const minus = dec[0] === "-";
|
|
121
|
+
if (minus) {
|
|
125
122
|
dec = dec.slice(1);
|
|
123
|
+
}
|
|
126
124
|
// Work 6 decimal digits at a time, acting like we're converting base 1e6
|
|
127
125
|
// digits to binary. This is safe to do with floating point math because
|
|
128
126
|
// Number.isSafeInteger(ALL_32_BITS * 1e6) == true.
|
|
@@ -144,18 +142,45 @@ export function int64fromString(dec) {
|
|
|
144
142
|
add1e6digit(-18, -12);
|
|
145
143
|
add1e6digit(-12, -6);
|
|
146
144
|
add1e6digit(-6);
|
|
147
|
-
return
|
|
145
|
+
return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits);
|
|
148
146
|
}
|
|
149
147
|
/**
|
|
150
|
-
*
|
|
148
|
+
* Losslessly converts a 64-bit signed integer in 32:32 split representation
|
|
149
|
+
* into a decimal string.
|
|
150
|
+
*
|
|
151
|
+
* Copyright 2008 Google Inc. All rights reserved.
|
|
152
|
+
*
|
|
153
|
+
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
|
|
154
|
+
*/
|
|
155
|
+
export function int64ToString(lo, hi) {
|
|
156
|
+
let bits = newBits(lo, hi);
|
|
157
|
+
// If we're treating the input as a signed value and the high bit is set, do
|
|
158
|
+
// a manual two's complement conversion before the decimal conversion.
|
|
159
|
+
const negative = (bits.hi & 0x80000000);
|
|
160
|
+
if (negative) {
|
|
161
|
+
bits = negate(bits.lo, bits.hi);
|
|
162
|
+
}
|
|
163
|
+
const result = uInt64ToString(bits.lo, bits.hi);
|
|
164
|
+
return negative ? "-" + result : result;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Losslessly converts a 64-bit unsigned integer in 32:32 split representation
|
|
168
|
+
* into a decimal string.
|
|
169
|
+
*
|
|
170
|
+
* Copyright 2008 Google Inc. All rights reserved.
|
|
151
171
|
*
|
|
152
|
-
*
|
|
172
|
+
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
|
|
153
173
|
*/
|
|
154
|
-
export function
|
|
174
|
+
export function uInt64ToString(lo, hi) {
|
|
175
|
+
({ lo, hi } = toUnsigned(lo, hi));
|
|
155
176
|
// Skip the expensive conversion if the number is small enough to use the
|
|
156
177
|
// built-in conversions.
|
|
157
|
-
|
|
158
|
-
|
|
178
|
+
// Number.MAX_SAFE_INTEGER = 0x001FFFFF FFFFFFFF, thus any number with
|
|
179
|
+
// highBits <= 0x1FFFFF can be safely expressed with a double and retain
|
|
180
|
+
// integer precision.
|
|
181
|
+
// Proven by: Number.isSafeInteger(0x1FFFFF * 2**32 + 0xFFFFFFFF) == true.
|
|
182
|
+
if (hi <= 0x1FFFFF) {
|
|
183
|
+
return String(TWO_PWR_32_DBL * hi + lo);
|
|
159
184
|
}
|
|
160
185
|
// What this code is doing is essentially converting the input number from
|
|
161
186
|
// base-2 to base-1e7, which allows us to represent the 64-bit range with
|
|
@@ -166,17 +191,17 @@ export function int64toString(bitsLow, bitsHigh) {
|
|
|
166
191
|
// 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7.
|
|
167
192
|
// Split 32:32 representation into 16:24:24 representation so our
|
|
168
193
|
// intermediate digits don't overflow.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
194
|
+
const low = lo & 0xFFFFFF;
|
|
195
|
+
const mid = ((lo >>> 24) | (hi << 8)) & 0xFFFFFF;
|
|
196
|
+
const high = (hi >> 16) & 0xFFFF;
|
|
172
197
|
// Assemble our three base-1e7 digits, ignoring carries. The maximum
|
|
173
198
|
// value in a digit at this step is representable as a 48-bit integer, which
|
|
174
199
|
// can be stored in a 64-bit floating point number.
|
|
175
|
-
let digitA = low + mid * 6777216 + high * 6710656;
|
|
176
|
-
let digitB = mid + high * 8147497;
|
|
177
|
-
let digitC = high * 2;
|
|
200
|
+
let digitA = low + (mid * 6777216) + (high * 6710656);
|
|
201
|
+
let digitB = mid + (high * 8147497);
|
|
202
|
+
let digitC = (high * 2);
|
|
178
203
|
// Apply carries from A to B and from B to C.
|
|
179
|
-
|
|
204
|
+
const base = 10000000;
|
|
180
205
|
if (digitA >= base) {
|
|
181
206
|
digitB += Math.floor(digitA / base);
|
|
182
207
|
digitA %= base;
|
|
@@ -185,20 +210,42 @@ export function int64toString(bitsLow, bitsHigh) {
|
|
|
185
210
|
digitC += Math.floor(digitB / base);
|
|
186
211
|
digitB %= base;
|
|
187
212
|
}
|
|
188
|
-
//
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
213
|
+
// If digitC is 0, then we should have returned in the trivial code path
|
|
214
|
+
// at the top for non-safe integers. Given this, we can assume both digitB
|
|
215
|
+
// and digitA need leading zeros.
|
|
216
|
+
return digitC.toString() + decimalFrom1e7WithLeadingZeros(digitB) +
|
|
217
|
+
decimalFrom1e7WithLeadingZeros(digitA);
|
|
218
|
+
}
|
|
219
|
+
function toUnsigned(lo, hi) {
|
|
220
|
+
return { lo: lo >>> 0, hi: hi >>> 0 };
|
|
221
|
+
}
|
|
222
|
+
function newBits(lo, hi) {
|
|
223
|
+
return { lo: lo | 0, hi: hi | 0 };
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Returns two's compliment negation of input.
|
|
227
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Signed_32-bit_integers
|
|
228
|
+
*/
|
|
229
|
+
function negate(lowBits, highBits) {
|
|
230
|
+
highBits = ~highBits;
|
|
231
|
+
if (lowBits) {
|
|
232
|
+
lowBits = ~lowBits + 1;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
// If lowBits is 0, then bitwise-not is 0xFFFFFFFF,
|
|
236
|
+
// adding 1 to that, results in 0x100000000, which leaves
|
|
237
|
+
// the low bits 0x0 and simply adds one to the high bits.
|
|
238
|
+
highBits += 1;
|
|
195
239
|
}
|
|
196
|
-
return (
|
|
197
|
-
decimalFrom1e7(digitB, /*needLeadingZeros=*/ digitC) +
|
|
198
|
-
// If the final 1e7 digit didn't need leading zeros, we would have
|
|
199
|
-
// returned via the trivial code path at the top.
|
|
200
|
-
decimalFrom1e7(digitA, /*needLeadingZeros=*/ 1));
|
|
240
|
+
return newBits(lowBits, highBits);
|
|
201
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Returns decimal representation of digit1e7 with leading zeros.
|
|
244
|
+
*/
|
|
245
|
+
const decimalFrom1e7WithLeadingZeros = (digit1e7) => {
|
|
246
|
+
const partial = String(digit1e7);
|
|
247
|
+
return "0000000".slice(partial.length) + partial;
|
|
248
|
+
};
|
|
202
249
|
/**
|
|
203
250
|
* Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`
|
|
204
251
|
*
|
package/dist/esm/index.js
CHANGED
|
@@ -15,14 +15,17 @@ export { proto3 } from "./proto3.js";
|
|
|
15
15
|
export { proto2 } from "./proto2.js";
|
|
16
16
|
export { protoInt64 } from "./proto-int64.js";
|
|
17
17
|
export { protoBase64 } from "./proto-base64.js";
|
|
18
|
+
export { codegenInfo } from "./codegen-info.js";
|
|
18
19
|
export { Message, } from "./message.js";
|
|
19
20
|
export { ScalarType } from "./field.js";
|
|
20
21
|
export { MethodKind, MethodIdempotency } from "./service-type.js";
|
|
21
|
-
export { TypeRegistry } from "./type-registry.js";
|
|
22
|
-
export { DescriptorRegistry } from "./descriptor-registry.js";
|
|
23
|
-
export { DescriptorSet } from "./descriptor-set.js";
|
|
24
22
|
export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
|
|
25
23
|
export {} from "./json-format.js";
|
|
24
|
+
export {} from "./descriptor-set.js";
|
|
25
|
+
export { createDescriptorSet } from "./create-descriptor-set.js";
|
|
26
|
+
export {} from "./type-registry.js";
|
|
27
|
+
export { createRegistry } from "./create-registry.js";
|
|
28
|
+
export { createRegistryFromDescriptors } from "./create-registry-from-desc.js";
|
|
26
29
|
// ideally, we would export these types with sub-path exports:
|
|
27
30
|
export * from "./google/protobuf/compiler/plugin_pb.js";
|
|
28
31
|
export * from "./google/protobuf/api_pb.js";
|