Skip to content

Commit

Permalink
fix: improve the types (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Sep 25, 2018
1 parent 968b618 commit 7e5f66f
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 226 deletions.
10 changes: 5 additions & 5 deletions packages/google-cloud-dns/src/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface CreateChangeRequest extends CreateOptions {

export type CreateChangeResponse = [Change, r.Response];

export interface ChangeCallback {
export interface CreateChangeCallback {
(err: Error|null, change?: Change|null, apiResponse?: r.Response): void;
}

Expand Down Expand Up @@ -233,11 +233,11 @@ export class Change extends ServiceObject {
* });
*/
create(config?: CreateChangeRequest): Promise<CreateChangeResponse>;
create(config: CreateChangeRequest, callback: ChangeCallback): void;
create(callback: ChangeCallback): void;
create(config: CreateChangeRequest, callback: CreateChangeCallback): void;
create(callback: CreateChangeCallback): void;
create(
configOrCallback?: CreateChangeRequest|ChangeCallback,
callback?: ChangeCallback): void|Promise<CreateChangeResponse> {
configOrCallback?: CreateChangeRequest|CreateChangeCallback,
callback?: CreateChangeCallback): void|Promise<CreateChangeResponse> {
const config = typeof configOrCallback === 'object' ? configOrCallback : {};
callback =
typeof configOrCallback === 'function' ? configOrCallback! : callback;
Expand Down
13 changes: 6 additions & 7 deletions packages/google-cloud-dns/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {promisifyAll} from '@google-cloud/promisify';
import * as extend from 'extend';
import {teenyRequest} from 'teeny-request';
import {Zone} from './zone';
import {Response} from 'request';
import * as r from 'request';
export {Record, RecordMetadata} from './record';

export interface GetZonesRequest {
Expand All @@ -41,13 +41,13 @@ export interface DNSConfig extends GoogleAuthOptions {

export interface GetZonesCallback {
(err: Error|null, zones: Zone[]|null, nextQuery?: GetZonesRequest|null,
apiResponse?: Response): void;
apiResponse?: r.Response): void;
}

export type GetZonesResponse = [Zone[], GetZonesRequest | null, Response];
export type GetZonesResponse = [Zone[], GetZonesRequest | null, r.Response];

export interface GetZoneCallback {
(err: Error|null, zone?: Zone|null, apiResponse?: Response): void;
(err: Error|null, zone?: Zone|null, apiResponse?: r.Response): void;
}

export interface CreateZoneRequest {
Expand All @@ -56,7 +56,7 @@ export interface CreateZoneRequest {
name?: string;
}

export type CreateZoneResponse = [Zone, Response];
export type CreateZoneResponse = [Zone, r.Response];

/**
* @typedef {object} ClientConfig
Expand Down Expand Up @@ -126,8 +126,7 @@ class DNS extends Service {
'https://www.googleapis.com/auth/cloud-platform',
],
packageJson: require('../../package.json'),
// tslint:disable-next-line:no-any
requestModule: teenyRequest as any,
requestModule: teenyRequest as typeof r,
};
super(config, options);

Expand Down
38 changes: 24 additions & 14 deletions packages/google-cloud-dns/src/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import * as arrify from 'arrify';
import {promisifyAll} from '@google-cloud/promisify';
import * as extend from 'extend';
import {ChangeCallback} from './change';
import {CreateChangeCallback, Change} from './change';
import {Zone} from './zone';
const format = require('string-format-obj');
import * as r from 'request';

export interface RecordObject {
rrdatas?: Array<{}>;
Expand All @@ -38,6 +39,23 @@ export interface RecordMetadata {
signatureRrdatas?: string[];
}

/**
* @typedef {array} DeleteRecordResponse
* @property {Change} 0 A {@link Change} object.
* @property {object} 1 The full API response.
*/
export type DeleteRecordResponse = [Change, r.Response];

/**
* @callback DeleteRecordCallback
* @param {?Error} err Request error, if any.
* @param {?Change} change A {@link Change} object.
* @param {object} apiResponse The full API response.
*/
export interface DeleteRecordCallback {
(err: Error|null, change?: Change, apiResponse?: r.Response): void;
}

/**
* Create a Resource Record object.
*
Expand Down Expand Up @@ -95,17 +113,7 @@ export class Record implements RecordObject {
delete this.rrdatas;
}
}
/**
* @typedef {array} DeleteRecordResponse
* @property {Change} 0 A {@link Change} object.
* @property {object} 1 The full API response.
*/
/**
* @callback DeleteRecordCallback
* @param {?Error} err Request error, if any.
* @param {?Change} change A {@link Change} object.
* @param {object} apiResponse The full API response.
*/

/**
* Delete this record by creating a change on your zone. This is a convenience
* method for:
Expand Down Expand Up @@ -143,8 +151,10 @@ export class Record implements RecordObject {
* const apiResponse = data[1];
* });
*/
delete(callback: ChangeCallback) {
this.zone_.deleteRecords(this, callback);
delete(): Promise<DeleteRecordResponse>;
delete(callback: CreateChangeCallback): void;
delete(callback?: CreateChangeCallback): void|Promise<DeleteRecordResponse> {
this.zone_.deleteRecords(this, callback!);
}
/**
* Serialize the record instance to the format the API expects.
Expand Down
Loading

0 comments on commit 7e5f66f

Please sign in to comment.