Skip to content

Commit 8672058

Browse files
refactor(ts): enable lint and fix (#287)
1 parent 40dc175 commit 8672058

16 files changed

Lines changed: 1303 additions & 1410 deletions

File tree

handwritten/datastore/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
"scripts": {
3232
"docs": "jsdoc -c .jsdoc.js",
3333
"generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json",
34-
"lint": "eslint 'samples/*.js' 'samples/**/*.js'",
34+
"lint": "gts check && eslint '**/*.js'",
3535
"cover": "nyc --reporter=lcov mocha build/test && nyc report",
3636
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
3737
"test-no-cover": "mocha build/test",
3838
"test": "npm run cover",
3939
"presystem-test": "npm run compile",
4040
"system-test": "mocha build/system-test --timeout 600000",
41-
"fix": "eslint 'samples/*.js' 'samples/**/*.js' --fix",
41+
"fix": "gts fix && eslint '**/*.js' --fix",
4242
"clean": "gts clean",
4343
"compile": "tsc -p . && cp -r src/v1/ build/src/v1/ && cp -r protos build/ && cp test/*.js build/test",
4444
"prepare": "npm run compile",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
rules:
3+
node/no-unpublished-require: off
4+
node/no-missing-require: off

handwritten/datastore/src/entity.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ entity.isDsGeoPoint = isDsGeoPoint;
184184
* });
185185
*/
186186
class Key {
187-
188187
namespace: string;
189188
id?: string;
190189
name?: string;
@@ -294,7 +293,7 @@ function decodeValueProto(valueProto) {
294293
}
295294

296295
case 'integerValue': {
297-
return parseInt(value, 10);
296+
return Number(value);
298297
}
299298

300299
case 'entityValue': {
@@ -306,13 +305,11 @@ function decodeValueProto(valueProto) {
306305
}
307306

308307
case 'timestampValue': {
309-
const milliseconds = parseInt(value.nanos, 10) / 1e6;
310-
return new Date(parseInt(value.seconds, 10) * 1000 + milliseconds);
308+
const milliseconds = Number(value.nanos) / 1e6;
309+
return new Date(Number(value.seconds) * 1000 + milliseconds);
311310
}
312311

313-
default: {
314-
return value;
315-
}
312+
default: { return value; }
316313
}
317314
}
318315

