Skip to content

Commit e21e2d1

Browse files
JustinBeckwithjkwlui
authored andcommitted
Enable noImplicitAny (#105)
* Enable noImplicitAny * lol
1 parent a7f47ca commit e21e2d1

File tree

9 files changed

+355
-278
lines changed

9 files changed

+355
-278
lines changed

packages/google-cloud-dns/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import * as extend from 'extend';
2424
import {teenyRequest} from 'teeny-request';
2525
import {Zone} from './zone';
2626
import {Response} from 'request';
27+
export {Record, RecordMetadata} from './record';
2728

2829
export interface GetZonesRequest {
2930
autoPaginate?: boolean;

packages/google-cloud-dns/src/record.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ import {ChangeCallback} from './change';
2323
import {Zone} from './zone';
2424
const format = require('string-format-obj');
2525

26+
export interface RecordObject {
27+
rrdatas?: Array<{}>;
28+
rrdata?: {};
29+
data?: {};
30+
type?: string;
31+
}
32+
33+
export interface RecordMetadata {
34+
name: string;
35+
data: string|string[];
36+
ttl: number;
37+
type?: string;
38+
signatureRrdatas?: string[];
39+
}
40+
2641
/**
2742
* Create a Resource Record object.
2843
*
@@ -49,13 +64,13 @@ const format = require('string-format-obj');
4964
* data: '1.2.3.4'
5065
* });
5166
*/
52-
export class Record {
67+
export class Record implements RecordObject {
5368
zone_: Zone;
5469
type: string;
55-
metadata;
56-
rrdatas;
57-
data;
58-
constructor(zone: Zone, type: string, metadata) {
70+
metadata: RecordMetadata;
71+
rrdatas?: Array<{}>;
72+
data?: {};
73+
constructor(zone: Zone, type: string, metadata: RecordMetadata) {
5974
this.zone_ = zone;
6075
/**
6176
* @name Record#type
@@ -137,7 +152,7 @@ export class Record {
137152
* @returns {object}
138153
*/
139154
toJSON() {
140-
const recordObject = extend({}, this.metadata, {
155+
const recordObject: RecordObject = extend({}, this.metadata, {
141156
type: this.type.toUpperCase(),
142157
});
143158
if (recordObject.data) {
@@ -171,7 +186,7 @@ export class Record {
171186
* based on the type of record.
172187
* @returns {Record}
173188
*/
174-
static fromZoneRecord_(zone: Zone, type: string, bindData) {
189+
static fromZoneRecord_(zone: Zone, type: string, bindData: RecordMetadata) {
175190
const typeToZoneFormat = {
176191
a: '{ip}',
177192
aaaa: '{ip}',
@@ -182,7 +197,7 @@ export class Record {
182197
spf: '{data}',
183198
srv: '{priority} {weight} {port} {target}',
184199
txt: '{txt}',
185-
};
200+
} as {[index: string]: string};
186201
const metadata = {
187202
data: format(typeToZoneFormat[type.toLowerCase()], bindData),
188203
name: bindData.name,

packages/google-cloud-dns/src/zone.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {teenyRequest} from 'teeny-request';
2929
const zonefile = require('dns-zonefile');
3030

3131
import {Change, ChangeCallback, CreateChangeRequest} from './change';
32-
import {Record} from './record';
32+
import {Record, RecordMetadata, RecordObject} from './record';
3333
import {DNS} from '.';
3434
import {Response} from 'request';
3535

@@ -52,6 +52,20 @@ export interface GetRecordsRequest {
5252
filterByTypes_?: {[index: string]: boolean};
5353
}
5454

55+
export interface GetChangesRequest {
56+
autoPaginate?: boolean;
57+
maxApiCalls?: number;
58+
maxResults?: number;
59+
pageToken?: string;
60+
sort?: string;
61+
sortOrder?: string;
62+
}
63+
64+
export interface GetChangesCallback {
65+
(err: Error|null, changes?: Change[]|null, nextQuery?: {}|null,
66+
apiResponse?: Response): void;
67+
}
68+
5569
/**
5670
* A Zone object is used to interact with your project's managed zone. It will
5771
* help you add or delete records, delete your zone, and many other convenience
@@ -349,7 +363,7 @@ class Zone extends ServiceObject {
349363
if (!config || (!config.add && !config.delete)) {
350364
throw new Error('Cannot create a change with no additions or deletions.');
351365
}
352-
const groupByType = changes => {
366+
const groupByType = (changes: RecordObject[]) => {
353367
changes = groupBy(changes, 'type');
354368
const changesArray: Array<{}> = [];
355369
// tslint:disable-next-line:forin
@@ -361,7 +375,8 @@ class Zone extends ServiceObject {
361375
const templateRecord = extend({}, records[0]);
362376
if (records.length > 1) {
363377
// Combine the `rrdatas` values from all records of the same type.
364-
templateRecord.rrdatas = flatten(records.map(x => x.rrdatas));
378+
templateRecord.rrdatas =
379+
flatten(records.map((x: RecordObject) => x.rrdatas));
365380
}
366381
changesArray.push(templateRecord);
367382
}
@@ -643,7 +658,7 @@ class Zone extends ServiceObject {
643658
* //-
644659
* zone.export(zoneFilename).then(() => {});
645660
*/
646-
export(localPath: string, callback) {
661+
export(localPath: string, callback: (err: Error|null) => void) {
647662
this.getRecords((err, records) => {
648663
if (err) {
649664
callback(err);
@@ -718,8 +733,13 @@ class Zone extends ServiceObject {
718733
* const changes = data[0];
719734
* });
720735
*/
721-
getChanges(query, callback?) {
722-
if (is.fn(query)) {
736+
getChanges(callback: GetChangesCallback): void;
737+
getChanges(query: GetChangesRequest, callback: GetChangesCallback): void;
738+
getChanges(
739+
queryOrCallback: GetChangesRequest|GetChangesCallback,
740+
callback?: GetChangesCallback) {
741+
let query = queryOrCallback as GetChangesRequest;
742+
if (typeof query === 'function') {
723743
callback = query;
724744
query = {};
725745
}
@@ -734,10 +754,10 @@ class Zone extends ServiceObject {
734754
},
735755
(err, resp) => {
736756
if (err) {
737-
callback(err, null, null, resp);
757+
callback!(err, null, null, resp);
738758
return;
739759
}
740-
const changes = (resp.changes || []).map(change => {
760+
const changes = (resp.changes || []).map((change: Change) => {
741761
const changeInstance = this.change(change.id);
742762
changeInstance.metadata = change;
743763
return changeInstance;
@@ -748,7 +768,7 @@ class Zone extends ServiceObject {
748768
pageToken: resp.nextPageToken,
749769
});
750770
}
751-
callback(null, changes, nextQuery, resp);
771+
callback!(null, changes, nextQuery, resp);
752772
});
753773
}
754774
/**
@@ -879,12 +899,12 @@ class Zone extends ServiceObject {
879899
callback!(err, null, null, resp);
880900
return;
881901
}
882-
let records = (resp.rrsets || []).map(record => {
883-
return this.record(record.type, record);
902+
let records = (resp.rrsets || []).map((record: RecordMetadata) => {
903+
return this.record(record.type!, record);
884904
});
885905
if ((query as GetRecordsRequest).filterByTypes_) {
886-
records = records.filter(record => {
887-
return (query as GetRecordsRequest).filterByTypes_![record.type];
906+
records = records.filter((record: RecordMetadata) => {
907+
return (query as GetRecordsRequest).filterByTypes_![record.type!];
888908
});
889909
}
890910
let nextQuery: {}|null = null;
@@ -1009,7 +1029,7 @@ class Zone extends ServiceObject {
10091029
* delete: oldARecord
10101030
* }, (err, change, apiResponse) => {});
10111031
*/
1012-
record(type: string, metadata: {}) {
1032+
record(type: string, metadata: RecordMetadata) {
10131033
return new Record(this, type, metadata);
10141034
}
10151035
/**

packages/google-cloud-dns/system-test/dns.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const tmp = require('tmp');
2525
import * as uuid from 'uuid';
2626
import {DNS} from '../src';
2727
import {ChangeCallback} from '../src/change';
28+
import {Record} from '../src';
29+
import {Response} from 'request';
2830

2931
const dns = new DNS();
3032
const DNS_DOMAIN = process.env.GCLOUD_TESTS_DNS_DOMAIN || 'gitnpm.com.';
@@ -175,7 +177,7 @@ describe('dns', () => {
175177
});
176178

177179
tmp.setGracefulCleanup();
178-
tmp.file((err, tmpFilePath) => {
180+
tmp.file((err: Error, tmpFilePath: string) => {
179181
assert.ifError(err);
180182
fs.writeFileSync(tmpFilePath, zoneFileTemplate, 'utf-8');
181183
ZONE.empty(err => {
@@ -191,15 +193,15 @@ describe('dns', () => {
191193
})[0];
192194

193195
assert.strictEqual(
194-
spfRecord.toJSON().rrdatas[0],
196+
spfRecord.toJSON().rrdatas![0],
195197
'"v=spf1" "mx:' + DNS_DOMAIN + '" "-all"');
196198

197199
const txtRecord = records!.filter(record => {
198200
return record.type === 'TXT';
199201
})[0];
200202

201203
assert.strictEqual(
202-
txtRecord.toJSON().rrdatas[0],
204+
txtRecord.toJSON().rrdatas![0],
203205
'"google-site-verification=xxxxxxxxxxxxYYYYYYXXX"');
204206

205207
done();
@@ -211,7 +213,7 @@ describe('dns', () => {
211213

212214
it('should export records to a zone file', done => {
213215
tmp.setGracefulCleanup();
214-
tmp.file((err, tmpFilename) => {
216+
tmp.file((err: Error, tmpFilename: string) => {
215217
assert.ifError(err);
216218
async.series(
217219
[
@@ -245,15 +247,15 @@ describe('dns', () => {
245247
it('should get a list of changes', done => {
246248
ZONE.getChanges((err, changes) => {
247249
assert.ifError(err);
248-
assert(changes.length >= 0);
250+
assert(changes!.length >= 0);
249251
done();
250252
});
251253
});
252254

253255
it('should get metadata', done => {
254256
ZONE.getChanges((err, changes) => {
255257
assert.ifError(err);
256-
const change = changes[0];
258+
const change = changes![0];
257259
const expectedMetadata = change.metadata;
258260
change.getMetadata((err, metadata) => {
259261
assert.ifError(err);
@@ -292,13 +294,15 @@ describe('dns', () => {
292294

293295
ZONE.replaceRecords('cname', newRecords, err => {
294296
assert.ifError(err);
295-
const onRecordsReceived = (err, records, nextQuery) => {
296-
if (nextQuery) {
297-
ZONE.getRecords(nextQuery, onRecordsReceived);
298-
return;
299-
}
300-
ZONE.deleteRecords(newRecords, done);
301-
};
297+
const onRecordsReceived =
298+
(err?: Error|null, records?: Record[]|null, nextQuery?: {}|null,
299+
apiResponse?: Response) => {
300+
if (nextQuery) {
301+
ZONE.getRecords(nextQuery, onRecordsReceived);
302+
return;
303+
}
304+
ZONE.deleteRecords(newRecords, done);
305+
};
302306
ZONE.getRecords(
303307
{
304308
type: 'cname',

packages/google-cloud-dns/test/change.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ import * as extend from 'extend';
2121
import * as proxyquire from 'proxyquire';
2222
import {ServiceObject, ServiceObjectConfig} from '@google-cloud/common';
2323
import * as promisify from '@google-cloud/promisify';
24+
import {Response} from 'request';
25+
import {Change} from '../src/change';
2426

2527
let promisified = false;
2628
const fakePromisify = extend({}, promisify, {
27-
// tslint:disable-next-line:variable-name
28-
promisifyAll(Class) {
29-
if (Class.name === 'Change') {
29+
promisifyAll(esClass: Function) {
30+
if (esClass.name === 'Change') {
3031
promisified = true;
3132
}
3233
},
@@ -41,9 +42,10 @@ class FakeServiceObject extends ServiceObject {
4142
}
4243

4344
describe('Change', () => {
44-
// tslint:disable-next-line:variable-name
45-
let Change;
46-
let change;
45+
// tslint:disable-next-line:variable-name no-any
46+
let Change: any;
47+
// tslint:disable-next-line: no-any
48+
let change: any;
4749

4850
const ZONE = {
4951
name: 'zone-name',
@@ -90,7 +92,7 @@ describe('Change', () => {
9092
it('should call the parent change method', done => {
9193
const config = {};
9294

93-
change.parent.createChange = config_ => {
95+
change.parent.createChange = (config_: {}) => {
9496
assert.strictEqual(config, config_);
9597
done();
9698
};
@@ -103,19 +105,19 @@ describe('Change', () => {
103105
const apiResponse = {};
104106

105107
beforeEach(() => {
106-
change.parent.createChange = (config, callback) => {
108+
change.parent.createChange = (config: {}, callback: Function) => {
107109
callback(error, null, apiResponse);
108110
};
109111
});
110112

111113
it('should execute callback with error & apiResponse', done => {
112-
change.create({}, (err, change, apiResponse_) => {
113-
assert.strictEqual(err, error);
114-
assert.strictEqual(change, null);
115-
assert.strictEqual(apiResponse_, apiResponse);
116-
117-
done();
118-
});
114+
change.create(
115+
{}, (err: Error, change: Change, apiResponse_: Response) => {
116+
assert.strictEqual(err, error);
117+
assert.strictEqual(change, null);
118+
assert.strictEqual(apiResponse_, apiResponse);
119+
done();
120+
});
119121
});
120122
});
121123

@@ -127,22 +129,23 @@ describe('Change', () => {
127129
const apiResponse = {};
128130

129131
beforeEach(() => {
130-
change.parent.createChange = (config, callback) => {
132+
change.parent.createChange = (config: {}, callback: Function) => {
131133
callback(null, changeInstance, apiResponse);
132134
};
133135
});
134136

135137
it('should execute callback with self & API response', done => {
136-
change.create({}, (err, change_, apiResponse_) => {
137-
assert.ifError(err);
138-
assert.strictEqual(change_, change);
139-
assert.strictEqual(apiResponse_, apiResponse);
140-
done();
141-
});
138+
change.create(
139+
{}, (err: Error, change_: Change, apiResponse_: Response) => {
140+
assert.ifError(err);
141+
assert.strictEqual(change_, change);
142+
assert.strictEqual(apiResponse_, apiResponse);
143+
done();
144+
});
142145
});
143146

144147
it('should assign the ID and metadata from the change', done => {
145-
change.create({}, (err, change_) => {
148+
change.create({}, (err: Error, change_: Change) => {
146149
assert.ifError(err);
147150
assert.strictEqual(change_.id, changeInstance.id);
148151
assert.strictEqual(change_.metadata, changeInstance.metadata);

0 commit comments

Comments
 (0)