Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Convert to TypeScript #97

Merged
merged 2 commits into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Language: JavaScript
BasedOnStyle: Google
ColumnLimit: 80
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ system-test/secrets.js
system-test/*key.json
*.lock
package-lock.json
build/
40 changes: 30 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"node": ">=6.0.0"
},
"repository": "googleapis/nodejs-dns",
"main": "./src/index.js",
"main": "./build/src/index.js",
"types": "./build/src/index.d.ts",
"files": [
"src",
"build/src",
"AUTHORS",
"CONTRIBUTORS",
"LICENSE"
Expand Down Expand Up @@ -41,19 +42,21 @@
"greenkeeper[bot] <greenkeeper[bot]@users.noreply.github.com>"
],
"scripts": {
"cover": "nyc --reporter=lcov mocha test/*.js && nyc report",
"docs": "jsdoc -c .jsdoc.js",
"generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json",
"lint": "eslint src/ samples/ system-test/ test/",
"prettier": "prettier --write src/*.js src/*/*.js samples/*.js samples/*/*.js test/*.js test/*/*.js system-test/*.js system-test/*/*.js",
"publish-module": "node ../../scripts/publish.js dns",
"test-no-cover": "mocha test/*.js",
"test": "npm run cover",
"lint": "echo lint not enabled 👻 # gts check && eslint samples/",
"test": "nyc mocha build/test",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
"system-test": "mocha system-test/*.js --timeout 600000"
"presystem-test": "npm run compile",
"system-test": "mocha build/system-test --timeout 600000",
"clean": "gts clean",
"compile": "tsc -p .",
"fix": "gts fix && prettier --write samples/*.js samples/*/*.js",
"prepare": "npm run compile",
"pretest": "npm run compile"
},
"dependencies": {
"@google-cloud/common": "^0.23.0",
"@google-cloud/common": "^0.24.0",
"@google-cloud/paginator": "^0.1.0",
"@google-cloud/promisify": "^0.3.0",
"arrify": "^1.0.1",
Expand All @@ -69,12 +72,23 @@
},
"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.20",
"@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/uuid": "^3.4.4",
"async": "^2.6.1",
"codecov": "^3.0.2",
"eslint": "^5.0.0",
"eslint-config-prettier": "^3.0.0",
"eslint-plugin-node": "^7.0.0",
"eslint-plugin-prettier": "^2.6.0",
"gts": "^0.8.0",
"ink-docstrap": "^1.3.2",
"intelli-espower-loader": "^1.0.1",
"jsdoc": "^3.5.5",
Expand All @@ -84,6 +98,12 @@
"prettier": "^1.13.5",
"proxyquire": "^2.0.1",
"tmp": "^0.0.33",
"typescript": "~2.8.0",
"uuid": "^3.2.1"
},
"nyc": {
"exclude": [
"build/test"
]
}
}
2 changes: 1 addition & 1 deletion samples/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const sinon = require(`sinon`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);

const DNS = proxyquire(`@google-cloud/dns`, {});
const {DNS} = proxyquire(`@google-cloud/dns`, {});
const dns = new DNS();

const uuid = require(`uuid`);
Expand Down
2 changes: 1 addition & 1 deletion samples/system-test/zones.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

