Skip to content

Commit 6f42f0c

Browse files
fix: improve typescript types (#663)
1 parent 9e27926 commit 6f42f0c

18 files changed

Lines changed: 507 additions & 460 deletions

handwritten/bigtable/src/app-profile.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
/*!
2-
* Copyright 2018 Google Inc. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
1614

1715
import {promisifyAll} from '@google-cloud/promisify';
1816
import * as is from 'is';

handwritten/bigtable/src/chunktransformer.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
/*!
2-
* Copyright 2018 Google Inc. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
import {Transform, TransformOptions} from 'stream';
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
1714

15+
import {Transform, TransformOptions} from 'stream';
1816
import {Bytes, Mutation} from './mutation';
1917

2018
export type Value = string | number | boolean | Uint8Array;

handwritten/bigtable/src/cluster.ts

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
/*!
2-
* Copyright 2016 Google Inc. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2016 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
1614

1715
import {promisifyAll} from '@google-cloud/promisify';
18-
import {CallOptions, Operation as GaxOperation} from 'google-gax';
16+
import {CallOptions, Operation as GaxOperation, Operation} from 'google-gax';
1917
import {ServiceError} from '@grpc/grpc-js';
2018

2119
import {google} from '../protos/protos';
@@ -49,7 +47,8 @@ export type CreateClusterResponse = [ICluster, GaxOperation, IOperation];
4947
export type BooleanResponse = [boolean];
5048
export type GetClusterResponse = [ICluster, IOperation];
5149
export type GetClustersResponse = [ICluster[], IOperation];
52-
export type MetadataResponse = [Metadata, IOperation];
50+
export type GetClusterMetadataResponse = [ICluster, IOperation];
51+
export type SetClusterMetadataResponse = [Operation, google.protobuf.Empty];
5352

5453
export type CreateClusterCallback = GenericCallback<IOperation>;
5554
export type DeleteClusterCallback = GenericCallback<IOperation>;
@@ -60,26 +59,21 @@ export type GetClustersCallback = (
6059
clusters?: ICluster[],
6160
apiResponse?: google.bigtable.admin.v2.IListClustersResponse
6261
) => void;
63-
export type SetClusterMetadataCallback = GenericOperationCallback<IOperation>;
62+
export type SetClusterMetadataCallback = GenericOperationCallback<
63+
Operation | null | undefined
64+
>;
6465

6566
export interface CreateClusterOptions {
6667
gaxOptions?: CallOptions;
67-
location: string;
68+
location?: string;
6869
nodes: number;
6970
storage?: string;
7071
}
71-
export interface GetClusterMetadataCallback {
72-
// tslint:disable-next-line no-any
73-
(...args: any[]): void;
74-
(
75-
err: ServiceError | null,
76-
metadata?: ICluster | null,
77-
apiResponse?: IOperation | null
78-
): void;
79-
}
80-
export interface Metadata extends CreateClusterOptions {
81-
displayName?: string;
82-
}
72+
export type GetClusterMetadataCallback = (
73+
err: ServiceError | null,
74+
metadata?: ICluster | null,
75+
apiResponse?: IOperation | null
76+
) => void;
8377

8478
/**
8579
* Create a cluster object to interact with your cluster.
@@ -99,7 +93,7 @@ export class Cluster {
9993
instance: Instance;
10094
id: string;
10195
name: string;
102-
metadata?: Metadata;
96+
metadata?: ICluster;
10397
constructor(instance: Instance, id: string) {
10498
this.bigtable = instance.bigtable;
10599
this.instance = instance;
@@ -322,8 +316,8 @@ Please use the format 'my-cluster' or '${instance.name}/clusters/my-cluster'.`);
322316
);
323317
}
324318

325-
getMetadata(): Promise<MetadataResponse>;
326-
getMetadata(gaxOptions: CallOptions): Promise<MetadataResponse>;
319+
getMetadata(): Promise<GetClusterMetadataResponse>;
320+
getMetadata(gaxOptions: CallOptions): Promise<GetClusterMetadataResponse>;
327321
getMetadata(callback: GetClusterMetadataCallback): void;
328322
getMetadata(
329323
gaxOptions: CallOptions,
@@ -346,15 +340,15 @@ Please use the format 'my-cluster' or '${instance.name}/clusters/my-cluster'.`);
346340
getMetadata(
347341
gaxOptionsOrCallback?: CallOptions | GetClusterMetadataCallback,
348342
cb?: GetClusterMetadataCallback
349-
): void | Promise<MetadataResponse> {
343+
): void | Promise<GetClusterMetadataResponse> {
350344
const callback =
351345
typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb!;
352346
const gaxOptions =
353347
typeof gaxOptionsOrCallback === 'object' && gaxOptionsOrCallback
354348
? gaxOptionsOrCallback
355349
: ({} as CallOptions);
356350

357-
this.bigtable.request(
351+
this.bigtable.request<google.bigtable.admin.v2.ICluster>(
358352
{
359353
client: 'BigtableInstanceAdminClient',
360354
method: 'getCluster',
@@ -363,22 +357,22 @@ Please use the format 'my-cluster' or '${instance.name}/clusters/my-cluster'.`);
363357
},
364358
gaxOpts: gaxOptions,
365359
},
366-
// tslint:disable-next-line no-any
367-
(...args: any[]) => {
368-
if (args[1]) {
369-
this.metadata = args[1];
360+
(err, resp) => {
361+
if (resp) {
362+
this.metadata = resp;
370363
}
371-
372-
callback(...args);
364+
callback(err, resp);
373365
}
374366
);
375367
}
376368

377-
setMetadata(metadata: CreateClusterOptions): Promise<MetadataResponse>;
369+
setMetadata(
370+
metadata: CreateClusterOptions
371+
): Promise<SetClusterMetadataResponse>;
378372
setMetadata(
379373
metadata: CreateClusterOptions,
380374
gaxOptions: CallOptions
381-
): Promise<MetadataResponse>;
375+
): Promise<SetClusterMetadataResponse>;
382376
setMetadata(
383377
metadata: CreateClusterOptions,
384378
callback: SetClusterMetadataCallback
@@ -408,16 +402,15 @@ Please use the format 'my-cluster' or '${instance.name}/clusters/my-cluster'.`);
408402
metadata: CreateClusterOptions,
409403
gaxOptionsOrCallback?: CallOptions | SetClusterMetadataCallback,
410404
cb?: SetClusterMetadataCallback
411-
): void | Promise<MetadataResponse> {
405+
): void | Promise<SetClusterMetadataResponse> {
412406
const callback =
413407
typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb!;
414408
const gaxOptions =
415409
typeof gaxOptionsOrCallback === 'object' && gaxOptionsOrCallback
416410
? gaxOptionsOrCallback
417411
: ({} as CallOptions);
418412

419-
// tslint:disable-next-line no-any
420-
const reqOpts: any = {
413+
const reqOpts: ICluster = {
421414
name: this.name,
422415
};
423416

@@ -436,14 +429,16 @@ Please use the format 'my-cluster' or '${instance.name}/clusters/my-cluster'.`);
436429
reqOpts.defaultStorageType = Cluster.getStorageType_(metadata.storage);
437430
}
438431

439-
this.bigtable.request(
432+
this.bigtable.request<Operation>(
440433
{
441434
client: 'BigtableInstanceAdminClient',
442435
method: 'updateCluster',
443436
reqOpts,
444437
gaxOpts: gaxOptions,
445438
},
446-
callback
439+
(err, resp) => {
440+
callback(err, resp);
441+
}
447442
);
448443
}
449444
}

handwritten/bigtable/src/decorateStatus.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
/*!
2-
* Copyright 2019 Google LLC. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
1614

1715
import * as extend from 'extend';
1816
import {google} from '../protos/protos';

handwritten/bigtable/src/family.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
/*!
2-
* Copyright 2016 Google Inc. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2016 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
1614

1715
import {promisifyAll} from '@google-cloud/promisify';
1816
import {CallOptions} from 'google-gax';

handwritten/bigtable/src/filter.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
/*!
2-
* Copyright 2016 Google Inc. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// Copyright 2016 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
1614

1715
import arrify = require('arrify');
1816
import * as escapeStringRegexp from 'escape-string-regexp';
@@ -49,9 +47,7 @@ export interface Time {
4947
end: Date;
5048
}
5149

52-
export interface RawFilter {
53-
[index: string]: {};
54-
}
50+
export type RawFilter = any;
5551

5652
export interface Condition {
5753
pass: {};
@@ -259,7 +255,7 @@ export class Filter {
259255
[index: string]: Function;
260256
}
261257
const filter = new Filter();
262-
arrify(filters).forEach(filterObj => {
258+
arrify(filters).forEach((filterObj: any) => {
263259
const key = Object.keys(filterObj)[0];
264260
if (typeof ((filter as {}) as Fn)[key] !== 'function') {
265261
throw new FilterError(key);

0 commit comments

Comments
 (0)