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

refactor(typescript): noImplicityAny for instance test file #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import {promisifyAll} from '@google-cloud/promisify';
import {ServiceError} from '@grpc/grpc-js';
import {CallOptions, Operation as GaxOperation} from 'google-gax';
import {ServiceError} from 'grpc';

import {google as btTypes} from '../proto/bigtable';

Expand All @@ -27,7 +27,7 @@ export interface GenericCallback<T> {
(err?: ServiceError|null, apiResponse?: T|null): void;
}
export interface GenericClusterCallback<T> {
(err?: ServiceError|null, cluster?: Cluster|null, apiResponse?: T|null);
(err?: ServiceError|null, cluster?: Cluster|null, apiResponse?: T|null): void;
}
export interface GenericOperationCallback<T> {
(err?: ServiceError|null, operation?: GaxOperation|null,
Expand All @@ -44,7 +44,7 @@ export type BooleanResponse = [boolean];
export type GetClusterResponse = [ICluster, IOperation];
export type MetadataResponse = [Metadata, IOperation];

export type CreateClusterCallback = GenericCallback<IOperation>;
export type CreateClusterCallback = GenericClusterCallback<ICluster>;
export type DeleteClusterCallback = GenericCallback<IOperation>;
export type ExistsClusterCallback = GenericCallback<boolean>;
export type GetClusterCallback = GenericClusterCallback<ICluster>;
Expand Down
91 changes: 91 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ import * as through from 'through2';
import {AppProfile} from './app-profile';
import {Cluster} from './cluster';
import {Instance} from './instance';
import {ServiceError} from 'grpc';
import {google as btTypes} from '../proto/bigtable';
import {Table} from './table';
import {Family} from './family';

const retryRequest = require('retry-request');
const streamEvents = require('stream-events');
Expand All @@ -57,6 +61,93 @@ const PKG = require('../../package.json');
const v2 = require('./v2');
const {grpc} = new gax.GrpcClient();


type RequestCallback<T, R = void> =
R extends void ? NormalCallback<T>: FullCallback<T, R>;
type NormalCallback<T> = (err: ServiceError|null, response?: T|null) => void;
type FullCallback<T, R> =
(err: ServiceError|null, response?: T|null, apiResponse?: R|null) => void;

type ApiResponse<T, R = void> =
R extends void ? NormalResponse<T>: FullResponse<T, R>;
type NormalResponse<T> = [T];
type FullResponse<T, R> = [T, R];
interface OptionInterface {
gaxOptions?: gax.CallOptions;
}

export interface AppProfileOptions extends OptionInterface {
routing: Cluster|'any';
allowTransactionalWrites?: boolean;
description?: string;
ignoreWarnings?: string|boolean;
}

export interface CreateTableOptions extends OptionInterface {
families?: Family[];
splits?: string[];
}
export interface CreateInstanceOptions extends OptionInterface {
clusters: Cluster[];
displayName: string;
labels?: {[key: string]: string};
type?: string;
}

export interface GetTablesOptions extends OptionInterface {
autoPaginate?: true;
maxApiCalls?: number;
maxResults?: number;
pageToken?: string;
view?: string;
}

export type EmptyResponse = ApiResponse<btTypes.protobuf.IEmpty>;
export type ExistsCallback = RequestCallback<boolean>;
export type ExistsResponse = ApiResponse<boolean>;

export type CreateInstanceCallback =
(err: ServiceError, instance: Instance,
opertaion: btTypes.longrunning.Operation,
apiResponse: btTypes.bigtable.admin.v2.Instance) => void;
export type CreateInstanceResponse = [
Instance, btTypes.longrunning.Operation, btTypes.bigtable.admin.v2.Instance
];
export type CreateAppProfileCallback =
RequestCallback<AppProfile, btTypes.bigtable.admin.v2.IAppProfile>;
export type CreateAppProfileResponse =
ApiResponse<AppProfile, btTypes.bigtable.admin.v2.IAppProfile>;
export type Arguments<T> = [(ServiceError | null),(T| null)?,any?];
export type CreateTableCallback =
RequestCallback<Table, btTypes.bigtable.admin.v2.ITable>;
export type CreateTableResponse =
ApiResponse<Table, btTypes.bigtable.admin.v2.ITable>;
export type DeleteInstanceCallback = RequestCallback<btTypes.protobuf.Empty>;
export type GetInstanceCallback =
RequestCallback<Instance, btTypes.bigtable.admin.v2.IInstance>;
export type GetInstanceResponse =
ApiResponse<Instance, btTypes.bigtable.admin.v2.IInstance>;
export type GetAppProfilesCallback =
RequestCallback<AppProfile[], btTypes.bigtable.admin.v2.IAppProfile[]>;
export type GetAppProfilesResponse =
ApiResponse<AppProfile[], btTypes.bigtable.admin.v2.IAppProfile[]>;
export type GetClustersCallback =
RequestCallback<Cluster[], btTypes.bigtable.admin.v2.IListClustersResponse>;
export type GetClustersResponse =
ApiResponse<Cluster[], btTypes.bigtable.admin.v2.IListClustersResponse>;
export type GetInstanceMetadataCallback =
RequestCallback<btTypes.bigtable.admin.v2.IInstance>;
export type GetInstanceMetadataResponse =
ApiResponse<btTypes.bigtable.admin.v2.IInstance>;
export type GetTablesCallback =
RequestCallback<Table[], btTypes.bigtable.admin.v2.ITable[]>;
export type GetTablesResponse =
ApiResponse<Table[], btTypes.bigtable.admin.v2.ITable[]>;
export type SetInstanceMetadataCallback =
RequestCallback<Instance, btTypes.bigtable.admin.v2.IInstance>;
export type SetInstanceMetadataResponse =
ApiResponse<btTypes.bigtable.admin.v2.IInstance>;

/**
* @typedef {object} ClientConfig
* @property {string} [apiEndpoint] Override the default API endpoint used
Expand Down
Loading