@gravity-ui/gateway 2.5.3 → 2.5.4

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.
@@ -75,16 +75,10 @@ function decodeResponse(response, packageRoot, ctx, encodedFields = [], ErrorCon
75
75
  const systemFields = ['metadata', 'response', 'error.details'];
76
76
  [...systemFields, ...encodedFields].forEach((fieldName) => {
77
77
  try {
78
- const traverseRegExp = /\.\*$/;
79
- const needTraverse = traverseRegExp.test(fieldName);
80
- const parsedFieldName = needTraverse
81
- ? fieldName.replace(traverseRegExp, '')
82
- : fieldName;
78
+ const parsedFieldName = fieldName.replace(/\.\*$/, '');
83
79
  const fieldValue = lodash_1.default.get(response, parsedFieldName);
84
80
  if (fieldValue) {
85
- lodash_1.default.set(response, parsedFieldName, needTraverse
86
- ? (0, grpc_1.traverseAnyMessage)(packageRoot, fieldValue)
87
- : (0, grpc_1.decodeAnyMessageRecursively)(packageRoot, fieldValue));
81
+ lodash_1.default.set(response, parsedFieldName, (0, grpc_1.decodeAnyMessageRecursively)(packageRoot, fieldValue));
88
82
  }
89
83
  }
90
84
  catch (error) {
@@ -1,15 +1,5 @@
1
- /// <reference types="node" />
2
1
  import * as grpc from '@grpc/grpc-js';
3
2
  import * as protobufjs from 'protobufjs';
4
- export declare function decodeAnyMessageRecursively(root: protobufjs.Root, message?: {
5
- type_url?: string;
6
- value?: Buffer;
7
- }): {
8
- type_url?: string | undefined;
9
- value?: Buffer | undefined;
10
- } | {
11
- [k: string]: any;
12
- } | undefined;
13
- export declare function traverseAnyMessage(root: protobufjs.Root, message?: any): any;
3
+ export declare function decodeAnyMessageRecursively(root: protobufjs.Root, message?: unknown): unknown;
14
4
  export declare function isRetryableError(error?: grpc.ServiceError): boolean;
15
5
  export declare function isRecreateServiceError(error?: grpc.ServiceError): boolean;
@@ -1,49 +1,34 @@
1
1
  "use strict";
2
2
  /* eslint-disable camelcase */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.isRecreateServiceError = exports.isRetryableError = exports.traverseAnyMessage = exports.decodeAnyMessageRecursively = void 0;
4
+ exports.isRecreateServiceError = exports.isRetryableError = exports.decodeAnyMessageRecursively = void 0;
5
5
  const constants_1 = require("../constants");
6
+ function isEncodedMessage(message) {
7
+ return Boolean(message.type_url && message.value);
8
+ }
6
9
  function decodeAnyMessageRecursively(root, message) {
7
- if (!message || !message.type_url || !message.value) {
10
+ if (!message || typeof message !== 'object') {
8
11
  return message;
9
12
  }
13
+ if (Array.isArray(message)) {
14
+ return message.map((innerMessage) => decodeAnyMessageRecursively(root, innerMessage));
15
+ }
16
+ if (typeof message === 'object' && !isEncodedMessage(message)) {
17
+ return Object.entries(message).reduce((res, [key, value]) => {
18
+ res[key] = decodeAnyMessageRecursively(root, value);
19
+ return res;
20
+ }, {});
21
+ }
10
22
  const lastSlashIndex = message.type_url.lastIndexOf('/');
11
23
  if (lastSlashIndex < 0) {
12
24
  return message;
13
25
  }
14
26
  const typeName = message.type_url.substring(lastSlashIndex + 1);
15
27
  const type = root.lookupType(typeName);
16
- const data = type.toObject(type.decode(message.value), constants_1.DEFAULT_PROTO_LOADER_OPTIONS);
17
- Object.keys(data).forEach((key) => {
18
- if (Array.isArray(data[key])) {
19
- data[key] = data[key].map((item) => decodeAnyMessageRecursively(root, item));
20
- }
21
- else {
22
- data[key] = decodeAnyMessageRecursively(root, data[key]);
23
- }
24
- });
25
- return data;
28
+ const decodedMessage = type.toObject(type.decode(message.value), constants_1.DEFAULT_PROTO_LOADER_OPTIONS);
29
+ return decodeAnyMessageRecursively(root, decodedMessage);
26
30
  }
27
31
  exports.decodeAnyMessageRecursively = decodeAnyMessageRecursively;
28
- function traverseAnyMessage(root, message) {
29
- if (!message) {
30
- return message;
31
- }
32
- if (Array.isArray(message)) {
33
- return message.map((item) => {
34
- return traverseAnyMessage(root, item);
35
- });
36
- }
37
- if (typeof message === 'object') {
38
- Object.keys(message).forEach((key) => {
39
- if (message[key]) {
40
- message[key] = traverseAnyMessage(root, message[key]);
41
- }
42
- });
43
- }
44
- return decodeAnyMessageRecursively(root, message);
45
- }
46
- exports.traverseAnyMessage = traverseAnyMessage;
47
32
  function isRetryableError(error) {
48
33
  if (!error) {
49
34
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/gateway",
3
- "version": "2.5.3",
3
+ "version": "2.5.4",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/index.js",