@google-cloud/spanner 7.18.0 → 7.18.1

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.
Files changed (82) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +1 -0
  3. package/build/protos/google/spanner/admin/database/v1/backup.proto +757 -0
  4. package/build/protos/google/spanner/admin/database/v1/backup_schedule.proto +230 -0
  5. package/build/protos/google/spanner/admin/database/v1/common.proto +132 -0
  6. package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +1209 -0
  7. package/build/protos/google/spanner/admin/instance/v1/common.proto +64 -0
  8. package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +2110 -0
  9. package/build/protos/google/spanner/executor/v1/cloud_executor.proto +1520 -0
  10. package/build/protos/google/spanner/v1/commit_response.proto +59 -0
  11. package/build/protos/google/spanner/v1/keys.proto +163 -0
  12. package/build/protos/google/spanner/v1/mutation.proto +107 -0
  13. package/build/protos/google/spanner/v1/query_plan.proto +128 -0
  14. package/build/protos/google/spanner/v1/result_set.proto +237 -0
  15. package/build/protos/google/spanner/v1/spanner.proto +1389 -0
  16. package/build/protos/google/spanner/v1/transaction.proto +575 -0
  17. package/build/protos/google/spanner/v1/type.proto +214 -0
  18. package/build/protos/protos.d.ts +39317 -0
  19. package/build/protos/protos.js +100360 -0
  20. package/build/protos/protos.json +10271 -0
  21. package/build/src/backup.d.ts +349 -0
  22. package/build/src/backup.js +246 -0
  23. package/build/src/batch-transaction.d.ts +247 -0
  24. package/build/src/batch-transaction.js +384 -0
  25. package/build/src/codec.d.ts +362 -0
  26. package/build/src/codec.js +791 -0
  27. package/build/src/common-grpc/service-object.d.ts +80 -0
  28. package/build/src/common-grpc/service-object.js +101 -0
  29. package/build/src/common-grpc/service.d.ts +445 -0
  30. package/build/src/common-grpc/service.js +826 -0
  31. package/build/src/common.d.ts +66 -0
  32. package/build/src/common.js +54 -0
  33. package/build/src/database.d.ts +2103 -0
  34. package/build/src/database.js +1655 -0
  35. package/build/src/extra_proto_list.json +1 -0
  36. package/build/src/helper.d.ts +45 -0
  37. package/build/src/helper.js +71 -0
  38. package/build/src/index.d.ts +1195 -0
  39. package/build/src/index.js +1059 -0
  40. package/build/src/instance-config.d.ts +294 -0
  41. package/build/src/instance-config.js +216 -0
  42. package/build/src/instance.d.ts +832 -0
  43. package/build/src/instance.js +781 -0
  44. package/build/src/instrument.d.ts +85 -0
  45. package/build/src/instrument.js +215 -0
  46. package/build/src/multiplexed-session.d.ts +136 -0
  47. package/build/src/multiplexed-session.js +197 -0
  48. package/build/src/partial-result-stream.d.ts +253 -0
  49. package/build/src/partial-result-stream.js +400 -0
  50. package/build/src/session-factory.d.ts +100 -0
  51. package/build/src/session-factory.js +93 -0
  52. package/build/src/session-pool.d.ts +471 -0
  53. package/build/src/session-pool.js +754 -0
  54. package/build/src/session.d.ts +258 -0
  55. package/build/src/session.js +348 -0
  56. package/build/src/spanner_grpc_config.json +92 -0
  57. package/build/src/table.d.ts +831 -0
  58. package/build/src/table.js +277 -0
  59. package/build/src/transaction-runner.d.ts +185 -0
  60. package/build/src/transaction-runner.js +282 -0
  61. package/build/src/transaction.d.ts +1691 -0
  62. package/build/src/transaction.js +2004 -0
  63. package/build/src/v1/database_admin_client.d.ts +2301 -0
  64. package/build/src/v1/database_admin_client.js +2286 -0
  65. package/build/src/v1/database_admin_client_config.json +160 -0
  66. package/build/src/v1/database_admin_proto_list.json +6 -0
  67. package/build/src/v1/gapic_metadata.json +27 -0
  68. package/build/src/v1/index.d.ts +4 -0
  69. package/build/src/v1/index.js +29 -0
  70. package/build/src/v1/instance_admin_client.d.ts +1985 -0
  71. package/build/src/v1/instance_admin_client.js +1768 -0
  72. package/build/src/v1/instance_admin_client_config.json +129 -0
  73. package/build/src/v1/instance_admin_proto_list.json +4 -0
  74. package/build/src/v1/spanner_client.d.ts +1250 -0
  75. package/build/src/v1/spanner_client.js +1086 -0
  76. package/build/src/v1/spanner_client_config.json +119 -0
  77. package/build/src/v1/spanner_executor_proxy_client.d.ts +418 -0
  78. package/build/src/v1/spanner_executor_proxy_client.js +706 -0
  79. package/build/src/v1/spanner_executor_proxy_client_config.json +30 -0
  80. package/build/src/v1/spanner_executor_proxy_proto_list.json +14 -0
  81. package/build/src/v1/spanner_proto_list.json +10 -0
  82. package/package.json +1 -1