@@ -455,6 +452,7 @@ function entityFromEntityProto(entityProto) {
455452

456453
const properties = entityProto.properties || {};
457454

455+
// tslint:disable-next-line forin
458456
for (const property in properties) {
459457
const value = properties[property];
460458
entityObject[property] = entity.decodeValueProto(value);
@@ -502,10 +500,13 @@ function entityToEntityProto(entityObject) {
502500
const entityProto = {
503501
key: null,
504502

505-
properties: Object.keys(properties).reduce((encoded, key) => {
506-
encoded[key] = entity.encodeValue(properties[key]);
507-
return encoded;
508-
}, {}),
503+
properties: Object.keys(properties)
504+
.reduce(
505+
(encoded, key) => {
506+
encoded[key] = entity.encodeValue(properties[key]);
507+
return encoded;
508+
},
509+
{}),
509510
};
510511

511512
if (excludeFromIndexes && excludeFromIndexes.length > 0) {
@@ -526,11 +527,9 @@ function entityToEntityProto(entityObject) {
526527
if (!hasArrayPath && !hasEntityPath) {
527528
// This is the path end node. Traversal ends here in either case.
528529
if (entity.properties) {
529-
if (
530-
entity.properties[path] &&
531-
// array properties should be excluded with [] syntax:
532-
!entity.properties[path].arrayValue
533-
) {
530+
if (entity.properties[path] &&
531+
// array properties should be excluded with [] syntax:
532+
!entity.properties[path].arrayValue) {
534533
// This is the property to exclude!
535534
entity.properties[path].excludeFromIndexes = true;
536535
}
@@ -561,27 +560,25 @@ function entityToEntityProto(entityObject) {
561560
return;
562561
}
563562

564-
if (
565-
firstPathPartIsArray &&
566-
// check also if the property in question is actually an array value.
567-
entity.properties[firstPathPart].arrayValue
568-
) {
563+
if (firstPathPartIsArray &&
564+
// check also if the property in question is actually an array value.
565+
entity.properties[firstPathPart].arrayValue) {
569566
const array = entity.properties[firstPathPart].arrayValue;
570567
array.values.forEach(value => {
571568
if (remainderPath === '') {
572569
// We want to exclude *this* array property, which is
573570
// equivalent with excluding all its values
574571
// (including entity values at their roots):
575572
excludePathFromEntity(
576-
value,
577-
remainderPath // === ''
573+
value,
574+
remainderPath // === ''
578575
);
579576
} else {
580577
// Path traversal continues at value.entityValue,
581578
// if it is an entity, or must end at value.
582579
excludePathFromEntity(
583-
value.entityValue || value,
584-
remainderPath // !== ''
580+
value.entityValue || value,
581+
remainderPath // !== ''
585582
);
586583
}
587584
});
@@ -758,6 +755,7 @@ function keyToKeyProto(key) {
758755
}
759756

760757
keyProto.path.unshift(pathElement);
758+
// tslint:disable-next-line no-conditional-assignment
761759
} while ((key = key.parent) && ++numKeysWalked);
762760

763761
return keyProto;

handwritten/datastore/src/index.ts

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
*/
3838

3939
import * as arrify from 'arrify';
40-
import {GrpcClient, GrpcClientOptions} from 'google-gax';
4140
import {GoogleAuth} from 'google-auth-library';
41+
import {GrpcClient, GrpcClientOptions} from 'google-gax';
4242
import * as is from 'is';
4343

44-
import {DatastoreRequest} from './request';
4544
import {entity} from './entity';
4645
import {Query} from './query';
46+
import {DatastoreRequest} from './request';
4747
import {Transaction} from './transaction';
4848

4949
const {grpc} = new GrpcClient({} as GrpcClientOptions);
@@ -88,7 +88,7 @@ const gapic = Object.freeze({
8888
*
8989
* Additionally, `DATASTORE_PROJECT_ID` is recognized. If you have this set,
9090
* you don't need to provide a `projectId`.
91-
*-
91+
*
9292
*
9393
* @class
9494
* @extends {DatastoreRequest}
@@ -104,13 +104,14 @@ const gapic = Object.freeze({
104104
* @example <caption>Import the client library</caption>
105105
* const {Datastore} = require('@google-cloud/datastore');
106106
*
107-
* @example <caption>Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:</caption>
108-
* const datastore = new Datastore();
107+
* @example <caption>Create a client that uses <a
108+
* href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application
109+
* Default Credentials (ADC)</a>:</caption> const datastore = new Datastore();
109110
*
110-
* @example <caption>Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:</caption>
111-
* const datastore = new Datastore({
112-
* projectId: 'your-project-id',
113-
* keyFilename: '/path/to/keyfile.json'
111+
* @example <caption>Create a client with <a
112+
* href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit
113+
* credentials</a>:</caption> const datastore = new Datastore({ projectId:
114+
* 'your-project-id', keyFilename: '/path/to/keyfile.json'
114115
* });
115116
*
116117
* @example <caption>Retrieving Records</caption>
@@ -312,9 +313,11 @@ const gapic = Object.freeze({
312313
* const customerId2 = 4993882;
313314
* const customerKey1 = datastore.key(['Customer', customerId1]);
314315
* const customerKey2 = datastore.key(['Customer', customerId2]);
315-
* const cookieKey1 = datastore.key(['Customer', customerId1, 'Cookie', 'cookie28839']); // child entity
316-
* const cookieKey2 = datastore.key(['Customer', customerId1, 'Cookie', 'cookie78984']); // child entity
317-
* const cookieKey3 = datastore.key(['Customer', customerId2, 'Cookie', 'cookie93911']); // child entity
316+
* const cookieKey1 = datastore.key(['Customer', customerId1, 'Cookie',
317+
* 'cookie28839']); // child entity const cookieKey2 =
318+
* datastore.key(['Customer', customerId1, 'Cookie', 'cookie78984']); // child
319+
* entity const cookieKey3 = datastore.key(['Customer', customerId2, 'Cookie',
320+
* 'cookie93911']); // child entity
318321
*
319322
* const entities = [];
320323
*
@@ -400,7 +403,7 @@ class Datastore extends DatastoreRequest {
400403
this.namespace = options.namespace;
401404

402405
const userProvidedProjectId =
403-
options.projectId || process.env.DATASTORE_PROJECT_ID;
406+
options.projectId || process.env.DATASTORE_PROJECT_ID;
404407
const defaultProjectId = '{{projectId}}';
405408

406409
/**
@@ -413,16 +416,15 @@ class Datastore extends DatastoreRequest {
413416
this.determineBaseUrl_(options.apiEndpoint);
414417

415418
this.options = Object.assign(
416-
{
417-
libName: 'gccl',
418-
libVersion: require('../../package.json').version,
419-
scopes: gapic.v1.DatastoreClient.scopes,
420-
servicePath: this.baseUrl_,
421-
port: is.number(this.port_) ? this.port_ : 443,
422-
projectId: userProvidedProjectId,
423-
},
424-
options
425-
);
419+
{
420+
libName: 'gccl',
421+
libVersion: require('../../package.json').version,
422+
scopes: gapic.v1.DatastoreClient.scopes,
423+
servicePath: this.baseUrl_,
424+
port: is.number(this.port_) ? this.port_ : 443,
425+
projectId: userProvidedProjectId,
426+
},
427+
options);
426428
if (this.customEndpoint_) {
427429
this.options.sslCreds = grpc.credentials.createInsecure();
428430
}
@@ -647,7 +649,8 @@ class Datastore extends DatastoreRequest {
647649
}
648650

649651
/**
650-
* Helper to create a Key object, scoped to the instance's namespace by default.
652+
* Helper to create a Key object, scoped to the instance's namespace by
653+
* default.
651654
*
652655
* You may also specify a configuration object to define a namespace and path.
653656
*
@@ -664,15 +667,15 @@ class Datastore extends DatastoreRequest {
664667
* const key = datastore.key('Company');
665668
*
666669
* @example
667-
* <caption>Create a complete key with a kind value of `Company` and id `123`.</caption>
668-
* const {Datastore} = require('@google-cloud/datastore');
670+
* <caption>Create a complete key with a kind value of `Company` and id
671+
* `123`.</caption> const {Datastore} = require('@google-cloud/datastore');
669672
* const datastore = new Datastore();
670673
* const key = datastore.key(['Company', 123]);
671674
*
672675
* @example
673-
* <caption>If the ID integer is outside the bounds of a JavaScript Number object, create an Int.</caption>
674-
* const {Datastore} = require('@google-cloud/datastore');
675-
* const datastore = new Datastore();
676+
* <caption>If the ID integer is outside the bounds of a JavaScript Number
677+
* object, create an Int.</caption> const {Datastore} =
678+
* require('@google-cloud/datastore'); const datastore = new Datastore();
676679
* const key = datastore.key([
677680
* 'Company',
678681
* datastore.int('100000000000001234')
@@ -686,21 +689,19 @@ class Datastore extends DatastoreRequest {
686689
* const key = datastore.key(['Company', 'Google']);
687690
*
688691
* @example
689-
* <caption>Create a complete key from a provided namespace and path.</caption>
690-
* const {Datastore} = require('@google-cloud/datastore');
692+
* <caption>Create a complete key from a provided namespace and
693+
* path.</caption> const {Datastore} = require('@google-cloud/datastore');
691694
* const datastore = new Datastore();
692695
* const key = datastore.key({
693696
* namespace: 'My-NS',
694697
* path: ['Company', 123]
695698
* });
696699
*/
697700
key(options) {
698-
options = is.object(options)
699-
? options
700-
: {
701-
namespace: this.namespace,
702-
path: arrify(options),
703-
};
701+
options = is.object(options) ? options : {
702+
namespace: this.namespace,
703+
path: arrify(options),
704+
};
704705
return new entity.Key(options);
705706
}
706707

@@ -742,9 +743,9 @@ class Datastore extends DatastoreRequest {
742743
}
743744

744745
/**
745-
* Determine the appropriate endpoint to use for API requests. If not explicitly
746-
* defined, check for the "DATASTORE_EMULATOR_HOST" environment variable, used
747-
* to connect to a local Datastore server.
746+
* Determine the appropriate endpoint to use for API requests. If not
747+
* explicitly defined, check for the "DATASTORE_EMULATOR_HOST" environment
748+
* variable, used to connect to a local Datastore server.
748749
*
749750
* @private
750751
*
@@ -768,10 +769,9 @@ class Datastore extends DatastoreRequest {
768769
this.port_ = Number(baseUrl.match(port)![1]);
769770
}
770771

771-
this.baseUrl_ = baseUrl
772-
.replace(leadingProtocol, '')
773-
.replace(port, '')
774-
.replace(trailingSlashes, '');
772+
this.baseUrl_ = baseUrl.replace(leadingProtocol, '')
773+
.replace(port, '')
774+
.replace(trailingSlashes, '');
775775
}
776776

777777
/**
@@ -813,19 +813,21 @@ export {Datastore};
813813
* @module {Datastore} @google-cloud/datastore
814814
* @alias nodejs-datastore
815815
*
816-
* @example <caption>Install the client library with <a href="https://www.npmjs.com/">npm</a>:</caption>
817-
* npm install --save @google-cloud/datastore
816+
* @example <caption>Install the client library with <a
817+
* href="https://www.npmjs.com/">npm</a>:</caption> npm install --save
818+
* @google-cloud/datastore
818819
*
819820
* @example <caption>Import the client library</caption>
820821
* const {Datastore} = require('@google-cloud/datastore');
821822
*
822-
* @example <caption>Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:</caption>
823-
* const datastore = new Datastore();
823+
* @example <caption>Create a client that uses <a
824+
* href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application
825+
* Default Credentials (ADC)</a>:</caption> const datastore = new Datastore();
824826
*
825-
* @example <caption>Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:</caption>
826-
* const datastore = new Datastore({
827-
* projectId: 'your-project-id',
828-
* keyFilename: '/path/to/keyfile.json'
827+
* @example <caption>Create a client with <a
828+
* href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit
829+
* credentials</a>:</caption> const datastore = new Datastore({ projectId:
830+
* 'your-project-id', keyFilename: '/path/to/keyfile.json'
829831
* });
830832
*
831833
* @example <caption>include:samples/quickstart.js</caption>

handwritten/datastore/src/query.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ class Query {
384384
* });
385385
*
386386
* //-
387-
* // A keys-only query returns just the keys of the result entities instead of
387+
* // A keys-only query returns just the keys of the result entities instead
388+
* of
388389
* // the entities themselves, at lower latency and cost.
389390
* //-
390391
* query.select('__key__');

0 commit comments

Comments
 (0)