|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | | -import {paginator, ResourceStream} from '@google-cloud/paginator'; |
16 | 15 | import {promisifyAll} from '@google-cloud/promisify'; |
| 16 | +import {Transform} from 'stream'; |
17 | 17 | import arrify = require('arrify'); |
18 | 18 | import * as is from 'is'; |
| 19 | +// eslint-disable-next-line @typescript-eslint/no-var-requires |
| 20 | +const pumpify = require('pumpify'); |
| 21 | + |
19 | 22 | import snakeCase = require('lodash.snakecase'); |
20 | 23 | import { |
21 | 24 | AppProfile, |
@@ -155,7 +158,6 @@ export class Instance { |
155 | 158 | id: string; |
156 | 159 | name: string; |
157 | 160 | metadata?: google.bigtable.admin.v2.IInstance; |
158 | | - getTablesStream!: (options?: GetTablesOptions) => ResourceStream<Table>; |
159 | 161 | constructor(bigtable: Bigtable, id: string) { |
160 | 162 | this.bigtable = bigtable; |
161 | 163 |
|
@@ -905,6 +907,68 @@ Please use the format 'my-instance' or '${bigtable.projectName}/instances/my-ins |
905 | 907 | ); |
906 | 908 | } |
907 | 909 |
|
| 910 | + /** |
| 911 | + * Get {@link Table} objects for all the tables in your Cloud Bigtable |
| 912 | + * instance as a readable object stream. |
| 913 | + * |
| 914 | + * @param {object} [options] Query object. See |
| 915 | + * {@link Instance#getTables} for a complete list of options. |
| 916 | + * @returns {stream} |
| 917 | + * |
| 918 | + * @example |
| 919 | + * const {Bigtable} = require('@google-cloud/bigtable'); |
| 920 | + * const bigtable = new Bigtable(); |
| 921 | + * const instance = bigtable.instance('my-instance'); |
| 922 | + * |
| 923 | + * instance.getTablesStream() |
| 924 | + * .on('error', console.error) |
| 925 | + * .on('data', function(table) { |
| 926 | + * // table is a Table object. |
| 927 | + * }) |
| 928 | + * .on('end', () => { |
| 929 | + * // All tables retrieved. |
| 930 | + * }); |
| 931 | + * |
| 932 | + * //- |
| 933 | + * // If you anticipate many results, you can end a stream early to prevent |
| 934 | + * // unnecessary processing and API requests. |
| 935 | + * //- |
| 936 | + * instance.getTablesStream() |
| 937 | + * .on('data', function(table) { |
| 938 | + * this.end(); |
| 939 | + * }); |
| 940 | + */ |
| 941 | + getTablesStream(options: GetTablesOptions = {}): NodeJS.ReadableStream { |
| 942 | + const reqOpts = Object.assign({}, options, { |
| 943 | + parent: this.name, |
| 944 | + view: Table.VIEWS[options.view || 'unspecified'], |
| 945 | + }); |
| 946 | + |
| 947 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 948 | + delete (reqOpts as any).gaxOptions; |
| 949 | + |
| 950 | + // eslint-disable-next-line @typescript-eslint/no-this-alias |
| 951 | + const self = this; |
| 952 | + const transformToTable = ( |
| 953 | + chunk: google.bigtable.admin.v2.ITable, |
| 954 | + enc: string, |
| 955 | + callback: Function |
| 956 | + ) => { |
| 957 | + const table = self.table(chunk.name!.split('/').pop()!); |
| 958 | + table.metadata = chunk; |
| 959 | + callback(null, table); |
| 960 | + }; |
| 961 | + return pumpify.obj([ |
| 962 | + this.bigtable.request({ |
| 963 | + client: 'BigtableTableAdminClient', |
| 964 | + method: 'listTablesStream', |
| 965 | + reqOpts, |
| 966 | + gaxOpts: options.gaxOptions, |
| 967 | + }), |
| 968 | + new Transform({objectMode: true, transform: transformToTable}), |
| 969 | + ]); |
| 970 | + } |
| 971 | + |
908 | 972 | setIamPolicy( |
909 | 973 | policy: Policy, |
910 | 974 | gaxOptions?: CallOptions |
@@ -1104,52 +1168,13 @@ Please use the format 'my-instance' or '${bigtable.projectName}/instances/my-ins |
1104 | 1168 | } |
1105 | 1169 | } |
1106 | 1170 |
|
1107 | | -/** |
1108 | | - * Get {@link Table} objects for all the tables in your Cloud Bigtable |
1109 | | - * instance as a readable object stream. |
1110 | | - * |
1111 | | - * @param {object} [query] Configuration object. See |
1112 | | - * {@link Instance#getTables} for a complete list of options. |
1113 | | - * @returns {stream} |
1114 | | - * |
1115 | | - * @example |
1116 | | - * const {Bigtable} = require('@google-cloud/bigtable'); |
1117 | | - * const bigtable = new Bigtable(); |
1118 | | - * const instance = bigtable.instance('my-instance'); |
1119 | | - * |
1120 | | - * instance.getTablesStream() |
1121 | | - * .on('error', console.error) |
1122 | | - * .on('data', function(table) { |
1123 | | - * // table is a Table object. |
1124 | | - * }) |
1125 | | - * .on('end', () => { |
1126 | | - * // All tables retrieved. |
1127 | | - * }); |
1128 | | - * |
1129 | | - * //- |
1130 | | - * // If you anticipate many results, you can end a stream early to prevent |
1131 | | - * // unnecessary processing and API requests. |
1132 | | - * //- |
1133 | | - * instance.getTablesStream() |
1134 | | - * .on('data', function(table) { |
1135 | | - * this.end(); |
1136 | | - * }); |
1137 | | - */ |
1138 | | -Instance.prototype.getTablesStream = paginator.streamify<Table>('getTables'); |
1139 | | - |
1140 | | -/*! Developer Documentation |
1141 | | - * |
1142 | | - * These methods can be auto-paginated. |
1143 | | - */ |
1144 | | -paginator.extend(Instance, ['getTables']); |
1145 | | - |
1146 | 1171 | /*! Developer Documentation |
1147 | 1172 | * |
1148 | 1173 | * All async methods (except for streams) will return a Promise in the event |
1149 | 1174 | * that a callback is omitted. |
1150 | 1175 | */ |
1151 | 1176 | promisifyAll(Instance, { |
1152 | | - exclude: ['appProfile', 'cluster', 'table'], |
| 1177 | + exclude: ['appProfile', 'cluster', 'table', 'getTablesStream'], |
1153 | 1178 | }); |
1154 | 1179 |
|
1155 | 1180 | /** |
|
0 commit comments