@@ -0,0 +1,349 @@
1
+ /**
2
+ * Copyright 2020 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
+ import { Instance } from './instance';
16
+ import { IOperation, LongRunningCallback, RequestCallback, ResourceCallback, NormalCallback } from './common';
17
+ import { EnumKey, RequestConfig, TranslateEnumKeys } from '.';
18
+ import { CallOptions, Metadata, Operation as GaxOperation } from 'google-gax';
19
+ import { PreciseDate } from '@google-cloud/precise-date';
20
+ import { google as databaseAdmin } from '../protos/protos';
21
+ import { common as p } from 'protobufjs';
22
+ export type CreateBackupCallback = LongRunningCallback<Backup>;
23
+ export type CopyBackupCallback = LongRunningCallback<Backup>;
24
+ export interface CreateBackupGaxOperation extends GaxOperation {
25
+ metadata: Metadata & databaseAdmin.spanner.admin.database.v1.ICreateBackupMetadata;
26
+ }
27
+ export type CreateBackupResponse = [
28
+ Backup,
29
+ CreateBackupGaxOperation,
30
+ IOperation
31
+ ];
32
+ export interface CreateBackupOptions {
33
+ databasePath: string;
34
+ expireTime: string | number | p.ITimestamp | PreciseDate;
35
+ versionTime?: string | number | p.ITimestamp | PreciseDate;
36
+ encryptionConfig?: databaseAdmin.spanner.admin.database.v1.ICreateBackupEncryptionConfig;
37
+ gaxOptions?: CallOptions;
38
+ }
39
+ export interface CopyBackupGaxOperation extends GaxOperation {
40
+ metadata: Metadata & databaseAdmin.spanner.admin.database.v1.ICopyBackupMetadata;
41
+ }
42
+ export type CopyBackupResponse = [Backup, CopyBackupGaxOperation, IOperation];
43
+ export interface CopyBackupOptions extends databaseAdmin.spanner.admin.database.v1.ICopyBackupRequest {
44
+ gaxOptions?: CallOptions;
45
+ }
46
+ /**
47
+ * IBackup structure with backup state enum translated to string form.
48
+ */
49
+ type IBackupTranslatedEnum = TranslateEnumKeys<databaseAdmin.spanner.admin.database.v1.IBackup, 'state', typeof databaseAdmin.spanner.admin.database.v1.Backup.State>;
50
+ export type GetMetadataResponse = [IBackupTranslatedEnum];
51
+ type GetMetadataCallback = RequestCallback<IBackupTranslatedEnum>;
52
+ type UpdateExpireTimeCallback = RequestCallback<databaseAdmin.spanner.admin.database.v1.IBackup>;
53
+ type DeleteCallback = RequestCallback<databaseAdmin.protobuf.IEmpty>;
54
+ interface BackupRequest {
55
+ (config: RequestConfig, callback: ResourceCallback<GaxOperation, IOperation>): void;
56
+ <T>(config: RequestConfig, callback: RequestCallback<T>): void;
57
+ }
58
+ export type GetStateCallback = NormalCallback<EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Backup.State>>;
59
+ export type GetExpireTimeCallback = NormalCallback<PreciseDate>;
60
+ export type ExistsCallback = NormalCallback<boolean>;
61
+ /**
62
+ * The {@link Backup} class represents a Cloud Spanner backup.
63
+ *
64
+ * Create a `Backup` object to interact with or create a Cloud Spanner backup or copy a backup.
65
+ *
66
+ * @class
67
+ *
68
+ * @example
69
+ * ```
70
+ * const {Spanner} = require('@google-cloud/spanner');
71
+ * const spanner = new Spanner();
72
+ * const instance = spanner.instance('my-instance');
73
+ * const backup = instance.backup('my-backup');
74
+ * ```
75
+ *
76
+ * ```
77
+ * * @example
78
+ * const {Spanner} = require('@google-cloud/spanner');
79
+ * const spanner = new Spanner();
80
+ * const instance = spanner.instance('my-instance');
81
+ * const sourceBackup = instance.backup('my-source-backup');
82
+ * const copyBackup = instance.copyBackup('my-copy-backup', 'my-source-backup');
83
+ * ```
84
+ */
85
+ declare class Backup {
86
+ id: string;
87
+ formattedName_: string;
88
+ instanceFormattedName_: string;
89
+ resourceHeader_: {
90
+ [k: string]: string;
91
+ };
92
+ request: BackupRequest;
93
+ metadata?: databaseAdmin.spanner.admin.database.v1.IBackup;
94
+ sourceName: string | undefined;
95
+ constructor(instance: Instance, name: string, sourceName?: string);
96
+ /**
97
+ * @typedef {object} CreateBackupOptions
98
+ * @property {string} databasePath The database path.
99
+ * @property {string|number|google.protobuf.Timestamp|external:PreciseDate}
100
+ * expireTime The expire time of the backup.
101
+ * @property {string|number|google.protobuf.Timestamp|external:PreciseDate}
102
+ * versionTime Take a backup of the state of the database at this time.
103
+ * @property {google.spanner.admin.database.v1.ICreateBackupEncryptionConfig}
104
+ * encryptionConfig An encryption configuration describing the
105
+ * encryption type and key resources in Cloud KMS to be used to encrypt
106
+ * the backup.
107
+ * @property {object} [gaxOptions] The request configuration options,
108
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
109
+ * for more details.
110
+ */
111
+ /**
112
+ * @typedef {array} CreateBackupResponse
113
+ * @property {Backup} 0 The new {@link Backup}.
114
+ * @property {google.longrunning.Operation} 1 An {@link Operation} object that can be used to check
115
+ * the status of the request.
116
+ * @property {object} 2 The full API response.
117
+ */
118
+ /**
119
+ * @callback CreateBackupCallback
120
+ * @param {?Error} err Request error, if any.
121
+ * @param {Backup} backup The new {@link Backup}.
122
+ * @param {google.longrunning.Operation} operation An {@link Operation} object that can be used to
123
+ * check the status of the request.
124
+ * @param {object} apiResponse The full API response.
125
+ */
126
+ /**
127
+ * Create a backup.
128
+ *
129
+ * @method Backup#create
130
+ * @param {CreateBackupOptions} options Parameters for creating a backup.
131
+ * @param {CallOptions} [options.gaxOptions] The request configuration
132
+ * options, See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
133
+ * for more details.
134
+ * @param {CreateBackupCallback} [callback] Callback function.
135
+ * @returns {Promise<CreateBackupResponse>} When resolved, the backup
136
+ * operation will have started, but will not have necessarily completed.
137
+ *
138
+ * @example
139
+ * ```
140
+ * const {Spanner} = require('@google-cloud/spanner');
141
+ * const spanner = new Spanner();
142
+ * const instance = spanner.instance('my-instance');
143
+ * const oneDay = 1000 * 60 * 60 * 24;
144
+ * const expireTime = Date.now() + oneDay;
145
+ * const versionTime = Date.now() - oneDay;
146
+ * const backup = instance.backup('my-backup');
147
+ * const [, backupOperation] = await backup.create({
148
+ * databasePath: 'projects/my-project/instances/my-instance/databases/my-database',
149
+ * expireTime: expireTime,
150
+ * versionTime: versionTime,
151
+ * encryptionConfig: {
152
+ * encryptionType: 'CUSTOMER_MANAGED_ENCRYPTION',
153
+ * kmsKeyName: 'projects/my-project-id/my-region/keyRings/my-key-ring/cryptoKeys/my-key',
154
+ * },
155
+ * });
156
+ * // Await completion of the backup operation.
157
+ * await backupOperation.promise();
158
+ * ```
159
+ */
160
+ create(options: CreateBackupOptions | CopyBackupOptions): Promise<CreateBackupResponse> | Promise<CopyBackupResponse>;
161
+ create(options: CreateBackupOptions | CopyBackupOptions, callback: CreateBackupCallback | CopyBackupCallback): void;
162
+ /**
163
+ * @typedef {array} GetMetadataResponse
164
+ * @property {object} 0 The {@link Backup} metadata.
165
+ * @property {object} 1 The full API response.
166
+ */
167
+ /**
168
+ * @callback GetMetadataCallback
169
+ * @param {?Error} err Request error, if any.
170
+ * @param {object} metadata The {@link Backup} metadata.
171
+ * @param {object} apiResponse The full API response.
172
+ */
173
+ /**
174
+ * Retrieves backup's metadata.
175
+ *
176
+ * @see {@link #getState}
177
+ * @see {@link #getExpireTime}
178
+ *
179
+ * @method Backup#getMetadata
180
+ * @param {object} [gaxOptions] Request configuration options,
181
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
182
+ * for more details.
183
+ * @param {GetMetadataCallback} [callback] Callback function.
184
+ * @returns {Promise<GetMetadataResponse>}
185
+ *
186
+ * @example
187
+ * ```
188
+ * const {Spanner} = require('@google-cloud/spanner');
189
+ * const spanner = new Spanner();
190
+ * const instance = spanner.instance('my-instance');
191
+ * const backup = instance.backup('my-backup');
192
+ * const [backupInfo] = await backup.getMetadata();
193
+ * console.log(`${backupInfo.name}: size=${backupInfo.sizeBytes}`);
194
+ * ```
195
+ */
196
+ getMetadata(gaxOptions?: CallOptions): Promise<GetMetadataResponse>;
197
+ getMetadata(callback: GetMetadataCallback): void;
198
+ getMetadata(gaxOptions: CallOptions, callback: GetMetadataCallback): void;
199
+ /**
200
+ * Retrieves the state of the backup.
201
+ *
202
+ * The backup state indicates if the backup has completed.
203
+ *
204
+ * @see {@link #getMetadata}
205
+ *
206
+ * @method Backup#getState
207
+ * @param {GetStateCallback} [callback] Callback function.
208
+ * @returns {Promise<EnumKey<typeof, databaseAdmin.spanner.admin.database.v1.Backup.State> | undefined>}
209
+ * When resolved, contains the current state of the backup if it exists.
210
+ *
211
+ * @example
212
+ * ```
213
+ * const {Spanner} = require('@google-cloud/spanner');
214
+ * const spanner = new Spanner();
215
+ * const instance = spanner.instance('my-instance');
216
+ * const backup = instance.backup('my-backup');
217
+ * const state = await backup.getState();
218
+ * const backupCompleted = (state === 'READY');
219
+ * ```
220
+ */
221
+ getState(): Promise<EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Backup.State> | undefined | null>;
222
+ getState(callback: GetStateCallback): void;
223
+ /**
224
+ * Retrieves the expiry time of the backup.
225
+ *
226
+ * @see {@link #updateExpireTime}
227
+ * @see {@link #getMetadata}
228
+ *
229
+ * @method Backup#getExpireTime
230
+ * @returns {Promise<external:PreciseDate>} When resolved, contains the
231
+ * current expire time of the backup if it exists.
232
+ *
233
+ * @example
234
+ * ```
235
+ * const {Spanner} = require('@google-cloud/spanner');
236
+ * const spanner = new Spanner();
237
+ * const instance = spanner.instance('my-instance');
238
+ * const backup = instance.backup('my-backup');
239
+ * const expireTime = await backup.getExpireTime();
240
+ * console.log(`Backup expires on ${expireTime.toISOString()}`);
241
+ * ```
242
+ */
243
+ getExpireTime(): Promise<PreciseDate | undefined>;
244
+ getExpireTime(callback: GetExpireTimeCallback): void;
245
+ /**
246
+ * Checks whether the backup exists.
247
+ *
248
+ * @see {@link #getMetadata}
249
+ *
250
+ * @method Backup#exists
251
+ * @returns {Promise<boolean>} When resolved, contains true if the backup
252
+ * exists and false if it does not exist.
253
+ *
254
+ * @example
255
+ * ```
256
+ * const {Spanner} = require('@google-cloud/spanner');
257
+ * const spanner = new Spanner();
258
+ * const instance = spanner.instance('my-instance');
259
+ * const backup = instance.backup('my-backup');
260
+ * const alreadyExists = await backup.exists();
261
+ * console.log(`Does backup exist? ${alreadyExists}`);
262
+ * ```
263
+ */
264
+ exists(): Promise<boolean>;
265
+ exists(callback: ExistsCallback): void;
266
+ /**
267
+ * @callback UpdateExpireTimeCallback
268
+ * @param {?Error} err Request error, if any.
269
+ * @param {google.spanner.admin.database.v1.IBackup} backup The updated
270
+ * backup.
271
+ */
272
+ /**
273
+ * Sets the expiry time of a backup.
274
+ *
275
+ * @see {@link #getExpireTime}
276
+ *
277
+ * @method Backup#updateExpireTime
278
+ * @param {string|number|google.protobuf.Timestamp|external:PreciseDate}
279
+ * expireTime The expiry time to update with.
280
+ * @param {object} [gaxOptions] Request configuration options,
281
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
282
+ * for more details.
283
+ * @param {UpdateExpireTimeCallback} [callback] Callback function.
284
+ * @returns {Promise<google.spanner.admin.database.v1.IBackup>} When resolved,
285
+ * the backup's expire time will have been updated.
286
+ *
287
+ * @example
288
+ * ```
289
+ * const {Spanner} = require('@google-cloud/spanner');
290
+ * const spanner = new Spanner();
291
+ * const instance = spanner.instance('my-instance');
292
+ * const backup = instance.backup('my-backup');
293
+ * const oneDay = 1000 * 60 * 60 * 24;
294
+ * const newExpireTime = Spanner.timestamp(Date.now() + oneDay);
295
+ * await backup.updateExpireTime(newExpireTime);
296
+ * ```
297
+ */
298
+ updateExpireTime(expireTime: string | number | p.ITimestamp | PreciseDate): Promise<databaseAdmin.spanner.admin.database.v1.IBackup>;
299
+ updateExpireTime(expireTime: string | number | p.ITimestamp | PreciseDate, gaxOptions?: CallOptions): Promise<databaseAdmin.spanner.admin.database.v1.IBackup>;
300
+ updateExpireTime(expireTime: string | number | p.ITimestamp | PreciseDate, callback: UpdateExpireTimeCallback): void;
301
+ updateExpireTime(expireTime: string | number | p.ITimestamp | PreciseDate, gaxOptions: CallOptions, callback: UpdateExpireTimeCallback): void;
302
+ /**
303
+ * Deletes a backup.
304
+ *
305
+ * @method Backup#delete
306
+ * @param {object} [gaxOptions] Request configuration options,
307
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
308
+ * for more details.
309
+ * @param {DeleteBackupCallback} [callback] Callback function.
310
+ * @returns {Promise<void>} When resolved, the backup will have been deleted.
311
+ *
312
+ * @example
313
+ * ```
314
+ * const {Spanner} = require('@google-cloud/spanner');
315
+ * const spanner = new Spanner();
316
+ * const instance = spanner.instance('my-instance');
317
+ * const backup = instance.backup('my-backup');
318
+ * await backup.delete();
319
+ * ```
320
+ */
321
+ delete(gaxOptions?: CallOptions): Promise<databaseAdmin.protobuf.IEmpty>;
322
+ delete(callback: DeleteCallback): void;
323
+ delete(gaxOptions: CallOptions, callback: DeleteCallback): void;
324
+ /**
325
+ * Format the backup name to include the instance name.
326
+ *
327
+ * @private
328
+ *
329
+ * @param {string} instanceName The formatted instance name.
330
+ * @param {string} name The table name.
331
+ * @returns {string}
332
+ *
333
+ * @example
334
+ * ```
335
+ * Backup.formatName_(
336
+ * 'projects/grape-spaceship-123/instances/my-instance',
337
+ * 'my-backup'
338
+ * );
339
+ * // 'projects/grape-spaceship-123/instances/my-instance/backups/my-backup'
340
+ * ```
341
+ */
342
+ static formatName_(instanceName: string, name: string): string;
343
+ }
344
+ /**
345
+ * Reference to the {@link Backup} class.
346
+ * @name module:@google-cloud/spanner.Backup
347
+ * @see Backup
348
+ */
349
+ export { Backup };
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2020 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.Backup = void 0;
18
+ const promisify_1 = require("@google-cloud/promisify");
19
+ const common_1 = require("./common");
20
+ const _1 = require(".");
21
+ const google_gax_1 = require("google-gax");
22
+ const precise_date_1 = require("@google-cloud/precise-date");
23
+ /**
24
+ * The {@link Backup} class represents a Cloud Spanner backup.
25
+ *
26
+ * Create a `Backup` object to interact with or create a Cloud Spanner backup or copy a backup.
27
+ *
28
+ * @class
29
+ *
30
+ * @example
31
+ * ```
32
+ * const {Spanner} = require('@google-cloud/spanner');
33
+ * const spanner = new Spanner();
34
+ * const instance = spanner.instance('my-instance');
35
+ * const backup = instance.backup('my-backup');
36
+ * ```
37
+ *
38
+ * ```
39
+ * * @example
40
+ * const {Spanner} = require('@google-cloud/spanner');
41
+ * const spanner = new Spanner();
42
+ * const instance = spanner.instance('my-instance');
43
+ * const sourceBackup = instance.backup('my-source-backup');
44
+ * const copyBackup = instance.copyBackup('my-copy-backup', 'my-source-backup');
45
+ * ```
46
+ */
47
+ class Backup {
48
+ constructor(instance, name, sourceName) {
49
+ this.request = instance.request;
50
+ this.instanceFormattedName_ = instance.formattedName_;
51
+ this.formattedName_ = Backup.formatName_(instance.formattedName_, name);
52
+ this.id = this.formattedName_.split('/').pop() || '';
53
+ this.sourceName = sourceName;
54
+ this.resourceHeader_ = {
55
+ [common_1.CLOUD_RESOURCE_HEADER]: this.instanceFormattedName_,
56
+ };
57
+ }
58
+ create(options, callback) {
59
+ const gaxOpts = options.gaxOptions;
60
+ if ('databasePath' in options) {
61
+ const reqOpts = {
62
+ parent: this.instanceFormattedName_,
63
+ backupId: this.id,
64
+ backup: {
65
+ database: options.databasePath,
66
+ expireTime: _1.Spanner.timestamp(options.expireTime).toStruct(),
67
+ name: this.formattedName_,
68
+ },
69
+ };
70
+ if ('versionTime' in options) {
71
+ reqOpts.backup.versionTime = _1.Spanner.timestamp(options.versionTime).toStruct();
72
+ }
73
+ if ('encryptionConfig' in options &&
74
+ options.encryptionConfig) {
75
+ reqOpts.encryptionConfig = options.encryptionConfig;
76
+ }
77
+ this.request({
78
+ client: 'DatabaseAdminClient',
79
+ method: 'createBackup',
80
+ reqOpts,
81
+ gaxOpts,
82
+ headers: this.resourceHeader_,
83
+ }, (err, operation, resp) => {
84
+ if (err) {
85
+ callback(err, null, null, resp);
86
+ return;
87
+ }
88
+ callback(null, this, operation, resp);
89
+ });
90
+ }
91
+ else if (this.sourceName) {
92
+ delete options.gaxOptions;
93
+ options.backupId = this.id;
94
+ options.parent = this.instanceFormattedName_;
95
+ options.sourceBackup = this.sourceName;
96
+ this.request({
97
+ client: 'DatabaseAdminClient',
98
+ method: 'copyBackup',
99
+ reqOpts: options,
100
+ gaxOpts,
101
+ headers: this.resourceHeader_,
102
+ }, (err, operation, resp) => {
103
+ if (err) {
104
+ callback(err, null, null, resp);
105
+ return;
106
+ }
107
+ callback(null, this, operation, resp);
108
+ });
109
+ }
110
+ }
111
+ getMetadata(gaxOptionsOrCallback, cb) {
112
+ const callback = typeof gaxOptionsOrCallback === 'function'
113
+ ? gaxOptionsOrCallback
114
+ : cb;
115
+ const gaxOpts = typeof gaxOptionsOrCallback === 'object'
116
+ ? gaxOptionsOrCallback
117
+ : {};
118
+ const reqOpts = {
119
+ name: this.formattedName_,
120
+ };
121
+ this.request({
122
+ client: 'DatabaseAdminClient',
123
+ method: 'getBackup',
124
+ reqOpts,
125
+ gaxOpts,
126
+ headers: this.resourceHeader_,
127
+ }, (err, response) => {
128
+ if (response) {
129
+ this.metadata = response;
130
+ }
131
+ callback(err, response);
132
+ });
133
+ }
134
+ async getState() {
135
+ const [backupInfo] = await this.getMetadata();
136
+ return backupInfo.state;
137
+ }
138
+ async getExpireTime() {
139
+ const [backupInfo] = await this.getMetadata();
140
+ return new precise_date_1.PreciseDate(backupInfo.expireTime);
141
+ }
142
+ async exists() {
143
+ try {
144
+ // Attempt to read metadata to determine whether backup exists
145
+ await this.getMetadata();
146
+ // Found therefore it exists
147
+ return true;
148
+ }
149
+ catch (err) {
150
+ if (err.code === google_gax_1.grpc.status.NOT_FOUND) {
151
+ return false;
152
+ }
153
+ // Some other error occurred, rethrow
154
+ throw err;
155
+ }
156
+ }
157
+ updateExpireTime(expireTime, gaxOptionsOrCallback, cb) {
158
+ const callback = typeof gaxOptionsOrCallback === 'function'
159
+ ? gaxOptionsOrCallback
160
+ : cb;
161
+ const gaxOpts = typeof gaxOptionsOrCallback === 'object'
162
+ ? gaxOptionsOrCallback
163
+ : {};
164
+ const reqOpts = {
165
+ backup: {
166
+ name: this.formattedName_,
167
+ expireTime: _1.Spanner.timestamp(expireTime).toStruct(),
168
+ },
169
+ updateMask: {
170
+ paths: ['expire_time'],
171
+ },
172
+ };
173
+ this.request({
174
+ client: 'DatabaseAdminClient',
175
+ method: 'updateBackup',
176
+ reqOpts,
177
+ gaxOpts,
178
+ headers: this.resourceHeader_,
179
+ }, (err, response) => {
180
+ callback(err, response);
181
+ });
182
+ }
183
+ delete(gaxOptionsOrCallback, cb) {
184
+ const callback = typeof gaxOptionsOrCallback === 'function'
185
+ ? gaxOptionsOrCallback
186
+ : cb;
187
+ const gaxOpts = typeof gaxOptionsOrCallback === 'object'
188
+ ? gaxOptionsOrCallback
189
+ : {};
190
+ const reqOpts = {
191
+ name: this.formattedName_,
192
+ };
193
+ this.request({
194
+ client: 'DatabaseAdminClient',
195
+ method: 'deleteBackup',
196
+ reqOpts,
197
+ gaxOpts,
198
+ headers: this.resourceHeader_,
199
+ }, err => {
200
+ callback(err);
201
+ });
202
+ }
203
+ /**
204
+ * Format the backup name to include the instance name.
205
+ *
206
+ * @private
207
+ *
208
+ * @param {string} instanceName The formatted instance name.
209
+ * @param {string} name The table name.
210
+ * @returns {string}
211
+ *
212
+ * @example
213
+ * ```
214
+ * Backup.formatName_(
215
+ * 'projects/grape-spaceship-123/instances/my-instance',
216
+ * 'my-backup'
217
+ * );
218
+ * // 'projects/grape-spaceship-123/instances/my-instance/backups/my-backup'
219
+ * ```
220
+ */
221
+ static formatName_(instanceName, name) {
222
+ if (name.indexOf('/') > -1) {
223
+ return name;
224
+ }
225
+ const backupName = name.split('/').pop();
226
+ return instanceName + '/backups/' + backupName;
227
+ }
228
+ }
229
+ exports.Backup = Backup;
230
+ /*! Developer Documentation
231
+ *
232
+ * All async methods (except for streams) will return a Promise in the event
233
+ * that a callback is omitted.
234
+ */
235
+ (0, promisify_1.promisifyAll)(Backup, {
236
+ exclude: ['getState', 'getExpireTime', 'exists'],
237
+ });
238
+ /*! Developer Documentation
239
+ *
240
+ * All async methods (except for streams) will return a Promise in the event
241
+ * that a callback is omitted.
242
+ */
243
+ (0, promisify_1.callbackifyAll)(Backup, {
244
+ exclude: ['create', 'getMetadata', 'updateExpireTime', 'delete'],
245
+ });
246
+ //# sourceMappingURL=backup.js.map