Skip to content

Commit

Permalink
refactor: asyncify the system test (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Feb 9, 2019
1 parent e8c72a2 commit 9b39431
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 509 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -65,16 +65,17 @@
"@types/proxyquire": "^1.3.28",
"@types/sinon": "^7.0.2",
"@types/through2": "^2.0.34",
"assert-rejects": "^1.0.0",
"codecov": "^3.0.2",
"eslint": "^5.0.0",
"eslint-config-prettier": "^4.0.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-prettier": "^3.0.0",
"google-proto-files": "^0.18.0",
"gts": "^0.9.0",
"jsdoc-baseline": "git+https://github.com/hegemonic/jsdoc-baseline.git",
"intelli-espower-loader": "^1.0.1",
"jsdoc": "^3.5.5",
"jsdoc-baseline": "git+https://github.com/hegemonic/jsdoc-baseline.git",
"mocha": "^5.2.0",
"nyc": "^13.0.0",
"power-assert": "^1.5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -35,7 +35,7 @@ import {Query} from './query';
import {DatastoreRequest} from './request';
import {Transaction} from './transaction';

const {grpc} = new GrpcClient({} as GrpcClientOptions);
const {grpc} = new GrpcClient();

// tslint:disable-next-line: no-any
export type PathType = any;
Expand Down
1 change: 0 additions & 1 deletion src/query.ts
Expand Up @@ -16,7 +16,6 @@

import * as arrify from 'arrify';
import {Key} from 'readline';

import {Datastore} from '.';
import {Entity} from './entity';
import {Transaction} from './transaction';
Expand Down
6 changes: 4 additions & 2 deletions src/request.ts
Expand Up @@ -197,7 +197,7 @@ class DatastoreRequest {
},
gaxOpts: options.gaxOptions,
},
(err: Error, resp: AllocateIdsRequestResponse) => {
(err, resp) => {
if (err) {
callback!(err, null, resp);
return;
Expand Down Expand Up @@ -960,7 +960,9 @@ class DatastoreRequest {
* });
*/
save(entities: Entities, gaxOptions?: CallOptions):
void|Promise<google.datastore.v1.ICommitResponse>;
Promise<google.datastore.v1.ICommitResponse>;
save(entities: Entities, gaxOptions: CallOptions, callback: SaveCallback):
void;
save(entities: Entities, callback: SaveCallback): void;
save(
entities: Entities, gaxOptionsOrCallback?: CallOptions|SaveCallback,
Expand Down
27 changes: 13 additions & 14 deletions src/transaction.ts
Expand Up @@ -17,15 +17,15 @@
import {promisifyAll} from '@google-cloud/promisify';
import * as arrify from 'arrify';
import {CallOptions} from 'google-gax';
import * as r from 'request';

import {google} from '../proto/datastore';

import {Datastore, TransactionOptions} from '.';
import {entity, Entity} from './entity';
import {Query} from './query';
import {DatastoreRequest} from './request';

type RollbackCallback = google.datastore.v1.Datastore.RollbackCallback;
type RollbackResponse = google.datastore.v1.RollbackResponse;

/**
* A transaction is a set of Datastore operations on one or more entities. Each
* transaction is guaranteed to be atomic, which means that transactions are
Expand Down Expand Up @@ -235,7 +235,7 @@ class Transaction extends DatastoreRequest {
reqOpts,
gaxOpts: gaxOptions || {},
},
(err: Error, resp: r.Response) => {
(err, resp) => {
if (err) {
// Rollback automatically for the user.
this.rollback(() => {
Expand Down Expand Up @@ -378,14 +378,12 @@ class Transaction extends DatastoreRequest {
* const apiResponse = data[0];
* });
*/
rollback(gaxOptions: CallOptions):
Promise<google.datastore.v1.RollbackResponse>;
rollback(callback: google.datastore.v1.Datastore.RollbackCallback): void;
rollback(gaxOptions?: CallOptions): Promise<RollbackResponse>;
rollback(callback: RollbackCallback): void;
rollback(gaxOptions: CallOptions, callback: RollbackCallback): void;
rollback(
gaxOptionsOrCallback: CallOptions|
google.datastore.v1.Datastore.RollbackCallback,
cb?: google.datastore.v1.Datastore.RollbackCallback):
void|Promise<google.datastore.v1.RollbackResponse> {
gaxOptionsOrCallback?: CallOptions|RollbackCallback,
cb?: RollbackCallback): void|Promise<RollbackResponse> {
const gaxOptions =
typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
const callback =
Expand All @@ -397,7 +395,7 @@ class Transaction extends DatastoreRequest {
method: 'rollback',
gaxOpts: gaxOptions || {},
},
(err: Error, resp: r.Response) => {
(err, resp) => {
this.skipCommit = true;
callback(err || null, resp);
});
Expand Down Expand Up @@ -490,7 +488,7 @@ class Transaction extends DatastoreRequest {
reqOpts,
gaxOpts: options.gaxOptions,
},
(err: Error, resp: r.Response) => {
(err, resp) => {
if (err) {
callback(err, null, resp);
return;
Expand Down Expand Up @@ -629,7 +627,8 @@ class Transaction extends DatastoreRequest {
* });
* });
*/
save(entities: Entities): void {
// tslint:disable-next-line no-any
save(entities: Entities): any {
arrify(entities).forEach(ent => {
this.modifiedEntities_.push({
entity: {
Expand Down

0 comments on commit 9b39431

Please sign in to comment.