Skip to content

Commit c3744f7

Browse files
carnesenJustinBeckwith
authored andcommitted
fix(types): A few more promisified method overloads (#134)
1 parent 5314153 commit c3744f7

File tree

1 file changed

+37
-42
lines changed
  • packages/google-cloud-dns/src

1 file changed

+37
-42
lines changed

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

+37-42
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ export interface GetRecordsRequest {
9898
filterByTypes_?: {[index: string]: boolean};
9999
}
100100

101+
/**
102+
* Query object for listing changes.
103+
*
104+
* @typedef {object} GetChangesRequest
105+
* @property {boolean} [autoPaginate=true] Have pagination handled automatically.
106+
* @property {number} [maxApiCalls] Maximum number of API calls to make.
107+
* @property {number} [maxResults] Maximum number of items plus prefixes to
108+
* return.
109+
* @property {string} [pageToken] A previously-returned page token
110+
* representing part of the larger set of results to view.
111+
* @property {string} [sort] Set to 'asc' for ascending, and 'desc' for
112+
* descending or omit for no sorting.
113+
*/
101114
export interface GetChangesRequest {
102115
autoPaginate?: boolean;
103116
maxApiCalls?: number;
@@ -107,6 +120,20 @@ export interface GetChangesRequest {
107120
sortOrder?: string;
108121
}
109122

123+
/**
124+
* @typedef {array} GetChangesResponse
125+
* @property {Change[]} 0 Array of {@link Change} instances.
126+
* @property {object} 1 The full API response.
127+
*/
128+
export type GetChangesResponse = [Change[], r.Response];
129+
130+
/**
131+
* @callback GetChangesCallback
132+
* @param {?Error} err Request error, if any.
133+
* @param {Change[]} changes Array of {@link Change} instances.
134+
* @param {object} apiResponse The full API response.
135+
*/
136+
110137
export interface GetChangesCallback {
111138
(err: Error|null, changes?: Change[]|null, nextQuery?: {}|null,
112139
apiResponse?: r.Response): void;
@@ -678,30 +705,6 @@ class Zone extends ServiceObject {
678705
});
679706
});
680707
}
681-
/**
682-
* Query object for listing changes.
683-
*
684-
* @typedef {object} GetChangesRequest
685-
* @property {boolean} [autoPaginate=true] Have pagination handled automatically.
686-
* @property {number} [maxApiCalls] Maximum number of API calls to make.
687-
* @property {number} [maxResults] Maximum number of items plus prefixes to
688-
* return.
689-
* @property {string} [pageToken] A previously-returned page token
690-
* representing part of the larger set of results to view.
691-
* @property {string} [sort] Set to 'asc' for ascending, and 'desc' for
692-
* descending or omit for no sorting.
693-
*/
694-
/**
695-
* @typedef {array} GetChangesResponse
696-
* @property {Change[]} 0 Array of {@link Change} instances.
697-
* @property {object} 1 The full API response.
698-
*/
699-
/**
700-
* @callback GetChangesCallback
701-
* @param {?Error} err Request error, if any.
702-
* @param {Change[]} changes Array of {@link Change} instances.
703-
* @param {object} apiResponse The full API response.
704-
*/
705708
/**
706709
* Get the list of changes associated with this zone. A change is an atomic
707710
* update to a collection of records.
@@ -741,11 +744,12 @@ class Zone extends ServiceObject {
741744
* const changes = data[0];
742745
* });
743746
*/
747+
getChanges(query?: GetChangesRequest): Promise<GetChangesResponse>;
744748
getChanges(callback: GetChangesCallback): void;
745749
getChanges(query: GetChangesRequest, callback: GetChangesCallback): void;
746750
getChanges(
747-
queryOrCallback: GetChangesRequest|GetChangesCallback,
748-
callback?: GetChangesCallback) {
751+
queryOrCallback?: GetChangesRequest|GetChangesCallback,
752+
callback?: GetChangesCallback): void|Promise<GetChangesResponse> {
749753
let query = queryOrCallback as GetChangesRequest;
750754
if (typeof query === 'function') {
751755
callback = query;
@@ -926,25 +930,14 @@ class Zone extends ServiceObject {
926930
callback!(null, records, nextQuery, resp);
927931
});
928932
}
929-
/**
930-
* @typedef {array} ZoneImportResponse
931-
* @property {Change} 0 A {@link Change} object.
932-
* @property {object} 1 The full API response.
933-
*/
934-
/**
935-
* @callback ZoneImportCallback
936-
* @param {?Error} err Request error, if any.
937-
* @param {?Change} change A {@link Change} object.
938-
* @param {object} apiResponse The full API response.
939-
*/
940933
/**
941934
* Copy the records from a zone file into this zone.
942935
*
943936
* @see [ManagedZones: create API Documentation]{@link https://cloud.google.com/dns/api/v1/managedZones/create}
944937
*
945938
* @param {string} localPath The fully qualified path to the zone file.
946-
* @param {ZoneImportCallback} [callback] Callback function.
947-
* @returns {Promise<ZoneImportResponse>}
939+
* @param {CreateChangeCallback} [callback] Callback function.
940+
* @returns {Promise<CreateChangeResponse>}
948941
* @example
949942
* const {DNS} = require('@google-cloud/dns');
950943
* const dns = new DNS();
@@ -966,9 +959,11 @@ class Zone extends ServiceObject {
966959
* const apiResponse = data[1];
967960
* });
968961
*/
969-
import(localPath: string, callback: CreateChangeCallback) {fs.readFile(localPath, 'utf-8', (err, file) => {
962+
import(localPath: string): Promise<CreateChangeResponse>;
963+
import(localPath: string, callback: CreateChangeCallback): void;
964+
import(localPath: string, callback?: CreateChangeCallback): void|Promise<CreateChangeResponse> {fs.readFile(localPath, 'utf-8', (err, file) => {
970965
if (err) {
971-
callback(err);
966+
callback!(err);
972967
return;
973968
}
974969
const parsedZonefile = zonefile.parse(file);
@@ -983,7 +978,7 @@ import(localPath: string, callback: CreateChangeCallback) {fs.readFile(localPath
983978
recordsToCreate.push(Record.fromZoneRecord_(this, recordType, record));
984979
});
985980
});
986-
this.addRecords(recordsToCreate, callback);
981+
this.addRecords(recordsToCreate, callback!);
987982
});}
988983
/**
989984
* A {@link Record} object can be used to construct a record you want to

0 commit comments

Comments
 (0)