@google-cloud/spanner 7.18.0 → 7.19.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 +30 -0
- package/README.md +1 -0
- package/build/protos/google/spanner/admin/database/v1/backup.proto +773 -0
- package/build/protos/google/spanner/admin/database/v1/backup_schedule.proto +230 -0
- package/build/protos/google/spanner/admin/database/v1/common.proto +132 -0
- package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +1279 -0
- package/build/protos/google/spanner/admin/instance/v1/common.proto +64 -0
- package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +2110 -0
- package/build/protos/google/spanner/executor/v1/cloud_executor.proto +1520 -0
- package/build/protos/google/spanner/v1/commit_response.proto +59 -0
- package/build/protos/google/spanner/v1/keys.proto +163 -0
- package/build/protos/google/spanner/v1/mutation.proto +107 -0
- package/build/protos/google/spanner/v1/query_plan.proto +128 -0
- package/build/protos/google/spanner/v1/result_set.proto +237 -0
- package/build/protos/google/spanner/v1/spanner.proto +1389 -0
- package/build/protos/google/spanner/v1/transaction.proto +622 -0
- package/build/protos/google/spanner/v1/type.proto +214 -0
- package/build/protos/protos.d.ts +39869 -0
- package/build/protos/protos.js +101659 -0
- package/build/protos/protos.json +10391 -0
- package/build/src/backup.d.ts +349 -0
- package/build/src/backup.js +246 -0
- package/build/src/batch-transaction.d.ts +247 -0
- package/build/src/batch-transaction.js +384 -0
- package/build/src/codec.d.ts +362 -0
- package/build/src/codec.js +791 -0
- package/build/src/common-grpc/service-object.d.ts +80 -0
- package/build/src/common-grpc/service-object.js +101 -0
- package/build/src/common-grpc/service.d.ts +445 -0
- package/build/src/common-grpc/service.js +826 -0
- package/build/src/common.d.ts +66 -0
- package/build/src/common.js +54 -0
- package/build/src/database.d.ts +2103 -0
- package/build/src/database.js +1660 -0
- package/build/src/extra_proto_list.json +1 -0
- package/build/src/helper.d.ts +45 -0
- package/build/src/helper.js +71 -0
- package/build/src/index.d.ts +1195 -0
- package/build/src/index.js +1059 -0
- package/build/src/instance-config.d.ts +294 -0
- package/build/src/instance-config.js +216 -0
- package/build/src/instance.d.ts +832 -0
- package/build/src/instance.js +781 -0
- package/build/src/instrument.d.ts +85 -0
- package/build/src/instrument.js +215 -0
- package/build/src/multiplexed-session.d.ts +135 -0
- package/build/src/multiplexed-session.js +194 -0
- package/build/src/partial-result-stream.d.ts +253 -0
- package/build/src/partial-result-stream.js +400 -0
- package/build/src/request_id_header.d.ts +41 -0
- package/build/src/request_id_header.js +138 -0
- package/build/src/session-factory.d.ts +115 -0
- package/build/src/session-factory.js +106 -0
- package/build/src/session-pool.d.ts +471 -0
- package/build/src/session-pool.js +765 -0
- package/build/src/session.d.ts +258 -0
- package/build/src/session.js +348 -0
- package/build/src/spanner_grpc_config.json +92 -0
- package/build/src/table.d.ts +831 -0
- package/build/src/table.js +277 -0
- package/build/src/transaction-runner.d.ts +185 -0
- package/build/src/transaction-runner.js +282 -0
- package/build/src/transaction.d.ts +1691 -0
- package/build/src/transaction.js +2003 -0
- package/build/src/v1/database_admin_client.d.ts +2332 -0
- package/build/src/v1/database_admin_client.js +2364 -0
- package/build/src/v1/database_admin_client_config.json +165 -0
- package/build/src/v1/database_admin_proto_list.json +6 -0
- package/build/src/v1/gapic_metadata.json +27 -0
- package/build/src/v1/index.d.ts +4 -0
- package/build/src/v1/index.js +29 -0
- package/build/src/v1/instance_admin_client.d.ts +1985 -0
- package/build/src/v1/instance_admin_client.js +1768 -0
- package/build/src/v1/instance_admin_client_config.json +129 -0
- package/build/src/v1/instance_admin_proto_list.json +4 -0
- package/build/src/v1/spanner_client.d.ts +1250 -0
- package/build/src/v1/spanner_client.js +1086 -0
- package/build/src/v1/spanner_client_config.json +119 -0
- package/build/src/v1/spanner_executor_proxy_client.d.ts +418 -0
- package/build/src/v1/spanner_executor_proxy_client.js +706 -0
- package/build/src/v1/spanner_executor_proxy_client_config.json +30 -0
- package/build/src/v1/spanner_executor_proxy_proto_list.json +14 -0
- package/build/src/v1/spanner_proto_list.json +10 -0
- package/package.json +1 -1
|
@@ -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 type IOperation = instanceAdmin.longrunning.IOperation;
|
|
22
|
+
export type CreateInstanceConfigCallback = LongRunningCallback<InstanceConfig>;
|
|
23
|
+
export type SetInstanceConfigMetadataCallback = ResourceCallback<GaxOperation, IOperation>;
|
|
24
|
+
export type DeleteInstanceConfigCallback = NormalCallback<instanceAdmin.protobuf.IEmpty>;
|
|
25
|
+
export type ExistsInstanceConfigCallback = NormalCallback<boolean>;
|
|
26
|
+
export type CreateInstanceConfigResponse = [
|
|
27
|
+
InstanceConfig,
|
|
28
|
+
GaxOperation,
|
|
29
|
+
IOperation
|
|
30
|
+
];
|
|
31
|
+
export type SetInstanceConfigMetadataResponse = [GaxOperation, IOperation];
|
|
32
|
+
export type DeleteInstanceConfigResponse = [instanceAdmin.protobuf.IEmpty];
|
|
33
|
+
export type ExistsInstanceConfigResponse = boolean;
|
|
34
|
+
export 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
|