@@ -27,7 +27,6 @@ import {
27
27
InstanceOptions ,
28
28
CreateInstanceCallback ,
29
29
CreateInstanceResponse ,
30
- ClusterInfo ,
31
30
IInstance ,
32
31
} from './instance' ;
33
32
import { shouldRetryRequest } from './decorateStatus' ;
@@ -49,14 +48,14 @@ const {grpc} = new gax.GrpcClient();
49
48
export interface GetInstancesCallback {
50
49
(
51
50
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
55
54
) : void ;
56
55
}
57
56
export type GetInstancesResponse = [
58
57
Instance [ ] ,
59
- { } | null ,
58
+ string [ ] ,
60
59
google . bigtable . admin . v2 . IListInstancesResponse
61
60
] ;
62
61
@@ -462,14 +461,13 @@ export class Bigtable {
462
461
463
462
createInstance (
464
463
id : string ,
465
- options ? : InstanceOptions
464
+ options : InstanceOptions
466
465
) : Promise < CreateInstanceResponse > ;
467
466
createInstance (
468
467
id : string ,
469
468
options : InstanceOptions ,
470
469
callback : CreateInstanceCallback
471
470
) : void ;
472
- createInstance ( id : string , callback : CreateInstanceCallback ) : void ;
473
471
/**
474
472
* Create a Cloud Bigtable instance.
475
473
*
@@ -479,7 +477,7 @@ export class Bigtable {
479
477
* @param {object } options Instance creation options.
480
478
* @param {object[] } options.clusters The clusters to be created within the
481
479
* instance.
482
- * @param {string } options.displayName The descriptive name for this instance
480
+ * @param {string } [ options.displayName] The descriptive name for this instance
483
481
* as it appears in UIs.
484
482
* @param {Object.<string, string> } [options.labels] Labels are a flexible and
485
483
* lightweight mechanism for organizing cloud resources into groups that
@@ -546,14 +544,19 @@ export class Bigtable {
546
544
*/
547
545
createInstance (
548
546
id : string ,
549
- optionsOrCallback ? : InstanceOptions | CreateInstanceCallback ,
550
- cb ?: CreateInstanceCallback
547
+ options : InstanceOptions ,
548
+ callback ?: CreateInstanceCallback
551
549
) : 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
+ }
557
560
const reqOpts = {
558
561
parent : this . projectName ,
559
562
instanceId : id ,
@@ -567,7 +570,7 @@ export class Bigtable {
567
570
reqOpts . instance ! . type = Instance . getTypeType_ ( options . type ) ;
568
571
}
569
572
570
- reqOpts . clusters = arrify ( options . clusters ! ) . reduce ( ( clusters , cluster ) => {
573
+ reqOpts . clusters = arrify ( options . clusters ) . reduce ( ( clusters , cluster ) => {
571
574
if ( ! cluster . id ) {
572
575
throw new Error (
573
576
'A cluster was provided without an `id` property defined.'
@@ -581,7 +584,7 @@ export class Bigtable {
581
584
} ;
582
585
583
586
return clusters ;
584
- } , { } as { [ index : string ] : ClusterInfo } ) ;
587
+ } , { } as { [ index : string ] : google . bigtable . admin . v2 . ICluster } ) ;
585
588
586
589
this . request (
587
590
{
@@ -606,12 +609,14 @@ export class Bigtable {
606
609
/**
607
610
* @typedef {array } GetInstancesResponse
608
611
* @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.
610
614
*/
611
615
/**
612
616
* @callback GetInstancesCallback
613
617
* @param {?Error } err Request error, if any.
614
618
* @param {Instance[] } instances Array of {@link Instance} instances.
619
+ * @param {string[] } locations from which Instance information could not be retrieved
615
620
* @param {object } apiResponse The full API response.
616
621
*/
617
622
/**
@@ -629,26 +634,21 @@ export class Bigtable {
629
634
* bigtable.getInstances(function(err, instances) {
630
635
* if (!err) {
631
636
* // `instances` is an array of Instance objects.
637
+ * if (failedLocations.length > 0) {
638
+ * // These locations contain instances which could not be retrieved.
639
+ * }
632
640
* }
633
641
* });
634
642
*
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
- *
648
643
* @example <caption>If the callback is omitted, we'll return a Promise.
649
644
* </caption>
650
645
* bigtable.getInstances().then(function(data) {
651
646
* 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
+ * }
652
652
* });
653
653
*/
654
654
getInstances (
@@ -683,7 +683,7 @@ export class Bigtable {
683
683
instance . metadata = instanceData ;
684
684
return instance ;
685
685
} ) ;
686
- callback ! ( null , instances , resp ) ;
686
+ callback ! ( null , instances , resp . failedLocations , resp ) ;
687
687
}
688
688
) ;
689
689
}
0 commit comments