@bufbuild/protobuf 0.0.6 → 0.0.7
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/binary-encoding.js +2 -2
- package/dist/cjs/descriptor-registry.js +18 -60
- package/dist/cjs/descriptor-set.js +15 -37
- 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/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 +1 -1
- package/dist/cjs/private/json-format-common.js +6 -5
- package/dist/cjs/private/message-type.js +2 -1
- package/dist/cjs/proto-int64.js +1 -1
- package/dist/cjs/proto2.js +6 -8
- package/dist/cjs/proto3.js +9 -12
- package/dist/esm/binary-encoding.js +2 -2
- package/dist/esm/descriptor-registry.js +18 -60
- package/dist/esm/descriptor-set.js +15 -37
- 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/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 +1 -1
- package/dist/esm/private/json-format-common.js +6 -5
- package/dist/esm/private/message-type.js +2 -1
- package/dist/esm/proto-int64.js +1 -1
- package/dist/esm/proto2.js +6 -8
- package/dist/esm/proto3.js +9 -12
- package/package.json +2 -2
|
@@ -67,7 +67,7 @@ class BinaryWriter {
|
|
|
67
67
|
* Previous fork states.
|
|
68
68
|
*/
|
|
69
69
|
this.stack = [];
|
|
70
|
-
this.textEncoder = textEncoder
|
|
70
|
+
this.textEncoder = textEncoder !== null && textEncoder !== void 0 ? textEncoder : new TextEncoder();
|
|
71
71
|
this.chunks = [];
|
|
72
72
|
this.buf = [];
|
|
73
73
|
}
|
|
@@ -283,7 +283,7 @@ class BinaryReader {
|
|
|
283
283
|
this.len = buf.length;
|
|
284
284
|
this.pos = 0;
|
|
285
285
|
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
286
|
-
this.textDecoder = textDecoder
|
|
286
|
+
this.textDecoder = textDecoder !== null && textDecoder !== void 0 ? textDecoder : new TextDecoder();
|
|
287
287
|
}
|
|
288
288
|
/**
|
|
289
289
|
* Reads a tag - field number and wire type.
|
|
@@ -65,7 +65,7 @@ class DescriptorRegistry {
|
|
|
65
65
|
this.enums = {};
|
|
66
66
|
this.messages = {};
|
|
67
67
|
this.services = {};
|
|
68
|
-
this.ds = descriptorSet
|
|
68
|
+
this.ds = descriptorSet !== null && descriptorSet !== void 0 ? descriptorSet : new descriptor_set_js_1.DescriptorSet();
|
|
69
69
|
if (replaceWkt) {
|
|
70
70
|
for (const mt of wkMessages) {
|
|
71
71
|
this.messages["." + mt.typeName] = mt;
|
|
@@ -177,8 +177,9 @@ class DescriptorRegistry {
|
|
|
177
177
|
}
|
|
178
178
|
exports.DescriptorRegistry = DescriptorRegistry;
|
|
179
179
|
function makeTypeLocalName(type) {
|
|
180
|
+
var _a;
|
|
180
181
|
const typeName = type.typeName;
|
|
181
|
-
const packagePrefix = (type.file.proto.package
|
|
182
|
+
const packagePrefix = ((_a = type.file.proto.package) !== null && _a !== void 0 ? _a : "") + ".";
|
|
182
183
|
if (!typeName.startsWith(packagePrefix)) {
|
|
183
184
|
return type.name;
|
|
184
185
|
}
|
|
@@ -207,32 +208,23 @@ function makeMapFieldInfo(field, resolver) {
|
|
|
207
208
|
if (field.map.value.message) {
|
|
208
209
|
const messageType = resolver.findMessage(field.map.value.message.typeName);
|
|
209
210
|
(0, assert_js_1.assert)(messageType, `message "${field.map.value.message.typeName}" for ${field.toString()} not found`);
|
|
210
|
-
return {
|
|
211
|
-
...base,
|
|
212
|
-
V: {
|
|
211
|
+
return Object.assign(Object.assign({}, base), { V: {
|
|
213
212
|
kind: "message",
|
|
214
213
|
T: messageType,
|
|
215
|
-
}
|
|
216
|
-
};
|
|
214
|
+
} });
|
|
217
215
|
}
|
|
218
216
|
if (field.map.value.enum) {
|
|
219
217
|
const enumType = resolver.findEnum(field.map.value.enum.typeName);
|
|
220
218
|
(0, assert_js_1.assert)(enumType, `enum "${field.map.value.enum.typeName}" for ${field.toString()} not found`);
|
|
221
|
-
return {
|
|
222
|
-
...base,
|
|
223
|
-
V: {
|
|
219
|
+
return Object.assign(Object.assign({}, base), { V: {
|
|
224
220
|
kind: "enum",
|
|
225
221
|
T: enumType,
|
|
226
|
-
}
|
|
227
|
-
};
|
|
222
|
+
} });
|
|
228
223
|
}
|
|
229
|
-
return {
|
|
230
|
-
...base,
|
|
231
|
-
V: {
|
|
224
|
+
return Object.assign(Object.assign({}, base), { V: {
|
|
232
225
|
kind: "scalar",
|
|
233
226
|
T: field.map.value.scalarType,
|
|
234
|
-
}
|
|
235
|
-
};
|
|
227
|
+
} });
|
|
236
228
|
}
|
|
237
229
|
function makeScalarFieldInfo(field) {
|
|
238
230
|
const base = {
|
|
@@ -242,25 +234,13 @@ function makeScalarFieldInfo(field) {
|
|
|
242
234
|
T: field.scalarType,
|
|
243
235
|
};
|
|
244
236
|
if (field.repeated) {
|
|
245
|
-
return {
|
|
246
|
-
...base,
|
|
247
|
-
repeated: true,
|
|
248
|
-
packed: field.packed,
|
|
249
|
-
oneof: undefined,
|
|
250
|
-
T: field.scalarType,
|
|
251
|
-
};
|
|
237
|
+
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined, T: field.scalarType });
|
|
252
238
|
}
|
|
253
239
|
if (field.oneof) {
|
|
254
|
-
return {
|
|
255
|
-
...base,
|
|
256
|
-
oneof: field.oneof.name,
|
|
257
|
-
};
|
|
240
|
+
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
258
241
|
}
|
|
259
242
|
if (field.optional) {
|
|
260
|
-
return {
|
|
261
|
-
...base,
|
|
262
|
-
opt: true,
|
|
263
|
-
};
|
|
243
|
+
return Object.assign(Object.assign({}, base), { opt: true });
|
|
264
244
|
}
|
|
265
245
|
return base;
|
|
266
246
|
}
|
|
@@ -274,24 +254,13 @@ function makeMessageFieldInfo(field, resolver) {
|
|
|
274
254
|
T: messageType,
|
|
275
255
|
};
|
|
276
256
|
if (field.repeated) {
|
|
277
|
-
return {
|
|
278
|
-
...base,
|
|
279
|
-
repeated: true,
|
|
280
|
-
packed: field.packed,
|
|
281
|
-
oneof: undefined,
|
|
282
|
-
};
|
|
257
|
+
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
|
283
258
|
}
|
|
284
259
|
if (field.oneof) {
|
|
285
|
-
return {
|
|
286
|
-
...base,
|
|
287
|
-
oneof: field.oneof.name,
|
|
288
|
-
};
|
|
260
|
+
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
289
261
|
}
|
|
290
262
|
if (field.optional) {
|
|
291
|
-
return {
|
|
292
|
-
...base,
|
|
293
|
-
opt: true,
|
|
294
|
-
};
|
|
263
|
+
return Object.assign(Object.assign({}, base), { opt: true });
|
|
295
264
|
}
|
|
296
265
|
return base;
|
|
297
266
|
}
|
|
@@ -305,24 +274,13 @@ function makeEnumFieldInfo(field, resolver) {
|
|
|
305
274
|
T: enumType,
|
|
306
275
|
};
|
|
307
276
|
if (field.repeated) {
|
|
308
|
-
return {
|
|
309
|
-
...base,
|
|
310
|
-
repeated: true,
|
|
311
|
-
packed: field.packed,
|
|
312
|
-
oneof: undefined,
|
|
313
|
-
};
|
|
277
|
+
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
|
314
278
|
}
|
|
315
279
|
if (field.oneof) {
|
|
316
|
-
return {
|
|
317
|
-
...base,
|
|
318
|
-
oneof: field.oneof.name,
|
|
319
|
-
};
|
|
280
|
+
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
320
281
|
}
|
|
321
282
|
if (field.optional) {
|
|
322
|
-
return {
|
|
323
|
-
...base,
|
|
324
|
-
opt: true,
|
|
325
|
-
};
|
|
283
|
+
return Object.assign(Object.assign({}, base), { opt: true });
|
|
326
284
|
}
|
|
327
285
|
return base;
|
|
328
286
|
}
|
|
@@ -151,6 +151,7 @@ function newEnumValue(proto, parent) {
|
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
153
|
function newMessage(proto, parent, file, us) {
|
|
154
|
+
var _a;
|
|
154
155
|
(0, assert_js_1.assert)(proto.name, `invalid descriptor: missing name`);
|
|
155
156
|
const nestedMessages = [];
|
|
156
157
|
const fields = [];
|
|
@@ -196,7 +197,7 @@ function newMessage(proto, parent, file, us) {
|
|
|
196
197
|
let oneof = undefined;
|
|
197
198
|
if (field.oneofIndex !== undefined) {
|
|
198
199
|
oneof = oneofs[field.oneofIndex];
|
|
199
|
-
(0, assert_js_1.assert)(oneof, `invalid descriptor: oneof declaration index ${field.oneofIndex} specified by field #${field.number
|
|
200
|
+
(0, assert_js_1.assert)(oneof, `invalid descriptor: oneof declaration index ${field.oneofIndex} specified by field #${(_a = field.number) !== null && _a !== void 0 ? _a : -1} not found`);
|
|
200
201
|
}
|
|
201
202
|
fields.push(newField(field, message, oneof));
|
|
202
203
|
}
|
|
@@ -209,11 +210,12 @@ function newMessage(proto, parent, file, us) {
|
|
|
209
210
|
return message;
|
|
210
211
|
}
|
|
211
212
|
function newField(proto, parent, oneof) {
|
|
213
|
+
var _a;
|
|
212
214
|
(0, assert_js_1.assert)(proto.name, `invalid descriptor: missing name`);
|
|
213
215
|
(0, assert_js_1.assert)(proto.number, `invalid descriptor: missing number`);
|
|
214
216
|
(0, assert_js_1.assert)(proto.type, `invalid descriptor: missing type`);
|
|
215
217
|
let optional = false;
|
|
216
|
-
let packed = proto.options
|
|
218
|
+
let packed = ((_a = proto.options) === null || _a === void 0 ? void 0 : _a.packed) === true;
|
|
217
219
|
switch (parent.file.syntax) {
|
|
218
220
|
case "proto2":
|
|
219
221
|
optional =
|
|
@@ -276,6 +278,7 @@ function newField(proto, parent, oneof) {
|
|
|
276
278
|
return field;
|
|
277
279
|
}
|
|
278
280
|
function resolveField(u, us) {
|
|
281
|
+
var _a;
|
|
279
282
|
const repeated = u.proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.REPEATED;
|
|
280
283
|
switch (u.type) {
|
|
281
284
|
case descriptor_pb_js_1.FieldDescriptorProto_Type.MESSAGE:
|
|
@@ -283,54 +286,28 @@ function resolveField(u, us) {
|
|
|
283
286
|
(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
287
|
const refMessage = us.messages[u.proto.typeName];
|
|
285
288
|
(0, assert_js_1.assert)(refMessage, `invalid descriptor: cannot find type_name "${u.proto.typeName}" specified by ${u.toString()}`);
|
|
286
|
-
if (refMessage.proto.options
|
|
287
|
-
return {
|
|
288
|
-
...u,
|
|
289
|
-
repeated: false,
|
|
290
|
-
scalarType: undefined,
|
|
291
|
-
message: undefined,
|
|
292
|
-
enum: undefined,
|
|
293
|
-
map: resolveMap(refMessage, us),
|
|
294
|
-
};
|
|
289
|
+
if (((_a = refMessage.proto.options) === null || _a === void 0 ? void 0 : _a.mapEntry) !== undefined) {
|
|
290
|
+
return Object.assign(Object.assign({}, u), { repeated: false, scalarType: undefined, message: undefined, enum: undefined, map: resolveMap(refMessage, us) });
|
|
295
291
|
}
|
|
296
|
-
return {
|
|
297
|
-
...u,
|
|
298
|
-
repeated,
|
|
299
|
-
scalarType: undefined,
|
|
300
|
-
message: refMessage,
|
|
301
|
-
enum: undefined,
|
|
302
|
-
map: undefined,
|
|
303
|
-
};
|
|
292
|
+
return Object.assign(Object.assign({}, u), { repeated, scalarType: undefined, message: refMessage, enum: undefined, map: undefined });
|
|
304
293
|
}
|
|
305
294
|
case descriptor_pb_js_1.FieldDescriptorProto_Type.ENUM: {
|
|
306
295
|
(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
296
|
const refEnum = us.enums[u.proto.typeName];
|
|
308
297
|
(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
|
-
};
|
|
298
|
+
return Object.assign(Object.assign({}, u), { repeated, scalarType: undefined, message: undefined, enum: refEnum, map: undefined });
|
|
317
299
|
}
|
|
318
300
|
default: {
|
|
319
301
|
const scalarType = fieldTypeToScalarType[u.type];
|
|
320
302
|
(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
|
-
|
|
323
|
-
repeated,
|
|
324
|
-
scalarType,
|
|
325
|
-
message: undefined,
|
|
326
|
-
enum: undefined,
|
|
327
|
-
map: undefined,
|
|
328
|
-
};
|
|
303
|
+
return Object.assign(Object.assign({}, u), { repeated,
|
|
304
|
+
scalarType, message: undefined, enum: undefined, map: undefined });
|
|
329
305
|
}
|
|
330
306
|
}
|
|
331
307
|
}
|
|
332
308
|
function resolveMap(mapEntry, us) {
|
|
333
|
-
|
|
309
|
+
var _a;
|
|
310
|
+
(0, assert_js_1.assert)((_a = mapEntry.proto.options) === null || _a === void 0 ? void 0 : _a.mapEntry, `invalid descriptor: expected ${mapEntry.toString()} to be a map entry`);
|
|
334
311
|
(0, assert_js_1.assert)(mapEntry.fields.length === 2, `invalid descriptor: map entry ${mapEntry.toString()} has ${mapEntry.fields.length} fields`);
|
|
335
312
|
const uKeyField = mapEntry.fields.find((f) => f.proto.number === 1);
|
|
336
313
|
(0, assert_js_1.assert)(uKeyField, `invalid descriptor: map entry ${mapEntry.toString()} is missing key field`);
|
|
@@ -422,6 +399,7 @@ function newService(proto, file, us) {
|
|
|
422
399
|
return service;
|
|
423
400
|
}
|
|
424
401
|
function newMethod(proto, parent) {
|
|
402
|
+
var _a;
|
|
425
403
|
(0, assert_js_1.assert)(proto.name, `invalid descriptor: missing method descriptor name`);
|
|
426
404
|
(0, assert_js_1.assert)(proto.inputType, `invalid descriptor: missing method input type`);
|
|
427
405
|
(0, assert_js_1.assert)(proto.outputType, `invalid descriptor: missing method output type`);
|
|
@@ -439,7 +417,7 @@ function newMethod(proto, parent) {
|
|
|
439
417
|
kind = service_type_js_1.MethodKind.Unary;
|
|
440
418
|
}
|
|
441
419
|
let idempotency;
|
|
442
|
-
switch (proto.options
|
|
420
|
+
switch ((_a = proto.options) === null || _a === void 0 ? void 0 : _a.idempotencyLevel) {
|
|
443
421
|
case descriptor_pb_js_1.MethodOptions_IdempotencyLevel.IDEMPOTENT:
|
|
444
422
|
idempotency = service_type_js_1.MethodIdempotency.Idempotent;
|
|
445
423
|
break;
|
|
@@ -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.7 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.7 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/message.js
CHANGED
|
@@ -84,8 +84,9 @@ class Message {
|
|
|
84
84
|
* Serialize the message to a JSON string.
|
|
85
85
|
*/
|
|
86
86
|
toJsonString(options) {
|
|
87
|
+
var _a;
|
|
87
88
|
const value = this.toJson(options);
|
|
88
|
-
return JSON.stringify(value, null, options
|
|
89
|
+
return JSON.stringify(value, null, (_a = options === null || options === void 0 ? void 0 : options.prettySpaces) !== null && _a !== void 0 ? _a : 0);
|
|
89
90
|
}
|
|
90
91
|
/**
|
|
91
92
|
* Retrieve the MessageType of this message - a singleton that represents
|
|
@@ -32,17 +32,18 @@ const writeDefaults = {
|
|
|
32
32
|
writerFactory: () => new binary_encoding_js_1.BinaryWriter(),
|
|
33
33
|
};
|
|
34
34
|
function makeReadOptions(options) {
|
|
35
|
-
return options ? {
|
|
35
|
+
return options ? Object.assign(Object.assign({}, readDefaults), options) : readDefaults;
|
|
36
36
|
}
|
|
37
37
|
function makeWriteOptions(options) {
|
|
38
|
-
return options ? {
|
|
38
|
+
return options ? Object.assign(Object.assign({}, writeDefaults), options) : writeDefaults;
|
|
39
39
|
}
|
|
40
40
|
function makeBinaryFormatCommon() {
|
|
41
41
|
return {
|
|
42
42
|
makeReadOptions,
|
|
43
43
|
makeWriteOptions,
|
|
44
44
|
listUnknownFields(message) {
|
|
45
|
-
|
|
45
|
+
var _a;
|
|
46
|
+
return (_a = message[unknownFieldsSymbol]) !== null && _a !== void 0 ? _a : [];
|
|
46
47
|
},
|
|
47
48
|
discardUnknownFields(message) {
|
|
48
49
|
delete message[unknownFieldsSymbol];
|
|
@@ -18,9 +18,7 @@ const field_js_1 = require("../field.js");
|
|
|
18
18
|
const binary_format_common_js_1 = require("./binary-format-common.js");
|
|
19
19
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions, no-case-declarations, prefer-const */
|
|
20
20
|
function makeBinaryFormatProto2() {
|
|
21
|
-
return {
|
|
22
|
-
...(0, binary_format_common_js_1.makeBinaryFormatCommon)(),
|
|
23
|
-
writeMessage(message, writer, options) {
|
|
21
|
+
return Object.assign(Object.assign({}, (0, binary_format_common_js_1.makeBinaryFormatCommon)()), { writeMessage(message, writer, options) {
|
|
24
22
|
const type = message.getType();
|
|
25
23
|
let field;
|
|
26
24
|
try {
|
|
@@ -84,7 +82,7 @@ function makeBinaryFormatProto2() {
|
|
|
84
82
|
}
|
|
85
83
|
catch (e) {
|
|
86
84
|
let m = field
|
|
87
|
-
? `cannot encode field ${type.typeName}.${field
|
|
85
|
+
? `cannot encode field ${type.typeName}.${field === null || field === void 0 ? void 0 : field.name} to binary`
|
|
88
86
|
: `cannot encode message ${type.typeName} to binary`;
|
|
89
87
|
let r = e instanceof Error ? e.message : String(e);
|
|
90
88
|
throw new Error(m + (r.length > 0 ? `: ${r}` : ""));
|
|
@@ -93,7 +91,6 @@ function makeBinaryFormatProto2() {
|
|
|
93
91
|
this.writeUnknownFields(message, writer);
|
|
94
92
|
}
|
|
95
93
|
return writer;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
94
|
+
} });
|
|
98
95
|
}
|
|
99
96
|
exports.makeBinaryFormatProto2 = makeBinaryFormatProto2;
|
|
@@ -18,9 +18,7 @@ const field_js_1 = require("../field.js");
|
|
|
18
18
|
const binary_format_common_js_1 = require("./binary-format-common.js");
|
|
19
19
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions, prefer-const, no-case-declarations */
|
|
20
20
|
function makeBinaryFormatProto3() {
|
|
21
|
-
return {
|
|
22
|
-
...(0, binary_format_common_js_1.makeBinaryFormatCommon)(),
|
|
23
|
-
writeMessage(message, writer, options) {
|
|
21
|
+
return Object.assign(Object.assign({}, (0, binary_format_common_js_1.makeBinaryFormatCommon)()), { writeMessage(message, writer, options) {
|
|
24
22
|
const type = message.getType();
|
|
25
23
|
for (const field of type.fields.byNumber()) {
|
|
26
24
|
let value, // this will be our field value, whether it is member of a oneof or regular field
|
|
@@ -76,7 +74,6 @@ function makeBinaryFormatProto3() {
|
|
|
76
74
|
this.writeUnknownFields(message, writer);
|
|
77
75
|
}
|
|
78
76
|
return writer;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
77
|
+
} });
|
|
81
78
|
}
|
|
82
79
|
exports.makeBinaryFormatProto3 = makeBinaryFormatProto3;
|
package/dist/cjs/private/enum.js
CHANGED
|
@@ -82,7 +82,7 @@ exports.makeEnumType = makeEnumType;
|
|
|
82
82
|
function makeEnum(typeName, values, opt) {
|
|
83
83
|
const enumObject = {};
|
|
84
84
|
for (const value of values) {
|
|
85
|
-
const name = makeEnumValueName(value, opt
|
|
85
|
+
const name = makeEnumValueName(value, opt === null || opt === void 0 ? void 0 : opt.sharedPrefix);
|
|
86
86
|
enumObject[name] = value.no;
|
|
87
87
|
enumObject[value.no] = name;
|
|
88
88
|
}
|
|
@@ -32,10 +32,10 @@ const jsonWriteDefaults = {
|
|
|
32
32
|
prettySpaces: 0,
|
|
33
33
|
};
|
|
34
34
|
function makeReadOptions(options) {
|
|
35
|
-
return options ? {
|
|
35
|
+
return options ? Object.assign(Object.assign({}, jsonReadDefaults), options) : jsonReadDefaults;
|
|
36
36
|
}
|
|
37
37
|
function makeWriteOptions(options) {
|
|
38
|
-
return options ? {
|
|
38
|
+
return options ? Object.assign(Object.assign({}, jsonWriteDefaults), options) : jsonWriteDefaults;
|
|
39
39
|
}
|
|
40
40
|
function makeJsonFormatCommon(makeWriteField) {
|
|
41
41
|
const writeField = makeWriteField(writeEnum, writeScalar);
|
|
@@ -46,7 +46,7 @@ function makeJsonFormatCommon(makeWriteField) {
|
|
|
46
46
|
if (json == null || Array.isArray(json) || typeof json != "object") {
|
|
47
47
|
throw new Error(`cannot decode message ${type.typeName} from JSON: ${this.debug(json)}`);
|
|
48
48
|
}
|
|
49
|
-
message = message
|
|
49
|
+
message = message !== null && message !== void 0 ? message : new type();
|
|
50
50
|
const oneofSeen = {};
|
|
51
51
|
for (const [jsonKey, jsonValue] of Object.entries(json)) {
|
|
52
52
|
const field = type.fields.findJsonName(jsonKey);
|
|
@@ -386,13 +386,14 @@ function readEnum(type, json, ignoreUnknownFields) {
|
|
|
386
386
|
case "string":
|
|
387
387
|
const value = type.findName(json);
|
|
388
388
|
if (value || ignoreUnknownFields) {
|
|
389
|
-
return value
|
|
389
|
+
return value === null || value === void 0 ? void 0 : value.no;
|
|
390
390
|
}
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
393
|
throw new Error(`cannot decode enum ${type.typeName} from JSON: ${debugJsonValue(json)}`);
|
|
394
394
|
}
|
|
395
395
|
function writeEnum(type, value, emitIntrinsicDefault, enumAsInteger) {
|
|
396
|
+
var _a;
|
|
396
397
|
if (value === undefined) {
|
|
397
398
|
return value;
|
|
398
399
|
}
|
|
@@ -407,7 +408,7 @@ function writeEnum(type, value, emitIntrinsicDefault, enumAsInteger) {
|
|
|
407
408
|
return null;
|
|
408
409
|
}
|
|
409
410
|
const val = type.findNumber(value);
|
|
410
|
-
return val
|
|
411
|
+
return (_a = val === null || val === void 0 ? void 0 : val.name) !== null && _a !== void 0 ? _a : value; // if we don't know the enum value, just return the number
|
|
411
412
|
}
|
|
412
413
|
function writeScalar(type, value, emitIntrinsicDefault) {
|
|
413
414
|
if (value === undefined) {
|
|
@@ -19,7 +19,8 @@ const message_js_1 = require("../message.js");
|
|
|
19
19
|
* Create a new message type using the given runtime.
|
|
20
20
|
*/
|
|
21
21
|
function makeMessageType(runtime, typeName, fields, opt) {
|
|
22
|
-
|
|
22
|
+
var _a;
|
|
23
|
+
const localName = (_a = opt === null || opt === void 0 ? void 0 : opt.localName) !== null && _a !== void 0 ? _a : typeName.substring(typeName.lastIndexOf(".") + 1);
|
|
23
24
|
const type = {
|
|
24
25
|
[localName]: function (data) {
|
|
25
26
|
runtime.util.initFields(this);
|
package/dist/cjs/proto-int64.js
CHANGED
|
@@ -18,7 +18,7 @@ const varint_js_1 = require("./google/varint.js");
|
|
|
18
18
|
function makeInt64Support() {
|
|
19
19
|
const dv = new DataView(new ArrayBuffer(8));
|
|
20
20
|
// note that Safari 14 implements BigInt, but not the DataView methods
|
|
21
|
-
const ok = globalThis.BigInt !== undefined &&
|
|
21
|
+
const ok = globalThis.BigInt !== undefined &&
|
|
22
22
|
typeof dv.getBigInt64 === "function" &&
|
|
23
23
|
typeof dv.getBigUint64 === "function" &&
|
|
24
24
|
typeof dv.setBigInt64 === "function" &&
|
package/dist/cjs/proto2.js
CHANGED
|
@@ -24,9 +24,7 @@ const json_format_proto2_js_1 = require("./private/json-format-proto2.js");
|
|
|
24
24
|
/**
|
|
25
25
|
* Provides functionality for messages defined with the proto2 syntax.
|
|
26
26
|
*/
|
|
27
|
-
exports.proto2 = (0, proto_runtime_js_1.makeProtoRuntime)("proto2", (0, json_format_proto2_js_1.makeJsonFormatProto2)(), (0, binary_format_proto2_js_1.makeBinaryFormatProto2)(), {
|
|
28
|
-
...(0, util_common_js_1.makeUtilCommon)(),
|
|
29
|
-
newFieldList(fields) {
|
|
27
|
+
exports.proto2 = (0, proto_runtime_js_1.makeProtoRuntime)("proto2", (0, json_format_proto2_js_1.makeJsonFormatProto2)(), (0, binary_format_proto2_js_1.makeBinaryFormatProto2)(), Object.assign(Object.assign({}, (0, util_common_js_1.makeUtilCommon)()), { newFieldList(fields) {
|
|
30
28
|
return new field_list_js_1.InternalFieldList(fields, normalizeFieldInfosProto2);
|
|
31
29
|
},
|
|
32
30
|
initFields(target) {
|
|
@@ -55,10 +53,10 @@ exports.proto2 = (0, proto_runtime_js_1.makeProtoRuntime)("proto2", (0, json_for
|
|
|
55
53
|
break;
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
56
|
+
} }));
|
|
60
57
|
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
61
58
|
function normalizeFieldInfosProto2(fieldInfos) {
|
|
59
|
+
var _a, _b, _c;
|
|
62
60
|
const r = [];
|
|
63
61
|
let o;
|
|
64
62
|
for (const field of typeof fieldInfos == "function"
|
|
@@ -66,10 +64,10 @@ function normalizeFieldInfosProto2(fieldInfos) {
|
|
|
66
64
|
: fieldInfos) {
|
|
67
65
|
const f = field;
|
|
68
66
|
f.localName = (0, names_js_1.makeFieldName)(field.name, field.oneof !== undefined);
|
|
69
|
-
f.jsonName = field.jsonName
|
|
70
|
-
f.repeated = field.repeated
|
|
67
|
+
f.jsonName = (_a = field.jsonName) !== null && _a !== void 0 ? _a : (0, names_js_1.makeJsonName)(field.name);
|
|
68
|
+
f.repeated = (_b = field.repeated) !== null && _b !== void 0 ? _b : false;
|
|
71
69
|
// In contrast to proto3, repeated fields are unpacked except when explicitly specified.
|
|
72
|
-
f.packed = field.packed
|
|
70
|
+
f.packed = (_c = field.packed) !== null && _c !== void 0 ? _c : false;
|
|
73
71
|
// We do not surface options at this time
|
|
74
72
|
// f.options = field.options ?? emptyReadonlyObject;
|
|
75
73
|
if (field.oneof !== undefined) {
|
package/dist/cjs/proto3.js
CHANGED
|
@@ -26,9 +26,7 @@ const names_js_1 = require("./private/names.js");
|
|
|
26
26
|
/**
|
|
27
27
|
* Provides functionality for messages defined with the proto3 syntax.
|
|
28
28
|
*/
|
|
29
|
-
exports.proto3 = (0, proto_runtime_js_1.makeProtoRuntime)("proto3", (0, json_format_proto3_js_1.makeJsonFormatProto3)(), (0, binary_format_proto3_js_1.makeBinaryFormatProto3)(), {
|
|
30
|
-
...(0, util_common_js_1.makeUtilCommon)(),
|
|
31
|
-
newFieldList(fields) {
|
|
29
|
+
exports.proto3 = (0, proto_runtime_js_1.makeProtoRuntime)("proto3", (0, json_format_proto3_js_1.makeJsonFormatProto3)(), (0, binary_format_proto3_js_1.makeBinaryFormatProto3)(), Object.assign(Object.assign({}, (0, util_common_js_1.makeUtilCommon)()), { newFieldList(fields) {
|
|
32
30
|
return new field_list_js_1.InternalFieldList(fields, normalizeFieldInfosProto3);
|
|
33
31
|
},
|
|
34
32
|
initFields(target) {
|
|
@@ -59,10 +57,10 @@ exports.proto3 = (0, proto_runtime_js_1.makeProtoRuntime)("proto3", (0, json_for
|
|
|
59
57
|
break;
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
60
|
+
} }));
|
|
64
61
|
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
65
62
|
function normalizeFieldInfosProto3(fieldInfos) {
|
|
63
|
+
var _a, _b, _c;
|
|
66
64
|
const r = [];
|
|
67
65
|
let o;
|
|
68
66
|
for (const field of typeof fieldInfos == "function"
|
|
@@ -70,19 +68,18 @@ function normalizeFieldInfosProto3(fieldInfos) {
|
|
|
70
68
|
: fieldInfos) {
|
|
71
69
|
const f = field;
|
|
72
70
|
f.localName = (0, names_js_1.makeFieldName)(field.name, field.oneof !== undefined);
|
|
73
|
-
f.jsonName = field.jsonName
|
|
74
|
-
f.repeated = field.repeated
|
|
71
|
+
f.jsonName = (_a = field.jsonName) !== null && _a !== void 0 ? _a : (0, names_js_1.makeJsonName)(field.name);
|
|
72
|
+
f.repeated = (_b = field.repeated) !== null && _b !== void 0 ? _b : false;
|
|
75
73
|
// From the proto3 language guide:
|
|
76
74
|
// > In proto3, repeated fields of scalar numeric types are packed by default.
|
|
77
75
|
// This information is incomplete - according to the conformance tests, BOOL
|
|
78
76
|
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
79
77
|
// are not packed by default, which makes sense because they are length-delimited.
|
|
80
78
|
f.packed =
|
|
81
|
-
field.packed
|
|
82
|
-
(field.kind == "
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
field.T != field_js_1.ScalarType.STRING));
|
|
79
|
+
(_c = field.packed) !== null && _c !== void 0 ? _c : (field.kind == "enum" ||
|
|
80
|
+
(field.kind == "scalar" &&
|
|
81
|
+
field.T != field_js_1.ScalarType.BYTES &&
|
|
82
|
+
field.T != field_js_1.ScalarType.STRING));
|
|
86
83
|
// We do not surface options at this time
|
|
87
84
|
// f.options = field.options ?? emptyReadonlyObject;
|
|
88
85
|
if (field.oneof !== undefined) {
|
|
@@ -64,7 +64,7 @@ export class BinaryWriter {
|
|
|
64
64
|
* Previous fork states.
|
|
65
65
|
*/
|
|
66
66
|
this.stack = [];
|
|
67
|
-
this.textEncoder = textEncoder
|
|
67
|
+
this.textEncoder = textEncoder !== null && textEncoder !== void 0 ? textEncoder : new TextEncoder();
|
|
68
68
|
this.chunks = [];
|
|
69
69
|
this.buf = [];
|
|
70
70
|
}
|
|
@@ -279,7 +279,7 @@ export class BinaryReader {
|
|
|
279
279
|
this.len = buf.length;
|
|
280
280
|
this.pos = 0;
|
|
281
281
|
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
282
|
-
this.textDecoder = textDecoder
|
|
282
|
+
this.textDecoder = textDecoder !== null && textDecoder !== void 0 ? textDecoder : new TextDecoder();
|
|
283
283
|
}
|
|
284
284
|
/**
|
|
285
285
|
* Reads a tag - field number and wire type.
|
|
@@ -62,7 +62,7 @@ export class DescriptorRegistry {
|
|
|
62
62
|
this.enums = {};
|
|
63
63
|
this.messages = {};
|
|
64
64
|
this.services = {};
|
|
65
|
-
this.ds = descriptorSet
|
|
65
|
+
this.ds = descriptorSet !== null && descriptorSet !== void 0 ? descriptorSet : new DescriptorSet();
|
|
66
66
|
if (replaceWkt) {
|
|
67
67
|
for (const mt of wkMessages) {
|
|
68
68
|
this.messages["." + mt.typeName] = mt;
|
|
@@ -173,8 +173,9 @@ export class DescriptorRegistry {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
function makeTypeLocalName(type) {
|
|
176
|
+
var _a;
|
|
176
177
|
const typeName = type.typeName;
|
|
177
|
-
const packagePrefix = (type.file.proto.package
|
|
178
|
+
const packagePrefix = ((_a = type.file.proto.package) !== null && _a !== void 0 ? _a : "") + ".";
|
|
178
179
|
if (!typeName.startsWith(packagePrefix)) {
|
|
179
180
|
return type.name;
|
|
180
181
|
}
|
|
@@ -203,32 +204,23 @@ function makeMapFieldInfo(field, resolver) {
|
|
|
203
204
|
if (field.map.value.message) {
|
|
204
205
|
const messageType = resolver.findMessage(field.map.value.message.typeName);
|
|
205
206
|
assert(messageType, `message "${field.map.value.message.typeName}" for ${field.toString()} not found`);
|
|
206
|
-
return {
|
|
207
|
-
...base,
|
|
208
|
-
V: {
|
|
207
|
+
return Object.assign(Object.assign({}, base), { V: {
|
|
209
208
|
kind: "message",
|
|
210
209
|
T: messageType,
|
|
211
|
-
}
|
|
212
|
-
};
|
|
210
|
+
} });
|
|
213
211
|
}
|
|
214
212
|
if (field.map.value.enum) {
|
|
215
213
|
const enumType = resolver.findEnum(field.map.value.enum.typeName);
|
|
216
214
|
assert(enumType, `enum "${field.map.value.enum.typeName}" for ${field.toString()} not found`);
|
|
217
|
-
return {
|
|
218
|
-
...base,
|
|
219
|
-
V: {
|
|
215
|
+
return Object.assign(Object.assign({}, base), { V: {
|
|
220
216
|
kind: "enum",
|
|
221
217
|
T: enumType,
|
|
222
|
-
}
|
|
223
|
-
};
|
|
218
|
+
} });
|
|
224
219
|
}
|
|
225
|
-
return {
|
|
226
|
-
...base,
|
|
227
|
-
V: {
|
|
220
|
+
return Object.assign(Object.assign({}, base), { V: {
|
|
228
221
|
kind: "scalar",
|
|
229
222
|
T: field.map.value.scalarType,
|
|
230
|
-
}
|
|
231
|
-
};
|
|
223
|
+
} });
|
|
232
224
|
}
|
|
233
225
|
function makeScalarFieldInfo(field) {
|
|
234
226
|
const base = {
|
|
@@ -238,25 +230,13 @@ function makeScalarFieldInfo(field) {
|
|
|
238
230
|
T: field.scalarType,
|
|
239
231
|
};
|
|
240
232
|
if (field.repeated) {
|
|
241
|
-
return {
|
|
242
|
-
...base,
|
|
243
|
-
repeated: true,
|
|
244
|
-
packed: field.packed,
|
|
245
|
-
oneof: undefined,
|
|
246
|
-
T: field.scalarType,
|
|
247
|
-
};
|
|
233
|
+
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined, T: field.scalarType });
|
|
248
234
|
}
|
|
249
235
|
if (field.oneof) {
|
|
250
|
-
return {
|
|
251
|
-
...base,
|
|
252
|
-
oneof: field.oneof.name,
|
|
253
|
-
};
|
|
236
|
+
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
254
237
|
}
|
|
255
238
|
if (field.optional) {
|
|
256
|
-
return {
|
|
257
|
-
...base,
|
|
258
|
-
opt: true,
|
|
259
|
-
};
|
|
239
|
+
return Object.assign(Object.assign({}, base), { opt: true });
|
|
260
240
|
}
|
|
261
241
|
return base;
|
|
262
242
|
}
|
|
@@ -270,24 +250,13 @@ function makeMessageFieldInfo(field, resolver) {
|
|
|
270
250
|
T: messageType,
|
|
271
251
|
};
|
|
272
252
|
if (field.repeated) {
|
|
273
|
-
return {
|
|
274
|
-
...base,
|
|
275
|
-
repeated: true,
|
|
276
|
-
packed: field.packed,
|
|
277
|
-
oneof: undefined,
|
|
278
|
-
};
|
|
253
|
+
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
|
279
254
|
}
|
|
280
255
|
if (field.oneof) {
|
|
281
|
-
return {
|
|
282
|
-
...base,
|
|
283
|
-
oneof: field.oneof.name,
|
|
284
|
-
};
|
|
256
|
+
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
285
257
|
}
|
|
286
258
|
if (field.optional) {
|
|
287
|
-
return {
|
|
288
|
-
...base,
|
|
289
|
-
opt: true,
|
|
290
|
-
};
|
|
259
|
+
return Object.assign(Object.assign({}, base), { opt: true });
|
|
291
260
|
}
|
|
292
261
|
return base;
|
|
293
262
|
}
|
|
@@ -301,24 +270,13 @@ function makeEnumFieldInfo(field, resolver) {
|
|
|
301
270
|
T: enumType,
|
|
302
271
|
};
|
|
303
272
|
if (field.repeated) {
|
|
304
|
-
return {
|
|
305
|
-
...base,
|
|
306
|
-
repeated: true,
|
|
307
|
-
packed: field.packed,
|
|
308
|
-
oneof: undefined,
|
|
309
|
-
};
|
|
273
|
+
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
|
310
274
|
}
|
|
311
275
|
if (field.oneof) {
|
|
312
|
-
return {
|
|
313
|
-
...base,
|
|
314
|
-
oneof: field.oneof.name,
|
|
315
|
-
};
|
|
276
|
+
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
316
277
|
}
|
|
317
278
|
if (field.optional) {
|
|
318
|
-
return {
|
|
319
|
-
...base,
|
|
320
|
-
opt: true,
|
|
321
|
-
};
|
|
279
|
+
return Object.assign(Object.assign({}, base), { opt: true });
|
|
322
280
|
}
|
|
323
281
|
return base;
|
|
324
282
|
}
|
|
@@ -147,6 +147,7 @@ function newEnumValue(proto, parent) {
|
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
function newMessage(proto, parent, file, us) {
|
|
150
|
+
var _a;
|
|
150
151
|
assert(proto.name, `invalid descriptor: missing name`);
|
|
151
152
|
const nestedMessages = [];
|
|
152
153
|
const fields = [];
|
|
@@ -192,7 +193,7 @@ function newMessage(proto, parent, file, us) {
|
|
|
192
193
|
let oneof = undefined;
|
|
193
194
|
if (field.oneofIndex !== undefined) {
|
|
194
195
|
oneof = oneofs[field.oneofIndex];
|
|
195
|
-
assert(oneof, `invalid descriptor: oneof declaration index ${field.oneofIndex} specified by field #${field.number
|
|
196
|
+
assert(oneof, `invalid descriptor: oneof declaration index ${field.oneofIndex} specified by field #${(_a = field.number) !== null && _a !== void 0 ? _a : -1} not found`);
|
|
196
197
|
}
|
|
197
198
|
fields.push(newField(field, message, oneof));
|
|
198
199
|
}
|
|
@@ -205,11 +206,12 @@ function newMessage(proto, parent, file, us) {
|
|
|
205
206
|
return message;
|
|
206
207
|
}
|
|
207
208
|
function newField(proto, parent, oneof) {
|
|
209
|
+
var _a;
|
|
208
210
|
assert(proto.name, `invalid descriptor: missing name`);
|
|
209
211
|
assert(proto.number, `invalid descriptor: missing number`);
|
|
210
212
|
assert(proto.type, `invalid descriptor: missing type`);
|
|
211
213
|
let optional = false;
|
|
212
|
-
let packed = proto.options
|
|
214
|
+
let packed = ((_a = proto.options) === null || _a === void 0 ? void 0 : _a.packed) === true;
|
|
213
215
|
switch (parent.file.syntax) {
|
|
214
216
|
case "proto2":
|
|
215
217
|
optional =
|
|
@@ -272,6 +274,7 @@ function newField(proto, parent, oneof) {
|
|
|
272
274
|
return field;
|
|
273
275
|
}
|
|
274
276
|
function resolveField(u, us) {
|
|
277
|
+
var _a;
|
|
275
278
|
const repeated = u.proto.label === FieldDescriptorProto_Label.REPEATED;
|
|
276
279
|
switch (u.type) {
|
|
277
280
|
case FieldDescriptorProto_Type.MESSAGE:
|
|
@@ -279,54 +282,28 @@ function resolveField(u, us) {
|
|
|
279
282
|
assert(u.proto.typeName, `invalid descriptor: ${u.toString()} has type ${FieldDescriptorProto_Type[u.type]}, but type_name is unset`);
|
|
280
283
|
const refMessage = us.messages[u.proto.typeName];
|
|
281
284
|
assert(refMessage, `invalid descriptor: cannot find type_name "${u.proto.typeName}" specified by ${u.toString()}`);
|
|
282
|
-
if (refMessage.proto.options
|
|
283
|
-
return {
|
|
284
|
-
...u,
|
|
285
|
-
repeated: false,
|
|
286
|
-
scalarType: undefined,
|
|
287
|
-
message: undefined,
|
|
288
|
-
enum: undefined,
|
|
289
|
-
map: resolveMap(refMessage, us),
|
|
290
|
-
};
|
|
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) });
|
|
291
287
|
}
|
|
292
|
-
return {
|
|
293
|
-
...u,
|
|
294
|
-
repeated,
|
|
295
|
-
scalarType: undefined,
|
|
296
|
-
message: refMessage,
|
|
297
|
-
enum: undefined,
|
|
298
|
-
map: undefined,
|
|
299
|
-
};
|
|
288
|
+
return Object.assign(Object.assign({}, u), { repeated, scalarType: undefined, message: refMessage, enum: undefined, map: undefined });
|
|
300
289
|
}
|
|
301
290
|
case FieldDescriptorProto_Type.ENUM: {
|
|
302
291
|
assert(u.proto.typeName, `invalid descriptor: ${u.toString()} has type ${FieldDescriptorProto_Type[u.type]}, but type_name is unset`);
|
|
303
292
|
const refEnum = us.enums[u.proto.typeName];
|
|
304
293
|
assert(refEnum, `invalid descriptor: cannot find type_name "${u.proto.typeName}" specified by ${u.toString()}`);
|
|
305
|
-
return {
|
|
306
|
-
...u,
|
|
307
|
-
repeated,
|
|
308
|
-
scalarType: undefined,
|
|
309
|
-
message: undefined,
|
|
310
|
-
enum: refEnum,
|
|
311
|
-
map: undefined,
|
|
312
|
-
};
|
|
294
|
+
return Object.assign(Object.assign({}, u), { repeated, scalarType: undefined, message: undefined, enum: refEnum, map: undefined });
|
|
313
295
|
}
|
|
314
296
|
default: {
|
|
315
297
|
const scalarType = fieldTypeToScalarType[u.type];
|
|
316
298
|
assert(scalarType, `invalid descriptor: unable to convert google.protobuf.FieldDescriptorProto.Type ${FieldDescriptorProto_Type[u.type]} to ScalarType`);
|
|
317
|
-
return {
|
|
318
|
-
|
|
319
|
-
repeated,
|
|
320
|
-
scalarType,
|
|
321
|
-
message: undefined,
|
|
322
|
-
enum: undefined,
|
|
323
|
-
map: undefined,
|
|
324
|
-
};
|
|
299
|
+
return Object.assign(Object.assign({}, u), { repeated,
|
|
300
|
+
scalarType, message: undefined, enum: undefined, map: undefined });
|
|
325
301
|
}
|
|
326
302
|
}
|
|
327
303
|
}
|
|
328
304
|
function resolveMap(mapEntry, us) {
|
|
329
|
-
|
|
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`);
|
|
330
307
|
assert(mapEntry.fields.length === 2, `invalid descriptor: map entry ${mapEntry.toString()} has ${mapEntry.fields.length} fields`);
|
|
331
308
|
const uKeyField = mapEntry.fields.find((f) => f.proto.number === 1);
|
|
332
309
|
assert(uKeyField, `invalid descriptor: map entry ${mapEntry.toString()} is missing key field`);
|
|
@@ -418,6 +395,7 @@ function newService(proto, file, us) {
|
|
|
418
395
|
return service;
|
|
419
396
|
}
|
|
420
397
|
function newMethod(proto, parent) {
|
|
398
|
+
var _a;
|
|
421
399
|
assert(proto.name, `invalid descriptor: missing method descriptor name`);
|
|
422
400
|
assert(proto.inputType, `invalid descriptor: missing method input type`);
|
|
423
401
|
assert(proto.outputType, `invalid descriptor: missing method output type`);
|
|
@@ -435,7 +413,7 @@ function newMethod(proto, parent) {
|
|
|
435
413
|
kind = MethodKind.Unary;
|
|
436
414
|
}
|
|
437
415
|
let idempotency;
|
|
438
|
-
switch (proto.options
|
|
416
|
+
switch ((_a = proto.options) === null || _a === void 0 ? void 0 : _a.idempotencyLevel) {
|
|
439
417
|
case MethodOptions_IdempotencyLevel.IDEMPOTENT:
|
|
440
418
|
idempotency = MethodIdempotency.Idempotent;
|
|
441
419
|
break;
|
|
@@ -145,11 +145,12 @@ export class Any extends Message {
|
|
|
145
145
|
proto3.util.initPartial(data, this);
|
|
146
146
|
}
|
|
147
147
|
toJson(options) {
|
|
148
|
+
var _a;
|
|
148
149
|
if (this.typeUrl === "") {
|
|
149
150
|
return {};
|
|
150
151
|
}
|
|
151
152
|
const typeName = this.typeUrlToName(this.typeUrl);
|
|
152
|
-
const messageType = options
|
|
153
|
+
const messageType = (_a = options === null || options === void 0 ? void 0 : options.typeRegistry) === null || _a === void 0 ? void 0 : _a.findMessage(typeName);
|
|
153
154
|
if (!messageType) {
|
|
154
155
|
throw new Error(`cannot encode message google.protobuf.Any to JSON: "${this.typeUrl}" is not in the type registry`);
|
|
155
156
|
}
|
|
@@ -162,6 +163,7 @@ export class Any extends Message {
|
|
|
162
163
|
return json;
|
|
163
164
|
}
|
|
164
165
|
fromJson(json, options) {
|
|
166
|
+
var _a;
|
|
165
167
|
if (json === null || Array.isArray(json) || typeof json != "object") {
|
|
166
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}`);
|
|
167
169
|
}
|
|
@@ -169,7 +171,7 @@ export class Any extends Message {
|
|
|
169
171
|
if (typeof typeUrl != "string" || typeUrl == "") {
|
|
170
172
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: "@type" is empty`);
|
|
171
173
|
}
|
|
172
|
-
const typeName = this.typeUrlToName(typeUrl), messageType = options
|
|
174
|
+
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);
|
|
173
175
|
if (!messageType) {
|
|
174
176
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: ${typeUrl} is not in the type registry`);
|
|
175
177
|
}
|
|
@@ -118,7 +118,7 @@ export class Duration extends Message {
|
|
|
118
118
|
if (typeof match[2] == "string") {
|
|
119
119
|
const nanosStr = match[2] + "0".repeat(9 - match[2].length);
|
|
120
120
|
this.nanos = parseInt(nanosStr);
|
|
121
|
-
if (longSeconds <
|
|
121
|
+
if (longSeconds < protoInt64.zero) {
|
|
122
122
|
this.nanos = -this.nanos;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
@@ -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.0.7 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";
|
|
@@ -125,7 +125,7 @@ export class Value extends Message {
|
|
|
125
125
|
return this.kind.value;
|
|
126
126
|
case "structValue":
|
|
127
127
|
case "listValue":
|
|
128
|
-
return this.kind.value.toJson({
|
|
128
|
+
return this.kind.value.toJson(Object.assign(Object.assign({}, options), { emitDefaultValues: true }));
|
|
129
129
|
}
|
|
130
130
|
throw new Error("google.protobuf.Value must have a value");
|
|
131
131
|
}
|
|
@@ -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.0.7 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";
|
package/dist/esm/message.js
CHANGED
|
@@ -81,8 +81,9 @@ export class Message {
|
|
|
81
81
|
* Serialize the message to a JSON string.
|
|
82
82
|
*/
|
|
83
83
|
toJsonString(options) {
|
|
84
|
+
var _a;
|
|
84
85
|
const value = this.toJson(options);
|
|
85
|
-
return JSON.stringify(value, null, options
|
|
86
|
+
return JSON.stringify(value, null, (_a = options === null || options === void 0 ? void 0 : options.prettySpaces) !== null && _a !== void 0 ? _a : 0);
|
|
86
87
|
}
|
|
87
88
|
/**
|
|
88
89
|
* Retrieve the MessageType of this message - a singleton that represents
|
|
@@ -29,17 +29,18 @@ const writeDefaults = {
|
|
|
29
29
|
writerFactory: () => new BinaryWriter(),
|
|
30
30
|
};
|
|
31
31
|
function makeReadOptions(options) {
|
|
32
|
-
return options ? {
|
|
32
|
+
return options ? Object.assign(Object.assign({}, readDefaults), options) : readDefaults;
|
|
33
33
|
}
|
|
34
34
|
function makeWriteOptions(options) {
|
|
35
|
-
return options ? {
|
|
35
|
+
return options ? Object.assign(Object.assign({}, writeDefaults), options) : writeDefaults;
|
|
36
36
|
}
|
|
37
37
|
export function makeBinaryFormatCommon() {
|
|
38
38
|
return {
|
|
39
39
|
makeReadOptions,
|
|
40
40
|
makeWriteOptions,
|
|
41
41
|
listUnknownFields(message) {
|
|
42
|
-
|
|
42
|
+
var _a;
|
|
43
|
+
return (_a = message[unknownFieldsSymbol]) !== null && _a !== void 0 ? _a : [];
|
|
43
44
|
},
|
|
44
45
|
discardUnknownFields(message) {
|
|
45
46
|
delete message[unknownFieldsSymbol];
|
|
@@ -15,9 +15,7 @@ import { ScalarType } from "../field.js";
|
|
|
15
15
|
import { makeBinaryFormatCommon, writeMapEntry, writeMessageField, writePacked, writeScalar, } from "./binary-format-common.js";
|
|
16
16
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions, no-case-declarations, prefer-const */
|
|
17
17
|
export function makeBinaryFormatProto2() {
|
|
18
|
-
return {
|
|
19
|
-
...makeBinaryFormatCommon(),
|
|
20
|
-
writeMessage(message, writer, options) {
|
|
18
|
+
return Object.assign(Object.assign({}, makeBinaryFormatCommon()), { writeMessage(message, writer, options) {
|
|
21
19
|
const type = message.getType();
|
|
22
20
|
let field;
|
|
23
21
|
try {
|
|
@@ -81,7 +79,7 @@ export function makeBinaryFormatProto2() {
|
|
|
81
79
|
}
|
|
82
80
|
catch (e) {
|
|
83
81
|
let m = field
|
|
84
|
-
? `cannot encode field ${type.typeName}.${field
|
|
82
|
+
? `cannot encode field ${type.typeName}.${field === null || field === void 0 ? void 0 : field.name} to binary`
|
|
85
83
|
: `cannot encode message ${type.typeName} to binary`;
|
|
86
84
|
let r = e instanceof Error ? e.message : String(e);
|
|
87
85
|
throw new Error(m + (r.length > 0 ? `: ${r}` : ""));
|
|
@@ -90,6 +88,5 @@ export function makeBinaryFormatProto2() {
|
|
|
90
88
|
this.writeUnknownFields(message, writer);
|
|
91
89
|
}
|
|
92
90
|
return writer;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
91
|
+
} });
|
|
95
92
|
}
|
|
@@ -15,9 +15,7 @@ import { ScalarType } from "../field.js";
|
|
|
15
15
|
import { makeBinaryFormatCommon, writeMapEntry, writeMessageField, writePacked, writeScalar, } from "./binary-format-common.js";
|
|
16
16
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions, prefer-const, no-case-declarations */
|
|
17
17
|
export function makeBinaryFormatProto3() {
|
|
18
|
-
return {
|
|
19
|
-
...makeBinaryFormatCommon(),
|
|
20
|
-
writeMessage(message, writer, options) {
|
|
18
|
+
return Object.assign(Object.assign({}, makeBinaryFormatCommon()), { writeMessage(message, writer, options) {
|
|
21
19
|
const type = message.getType();
|
|
22
20
|
for (const field of type.fields.byNumber()) {
|
|
23
21
|
let value, // this will be our field value, whether it is member of a oneof or regular field
|
|
@@ -73,6 +71,5 @@ export function makeBinaryFormatProto3() {
|
|
|
73
71
|
this.writeUnknownFields(message, writer);
|
|
74
72
|
}
|
|
75
73
|
return writer;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
74
|
+
} });
|
|
78
75
|
}
|
package/dist/esm/private/enum.js
CHANGED
|
@@ -76,7 +76,7 @@ export function makeEnumType(typeName, values
|
|
|
76
76
|
export function makeEnum(typeName, values, opt) {
|
|
77
77
|
const enumObject = {};
|
|
78
78
|
for (const value of values) {
|
|
79
|
-
const name = makeEnumValueName(value, opt
|
|
79
|
+
const name = makeEnumValueName(value, opt === null || opt === void 0 ? void 0 : opt.sharedPrefix);
|
|
80
80
|
enumObject[name] = value.no;
|
|
81
81
|
enumObject[value.no] = name;
|
|
82
82
|
}
|
|
@@ -29,10 +29,10 @@ const jsonWriteDefaults = {
|
|
|
29
29
|
prettySpaces: 0,
|
|
30
30
|
};
|
|
31
31
|
function makeReadOptions(options) {
|
|
32
|
-
return options ? {
|
|
32
|
+
return options ? Object.assign(Object.assign({}, jsonReadDefaults), options) : jsonReadDefaults;
|
|
33
33
|
}
|
|
34
34
|
function makeWriteOptions(options) {
|
|
35
|
-
return options ? {
|
|
35
|
+
return options ? Object.assign(Object.assign({}, jsonWriteDefaults), options) : jsonWriteDefaults;
|
|
36
36
|
}
|
|
37
37
|
export function makeJsonFormatCommon(makeWriteField) {
|
|
38
38
|
const writeField = makeWriteField(writeEnum, writeScalar);
|
|
@@ -43,7 +43,7 @@ export function makeJsonFormatCommon(makeWriteField) {
|
|
|
43
43
|
if (json == null || Array.isArray(json) || typeof json != "object") {
|
|
44
44
|
throw new Error(`cannot decode message ${type.typeName} from JSON: ${this.debug(json)}`);
|
|
45
45
|
}
|
|
46
|
-
message = message
|
|
46
|
+
message = message !== null && message !== void 0 ? message : new type();
|
|
47
47
|
const oneofSeen = {};
|
|
48
48
|
for (const [jsonKey, jsonValue] of Object.entries(json)) {
|
|
49
49
|
const field = type.fields.findJsonName(jsonKey);
|
|
@@ -382,13 +382,14 @@ function readEnum(type, json, ignoreUnknownFields) {
|
|
|
382
382
|
case "string":
|
|
383
383
|
const value = type.findName(json);
|
|
384
384
|
if (value || ignoreUnknownFields) {
|
|
385
|
-
return value
|
|
385
|
+
return value === null || value === void 0 ? void 0 : value.no;
|
|
386
386
|
}
|
|
387
387
|
break;
|
|
388
388
|
}
|
|
389
389
|
throw new Error(`cannot decode enum ${type.typeName} from JSON: ${debugJsonValue(json)}`);
|
|
390
390
|
}
|
|
391
391
|
function writeEnum(type, value, emitIntrinsicDefault, enumAsInteger) {
|
|
392
|
+
var _a;
|
|
392
393
|
if (value === undefined) {
|
|
393
394
|
return value;
|
|
394
395
|
}
|
|
@@ -403,7 +404,7 @@ function writeEnum(type, value, emitIntrinsicDefault, enumAsInteger) {
|
|
|
403
404
|
return null;
|
|
404
405
|
}
|
|
405
406
|
const val = type.findNumber(value);
|
|
406
|
-
return val
|
|
407
|
+
return (_a = val === null || val === void 0 ? void 0 : val.name) !== null && _a !== void 0 ? _a : value; // if we don't know the enum value, just return the number
|
|
407
408
|
}
|
|
408
409
|
function writeScalar(type, value, emitIntrinsicDefault) {
|
|
409
410
|
if (value === undefined) {
|
|
@@ -16,7 +16,8 @@ import { Message, } from "../message.js";
|
|
|
16
16
|
* Create a new message type using the given runtime.
|
|
17
17
|
*/
|
|
18
18
|
export function makeMessageType(runtime, typeName, fields, opt) {
|
|
19
|
-
|
|
19
|
+
var _a;
|
|
20
|
+
const localName = (_a = opt === null || opt === void 0 ? void 0 : opt.localName) !== null && _a !== void 0 ? _a : typeName.substring(typeName.lastIndexOf(".") + 1);
|
|
20
21
|
const type = {
|
|
21
22
|
[localName]: function (data) {
|
|
22
23
|
runtime.util.initFields(this);
|
package/dist/esm/proto-int64.js
CHANGED
|
@@ -15,7 +15,7 @@ import { int64fromString, int64toString } from "./google/varint.js";
|
|
|
15
15
|
function makeInt64Support() {
|
|
16
16
|
const dv = new DataView(new ArrayBuffer(8));
|
|
17
17
|
// note that Safari 14 implements BigInt, but not the DataView methods
|
|
18
|
-
const ok = globalThis.BigInt !== undefined &&
|
|
18
|
+
const ok = globalThis.BigInt !== undefined &&
|
|
19
19
|
typeof dv.getBigInt64 === "function" &&
|
|
20
20
|
typeof dv.getBigUint64 === "function" &&
|
|
21
21
|
typeof dv.setBigInt64 === "function" &&
|
package/dist/esm/proto2.js
CHANGED
|
@@ -21,9 +21,7 @@ import { makeJsonFormatProto2 } from "./private/json-format-proto2.js";
|
|
|
21
21
|
/**
|
|
22
22
|
* Provides functionality for messages defined with the proto2 syntax.
|
|
23
23
|
*/
|
|
24
|
-
export const proto2 = makeProtoRuntime("proto2", makeJsonFormatProto2(), makeBinaryFormatProto2(), {
|
|
25
|
-
...makeUtilCommon(),
|
|
26
|
-
newFieldList(fields) {
|
|
24
|
+
export const proto2 = makeProtoRuntime("proto2", makeJsonFormatProto2(), makeBinaryFormatProto2(), Object.assign(Object.assign({}, makeUtilCommon()), { newFieldList(fields) {
|
|
27
25
|
return new InternalFieldList(fields, normalizeFieldInfosProto2);
|
|
28
26
|
},
|
|
29
27
|
initFields(target) {
|
|
@@ -52,10 +50,10 @@ export const proto2 = makeProtoRuntime("proto2", makeJsonFormatProto2(), makeBin
|
|
|
52
50
|
break;
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
}
|
|
56
|
-
});
|
|
53
|
+
} }));
|
|
57
54
|
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
58
55
|
function normalizeFieldInfosProto2(fieldInfos) {
|
|
56
|
+
var _a, _b, _c;
|
|
59
57
|
const r = [];
|
|
60
58
|
let o;
|
|
61
59
|
for (const field of typeof fieldInfos == "function"
|
|
@@ -63,10 +61,10 @@ function normalizeFieldInfosProto2(fieldInfos) {
|
|
|
63
61
|
: fieldInfos) {
|
|
64
62
|
const f = field;
|
|
65
63
|
f.localName = makeFieldName(field.name, field.oneof !== undefined);
|
|
66
|
-
f.jsonName = field.jsonName
|
|
67
|
-
f.repeated = field.repeated
|
|
64
|
+
f.jsonName = (_a = field.jsonName) !== null && _a !== void 0 ? _a : makeJsonName(field.name);
|
|
65
|
+
f.repeated = (_b = field.repeated) !== null && _b !== void 0 ? _b : false;
|
|
68
66
|
// In contrast to proto3, repeated fields are unpacked except when explicitly specified.
|
|
69
|
-
f.packed = field.packed
|
|
67
|
+
f.packed = (_c = field.packed) !== null && _c !== void 0 ? _c : false;
|
|
70
68
|
// We do not surface options at this time
|
|
71
69
|
// f.options = field.options ?? emptyReadonlyObject;
|
|
72
70
|
if (field.oneof !== undefined) {
|
package/dist/esm/proto3.js
CHANGED
|
@@ -23,9 +23,7 @@ import { makeFieldName, makeJsonName } from "./private/names.js";
|
|
|
23
23
|
/**
|
|
24
24
|
* Provides functionality for messages defined with the proto3 syntax.
|
|
25
25
|
*/
|
|
26
|
-
export const proto3 = makeProtoRuntime("proto3", makeJsonFormatProto3(), makeBinaryFormatProto3(), {
|
|
27
|
-
...makeUtilCommon(),
|
|
28
|
-
newFieldList(fields) {
|
|
26
|
+
export const proto3 = makeProtoRuntime("proto3", makeJsonFormatProto3(), makeBinaryFormatProto3(), Object.assign(Object.assign({}, makeUtilCommon()), { newFieldList(fields) {
|
|
29
27
|
return new InternalFieldList(fields, normalizeFieldInfosProto3);
|
|
30
28
|
},
|
|
31
29
|
initFields(target) {
|
|
@@ -56,10 +54,10 @@ export const proto3 = makeProtoRuntime("proto3", makeJsonFormatProto3(), makeBin
|
|
|
56
54
|
break;
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
57
|
+
} }));
|
|
61
58
|
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
62
59
|
function normalizeFieldInfosProto3(fieldInfos) {
|
|
60
|
+
var _a, _b, _c;
|
|
63
61
|
const r = [];
|
|
64
62
|
let o;
|
|
65
63
|
for (const field of typeof fieldInfos == "function"
|
|
@@ -67,19 +65,18 @@ function normalizeFieldInfosProto3(fieldInfos) {
|
|
|
67
65
|
: fieldInfos) {
|
|
68
66
|
const f = field;
|
|
69
67
|
f.localName = makeFieldName(field.name, field.oneof !== undefined);
|
|
70
|
-
f.jsonName = field.jsonName
|
|
71
|
-
f.repeated = field.repeated
|
|
68
|
+
f.jsonName = (_a = field.jsonName) !== null && _a !== void 0 ? _a : makeJsonName(field.name);
|
|
69
|
+
f.repeated = (_b = field.repeated) !== null && _b !== void 0 ? _b : false;
|
|
72
70
|
// From the proto3 language guide:
|
|
73
71
|
// > In proto3, repeated fields of scalar numeric types are packed by default.
|
|
74
72
|
// This information is incomplete - according to the conformance tests, BOOL
|
|
75
73
|
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
76
74
|
// are not packed by default, which makes sense because they are length-delimited.
|
|
77
75
|
f.packed =
|
|
78
|
-
field.packed
|
|
79
|
-
(field.kind == "
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
field.T != ScalarType.STRING));
|
|
76
|
+
(_c = field.packed) !== null && _c !== void 0 ? _c : (field.kind == "enum" ||
|
|
77
|
+
(field.kind == "scalar" &&
|
|
78
|
+
field.T != ScalarType.BYTES &&
|
|
79
|
+
field.T != ScalarType.STRING));
|
|
83
80
|
// We do not surface options at this time
|
|
84
81
|
// f.options = field.options ?? emptyReadonlyObject;
|
|
85
82
|
if (field.oneof !== undefined) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protobuf",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"license": "(Apache-2.0 AND BSD-3-Clause)",
|
|
5
5
|
"description": "A complete implementation of protocol buffers in TypeScript, suitable for web browsers and Node.js.",
|
|
6
6
|
"repository": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"default": "./dist/esm/index.js"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"typescript": "^4.7.
|
|
26
|
+
"typescript": "^4.7.4"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"dist/**/"
|