grpc-js-core: remove simple uses of lodash

This commit removes lodash as a production dependency. It
remains as a devDependency because it's used in tests, but the
uses in the src/ directory were easily replaced with vanilla
JavaScript.
This commit is contained in:
cjihrig 2018-10-31 16:57:01 -04:00
parent 9a92764f94
commit 493ca2fec4
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
4 changed files with 18 additions and 14 deletions

View File

@ -20,6 +20,7 @@
"@types/node": "^10.5.4",
"clang-format": "^1.0.55",
"gts": "^0.5.1",
"lodash": "^4.17.4",
"typescript": "~2.7.0"
},
"contributors": [
@ -41,7 +42,6 @@
"posttest": "npm run check"
},
"dependencies": {
"lodash": "^4.17.4",
"semver": "^5.5.0"
},
"files": [

View File

@ -1,5 +1,3 @@
import {map} from 'lodash';
import {Metadata} from './metadata';
export type CallMetadataOptions = {
@ -53,7 +51,7 @@ class ComposedCallCredentials extends CallCredentials {
async generateMetadata(options: CallMetadataOptions): Promise<Metadata> {
const base: Metadata = new Metadata();
const generated: Metadata[] = await Promise.all(
map(this.creds, (cred) => cred.generateMetadata(options)));
this.creds.map((cred) => cred.generateMetadata(options)));
for (const gen of generated) {
base.merge(gen);
}

View File

@ -1,5 +1,3 @@
import {map} from 'lodash';
import {Call, StatusObject, WriteObject} from './call-stream';
import {Filter, FilterFactory} from './filter';
import {Metadata} from './metadata';
@ -63,6 +61,6 @@ export class FilterStackFactory implements FilterFactory<FilterStack> {
createFilter(callStream: Call): FilterStack {
return new FilterStack(
map(this.factories, (factory) => factory.createFilter(callStream)));
this.factories.map((factory) => factory.createFilter(callStream)));
}
}

View File

@ -1,5 +1,3 @@
import * as _ from 'lodash';
import {ChannelCredentials} from './channel-credentials';
import {ChannelOptions} from './channel-options';
import {Client} from './client';
@ -73,10 +71,11 @@ export function makeClientConstructor(
[methodName: string]: Function;
}
_.each(methods, (attrs, name) => {
Object.keys(methods).forEach((name) => {
const attrs = methods[name];
let methodType: keyof typeof requesterFuncs;
// TODO(murgatroid99): Verify that we don't need this anymore
if (_.startsWith(name, '$')) {
if (typeof name === 'string' && name.charAt(0) === '$') {
throw new Error('Method names cannot start with $');
}
if (attrs.requestStream) {
@ -94,11 +93,11 @@ export function makeClientConstructor(
}
const serialize = attrs.requestSerialize;
const deserialize = attrs.responseDeserialize;
const methodFunc = _.partial(
requesterFuncs[methodType], attrs.path, serialize, deserialize);
const methodFunc =
partial(requesterFuncs[methodType], attrs.path, serialize, deserialize);
ServiceClientImpl.prototype[name] = methodFunc;
// Associate all provided attributes with the method
_.assign(ServiceClientImpl.prototype[name], attrs);
Object.assign(ServiceClientImpl.prototype[name], attrs);
if (attrs.originalName) {
ServiceClientImpl.prototype[attrs.originalName] =
ServiceClientImpl.prototype[name];
@ -110,6 +109,15 @@ export function makeClientConstructor(
return ServiceClientImpl;
}
function partial(
fn: Function, path: string, serialize: Function,
deserialize: Function): Function {
// tslint:disable-next-line:no-any
return function(this: any, ...args: any[]) {
return fn.call(this, path, serialize, deserialize, ...args);
};
}
export type GrpcObject = {
[index: string]: GrpcObject|ServiceClientConstructor;
};