@gravity-ui/gateway 4.12.0 → 4.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/components/grpc.js
CHANGED
|
@@ -549,6 +549,10 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
549
549
|
const timeout = (_c = (_b = (_a = actionConfig === null || actionConfig === void 0 ? void 0 : actionConfig.timeout) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config.timeout) !== null && _b !== void 0 ? _b : options === null || options === void 0 ? void 0 : options.timeout) !== null && _c !== void 0 ? _c : constants_1.DEFAULT_TIMEOUT;
|
|
550
550
|
let serviceOptions = createServiceOptions(timeout);
|
|
551
551
|
const { body = null } = params !== null && params !== void 0 ? params : { body: args };
|
|
552
|
+
// protobufjs >=7.5.5 rejects null/undefined request payloads with
|
|
553
|
+
// ".<Type>: object expected" (any message with fields; >=8.x even for
|
|
554
|
+
// empty messages). An empty request body must be sent as {}.
|
|
555
|
+
const requestBody = body !== null && body !== void 0 ? body : {};
|
|
552
556
|
const serviceMetadata = createMetadata({
|
|
553
557
|
options,
|
|
554
558
|
actionConfig,
|
|
@@ -573,7 +577,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
573
577
|
debugHeaders: (0, common_2.sanitizeDebugHeaders)(debugHeaders),
|
|
574
578
|
});
|
|
575
579
|
const actionCall = service[action].bind(service);
|
|
576
|
-
const stream = actionCall(
|
|
580
|
+
const stream = actionCall(requestBody, serviceMetadata, serviceOptions);
|
|
577
581
|
stopListeningForAbort = (0, grpc_1.listenForAbort)({
|
|
578
582
|
signal: abortSignal,
|
|
579
583
|
config,
|
|
@@ -666,7 +670,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
666
670
|
let actionCall = service[action].bind(service);
|
|
667
671
|
const callAction = () => {
|
|
668
672
|
let trailingMetadata = {};
|
|
669
|
-
const call = actionCall(
|
|
673
|
+
const call = actionCall(requestBody, serviceMetadata, serviceOptions, async (error, response) => {
|
|
670
674
|
var _a, _b;
|
|
671
675
|
const endRequestTime = Date.now();
|
|
672
676
|
requestData.requestTime = endRequestTime - startRequestTime;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/gateway",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "build/index.js",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"axios-retry": "^3.9.1",
|
|
47
47
|
"lodash": "^4.17.21",
|
|
48
48
|
"object-sizeof": "^2.6.5",
|
|
49
|
-
"protobufjs": "^7.
|
|
49
|
+
"protobufjs": "^7.6.4",
|
|
50
50
|
"uuid": "^9.0.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
diff --git a/node_modules/protobufjs/Oops.rej b/node_modules/protobufjs/Oops.rej
|
|
2
|
+
new file mode 100644
|
|
3
|
+
index 0000000..2dd05fc
|
|
4
|
+
--- /dev/null
|
|
5
|
+
+++ b/node_modules/protobufjs/Oops.rej
|
|
6
|
+
@@ -0,0 +1,78 @@
|
|
7
|
+
+@@ -242,31 +242,12 @@
|
|
8
|
+
+ if (!nested)
|
|
9
|
+
+ type._edition = edition;
|
|
10
|
+
+
|
|
11
|
+
+- // gateway patch: record key/value types of map-entry nested types so that
|
|
12
|
+
+- // map fields restored from a descriptor (reflection) become real MapFields.
|
|
13
|
+
+- var mapTypes = {};
|
|
14
|
+
+- if (descriptor.nestedType)
|
|
15
|
+
+- for (i = 0; i < descriptor.nestedType.length; ++i)
|
|
16
|
+
+- if (descriptor.nestedType[i].options && descriptor.nestedType[i].options.mapEntry && descriptor.nestedType[i].field.length === 2)
|
|
17
|
+
+- mapTypes[descriptor.nestedType[i].name] = [
|
|
18
|
+
+- fromDescriptorType(descriptor.nestedType[i].field[0].type),
|
|
19
|
+
+- descriptor.nestedType[i].field[1].typeName ? descriptor.nestedType[i].field[1].typeName : fromDescriptorType(descriptor.nestedType[i].field[1].type)
|
|
20
|
+
+- ];
|
|
21
|
+
+-
|
|
22
|
+
+ /* Oneofs */ if (descriptor.oneofDecl)
|
|
23
|
+
+ for (i = 0; i < descriptor.oneofDecl.length; ++i)
|
|
24
|
+
+ type.add(OneOf.fromDescriptor(descriptor.oneofDecl[i]));
|
|
25
|
+
+ /* Fields */ if (descriptor.field)
|
|
26
|
+
+ for (i = 0; i < descriptor.field.length; ++i) {
|
|
27
|
+
+- var fieldTypeName = descriptor.field[i].typeName;
|
|
28
|
+
+- var mapKv = fieldTypeName ? mapTypes[fieldTypeName] : undefined;
|
|
29
|
+
+- if (fieldTypeName && !mapKv) {
|
|
30
|
+
+- // after reflection the typeName may be just the short name
|
|
31
|
+
+- var nameParts = fieldTypeName.split("." + type.name + ".");
|
|
32
|
+
+- if (nameParts.length === 2)
|
|
33
|
+
+- mapKv = mapTypes[nameParts[1]];
|
|
34
|
+
+- }
|
|
35
|
+
+- var field = Field.fromDescriptor(descriptor.field[i], edition, true, mapKv);
|
|
36
|
+
++ var field = Field.fromDescriptor(descriptor.field[i], edition, true);
|
|
37
|
+
+ type.add(field);
|
|
38
|
+
+ if (descriptor.field[i].hasOwnProperty("oneofIndex")) // eslint-disable-line no-prototype-builtins
|
|
39
|
+
+ type.oneofsArray[descriptor.field[i].oneofIndex].add(field);
|
|
40
|
+
+@@ -276,10 +257,9 @@
|
|
41
|
+
+ type.add(Field.fromDescriptor(descriptor.extension[i], edition, true));
|
|
42
|
+
+ /* Nested types */ if (descriptor.nestedType)
|
|
43
|
+
+ for (i = 0; i < descriptor.nestedType.length; ++i) {
|
|
44
|
+
+- // map-entry types are reconstructed as MapFields above (gateway patch)
|
|
45
|
+
+- if (descriptor.nestedType[i].options && descriptor.nestedType[i].options.mapEntry && descriptor.nestedType[i].field.length === 2)
|
|
46
|
+
+- continue;
|
|
47
|
+
+ type.add(Type.fromDescriptor(descriptor.nestedType[i], edition, true, depth + 1));
|
|
48
|
+
++ if (descriptor.nestedType[i].options && descriptor.nestedType[i].options.mapEntry)
|
|
49
|
+
++ type.setOption("map_entry", true);
|
|
50
|
+
+ }
|
|
51
|
+
+ /* Nested enums */ if (descriptor.enumType)
|
|
52
|
+
+ for (i = 0; i < descriptor.enumType.length; ++i)
|
|
53
|
+
+@@ -430,10 +410,9 @@
|
|
54
|
+
+ * @param {IFieldDescriptorProto|Reader|Uint8Array} descriptor Descriptor
|
|
55
|
+
+ * @param {string} [edition="proto2"] The syntax or edition to use
|
|
56
|
+
+ * @param {boolean} [nested=false] Whether or not this is a top-level object
|
|
57
|
+
+- * @param {string[]} [mapKv] Key & value types for a map field (gateway patch)
|
|
58
|
+
+- * @returns {Field|MapField} Field instance
|
|
59
|
+
++ * @returns {Field} Field instance
|
|
60
|
+
+ */
|
|
61
|
+
+-Field.fromDescriptor = function fromDescriptor(descriptor, edition, nested, mapKv) {
|
|
62
|
+
++Field.fromDescriptor = function fromDescriptor(descriptor, edition, nested) {
|
|
63
|
+
+
|
|
64
|
+
+ // Decode the descriptor message if specified as a buffer:
|
|
65
|
+
+ if (typeof descriptor.length === "number")
|
|
66
|
+
+@@ -468,16 +447,8 @@
|
|
67
|
+
+ throw Error("illegal type name: " + extendee);
|
|
68
|
+
+ } else
|
|
69
|
+
+ extendee = undefined;
|
|
70
|
+
+- // gateway patch: protobufjs expects camelCased field names, while descriptors
|
|
71
|
+
+- // (reflection) carry the original proto names; build a MapField for map fields.
|
|
72
|
+
+- var fieldName = $protobuf.util.camelCase(descriptor.name.length ? descriptor.name : "field" + descriptor.number);
|
|
73
|
+
+- var field = mapKv ? new MapField(
|
|
74
|
+
+- fieldName,
|
|
75
|
+
+- descriptor.number,
|
|
76
|
+
+- mapKv[0],
|
|
77
|
+
+- mapKv[1]
|
|
78
|
+
+- ) : new Field(
|
|
79
|
+
+- fieldName,
|
|
80
|
+
++ var field = new Field(
|
|
81
|
+
++ descriptor.name.length ? descriptor.name : "field" + descriptor.number,
|
|
82
|
+
+ descriptor.number,
|
|
83
|
+
+ fieldType,
|
|
84
|
+
+ fieldRule,
|
|
85
|
+
diff --git a/node_modules/protobufjs/ext/descriptor/index.js b/node_modules/protobufjs/ext/descriptor/index.js
|
|
86
|
+
index 6ea795b..cdb50c1 100644
|
|
87
|
+
--- a/node_modules/protobufjs/ext/descriptor/index.js
|
|
88
|
+
+++ b/node_modules/protobufjs/ext/descriptor/index.js
|
|
89
|
+
@@ -242,12 +242,31 @@ Type.fromDescriptor = function fromDescriptor(descriptor, edition, nested, depth
|
|
90
|
+
if (!nested)
|
|
91
|
+
type._edition = edition;
|
|
92
|
+
|
|
93
|
+
+ // gateway patch: record key/value types of map-entry nested types so that
|
|
94
|
+
+ // map fields restored from a descriptor (reflection) become real MapFields.
|
|
95
|
+
+ var mapTypes = {};
|
|
96
|
+
+ if (descriptor.nestedType)
|
|
97
|
+
+ for (i = 0; i < descriptor.nestedType.length; ++i)
|
|
98
|
+
+ if (descriptor.nestedType[i].options && descriptor.nestedType[i].options.mapEntry && descriptor.nestedType[i].field.length === 2)
|
|
99
|
+
+ mapTypes[descriptor.nestedType[i].name] = [
|
|
100
|
+
+ fromDescriptorType(descriptor.nestedType[i].field[0].type),
|
|
101
|
+
+ descriptor.nestedType[i].field[1].typeName ? descriptor.nestedType[i].field[1].typeName : fromDescriptorType(descriptor.nestedType[i].field[1].type)
|
|
102
|
+
+ ];
|
|
103
|
+
+
|
|
104
|
+
/* Oneofs */ if (descriptor.oneofDecl)
|
|
105
|
+
for (i = 0; i < descriptor.oneofDecl.length; ++i)
|
|
106
|
+
type.add(OneOf.fromDescriptor(descriptor.oneofDecl[i]));
|
|
107
|
+
/* Fields */ if (descriptor.field)
|
|
108
|
+
for (i = 0; i < descriptor.field.length; ++i) {
|
|
109
|
+
- var field = Field.fromDescriptor(descriptor.field[i], edition, true);
|
|
110
|
+
+ var fieldTypeName = descriptor.field[i].typeName;
|
|
111
|
+
+ var mapKv = fieldTypeName ? mapTypes[fieldTypeName] : undefined;
|
|
112
|
+
+ if (fieldTypeName && !mapKv) {
|
|
113
|
+
+ // after reflection the typeName may be just the short name
|
|
114
|
+
+ var nameParts = fieldTypeName.split("." + type.name + ".");
|
|
115
|
+
+ if (nameParts.length === 2)
|
|
116
|
+
+ mapKv = mapTypes[nameParts[1]];
|
|
117
|
+
+ }
|
|
118
|
+
+ var field = Field.fromDescriptor(descriptor.field[i], edition, true, mapKv);
|
|
119
|
+
type.add(field);
|
|
120
|
+
if (descriptor.field[i].hasOwnProperty("oneofIndex")) // eslint-disable-line no-prototype-builtins
|
|
121
|
+
type.oneofsArray[descriptor.field[i].oneofIndex].add(field);
|
|
122
|
+
@@ -257,9 +276,10 @@ Type.fromDescriptor = function fromDescriptor(descriptor, edition, nested, depth
|
|
123
|
+
type.add(Field.fromDescriptor(descriptor.extension[i], edition, true));
|
|
124
|
+
/* Nested types */ if (descriptor.nestedType)
|
|
125
|
+
for (i = 0; i < descriptor.nestedType.length; ++i) {
|
|
126
|
+
+ // map-entry types are reconstructed as MapFields above (gateway patch)
|
|
127
|
+
+ if (descriptor.nestedType[i].options && descriptor.nestedType[i].options.mapEntry && descriptor.nestedType[i].field.length === 2)
|
|
128
|
+
+ continue;
|
|
129
|
+
type.add(Type.fromDescriptor(descriptor.nestedType[i], edition, true, depth + 1));
|
|
130
|
+
- if (descriptor.nestedType[i].options && descriptor.nestedType[i].options.mapEntry)
|
|
131
|
+
- type.setOption("map_entry", true);
|
|
132
|
+
}
|
|
133
|
+
/* Nested enums */ if (descriptor.enumType)
|
|
134
|
+
for (i = 0; i < descriptor.enumType.length; ++i)
|
|
135
|
+
@@ -410,9 +430,10 @@ Type.prototype.toDescriptor = function toDescriptor(edition) {
|
|
136
|
+
* @param {IFieldDescriptorProto|Reader|Uint8Array} descriptor Descriptor
|
|
137
|
+
* @param {string} [edition="proto2"] The syntax or edition to use
|
|
138
|
+
* @param {boolean} [nested=false] Whether or not this is a top-level object
|
|
139
|
+
- * @returns {Field} Field instance
|
|
140
|
+
+ * @param {string[]} [mapKv] Key & value types for a map field (gateway patch)
|
|
141
|
+
+ * @returns {Field|MapField} Field instance
|
|
142
|
+
*/
|
|
143
|
+
-Field.fromDescriptor = function fromDescriptor(descriptor, edition, nested) {
|
|
144
|
+
+Field.fromDescriptor = function fromDescriptor(descriptor, edition, nested, mapKv) {
|
|
145
|
+
|
|
146
|
+
// Decode the descriptor message if specified as a buffer:
|
|
147
|
+
if (typeof descriptor.length === "number")
|
|
148
|
+
@@ -447,8 +468,16 @@ Field.fromDescriptor = function fromDescriptor(descriptor, edition, nested) {
|
|
149
|
+
throw Error("illegal type name: " + extendee);
|
|
150
|
+
} else
|
|
151
|
+
extendee = undefined;
|
|
152
|
+
- var field = new Field(
|
|
153
|
+
- descriptor.name.length ? descriptor.name : "field" + descriptor.number,
|
|
154
|
+
+ // gateway patch: protobufjs expects camelCased field names, while descriptors
|
|
155
|
+
+ // (reflection) carry the original proto names; build a MapField for map fields.
|
|
156
|
+
+ var fieldName = $protobuf.util.camelCase(descriptor.name.length ? descriptor.name : "field" + descriptor.number);
|
|
157
|
+
+ var field = mapKv ? new MapField(
|
|
158
|
+
+ fieldName,
|
|
159
|
+
+ descriptor.number,
|
|
160
|
+
+ mapKv[0],
|
|
161
|
+
+ mapKv[1]
|
|
162
|
+
+ ) : new Field(
|
|
163
|
+
+ fieldName,
|
|
164
|
+
descriptor.number,
|
|
165
|
+
fieldType,
|
|
166
|
+
fieldRule,
|
|
167
|
+
@@ -909,7 +938,14 @@ function fromDescriptorOptionsRecursive(obj, type) {
|
|
168
|
+
function fromDescriptorOptions(options, type) {
|
|
169
|
+
if (!options)
|
|
170
|
+
return undefined;
|
|
171
|
+
- return fromDescriptorOptionsRecursive(type.toObject(options), type);
|
|
172
|
+
+ var val = fromDescriptorOptionsRecursive(type.toObject(options), type);
|
|
173
|
+
+ // gateway patch: keep options that are not declared on the Options type
|
|
174
|
+
+ // (e.g. custom proto options) so they survive a reflection round-trip.
|
|
175
|
+
+ for (var option in options)
|
|
176
|
+
+ if (Object.prototype.hasOwnProperty.call(options, option) &&
|
|
177
|
+
+ !type._fieldsArray.some(function (f) { return f.name === option; }))
|
|
178
|
+
+ val[underScore(option)] = options[option];
|
|
179
|
+
+ return val;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function toDescriptorOptionsRecursive(obj, type) {
|
|
@@ -24,6 +24,57 @@ option java_outer_classname = "ErrorDetailsProto";
|
|
|
24
24
|
option java_package = "com.google.rpc";
|
|
25
25
|
option objc_class_prefix = "RPC";
|
|
26
26
|
|
|
27
|
+
// Describes the cause of the error with structured details.
|
|
28
|
+
//
|
|
29
|
+
// Example of an error when contacting the "pubsub.googleapis.com" API when it
|
|
30
|
+
// is not enabled:
|
|
31
|
+
//
|
|
32
|
+
// { "reason": "API_DISABLED"
|
|
33
|
+
// "domain": "googleapis.com"
|
|
34
|
+
// "metadata": {
|
|
35
|
+
// "resource": "projects/123",
|
|
36
|
+
// "service": "pubsub.googleapis.com"
|
|
37
|
+
// }
|
|
38
|
+
// }
|
|
39
|
+
//
|
|
40
|
+
// This response indicates that the pubsub.googleapis.com API is not enabled.
|
|
41
|
+
//
|
|
42
|
+
// Example of an error that is returned when attempting to create a Spanner
|
|
43
|
+
// instance in a region that is out of stock:
|
|
44
|
+
//
|
|
45
|
+
// { "reason": "STOCKOUT"
|
|
46
|
+
// "domain": "spanner.googleapis.com",
|
|
47
|
+
// "metadata": {
|
|
48
|
+
// "availableRegions": "us-central1,us-east2"
|
|
49
|
+
// }
|
|
50
|
+
// }
|
|
51
|
+
message ErrorInfo {
|
|
52
|
+
// The reason of the error. This is a constant value that identifies the
|
|
53
|
+
// proximate cause of the error. Error reasons are unique within a particular
|
|
54
|
+
// domain of errors. This should be at most 63 characters and match a
|
|
55
|
+
// regular expression of `[A-Z][A-Z0-9_]+[A-Z0-9]`, which represents
|
|
56
|
+
// UPPER_SNAKE_CASE.
|
|
57
|
+
string reason = 1;
|
|
58
|
+
|
|
59
|
+
// The logical grouping to which the "reason" belongs. The error domain
|
|
60
|
+
// is typically the registered service name of the tool or product that
|
|
61
|
+
// generates the error. Example: "pubsub.googleapis.com". If the error is
|
|
62
|
+
// generated by some common infrastructure, the error domain must be a
|
|
63
|
+
// globally unique value that identifies the infrastructure. For Google API
|
|
64
|
+
// infrastructure, the error domain is "googleapis.com".
|
|
65
|
+
string domain = 2;
|
|
66
|
+
|
|
67
|
+
// Additional structured details about this error.
|
|
68
|
+
//
|
|
69
|
+
// Keys must match a regular expression of `[a-z][a-zA-Z0-9-_]+` but should
|
|
70
|
+
// ideally be lowerCamelCase. Also, they must be limited to 64 characters in
|
|
71
|
+
// length. When identifying the current value of an exceeded limit, the units
|
|
72
|
+
// should be contained in the key, not the value. For example, rather than
|
|
73
|
+
// `{"instanceLimit": "100/request"}`, should be returned as,
|
|
74
|
+
// `{"instanceLimitPerRequest": "100"}`, if the client exceeds the number of
|
|
75
|
+
// instances that can be created in a single (batch) request.
|
|
76
|
+
map<string, string> metadata = 3;
|
|
77
|
+
}
|
|
27
78
|
|
|
28
79
|
// Describes when the clients can retry a failed request. Clients could ignore
|
|
29
80
|
// the recommendation here or retry when this information is missing from error
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
diff --git a/node_modules/protobufjs/ext/descriptor/index.js b/node_modules/protobufjs/ext/descriptor/index.js
|
|
2
|
-
index 6aafd2a..b8e9f58 100644
|
|
3
|
-
--- a/node_modules/protobufjs/ext/descriptor/index.js
|
|
4
|
-
+++ b/node_modules/protobufjs/ext/descriptor/index.js
|
|
5
|
-
@@ -204,6 +204,8 @@ Type.fromDescriptor = function fromDescriptor(descriptor, syntax) {
|
|
6
|
-
if (typeof descriptor.length === "number")
|
|
7
|
-
descriptor = exports.DescriptorProto.decode(descriptor);
|
|
8
|
-
|
|
9
|
-
+ // record mapTypes for map fields
|
|
10
|
-
+ var mapTypes = {};
|
|
11
|
-
// Create the message type
|
|
12
|
-
var type = new Type(descriptor.name.length ? descriptor.name : "Type" + unnamedMessageIndex++, fromDescriptorOptions(descriptor.options, exports.MessageOptions)),
|
|
13
|
-
i;
|
|
14
|
-
@@ -211,9 +213,34 @@ Type.fromDescriptor = function fromDescriptor(descriptor, syntax) {
|
|
15
|
-
/* Oneofs */ if (descriptor.oneofDecl)
|
|
16
|
-
for (i = 0; i < descriptor.oneofDecl.length; ++i)
|
|
17
|
-
type.add(OneOf.fromDescriptor(descriptor.oneofDecl[i]));
|
|
18
|
-
+ /* Nested types */ if (descriptor.nestedType)
|
|
19
|
-
+ for (i = 0; i < descriptor.nestedType.length; ++i) {
|
|
20
|
-
+ if (descriptor.nestedType[i].options && descriptor.nestedType[i].options.mapEntry && descriptor.nestedType[i].field.length === 2){
|
|
21
|
-
+ mapTypes[descriptor.nestedType[i].name] = [fromDescriptorType(descriptor.nestedType[i].field[0].type), descriptor.nestedType[i].field[1].typeName ? descriptor.nestedType[i].field[1].typeName : fromDescriptorType(descriptor.nestedType[i].field[1].type)];
|
|
22
|
-
+ }else{
|
|
23
|
-
+ type.add(Type.fromDescriptor(descriptor.nestedType[i], syntax));
|
|
24
|
-
+ }
|
|
25
|
-
+ }
|
|
26
|
-
/* Fields */ if (descriptor.field)
|
|
27
|
-
for (i = 0; i < descriptor.field.length; ++i) {
|
|
28
|
-
- var field = Field.fromDescriptor(descriptor.field[i], syntax);
|
|
29
|
-
+ var field = null;
|
|
30
|
-
+ while(!field) {
|
|
31
|
-
+ if(descriptor.field[i].typeName) {
|
|
32
|
-
+ // after reflection in typeName maybe just short type name
|
|
33
|
-
+ var foundedKvType = mapTypes[descriptor.field[i].typeName];
|
|
34
|
-
+ if (!foundedKvType) {
|
|
35
|
-
+ var nameParts = descriptor.field[i].typeName.split("."+type.name+".");
|
|
36
|
-
+ if (nameParts.length===2) {
|
|
37
|
-
+ foundedKvType = mapTypes[nameParts[1]];
|
|
38
|
-
+ }
|
|
39
|
-
+ }
|
|
40
|
-
+ if(foundedKvType) {
|
|
41
|
-
+ field = Field.fromDescriptor(descriptor.field[i], syntax, foundedKvType);
|
|
42
|
-
+ break;
|
|
43
|
-
+ }
|
|
44
|
-
+ }
|
|
45
|
-
+ field = Field.fromDescriptor(descriptor.field[i], syntax);
|
|
46
|
-
+ }
|
|
47
|
-
type.add(field);
|
|
48
|
-
if (descriptor.field[i].hasOwnProperty("oneofIndex")) // eslint-disable-line no-prototype-builtins
|
|
49
|
-
type.oneofsArray[descriptor.field[i].oneofIndex].add(field);
|
|
50
|
-
@@ -221,12 +248,6 @@ Type.fromDescriptor = function fromDescriptor(descriptor, syntax) {
|
|
51
|
-
/* Extension fields */ if (descriptor.extension)
|
|
52
|
-
for (i = 0; i < descriptor.extension.length; ++i)
|
|
53
|
-
type.add(Field.fromDescriptor(descriptor.extension[i], syntax));
|
|
54
|
-
- /* Nested types */ if (descriptor.nestedType)
|
|
55
|
-
- for (i = 0; i < descriptor.nestedType.length; ++i) {
|
|
56
|
-
- type.add(Type.fromDescriptor(descriptor.nestedType[i], syntax));
|
|
57
|
-
- if (descriptor.nestedType[i].options && descriptor.nestedType[i].options.mapEntry)
|
|
58
|
-
- type.setOption("map_entry", true);
|
|
59
|
-
- }
|
|
60
|
-
/* Nested enums */ if (descriptor.enumType)
|
|
61
|
-
for (i = 0; i < descriptor.enumType.length; ++i)
|
|
62
|
-
type.add(Enum.fromDescriptor(descriptor.enumType[i]));
|
|
63
|
-
@@ -375,9 +396,10 @@ var numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/;
|
|
64
|
-
* Creates a field from a descriptor.
|
|
65
|
-
* @param {IFieldDescriptorProto|Reader|Uint8Array} descriptor Descriptor
|
|
66
|
-
* @param {string} [syntax="proto2"] Syntax
|
|
67
|
-
- * @returns {Field} Field instance
|
|
68
|
-
+ * @param {string[]} mapKv Key & value types for map field
|
|
69
|
-
+ * @returns {Field|MapField} Field instance
|
|
70
|
-
*/
|
|
71
|
-
-Field.fromDescriptor = function fromDescriptor(descriptor, syntax) {
|
|
72
|
-
+Field.fromDescriptor = function fromDescriptor(descriptor, syntax, mapKv) {
|
|
73
|
-
|
|
74
|
-
// Decode the descriptor message if specified as a buffer:
|
|
75
|
-
if (typeof descriptor.length === "number")
|
|
76
|
-
@@ -407,8 +429,16 @@ Field.fromDescriptor = function fromDescriptor(descriptor, syntax) {
|
|
77
|
-
if (descriptor.extendee !== undefined) {
|
|
78
|
-
extendee = extendee.length ? extendee : undefined;
|
|
79
|
-
}
|
|
80
|
-
- var field = new Field(
|
|
81
|
-
- descriptor.name.length ? descriptor.name : "field" + descriptor.number,
|
|
82
|
-
+
|
|
83
|
-
+ var rawFieldName = descriptor.name.length ? descriptor.name : "field" + descriptor.number;
|
|
84
|
-
+ var fieldName = $protobuf.util.camelCase(rawFieldName);
|
|
85
|
-
+ var field = mapKv ? new MapField(
|
|
86
|
-
+ fieldName,
|
|
87
|
-
+ descriptor.number,
|
|
88
|
-
+ mapKv[0],
|
|
89
|
-
+ mapKv[1]
|
|
90
|
-
+ ) : new Field(
|
|
91
|
-
+ fieldName,
|
|
92
|
-
descriptor.number,
|
|
93
|
-
fieldType,
|
|
94
|
-
fieldRule,
|
|
95
|
-
@@ -816,6 +846,12 @@ function fromDescriptorOptions(options, type) {
|
|
96
|
-
val = field.resolvedType.valuesById[val];
|
|
97
|
-
out.push(underScore(key), val);
|
|
98
|
-
}
|
|
99
|
-
+
|
|
100
|
-
+ for (var option in options) {
|
|
101
|
-
+ if (!type._fieldsArray.find(({name}) => name === option) && options.hasOwnProperty(option)) {
|
|
102
|
-
+ out.push(underScore(option), options[option]);
|
|
103
|
-
+ }
|
|
104
|
-
+ }
|
|
105
|
-
return out.length ? $protobuf.util.toObject(out) : undefined;
|
|
106
|
-
}
|
|
107
|
-
|