diff --git a/package.json b/package.json index 23df8fa..993329c 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -62,4 +60,4 @@ "peerDependencies": { "@grpc/grpc-js": "^1.0.0" } -} +} \ No newline at end of file diff --git a/src/client.ts b/src/client.ts index 50cf798..2c8a438 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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, @@ -11,7 +11,6 @@ import { IFileDescriptorProto, FileDescriptorProto, } from 'protobufjs/ext/descriptor'; -import set from 'lodash.set'; export class Client { metadata: Metadata; diff --git a/src/descriptor.js b/src/descriptor.js index 58b24c7..0617937 100644 --- a/src/descriptor.js +++ b/src/descriptor.js @@ -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 diff --git a/test/descriptor.test.ts b/test/descriptor.test.ts index bc5b82b..0c55545 100644 --- a/test/descriptor.test.ts +++ b/test/descriptor.test.ts @@ -1,6 +1,7 @@ import { getDescriptorRoot, getDescriptorRootFromDescriptorSet, + set, } from '../src/descriptor'; // eslint-disable-next-line node/no-unpublished-import import {assert} from 'chai'; @@ -8,7 +9,6 @@ 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]); diff --git a/yarn.lock b/yarn.lock index 4a16531..aca6ddd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -2303,11 +2291,6 @@ 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" @@ -2315,7 +2298,7 @@ lodash.truncate@^4.4.2: 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== log-symbols@3.0.0: