UNPKG

@google-cloud/bigtable

Version:
387 lines (386 loc) 16.9 kB
import { GoogleAuth, CallOptions } from 'google-gax'; import * as gax from 'google-gax'; import * as protos from '../protos/protos'; import * as SqlTypes from './execute-query/types'; import { AppProfile } from './app-profile'; import { Cluster } from './cluster'; import { Instance, InstanceOptions, CreateInstanceCallback, CreateInstanceResponse } from './instance'; import { google } from '../protos/protos'; import { ServiceError } from 'google-gax'; import * as v2 from './v2'; import { Duplex } from 'stream'; import { ClientSideMetricsConfigManager } from './client-side-metrics/metrics-config-manager'; export interface GetInstancesCallback { (err: ServiceError | null, result?: Instance[], failedLocations?: string[], response?: google.bigtable.admin.v2.IListInstancesResponse): void; } export type GetInstancesResponse = [ Instance[], string[], google.bigtable.admin.v2.IListInstancesResponse ]; export type RequestCallback<T> = (err: ServiceError | null, resp?: T) => void; export interface RequestOptions { client: 'BigtableInstanceAdminClient' | 'BigtableTableAdminClient' | 'BigtableClient'; reqOpts?: {}; retryOpts?: {}; gaxOpts?: {}; method?: string; } export interface AbortableDuplex extends Duplex { abort(): void; } export interface BigtableOptions extends gax.GoogleAuthOptions { /** * Override the default API endpoint used to reach Bigtable. This is useful for connecting to your local Bigtable emulator. */ apiEndpoint?: string; appProfileId?: string; /** * Internal only. */ BigtableClient?: gax.ClientOptions; /** * Internal only. */ BigtableInstanceAdminClient?: gax.ClientOptions; /** * Internal only. */ BigtableTableAdminClient?: gax.ClientOptions; metricsEnabled?: boolean; } /** * @typedef {object} ClientConfig * @property {string} [apiEndpoint] Override the default API endpoint used * to reach Bigtable. This is useful for connecting to your local Bigtable * emulator. * @property {string} [projectId] The project ID from the Google Developer's * Console, e.g. 'grape-spaceship-123'. We will also check the environment * variable `GCLOUD_PROJECT` for your project ID. If your app is running in * an environment which supports {@link * https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application * Application Default Credentials}, your project ID will be detected * automatically. * @property {string} [keyFilename] Full path to the a .json, .pem, or .p12 key * downloaded from the Google Developers Console. If you provide a path to a * JSON file, the `projectId` option above is not necessary. NOTE: .pem and * .p12 require you to specify the `email` option as well. * @property {string} [appProfileId] An application profile ID, a configuration * string value describing how Cloud Bigtable should treat traffic from a * particular end user application. * @property {string} [email] Account email address. Required when using a .pem * or .p12 keyFilename. * @property {object} [credentials] Credentials object. * @property {string} [credentials.client_email] * @property {string} [credentials.private_key] * @property {boolean} [autoRetry=true] Automatically retry requests if the * response is related to rate limits or certain intermittent server errors. * We will exponentially backoff subsequent requests by default. * @property {number} [maxRetries=3] Maximum number of automatic retries * attempted before returning the error. */ /** * @see [Creating a Cloud Bigtable Cluster]{@link https://cloud.google.com/bigtable/docs/creating-instance} * @see [Cloud Bigtable Concepts Overview]{@link https://cloud.google.com/bigtable/docs/concepts} * * @class * @param {ClientConfig} [options] Configuration options. * * @example Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>: * ``` * const {Bigtable} = require('@google-cloud/bigtable'); * const bigtable = new Bigtable(); * * ``` * @example Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>: * ``` * const {Bigtable} = require('@google-cloud/bigtable'); * const bigtable = new Bigtable({ * projectId: 'your-project-id', * keyFilename: '/path/to/keyfile.json' * }); * * ``` * @example The Bigtable Emulator * ``` * // Make sure you have the {@link https://cloud.google.com/sdk/downloads gcloud SDK installed}, then run: * $ gcloud beta emulators bigtable start * * // Before running your Node.js app, set the environment variables that this * // library will look for to connect to the emulator: * * $ $(gcloud beta emulators bigtable env-init) * * ``` * @example Creating a Bigtable Instance and Cluster * ``` * * // Before you create your table, you first need to create a Bigtable Instance * // and cluster for the table to be served from. * * const {Bigtable} = require('@google-cloud/bigtable'); * const bigtable = new Bigtable(); * * const callback = (err, instance, operation) => { * operation * .on('error', console.log) * .on('complete', () => { * // `instance` is your newly created Instance object. * }); * }; * * const instance = bigtable.instance('my-instance'); * * instance.create({ * clusters: [ * { * id: 'my-cluster', * location: 'us-central1-b', * nodes: 3 * } * ] * }, callback); * * // This can also be done from either the Google Cloud Platform Console or the * // `gcloud` cli tool. Please refer to the * // {@link https://cloud.google.com/bigtable/docs/creating-instance official Bigtable documentation} * // for more information. * * ``` * @example Creating Tables * ``` * // After creating your instance and enabling the Bigtable APIs, you are now * // ready to create your table with {@link Instance#createTable}. * instance.createTable('prezzy', function(err, table) { * // `table` is your newly created Table object. * }); * * ``` * @example Creating Column Families * ``` * // Column families are used to group together various pieces of data within * // your table. You can think of column families as a mechanism to categorize * // all of your data. * // * // We can create a column family with {@link Table#createFamily}. * const table = instance.table('prezzy'); * * table.createFamily('follows', function(err, family) { * // `family` is your newly created Family object. * }); * * // It is also possible to create your column families when creating a new * // table. * const options = { * families: ['follows'] * }; * * instance.createTable('prezzy', options, function(err, table) {}); * * ``` * @example Creating Rows * ``` * // New rows can be created within your table using * // {@link Table#insert}. You must provide a unique key for each row * // to be inserted, this key can then be used to retrieve your row at a later * // time. * // * // With Bigtable, all columns have a unique id composed of a column family * // and a column qualifier. In the example below `follows` is the column * // family and `tjefferson` is the column qualifier. Together they could be * // referred to as `follows:tjefferson`. * const rows = [ * { * key: 'wmckinley', * data: { * follows: { * tjefferson: 1 * } * } * } * ]; * * table.insert(rows, err => { * if (!err) { * // Your rows were successfully inserted. * } * }); * * ``` * @example Retrieving Rows * ``` * // If you're anticipating a large number of rows to be returned, we suggest * // using the {@link Table#getRows} streaming API. * table.createReadStream() * .on('error', console.error) * .on('data', row => { * // `row` is a Row object. * }); * * // If you're not anticpating a large number of results, a callback mode * // is also available. * const callback = (err, rows) => { * // `rows` is an array of Row objects. * }; * * table.getRows(callback); * * // A range of rows can be retrieved by providing `start` and `end` row keys. * const options = { * start: 'gwashington', * end: 'wmckinley' * }; * * table.getRows(options, callback); * * // Retrieve an individual row with {@link Row#get}. * const row = table.row('alincoln'); * * row.get(err => { * // `row.data` is now populated. * }); * * ``` * @example Accessing Row Data * ``` * // When retrieving rows, upon success the `row.data` property will be * // populated by an object. That object will contain additional objects * // for each family in your table that the row has data for. * // * // By default, when retrieving rows, each column qualifier will provide you * // with all previous versions of the data. So your `row.data` object could * // resemble the following. * { * follows: { * wmckinley: [ * { * value: 1, * timestamp: 1466017315951 * }, { * value: 2, * timestamp: 1458619200000 * } * ] * } * } * * // The `timestamp` field can be used to order cells from newest to oldest. * // If you only wish to retrieve the most recent version of the data, you * // can specify the number of cells with a {@link Filter} object. * const filter = [ * { * column: { * cellLimit: 1 * } * } * ]; * * table.getRows({ * filter: filter * }, callback); * * ``` * @example Deleting Row Data * ``` * // We can delete all of an individual row's cells using {@link Row#delete}. * const callback = err => { * if (!err) { * // All cells for this row were deleted successfully. * } * }; * * row.delete(callback); * * // To delete a specific set of cells, we can provide an array of * // column families and qualifiers. * const cells = [ * 'follows:gwashington', * 'traits' * ]; * * row.delete(cells, callback); * * ``` * @example Deleting Rows * ``` * // If you wish to delete multiple rows entirely, we can do so with * // {@link Table#deleteRows}. You can provide this method with a * // row key prefix. * const options = { * prefix: 'gwash' * }; * * table.deleteRows(options, err => { * if (!err) { * // Rows were deleted successfully. * } * }); * * // If you omit the prefix, you can delete all rows in your table. * table.deleteRows(err => { * if (!err) { * // All rows were deleted successfully. * } * }); * ``` */ export declare class Bigtable { customEndpoint?: string; options: BigtableOptions; api: { [index: string]: v2.BigtableClient | v2.BigtableInstanceAdminClient | v2.BigtableTableAdminClient; }; auth: GoogleAuth; projectId: string; appProfileId?: string; projectName: string; shouldReplaceProjectIdToken: boolean; static AppProfile: AppProfile; static Instance: Instance; static Cluster: Cluster; _metricsConfigManager: ClientSideMetricsConfigManager; constructor(options?: BigtableOptions); createInstance(id: string, options: InstanceOptions): Promise<CreateInstanceResponse>; createInstance(id: string, options: InstanceOptions, callback: CreateInstanceCallback): void; getInstances(gaxOptions?: CallOptions): Promise<GetInstancesResponse>; getInstances(callback: GetInstancesCallback): void; getInstances(gaxOptions: CallOptions, callback: GetInstancesCallback): void; /** * Get a reference to a Cloud Bigtable instance. * * @param {string} id The id of the instance. * @returns {Instance} */ instance(name: string): Instance; request<T = any>(config?: any): AbortableDuplex; request<T = any>(config?: any, callback?: RequestCallback<T>): void; /** * Close all bigtable clients. New requests will be rejected but it will not * kill connections with pending requests. */ close(): Promise<void[]>; /** * Determine and localize the project ID. If a user provides an ID, we bypass * checking with the auth client for an ID. * * @private * * @param {function} callback Callback function. * @param {?error} callback.err An error returned from the auth client. * @param {string} callback.projectId The detected project ID. */ getProjectId_(callback: (err: Error | null, projectId?: string) => void): void; } export { v2 }; export { protos }; export { AppProfile, AppProfileExistsCallback, AppProfileExistsResponse, AppProfileOptions, CreateAppProfileCallback, CreateAppProfileResponse, DeleteAppProfileCallback, DeleteAppProfileOptions, DeleteAppProfileResponse, GetAppProfileCallback, GetAppProfileMetadataCallback, GetAppProfileMetadataResponse, GetAppProfileResponse, GetAppProfilesCallback, GetAppProfilesResponse, SetAppProfileMetadataCallback, SetAppProfileMetadataResponse, } from './app-profile'; export { Backup, BackupTimestamp, DeleteBackupCallback, DeleteBackupResponse, GenericBackupCallback, GetBackupCallback, GetBackupResponse, GetBackupsCallback, GetBackupsOptions, GetBackupsResponse, IBackup, ModifiableBackupFields, RestoreTableCallback, RestoreTableResponse, BackupSetMetadataCallback, BackupSetMetadataResponse, BackupGetMetadataCallback, BackupGetMetadataResponse, } from './backup'; export { Chunk, ChunkTransformer, Data, Qualifier, RowStateEnum, TransformErrorProps, Value, } from './chunktransformer'; export { Cluster, ICluster, IOperation, ApiResponse, BooleanResponse, CreateBackupCallback, CreateBackupResponse, CreateClusterCallback, CreateClusterOptions, CreateClusterResponse, DeleteClusterCallback, ExistsClusterCallback, GenericCallback, GenericClusterCallback, GenericOperationCallback, GetClusterCallback, GetClusterMetadataCallback, GetClusterMetadataResponse, GetClusterResponse, GetClustersCallback, GetClustersResponse, IEmpty, SetClusterMetadataCallback, SetClusterMetadataResponse, } from './cluster'; export { CreateFamilyCallback, CreateFamilyOptions, FamilyError, GcRule, IGcRule, ITable, CreateFamilyResponse, DeleteFamilyCallback, DeleteFamilyResponse, Family, FamilyExistsCallback, FamilyExistsResponse, GetFamilyCallback, GetFamilyMetadataCallback, GetFamilyMetadataResponse, GetFamilyOptions, GetFamilyResponse, IColumnFamily, IModification, InstanceCallback, SetFamilyMetadataCallback, SetFamilyMetadataOptions, SetFamilyMetadataResponse, } from './family'; export { RawFilter, BoundData, Column, Condition, Filter, FilterError, Time, ValueFilter, } from './filter'; export { ClusterInfo, CreateInstanceCallback, Instance, InstanceOptions, CreateInstanceResponse, DeleteInstanceCallback, DeleteInstanceResponse, GetInstanceCallback, GetInstanceMetadataCallback, GetInstanceMetadataResponse, GetInstanceResponse, IInstance, InstanceExistsCallback, InstanceExistsResponse, SetInstanceMetadataCallback, SetInstanceMetadataResponse, } from './instance'; export { IMutation, Bytes, ConvertFromBytesOptions, ConvertFromBytesUserOptions, IMutateRowRequest, ISetCell, JsonObj, Mutation, MutationConstructorObj, MutationSettingsObj, ParsedColumn, SetCellObj, TimeRange, ValueObj, } from './mutation'; export { GetRowCallback, IncrementResponse, Rule, CreateRowCallback, CreateRowOptions, CreateRowResponse, CreateRulesCallback, CreateRulesResponse, FilterCallback, FilterConfig, FilterConfigOption, FilterResponse, FormatFamiliesOptions, GetRowMetadataCallback, GetRowMetadataResponse, GetRowOptions, GetRowResponse, IncrementCallback, Row, RowError, RowExistsCallback, RowExistsResponse, } from './row'; export { GetIamPolicyOptions, GetRowsOptions, GetTablesOptions, CheckConsistencyCallback, CheckConsistencyResponse, CreateTableCallback, CreateTableOptions, CreateTableResponse, DeleteRowsCallback, DeleteRowsResponse, DeleteTableCallback, DeleteTableResponse, Entry, GenerateConsistencyTokenCallback, GenerateConsistencyTokenResponse, GetFamiliesCallback, GetFamiliesResponse, GetIamPolicyCallback, GetIamPolicyResponse, GetMetadataCallback, GetMetadataOptions, GetMetadataResponse, GetReplicationStatesCallback, GetReplicationStatesResponse, GetRowsCallback, GetRowsResponse, GetTableCallback, GetTableOptions, GetTableResponse, GetTablesCallback, GetTablesResponse, InsertRowsCallback, InsertRowsResponse, MutateCallback, MutateOptions, MutateResponse, PartialFailureError, Policy, PolicyBinding, PrefixRange, SampleRowKeysCallback, SampleRowsKeysResponse, SetIamPolicyCallback, SetIamPolicyResponse, Table, TableExistsCallback, TableExistsResponse, TestIamPermissionsCallback, TestIamPermissionsResponse, TruncateCallback, TruncateResponse, WaitForReplicationCallback, WaitForReplicationResponse, } from './table'; export { SqlTypes };