Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: drop extend and lodash.flatten #345

Merged
merged 2 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
"@grpc/grpc-js": "^0.3.0",
"@grpc/proto-loader": "^0.3.0",
"duplexify": "^3.6.0",
"extend": "^3.0.1",
"globby": "^8.0.1",
"google-auth-library": "^2.0.0",
"google-proto-files": "^0.17.0",
"grpc": "^1.15.1",
"is-stream-ended": "^0.1.4",
"lodash.at": "^4.6.0",
"lodash.flatten": "^4.4.0",
"lodash.has": "^4.5.2",
"protobufjs": "^6.8.8",
"retry-request": "^4.0.0",
Expand All @@ -27,10 +25,8 @@
"devDependencies": {
"@types/chai": "^4.1.3",
"@types/duplexify": "^3.5.0",
"@types/extend": "^3.0.0",
"@types/globby": "^8.0.0",
"@types/lodash.at": "^4.6.4",
"@types/lodash.flatten": "^4.4.4",
"@types/lodash.has": "^4.5.4",
"@types/mocha": "^5.2.1",
"@types/node": "^10.3.2",
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import * as extend from 'extend';

import {GrpcClient, GrpcClientOptions} from './grpc';
import * as operationsClient from './operations_client';
import * as routingHeader from './routing_header';
Expand All @@ -48,7 +46,7 @@ export {StreamDescriptor, StreamType} from './streaming';
export {routingHeader};

function lro(options: GrpcClientOptions) {
options = extend({scopes: lro.ALL_SCOPES}, options);
options = Object.assign({scopes: lro.ALL_SCOPES}, options);
const gaxGrpc = new GrpcClient(options);
return new operationsClient.OperationsClientBuilder(gaxGrpc);
}
Expand Down
14 changes: 6 additions & 8 deletions src/operations_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@
* merge preserves those additions if the generated source changes.
*/

import * as extend from 'extend';

import * as apiCallable from './api_callable';
import * as gax from './gax';
import * as pagedIteration from './paged_iteration';
import * as pathTemplate from './path_template';

const configData = require('./operations_client_config');

extend(gax, apiCallable);
extend(gax, pathTemplate);
extend(gax, pagedIteration);
Object.assign(gax, apiCallable);
Object.assign(gax, pathTemplate);
Object.assign(gax, pagedIteration);

export const SERVICE_ADDRESS = 'longrunning.googleapis.com';

Expand Down Expand Up @@ -76,7 +74,7 @@ export class OperationsClient {
auth;

constructor(gaxGrpc, grpcClients, opts) {
opts = extend(
opts = Object.assign(
{
servicePath: SERVICE_ADDRESS,
port: DEFAULT_SERVICE_PORT,
Expand Down Expand Up @@ -438,7 +436,7 @@ export class OperationsClientBuilder {
const protoFilesRoot = require('google-proto-files')('..');
const operationsClient = gaxGrpc.loadProto(
protoFilesRoot, 'google/longrunning/operations.proto');
extend(this, operationsClient.google.longrunning);
Object.assign(this, operationsClient.google.longrunning);

/**
* Build a new instance of {@link OperationsClient}.
Expand All @@ -457,6 +455,6 @@ export class OperationsClientBuilder {
this['operationsClient'] = opts => {
return new OperationsClient(gaxGrpc, operationsClient, opts);
};
extend(this['operationsClient'], OperationsClient);
Object.assign(this['operationsClient'], OperationsClient);
}
}
5 changes: 2 additions & 3 deletions src/paged_iteration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import * as extend from 'extend';
import * as ended from 'is-stream-ended';
import {PassThrough, Transform} from 'stream';

Expand Down Expand Up @@ -83,7 +82,7 @@ export class PagedIteration extends NormalApiCaller {
}

call(apiCall: APICall, argument: {[index: string]: {}}, settings, canceller) {
argument = extend({}, argument);
argument = Object.assign({}, argument);
if (settings.pageToken) {
argument[this.pageDescriptor.requestPageTokenField] = settings.pageToken;
}
Expand Down Expand Up @@ -160,7 +159,7 @@ export class PageDescriptor {
*/
createStream(apiCall, request, options): Transform {
const stream = new PassThrough({objectMode: true});
options = extend({}, options, {autoPaginate: false});
options = Object.assign({}, options, {autoPaginate: false});
const maxResults = 'maxResults' in options ? options.maxResults : -1;
let pushCount = 0;
let started = false;
Expand Down
5 changes: 2 additions & 3 deletions src/path_template_parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
*/

{
const flatten = require('lodash.flatten');
const extras = require('./parser_extras');
}

Expand All @@ -55,11 +54,11 @@ bound_segment

variable
= '{' l:literal '=' segments:unbound_segments '}' {
return flatten([
return ([
{ kind: extras.BINDING, literal: l },
segments,
{ kind: extras.END_BINDING, literal: '' }
]);
]).reduce((a, b) => a.concat(b), []);
}
/ '{' l:literal '}' {
return [
Expand Down
12 changes: 6 additions & 6 deletions src/path_template_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ module.exports = (() => {
const peg$c9 = '}';
const peg$c10 = {type: 'literal', value: '}', description: '"}"'};
const peg$c11 = (l, segments) => {
return flatten([
{kind: extras.BINDING, literal: l},
segments,
{kind: extras.END_BINDING, literal: ''},
]);
return ([
{kind: extras.BINDING, literal: l},
segments,
{kind: extras.END_BINDING, literal: ''},
])
.reduce((a, b) => a.concat(b), []);
};
const peg$c12 = l => {
return [
Expand Down Expand Up @@ -617,7 +618,6 @@ module.exports = (() => {
return s0;
}

const flatten = require('lodash.flatten');
const extras = require('./parser_extras');

peg$result = peg$startRuleFunction();
Expand Down