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

fix(deps): update dependency @google-cloud/common-grpc to ^0.10.0 #504

Merged
merged 4 commits into from
Jan 31, 2019
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 9 additions & 7 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = {
/**
Expand Down Expand Up @@ -659,8 +661,8 @@ class Database 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_,
};
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
});
});
Expand Down
10 changes: 5 additions & 5 deletions src/session-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
});
}

Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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 = {
/**
Expand Down Expand Up @@ -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_,
};
Expand Down
3 changes: 2 additions & 1 deletion test/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions test/session-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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()));
Expand Down