Skip to content

Commit daf7646

Browse files
JustinBeckwiththiyaguk09
authored andcommitted
refactor: drop dependency on @google-cloud/common (googleapis#714)
1 parent 09df8aa commit daf7646

9 files changed

Lines changed: 44 additions & 32 deletions

File tree

handwritten/bigtable/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"test": "c8 mocha build/test"
4444
},
4545
"dependencies": {
46-
"@google-cloud/common": "^3.0.0",
4746
"@google-cloud/paginator": "^3.0.0",
4847
"@google-cloud/projectify": "^2.0.0",
4948
"@google-cloud/promisify": "^2.0.0",

handwritten/bigtable/src/.eslintrc.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

handwritten/bigtable/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import * as extend from 'extend';
1919
import {GoogleAuth, CallOptions} from 'google-gax';
2020
import * as gax from 'google-gax';
2121
import * as protos from '../protos/protos';
22-
import {AbortableDuplex} from '@google-cloud/common';
2322

2423
import {AppProfile} from './app-profile';
2524
import {Cluster} from './cluster';
@@ -35,7 +34,7 @@ import {shouldRetryRequest} from './decorateStatus';
3534
import {google} from '../protos/protos';
3635
import {ServiceError} from 'google-gax';
3736
import * as v2 from './v2';
38-
import {PassThrough} from 'stream';
37+
import {PassThrough, Duplex} from 'stream';
3938

4039
// eslint-disable-next-line @typescript-eslint/no-var-requires
4140
const retryRequest = require('retry-request');
@@ -74,6 +73,10 @@ export interface RequestOptions {
7473
method?: string;
7574
}
7675

76+
export interface AbortableDuplex extends Duplex {
77+
abort(): void;
78+
}
79+
7780
export interface BigtableOptions extends gax.GoogleAuthOptions {
7881
/**
7982
* Override the default API endpoint used to reach Bigtable. This is useful for connecting to your local Bigtable emulator.
@@ -1093,6 +1096,7 @@ export {
10931096
MutateCallback,
10941097
MutateOptions,
10951098
MutateResponse,
1099+
PartialFailureError,
10961100
Policy,
10971101
PolicyBinding,
10981102
PrefixRange,

handwritten/bigtable/src/row.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
MutateCallback,
2626
MutateResponse,
2727
MutateOptions,
28+
PartialFailureError,
2829
} from './table';
2930
import {Chunk} from './chunktransformer';
3031
import {CallOptions} from 'google-gax';
@@ -89,7 +90,7 @@ export type CreateRulesResponse = [
8990
google.bigtable.v2.IReadModifyWriteRowResponse
9091
];
9192
export type CreateRowCallback = (
92-
err: ServiceError | null,
93+
err: ServiceError | PartialFailureError | null,
9394
row?: Row | null,
9495
apiResponse?: google.protobuf.Empty
9596
) => void;

handwritten/bigtable/src/table.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import * as common from '@google-cloud/common';
1615
import {promisifyAll} from '@google-cloud/promisify';
1716
import arrify = require('arrify');
1817
import {ServiceError} from 'google-gax';
@@ -38,7 +37,7 @@ import {Mutation} from './mutation';
3837
import {Row} from './row';
3938
import {ChunkTransformer} from './chunktransformer';
4039
import {CallOptions} from 'google-gax';
41-
import {Bigtable} from '.';
40+
import {Bigtable, AbortableDuplex} from '.';
4241
import {Instance} from './instance';
4342
import {google} from '../protos/protos';
4443
import {Duplex} from 'stream';
@@ -353,12 +352,12 @@ export type GetRowsCallback = (
353352
) => void;
354353
export type GetRowsResponse = [Row[], google.bigtable.v2.ReadRowsResponse];
355354
export type InsertRowsCallback = (
356-
err: ServiceError | null,
355+
err: ServiceError | PartialFailureError | null,
357356
apiResponse?: google.protobuf.Empty
358357
) => void;
359358
export type InsertRowsResponse = [google.protobuf.Empty];
360359
export type MutateCallback = (
361-
err: ServiceError | null,
360+
err: ServiceError | PartialFailureError | null,
362361
apiResponse?: google.protobuf.Empty
363362
) => void;
364363
export type MutateResponse = [google.protobuf.Empty];
@@ -632,7 +631,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
632631
createReadStream(opts?: GetRowsOptions) {
633632
const options = opts || {};
634633
const maxRetries = is.number(this.maxRetries) ? this.maxRetries! : 3;
635-
let activeRequestStream: common.AbortableDuplex;
634+
let activeRequestStream: AbortableDuplex;
636635
let rowKeys: string[] | null;
637636
const ranges = options.ranges || [];
638637
let filter: {} | null;
@@ -1382,7 +1381,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
13821381
typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;
13831382
const options =
13841383
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
1385-
const entries = (arrify(entriesRaw) as Entry[]).reduce(
1384+
const entries: Entry[] = (arrify(entriesRaw) as Entry[]).reduce(
13861385
(a, b) => a.concat(b),
13871386
[]
13881387
);
@@ -1398,10 +1397,11 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
13981397
);
13991398
const mutationErrorsByEntryIndex = new Map();
14001399

1401-
const onBatchResponse = (err: ServiceError | null) => {
1400+
const onBatchResponse = (
1401+
err: ServiceError | PartialFailureError | null
1402+
) => {
14021403
if (err) {
1403-
// The error happened before a request was even made, don't
1404-
// retry.
1404+
// The error happened before a request was even made, don't retry.
14051405
callback(err);
14061406
return;
14071407
}
@@ -1412,10 +1412,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
14121412

14131413
if (mutationErrorsByEntryIndex.size !== 0) {
14141414
const mutationErrors = Array.from(mutationErrorsByEntryIndex.values());
1415-
err = new common.util.PartialFailureError({
1416-
errors: mutationErrors,
1417-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1418-
} as any) as ServiceError;
1415+
err = new PartialFailureError(mutationErrors);
14191416
}
14201417

14211418
callback(err);
@@ -1439,7 +1436,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
14391436
};
14401437

14411438
this.bigtable
1442-
.request({
1439+
.request<google.bigtable.v2.MutateRowsResponse>({
14431440
client: 'BigtableClient',
14441441
method: 'mutateRows',
14451442
reqOpts,
@@ -1878,3 +1875,26 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
18781875
promisifyAll(Table, {
18791876
exclude: ['family', 'row'],
18801877
});
1878+
1879+
export interface GoogleInnerError {
1880+
reason?: string;
1881+
message?: string;
1882+
}
1883+
1884+
export class PartialFailureError extends Error {
1885+
errors?: GoogleInnerError[];
1886+
constructor(errors: GoogleInnerError[]) {
1887+
super();
1888+
this.errors = errors;
1889+
this.name = 'PartialFailureError';
1890+
let messages = errors.map(e => e.message);
1891+
if (messages.length > 1) {
1892+
messages = messages.map((message, i) => ` ${i + 1}. ${message}`);
1893+
messages.unshift(
1894+
'Multiple errors occurred during the request. Please see the `errors` array for complete details.\n'
1895+
);
1896+
messages.push('\n');
1897+
}
1898+
this.message = messages.join('\n');
1899+
}
1900+
}

handwritten/bigtable/system-test/.eslintrc.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

handwritten/bigtable/system-test/mutate-rows.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import {afterEach, beforeEach, describe, it} from 'mocha';
2525
import * as sinon from 'sinon';
2626
import {EventEmitter} from 'events';
2727
import {ProjectIdCallback, GoogleAuth} from 'google-auth-library';
28-
import {PartialFailureError} from '@google-cloud/common/build/src/util';
29-
import {Entry} from '../src/table';
28+
import {Entry, PartialFailureError} from '../src/table';
3029
import {CancellableStream, GrpcClient} from 'google-gax';
3130
import {BigtableClient} from '../src/v2';
3231
import {PassThrough} from 'stream';

handwritten/bigtable/system-test/read-rows-acceptance-tests.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import * as ProtoBuf from 'protobufjs';
2424
import * as fs from 'fs';
2525
import * as path from 'path';
2626
import {Instance} from '../src/instance';
27-
import {Bigtable} from '../src';
28-
import {AbortableDuplex} from '@google-cloud/common';
27+
import {Bigtable, AbortableDuplex} from '../src';
2928

3029
const protosJson = path.resolve(__dirname, '../protos/protos.json');
3130
const root = ProtoBuf.Root.fromJSON(

handwritten/bigtable/test/.eslintrc.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)