Skip to content

Commit

Permalink
refactor: remove dependency on extend (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Nov 10, 2018
1 parent 610eca7 commit 123d04e
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 46 deletions.
5 changes: 2 additions & 3 deletions packages/google-cloud-dns/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules/*
samples/node_modules/*
src/**/doc/*
**/node_modules
build/
docs/
4 changes: 1 addition & 3 deletions packages/google-cloud-dns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"system-test": "mocha build/system-test --timeout 600000",
"clean": "gts clean",
"compile": "tsc -p .",
"fix": "eslint --fix 'samples/**/*.js' && gts fix",
"fix": "eslint --fix '**/*.js' && gts fix",
"prepare": "npm run compile",
"pretest": "npm run compile"
},
Expand All @@ -49,15 +49,13 @@
"@google-cloud/promisify": "^0.3.0",
"arrify": "^1.0.1",
"dns-zonefile": "0.2.2",
"extend": "^3.0.0",
"lodash.groupby": "^4.6.0",
"string-format-obj": "^1.1.1",
"teeny-request": "^3.6.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^2.3.0",
"@types/arrify": "^1.0.4",
"@types/extend": "^3.0.0",
"@types/lodash.groupby": "^4.6.4",
"@types/mocha": "^5.2.5",
"@types/node": "^10.9.4",
Expand Down
3 changes: 1 addition & 2 deletions packages/google-cloud-dns/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {GoogleAuthOptions, Service} from '@google-cloud/common';
import {paginator} from '@google-cloud/paginator';
import {promisifyAll} from '@google-cloud/promisify';
import * as arrify from 'arrify';
import * as extend from 'extend';
import * as r from 'request';
import {Stream} from 'stream';
import {teenyRequest} from 'teeny-request';
Expand Down Expand Up @@ -323,7 +322,7 @@ class DNS extends Service {
});
let nextQuery: GetZonesRequest|null = null;
if (resp.nextPageToken) {
nextQuery = extend({}, query, {
nextQuery = Object.assign({}, query, {
pageToken: resp.nextPageToken,
});
}
Expand Down
6 changes: 2 additions & 4 deletions packages/google-cloud-dns/src/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

import {promisifyAll} from '@google-cloud/promisify';
import * as arrify from 'arrify';
import * as extend from 'extend';

import {Change, CreateChangeCallback} from './change';
import {Zone} from './zone';

Expand Down Expand Up @@ -103,7 +101,7 @@ export class Record implements RecordObject {
* @property {number} metadata.ttl
*/
this.metadata = metadata;
extend(this, this.toJSON());
Object.assign(this, this.toJSON());
if (this.rrdatas) {
/**
* @name Record#data
Expand Down Expand Up @@ -162,7 +160,7 @@ export class Record implements RecordObject {
* @returns {object}
*/
toJSON() {
const recordObject: RecordObject = extend({}, this.metadata, {
const recordObject: RecordObject = Object.assign({}, this.metadata, {
type: this.type.toUpperCase(),
});
if (recordObject.data) {
Expand Down
11 changes: 5 additions & 6 deletions packages/google-cloud-dns/src/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {DeleteCallback, ServiceObject} from '@google-cloud/common';
import {paginator} from '@google-cloud/paginator';
import {promisifyAll} from '@google-cloud/promisify';
import * as arrify from 'arrify';
import * as extend from 'extend';
import * as fs from 'fs';

import groupBy = require('lodash.groupby');
Expand Down Expand Up @@ -433,7 +432,7 @@ class Zone extends ServiceObject {
// tslint:disable-next-line:forin
for (const recordName in recordsByName) {
const records = recordsByName[recordName];
const templateRecord = extend({}, records[0]);
const templateRecord = Object.assign({}, records[0]);
if (records.length > 1) {
// Combine the `rrdatas` values from all records of the same type.
templateRecord.rrdatas =
Expand All @@ -445,7 +444,7 @@ class Zone extends ServiceObject {
}
return recordsOut;
};
const body = extend(
const body = Object.assign(
{
additions: groupByType(arrify(config.add).map(x => x.toJSON())),
deletions: groupByType(arrify(config.delete).map(x => x.toJSON())),
Expand Down Expand Up @@ -774,7 +773,7 @@ class Zone extends ServiceObject {
});
let nextQuery = null;
if (resp.nextPageToken) {
nextQuery = extend({}, query, {
nextQuery = Object.assign({}, query, {
pageToken: resp.nextPageToken,
});
}
Expand Down Expand Up @@ -899,7 +898,7 @@ class Zone extends ServiceObject {
filterByTypes_,
};
}
const requestQuery = extend({}, query) as GetRecordsRequest;
const requestQuery = Object.assign({}, query) as GetRecordsRequest;
delete requestQuery.filterByTypes_;
this.request(
{
Expand All @@ -921,7 +920,7 @@ class Zone extends ServiceObject {
}
let nextQuery: {}|null = null;
if (resp.nextPageToken) {
nextQuery = extend({}, query, {
nextQuery = Object.assign({}, query, {
pageToken: resp.nextPageToken,
});
}
Expand Down
1 change: 0 additions & 1 deletion packages/google-cloud-dns/system-test/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
env:
mocha: true
rules:
node/no-unpublished-require: off
no-console: off
2 changes: 0 additions & 2 deletions packages/google-cloud-dns/test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
---
env:
mocha: true
rules:
node/no-unpublished-require: off
3 changes: 1 addition & 2 deletions packages/google-cloud-dns/test/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import {ServiceObject, ServiceObjectConfig} from '@google-cloud/common';
import * as promisify from '@google-cloud/promisify';
import * as assert from 'assert';
import * as extend from 'extend';
import * as proxyquire from 'proxyquire';
import {Response} from 'request';

import {Change} from '../src/change';

let promisified = false;
const fakePromisify = extend({}, promisify, {
const fakePromisify = Object.assign({}, promisify, {
promisifyAll(esClass: Function) {
if (esClass.name === 'Change') {
promisified = true;
Expand Down
24 changes: 11 additions & 13 deletions packages/google-cloud-dns/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {Service, ServiceConfig, ServiceOptions, util} from '@google-cloud/common
import * as promisify from '@google-cloud/promisify';
import * as arrify from 'arrify';
import * as assert from 'assert';
import * as extend from 'extend';
import * as proxyquire from 'proxyquire';
import {CoreOptions, OptionsWithUri, Response} from 'request';

Expand Down Expand Up @@ -50,13 +49,13 @@ class FakeService extends Service {
}
}

const fakeUtil = extend({}, util, {
const fakeUtil = Object.assign({}, util, {
makeAuthenticatedRequestFactory() {},
});
const originalFakeUtil = extend(true, {}, fakeUtil);
const originalFakeUtil = Object.assign({}, fakeUtil);

let promisified = false;
const fakePromisify = extend({}, promisify, {
const fakePromisify = Object.assign({}, promisify, {
// tslint:disable-next-line:variable-name
promisifyAll(esClass: Function, options: promisify.PromisifyAllOptions) {
if (esClass.name !== 'DNS') {
Expand Down Expand Up @@ -96,7 +95,7 @@ describe('DNS', () => {
});

beforeEach(() => {
extend(fakeUtil, originalFakeUtil);
Object.assign(fakeUtil, originalFakeUtil);
dns = new DNS({
projectId: PROJECT_ID,
});
Expand Down Expand Up @@ -152,7 +151,7 @@ describe('DNS', () => {
});

it('should use a provided description', done => {
const cfg = extend({}, config, {description: 'description'});
const cfg = Object.assign({}, config, {description: 'description'});

dns.request = (reqOpts: CoreOptions) => {
assert.strictEqual(reqOpts.json.description, cfg.description);
Expand All @@ -175,7 +174,7 @@ describe('DNS', () => {
dns.request = (reqOpts: OptionsWithUri) => {
assert.strictEqual(reqOpts.method, 'POST');
assert.strictEqual(reqOpts.uri, '/managedZones');
const expectedBody = extend({}, config, {
const expectedBody = Object.assign({}, config, {
name: zoneName,
description: '',
});
Expand Down Expand Up @@ -327,12 +326,12 @@ describe('DNS', () => {
});

it('should set a nextQuery if necessary', done => {
const apiResponseWithNextPageToken = extend({}, apiResponse, {
const apiResponseWithNextPageToken = Object.assign({}, apiResponse, {
nextPageToken: 'next-page-token',
});

const query = {a: 'b', c: 'd'};
const originalQuery = extend({}, query);
const originalQuery = Object.assign({}, query);

dns.request = (reqOpts: {}, callback: Function) => {
callback(null, apiResponseWithNextPageToken);
Expand All @@ -344,10 +343,9 @@ describe('DNS', () => {
// Check the original query wasn't modified.
assert.deepStrictEqual(query, originalQuery);

assert.deepStrictEqual(
nextQuery, extend({}, query, {
pageToken: apiResponseWithNextPageToken.nextPageToken,
}));
assert.deepStrictEqual(nextQuery, Object.assign({}, query, {
pageToken: apiResponseWithNextPageToken.nextPageToken,
}));

done();
});
Expand Down
7 changes: 3 additions & 4 deletions packages/google-cloud-dns/test/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

import * as promisify from '@google-cloud/promisify';
import * as assert from 'assert';
import * as extend from 'extend';
import * as proxyquire from 'proxyquire';

import {Record} from '../src';

let promisified = false;
const fakePromisify = extend({}, promisify, {
const fakePromisify = Object.assign({}, promisify, {
promisifyAll(esClass: Function, options: promisify.PromisifyAllOptions) {
if (esClass.name !== 'Record') {
return;
Expand Down Expand Up @@ -304,7 +303,7 @@ describe('Record', () => {

describe('toJSON', () => {
it('should format the data for the API', () => {
const expectedRecord = extend({}, METADATA, {
const expectedRecord = Object.assign({}, METADATA, {
type: 'A',
rrdatas: METADATA.data,
});
Expand All @@ -316,7 +315,7 @@ describe('Record', () => {

describe('toString', () => {
it('should format the data for a zonefile', () => {
const jsonRecord = extend({}, METADATA, {
const jsonRecord = Object.assign({}, METADATA, {
type: TYPE,
rrdatas: ['example.com.', 'example2.com.'],
});
Expand Down
11 changes: 5 additions & 6 deletions packages/google-cloud-dns/test/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {ServiceObject, ServiceObjectConfig} from '@google-cloud/common';
import * as promisify from '@google-cloud/promisify';
import * as arrify from 'arrify';
import * as assert from 'assert';
import * as extend from 'extend';
import * as proxyquire from 'proxyquire';
import {CoreOptions, OptionsWithUri, Response} from 'request';
import * as uuid from 'uuid';
Expand All @@ -27,7 +26,7 @@ import {Change, CreateChangeRequest} from '../src/change';
import {Record, RecordObject} from '../src/record';

let promisified = false;
const fakePromisify = extend({}, promisify, {
const fakePromisify = Object.assign({}, promisify, {
promisifyAll(esClass: Function, options: promisify.PromisifyAllOptions) {
if (esClass.name !== 'Zone') {
return;
Expand Down Expand Up @@ -153,7 +152,7 @@ describe('Zone', () => {
});

it('should inherit from ServiceObject', done => {
const dnsInstance = extend({}, DNS, {
const dnsInstance = Object.assign({}, DNS, {
createZone: {
bind(context: {}) {
assert.strictEqual(context, dnsInstance);
Expand Down Expand Up @@ -205,7 +204,7 @@ describe('Zone', () => {

describe('createChange', () => {
function generateRecord(recordJson?: {}) {
recordJson = extend(
recordJson = Object.assign(
{
name: uuid.v1(),
type: uuid.v1(),
Expand Down Expand Up @@ -645,7 +644,7 @@ describe('Zone', () => {

it('should build a nextQuery if necessary', done => {
const nextPageToken = 'next-page-token';
const apiResponseWithNextPageToken = extend({}, apiResponse, {
const apiResponseWithNextPageToken = Object.assign({}, apiResponse, {
nextPageToken,
});
const expectedNextQuery = {
Expand Down Expand Up @@ -728,7 +727,7 @@ describe('Zone', () => {

it('should execute callback with nextQuery if necessary', done => {
const nextPageToken = 'next-page-token';
const apiResponseWithNextPageToken = extend({}, apiResponse, {
const apiResponseWithNextPageToken = Object.assign({}, apiResponse, {
nextPageToken,
});
const expectedNextQuery = {pageToken: nextPageToken};
Expand Down

0 comments on commit 123d04e

Please sign in to comment.