@@ -27,7 +27,6 @@ import {
2727 InstanceOptions ,
2828 CreateInstanceCallback ,
2929 CreateInstanceResponse ,
30- ClusterInfo ,
3130 IInstance ,
3231} from './instance' ;
3332import { shouldRetryRequest } from './decorateStatus' ;
@@ -49,14 +48,14 @@ const {grpc} = new gax.GrpcClient();
4948export interface GetInstancesCallback {
5049 (
5150 err : ServiceError | null ,
52- result ?: Instance [ ] | null ,
53- nextQuery ?: { } | null ,
54- response ?: google . bigtable . admin . v2 . IListInstancesResponse | null
51+ result ?: Instance [ ] ,
52+ failedLocations ?: string [ ] ,
53+ response ?: google . bigtable . admin . v2 . IListInstancesResponse
5554 ) : void ;
5655}
5756export type GetInstancesResponse = [
5857 Instance [ ] ,
59- { } | null ,
58+ string [ ] ,
6059 google . bigtable . admin . v2 . IListInstancesResponse
6160] ;
6261
@@ -462,14 +461,13 @@ export class Bigtable {
462461
463462 createInstance (
464463 id : string ,
465- options ? : InstanceOptions
464+ options : InstanceOptions
466465 ) : Promise < CreateInstanceResponse > ;
467466 createInstance (
468467 id : string ,
469468 options : InstanceOptions ,
470469 callback : CreateInstanceCallback
471470 ) : void ;
472- createInstance ( id : string , callback : CreateInstanceCallback ) : void ;
473471 /**
474472 * Create a Cloud Bigtable instance.
475473 *
@@ -479,7 +477,7 @@ export class Bigtable {
479477 * @param {object } options Instance creation options.
480478 * @param {object[] } options.clusters The clusters to be created within the
481479 * instance.
482- * @param {string } options.displayName The descriptive name for this instance
480+ * @param {string } [ options.displayName] The descriptive name for this instance
483481 * as it appears in UIs.
484482 * @param {Object.<string, string> } [options.labels] Labels are a flexible and
485483 * lightweight mechanism for organizing cloud resources into groups that
@@ -546,14 +544,19 @@ export class Bigtable {
546544 */
547545 createInstance (
548546 id : string ,
549- optionsOrCallback ? : InstanceOptions | CreateInstanceCallback ,
550- cb ?: CreateInstanceCallback
547+ options : InstanceOptions ,
548+ callback ?: CreateInstanceCallback
551549 ) : void | Promise < CreateInstanceResponse > {
552- const options =
553- typeof optionsOrCallback === 'object' ? optionsOrCallback : { } ;
554- const callback =
555- typeof optionsOrCallback === 'function' ? optionsOrCallback : cb ;
556-
550+ if ( typeof options !== 'object' ) {
551+ throw new Error (
552+ 'A configuration object is required to create an instance.'
553+ ) ;
554+ }
555+ if ( ! options . clusters ) {
556+ throw new Error (
557+ 'At least one cluster configuration object is required to create an instance.'
558+ ) ;
559+ }
557560 const reqOpts = {
558561 parent : this . projectName ,
559562 instanceId : id ,
@@ -567,7 +570,7 @@ export class Bigtable {
567570 reqOpts . instance ! . type = Instance . getTypeType_ ( options . type ) ;
568571 }
569572
570- reqOpts . clusters = arrify ( options . clusters ! ) . reduce ( ( clusters , cluster ) => {
573+ reqOpts . clusters = arrify ( options . clusters ) . reduce ( ( clusters , cluster ) => {
571574 if ( ! cluster . id ) {
572575 throw new Error (
573576 'A cluster was provided without an `id` property defined.'
@@ -581,7 +584,7 @@ export class Bigtable {
581584 } ;
582585
583586 return clusters ;
584- } , { } as { [ index : string ] : ClusterInfo } ) ;
587+ } , { } as { [ index : string ] : google . bigtable . admin . v2 . ICluster } ) ;
585588
586589 this . request (
587590 {
@@ -606,12 +609,14 @@ export class Bigtable {
606609 /**
607610 * @typedef {array } GetInstancesResponse
608611 * @property {Instance[] } 0 Array of {@link Instance} instances.
609- * @property {object } 1 The full API response.
612+ * @property {string[] } 1 locations from which Instance information could not be retrieved
613+ * @property {object } 2 The full API response.
610614 */
611615 /**
612616 * @callback GetInstancesCallback
613617 * @param {?Error } err Request error, if any.
614618 * @param {Instance[] } instances Array of {@link Instance} instances.
619+ * @param {string[] } locations from which Instance information could not be retrieved
615620 * @param {object } apiResponse The full API response.
616621 */
617622 /**
@@ -629,26 +634,21 @@ export class Bigtable {
629634 * bigtable.getInstances(function(err, instances) {
630635 * if (!err) {
631636 * // `instances` is an array of Instance objects.
637+ * if (failedLocations.length > 0) {
638+ * // These locations contain instances which could not be retrieved.
639+ * }
632640 * }
633641 * });
634642 *
635- * @example <caption>To control how many API requests are made and page
636- * through the results manually, set `autoPaginate` to `false`.</caption>
637- * function callback(err, instances, nextQuery, apiResponse) {
638- * if (nextQuery) {
639- * // More results exist.
640- * bigtable.getInstances(nextQuery, callback);
641- * }
642- * }
643- *
644- * bigtable.getInstances({
645- * autoPaginate: false
646- * }, callback);
647- *
648643 * @example <caption>If the callback is omitted, we'll return a Promise.
649644 * </caption>
650645 * bigtable.getInstances().then(function(data) {
651646 * const instances = data[0];
647+ *
648+ * if (data[1]) {
649+ * // These locations contain instances which could not be retrieved.
650+ * const failedLocations = data[1];
651+ * }
652652 * });
653653 */
654654 getInstances (
@@ -683,7 +683,7 @@ export class Bigtable {
683683 instance . metadata = instanceData ;
684684 return instance ;
685685 } ) ;
686- callback ! ( null , instances , resp ) ;
686+ callback ! ( null , instances , resp . failedLocations , resp ) ;
687687 }
688688 ) ;
689689 }
0 commit comments