From 8f5464fc02b26a09448141e81c28577646b6a3b1 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" Date: Tue, 29 Jan 2019 09:25:31 +0000 Subject: [PATCH 1/3] fix(deps): update dependency @google-cloud/common-grpc to ^0.10.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 216d33f0d..5324ab133 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "presystem-test": "npm run compile" }, "dependencies": { - "@google-cloud/common-grpc": "^0.9.2", + "@google-cloud/common-grpc": "^0.10.0", "@google-cloud/paginator": "^0.1.0", "@google-cloud/projectify": "^0.3.0", "@google-cloud/promisify": "^0.3.0", From a144f4a1a1dead3a8ed281ea7129cecd0a200bad Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Tue, 29 Jan 2019 09:47:30 -0800 Subject: [PATCH 2/3] fixy --- src/database.ts | 16 +++++++++------- src/session-pool.ts | 10 +++++----- src/session.ts | 10 +++++++--- system-test/spanner.ts | 2 +- test/database.ts | 3 ++- test/index.ts | 3 ++- test/session-pool.ts | 8 ++++---- 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/database.ts b/src/database.ts index 7c4ff8d7c..ee94e1d37 100644 --- a/src/database.ts +++ b/src/database.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {ApiError, DeleteCallback, ExistsCallback, GetMetadataCallback, Metadata, ServiceObjectConfig} from '@google-cloud/common'; +import {ApiError, DeleteCallback, ExistsCallback, Metadata, MetadataCallback, ServiceObjectConfig} from '@google-cloud/common'; import {ServiceObject} from '@google-cloud/common-grpc'; import {promisifyAll} from '@google-cloud/promisify'; import * as arrify from 'arrify'; @@ -59,6 +59,8 @@ export interface DatabaseCallback { * const database = instance.database('my-database'); */ class Database extends ServiceObject { + formattedName_: string; + pool_: SessionPool; constructor(instance: Instance, name: string, poolOptions?) { const methods = { /** @@ -659,8 +661,8 @@ class Database extends ServiceObject { * }); */ getMetadata(): Promise; - getMetadata(callback: GetMetadataCallback): void; - getMetadata(callback?: GetMetadataCallback): void|Promise { + getMetadata(callback: MetadataCallback): void; + getMetadata(callback?: MetadataCallback): void|Promise { const reqOpts = { name: this.formattedName_, }; @@ -904,9 +906,9 @@ class Database extends ServiceObject { callback(err, null); return; } - session.beginTransaction(options, (err, transaction) => { + session!.beginTransaction(options, (err, transaction) => { if (err) { - this.pool_.release(session); + this.pool_.release(session!); callback(err, null); return; } @@ -930,10 +932,10 @@ class Database extends ServiceObject { callback(err, null); return; } - config.reqOpts.session = session.formattedName_; + config.reqOpts.session = session!.formattedName_; // tslint:disable-next-line only-arrow-functions this.request(config, function() { - pool.release(session); + pool.release(session!); callback.apply(null, arguments); }); }); diff --git a/src/session-pool.ts b/src/session-pool.ts index 6798003b6..d19cca3d3 100644 --- a/src/session-pool.ts +++ b/src/session-pool.ts @@ -492,7 +492,7 @@ export class SessionPool extends EventEmitter implements SessionPoolInterface { * @param {Session} session The session object. */ _borrow(session: Session): void { - const type = session.type; + const type = session.type!; const index = this._inventory[type].indexOf(session); this._inventory.borrowed.add(session); @@ -634,7 +634,7 @@ export class SessionPool extends EventEmitter implements SessionPoolInterface { continue; } - const type = session.type; + const type = session.type!; const index = this._inventory[type].indexOf(session); this._inventory[type].splice(index, 1); @@ -680,7 +680,7 @@ export class SessionPool extends EventEmitter implements SessionPoolInterface { ]; return sessions.filter(session => { - return Date.now() - session.lastUsed >= idlesAfter; + return Date.now() - session.lastUsed! >= idlesAfter; }); } @@ -762,7 +762,7 @@ export class SessionPool extends EventEmitter implements SessionPoolInterface { // unpinged sessions only stay good for 1 hour const MAX_DURATION = 60000 * 60; - return Date.now() - session.lastUsed < MAX_DURATION; + return Date.now() - session.lastUsed! < MAX_DURATION; } /** @@ -829,7 +829,7 @@ export class SessionPool extends EventEmitter implements SessionPoolInterface { * @param {Session} session The session object. */ _release(session: Session): void { - const type = session.type; + const type = session.type!; this._inventory[type].unshift(session); this._inventory.borrowed.delete(session); diff --git a/src/session.ts b/src/session.ts index ad1d493c9..73fc49479 100644 --- a/src/session.ts +++ b/src/session.ts @@ -27,7 +27,7 @@ import * as is from 'is'; import * as r from 'request'; import {Transaction, TransactionOptions} from './transaction'; import {Database} from './database'; -import {ServiceObjectConfig, DeleteCallback, Metadata, GetMetadataCallback, ResponseCallback} from '@google-cloud/common'; +import {ServiceObjectConfig, DeleteCallback, Metadata, MetadataCallback} from '@google-cloud/common'; import {CreateSessionOptions} from './common'; export type GetSessionResponse = [Session, r.Response]; @@ -83,6 +83,10 @@ export type BeginTransactionResponse = [Transaction, r.Response]; */ export class Session extends ServiceObject { id!: string; + formattedName_?: string; + type?: string; + txn?: Transaction; + lastUsed?: number; constructor(database: Database, name?: string) { const methods = { /** @@ -339,8 +343,8 @@ export class Session extends ServiceObject { * }); */ getMetadata(): Promise<[Metadata]>; - getMetadata(callback: GetMetadataCallback): void; - getMetadata(callback?: GetMetadataCallback): void|Promise<[Metadata]> { + getMetadata(callback: MetadataCallback): void; + getMetadata(callback?: MetadataCallback): void|Promise<[Metadata]> { const reqOpts = { name: this.formattedName_, }; diff --git a/system-test/spanner.ts b/system-test/spanner.ts index 2cfe25204..b8da0fcb5 100644 --- a/system-test/spanner.ts +++ b/system-test/spanner.ts @@ -29,7 +29,7 @@ const {Spanner} = require('../src'); const PREFIX = 'gcloud-tests-'; const RUN_ID = uuid.v1().split('-').shift(); // get a short uuid const LABEL = `gcloud-tests-${RUN_ID}`; -const spanner = new Spanner({projectId: process.env.GCLOUD_PROJECT}); +const spanner = new Spanner(); const CURRENT_TIME = Math.round(Date.now() / 1000).toString(); diff --git a/test/database.ts b/test/database.ts index 648e06470..b6f7dd7d5 100644 --- a/test/database.ts +++ b/test/database.ts @@ -240,7 +240,8 @@ describe('Database', () => { }, }); - const database = new Database(instanceInstance, NAME); + // tslint:disable-next-line no-any + const database: any = new Database(instanceInstance, NAME); assert(database instanceof FakeGrpcServiceObject); const calledWith = database.calledWith_[0]; diff --git a/test/index.ts b/test/index.ts index 570c3c411..43bb3196c 100644 --- a/test/index.ts +++ b/test/index.ts @@ -690,7 +690,8 @@ describe('Spanner', () => { }); it('should return an Operation object', () => { - const operation = spanner.operation(NAME); + // tslint:disable-next-line no-any + const operation: any = spanner.operation(NAME); assert(operation instanceof FakeGrpcOperation); assert.strictEqual(operation.calledWith_[0], spanner); assert.strictEqual(operation.calledWith_[1], NAME); diff --git a/test/session-pool.ts b/test/session-pool.ts index 9e073378f..0086a22f1 100644 --- a/test/session-pool.ts +++ b/test/session-pool.ts @@ -23,7 +23,7 @@ import * as sinon from 'sinon'; import * as stackTrace from 'stack-trace'; import * as timeSpan from 'time-span'; -import {Session} from '../src'; +import {Session, Transaction} from '../src'; import {Database} from '../src/database'; import * as sp from '../src/session-pool'; @@ -407,7 +407,7 @@ describe('SessionPool', () => { describe('getWriteSession', () => { it('should pass back the session and txn', done => { const fakeSession = createSession(); - const fakeTxn = new FakeTransaction(); + const fakeTxn = new FakeTransaction() as Transaction; fakeSession.txn = fakeTxn; @@ -496,7 +496,7 @@ describe('SessionPool', () => { sessionPool._release = noop; inventory.borrowed.add(session); - session.txn = {}; + session.txn = {} as Transaction; sessionPool.release(session); assert.strictEqual(session.txn, undefined); @@ -507,7 +507,7 @@ describe('SessionPool', () => { sessionPool._release = noop; inventory.borrowed.add(session); - session.lastUsed = null; + session.lastUsed = null!; sessionPool.release(session); assert(isAround(session.lastUsed, Date.now())); From 07d38cd7931ffe459a793e335c73441cfa029935 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Wed, 30 Jan 2019 10:05:41 -0800 Subject: [PATCH 3/3] Update spanner.ts --- system-test/spanner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-test/spanner.ts b/system-test/spanner.ts index b8da0fcb5..2cfe25204 100644 --- a/system-test/spanner.ts +++ b/system-test/spanner.ts @@ -29,7 +29,7 @@ const {Spanner} = require('../src'); const PREFIX = 'gcloud-tests-'; const RUN_ID = uuid.v1().split('-').shift(); // get a short uuid const LABEL = `gcloud-tests-${RUN_ID}`; -const spanner = new Spanner(); +const spanner = new Spanner({projectId: process.env.GCLOUD_PROJECT}); const CURRENT_TIME = Math.round(Date.now() / 1000).toString();