const DNS = require(`@google-cloud/dns`);
const {DNS} = require(`@google-cloud/dns`);
const path = require(`path`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
Expand Down
2 changes: 1 addition & 1 deletion samples/zones.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
function listZones() {
// [START dns_list_zones]
// Imports the Google Cloud client library
const DNS = require('@google-cloud/dns');
const {DNS} = require('@google-cloud/dns');

// Creates a client
const dns = new DNS();
Expand Down
20 changes: 9 additions & 11 deletions src/change.js → src/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

'use strict';

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

/**
* @class
Expand All @@ -32,7 +32,7 @@ const {promisifyAll} = require('@google-cloud/promisify');
* const zone = dns.zone('zone-id');
* const change = zone.change('change-id');
*/
class Change extends ServiceObject {
export class Change extends ServiceObject {
constructor(zone, id) {
const methods = {
/**
Expand Down Expand Up @@ -178,9 +178,9 @@ class Change extends ServiceObject {
* @name Change#id
* @type {string}
*/
id: id,
methods: methods,
requestModule: teenyRequest,
id,
methods,
requestModule: teenyRequest as any,
});
}
/**
Expand Down Expand Up @@ -217,8 +217,8 @@ class Change extends ServiceObject {
* const apiResponse = data[1];
* });
*/
create(config, callback) {
this.parent.createChange(config, (err, change, apiResponse) => {
create(config, callback?) {
(this.parent as any).createChange(config, (err, change, apiResponse) => {
if (err) {
callback(err, null, apiResponse);
return;
Expand All @@ -236,5 +236,3 @@ class Change extends ServiceObject {
* that a callback is omitted.
*/
promisifyAll(Change);

module.exports = Change;
95 changes: 48 additions & 47 deletions src/index.js → src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

'use strict';

const arrify = require('arrify');
const {Service} = require('@google-cloud/common');
const {paginator} = require('@google-cloud/paginator');
const {promisifyAll} = require('@google-cloud/promisify');
const extend = require('extend');
const is = require('is');
const teenyRequest = require('teeny-request').teenyRequest;
import * as arrify from 'arrify';
import { Service } from '@google-cloud/common';
import { paginator } from '@google-cloud/paginator';
import { promisifyAll } from '@google-cloud/promisify';
import * as extend from 'extend';
import * as is from 'is';
import { teenyRequest } from 'teeny-request';

const Zone = require('./zone');
import { Zone } from './zone';

/**
* @typedef {object} ClientConfig
Expand Down Expand Up @@ -80,6 +80,7 @@ const Zone = require('./zone');
* Full quickstart example:
*/
class DNS extends Service {
getZonesStream;
constructor(options) {
options = options || {};
const config = {
Expand All @@ -88,10 +89,42 @@ class DNS extends Service {
'https://www.googleapis.com/auth/ndev.clouddns.readwrite',
'https://www.googleapis.com/auth/cloud-platform',
],
packageJson: require('../package.json'),
requestModule: teenyRequest,
packageJson: require('../../package.json'),
requestModule: teenyRequest as any,
};
super(config, options);

/**
* Get {@link Zone} objects for all of the zones in your project as
* a readable object stream.
*
* @method DNS#getZonesStream
* @param {GetZonesRequest} [query] Query object for listing zones.
* @returns {ReadableStream} A readable stream that emits {@link Zone} instances.
*
* @example
* const DNS = require('@google-cloud/dns');
* const dns = new DNS();
*
* dns.getZonesStream()
* .on('error', console.error)
* .on('data', function(zone) {
* // zone is a Zone object.
* })
* .on('end', function() {
* // All zones retrieved.
* });
*
* //-
* // If you anticipate many results, you can end a stream early to prevent
* // unnecessary processing and API requests.
* //-
* dns.getZonesStream()
* .on('data', function(zone) {
* this.end();
* });
*/
this.getZonesStream = paginator.streamify('getZones');
}
/**
* Config to set for the zone.
Expand Down Expand Up @@ -166,7 +199,7 @@ class DNS extends Service {
uri: '/managedZones',
json: config,
},
function(err, resp) {
function (err, resp) {
if (err) {
callback(err, null, resp);
return;
Expand Down Expand Up @@ -233,12 +266,12 @@ class DNS extends Service {
uri: '/managedZones',
qs: query,
},
function(err, resp) {
function (err, resp) {
if (err) {
callback(err, null, null, resp);
return;
}
const zones = arrify(resp.managedZones).map(function(zone) {
const zones = arrify(resp.managedZones).map(function (zone) {
const zoneInstance = self.zone(zone.name);
zoneInstance.metadata = zone;
return zoneInstance;
Expand Down Expand Up @@ -276,38 +309,6 @@ class DNS extends Service {
}
}

/**
* Get {@link Zone} objects for all of the zones in your project as
* a readable object stream.
*
* @method DNS#getZonesStream
* @param {GetZonesRequest} [query] Query object for listing zones.
* @returns {ReadableStream} A readable stream that emits {@link Zone} instances.
*
* @example
* const DNS = require('@google-cloud/dns');
* const dns = new DNS();
*
* dns.getZonesStream()
* .on('error', console.error)
* .on('data', function(zone) {
* // zone is a Zone object.
* })
* .on('end', function() {
* // All zones retrieved.
* });
*
* //-
* // If you anticipate many results, you can end a stream early to prevent
* // unnecessary processing and API requests.
* //-
* dns.getZonesStream()
* .on('data', function(zone) {
* this.end();
* });
*/
DNS.prototype.getZonesStream = paginator.streamify('getZones');

/*! Developer Documentation
*
* These methods can be auto-paginated.
Expand All @@ -330,7 +331,7 @@ promisifyAll(DNS, {
* @see Zone
* @type {Constructor}
*/
DNS.Zone = Zone;
export { Zone };

/**
* The default export of the `@google-cloud/dns` package is the {@link DNS}
Expand Down Expand Up @@ -361,4 +362,4 @@ DNS.Zone = Zone;
* region_tag:dns_quickstart
* Full quickstart example:
*/
module.exports = DNS;
export { DNS };
15 changes: 9 additions & 6 deletions src/record.js → src/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

'use strict';

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

/**
Expand Down Expand Up @@ -47,7 +47,12 @@ const format = require('string-format-obj');
* data: '1.2.3.4'
* });
*/
class Record {
export class Record {
zone_;
type;
metadata;
rrdatas;
data;
constructor(zone, type, metadata) {
this.zone_ = zone;
/**
Expand Down Expand Up @@ -193,5 +198,3 @@ class Record {
promisifyAll(Record, {
exclude: ['toJSON', 'toString'],
});

module.exports = Record;
Loading