@bufbuild/protobuf 0.0.5 → 0.0.8
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 +11 -8
- package/dist/cjs/google/protobuf/api_pb.js +19 -18
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +23 -22
- package/dist/cjs/google/protobuf/descriptor_pb.js +149 -148
- package/dist/cjs/google/protobuf/duration_pb.js +14 -12
- package/dist/cjs/google/protobuf/empty_pb.js +7 -6
- package/dist/cjs/google/protobuf/field_mask_pb.js +8 -7
- package/dist/cjs/google/protobuf/source_context_pb.js +7 -6
- package/dist/cjs/google/protobuf/struct_pb.js +26 -22
- package/dist/cjs/google/protobuf/timestamp_pb.js +12 -10
- package/dist/cjs/google/protobuf/type_pb.js +37 -33
- package/dist/cjs/google/protobuf/wrappers_pb.js +69 -66
- package/dist/cjs/index.js +40 -4
- 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 +6 -3
- package/dist/esm/google/protobuf/api_pb.js +2 -1
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +2 -1
- package/dist/esm/google/protobuf/descriptor_pb.js +2 -1
- package/dist/esm/google/protobuf/duration_pb.js +4 -2
- package/dist/esm/google/protobuf/empty_pb.js +2 -1
- package/dist/esm/google/protobuf/field_mask_pb.js +2 -1
- package/dist/esm/google/protobuf/source_context_pb.js +2 -1
- package/dist/esm/google/protobuf/struct_pb.js +6 -2
- package/dist/esm/google/protobuf/timestamp_pb.js +3 -1
- package/dist/esm/google/protobuf/type_pb.js +5 -1
- package/dist/esm/google/protobuf/wrappers_pb.js +4 -1
- package/dist/esm/index.js +25 -4
- 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/dist/protobuf.cjs +2 -0
- package/dist/protobuf.cjs.map +1 -0
- package/dist/protobuf.esm.js +2 -0
- package/dist/protobuf.esm.js.map +1 -0
- package/dist/protobuf.modern.js +2 -0
- package/dist/protobuf.modern.js.map +1 -0
- package/dist/types/google/protobuf/any_pb.d.ts +6 -2
- package/dist/types/google/protobuf/api_pb.d.ts +5 -2
- package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +5 -2
- package/dist/types/google/protobuf/descriptor_pb.d.ts +5 -2
- package/dist/types/google/protobuf/duration_pb.d.ts +5 -2
- package/dist/types/google/protobuf/empty_pb.d.ts +5 -2
- package/dist/types/google/protobuf/field_mask_pb.d.ts +5 -2
- package/dist/types/google/protobuf/source_context_pb.d.ts +5 -2
- package/dist/types/google/protobuf/struct_pb.d.ts +5 -2
- package/dist/types/google/protobuf/timestamp_pb.d.ts +5 -2
- package/dist/types/google/protobuf/type_pb.d.ts +5 -2
- package/dist/types/google/protobuf/wrappers_pb.d.ts +5 -2
- package/dist/types/index.d.ts +31 -2
- package/package.json +3 -2
- package/dist/cjs/index-runtime.js +0 -42
- package/dist/cjs/index-wkt.js +0 -42
- package/dist/esm/index-runtime.js +0 -25
- package/dist/esm/index-wkt.js +0 -26
- package/dist/types/index-runtime.d.ts +0 -19
- package/dist/types/index-wkt.d.ts +0 -12
package/dist/cjs/index.js
CHANGED
|
@@ -27,7 +27,43 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
27
27
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
exports.BinaryReader = exports.BinaryWriter = exports.WireType = exports.DescriptorSet = exports.DescriptorRegistry = exports.TypeRegistry = exports.MethodIdempotency = exports.MethodKind = exports.ScalarType = exports.Message = exports.protoBase64 = exports.protoInt64 = exports.proto2 = exports.proto3 = void 0;
|
|
31
|
+
var proto3_js_1 = require("./proto3.js");
|
|
32
|
+
Object.defineProperty(exports, "proto3", { enumerable: true, get: function () { return proto3_js_1.proto3; } });
|
|
33
|
+
var proto2_js_1 = require("./proto2.js");
|
|
34
|
+
Object.defineProperty(exports, "proto2", { enumerable: true, get: function () { return proto2_js_1.proto2; } });
|
|
35
|
+
var proto_int64_js_1 = require("./proto-int64.js");
|
|
36
|
+
Object.defineProperty(exports, "protoInt64", { enumerable: true, get: function () { return proto_int64_js_1.protoInt64; } });
|
|
37
|
+
var proto_base64_js_1 = require("./proto-base64.js");
|
|
38
|
+
Object.defineProperty(exports, "protoBase64", { enumerable: true, get: function () { return proto_base64_js_1.protoBase64; } });
|
|
39
|
+
var message_js_1 = require("./message.js");
|
|
40
|
+
Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return message_js_1.Message; } });
|
|
41
|
+
var field_js_1 = require("./field.js");
|
|
42
|
+
Object.defineProperty(exports, "ScalarType", { enumerable: true, get: function () { return field_js_1.ScalarType; } });
|
|
43
|
+
var service_type_js_1 = require("./service-type.js");
|
|
44
|
+
Object.defineProperty(exports, "MethodKind", { enumerable: true, get: function () { return service_type_js_1.MethodKind; } });
|
|
45
|
+
Object.defineProperty(exports, "MethodIdempotency", { enumerable: true, get: function () { return service_type_js_1.MethodIdempotency; } });
|
|
46
|
+
var type_registry_js_1 = require("./type-registry.js");
|
|
47
|
+
Object.defineProperty(exports, "TypeRegistry", { enumerable: true, get: function () { return type_registry_js_1.TypeRegistry; } });
|
|
48
|
+
var descriptor_registry_js_1 = require("./descriptor-registry.js");
|
|
49
|
+
Object.defineProperty(exports, "DescriptorRegistry", { enumerable: true, get: function () { return descriptor_registry_js_1.DescriptorRegistry; } });
|
|
50
|
+
var descriptor_set_js_1 = require("./descriptor-set.js");
|
|
51
|
+
Object.defineProperty(exports, "DescriptorSet", { enumerable: true, get: function () { return descriptor_set_js_1.DescriptorSet; } });
|
|
52
|
+
var binary_encoding_js_1 = require("./binary-encoding.js");
|
|
53
|
+
Object.defineProperty(exports, "WireType", { enumerable: true, get: function () { return binary_encoding_js_1.WireType; } });
|
|
54
|
+
Object.defineProperty(exports, "BinaryWriter", { enumerable: true, get: function () { return binary_encoding_js_1.BinaryWriter; } });
|
|
55
|
+
Object.defineProperty(exports, "BinaryReader", { enumerable: true, get: function () { return binary_encoding_js_1.BinaryReader; } });
|
|
56
|
+
var json_format_js_1 = require("./json-format.js");
|
|
57
|
+
// ideally, we would export these types with sub-path exports:
|
|
58
|
+
__exportStar(require("./google/protobuf/compiler/plugin_pb.js"), exports);
|
|
59
|
+
__exportStar(require("./google/protobuf/api_pb.js"), exports);
|
|
60
|
+
__exportStar(require("./google/protobuf/any_pb.js"), exports);
|
|
61
|
+
__exportStar(require("./google/protobuf/descriptor_pb.js"), exports);
|
|
62
|
+
__exportStar(require("./google/protobuf/duration_pb.js"), exports);
|
|
63
|
+
__exportStar(require("./google/protobuf/empty_pb.js"), exports);
|
|
64
|
+
__exportStar(require("./google/protobuf/field_mask_pb.js"), exports);
|
|
65
|
+
__exportStar(require("./google/protobuf/source_context_pb.js"), exports);
|
|
66
|
+
__exportStar(require("./google/protobuf/struct_pb.js"), exports);
|
|
67
|
+
__exportStar(require("./google/protobuf/timestamp_pb.js"), exports);
|
|
68
|
+
__exportStar(require("./google/protobuf/type_pb.js"), exports);
|
|
69
|
+
__exportStar(require("./google/protobuf/wrappers_pb.js"), exports);
|
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;
|
|
@@ -11,7 +11,8 @@
|
|
|
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
|
-
import { Message
|
|
14
|
+
import { Message } from "../../message.js";
|
|
15
|
+
import { proto3 } from "../../proto3.js";
|
|
15
16
|
/**
|
|
16
17
|
* `Any` contains an arbitrary serialized protocol buffer message along with a
|
|
17
18
|
* URL that describes the type of the serialized message.
|
|
@@ -144,11 +145,12 @@ export class Any extends Message {
|
|
|
144
145
|
proto3.util.initPartial(data, this);
|
|
145
146
|
}
|
|
146
147
|
toJson(options) {
|
|
148
|
+
var _a;
|
|
147
149
|
if (this.typeUrl === "") {
|
|
148
150
|
return {};
|
|
149
151
|
}
|
|
150
152
|
const typeName = this.typeUrlToName(this.typeUrl);
|
|
151
|
-
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);
|
|
152
154
|
if (!messageType) {
|
|
153
155
|
throw new Error(`cannot encode message google.protobuf.Any to JSON: "${this.typeUrl}" is not in the type registry`);
|
|
154
156
|
}
|
|
@@ -161,6 +163,7 @@ export class Any extends Message {
|
|
|
161
163
|
return json;
|
|
162
164
|
}
|
|
163
165
|
fromJson(json, options) {
|
|
166
|
+
var _a;
|
|
164
167
|
if (json === null || Array.isArray(json) || typeof json != "object") {
|
|
165
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}`);
|
|
166
169
|
}
|
|
@@ -168,7 +171,7 @@ export class Any extends Message {
|
|
|
168
171
|
if (typeof typeUrl != "string" || typeUrl == "") {
|
|
169
172
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: "@type" is empty`);
|
|
170
173
|
}
|
|
171
|
-
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);
|
|
172
175
|
if (!messageType) {
|
|
173
176
|
throw new Error(`cannot decode message google.protobuf.Any from JSON: ${typeUrl} is not in the type registry`);
|
|
174
177
|
}
|
|
@@ -11,9 +11,10 @@
|
|
|
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
|
-
import { Message
|
|
14
|
+
import { Message } from "../../message.js";
|
|
15
15
|
import { Option, Syntax } from "./type_pb.js";
|
|
16
16
|
import { SourceContext } from "./source_context_pb.js";
|
|
17
|
+
import { proto3 } from "../../proto3.js";
|
|
17
18
|
/**
|
|
18
19
|
* Api is a light-weight descriptor for an API Interface.
|
|
19
20
|
*
|
|
@@ -11,7 +11,8 @@
|
|
|
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
|
-
import { Message
|
|
14
|
+
import { Message } from "../../../message.js";
|
|
15
|
+
import { proto2 } from "../../../proto2.js";
|
|
15
16
|
import { FileDescriptorProto, GeneratedCodeInfo } from "../descriptor_pb.js";
|
|
16
17
|
/**
|
|
17
18
|
* The version number of protocol compiler.
|