@google-cloud/spanner 6.2.0 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +4 -0
- package/build/src/index.d.ts +206 -0
- package/build/src/index.js +110 -1
- package/build/src/instance-config.d.ts +294 -0
- package/build/src/instance-config.js +216 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
[1]: https://www.npmjs.com/package/nodejs-spanner?activeTab=versions
|
|
6
6
|
|
|
7
|
+
## [6.3.0](https://github.com/googleapis/nodejs-spanner/compare/v6.2.0...v6.3.0) (2022-10-03)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* Support customer managed instance configurations ([#1611](https://github.com/googleapis/nodejs-spanner/issues/1611)) ([bbe8f69](https://github.com/googleapis/nodejs-spanner/commit/bbe8f697e8838e358973cd4a5f2db9e2d4df5349))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* **deps:** Update dependency @google-cloud/precise-date to v3 ([#1676](https://github.com/googleapis/nodejs-spanner/issues/1676)) ([3f20ec4](https://github.com/googleapis/nodejs-spanner/commit/3f20ec47bbf89e1f72546a8ebf41a8b4ba93832f))
|
|
18
|
+
* Do not import the whole google-gax from proto JS ([#1553](https://github.com/googleapis/nodejs-spanner/issues/1553)) ([#1700](https://github.com/googleapis/nodejs-spanner/issues/1700)) ([f9c2640](https://github.com/googleapis/nodejs-spanner/commit/f9c2640e054659a2e8299b8f989fa7936d04b0d7))
|
|
19
|
+
* use google-gax v3.3.0 ([f9c2640](https://github.com/googleapis/nodejs-spanner/commit/f9c2640e054659a2e8299b8f989fa7936d04b0d7))
|
|
20
|
+
|
|
7
21
|
## [6.2.0](https://github.com/googleapis/nodejs-spanner/compare/v6.1.4...v6.2.0) (2022-09-16)
|
|
8
22
|
|
|
9
23
|
|
package/README.md
CHANGED
|
@@ -119,6 +119,10 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-spanner/tre
|
|
|
119
119
|
| Reads data using an existing storing index. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/index-read-data-with-storing.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/index-read-data-with-storing.js,samples/README.md) |
|
|
120
120
|
| Read data using an existing index. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/index-read-data.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/index-read-data.js,samples/README.md) |
|
|
121
121
|
| Indexing | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/indexing.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/indexing.js,samples/README.md) |
|
|
122
|
+
| Creates a user-managed instance configuration. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance-config-create.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance-config-create.js,samples/README.md) |
|
|
123
|
+
| Deletes a user-managed instance configuration. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance-config-delete.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance-config-delete.js,samples/README.md) |
|
|
124
|
+
| Lists the instance configuration operations. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance-config-get-operations.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance-config-get-operations.js,samples/README.md) |
|
|
125
|
+
| Updates a user-managed instance configuration. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance-config-update.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance-config-update.js,samples/README.md) |
|
|
122
126
|
| Instance-with-processing-units | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance-with-processing-units.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance-with-processing-units.js,samples/README.md) |
|
|
123
127
|
| Instance | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance.js,samples/README.md) |
|
|
124
128
|
| Json-add-column | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/json-add-column.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/json-add-column.js,samples/README.md) |
|
package/build/src/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { Float, Int, Numeric, PGNumeric, Struct } from './codec';
|
|
|
22
22
|
import { Backup } from './backup';
|
|
23
23
|
import { Database } from './database';
|
|
24
24
|
import { Instance, CreateInstanceCallback, CreateInstanceResponse } from './instance';
|
|
25
|
+
import { InstanceConfig, CreateInstanceConfigCallback, CreateInstanceConfigResponse } from './instance-config';
|
|
25
26
|
import { grpc, GrpcClientOptions, CallOptions } from 'google-gax';
|
|
26
27
|
import { google, google as instanceAdmin } from '../protos/protos';
|
|
27
28
|
import { PagedOptions, PagedResponse, PagedCallback, PagedOptionsWithFilter, NormalCallback } from './common';
|
|
@@ -42,6 +43,9 @@ export interface GetInstanceConfigOptions {
|
|
|
42
43
|
}
|
|
43
44
|
export declare type GetInstanceConfigResponse = [IInstanceConfig];
|
|
44
45
|
export declare type GetInstanceConfigCallback = NormalCallback<IInstanceConfig>;
|
|
46
|
+
export declare type GetInstanceConfigOperationsOptions = PagedOptionsWithFilter;
|
|
47
|
+
export declare type GetInstanceConfigOperationsResponse = PagedResponse<IOperation, instanceAdmin.spanner.admin.instance.v1.IListInstanceConfigOperationsResponse>;
|
|
48
|
+
export declare type GetInstanceConfigOperationsCallback = PagedCallback<IOperation, instanceAdmin.spanner.admin.instance.v1.IListInstanceConfigOperationsResponse>;
|
|
45
49
|
export interface SpannerOptions extends GrpcClientOptions {
|
|
46
50
|
apiEndpoint?: string;
|
|
47
51
|
servicePath?: string;
|
|
@@ -67,6 +71,17 @@ export interface CreateInstanceRequest {
|
|
|
67
71
|
} | null;
|
|
68
72
|
gaxOptions?: CallOptions;
|
|
69
73
|
}
|
|
74
|
+
export interface CreateInstanceConfigRequest {
|
|
75
|
+
displayName?: string;
|
|
76
|
+
replicas?: google.spanner.admin.instance.v1.IReplicaInfo[];
|
|
77
|
+
baseConfig?: string;
|
|
78
|
+
labels?: {
|
|
79
|
+
[k: string]: string;
|
|
80
|
+
} | null;
|
|
81
|
+
etag?: string;
|
|
82
|
+
validateOnly?: boolean;
|
|
83
|
+
gaxOptions?: CallOptions;
|
|
84
|
+
}
|
|
70
85
|
/**
|
|
71
86
|
* Translates enum values to string keys.
|
|
72
87
|
*
|
|
@@ -133,6 +148,7 @@ declare class Spanner extends GrpcService {
|
|
|
133
148
|
auth: GoogleAuth;
|
|
134
149
|
clients_: Map<string, {}>;
|
|
135
150
|
instances_: Map<string, Instance>;
|
|
151
|
+
instanceConfigs_: Map<string, InstanceConfig>;
|
|
136
152
|
projectIdReplaced_: boolean;
|
|
137
153
|
projectFormattedName_: string;
|
|
138
154
|
resourceHeader_: {
|
|
@@ -374,6 +390,106 @@ declare class Spanner extends GrpcService {
|
|
|
374
390
|
* ```
|
|
375
391
|
*/
|
|
376
392
|
getInstancesStream(options?: GetInstancesOptions): NodeJS.ReadableStream;
|
|
393
|
+
/**
|
|
394
|
+
* Config for the new instance config.
|
|
395
|
+
*
|
|
396
|
+
* @typedef {object} CreateInstanceConfigRequest
|
|
397
|
+
* @property {string} [displayName] The name of this instance configuration as
|
|
398
|
+
* it appears in the user interface.
|
|
399
|
+
* @property {google.spanner.admin.instance.v1.IReplicaInfo[]} [replicas] The
|
|
400
|
+
* geographic placement of nodes in this instance configuration and their
|
|
401
|
+
* replication properties.
|
|
402
|
+
* @property {string} [baseConfig] Base configuration name,
|
|
403
|
+
* e.g. projects/<project_name>/instanceConfigs/nam3 based on which this
|
|
404
|
+
* configuration is created.
|
|
405
|
+
* @property {Object.<string, string>} [labels] Cloud Labels are a flexible
|
|
406
|
+
* and lightweight mechanism for organizing cloud resources into groups
|
|
407
|
+
* that reflect a customer's organizational needs and deployment
|
|
408
|
+
* strategies. Cloud Labels can be used to filter collections of
|
|
409
|
+
* resources. They can be used to control how resource metrics are
|
|
410
|
+
* aggregated. And they can be used as arguments to policy management
|
|
411
|
+
* rules (e.g. route, firewall, load balancing, etc.).
|
|
412
|
+
* @property {string} [etag] etag is used for optimistic concurrency control
|
|
413
|
+
* as a way to help prevent simultaneous updates of a instance config from
|
|
414
|
+
* overwriting each other.
|
|
415
|
+
* @property {boolean} [validateOnly] An option to validate, but not actually
|
|
416
|
+
* execute, a request, and provide the same response.
|
|
417
|
+
*/
|
|
418
|
+
/**
|
|
419
|
+
* @typedef {array} CreateInstanceConfigResponse
|
|
420
|
+
* @property {InstanceConfig} 0 The new {@link google.spanner.admin.instance.v1.InstanceConfig}.
|
|
421
|
+
* @property {google.longrunning.Operation} 1 An operation object that can be
|
|
422
|
+
* used to check the status of the request.
|
|
423
|
+
* @property {google.longrunning.IOperation} 2 The full API response.
|
|
424
|
+
*/
|
|
425
|
+
/**
|
|
426
|
+
* @callback CreateInstanceConfigCallback
|
|
427
|
+
* @param {?Error} err Request error, if any.
|
|
428
|
+
* @param {InstanceConfig} instanceConfig The new {@link google.spanner.admin.instance.v1.InstanceConfig}.
|
|
429
|
+
* @param {google.longrunning.Operation} operation An operation object that
|
|
430
|
+
* can be used to check the status of the request.
|
|
431
|
+
* @param {google.longrunning.IOperation} apiResponse The full API response.
|
|
432
|
+
*/
|
|
433
|
+
/**
|
|
434
|
+
* Create an instance config.
|
|
435
|
+
*
|
|
436
|
+
* Wrapper around {@link v1.InstanceAdminClient#createInstanceConfig}.
|
|
437
|
+
*
|
|
438
|
+
* @see {@link v1.InstanceAdminClient#createInstanceConfig}
|
|
439
|
+
* @see [CreateInstanceConfig API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig)
|
|
440
|
+
*
|
|
441
|
+
* @throws {GoogleError} If a name is not provided.
|
|
442
|
+
* @throws {GoogleError} If a configuration object is not provided.
|
|
443
|
+
* @throws {GoogleError} If a base config is not provided in the configuration
|
|
444
|
+
* object.
|
|
445
|
+
*
|
|
446
|
+
* @param {string} name The name of the instance config to be created.
|
|
447
|
+
* @param {CreateInstanceConfigRequest} config Configuration object.
|
|
448
|
+
* @param {CreateInstanceConfigCallback} [callback] Callback function.
|
|
449
|
+
* @returns {Promise<CreateInstanceConfigResponse>}
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* ```
|
|
453
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
454
|
+
* const spanner = new Spanner();
|
|
455
|
+
*
|
|
456
|
+
* const [baseInstanceConfig] =
|
|
457
|
+
* await spanner.getInstanceConfig(baseInstanceConfigId);
|
|
458
|
+
* const config = {
|
|
459
|
+
* baseConfig: baseInstanceConfig.name,
|
|
460
|
+
* replicas: baseInstanceConfig.replicas.concat(baseInstanceConfig.optionalReplicas[0])
|
|
461
|
+
* };
|
|
462
|
+
*
|
|
463
|
+
* function callback(err, instance, operation, apiResponse) {
|
|
464
|
+
* if (err) {
|
|
465
|
+
* // Error handling omitted.
|
|
466
|
+
* }
|
|
467
|
+
*
|
|
468
|
+
* operation
|
|
469
|
+
* .on('error', function(err) {})
|
|
470
|
+
* .on('complete', function() {
|
|
471
|
+
* // Instance created successfully.
|
|
472
|
+
* });
|
|
473
|
+
* }
|
|
474
|
+
*
|
|
475
|
+
* spanner.createInstanceConfig('custom-new-instance-config', config, callback);
|
|
476
|
+
*
|
|
477
|
+
* //-
|
|
478
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
479
|
+
* //-
|
|
480
|
+
* spanner.createInstanceConfig('custom-new-instance-config', config)
|
|
481
|
+
* .then(function(data) {
|
|
482
|
+
* const instanceConfig = data[0];
|
|
483
|
+
* const operation = data[1];
|
|
484
|
+
* return operation.promise();
|
|
485
|
+
* })
|
|
486
|
+
* .then(function() {
|
|
487
|
+
* // Instance config created successfully.
|
|
488
|
+
* });
|
|
489
|
+
* ```
|
|
490
|
+
*/
|
|
491
|
+
createInstanceConfig(name: string, config: CreateInstanceConfigRequest): Promise<CreateInstanceConfigResponse>;
|
|
492
|
+
createInstanceConfig(name: string, config: CreateInstanceConfigRequest, callback: CreateInstanceConfigCallback): void;
|
|
377
493
|
/**
|
|
378
494
|
* Lists the supported instance configurations for a given project.
|
|
379
495
|
*
|
|
@@ -555,6 +671,72 @@ declare class Spanner extends GrpcService {
|
|
|
555
671
|
getInstanceConfig(name: string, options: GetInstanceConfigOptions): Promise<GetInstanceConfigResponse>;
|
|
556
672
|
getInstanceConfig(name: string, callback: GetInstanceConfigCallback): void;
|
|
557
673
|
getInstanceConfig(name: string, options: GetInstanceConfigOptions, callback: GetInstanceConfigCallback): void;
|
|
674
|
+
/**
|
|
675
|
+
* Query object for listing instance config operations.
|
|
676
|
+
*
|
|
677
|
+
* @typedef {object} GetInstanceConfigOperationsOptions
|
|
678
|
+
* @property {string} [filter] An expression for filtering the results of the
|
|
679
|
+
* request. Filter can be configured as outlined in
|
|
680
|
+
* {@link v1.DatabaseAdminClient#listInstanceConfigOperations}.
|
|
681
|
+
* @property {number} [pageSize] Maximum number of results per page.
|
|
682
|
+
* @property {string} [pageToken] A previously-returned page token
|
|
683
|
+
* representing part of the larger set of results to view.
|
|
684
|
+
* @property {object} [gaxOptions] Request configuration options,
|
|
685
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
686
|
+
* for more details.
|
|
687
|
+
*/
|
|
688
|
+
/**
|
|
689
|
+
* @typedef {array} GetInstanceConfigOperationsResponse
|
|
690
|
+
* @property {google.longrunning.IOperation[]} 0 Array of {@link IOperation} instances.
|
|
691
|
+
* @property {object} 1 A query object to receive more results.
|
|
692
|
+
* @property {object} 2 The full API response.
|
|
693
|
+
*/
|
|
694
|
+
/**
|
|
695
|
+
* @callback GetInstanceConfigOperationsCallback
|
|
696
|
+
* @param {?Error} err Request error, if any.
|
|
697
|
+
* @param {google.longrunning.IOperation[]} 0 Array of {@link IOperation} instances.
|
|
698
|
+
* @param {object} nextQuery A query object to receive more results.
|
|
699
|
+
* @param {object} apiResponse The full API response.
|
|
700
|
+
*/
|
|
701
|
+
/**
|
|
702
|
+
* List pending and completed instance config operations.
|
|
703
|
+
*
|
|
704
|
+
* @see {@link #listOperations}
|
|
705
|
+
*
|
|
706
|
+
* @param {GetInstanceConfigOperationsOptions} [options] The query object for
|
|
707
|
+
* listing InstanceConfig operations.
|
|
708
|
+
* @param {gax.CallOptions} [options.gaxOptions] The request configuration
|
|
709
|
+
* options, See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
710
|
+
* for more details.
|
|
711
|
+
* @returns {Promise<GetInstanceConfigOperationsResponse>} When resolved,
|
|
712
|
+
* contains a paged list of InstanceConfig operations.
|
|
713
|
+
*
|
|
714
|
+
* @example
|
|
715
|
+
* ```
|
|
716
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
717
|
+
* const spanner = new Spanner();
|
|
718
|
+
* const [operations] = await spanner.getInstanceConfigOperations();
|
|
719
|
+
*
|
|
720
|
+
* //-
|
|
721
|
+
* // To manually handle pagination, set autoPaginate:false in gaxOptions.
|
|
722
|
+
* //-
|
|
723
|
+
* let pageToken = undefined;
|
|
724
|
+
* do {
|
|
725
|
+
* const [operations, , response] = await spanner.getInstanceConfigOperations({
|
|
726
|
+
* pageSize: 3,
|
|
727
|
+
* pageToken,
|
|
728
|
+
* gaxOptions: {autoPaginate: false},
|
|
729
|
+
* });
|
|
730
|
+
* operations.forEach(operation => {
|
|
731
|
+
* // Do something with operation
|
|
732
|
+
* });
|
|
733
|
+
* pageToken = response.nextPageToken;
|
|
734
|
+
* } while (pageToken);
|
|
735
|
+
* ```
|
|
736
|
+
*/
|
|
737
|
+
getInstanceConfigOperations(options?: GetInstanceConfigOperationsOptions): Promise<GetInstanceConfigOperationsResponse>;
|
|
738
|
+
getInstanceConfigOperations(callback: GetInstanceConfigOperationsCallback): void;
|
|
739
|
+
getInstanceConfigOperations(options: GetInstanceConfigOperationsOptions, callback: GetInstanceConfigOperationsCallback): void;
|
|
558
740
|
/**
|
|
559
741
|
* Get a reference to an Instance object.
|
|
560
742
|
*
|
|
@@ -571,6 +753,22 @@ declare class Spanner extends GrpcService {
|
|
|
571
753
|
* ```
|
|
572
754
|
*/
|
|
573
755
|
instance(name: string): Instance;
|
|
756
|
+
/**
|
|
757
|
+
* Get a reference to an InstanceConfig object.
|
|
758
|
+
*
|
|
759
|
+
* @throws {GoogleError} If a name is not provided.
|
|
760
|
+
*
|
|
761
|
+
* @param {string} name The name of the instance config.
|
|
762
|
+
* @returns {InstanceConfig} An InstanceConfig object.
|
|
763
|
+
*
|
|
764
|
+
* @example
|
|
765
|
+
* ```
|
|
766
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
767
|
+
* const spanner = new Spanner();
|
|
768
|
+
* const instanceConfig = spanner.instanceConfig('my-instance-config');
|
|
769
|
+
* ```
|
|
770
|
+
*/
|
|
771
|
+
instanceConfig(name: string): InstanceConfig;
|
|
574
772
|
/**
|
|
575
773
|
* Prepare a gapic request. This will cache the GAX client and replace
|
|
576
774
|
* {{projectId}} placeholders, if necessary.
|
|
@@ -766,6 +964,14 @@ export { Spanner };
|
|
|
766
964
|
* @type {Constructor}
|
|
767
965
|
*/
|
|
768
966
|
export { Instance };
|
|
967
|
+
/**
|
|
968
|
+
* {@link InstanceConfig} class.
|
|
969
|
+
*
|
|
970
|
+
* @name Spanner.InstanceConfig
|
|
971
|
+
* @see InstanceConfig
|
|
972
|
+
* @type {Constructor}
|
|
973
|
+
*/
|
|
974
|
+
export { InstanceConfig };
|
|
769
975
|
/**
|
|
770
976
|
* {@link Database} class.
|
|
771
977
|
*
|
package/build/src/index.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.protos = exports.v1 = exports.Transaction = exports.Snapshot = exports.PartitionedDml = exports.Table = exports.SessionPool = exports.Session = exports.Backup = exports.Database = exports.Instance = exports.Spanner = void 0;
|
|
18
|
+
exports.protos = exports.v1 = exports.Transaction = exports.Snapshot = exports.PartitionedDml = exports.Table = exports.SessionPool = exports.Session = exports.Backup = exports.Database = exports.InstanceConfig = exports.Instance = exports.Spanner = void 0;
|
|
19
19
|
const service_1 = require("./common-grpc/service");
|
|
20
20
|
const precise_date_1 = require("@google-cloud/precise-date");
|
|
21
21
|
const projectify_1 = require("@google-cloud/projectify");
|
|
@@ -32,6 +32,8 @@ const database_1 = require("./database");
|
|
|
32
32
|
Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return database_1.Database; } });
|
|
33
33
|
const instance_1 = require("./instance");
|
|
34
34
|
Object.defineProperty(exports, "Instance", { enumerable: true, get: function () { return instance_1.Instance; } });
|
|
35
|
+
const instance_config_1 = require("./instance-config");
|
|
36
|
+
Object.defineProperty(exports, "InstanceConfig", { enumerable: true, get: function () { return instance_config_1.InstanceConfig; } });
|
|
35
37
|
const google_gax_1 = require("google-gax");
|
|
36
38
|
const protos_1 = require("../protos/protos");
|
|
37
39
|
const common_1 = require("./common");
|
|
@@ -143,6 +145,7 @@ class Spanner extends service_1.GrpcService {
|
|
|
143
145
|
this.auth = new google_auth_library_1.GoogleAuth(this.options);
|
|
144
146
|
this.clients_ = new Map();
|
|
145
147
|
this.instances_ = new Map();
|
|
148
|
+
this.instanceConfigs_ = new Map();
|
|
146
149
|
this.projectIdReplaced_ = false;
|
|
147
150
|
this.projectFormattedName_ = 'projects/' + this.projectId;
|
|
148
151
|
this.resourceHeader_ = {
|
|
@@ -337,6 +340,53 @@ class Spanner extends service_1.GrpcService {
|
|
|
337
340
|
headers: this.resourceHeader_,
|
|
338
341
|
});
|
|
339
342
|
}
|
|
343
|
+
createInstanceConfig(name, config, callback) {
|
|
344
|
+
if (!name) {
|
|
345
|
+
throw new google_gax_1.GoogleError('A name is required to create an instance config.');
|
|
346
|
+
}
|
|
347
|
+
if (!config) {
|
|
348
|
+
throw new google_gax_1.GoogleError([
|
|
349
|
+
'A configuration object is required to create an instance config.',
|
|
350
|
+
].join(''));
|
|
351
|
+
}
|
|
352
|
+
if (!config.baseConfig) {
|
|
353
|
+
throw new google_gax_1.GoogleError(['Base instance config is required to create an instance config.'].join(''));
|
|
354
|
+
}
|
|
355
|
+
const formattedName = instance_config_1.InstanceConfig.formatName_(this.projectId, name);
|
|
356
|
+
const displayName = config.displayName || formattedName.split('/').pop();
|
|
357
|
+
const reqOpts = {
|
|
358
|
+
parent: this.projectFormattedName_,
|
|
359
|
+
instanceConfigId: formattedName.split('/').pop(),
|
|
360
|
+
instanceConfig: extend({
|
|
361
|
+
name: formattedName,
|
|
362
|
+
displayName,
|
|
363
|
+
}, config),
|
|
364
|
+
validateOnly: config.validateOnly,
|
|
365
|
+
};
|
|
366
|
+
if (config.baseConfig.indexOf('/') === -1) {
|
|
367
|
+
reqOpts.instanceConfig.baseConfig = `projects/${this.projectId}/instanceConfigs/${config.baseConfig}`;
|
|
368
|
+
}
|
|
369
|
+
// validateOnly need not be passed in if it is null.
|
|
370
|
+
if (reqOpts.validateOnly === null || reqOpts.validateOnly === undefined)
|
|
371
|
+
delete reqOpts.validateOnly;
|
|
372
|
+
// validateOnly and gaxOptions are not fields in InstanceConfig.
|
|
373
|
+
delete reqOpts.instanceConfig.validateOnly;
|
|
374
|
+
delete reqOpts.instanceConfig.gaxOptions;
|
|
375
|
+
this.request({
|
|
376
|
+
client: 'InstanceAdminClient',
|
|
377
|
+
method: 'createInstanceConfig',
|
|
378
|
+
reqOpts,
|
|
379
|
+
gaxOpts: config.gaxOptions,
|
|
380
|
+
headers: this.resourceHeader_,
|
|
381
|
+
}, (err, operation, resp) => {
|
|
382
|
+
if (err) {
|
|
383
|
+
callback(err, null, null, resp);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const instanceConfig = this.instanceConfig(formattedName);
|
|
387
|
+
callback(null, instanceConfig, operation, resp);
|
|
388
|
+
});
|
|
389
|
+
}
|
|
340
390
|
getInstanceConfigs(optionsOrCallback, cb) {
|
|
341
391
|
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
342
392
|
const options = typeof optionsOrCallback === 'object'
|
|
@@ -448,6 +498,39 @@ class Spanner extends service_1.GrpcService {
|
|
|
448
498
|
callback(err, instanceConfig);
|
|
449
499
|
});
|
|
450
500
|
}
|
|
501
|
+
getInstanceConfigOperations(optionsOrCallback, cb) {
|
|
502
|
+
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
503
|
+
const options = typeof optionsOrCallback === 'object'
|
|
504
|
+
? optionsOrCallback
|
|
505
|
+
: {};
|
|
506
|
+
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
507
|
+
let reqOpts = extend({}, options, {
|
|
508
|
+
parent: this.projectFormattedName_,
|
|
509
|
+
});
|
|
510
|
+
delete reqOpts.gaxOptions;
|
|
511
|
+
// Copy over pageSize and pageToken values from gaxOptions.
|
|
512
|
+
// However, values set on options take precedence.
|
|
513
|
+
if (gaxOpts) {
|
|
514
|
+
reqOpts = extend({}, {
|
|
515
|
+
pageSize: gaxOpts.pageSize,
|
|
516
|
+
pageToken: gaxOpts.pageToken,
|
|
517
|
+
}, reqOpts);
|
|
518
|
+
delete gaxOpts.pageSize;
|
|
519
|
+
delete gaxOpts.pageToken;
|
|
520
|
+
}
|
|
521
|
+
this.request({
|
|
522
|
+
client: 'InstanceAdminClient',
|
|
523
|
+
method: 'listInstanceConfigOperations',
|
|
524
|
+
reqOpts,
|
|
525
|
+
gaxOpts,
|
|
526
|
+
headers: this.resourceHeader_,
|
|
527
|
+
}, (err, operations, nextPageRequest, ...args) => {
|
|
528
|
+
const nextQuery = nextPageRequest
|
|
529
|
+
? extend({}, options, nextPageRequest)
|
|
530
|
+
: null;
|
|
531
|
+
callback(err, operations, nextQuery, ...args);
|
|
532
|
+
});
|
|
533
|
+
}
|
|
451
534
|
/**
|
|
452
535
|
* Get a reference to an Instance object.
|
|
453
536
|
*
|
|
@@ -473,6 +556,31 @@ class Spanner extends service_1.GrpcService {
|
|
|
473
556
|
}
|
|
474
557
|
return this.instances_.get(key);
|
|
475
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* Get a reference to an InstanceConfig object.
|
|
561
|
+
*
|
|
562
|
+
* @throws {GoogleError} If a name is not provided.
|
|
563
|
+
*
|
|
564
|
+
* @param {string} name The name of the instance config.
|
|
565
|
+
* @returns {InstanceConfig} An InstanceConfig object.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* ```
|
|
569
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
570
|
+
* const spanner = new Spanner();
|
|
571
|
+
* const instanceConfig = spanner.instanceConfig('my-instance-config');
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
instanceConfig(name) {
|
|
575
|
+
if (!name) {
|
|
576
|
+
throw new google_gax_1.GoogleError('A name is required to access an InstanceConfig object.');
|
|
577
|
+
}
|
|
578
|
+
const key = name.split('/').pop();
|
|
579
|
+
if (!this.instanceConfigs_.has(key)) {
|
|
580
|
+
this.instanceConfigs_.set(key, new instance_config_1.InstanceConfig(this, name));
|
|
581
|
+
}
|
|
582
|
+
return this.instanceConfigs_.get(key);
|
|
583
|
+
}
|
|
476
584
|
/**
|
|
477
585
|
* Prepare a gapic request. This will cache the GAX client and replace
|
|
478
586
|
* {{projectId}} placeholders, if necessary.
|
|
@@ -764,6 +872,7 @@ Spanner.GOOGLE_STANDARD_SQL = protos_1.google.spanner.admin.database.v1.Database
|
|
|
764
872
|
'date',
|
|
765
873
|
'float',
|
|
766
874
|
'instance',
|
|
875
|
+
'instanceConfig',
|
|
767
876
|
'int',
|
|
768
877
|
'numeric',
|
|
769
878
|
'pgNumeric',
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2022 Google LLC
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
declare const common: any;
|
|
16
|
+
import { google as instanceAdmin } from '../protos/protos';
|
|
17
|
+
import { Operation as GaxOperation } from 'google-gax/build/src/longRunningCalls/longrunning';
|
|
18
|
+
import { LongRunningCallback, RequestCallback, ResourceCallback, NormalCallback } from './common';
|
|
19
|
+
import { GetInstanceConfigCallback, GetInstanceConfigOptions, GetInstanceConfigResponse, RequestConfig, Spanner } from './index';
|
|
20
|
+
import { CallOptions } from 'google-gax';
|
|
21
|
+
export declare type IOperation = instanceAdmin.longrunning.IOperation;
|
|
22
|
+
export declare type CreateInstanceConfigCallback = LongRunningCallback<InstanceConfig>;
|
|
23
|
+
export declare type SetInstanceConfigMetadataCallback = ResourceCallback<GaxOperation, IOperation>;
|
|
24
|
+
export declare type DeleteInstanceConfigCallback = NormalCallback<instanceAdmin.protobuf.IEmpty>;
|
|
25
|
+
export declare type ExistsInstanceConfigCallback = NormalCallback<boolean>;
|
|
26
|
+
export declare type CreateInstanceConfigResponse = [
|
|
27
|
+
InstanceConfig,
|
|
28
|
+
GaxOperation,
|
|
29
|
+
IOperation
|
|
30
|
+
];
|
|
31
|
+
export declare type SetInstanceConfigMetadataResponse = [GaxOperation, IOperation];
|
|
32
|
+
export declare type DeleteInstanceConfigResponse = [instanceAdmin.protobuf.IEmpty];
|
|
33
|
+
export declare type ExistsInstanceConfigResponse = boolean;
|
|
34
|
+
export declare type IInstanceConfig = instanceAdmin.spanner.admin.instance.v1.IInstanceConfig;
|
|
35
|
+
interface InstanceConfigRequest {
|
|
36
|
+
(config: RequestConfig, callback: ResourceCallback<GaxOperation, IOperation>): void;
|
|
37
|
+
<T>(config: RequestConfig, callback: RequestCallback<T>): void;
|
|
38
|
+
<T, R>(config: RequestConfig, callback: RequestCallback<T, R>): void;
|
|
39
|
+
}
|
|
40
|
+
export interface SetInstanceConfigMetadataRequest {
|
|
41
|
+
instanceConfig: IInstanceConfig;
|
|
42
|
+
validateOnly?: boolean;
|
|
43
|
+
gaxOpts?: CallOptions;
|
|
44
|
+
}
|
|
45
|
+
interface DeleteInstanceConfigRequest {
|
|
46
|
+
etag?: string;
|
|
47
|
+
validateOnly?: boolean;
|
|
48
|
+
gaxOpts?: CallOptions;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The {@link InstanceConfig} class represents a possible configuration for a
|
|
52
|
+
* Cloud Spanner instance.
|
|
53
|
+
*
|
|
54
|
+
* Create an `InstanceConfig` object to interact with a Cloud Spanner instance
|
|
55
|
+
* config.
|
|
56
|
+
*
|
|
57
|
+
* @class
|
|
58
|
+
*
|
|
59
|
+
* @param {Spanner} spanner {@link Spanner} instance.
|
|
60
|
+
* @param {string} name Name of the instance config.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```
|
|
64
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
65
|
+
* const spanner = new Spanner();
|
|
66
|
+
* const instance = spanner.instanceConfig('my-instance-config');
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare class InstanceConfig extends common.GrpcServiceObject {
|
|
70
|
+
formattedName_: string;
|
|
71
|
+
request: InstanceConfigRequest;
|
|
72
|
+
metadata?: IInstanceConfig;
|
|
73
|
+
resourceHeader_: {
|
|
74
|
+
[k: string]: string;
|
|
75
|
+
};
|
|
76
|
+
constructor(spanner: Spanner, name: string);
|
|
77
|
+
/**
|
|
78
|
+
* Gets the metadata from the backend for this InstanceConfig.
|
|
79
|
+
*/
|
|
80
|
+
/**
|
|
81
|
+
* @typedef {array} GetInstanceConfigResponse
|
|
82
|
+
* @property {object[]} 0 The metadata of the instance config.
|
|
83
|
+
* @property {string} 0.name The unique identifier for the instance config.
|
|
84
|
+
* @property {string} 0.displayName The name of the instance config as it
|
|
85
|
+
* appears in UIs.
|
|
86
|
+
* @property {google.spanner.admin.instance.v1.IReplicaInfo[]} 0.replicas The replicas used by
|
|
87
|
+
* this instance config.
|
|
88
|
+
* @property {string[]} 0.leaderOptions The possible leader options for this instance config.
|
|
89
|
+
*/
|
|
90
|
+
/**
|
|
91
|
+
* @callback GetInstanceConfigCallback
|
|
92
|
+
* @param {?Error} err Request error, if any.
|
|
93
|
+
* @param {object} instanceConfig The metadata of the instance config.
|
|
94
|
+
* @param {string} instanceConfig.name The unique identifier for the instance
|
|
95
|
+
* config.
|
|
96
|
+
* @param {string} instanceConfig.displayName The name of the instance config
|
|
97
|
+
* as it appears in UIs.
|
|
98
|
+
* @param {google.spanner.admin.instance.v1.IReplicaInfo[]} instanceConfig.replicas The replicas used by
|
|
99
|
+
* this instance config.
|
|
100
|
+
* @param {string[]} 0.leaderOptions The possible leader options for this instance config.
|
|
101
|
+
*/
|
|
102
|
+
/**
|
|
103
|
+
* Gets the metadata from the backend for this InstanceConfig.
|
|
104
|
+
*
|
|
105
|
+
* Wrapper around {@link v1.InstanceAdminClient#getInstanceConfig}.
|
|
106
|
+
*
|
|
107
|
+
* @see {@link v1.InstanceAdminClient#getInstanceConfig}
|
|
108
|
+
* @see [GetInstanceConfig API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig)
|
|
109
|
+
*
|
|
110
|
+
* @param {GetInstanceConfigCallback} [callback] Callback function.
|
|
111
|
+
* @returns {Promise<GetInstanceConfigResponse>}
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```
|
|
115
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
116
|
+
* const spanner = new Spanner();
|
|
117
|
+
*
|
|
118
|
+
* const instanceConfig = spanner.instanceConfig('custom-my-instance-config');
|
|
119
|
+
*
|
|
120
|
+
* instanceConfig.get(function(err, instanceConfig) {
|
|
121
|
+
* // `instanceConfig` is an instance configuration descriptor.
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* //-
|
|
125
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
126
|
+
* //-
|
|
127
|
+
* instanceConfig.get().then(function(data) {
|
|
128
|
+
* const instanceConfig = data[0];
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
get(options?: GetInstanceConfigOptions): Promise<GetInstanceConfigResponse>;
|
|
133
|
+
get(callback: GetInstanceConfigCallback): void;
|
|
134
|
+
get(options: GetInstanceConfigOptions, callback: GetInstanceConfigCallback): void;
|
|
135
|
+
/**
|
|
136
|
+
* Update the metadata for this instance config. Note that this method follows
|
|
137
|
+
* PATCH semantics, so previously-configured settings will persist.
|
|
138
|
+
* This function can only be called for deleting user managed instance
|
|
139
|
+
* configs.
|
|
140
|
+
*
|
|
141
|
+
* Wrapper around {@link v1.InstanceAdminClient#updateInstanceConfig}.
|
|
142
|
+
*
|
|
143
|
+
* @see {@link v1.InstanceAdminClient#updateInstanceConfig}
|
|
144
|
+
* @see [UpdateInstanceConfig API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.UpdateInstanceConfig)
|
|
145
|
+
*
|
|
146
|
+
* @param {object} metadata The metadata you wish to set.
|
|
147
|
+
* @param {object} [gaxOptions] Request configuration options,
|
|
148
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
149
|
+
* for more details.
|
|
150
|
+
* @param {SetInstanceConfigMetadataCallback} [callback] Callback function.
|
|
151
|
+
* @returns {Promise<LongRunningOperationResponse>}
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```
|
|
155
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
156
|
+
* const spanner = new Spanner();
|
|
157
|
+
*
|
|
158
|
+
* const instanceConfig = spanner.instanceConfig('custom-my-instance-config');
|
|
159
|
+
*
|
|
160
|
+
* const metadata = {
|
|
161
|
+
* instanceConfig: {
|
|
162
|
+
* displayName: 'My Instance Config'
|
|
163
|
+
* }
|
|
164
|
+
* };
|
|
165
|
+
*
|
|
166
|
+
* instanceConfig.setMetadata(metadata, function(err, operation, apiResponse) {
|
|
167
|
+
* if (err) {
|
|
168
|
+
* // Error handling omitted.
|
|
169
|
+
* }
|
|
170
|
+
*
|
|
171
|
+
* operation
|
|
172
|
+
* .on('error', function(err) {})
|
|
173
|
+
* .on('complete', function() {
|
|
174
|
+
* // Metadata updated successfully.
|
|
175
|
+
* });
|
|
176
|
+
* });
|
|
177
|
+
*
|
|
178
|
+
* //-
|
|
179
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
180
|
+
* //-
|
|
181
|
+
* instanceConfig.setMetadata(metadata).then(function(data) {
|
|
182
|
+
* const operation = data[0];
|
|
183
|
+
* const apiResponse = data[1];
|
|
184
|
+
* });
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
setMetadata(config: SetInstanceConfigMetadataRequest): Promise<SetInstanceConfigMetadataResponse>;
|
|
188
|
+
setMetadata(config: SetInstanceConfigMetadataRequest, callback: SetInstanceConfigMetadataCallback): void;
|
|
189
|
+
/**
|
|
190
|
+
* @typedef {array} DeleteInstanceConfigResponse
|
|
191
|
+
* @property {object} 0 The full API response.
|
|
192
|
+
*/
|
|
193
|
+
/**
|
|
194
|
+
* @callback DeleteInstanceConfigCallback
|
|
195
|
+
* @param {?Error} err Request error, if any.
|
|
196
|
+
* @param {object} apiResponse The full API response.
|
|
197
|
+
*/
|
|
198
|
+
/**
|
|
199
|
+
* Delete the instance config. This function can only be called for deleting
|
|
200
|
+
* user managed instance configs.
|
|
201
|
+
*
|
|
202
|
+
* Wrapper around {@link v1.InstanceAdminClient#deleteInstanceConfig}.
|
|
203
|
+
*
|
|
204
|
+
* @see {@link v1.InstanceAdminClient#deleteInstanceConfig}
|
|
205
|
+
* @see [DeleteInstanceConfig API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.DeleteInstanceConfig)
|
|
206
|
+
*
|
|
207
|
+
* @param {object} [gaxOptions] Request configuration options,
|
|
208
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
209
|
+
* for more details.
|
|
210
|
+
* @param {DeleteInstanceConfigCallback} [callback] Callback function.
|
|
211
|
+
* @returns {Promise<DeleteInstanceConfigResponse>}
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```
|
|
215
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
216
|
+
* const spanner = new Spanner();
|
|
217
|
+
*
|
|
218
|
+
* const instanceConfig = spanner.instanceConfig('custom-my-instance-config');
|
|
219
|
+
*
|
|
220
|
+
* instanceConfig.delete(function(err, apiResponse) {
|
|
221
|
+
* if (err) {
|
|
222
|
+
* // Error handling omitted.
|
|
223
|
+
* }
|
|
224
|
+
*
|
|
225
|
+
* // Instance config was deleted successfully.
|
|
226
|
+
* });
|
|
227
|
+
*
|
|
228
|
+
* //-
|
|
229
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
230
|
+
* //-
|
|
231
|
+
* instanceConfig.delete().then(function(data) {
|
|
232
|
+
* const apiResponse = data[0];
|
|
233
|
+
* });
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
delete(config?: DeleteInstanceConfigRequest): Promise<DeleteInstanceConfigResponse>;
|
|
237
|
+
delete(callback: DeleteInstanceConfigCallback): void;
|
|
238
|
+
delete(config: DeleteInstanceConfigRequest, callback: DeleteInstanceConfigCallback): void;
|
|
239
|
+
/**
|
|
240
|
+
* @typedef {array} ExistsInstanceConfigResponse
|
|
241
|
+
* @property {boolean} 0 Whether the {@link InstanceConfig} exists.
|
|
242
|
+
*/
|
|
243
|
+
/**
|
|
244
|
+
* @callback ExistsInstanceConfigCallback
|
|
245
|
+
* @param {?Error} err Request error, if any.
|
|
246
|
+
* @param {boolean} exists Whether the {@link InstanceConfig} exists.
|
|
247
|
+
*/
|
|
248
|
+
/**
|
|
249
|
+
* Check if an instance config exists.
|
|
250
|
+
*
|
|
251
|
+
* @method InstanceConfig#exists
|
|
252
|
+
* @param {object} [gaxOptions] Request configuration options,
|
|
253
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
254
|
+
* for more details.
|
|
255
|
+
* @param {ExistsInstanceConfigCallback} [callback] Callback function.
|
|
256
|
+
* @returns {Promise<ExistsInstanceConfigResponse>} When resolved, contains
|
|
257
|
+
* true if the instance config exists and false if it does not exist.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```
|
|
261
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
262
|
+
* const spanner = new Spanner();
|
|
263
|
+
*
|
|
264
|
+
* const instanceConfig = spanner.instanceConfig('custom-my-instance-config');
|
|
265
|
+
*
|
|
266
|
+
* const exists = await instanceConfig.exists();
|
|
267
|
+
* console.log(`Does instance config exist? ${exists}`);
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
exists(): Promise<ExistsInstanceConfigResponse>;
|
|
271
|
+
exists(callback: ExistsInstanceConfigCallback): void;
|
|
272
|
+
/**
|
|
273
|
+
* Format the instance config name to include the project ID.
|
|
274
|
+
*
|
|
275
|
+
* @private
|
|
276
|
+
*
|
|
277
|
+
* @param {string} projectId The project ID.
|
|
278
|
+
* @param {string} name The instance config name.
|
|
279
|
+
* @returns {string}
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```
|
|
283
|
+
* InstanceConfig.formatName_('grape-spaceship-123', 'my-instance-config');
|
|
284
|
+
* // 'projects/grape-spaceship-123/instanceConfigs/my-instance-config'
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
static formatName_(projectId: string, name: string): string;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Reference to the {@link InstanceConfig} class.
|
|
291
|
+
* @name module:@google-cloud/spanner.InstanceConfig
|
|
292
|
+
* @see InstanceConfig
|
|
293
|
+
*/
|
|
294
|
+
export { InstanceConfig };
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.InstanceConfig = void 0;
|
|
18
|
+
const common = require('./common-grpc/service-object');
|
|
19
|
+
const snakeCase = require("lodash.snakecase");
|
|
20
|
+
const common_1 = require("./common");
|
|
21
|
+
const promisify_1 = require("@google-cloud/promisify");
|
|
22
|
+
const google_gax_1 = require("google-gax");
|
|
23
|
+
const extend = require("extend");
|
|
24
|
+
/**
|
|
25
|
+
* The {@link InstanceConfig} class represents a possible configuration for a
|
|
26
|
+
* Cloud Spanner instance.
|
|
27
|
+
*
|
|
28
|
+
* Create an `InstanceConfig` object to interact with a Cloud Spanner instance
|
|
29
|
+
* config.
|
|
30
|
+
*
|
|
31
|
+
* @class
|
|
32
|
+
*
|
|
33
|
+
* @param {Spanner} spanner {@link Spanner} instance.
|
|
34
|
+
* @param {string} name Name of the instance config.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```
|
|
38
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
39
|
+
* const spanner = new Spanner();
|
|
40
|
+
* const instance = spanner.instanceConfig('my-instance-config');
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
class InstanceConfig extends common.GrpcServiceObject {
|
|
44
|
+
constructor(spanner, name) {
|
|
45
|
+
const formattedName_ = InstanceConfig.formatName_(spanner.projectId, name);
|
|
46
|
+
const methods = {
|
|
47
|
+
/**
|
|
48
|
+
* Create an instance config.
|
|
49
|
+
*
|
|
50
|
+
* Wrapper around {@link v1.InstanceAdminClient#createInstanceConfig}.
|
|
51
|
+
*
|
|
52
|
+
* @see {@link v1.InstanceAdminClient#createInstanceConfig}
|
|
53
|
+
* @see [CreateInstanceConfig API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.CreateInstanceConfig)
|
|
54
|
+
*
|
|
55
|
+
* @method InstanceConfig#create
|
|
56
|
+
* @param {CreateInstanceConfigRequest} config Configuration object.
|
|
57
|
+
* @param {CreateInstanceConfigCallback} [callback] Callback function.
|
|
58
|
+
* @returns {Promise<CreateInstanceConfigResponse>}
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```
|
|
62
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
63
|
+
* const spanner = new Spanner();
|
|
64
|
+
*
|
|
65
|
+
* const instanceConfig =
|
|
66
|
+
* spanner.instanceConfig('custom-my-instance-config');
|
|
67
|
+
*
|
|
68
|
+
* instanceConfig.create(function(err, instance, operation, apiResponse) {
|
|
69
|
+
* if (err) {
|
|
70
|
+
* // Error handling omitted.
|
|
71
|
+
* }
|
|
72
|
+
*
|
|
73
|
+
* operation
|
|
74
|
+
* .on('error', function(err) {})
|
|
75
|
+
* .on('complete', function() {
|
|
76
|
+
* // Instance config created successfully.
|
|
77
|
+
* });
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* //-
|
|
81
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
82
|
+
* //-
|
|
83
|
+
* instanceConfig.create()
|
|
84
|
+
* .then(function(data) {
|
|
85
|
+
* const operation = data[0];
|
|
86
|
+
* const apiResponse = data[1];
|
|
87
|
+
*
|
|
88
|
+
* return operation.promise();
|
|
89
|
+
* })
|
|
90
|
+
* .then(function() {
|
|
91
|
+
* // Instance config created successfully.
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
create: true,
|
|
96
|
+
};
|
|
97
|
+
super({
|
|
98
|
+
parent: spanner,
|
|
99
|
+
id: name,
|
|
100
|
+
methods,
|
|
101
|
+
createMethod(_, options, callback) {
|
|
102
|
+
spanner.createInstanceConfig(formattedName_, options, callback);
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
this.formattedName_ = formattedName_;
|
|
106
|
+
this.request = spanner.request.bind(spanner);
|
|
107
|
+
this.resourceHeader_ = {
|
|
108
|
+
[common_1.CLOUD_RESOURCE_HEADER]: this.formattedName_,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
get(optionsOrCallback, cb) {
|
|
112
|
+
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
113
|
+
const options = typeof optionsOrCallback === 'object'
|
|
114
|
+
? optionsOrCallback
|
|
115
|
+
: {};
|
|
116
|
+
this.parent.getInstanceConfig(this.id, options, callback);
|
|
117
|
+
}
|
|
118
|
+
setMetadata(config, callback) {
|
|
119
|
+
const reqOpts = {
|
|
120
|
+
instanceConfig: extend({
|
|
121
|
+
name: this.formattedName_,
|
|
122
|
+
}, config.instanceConfig),
|
|
123
|
+
updateMask: {
|
|
124
|
+
paths: Object.keys(config.instanceConfig).map(snakeCase),
|
|
125
|
+
},
|
|
126
|
+
validateOnly: config.validateOnly,
|
|
127
|
+
};
|
|
128
|
+
// validateOnly need not be passed in if it is null or undefined.
|
|
129
|
+
if (reqOpts.validateOnly === null || reqOpts.validateOnly === undefined)
|
|
130
|
+
delete reqOpts.validateOnly;
|
|
131
|
+
return this.request({
|
|
132
|
+
client: 'InstanceAdminClient',
|
|
133
|
+
method: 'updateInstanceConfig',
|
|
134
|
+
reqOpts,
|
|
135
|
+
gaxOpts: config.gaxOpts === null || config.gaxOpts === undefined
|
|
136
|
+
? {}
|
|
137
|
+
: config.gaxOpts,
|
|
138
|
+
headers: this.resourceHeader_,
|
|
139
|
+
}, callback);
|
|
140
|
+
}
|
|
141
|
+
delete(optionsOrCallback, cb) {
|
|
142
|
+
const config = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
143
|
+
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
144
|
+
const reqOpts = {
|
|
145
|
+
name: this.formattedName_,
|
|
146
|
+
etag: config.etag,
|
|
147
|
+
validateOnly: config.validateOnly,
|
|
148
|
+
};
|
|
149
|
+
// etag/validateOnly need not be passed in if null or undefined.
|
|
150
|
+
if (reqOpts.etag === null || reqOpts.etag === undefined)
|
|
151
|
+
delete reqOpts.etag;
|
|
152
|
+
if (reqOpts.validateOnly === null || reqOpts.etag === undefined)
|
|
153
|
+
delete reqOpts.validateOnly;
|
|
154
|
+
this.request({
|
|
155
|
+
client: 'InstanceAdminClient',
|
|
156
|
+
method: 'deleteInstanceConfig',
|
|
157
|
+
reqOpts,
|
|
158
|
+
gaxOpts: config.gaxOpts === null || config.gaxOpts === undefined
|
|
159
|
+
? {}
|
|
160
|
+
: config.gaxOpts,
|
|
161
|
+
headers: this.resourceHeader_,
|
|
162
|
+
}, (err, resp) => {
|
|
163
|
+
if (!err) {
|
|
164
|
+
this.parent.instanceConfigs_.delete(this.id);
|
|
165
|
+
}
|
|
166
|
+
callback(err, resp);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
async exists() {
|
|
170
|
+
try {
|
|
171
|
+
// Attempt to read metadata to determine whether instance config exists
|
|
172
|
+
await this.get();
|
|
173
|
+
// Found, therefore it exists
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
if (err.code === google_gax_1.grpc.status.NOT_FOUND) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
// Some other error occurred, rethrow
|
|
181
|
+
throw err;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Format the instance config name to include the project ID.
|
|
186
|
+
*
|
|
187
|
+
* @private
|
|
188
|
+
*
|
|
189
|
+
* @param {string} projectId The project ID.
|
|
190
|
+
* @param {string} name The instance config name.
|
|
191
|
+
* @returns {string}
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```
|
|
195
|
+
* InstanceConfig.formatName_('grape-spaceship-123', 'my-instance-config');
|
|
196
|
+
* // 'projects/grape-spaceship-123/instanceConfigs/my-instance-config'
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
static formatName_(projectId, name) {
|
|
200
|
+
if (name.indexOf('/') > -1) {
|
|
201
|
+
return name;
|
|
202
|
+
}
|
|
203
|
+
const instanceConfigName = name.split('/').pop();
|
|
204
|
+
return 'projects/' + projectId + '/instanceConfigs/' + instanceConfigName;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.InstanceConfig = InstanceConfig;
|
|
208
|
+
/*! Developer Documentation
|
|
209
|
+
*
|
|
210
|
+
* All async methods (except for streams) will return a Promise in the event
|
|
211
|
+
* that a callback is omitted.
|
|
212
|
+
*/
|
|
213
|
+
(0, promisify_1.promisifyAll)(InstanceConfig, {
|
|
214
|
+
exclude: ['exists'],
|
|
215
|
+
});
|
|
216
|
+
//# sourceMappingURL=instance-config.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@google-cloud/spanner",
|
|
3
3
|
"description": "Cloud Spanner Client Library for Node.js",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.3.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Google Inc.",
|
|
7
7
|
"engines": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@google-cloud/common": "^4.0.0",
|
|
54
|
-
"@google-cloud/precise-date": "^
|
|
54
|
+
"@google-cloud/precise-date": "^3.0.0",
|
|
55
55
|
"@google-cloud/projectify": "^3.0.0",
|
|
56
56
|
"@google-cloud/promisify": "^3.0.0",
|
|
57
57
|
"@grpc/proto-loader": "^0.7.0",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"events-intercept": "^2.0.0",
|
|
65
65
|
"extend": "^3.0.2",
|
|
66
66
|
"google-auth-library": "^8.0.2",
|
|
67
|
-
"google-gax": "^3.0
|
|
67
|
+
"google-gax": "^3.3.0",
|
|
68
68
|
"grpc-gcp": "^1.0.0",
|
|
69
69
|
"is": "^3.2.1",
|
|
70
70
|
"lodash.snakecase": "^4.1.1",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"jsdoc": "^3.6.2",
|
|
103
103
|
"jsdoc-fresh": "^2.0.0",
|
|
104
104
|
"jsdoc-region-tag": "^2.0.0",
|
|
105
|
-
"linkinator": "^
|
|
105
|
+
"linkinator": "^4.0.0",
|
|
106
106
|
"lodash.random": "^3.2.0",
|
|
107
107
|
"mocha": "^9.2.2",
|
|
108
108
|
"mv": "^2.1.1",
|