Skip to content

Commit 9ebae03

Browse files
Convert to TypeScript (#97)
1 parent ecdef82 commit 9ebae03

14 files changed

Lines changed: 233 additions & 211 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Language: JavaScript
2+
BasedOnStyle: Google
3+
ColumnLimit: 80

packages/google-cloud-dns/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ system-test/secrets.js
88
system-test/*key.json
99
*.lock
1010
package-lock.json
11+
build/

packages/google-cloud-dns/package.json

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
"node": ">=6.0.0"
99
},
1010
"repository": "googleapis/nodejs-dns",
11-
"main": "./src/index.js",
11+
"main": "./build/src/index.js",
12+
"types": "./build/src/index.d.ts",
1213
"files": [
13-
"src",
14+
"build/src",
1415
"AUTHORS",
1516
"CONTRIBUTORS",
1617
"LICENSE"
@@ -41,19 +42,21 @@
4142
"greenkeeper[bot] <greenkeeper[bot]@users.noreply.github.com>"
4243
],
4344
"scripts": {
44-
"cover": "nyc --reporter=lcov mocha test/*.js && nyc report",
4545
"docs": "jsdoc -c .jsdoc.js",
4646
"generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json",
47-
"lint": "eslint src/ samples/ system-test/ test/",
48-
"prettier": "prettier --write src/*.js src/*/*.js samples/*.js samples/*/*.js test/*.js test/*/*.js system-test/*.js system-test/*/*.js",
49-
"publish-module": "node ../../scripts/publish.js dns",
50-
"test-no-cover": "mocha test/*.js",
51-
"test": "npm run cover",
47+
"lint": "echo lint not enabled 👻 # gts check && eslint samples/",
48+
"test": "nyc mocha build/test",
5249
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
53-
"system-test": "mocha system-test/*.js --timeout 600000"
50+
"presystem-test": "npm run compile",
51+
"system-test": "mocha build/system-test --timeout 600000",
52+
"clean": "gts clean",
53+
"compile": "tsc -p .",
54+
"fix": "gts fix && prettier --write samples/*.js samples/*/*.js",
55+
"prepare": "npm run compile",
56+
"pretest": "npm run compile"
5457
},
5558
"dependencies": {
56-
"@google-cloud/common": "^0.23.0",
59+
"@google-cloud/common": "^0.24.0",
5760
"@google-cloud/paginator": "^0.1.0",
5861
"@google-cloud/promisify": "^0.3.0",
5962
"arrify": "^1.0.1",
@@ -69,12 +72,23 @@
6972
},
7073
"devDependencies": {
7174
"@google-cloud/nodejs-repo-tools": "^2.3.0",
75+
"@types/arrify": "^1.0.4",
76+
"@types/async": "^2.0.49",
77+
"@types/extend": "^3.0.0",
78+
"@types/is": "0.0.20",
79+
"@types/lodash.flatten": "^4.4.4",
80+
"@types/lodash.groupby": "^4.6.4",
81+
"@types/mocha": "^5.2.5",
82+
"@types/node": "^10.9.4",
83+
"@types/proxyquire": "^1.3.28",
84+
"@types/uuid": "^3.4.4",
7285
"async": "^2.6.1",
7386
"codecov": "^3.0.2",
7487
"eslint": "^5.0.0",
7588
"eslint-config-prettier": "^3.0.0",
7689
"eslint-plugin-node": "^7.0.0",
7790
"eslint-plugin-prettier": "^2.6.0",
91+
"gts": "^0.8.0",
7892
"ink-docstrap": "^1.3.2",
7993
"intelli-espower-loader": "^1.0.1",
8094
"jsdoc": "^3.5.5",
@@ -84,6 +98,12 @@
8498
"prettier": "^1.13.5",
8599
"proxyquire": "^2.0.1",
86100
"tmp": "^0.0.33",
101+
"typescript": "~2.8.0",
87102
"uuid": "^3.2.1"
103+
},
104+
"nyc": {
105+
"exclude": [
106+
"build/test"
107+
]
88108
}
89109
}
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
'use strict';
1818

