Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ts): convert to typescript #236

Merged
merged 5 commits into from
Nov 7, 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
2 changes: 1 addition & 1 deletion .jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
source: {
excludePattern: '(^|\\/|\\\\)[._]',
include: [
'src'
'build/src'
],
includePattern: '\\.js$'
},
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].

```javascript
// Imports the Google Cloud client library
const Datastore = require('@google-cloud/datastore');
const {Datastore} = require('@google-cloud/datastore');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';
Expand Down
35 changes: 27 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"node": ">=6.0.0"
},
"repository": "googleapis/nodejs-datastore",
"main": "./src/index.js",
"main": "./build/src/index.js",
"files": [
"protos",
"src",
Expand Down Expand Up @@ -53,14 +53,18 @@
"scripts": {
"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",
"cover": "nyc --reporter=lcov mocha test/*.js && nyc report",
"lint": "eslint 'samples/*.js' 'samples/**/*.js'",
"cover": "nyc --reporter=lcov mocha build/test && nyc report",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
"test-no-cover": "mocha test/*.js",
"test-no-cover": "mocha build/test",
"test": "npm run cover",
"system-test": "mocha system-test/*.js --timeout 600000",
"fix": "eslint '**/*.js' --fix && npm run prettier"
"presystem-test": "npm run compile",
"system-test": "mocha build/system-test --timeout 600000",
"fix": "eslint 'samples/*.js' 'samples/**/*.js' --fix",
"clean": "gts clean",
"compile": "tsc -p . && cp -r src/v1/ build/src/v1/ && cp -r protos build/",
"prepare": "npm run compile",
"pretest": "npm run compile"
},
"dependencies": {
"@google-cloud/projectify": "^0.3.0",
Expand All @@ -79,12 +83,21 @@
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^2.3.0",
"@types/arrify": "^1.0.4",
"@types/async": "^2.0.50",
"@types/extend": "^3.0.0",
"@types/is": "0.0.20",
"@types/mocha": "^5.2.5",
"@types/proxyquire": "^1.3.28",
"@types/sinon": "^5.0.5",
"@types/through2": "^2.0.34",
"async": "^2.6.1",
"codecov": "^3.0.2",
"eslint": "^5.0.0",
"eslint-config-prettier": "^3.0.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-prettier": "^3.0.0",
"gts": "^0.8.0",
"ink-docstrap": "^1.3.2",
"intelli-espower-loader": "^1.0.1",
"jsdoc": "^3.5.5",
Expand All @@ -93,6 +106,12 @@
"power-assert": "^1.5.0",
"prettier": "^1.13.5",
"proxyquire": "^2.0.1",
"sinon": "^7.0.0"
"sinon": "^7.0.0",
"typescript": "~3.1.5"
},
"nyc": {
"exclude": [
"build/test"
]
}
}
2 changes: 1 addition & 1 deletion samples/concepts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const sinon = require('sinon');
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
const Datastore = require('@google-cloud/datastore');
const {Datastore} = require('@google-cloud/datastore');

function makeStub() {
return sinon.stub().returns(Promise.resolve([]));
Expand Down
2 changes: 1 addition & 1 deletion samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// [START datastore_quickstart]
// Imports the Google Cloud client library
const Datastore = require('@google-cloud/datastore');
const {Datastore} = require('@google-cloud/datastore');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';
Expand Down
7 changes: 5 additions & 2 deletions samples/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const sinon = require(`sinon`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);

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

const entity = {description: `Buy milk`};
const kind = `Task`;
Expand Down Expand Up @@ -70,6 +71,8 @@ test.cb(`should get a task from Datastore`, t => {
};

proxyquire(`../quickstart`, {
'@google-cloud/datastore': sinon.stub().returns(datastoreMock),
'@google-cloud/datastore': {
Datastore: sinon.stub().returns(datastoreMock),
},
});
});
10 changes: 5 additions & 5 deletions samples/system-test/tasks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

'use strict';

const Datastore = require(`@google-cloud/datastore`);
const datastore = new Datastore({});
const path = require(`path`);
const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();
const path = require('path');
const test = require('ava');
const tools = require('@google-cloud/nodejs-repo-tools');

const cmd = `node tasks.js`;
const cwd = path.join(__dirname, `..`);
Expand Down
4 changes: 2 additions & 2 deletions samples/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/google-cloud-node/#/docs/datastore/latest/guides/authentication
const Datastore = require('@google-cloud/datastore');
const {Datastore} = require('@google-cloud/datastore');

// Creates a client
const datastore = new Datastore({});
const datastore = new Datastore();
// [END datastore_build_service]

/*
Expand Down
36 changes: 21 additions & 15 deletions src/entity.js → src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

'use strict';

const arrify = require('arrify');
const extend = require('extend');
const is = require('is');
import * as arrify from 'arrify';
import * as extend from 'extend';
import * as is from 'is';

const entity = module.exports;

Expand Down Expand Up @@ -48,7 +48,7 @@ entity.KEY_SYMBOL = Symbol('KEY');
* @param {number} value The double value.
*
* @example
* const Datastore = require('@google-cloud/datastore');
* const {Datastore} = require('@google-cloud/datastore');
* const datastore = new Datastore();
* const aDouble = datastore.double(7.3);
*/
Expand Down Expand Up @@ -82,7 +82,7 @@ entity.isDsDouble = isDsDouble;
* @param {number|string} value The integer value.
*
* @example
* const Datastore = require('@google-cloud/datastore');
* const {Datastore} = require('@google-cloud/datastore');
* const datastore = new Datastore();
* const anInt = datastore.int(7);
*/
Expand Down Expand Up @@ -118,7 +118,7 @@ entity.isDsInt = isDsInt;
* @param {number} coordinates.longitude Longitudinal value.
*
* @example
* const Datastore = require('@google-cloud/datastore');
* const {Datastore} = require('@google-cloud/datastore');
* const datastore = new Datastore();
* const coordinates = {
* latitude: 40.6894,
Expand Down Expand Up @@ -163,7 +163,7 @@ entity.isDsGeoPoint = isDsGeoPoint;
* @param {string} [options.namespace] Optional namespace.
*
* @example
* const Datastore = require('@google-cloud/datastore');
* const {Datastore} = require('@google-cloud/datastore');
* const datastore = new Datastore();
* const key = datastore.key({
* namespace: 'ns',
Expand Down Expand Up @@ -268,7 +268,7 @@ function decodeValueProto(valueProto) {
}

case 'doubleValue': {
return parseFloat(value, 10);
return Number(value);
}

case 'integerValue': {
Expand Down Expand Up @@ -310,14 +310,15 @@ entity.decodeValueProto = decodeValueProto;
* // }
*/
function encodeValue(value) {
const valueProto = {};
// tslint:disable-next-line no-any
const valueProto: any = {};

if (is.boolean(value)) {
valueProto.booleanValue = value;
return valueProto;
}

if (is.nil(value)) {
if (is.null(value)) {
valueProto.nullValue = 0;
return valueProto;
}
Expand Down Expand Up @@ -642,7 +643,8 @@ entity.isKeyComplete = isKeyComplete;
* });
*/
function keyFromKeyProto(keyProto) {
const keyOptions = {
// tslint:disable-next-line no-any
const keyOptions: any = {
path: [],
};

Expand Down Expand Up @@ -698,7 +700,8 @@ function keyToKeyProto(key) {
});
}

const keyProto = {
// tslint:disable-next-line no-any
const keyProto: any = {
path: [],
};

Expand All @@ -719,7 +722,8 @@ function keyToKeyProto(key) {
});
}

const pathElement = {
// tslint:disable-next-line no-any
const pathElement: any = {
kind: key.kind,
};

Expand Down Expand Up @@ -787,7 +791,8 @@ function queryToQueryProto(query) {
'+': 'ASCENDING',
};

const queryProto = {
// tslint:disable-next-line no-any
const queryProto: any = {
distinctOn: query.groupByVal.map(groupBy => {
return {
name: groupBy,
Expand Down Expand Up @@ -838,7 +843,8 @@ function queryToQueryProto(query) {

if (query.filters.length > 0) {
const filters = query.filters.map(filter => {
let value = {};
// tslint:disable-next-line no-any
let value: any = {};

if (filter.name === '__key__') {
value.keyValue = entity.keyToKeyProto(filter.val);
Expand Down
Loading