Skip to content

Commit

Permalink
refactor: improve types (googleapis#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Mar 23, 2020
1 parent 809c719 commit 3bf1ed8
Show file tree
Hide file tree
Showing 17 changed files with 870 additions and 1,141 deletions.
8 changes: 6 additions & 2 deletions src/app-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ export interface DeleteAppProfileOptions {

export type CreateAppProfileCallback = (
err: ServiceError | null,
appProfile?: AppProfile
appProfile?: AppProfile,
apiResponse?: google.bigtable.admin.v2.IAppProfile
) => void;
export type CreateAppProfileResponse = [AppProfile];
export type CreateAppProfileResponse = [
AppProfile,
google.bigtable.admin.v2.IAppProfile
];
export type DeleteAppProfileCallback = (
err: ServiceError | null,
apiResponse?: google.protobuf.Empty
Expand Down
4 changes: 2 additions & 2 deletions src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type ApiResponse = [IOperation];
export type CreateClusterResponse = [ICluster, GaxOperation, IOperation];
export type BooleanResponse = [boolean];
export type GetClusterResponse = [ICluster, IOperation];
export type GetClustersResponse = [ICluster[], IOperation];
export type GetClustersResponse = [Cluster[], IOperation];
export type GetClusterMetadataResponse = [ICluster, IOperation];
export type SetClusterMetadataResponse = [Operation, google.protobuf.Empty];

Expand All @@ -56,7 +56,7 @@ export type ExistsClusterCallback = GenericCallback<boolean>;
export type GetClusterCallback = GenericClusterCallback<ICluster>;
export type GetClustersCallback = (
err: ServiceError | null,
clusters?: ICluster[],
clusters?: Cluster[],
apiResponse?: google.bigtable.admin.v2.IListClustersResponse
) => void;
export type SetClusterMetadataCallback = GenericOperationCallback<
Expand Down
4 changes: 2 additions & 2 deletions src/family.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface InstanceCallback<I, R> {
}

export interface GcRule {
age?: google.protobuf.IDuration;
age?: google.protobuf.IDuration | number;
versions?: number;
rule?: GcRule;
union?: boolean;
Expand Down Expand Up @@ -166,7 +166,7 @@ Please use the format 'follows' or '${table.name}/columnFamilies/my-family'.`);

if (ruleObj.age) {
rules.push({
maxAge: ruleObj.age,
maxAge: ruleObj.age as google.protobuf.IDuration,
});
}

Expand Down
32 changes: 27 additions & 5 deletions src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export interface BoundData {
}

export interface Time {
start: Date;
end: Date;
start: Date | number;
end: Date | number;
}

// tslint:disable-next-line no-any
Expand Down Expand Up @@ -136,7 +136,15 @@ export class Filter {
* // => '(a|b|c)'
*/
static convertToRegExpString(
regex: RegExp | string | string[] | Buffer | number
regex:
| RegExp
| RegExp[]
| string
| string[]
| Buffer
| Buffer[]
| number
| number[]
): string | Buffer {
if (is.regexp(regex)) {
return regex.toString().replace(/^\/|\/$/g, '');
Expand Down Expand Up @@ -199,7 +207,11 @@ export class Filter {
* // startTest2Exclusive: 'value3'
* // }
*/
static createRange(start: BoundData, end: BoundData, key: string) {
static createRange(
start: BoundData | null,
end: BoundData | null,
key: string
) {
const range = {};

if (start) {
Expand Down Expand Up @@ -521,7 +533,17 @@ export class Filter {
* }
* ];
*/
family(family: RegExp): void {
family(
family:
| RegExp
| string
| number
| Buffer
| RegExp[]
| string[]
| number[]
| Buffer[]
): void {
const f = Filter.convertToRegExpString(family);
this.set('familyNameRegexFilter', f);
}
Expand Down
6 changes: 3 additions & 3 deletions src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,16 @@ Please use the format 'my-instance' or '${bigtable.projectName}/instances/my-ins
* Instance.getTypeType_('production');
* // 1
*/
static getTypeType_(type: string): number {
static getTypeType_(type?: string): number {
const types = {
unspecified: 0,
production: 1,
development: 2,
} as {[index: string]: number};
if (is.string(type)) {
if (typeof type === 'string') {
type = type.toLowerCase();
}
return types[type] || types.unspecified;
return types[type!] || types.unspecified;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export type IMutateRowRequest = btTypes.bigtable.v2.IMutateRowRequest;
export type ISetCell = btTypes.bigtable.v2.Mutation.ISetCell;

export type Bytes = string | Buffer;
export type Data = Value | Value[] | MutationSettingsObj;
// tslint:disable-next-line:no-any
export type Data = any;
export interface JsonObj {
[k: string]: string | JsonObj;
}
Expand Down Expand Up @@ -158,7 +159,7 @@ export class Mutation {
* @returns {object}
* @private
*/
static createTimeRange(start: Date, end: Date): TimeRange {
static createTimeRange(start: Date | number, end: Date | number): TimeRange {
const range: TimeRange = {};

if (is.date(start)) {
Expand Down
2 changes: 1 addition & 1 deletion src/row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class Row {
* // }
* // }
*/
static formatChunks_(chunks: Chunk[], options: ConvertFromBytesUserOptions) {
static formatChunks_(chunks: Chunk[], options?: ConvertFromBytesUserOptions) {
const rows: Row[] = [];
let familyName: string | null;
let qualifierName: string | null;
Expand Down
Loading

0 comments on commit 3bf1ed8

Please sign in to comment.