19-
const teenyRequest = require('teeny-request').teenyRequest;
20-
const {ServiceObject} = require('@google-cloud/common');
21-
const {promisifyAll} = require('@google-cloud/promisify');
19+
import {teenyRequest} from 'teeny-request';
20+
import {ServiceObject} from '@google-cloud/common';
21+
import {promisifyAll} from '@google-cloud/promisify';
2222

2323
/**
2424
* @class
@@ -32,7 +32,7 @@ const {promisifyAll} = require('@google-cloud/promisify');
3232
* const zone = dns.zone('zone-id');
3333
* const change = zone.change('change-id');
3434
*/
35-
class Change extends ServiceObject {
35+
export class Change extends ServiceObject {
3636
constructor(zone, id) {
3737
const methods = {
3838
/**
@@ -178,9 +178,9 @@ class Change extends ServiceObject {
178178
* @name Change#id
179179
* @type {string}
180180
*/
181-
id: id,
182-
methods: methods,
183-
requestModule: teenyRequest,
181+
id,
182+
methods,
183+
requestModule: teenyRequest as any,
184184
});
185185
}
186186
/**
@@ -217,8 +217,8 @@ class Change extends ServiceObject {
217217
* const apiResponse = data[1];
218218
* });
219219
*/
220-
create(config, callback) {
221-
this.parent.createChange(config, (err, change, apiResponse) => {
220+
create(config, callback?) {
221+
(this.parent as any).createChange(config, (err, change, apiResponse) => {
222222
if (err) {
223223
callback(err, null, apiResponse);
224224
return;
@@ -236,5 +236,3 @@ class Change extends ServiceObject {
236236
* that a callback is omitted.
237237
*/
238238
promisifyAll(Change);
239-
240-
module.exports = Change;
Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
'use strict';
1818

19-
const arrify = require('arrify');
20-
const {Service} = require('@google-cloud/common');
21-
const {paginator} = require('@google-cloud/paginator');
22-
const {promisifyAll} = require('@google-cloud/promisify');
23-
const extend = require('extend');
24-
const is = require('is');
25-
const teenyRequest = require('teeny-request').teenyRequest;
19+
import * as arrify from 'arrify';
20+
import { Service } from '@google-cloud/common';
21+
import { paginator } from '@google-cloud/paginator';
22+
import { promisifyAll } from '@google-cloud/promisify';
23+
import * as extend from 'extend';
24+
import * as is from 'is';
25+
import { teenyRequest } from 'teeny-request';
2626

27-
const Zone = require('./zone');
27+
import { Zone } from './zone';
2828

2929
/**
3030
* @typedef {object} ClientConfig
@@ -80,6 +80,7 @@ const Zone = require('./zone');
8080
* Full quickstart example:
8181
*/
8282
class DNS extends Service {
83+
getZonesStream;
8384
constructor(options) {
8485
options = options || {};
8586
const config = {
@@ -88,10 +89,42 @@ class DNS extends Service {
8889
'https://www.googleapis.com/auth/ndev.clouddns.readwrite',
8990
'https://www.googleapis.com/auth/cloud-platform',
9091
],
91-
packageJson: require('../package.json'),
92-
requestModule: teenyRequest,
92+
packageJson: require('../../package.json'),
93+
requestModule: teenyRequest as any,
9394
};
9495
super(config, options);
96+
97+
/**
98+
* Get {@link Zone} objects for all of the zones in your project as
99+
* a readable object stream.
100+
*
101+
* @method DNS#getZonesStream
102+
* @param {GetZonesRequest} [query] Query object for listing zones.
103+
* @returns {ReadableStream} A readable stream that emits {@link Zone} instances.
104+
*
105+
* @example
106+
* const DNS = require('@google-cloud/dns');
107+
* const dns = new DNS();
108+
*
109+
* dns.getZonesStream()
110+
* .on('error', console.error)
111+
* .on('data', function(zone) {
112+
* // zone is a Zone object.
113+
* })
114+
* .on('end', function() {
115+
* // All zones retrieved.
116+
* });
117+
*
118+
* //-
119+
* // If you anticipate many results, you can end a stream early to prevent
120+
* // unnecessary processing and API requests.
121+
* //-
122+
* dns.getZonesStream()
123+
* .on('data', function(zone) {
124+
* this.end();
125+
* });
126+
*/
127+
this.getZonesStream = paginator.streamify('getZones');
95128
}
96129
/**
97130
* Config to set for the zone.
@@ -166,7 +199,7 @@ class DNS extends Service {
166199
uri: '/managedZones',
167200
json: config,
168201
},
169-
function(err, resp) {
202+
function (err, resp) {
170203
if (err) {
171204
callback(err, null, resp);
172205
return;
@@ -233,12 +266,12 @@ class DNS extends Service {
233266
uri: '/managedZones',
234267
qs: query,
235268
},
236-
function(err, resp) {
269+
function (err, resp) {
237270
if (err) {
238271
callback(err, null, null, resp);
239272
return;
240273
}
241-
const zones = arrify(resp.managedZones).map(function(zone) {
274+
const zones = arrify(resp.managedZones).map(function (zone) {
242275
const zoneInstance = self.zone(zone.name);
243276
zoneInstance.metadata = zone;
244277
return zoneInstance;
@@ -276,38 +309,6 @@ class DNS extends Service {
276309
}
277310
}
278311

279-
/**
280-
* Get {@link Zone} objects for all of the zones in your project as
281-
* a readable object stream.
282-
*
283-
* @method DNS#getZonesStream
284-
* @param {GetZonesRequest} [query] Query object for listing zones.
285-
* @returns {ReadableStream} A readable stream that emits {@link Zone} instances.
286-
*
287-
* @example
288-
* const DNS = require('@google-cloud/dns');
289-
* const dns = new DNS();
290-
*
291-
* dns.getZonesStream()
292-
* .on('error', console.error)
293-
* .on('data', function(zone) {
294-
* // zone is a Zone object.
295-
* })
296-
* .on('end', function() {
297-
* // All zones retrieved.
298-
* });
299-
*
300-
* //-
301-
* // If you anticipate many results, you can end a stream early to prevent
302-
* // unnecessary processing and API requests.
303-
* //-
304-
* dns.getZonesStream()
305-
* .on('data', function(zone) {
306-
* this.end();
307-
* });
308-
*/
309-
DNS.prototype.getZonesStream = paginator.streamify('getZones');
310-
311312
/*! Developer Documentation
312313
*
313314
* These methods can be auto-paginated.
@@ -330,7 +331,7 @@ promisifyAll(DNS, {
330331
* @see Zone
331332
* @type {Constructor}
332333
*/
333-
DNS.Zone = Zone;
334+
export { Zone };
334335

335336
/**
336337
* The default export of the `@google-cloud/dns` package is the {@link DNS}
@@ -361,4 +362,4 @@ DNS.Zone = Zone;
361362
* region_tag:dns_quickstart
362363
* Full quickstart example:
363364
*/
364-
module.exports = DNS;
365+
export { DNS };
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
'use strict';
1818

19-
const arrify = require('arrify');
20-
const {promisifyAll} = require('@google-cloud/promisify');
21-
const extend = require('extend');
19+
import * as arrify from 'arrify';
20+
import {promisifyAll} from '@google-cloud/promisify';
21+
import * as extend from 'extend';
2222
const format = require('string-format-obj');
2323

2424
/**
@@ -47,7 +47,12 @@ const format = require('string-format-obj');
4747
* data: '1.2.3.4'
4848
* });
4949
*/
50-
class Record {
50+
export class Record {
51+
zone_;
52+
type;
53+
metadata;
54+
rrdatas;
55+
data;
5156
constructor(zone, type, metadata) {
5257
this.zone_ = zone;
5358
/**
@@ -193,5 +198,3 @@ class Record {
193198
promisifyAll(Record, {
194199
exclude: ['toJSON', 'toString'],
195200
});
196-
197-
module.exports = Record;

0 commit comments

Comments
 (0)