Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"license": "MIT",
"dependencies": {
"@types/google-protobuf": "^3.7.2",
"@types/lodash.set": "^4.3.6",
"google-protobuf": "^3.12.2",
"lodash.set": "^4.3.2",
"protobufjs": "^7.2.2"
},
"devDependencies": {
Expand Down Expand Up @@ -62,4 +60,4 @@
"peerDependencies": {
"@grpc/grpc-js": "^1.0.0"
}
}
}
3 changes: 1 addition & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ChannelCredentials, Metadata, ServiceError} from '@grpc/grpc-js';
import {getDescriptorRootFromDescriptorSet} from './descriptor';
import {getDescriptorRootFromDescriptorSet, set} from './descriptor';
import * as services from './reflection_grpc_pb';
import {
ServerReflectionRequest,
Expand All @@ -11,7 +11,6 @@ import {
IFileDescriptorProto,
FileDescriptorProto,
} from 'protobufjs/ext/descriptor';
import set from 'lodash.set';

export class Client {
metadata: Metadata;
Expand Down
12 changes: 11 additions & 1 deletion src/descriptor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
const protobuf = require('protobufjs');
const Descriptor = require('protobufjs/ext/descriptor');
const set = require('lodash.set');

// eslint-disable-next-line node/no-unsupported-features/es-syntax
export function set(obj, path, value) {
// Regex explained: https://regexr.com/58j0k
const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g);

pathArray.reduce((acc, key, i) => {
if (acc[key] === undefined) acc[key] = {};
if (i === pathArray.length - 1) acc[key] = value;
return acc[key];
}, obj);
}
/**
* @typedef {import('protobufjs').Root} Root
* @typedef {import('protobufjs').Message} Message
Expand Down
2 changes: 1 addition & 1 deletion test/descriptor.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
getDescriptorRoot,
getDescriptorRootFromDescriptorSet,
set,
} from '../src/descriptor';
// eslint-disable-next-line node/no-unpublished-import
import {assert} from 'chai';
import {
FileDescriptorProto,
FileDescriptorSet,
} from 'protobufjs/ext/descriptor';
import set from 'lodash.set';

// eslint-disable-next-line prettier/prettier
const protoBytes = Buffer.from([10,11,112,104,111,110,101,46,112,114,111,116,111,18,5,112,104,111,110,101,34,55,10,11,84,101,120,116,82,101,113,117,101,115,116,18,14,10,2,105,100,24,1,32,1,40,9,82,2,105,100,18,24,10,7,109,101,115,115,97,103,101,24,2,32,1,40,9,82,7,109,101,115,115,97,103,101,34,40,10,12,84,101,120,116,82,101,115,112,111,110,115,101,18,24,10,7,115,117,99,99,101,115,115,24,1,32,1,40,8,82,7,115,117,99,99,101,115,115,50,63,10,9,77,101,115,115,101,110,103,101,114,18,50,10,7,77,101,115,115,97,103,101,18,18,46,112,104,111,110,101,46,84,101,120,116,82,101,113,117,101,115,116,26,19,46,112,104,111,110,101,46,84,101,120,116,82,101,115,112,111,110,115,101,98,6,112,114,111,116,111,51]);
Expand Down
19 changes: 1 addition & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -421,18 +421,6 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.12.tgz#d70faba7039d5fca54c83c7dbab41051d2b6f6cb"
integrity sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==

"@types/lodash.set@^4.3.6":
version "4.3.6"
resolved "https://registry.npmjs.org/@types/lodash.set/-/lodash.set-4.3.6.tgz"
integrity sha512-ZeGDDlnRYTvS31Laij0RsSaguIUSBTYIlJFKL3vm3T2OAZAQj2YpSvVWJc0WiG4jqg9fGX6PAPGvDqBcHfSgFg==
dependencies:
"@types/lodash" "*"

"@types/lodash@*":
version "4.14.162"
resolved "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.162.tgz"
integrity sha512-alvcho1kRUnnD1Gcl4J+hK0eencvzq9rmzvFPRmP5rPHx9VVsJj6bKLTATPVf9ktgv4ujzh7T+XWKp+jhuODig==

"@types/long@^4.0.1":
version "4.0.2"
resolved "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz"
Expand Down Expand Up @@ -2303,19 +2291,14 @@ lodash.merge@^4.6.2:
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==

lodash.set@^4.3.2:
version "4.3.2"
resolved "https://registry.npmjs.org/lodash.set/-/lodash.set-4.3.2.tgz"
integrity sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM=

lodash.truncate@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193"
integrity sha512-jttmRe7bRse52OsWIMDLaXxWqRAmtIUccAQ3garviCqJjafXOfNMO0yMfNpdD6zbGaTU0P5Nz7e7gAT6cKmJRw==

lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19:
version "4.17.21"
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

[email protected]:
Expand Down