Skip to content

Commit

Permalink
refactor: reduce the number of deps (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Nov 8, 2018
1 parent e181810 commit e205a79
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 97 deletions.
2 changes: 1 addition & 1 deletion packages/google-cloud-dns/.jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
source: {
excludePattern: '(^|\\/|\\\\)[._]',
include: [
'src'
'build/src'
],
includePattern: '\\.js$'
},
Expand Down
8 changes: 0 additions & 8 deletions packages/google-cloud-dns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,21 @@
"arrify": "^1.0.1",
"dns-zonefile": "0.2.2",
"extend": "^3.0.0",
"is": "^3.2.1",
"lodash.flatten": "^4.4.0",
"lodash.groupby": "^4.6.0",
"methmeth": "^1.1.0",
"propprop": "^0.3.1",
"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/async": "^2.0.49",
"@types/extend": "^3.0.0",
"@types/is": "0.0.21",
"@types/lodash.flatten": "^4.4.4",
"@types/lodash.groupby": "^4.6.4",
"@types/mocha": "^5.2.5",
"@types/node": "^10.9.4",
"@types/proxyquire": "^1.3.28",
"@types/request": "^2.47.1",
"@types/tmp": "0.0.33",
"@types/uuid": "^3.4.4",
"async": "^2.6.1",
"codecov": "^3.0.2",
"eslint": "^5.0.0",
"eslint-config-prettier": "^3.0.0",
Expand Down
11 changes: 5 additions & 6 deletions packages/google-cloud-dns/src/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
* limitations under the License.
*/

'use strict';

import {teenyRequest} from 'teeny-request';
import {ServiceObject, CreateOptions} from '@google-cloud/common';
import {CreateOptions, ServiceObject} from '@google-cloud/common';
import {promisifyAll} from '@google-cloud/promisify';
import {Zone} from './zone';
import {Record} from './record';
import * as r from 'request';
import {teenyRequest} from 'teeny-request';

import {Record} from './record';
import {Zone} from './zone';

export interface CreateChangeRequest extends CreateOptions {
add?: Record|Record[];
Expand Down
12 changes: 6 additions & 6 deletions packages/google-cloud-dns/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
* limitations under the License.
*/

'use strict';

import {Stream} from 'stream';
import * as arrify from 'arrify';
import {Service, GoogleAuthOptions} from '@google-cloud/common';
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';

import {Zone} from './zone';
import * as r from 'request';

export {Record, RecordMetadata} from './record';

export interface GetZonesRequest {
Expand Down
8 changes: 4 additions & 4 deletions packages/google-cloud-dns/src/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

'use strict';

import * as arrify from 'arrify';
import {promisifyAll} from '@google-cloud/promisify';
import * as arrify from 'arrify';
import * as extend from 'extend';
import {CreateChangeCallback, Change} from './change';

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

const format = require('string-format-obj');
import * as r from 'request';

Expand Down
16 changes: 7 additions & 9 deletions packages/google-cloud-dns/src/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
* limitations under the License.
*/

'use strict';

import * as arrify from 'arrify';
import {ServiceObject, DeleteCallback} from '@google-cloud/common';
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';
const flatten = require('lodash.flatten');
import * as fs from 'fs';

import groupBy = require('lodash.groupby');
import * as is from 'is';
import {teenyRequest} from 'teeny-request';
const zonefile = require('dns-zonefile');

Expand Down Expand Up @@ -440,7 +437,8 @@ class Zone extends ServiceObject {
if (records.length > 1) {
// Combine the `rrdatas` values from all records of the same type.
templateRecord.rrdatas =
flatten(records.map((x: RecordObject) => x.rrdatas));
records.map(x => x.rrdatas)
.reduce((acc, rrdata) => acc!.concat(rrdata!), []);
}
recordsOut.push(templateRecord);
}
Expand Down Expand Up @@ -627,7 +625,7 @@ class Zone extends ServiceObject {
records = arrify<Record|string>(recordsOrCallback);
}

if (is.string(records[0])) {
if (typeof records[0] === 'string') {
this.deleteRecordsByType_(records as string[], callback!);
return;
}
Expand Down Expand Up @@ -891,7 +889,7 @@ class Zone extends ServiceObject {
query = queryOrCallback!;
}

if (is.string(query) || is.array(query)) {
if (typeof query === 'string' || Array.isArray(query)) {
const filterByTypes_: {[index: string]: boolean} = {};
// For faster lookups, store the record types the user wants in an object.
arrify(query as string).forEach(type => {
Expand Down
2 changes: 1 addition & 1 deletion packages/google-cloud-dns/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

logging.basicConfig(level=logging.DEBUG)
common_templates = gcp.CommonTemplates()
templates = common_templates.node_library()
templates = common_templates.node_library(source_location='build/src')
s.copy(templates)
55 changes: 17 additions & 38 deletions packages/google-cloud-dns/system-test/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@
* limitations under the License.
*/

'use strict';

import * as assert from 'assert';
import * as async from 'async';
const exec = require('methmeth');
const format = require('string-format-obj');
import * as fs from 'fs';
const tmp = require('tmp');
import * as uuid from 'uuid';
import {DNS} from '../src';
import {CreateChangeCallback} from '../src/change';
import {Record} from '../src';
import {Response} from 'request';
import * as tmp from 'tmp';
import * as util from 'util';
import * as uuid from 'uuid';

const format = require('string-format-obj');

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

const dns = new DNS();
const DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN || 'gitnpm.com.';
Expand Down Expand Up @@ -111,22 +108,10 @@ describe('dns', () => {
}),
};

before(done => {
dns.getZones((err, zones) => {
if (err) {
done(err);
return;
}

async.each(zones!, exec('delete', {force: true}), err => {
if (err) {
done(err);
return;
}

ZONE.create({dnsName: DNS_DOMAIN}, done);
});
});
before(async () => {
const [zones] = await dns.getZones();
await Promise.all(zones.map(zone => zone.delete({force: true})));
await ZONE.create({dnsName: DNS_DOMAIN});
});

after(done => {
Expand Down Expand Up @@ -211,19 +196,13 @@ describe('dns', () => {
});
});

it('should export records to a zone file', done => {
it('should export records to a zone file', async () => {
tmp.setGracefulCleanup();
tmp.file((err: Error, tmpFilename: string) => {
assert.ifError(err);
async.series(
[
next => ZONE.empty(next as CreateChangeCallback),
next => ZONE.addRecords(
[records.spf, records.srv], next as CreateChangeCallback),
next => ZONE.export(tmpFilename, next)
],
done);
});
const tmpFile: Function = util.promisify(tmp.file);
const tmpFilename = await tmpFile();
await ZONE.empty();
await ZONE.addRecords([records.spf, records.srv]);
await ZONE.export(tmpFilename);
});

describe('changes', () => {
Expand Down
7 changes: 3 additions & 4 deletions packages/google-cloud-dns/test/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
* limitations under the License.
*/

'use strict';

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 {ServiceObject, ServiceObjectConfig} from '@google-cloud/common';
import * as promisify from '@google-cloud/promisify';
import {Response} from 'request';

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

let promisified = false;
Expand Down
9 changes: 3 additions & 6 deletions packages/google-cloud-dns/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
* limitations under the License.
*/

'use strict';

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 {Service, ServiceConfig, ServiceOptions} from '@google-cloud/common';
import {util} from '@google-cloud/common';
import * as promisify from '@google-cloud/promisify';
import {RequestOptions} from 'http';
import {CoreOptions, OptionsWithUri, Response} from 'request';

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

let extended = false;
Expand Down
5 changes: 2 additions & 3 deletions packages/google-cloud-dns/test/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
* limitations under the License.
*/

'use strict';

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

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

let promisified = false;
Expand Down
20 changes: 9 additions & 11 deletions packages/google-cloud-dns/test/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@
* limitations under the License.
*/

'use strict';

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';
const flatten = require('lodash.flatten');
import * as proxyquire from 'proxyquire';
import {ServiceObject, ServiceObjectConfig} from '@google-cloud/common';
import * as promisify from '@google-cloud/promisify';
import {CoreOptions, OptionsWithUri, Response} from 'request';
import * as uuid from 'uuid';
import {CreateChangeRequest, Change} from '../src/change';

import {Change, CreateChangeRequest} from '../src/change';
import {Record, RecordObject} from '../src/record';
import {CoreOptions, OptionsWithUri, Response} from 'request';

let promisified = false;
const fakePromisify = extend({}, promisify, {
Expand Down Expand Up @@ -217,7 +215,7 @@ describe('Zone', () => {

return {
toJSON() {
return recordJson;
return recordJson! as {rrdatas: Array<{}>};
},
};
}
Expand Down Expand Up @@ -263,9 +261,9 @@ describe('Zone', () => {
];

zone.request = (reqOpts: CoreOptions) => {
const expectedRRDatas = flatten(
// tslint:disable-next-line:no-any
recordsToAdd.map(x => x.toJSON()).map((x: any) => x!.rrdatas));
const expectedRRDatas =
recordsToAdd.map(x => x.toJSON().rrdatas)
.reduce((acc, rrdata) => acc.concat(rrdata), []);

assert.deepStrictEqual(reqOpts.json.additions, [
{
Expand Down

0 comments on commit e205a79

Please sign in to comment.