Compare fe003c0 ... +118 ... 08b7c52

Showing 20 of 113 files from the diff.
Newly tracked file
.mocharc.js changed.
Other files ignored by Codecov
test/instance.ts has changed.
test/database.ts has changed.
synth.metadata has changed.
test/backup.ts has changed.
CHANGELOG.md has changed.
.kokoro/test.sh has changed.
test/spanner.ts has changed.
protos/protos.js has changed.
test/table.ts has changed.
README.md has changed.
src/.eslintrc.yml was deleted.
tsconfig.json has changed.
test/index.ts has changed.
test/codec.ts has changed.
package.json has changed.
.kokoro/docs.sh has changed.
synth.py has changed.
test/session.ts has changed.
samples/crud.js has changed.
samples/README.md has changed.
samples/dml.js has changed.
.kokoro/lint.sh has changed.

@@ -18,7 +18,8 @@
Loading
18 18
 * @module spanner/session
19 19
 */
20 20
21 -
import {GrpcServiceObject} from './common-grpc/service-object';
21 +
// eslint-disable-next-line @typescript-eslint/no-var-requires
22 +
const common = require('./common-grpc/service-object');
22 23
import {promisifyAll} from '@google-cloud/promisify';
23 24
import * as extend from 'extend';
24 25
import * as r from 'teeny-request';
@@ -34,9 +35,9 @@
Loading
34 35
  CreateSessionCallback,
35 36
  CreateSessionOptions,
36 37
} from './database';
37 -
import {ServiceObjectConfig, DeleteCallback} from '@google-cloud/common';
38 -
import {NormalCallback} from './common';
39 -
import {ServiceError} from 'grpc';
38 +
import {ServiceObjectConfig} from '@google-cloud/common';
39 +
import {NormalCallback, CLOUD_RESOURCE_HEADER} from './common';
40 +
import {grpc, CallOptions} from 'google-gax';
40 41
41 42
export type GetSessionResponse = [Session, r.Response];
42 43
@@ -48,14 +49,14 @@
Loading
48 49
  ReadWrite = 'readwrite',
49 50
}
50 51
51 -
export type GetSessionMetadataCallback = NormalCallback<
52 -
  google.spanner.v1.ISession
53 -
>;
52 +
export type GetSessionMetadataCallback = NormalCallback<google.spanner.v1.ISession>;
54 53
export type GetSessionMetadataResponse = [google.spanner.v1.ISession];
55 54
56 55
export type KeepAliveCallback = NormalCallback<google.spanner.v1.IResultSet>;
57 56
export type KeepAliveResponse = [google.spanner.v1.IResultSet];
58 -
export type DeleteResponse = [r.Response];
57 +
export type DeleteSessionResponse = [google.protobuf.IEmpty];
58 +
export type DeleteSessionCallback = NormalCallback<google.protobuf.IEmpty>;
59 +
59 60
/**
60 61
 * Create a Session object to interact with a Cloud Spanner session.
61 62
 *
@@ -94,13 +95,14 @@
Loading
94 95
 * //-
95 96
 * const session = database.session('session-name');
96 97
 */
97 -
export class Session extends GrpcServiceObject {
98 +
export class Session extends common.GrpcServiceObject {
98 99
  id!: string;
99 100
  formattedName_?: string;
100 101
  type?: types;
101 102
  txn?: Transaction;
102 103
  lastUsed?: number;
103 -
  lastError?: ServiceError;
104 +
  lastError?: grpc.ServiceError;
105 +
  resourceHeader_: {[k: string]: string};
104 106
  constructor(database: Database, name?: string) {
105 107
    const methods = {
106 108
      /**
@@ -231,15 +233,19 @@
Loading
231 233
      },
232 234
    } as {}) as ServiceObjectConfig);
233 235
236 +
    this.resourceHeader_ = {
237 +
      [CLOUD_RESOURCE_HEADER]: (this.parent as Database).formattedName_,
238 +
    };
234 239
    this.request = database.request;
235 240
    this.requestStream = database.requestStream;
236 241
237 242
    if (name) {
238 243
      this.formattedName_ = Session.formatName_(database.formattedName_, name);
239 244
    }
240 245
  }
241 -
  delete(): Promise<DeleteResponse>;
242 -
  delete(callback: DeleteCallback): void;
246 +
  delete(gaxOptions?: CallOptions): Promise<DeleteSessionResponse>;
247 +
  delete(callback: DeleteSessionCallback): void;
248 +
  delete(gaxOptions: CallOptions, callback: DeleteSessionCallback): void;
243 249
  /**
244 250
   * Delete a session.
245 251
   *
@@ -248,8 +254,10 @@
Loading
248 254
   * @see {@link v1.SpannerClient#deleteSession}
249 255
   * @see [DeleteSession API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.DeleteSession)
250 256
   *
251 -
   * @param {BasicCallback} [callback] Callback function.
252 -
   * @returns {Promise<BasicResponse>}
257 +
   * @param {object} [gaxOptions] Request configuration options, outlined here:
258 +
   *     https://googleapis.github.io/gax-nodejs/classes/CallSettings.html.
259 +
   * @param {DeleteSessionCallback} [callback] Callback function.
260 +
   * @returns {Promise<DeleteSessionResponse>}
253 261
   *
254 262
   * @example
255 263
   * session.delete(function(err, apiResponse) {
@@ -267,7 +275,15 @@
Loading
267 275
   *   const apiResponse = data[0];
268 276
   * });
269 277
   */
270 -
  delete(callback?: DeleteCallback): void | Promise<DeleteResponse> {
278 +
  delete(
279 +
    optionsOrCallback?: CallOptions | DeleteSessionCallback,
280 +
    cb?: DeleteSessionCallback
281 +
  ): void | Promise<DeleteSessionResponse> {
282 +
    const gaxOpts =
283 +
      typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
284 +
    const callback =
285 +
      typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;
286 +
271 287
    const reqOpts = {
272 288
      name: this.formattedName_,
273 289
    };
@@ -276,12 +292,18 @@
Loading
276 292
        client: 'SpannerClient',
277 293
        method: 'deleteSession',
278 294
        reqOpts,
295 +
        gaxOpts,
296 +
        headers: this.resourceHeader_,
279 297
      },
280 298
      callback!
281 299
    );
282 300
  }
283 -
  getMetadata(): Promise<GetSessionMetadataResponse>;
301 +
  getMetadata(gaxOptions?: CallOptions): Promise<GetSessionMetadataResponse>;
284 302
  getMetadata(callback: GetSessionMetadataCallback): void;
303 +
  getMetadata(
304 +
    gaxOptions: CallOptions,
305 +
    callback: GetSessionMetadataCallback
306 +
  ): void;
285 307
  /**
286 308
   * @typedef {array} GetSessionMetadataResponse
287 309
   * @property {object} 0 The session's metadata.
@@ -301,6 +323,8 @@
Loading
301 323
   * @see {@link v1.SpannerClient#getSession}
302 324
   * @see [GetSession API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.GetSession)
303 325
   *
326 +
   * @param {object} [gaxOptions] Request configuration options, outlined here:
327 +
   *     https://googleapis.github.io/gax-nodejs/classes/CallSettings.html.
304 328
   * @param {GetSessionMetadataCallback} [callback] Callback function.
305 329
   * @returns {Promise<GetSessionMetadataResponse>}
306 330
   *
@@ -316,8 +340,14 @@
Loading
316 340
   * });
317 341
   */
318 342
  getMetadata(
319 -
    callback?: GetSessionMetadataCallback
343 +
    optionsOrCallback?: CallOptions | GetSessionMetadataCallback,
344 +
    cb?: GetSessionMetadataCallback
320 345
  ): void | Promise<GetSessionMetadataResponse> {
346 +
    const gaxOpts =
347 +
      typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
348 +
    const callback =
349 +
      typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;
350 +
321 351
    const reqOpts = {
322 352
      name: this.formattedName_,
323 353
    };
@@ -326,15 +356,25 @@
Loading
326 356
        client: 'SpannerClient',
327 357
        method: 'getSession',
328 358
        reqOpts,
359 +
        gaxOpts,
360 +
        headers: this.resourceHeader_,
329 361
      },
330 -
      callback!
362 +
      (err, resp) => {
363 +
        if (resp) {
364 +
          this.metadata = resp;
365 +
        }
366 +
        callback!(err, resp);
367 +
      }
331 368
    );
332 369
  }
333 -
  keepAlive(): Promise<KeepAliveResponse>;
370 +
  keepAlive(gaxOptions?: CallOptions): Promise<KeepAliveResponse>;
334 371
  keepAlive(callback: KeepAliveCallback): void;
372 +
  keepAlive(gaxOptions: CallOptions, callback: KeepAliveCallback): void;
335 373
  /**
336 374
   * Ping the session with `SELECT 1` to prevent it from expiring.
337 375
   *
376 +
   * @param {object} [gaxOptions] Request configuration options, outlined here:
377 +
   *     https://googleapis.github.io/gax-nodejs/classes/CallSettings.html.
338 378
   * @param {BasicCallback} [callback] Callback function.
339 379
   * @returns {Promise<BasicResponse>}
340 380
   *
@@ -345,7 +385,15 @@
Loading
345 385
   *   }
346 386
   * });
347 387
   */
348 -
  keepAlive(callback?: KeepAliveCallback): void | Promise<KeepAliveResponse> {
388 +
  keepAlive(
389 +
    optionsOrCallback?: CallOptions | KeepAliveCallback,
390 +
    cb?: KeepAliveCallback
391 +
  ): void | Promise<KeepAliveResponse> {
392 +
    const gaxOpts =
393 +
      typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
394 +
    const callback =
395 +
      typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;
396 +
349 397
    const reqOpts = {
350 398
      session: this.formattedName_,
351 399
      sql: 'SELECT 1',
@@ -355,6 +403,8 @@
Loading
355 403
        client: 'SpannerClient',
356 404
        method: 'executeSql',
357 405
        reqOpts,
406 +
        gaxOpts,
407 +
        headers: this.resourceHeader_,
358 408
      },
359 409
      callback!
360 410
    );

@@ -15,51 +15,47 @@
Loading
15 15
 */
16 16
17 17
import {GrpcService, GrpcServiceConfig} from './common-grpc/service';
18 -
import {paginator} from '@google-cloud/paginator';
19 18
import {PreciseDate} from '@google-cloud/precise-date';
20 19
import {replaceProjectIdToken} from '@google-cloud/projectify';
21 20
import {promisifyAll} from '@google-cloud/promisify';
22 21
import * as extend from 'extend';
23 22
import {GoogleAuth, GoogleAuthOptions} from 'google-auth-library';
24 -
import * as is from 'is';
25 23
import * as path from 'path';
26 24
import {common as p} from 'protobufjs';
27 25
import * as streamEvents from 'stream-events';
28 26
import * as through from 'through2';
29 -
import {codec, Float, Int, SpannerDate, Struct} from './codec';
27 +
import {codec, Float, Int, Numeric, SpannerDate, Struct} from './codec';
30 28
import {Backup} from './backup';
31 29
import {Database} from './database';
32 30
import {
33 31
  Instance,
34 32
  CreateInstanceCallback,
35 33
  CreateInstanceResponse,
36 34
} from './instance';
35 +
import {grpc, GrpcClientOptions, CallOptions} from 'google-gax';
37 36
import {google as instanceAdmin} from '../protos/protos';
38 -
import {PagedRequest, PagedResponse, PagedCallback} from './common';
37 +
import {
38 +
  PagedOptions,
39 +
  PagedResponse,
40 +
  PagedCallback,
41 +
  PagedOptionsWithFilter,
42 +
  CLOUD_RESOURCE_HEADER,
43 +
} from './common';
39 44
import {Session} from './session';
40 45
import {SessionPool} from './session-pool';
41 46
import {Table} from './table';
42 47
import {PartitionedDml, Snapshot, Transaction} from './transaction';
43 -
import {GrpcClientOptions} from 'google-gax';
44 -
import {ChannelCredentials} from 'grpc';
45 -
import {
46 -
  createGcpApiConfig,
47 -
  gcpCallInvocationTransformer,
48 -
  gcpChannelFactoryOverride,
49 -
} from 'grpc-gcp';
48 +
import grpcGcpModule = require('grpc-gcp');
49 +
const grpcGcp = grpcGcpModule(grpc);
50 50
import * as v1 from './v1';
51 -
import * as grpc from 'grpc';
52 51
53 52
// eslint-disable-next-line @typescript-eslint/no-var-requires
54 53
const gcpApiConfig = require('./spanner_grpc_config.json');
55 54
56 55
export type IOperation = instanceAdmin.longrunning.IOperation;
57 56
58 -
export type GetInstancesRequest = PagedRequest<
59 -
  instanceAdmin.spanner.admin.instance.v1.IListInstancesRequest & {
60 -
    maxResults?: number;
61 -
  }
62 -
>;
57 +
export type GetInstancesOptions = PagedOptionsWithFilter;
58 +
63 59
export type GetInstancesResponse = PagedResponse<
64 60
  Instance,
65 61
  instanceAdmin.spanner.admin.instance.v1.IListInstancesResponse
@@ -69,37 +65,36 @@
Loading
69 65
  instanceAdmin.spanner.admin.instance.v1.IListInstancesResponse
70 66
>;
71 67
72 -
export type GetInstanceConfigsRequest = PagedRequest<
73 -
  instanceAdmin.spanner.admin.instance.v1.IListInstanceConfigsRequest & {
74 -
    maxResults?: number;
75 -
  }
76 -
>;
68 +
export type GetInstanceConfigsOptions = PagedOptions;
77 69
export type GetInstanceConfigsResponse = PagedResponse<
78 -
  instanceAdmin.spanner.admin.instance.v1.InstanceConfig,
70 +
  instanceAdmin.spanner.admin.instance.v1.IInstanceConfig,
79 71
  instanceAdmin.spanner.admin.instance.v1.IListInstanceConfigsResponse
80 72
>;
81 73
export type GetInstanceConfigsCallback = PagedCallback<
82 -
  instanceAdmin.spanner.admin.instance.v1.InstanceConfig,
74 +
  instanceAdmin.spanner.admin.instance.v1.IInstanceConfig,
83 75
  instanceAdmin.spanner.admin.instance.v1.IListInstanceConfigsResponse
84 76
>;
85 77
86 78
export interface SpannerOptions extends GrpcClientOptions {
87 79
  apiEndpoint?: string;
88 80
  servicePath?: string;
89 81
  port?: number;
90 -
  sslCreds?: ChannelCredentials;
82 +
  sslCreds?: grpc.ChannelCredentials;
91 83
}
92 84
export interface RequestConfig {
93 85
  client: string;
94 86
  method: string;
95 87
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
96 88
  reqOpts: any;
97 -
  gaxOpts?: {};
89 +
  gaxOpts?: CallOptions;
90 +
  headers: {[k: string]: string};
98 91
}
99 92
export interface CreateInstanceRequest {
100 -
  config: string;
93 +
  config?: string;
101 94
  nodes?: number;
95 +
  displayName?: string;
102 96
  labels?: {[k: string]: string} | null;
97 +
  gaxOptions?: CallOptions;
103 98
}
104 99
/**
105 100
 * Translates enum values to string keys.
@@ -161,7 +156,8 @@
Loading
161 156
  auth: GoogleAuth;
162 157
  clients_: Map<string, {}>;
163 158
  instances_: Map<string, Instance>;
164 -
  getInstancesStream: Function;
159 +
  projectFormattedName_: string;
160 +
  resourceHeader_: {[k: string]: string};
165 161
166 162
  /**
167 163
   * Placeholder used to auto populate a column with the commit timestamp.
@@ -225,9 +221,9 @@
Loading
225 221
        libVersion: require('../../package.json').version,
226 222
        scopes,
227 223
        // Enable grpc-gcp support
228 -
        'grpc.callInvocationTransformer': gcpCallInvocationTransformer,
229 -
        'grpc.channelFactoryOverride': gcpChannelFactoryOverride,
230 -
        'grpc.gcpApiConfig': createGcpApiConfig(gcpApiConfig),
224 +
        'grpc.callInvocationTransformer': grpcGcp.gcpCallInvocationTransformer,
225 +
        'grpc.channelFactoryOverride': grpcGcp.gcpChannelFactoryOverride,
226 +
        'grpc.gcpApiConfig': grpcGcp.createGcpApiConfig(gcpApiConfig),
231 227
        grpc,
232 228
      },
233 229
      options || {}
@@ -262,43 +258,10 @@
Loading
262 258
    this.auth = new GoogleAuth(this.options);
263 259
    this.clients_ = new Map();
264 260
    this.instances_ = new Map();
265 -
266 -
    /**
267 -
     * Get a list of {@link Instance} objects as a readable object stream.
268 -
     *
269 -
     * Wrapper around {@link v1.InstanceAdminClient#listInstances}.
270 -
     *
271 -
     * @see {@link v1.InstanceAdminClient#listInstances}
272 -
     * @see [ListInstances API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.ListInstances)
273 -
     *
274 -
     * @method Spanner#getInstancesStream
275 -
     * @param {GetInstancesRequest} [query] Query object for listing instances.
276 -
     * @returns {ReadableStream} A readable stream that emits {@link Instance}
277 -
     *     instances.
278 -
     *
279 -
     * @example
280 -
     * const {Spanner} = require('@google-cloud/spanner');
281 -
     * const spanner = new Spanner();
282 -
     *
283 -
     * spanner.getInstancesStream()
284 -
     *   .on('error', console.error)
285 -
     *   .on('data', function(instance) {
286 -
     *     // `instance` is an `Instance` object.
287 -
     *   })
288 -
     *   .on('end', function() {
289 -
     *     // All instances retrieved.
290 -
     *   });
291 -
     *
292 -
     * //-
293 -
     * // If you anticipate many results, you can end a stream early to prevent
294 -
     * // unnecessary processing and API requests.
295 -
     * //-
296 -
     * spanner.getInstancesStream()
297 -
     *   .on('data', function(instance) {
298 -
     *     this.end();
299 -
     *   });
300 -
     */
301 -
    this.getInstancesStream = paginator.streamify('getInstances');
261 +
    this.projectFormattedName_ = 'projects/' + this.projectId;
262 +
    this.resourceHeader_ = {
263 +
      [CLOUD_RESOURCE_HEADER]: this.projectFormattedName_,
264 +
    };
302 265
  }
303 266
304 267
  createInstance(
@@ -324,6 +287,11 @@
Loading
324 287
   *     be used to control how resource metrics are aggregated. And they can
325 288
   *     be used as arguments to policy management rules (e.g. route,
326 289
   *     firewall, load balancing, etc.).
290 +
   * @property {string} [displayName] The descriptive name for this instance
291 +
   *     as it appears in UIs. Must be unique per project and between 4 and 30
292 +
   *     characters in length.
293 +
   *     Defaults to the instance unique identifier '<instance>' of the full
294 +
   *     instance name of the form 'projects/<project>/instances/<instance>'.
327 295
   */
328 296
  /**
329 297
   * @typedef {array} CreateInstanceResponse
@@ -406,30 +374,33 @@
Loading
406 374
      );
407 375
    }
408 376
    const formattedName = Instance.formatName_(this.projectId, name);
409 -
    const shortName = formattedName.split('/').pop();
377 +
    const displayName = config.displayName || formattedName.split('/').pop();
410 378
    const reqOpts = {
411 -
      parent: 'projects/' + this.projectId,
412 -
      instanceId: shortName,
379 +
      parent: this.projectFormattedName_,
380 +
      instanceId: formattedName.split('/').pop(),
413 381
      instance: extend(
414 382
        {
415 383
          name: formattedName,
416 -
          displayName: shortName,
384 +
          displayName,
417 385
          nodeCount: config.nodes || 1,
418 386
        },
419 387
        config
420 388
      ),
421 389
    };
422 390
423 391
    delete reqOpts.instance.nodes;
392 +
    delete reqOpts.instance.gaxOptions;
424 393
425 -
    if (config.config.indexOf('/') === -1) {
394 +
    if (config.config!.indexOf('/') === -1) {
426 395
      reqOpts.instance.config = `projects/${this.projectId}/instanceConfigs/${config.config}`;
427 396
    }
428 397
    this.request(
429 398
      {
430 399
        client: 'InstanceAdminClient',
431 400
        method: 'createInstance',
432 401
        reqOpts,
402 +
        gaxOpts: config.gaxOptions,
403 +
        headers: this.resourceHeader_,
433 404
      },
434 405
      (err, operation, resp) => {
435 406
        if (err) {
@@ -442,18 +413,18 @@
Loading
442 413
    );
443 414
  }
444 415
445 -
  getInstances(query?: GetInstancesRequest): Promise<GetInstancesResponse>;
416 +
  getInstances(options?: GetInstancesOptions): Promise<GetInstancesResponse>;
446 417
  getInstances(callback: GetInstancesCallback): void;
447 418
  getInstances(
448 -
    query: GetInstancesRequest,
419 +
    query: GetInstancesOptions,
449 420
    callback: GetInstancesCallback
450 421
  ): void;
451 422
  /**
452 423
   * Query object for listing instances.
453 424
   *
454 -
   * @typedef {object} GetInstancesRequest
455 -
   * @property {boolean} [autoPaginate=true] Have pagination handled
456 -
   *     automatically.
425 +
   * @typedef {object} GetInstancesOptions
426 +
   * @property {object} [gaxOptions] Request configuration options, outlined
427 +
   *     here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
457 428
   * @property {string} [filter] An expression for filtering the results of the
458 429
   *     request. Filter rules are case insensitive. The fields eligible for
459 430
   *     filtering are:
@@ -468,21 +439,21 @@
Loading
468 439
   *     - **`labels.env:dev`** The instance's label env has the value dev.
469 440
   *     - **`name:howl labels.env:dev`** The instance's name is howl and it has
470 441
   *       the label env with value dev.
471 -
   * @property {number} [maxApiCalls] Maximum number of API calls to make.
472 -
   * @property {number} [maxResults] Maximum number of items to return.
473 442
   * @property {number} [pageSize] Maximum number of results per page.
474 443
   * @property {string} [pageToken] A previously-returned page token
475 444
   *     representing part of the larger set of results to view.
476 445
   */
477 446
  /**
478 447
   * @typedef {array} GetInstancesResponse
479 448
   * @property {Instance[]} 0 Array of {@link Instance} instances.
480 -
   * @property {object} 1 The full API response.
449 +
   * @property {object} 1 A query object to receive more results.
450 +
   * @property {object} 2 The full API response.
481 451
   */
482 452
  /**
483 453
   * @callback GetInstancesCallback
484 454
   * @param {?Error} err Request error, if any.
485 455
   * @param {Instance[]} instances Array of {@link Instance} instances.
456 +
   * @param {string} nextQuery A query object to receive more results.
486 457
   * @param {object} apiResponse The full API response.
487 458
   */
488 459
  /**
@@ -493,7 +464,7 @@
Loading
493 464
   * @see {@link v1.InstanceAdminClient#listInstances}
494 465
   * @see [ListInstances API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.ListInstances)
495 466
   *
496 -
   * @param {GetInstancesRequest} [query] Query object for listing instances.
467 +
   * @param {GetInstancesOptions} [options] Query object for listing instances.
497 468
   * @param {GetInstancesCallback} [callback] Callback function.
498 469
   * @returns {Promise<GetInstancesResponse>}
499 470
   *
@@ -517,7 +488,9 @@
Loading
517 488
   * }
518 489
   *
519 490
   * spanner.getInstances({
520 -
   *   autoPaginate: false
491 +
   *   gaxOptions: {
492 +
   *     autoPaginate: false,
493 +
   *   }
521 494
   * }, callback);
522 495
   *
523 496
   * //-
@@ -528,26 +501,50 @@
Loading
528 501
   * });
529 502
   */
530 503
  getInstances(
531 -
    query?: GetInstancesRequest | GetInstancesCallback,
532 -
    callback?: GetInstancesCallback
504 +
    optionsOrCallback?: GetInstancesOptions | GetInstancesCallback,
505 +
    cb?: GetInstancesCallback
533 506
  ): Promise<GetInstancesResponse> | void {
534 507
    // eslint-disable-next-line @typescript-eslint/no-this-alias
535 508
    const self = this;
536 -
    if (is.fn(query)) {
537 -
      callback = query as GetInstancesCallback;
538 -
      query = {};
539 -
    }
540 -
    const reqOpts = extend({}, query, {
509 +
    const options =
510 +
      typeof optionsOrCallback === 'object'
511 +
        ? optionsOrCallback
512 +
        : ({} as GetInstancesOptions);
513 +
    const callback =
514 +
      typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;
515 +
516 +
    const gaxOpts = extend(true, {}, options.gaxOptions);
517 +
518 +
    let reqOpts = extend({}, options, {
541 519
      parent: 'projects/' + this.projectId,
542 520
    });
521 +
522 +
    delete reqOpts.gaxOptions;
523 +
524 +
    // Copy over pageSize and pageToken values from gaxOptions.
525 +
    // However values set on options take precedence.
526 +
    if (gaxOpts) {
527 +
      reqOpts = extend(
528 +
        {},
529 +
        {
530 +
          pageSize: gaxOpts.pageSize,
531 +
          pageToken: gaxOpts.pageToken,
532 +
        },
533 +
        reqOpts
534 +
      );
535 +
      delete gaxOpts.pageToken;
536 +
      delete gaxOpts.pageSize;
537 +
    }
538 +
543 539
    this.request(
544 540
      {
545 541
        client: 'InstanceAdminClient',
546 542
        method: 'listInstances',
547 543
        reqOpts,
548 -
        gaxOpts: query,
544 +
        gaxOpts,
545 +
        headers: this.resourceHeader_,
549 546
      },
550 -
      (err, instances, ...args) => {
547 +
      (err, instances, nextPageRequest, ...args) => {
551 548
        let instanceInstances: Instance[] | null = null;
552 549
        if (instances) {
553 550
          instanceInstances = instances.map(instance => {
@@ -556,38 +553,108 @@
Loading
556 553
            return instanceInstance;
557 554
          });
558 555
        }
559 -
        callback!(err, instanceInstances, ...args);
556 +
        const nextQuery = nextPageRequest!
557 +
          ? extend({}, options, nextPageRequest!)
558 +
          : null;
559 +
        callback!(err, instanceInstances, nextQuery, ...args);
560 560
      }
561 561
    );
562 562
  }
563 563
564 +
  /**
565 +
   * Get a list of {@link Instance} objects as a readable object stream.
566 +
   *
567 +
   * Wrapper around {@link v1.InstanceAdminClient#listInstances}.
568 +
   *
569 +
   * @see {@link v1.InstanceAdminClient#listInstances}
570 +
   * @see [ListInstances API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.ListInstances)
571 +
   *
572 +
   * @method Spanner#getInstancesStream
573 +
   * @param {GetInstancesOptions} [options] Query object for listing instances.
574 +
   * @returns {ReadableStream} A readable stream that emits {@link Instance}
575 +
   *     instances.
576 +
   *
577 +
   * @example
578 +
   * const {Spanner} = require('@google-cloud/spanner');
579 +
   * const spanner = new Spanner();
580 +
   *
581 +
   * spanner.getInstancesStream()
582 +
   *   .on('error', console.error)
583 +
   *   .on('data', function(instance) {
584 +
   *     // `instance` is an `Instance` object.
585 +
   *   })
586 +
   *   .on('end', function() {
587 +
   *     // All instances retrieved.
588 +
   *   });
589 +
   *
590 +
   * //-
591 +
   * // If you anticipate many results, you can end a stream early to prevent
592 +
   * // unnecessary processing and API requests.
593 +
   * //-
594 +
   * spanner.getInstancesStream()
595 +
   *   .on('data', function(instance) {
596 +
   *     this.end();
597 +
   *   });
598 +
   */
599 +
  getInstancesStream(options: GetInstancesOptions = {}): NodeJS.ReadableStream {
600 +
    const gaxOpts = extend(true, {}, options.gaxOptions);
601 +
602 +
    let reqOpts = extend({}, options, {
603 +
      parent: 'projects/' + this.projectId,
604 +
    });
605 +
    delete reqOpts.gaxOptions;
606 +
607 +
    // Copy over pageSize and pageToken values from gaxOptions.
608 +
    // However values set on options take precedence.
609 +
    if (gaxOpts) {
610 +
      reqOpts = extend(
611 +
        {},
612 +
        {
613 +
          pageSize: gaxOpts.pageSize,
614 +
          pageToken: gaxOpts.pageToken,
615 +
        },
616 +
        reqOpts
617 +
      );
618 +
      delete gaxOpts.pageSize;
619 +
      delete gaxOpts.pageToken;
620 +
    }
621 +
622 +
    return this.requestStream({
623 +
      client: 'InstanceAdminClient',
624 +
      method: 'listInstancesStream',
625 +
      reqOpts,
626 +
      gaxOpts,
627 +
      headers: this.resourceHeader_,
628 +
    });
629 +
  }
630 +
564 631
  getInstanceConfigs(
565 -
    query?: GetInstanceConfigsRequest
632 +
    query?: GetInstanceConfigsOptions
566 633
  ): Promise<GetInstanceConfigsResponse>;
567 634
  getInstanceConfigs(callback: GetInstanceConfigsCallback): void;
568 635
  getInstanceConfigs(
569 -
    query: GetInstanceConfigsRequest,
636 +
    query: GetInstanceConfigsOptions,
570 637
    callback: GetInstanceConfigsCallback
571 638
  ): void;
572 639
  /**
573 -
   * Query object for listing instance configs.
640 +
   * Lists the supported instance configurations for a given project.
574 641
   *
575 -
   * @typedef {object} GetInstanceConfigsRequest
576 -
   * @property {boolean} [autoPaginate=true] Have pagination handled
577 -
   *     automatically.
578 -
   * @property {number} [maxApiCalls] Maximum number of API calls to make.
579 -
   * @property {number} [maxResults] Maximum number of items to return.
642 +
   * @typedef {object} GetInstanceConfigsOptions
580 643
   * @property {number} [pageSize] Maximum number of results per page.
581 644
   * @property {string} [pageToken] A previously-returned page token
582 645
   *     representing part of the larger set of results to view.
646 +
   * @property {object} [gaxOptions] Request configuration options, outlined
647 +
   *     here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
648 +
583 649
   */
584 650
  /**
585 651
   * @typedef {array} GetInstanceConfigsResponse
586 652
   * @property {object[]} 0 List of all available instance configs.
587 653
   * @property {string} 0.name The unique identifier for the instance config.
588 654
   * @property {string} 0.displayName The name of the instance config as it
589 655
   *     appears in UIs.
590 -
   * @property {object} 1 The full API response.
656 +
   * @property {object} 1 A query object to receive more results.
657 +
   * @property {object} 2 The full API response.
591 658
   */
592 659
  /**
593 660
   * @callback GetInstanceConfigsCallback
@@ -597,6 +664,7 @@
Loading
597 664
   *     config.
598 665
   * @param {string} instanceConfigs.displayName The name of the instance config
599 666
   *     as it appears in UIs.
667 +
   * @param {object} nextQuery A query object to receive more results.
600 668
   * @param {object} apiResponse The full API response.
601 669
   */
602 670
  /**
@@ -607,7 +675,7 @@
Loading
607 675
   * @see {@link v1.InstanceAdminClient#listInstanceConfigs}
608 676
   * @see [ListInstanceConfigs API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs)
609 677
   *
610 -
   * @param {GetInstanceConfigsRequest} [query] Query object for listing instance
678 +
   * @param {GetInstanceConfigsOptions} [options] Query object for listing instance
611 679
   *     configs.
612 680
   * @param {GetInstanceConfigsCallback} [callback] Callback function.
613 681
   * @returns {Promise<GetInstanceConfigsResponse>}
@@ -632,7 +700,9 @@
Loading
632 700
   * }
633 701
   *
634 702
   * spanner.getInstanceConfigs({
635 -
   *   autoPaginate: false
703 +
   *   gaxOptions: {
704 +
   *     autoPaginate: false,
705 +
   *   }
636 706
   * }, callback);
637 707
   *
638 708
   * //-
@@ -643,28 +713,51 @@
Loading
643 713
   * });
644 714
   */
645 715
  getInstanceConfigs(
646 -
    queryOrCallback?: GetInstanceConfigsRequest | GetInstanceConfigsCallback,
716 +
    optionsOrCallback?: GetInstanceConfigsOptions | GetInstanceConfigsCallback,
647 717
    cb?: GetInstanceConfigsCallback
648 718
  ): Promise<GetInstanceConfigsResponse> | void {
649 719
    const callback =
650 -
      typeof queryOrCallback === 'function'
651 -
        ? (queryOrCallback as GetInstanceConfigsCallback)
652 -
        : cb;
653 -
    const query =
654 -
      typeof queryOrCallback === 'object'
655 -
        ? (queryOrCallback as GetInstanceConfigsRequest)
656 -
        : {};
657 -
    const reqOpts = extend({}, query, {
720 +
      typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
721 +
    const options =
722 +
      typeof optionsOrCallback === 'object'
723 +
        ? optionsOrCallback
724 +
        : ({} as GetInstanceConfigsOptions);
725 +
726 +
    const gaxOpts = extend(true, {}, options.gaxOptions);
727 +
    let reqOpts = extend({}, options, {
658 728
      parent: 'projects/' + this.projectId,
659 729
    });
730 +
    delete reqOpts.gaxOptions;
731 +
732 +
    // Copy over pageSize and pageToken values from gaxOptions.
733 +
    // However values set on options take precedence.
734 +
    if (gaxOpts) {
735 +
      reqOpts = extend(
736 +
        {},
737 +
        {
738 +
          pageSize: gaxOpts.pageSize,
739 +
          pageToken: gaxOpts.pageToken,
740 +
        },
741 +
        reqOpts
742 +
      );
743 +
      delete gaxOpts.pageSize;
744 +
      delete gaxOpts.pageToken;
745 +
    }
746 +
660 747
    return this.request(
661 748
      {
662 749
        client: 'InstanceAdminClient',
663 750
        method: 'listInstanceConfigs',
664 751
        reqOpts,
665 -
        gaxOpts: query,
752 +
        gaxOpts,
753 +
        headers: this.resourceHeader_,
666 754
      },
667 -
      callback
755 +
      (err, instanceConfigs, nextPageRequest, ...args) => {
756 +
        const nextQuery = nextPageRequest!
757 +
          ? extend({}, options, nextPageRequest!)
758 +
          : null;
759 +
        callback!(err, instanceConfigs, nextQuery, ...args);
760 +
      }
668 761
    );
669 762
  }
670 763
@@ -677,7 +770,7 @@
Loading
677 770
   * @see [ListInstanceConfigs API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs)
678 771
   *
679 772
   * @method Spanner#getInstanceConfigsStream
680 -
   * @param {GetInstanceConfigsRequest} [query] Query object for listing instance
773 +
   * @param {GetInstanceConfigsOptions} [options] Query object for listing instance
681 774
   *     configs.
682 775
   * @returns {ReadableStream} A readable stream that emits instance configs.
683 776
   *
@@ -702,16 +795,36 @@
Loading
702 795
   *   });
703 796
   */
704 797
  getInstanceConfigsStream(
705 -
    query?: GetInstanceConfigsRequest
798 +
    options: GetInstanceConfigsOptions = {}
706 799
  ): NodeJS.ReadableStream {
707 -
    const reqOpts = extend({}, query, {
800 +
    const gaxOpts = extend(true, {}, options.gaxOptions);
801 +
802 +
    let reqOpts = extend({}, options, {
708 803
      parent: 'projects/' + this.projectId,
709 804
    });
805 +
806 +
    // Copy over pageSize and pageToken values from gaxOptions.
807 +
    // However values set on options take precedence.
808 +
    if (gaxOpts) {
809 +
      reqOpts = extend(
810 +
        {},
811 +
        {
812 +
          pageSize: gaxOpts.pageSize,
813 +
          pageToken: gaxOpts.pageToken,
814 +
        },
815 +
        reqOpts
816 +
      );
817 +
      delete gaxOpts.pageSize;
818 +
      delete gaxOpts.pageToken;
819 +
    }
820 +
821 +
    delete reqOpts.gaxOptions;
710 822
    return this.requestStream({
711 823
      client: 'InstanceAdminClient',
712 824
      method: 'listInstanceConfigsStream',
713 825
      reqOpts,
714 -
      gaxOpts: query,
826 +
      gaxOpts,
827 +
      headers: this.resourceHeader_,
715 828
    });
716 829
  }
717 830
@@ -764,7 +877,12 @@
Loading
764 877
      const requestFn = gaxClient[config.method].bind(
765 878
        gaxClient,
766 879
        reqOpts,
767 -
        config.gaxOpts
880 +
        // Add headers to `gaxOpts`
881 +
        extend(true, {}, config.gaxOpts, {
882 +
          otherArgs: {
883 +
            headers: config.headers,
884 +
          },
885 +
        })
768 886
      );
769 887
      callback(null, requestFn);
770 888
    });
@@ -783,7 +901,7 @@
Loading
783 901
   */
784 902
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
785 903
  request(config: any, callback?: any): any {
786 -
    if (is.fn(callback)) {
904 +
    if (typeof callback === 'function') {
787 905
      this.prepareGapicRequest_(config, (err, requestFn) => {
788 906
        if (err) {
789 907
          callback(err);
@@ -939,6 +1057,20 @@
Loading
939 1057
    return new codec.Int(value);
940 1058
  }
941 1059
1060 +
  /**
1061 +
   * Helper function to get a Cloud Spanner Numeric object.
1062 +
   *
1063 +
   * @param {string} value The numeric value as a string.
1064 +
   * @returns {Numeric}
1065 +
   *
1066 +
   * @example
1067 +
   * const {Spanner} = require('@google-cloud/spanner');
1068 +
   * const numeric = Spanner.numeric("3.141592653");
1069 +
   */
1070 +
  static numeric(value): Numeric {
1071 +
    return new codec.Numeric(value);
1072 +
  }
1073 +
942 1074
  /**
943 1075
   * Helper function to get a Cloud Spanner Struct object.
944 1076
   *
@@ -969,9 +1101,9 @@
Loading
969 1101
  exclude: [
970 1102
    'date',
971 1103
    'float',
972 -
    'getInstanceConfigs',
973 1104
    'instance',
974 1105
    'int',
1106 +
    'numeric',
975 1107
    'operation',
976 1108
    'timestamp',
977 1109
  ],

@@ -16,6 +16,7 @@
Loading
16 16
// ** https://github.com/googleapis/gapic-generator-typescript **
17 17
// ** All changes to this file may be overwritten. **
18 18
19 +
/* global window */
19 20
import * as gax from 'google-gax';
20 21
import {
21 22
  Callback,
@@ -31,8 +32,13 @@
Loading
31 32
import {Transform} from 'stream';
32 33
import {RequestType} from 'google-gax/build/src/apitypes';
33 34
import * as protos from '../../protos/protos';
35 +
/**
36 +
 * Client JSON configuration object, loaded from
37 +
 * `src/v1/instance_admin_client_config.json`.
38 +
 * This file defines retry strategy and timeouts for all API methods in this library.
39 +
 */
34 40
import * as gapicConfig from './instance_admin_client_config.json';
35 -
41 +
import {operationsProtos} from 'google-gax';
36 42
const version = require('../../../package.json').version;
37 43
38 44
/**
@@ -82,8 +88,10 @@
Loading
82 88
  /**
83 89
   * Construct an instance of InstanceAdminClient.
84 90
   *
85 -
   * @param {object} [options] - The configuration object. See the subsequent
86 -
   *   parameters for more details.
91 +
   * @param {object} [options] - The configuration object.
92 +
   * The options accepted by the constructor are described in detail
93 +
   * in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
94 +
   * The common options are:
87 95
   * @param {object} [options.credentials] - Credentials object.
88 96
   * @param {string} [options.credentials.client_email]
89 97
   * @param {string} [options.credentials.private_key]
@@ -103,38 +111,35 @@
Loading
103 111
   *     your project ID will be detected automatically.
104 112
   * @param {string} [options.apiEndpoint] - The domain name of the
105 113
   *     API remote host.
114 +
   * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
115 +
   *     Follows the structure of {@link gapicConfig}.
116 +
   * @param {boolean} [options.fallback] - Use HTTP fallback mode.
117 +
   *     In fallback mode, a special browser-compatible transport implementation is used
118 +
   *     instead of gRPC transport. In browser context (if the `window` object is defined)
119 +
   *     the fallback mode is enabled automatically; set `options.fallback` to `false`
120 +
   *     if you need to override this behavior.
106 121
   */
107 -
108 122
  constructor(opts?: ClientOptions) {
109 -
    // Ensure that options include the service address and port.
123 +
    // Ensure that options include all the required fields.
110 124
    const staticMembers = this.constructor as typeof InstanceAdminClient;
111 125
    const servicePath =
112 -
      opts && opts.servicePath
113 -
        ? opts.servicePath
114 -
        : opts && opts.apiEndpoint
115 -
        ? opts.apiEndpoint
116 -
        : staticMembers.servicePath;
117 -
    const port = opts && opts.port ? opts.port : staticMembers.port;
126 +
      opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
127 +
    const port = opts?.port || staticMembers.port;
128 +
    const clientConfig = opts?.clientConfig ?? {};
129 +
    const fallback =
130 +
      opts?.fallback ??
131 +
      (typeof window !== 'undefined' && typeof window?.fetch === 'function');
132 +
    opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);
118 133
119 -
    if (!opts) {
120 -
      opts = {servicePath, port};
134 +
    // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
135 +
    if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) {
136 +
      opts['scopes'] = staticMembers.scopes;
121 137
    }
122 -
    opts.servicePath = opts.servicePath || servicePath;
123 -
    opts.port = opts.port || port;
124 -
    opts.clientConfig = opts.clientConfig || {};
125 138
126 -
    const isBrowser = typeof window !== 'undefined';
127 -
    if (isBrowser) {
128 -
      opts.fallback = true;
129 -
    }
130 -
    // If we are in browser, we are already using fallback because of the
131 -
    // "browser" field in package.json.
132 -
    // But if we were explicitly requested to use fallback, let's do it now.
133 -
    this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax;
139 +
    // Choose either gRPC or proto-over-HTTP implementation of google-gax.
140 +
    this._gaxModule = opts.fallback ? gax.fallback : gax;
134 141
135 -
    // Create a `gaxGrpc` object, with any grpc-specific options
136 -
    // sent to the client.
137 -
    opts.scopes = (this.constructor as typeof InstanceAdminClient).scopes;
142 +
    // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
138 143
    this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
139 144
140 145
    // Save options to use in initialize() method.
@@ -143,6 +148,11 @@
Loading
143 148
    // Save the auth object to the client, for use by other methods.
144 149
    this.auth = this._gaxGrpc.auth as gax.GoogleAuth;
145 150
151 +
    // Set the default scopes in auth client if needed.
152 +
    if (servicePath === staticMembers.servicePath) {
153 +
      this.auth.defaultScopes = staticMembers.scopes;
154 +
    }
155 +
146 156
    // Determine the client header string.
147 157
    const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
148 158
    if (typeof process !== 'undefined' && 'versions' in process) {
@@ -184,6 +194,9 @@
Loading
184 194
      instanceConfigPathTemplate: new this._gaxModule.PathTemplate(
185 195
        'projects/{project}/instanceConfigs/{instance_config}'
186 196
      ),
197 +
      projectPathTemplate: new this._gaxModule.PathTemplate(
198 +
        'projects/{project}'
199 +
      ),
187 200
    };
188 201
189 202
    // Some of the methods on this service return "paged" results,
@@ -315,12 +328,14 @@
Loading
315 328
        }
316 329
      );
317 330
331 +
      const descriptor =
332 +
        this.descriptors.page[methodName] ||
333 +
        this.descriptors.longrunning[methodName] ||
334 +
        undefined;
318 335
      const apiCall = this._gaxModule.createApiCall(
319 336
        callPromise,
320 337
        this._defaults[methodName],
321 -
        this.descriptors.page[methodName] ||
322 -
          this.descriptors.stream[methodName] ||
323 -
          this.descriptors.longrunning[methodName]
338 +
        descriptor
324 339
      );
325 340
326 341
      this.innerApiCalls[methodName] = apiCall;
@@ -331,6 +346,7 @@
Loading
331 346
332 347
  /**
333 348
   * The DNS address for this API service.
349 +
   * @returns {string} The DNS address for this service.
334 350
   */
335 351
  static get servicePath() {
336 352
    return 'spanner.googleapis.com';
@@ -339,13 +355,15 @@
Loading
339 355
  /**
340 356
   * The DNS address for this API service - same as servicePath(),
341 357
   * exists for compatibility reasons.
358 +
   * @returns {string} The DNS address for this service.
342 359
   */
343 360
  static get apiEndpoint() {
344 361
    return 'spanner.googleapis.com';
345 362
  }
346 363
347 364
  /**
348 365
   * The port for this API service.
366 +
   * @returns {number} The default port for this service.
349 367
   */
350 368
  static get port() {
351 369
    return 443;
@@ -354,6 +372,7 @@
Loading
354 372
  /**
355 373
   * The scopes needed to make gRPC calls for every method defined
356 374
   * in this service.
375 +
   * @returns {string[]} List of default scopes.
357 376
   */
358 377
  static get scopes() {
359 378
    return [
@@ -366,8 +385,7 @@
Loading
366 385
  getProjectId(callback: Callback<string, undefined, undefined>): void;
367 386
  /**
368 387
   * Return the project ID used by this class.
369 -
   * @param {function(Error, string)} callback - the callback to
370 -
   *   be called with the current project Id.
388 +
   * @returns {Promise} A promise that resolves to string containing the project ID.
371 389
   */
372 390
  getProjectId(
373 391
    callback?: Callback<string, undefined, undefined>
@@ -384,7 +402,7 @@
Loading
384 402
  // -------------------
385 403
  getInstanceConfig(
386 404
    request: protos.google.spanner.admin.instance.v1.IGetInstanceConfigRequest,
387 -
    options?: gax.CallOptions
405 +
    options?: CallOptions
388 406
  ): Promise<
389 407
    [
390 408
      protos.google.spanner.admin.instance.v1.IInstanceConfig,
@@ -397,7 +415,7 @@
Loading
397 415
  >;
398 416
  getInstanceConfig(
399 417
    request: protos.google.spanner.admin.instance.v1.IGetInstanceConfigRequest,
400 -
    options: gax.CallOptions,
418 +
    options: CallOptions,
401 419
    callback: Callback<
402 420
      protos.google.spanner.admin.instance.v1.IInstanceConfig,
403 421
      | protos.google.spanner.admin.instance.v1.IGetInstanceConfigRequest
@@ -428,12 +446,16 @@
Loading
428 446
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
429 447
   * @returns {Promise} - The promise which resolves to an array.
430 448
   *   The first element of the array is an object representing [InstanceConfig]{@link google.spanner.admin.instance.v1.InstanceConfig}.
431 -
   *   The promise has a method named "cancel" which cancels the ongoing API call.
449 +
   *   Please see the
450 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
451 +
   *   for more details and examples.
452 +
   * @example
453 +
   * const [response] = await client.getInstanceConfig(request);
432 454
   */
433 455
  getInstanceConfig(
434 456
    request: protos.google.spanner.admin.instance.v1.IGetInstanceConfigRequest,
435 457
    optionsOrCallback?:
436 -
      | gax.CallOptions
458 +
      | CallOptions
437 459
      | Callback<
438 460
          protos.google.spanner.admin.instance.v1.IInstanceConfig,
439 461
          | protos.google.spanner.admin.instance.v1.IGetInstanceConfigRequest
@@ -459,12 +481,12 @@
Loading
459 481
    ]
460 482
  > | void {
461 483
    request = request || {};
462 -
    let options: gax.CallOptions;
484 +
    let options: CallOptions;
463 485
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
464 486
      callback = optionsOrCallback;
465 487
      options = {};
466 488
    } else {
467 -
      options = optionsOrCallback as gax.CallOptions;
489 +
      options = optionsOrCallback as CallOptions;
468 490
    }
469 491
    options = options || {};
470 492
    options.otherArgs = options.otherArgs || {};
@@ -479,7 +501,7 @@
Loading
479 501
  }
480 502
  getInstance(
481 503
    request: protos.google.spanner.admin.instance.v1.IGetInstanceRequest,
482 -
    options?: gax.CallOptions
504 +
    options?: CallOptions
483 505
  ): Promise<
484 506
    [
485 507
      protos.google.spanner.admin.instance.v1.IInstance,
@@ -489,7 +511,7 @@
Loading
489 511
  >;
490 512
  getInstance(
491 513
    request: protos.google.spanner.admin.instance.v1.IGetInstanceRequest,
492 -
    options: gax.CallOptions,
514 +
    options: CallOptions,
493 515
    callback: Callback<
494 516
      protos.google.spanner.admin.instance.v1.IInstance,
495 517
      | protos.google.spanner.admin.instance.v1.IGetInstanceRequest
@@ -524,12 +546,16 @@
Loading
524 546
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
525 547
   * @returns {Promise} - The promise which resolves to an array.
526 548
   *   The first element of the array is an object representing [Instance]{@link google.spanner.admin.instance.v1.Instance}.
527 -
   *   The promise has a method named "cancel" which cancels the ongoing API call.
549 +
   *   Please see the
550 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
551 +
   *   for more details and examples.
552 +
   * @example
553 +
   * const [response] = await client.getInstance(request);
528 554
   */
529 555
  getInstance(
530 556
    request: protos.google.spanner.admin.instance.v1.IGetInstanceRequest,
531 557
    optionsOrCallback?:
532 -
      | gax.CallOptions
558 +
      | CallOptions
533 559
      | Callback<
534 560
          protos.google.spanner.admin.instance.v1.IInstance,
535 561
          | protos.google.spanner.admin.instance.v1.IGetInstanceRequest
@@ -552,12 +578,12 @@
Loading
552 578
    ]
553 579
  > | void {
554 580
    request = request || {};
555 -
    let options: gax.CallOptions;
581 +
    let options: CallOptions;
556 582
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
557 583
      callback = optionsOrCallback;
558 584
      options = {};
559 585
    } else {
560 -
      options = optionsOrCallback as gax.CallOptions;
586 +
      options = optionsOrCallback as CallOptions;
561 587
    }
562 588
    options = options || {};
563 589
    options.otherArgs = options.otherArgs || {};
@@ -572,7 +598,7 @@
Loading
572 598
  }
573 599
  deleteInstance(
574 600
    request: protos.google.spanner.admin.instance.v1.IDeleteInstanceRequest,
575 -
    options?: gax.CallOptions
601 +
    options?: CallOptions
576 602
  ): Promise<
577 603
    [
578 604
      protos.google.protobuf.IEmpty,
@@ -585,7 +611,7 @@
Loading
585 611
  >;
586 612
  deleteInstance(
587 613
    request: protos.google.spanner.admin.instance.v1.IDeleteInstanceRequest,
588 -
    options: gax.CallOptions,
614 +
    options: CallOptions,
589 615
    callback: Callback<
590 616
      protos.google.protobuf.IEmpty,
591 617
      | protos.google.spanner.admin.instance.v1.IDeleteInstanceRequest
@@ -626,12 +652,16 @@
Loading
626 652
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
627 653
   * @returns {Promise} - The promise which resolves to an array.
628 654
   *   The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}.
629 -
   *   The promise has a method named "cancel" which cancels the ongoing API call.
655 +
   *   Please see the
656 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
657 +
   *   for more details and examples.
658 +
   * @example
659 +
   * const [response] = await client.deleteInstance(request);
630 660
   */
631 661
  deleteInstance(
632 662
    request: protos.google.spanner.admin.instance.v1.IDeleteInstanceRequest,
633 663
    optionsOrCallback?:
634 -
      | gax.CallOptions
664 +
      | CallOptions
635 665
      | Callback<
636 666
          protos.google.protobuf.IEmpty,
637 667
          | protos.google.spanner.admin.instance.v1.IDeleteInstanceRequest
@@ -657,12 +687,12 @@
Loading
657 687
    ]
658 688
  > | void {
659 689
    request = request || {};
660 -
    let options: gax.CallOptions;
690 +
    let options: CallOptions;
661 691
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
662 692
      callback = optionsOrCallback;
663 693
      options = {};
664 694
    } else {
665 -
      options = optionsOrCallback as gax.CallOptions;
695 +
      options = optionsOrCallback as CallOptions;
666 696
    }
667 697
    options = options || {};
668 698
    options.otherArgs = options.otherArgs || {};
@@ -677,7 +707,7 @@
Loading
677 707
  }
678 708
  setIamPolicy(
679 709
    request: protos.google.iam.v1.ISetIamPolicyRequest,
680 -
    options?: gax.CallOptions
710 +
    options?: CallOptions
681 711
  ): Promise<
682 712
    [
683 713
      protos.google.iam.v1.IPolicy,
@@ -687,7 +717,7 @@
Loading
687 717
  >;
688 718
  setIamPolicy(
689 719
    request: protos.google.iam.v1.ISetIamPolicyRequest,
690 -
    options: gax.CallOptions,
720 +
    options: CallOptions,
691 721
    callback: Callback<
692 722
      protos.google.iam.v1.IPolicy,
693 723
      protos.google.iam.v1.ISetIamPolicyRequest | null | undefined,
@@ -723,12 +753,16 @@
Loading
723 753
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
724 754
   * @returns {Promise} - The promise which resolves to an array.
725 755
   *   The first element of the array is an object representing [Policy]{@link google.iam.v1.Policy}.
726 -
   *   The promise has a method named "cancel" which cancels the ongoing API call.
756 +
   *   Please see the
757 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
758 +
   *   for more details and examples.
759 +
   * @example
760 +
   * const [response] = await client.setIamPolicy(request);
727 761
   */
728 762
  setIamPolicy(
729 763
    request: protos.google.iam.v1.ISetIamPolicyRequest,
730 764
    optionsOrCallback?:
731 -
      | gax.CallOptions
765 +
      | CallOptions
732 766
      | Callback<
733 767
          protos.google.iam.v1.IPolicy,
734 768
          protos.google.iam.v1.ISetIamPolicyRequest | null | undefined,
@@ -747,12 +781,12 @@
Loading
747 781
    ]
748 782
  > | void {
749 783
    request = request || {};
750 -
    let options: gax.CallOptions;
784 +
    let options: CallOptions;
751 785
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
752 786
      callback = optionsOrCallback;
753 787
      options = {};
754 788
    } else {
755 -
      options = optionsOrCallback as gax.CallOptions;
789 +
      options = optionsOrCallback as CallOptions;
756 790
    }
757 791
    options = options || {};
758 792
    options.otherArgs = options.otherArgs || {};
@@ -767,7 +801,7 @@
Loading
767 801
  }
768 802
  getIamPolicy(
769 803
    request: protos.google.iam.v1.IGetIamPolicyRequest,
770 -
    options?: gax.CallOptions
804 +
    options?: CallOptions
771 805
  ): Promise<
772 806
    [
773 807
      protos.google.iam.v1.IPolicy,
@@ -777,7 +811,7 @@
Loading
777 811
  >;
778 812
  getIamPolicy(
779 813
    request: protos.google.iam.v1.IGetIamPolicyRequest,
780 -
    options: gax.CallOptions,
814 +
    options: CallOptions,
781 815
    callback: Callback<
782 816
      protos.google.iam.v1.IPolicy,
783 817
      protos.google.iam.v1.IGetIamPolicyRequest | null | undefined,
@@ -811,12 +845,16 @@
Loading
811 845
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
812 846
   * @returns {Promise} - The promise which resolves to an array.
813 847
   *   The first element of the array is an object representing [Policy]{@link google.iam.v1.Policy}.
814 -
   *   The promise has a method named "cancel" which cancels the ongoing API call.
848 +
   *   Please see the
849 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
850 +
   *   for more details and examples.
851 +
   * @example
852 +
   * const [response] = await client.getIamPolicy(request);
815 853
   */
816 854
  getIamPolicy(
817 855
    request: protos.google.iam.v1.IGetIamPolicyRequest,
818 856
    optionsOrCallback?:
819 -
      | gax.CallOptions
857 +
      | CallOptions
820 858
      | Callback<
821 859
          protos.google.iam.v1.IPolicy,
822 860
          protos.google.iam.v1.IGetIamPolicyRequest | null | undefined,
@@ -835,12 +873,12 @@
Loading
835 873
    ]
836 874
  > | void {
837 875
    request = request || {};
838 -
    let options: gax.CallOptions;
876 +
    let options: CallOptions;
839 877
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
840 878
      callback = optionsOrCallback;
841 879
      options = {};
842 880
    } else {
843 -
      options = optionsOrCallback as gax.CallOptions;
881 +
      options = optionsOrCallback as CallOptions;
844 882
    }
845 883
    options = options || {};
846 884
    options.otherArgs = options.otherArgs || {};
@@ -855,7 +893,7 @@
Loading
855 893
  }
856 894
  testIamPermissions(
857 895
    request: protos.google.iam.v1.ITestIamPermissionsRequest,
858 -
    options?: gax.CallOptions
896 +
    options?: CallOptions
859 897
  ): Promise<
860 898
    [
861 899
      protos.google.iam.v1.ITestIamPermissionsResponse,
@@ -865,7 +903,7 @@
Loading
865 903
  >;
866 904
  testIamPermissions(
867 905
    request: protos.google.iam.v1.ITestIamPermissionsRequest,
868 -
    options: gax.CallOptions,
906 +
    options: CallOptions,
869 907
    callback: Callback<
870 908
      protos.google.iam.v1.ITestIamPermissionsResponse,
871 909
      protos.google.iam.v1.ITestIamPermissionsRequest | null | undefined,
@@ -902,12 +940,16 @@
Loading
902 940
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
903 941
   * @returns {Promise} - The promise which resolves to an array.
904 942
   *   The first element of the array is an object representing [TestIamPermissionsResponse]{@link google.iam.v1.TestIamPermissionsResponse}.
905 -
   *   The promise has a method named "cancel" which cancels the ongoing API call.
943 +
   *   Please see the
944 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
945 +
   *   for more details and examples.
946 +
   * @example
947 +
   * const [response] = await client.testIamPermissions(request);
906 948
   */
907 949
  testIamPermissions(
908 950
    request: protos.google.iam.v1.ITestIamPermissionsRequest,
909 951
    optionsOrCallback?:
910 -
      | gax.CallOptions
952 +
      | CallOptions
911 953
      | Callback<
912 954
          protos.google.iam.v1.ITestIamPermissionsResponse,
913 955
          protos.google.iam.v1.ITestIamPermissionsRequest | null | undefined,
@@ -926,12 +968,12 @@
Loading
926 968
    ]
927 969
  > | void {
928 970
    request = request || {};
929 -
    let options: gax.CallOptions;
971 +
    let options: CallOptions;
930 972
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
931 973
      callback = optionsOrCallback;
932 974
      options = {};
933 975
    } else {
934 -
      options = optionsOrCallback as gax.CallOptions;
976 +
      options = optionsOrCallback as CallOptions;
935 977
    }
936 978
    options = options || {};
937 979
    options.otherArgs = options.otherArgs || {};
@@ -947,7 +989,7 @@
Loading
947 989
948 990
  createInstance(
949 991
    request: protos.google.spanner.admin.instance.v1.ICreateInstanceRequest,
950 -
    options?: gax.CallOptions
992 +
    options?: CallOptions
951 993
  ): Promise<
952 994
    [
953 995
      LROperation<
@@ -960,7 +1002,7 @@
Loading
960 1002
  >;
961 1003
  createInstance(
962 1004
    request: protos.google.spanner.admin.instance.v1.ICreateInstanceRequest,
963 -
    options: gax.CallOptions,
1005 +
    options: CallOptions,
964 1006
    callback: Callback<
965 1007
      LROperation<
966 1008
        protos.google.spanner.admin.instance.v1.IInstance,
@@ -1032,13 +1074,20 @@
Loading
1032 1074
   * @param {object} [options]
1033 1075
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
1034 1076
   * @returns {Promise} - The promise which resolves to an array.
1035 -
   *   The first element of the array is an object representing [Operation]{@link google.longrunning.Operation}.
1036 -
   *   The promise has a method named "cancel" which cancels the ongoing API call.
1077 +
   *   The first element of the array is an object representing
1078 +
   *   a long running operation. Its `promise()` method returns a promise
1079 +
   *   you can `await` for.
1080 +
   *   Please see the
1081 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
1082 +
   *   for more details and examples.
1083 +
   * @example
1084 +
   * const [operation] = await client.createInstance(request);
1085 +
   * const [response] = await operation.promise();
1037 1086
   */
1038 1087
  createInstance(
1039 1088
    request: protos.google.spanner.admin.instance.v1.ICreateInstanceRequest,
1040 1089
    optionsOrCallback?:
1041 -
      | gax.CallOptions
1090 +
      | CallOptions
1042 1091
      | Callback<
1043 1092
          LROperation<
1044 1093
            protos.google.spanner.admin.instance.v1.IInstance,
@@ -1066,12 +1115,12 @@
Loading
1066 1115
    ]
1067 1116
  > | void {
1068 1117
    request = request || {};
1069 -
    let options: gax.CallOptions;
1118 +
    let options: CallOptions;
1070 1119
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
1071 1120
      callback = optionsOrCallback;
1072 1121
      options = {};
1073 1122
    } else {
1074 -
      options = optionsOrCallback as gax.CallOptions;
1123 +
      options = optionsOrCallback as CallOptions;
1075 1124
    }
1076 1125
    options = options || {};
1077 1126
    options.otherArgs = options.otherArgs || {};
@@ -1084,9 +1133,46 @@
Loading
1084 1133
    this.initialize();
1085 1134
    return this.innerApiCalls.createInstance(request, options, callback);
1086 1135
  }
1136 +
  /**
1137 +
   * Check the status of the long running operation returned by `createInstance()`.
1138 +
   * @param {String} name
1139 +
   *   The operation name that will be passed.
1140 +
   * @returns {Promise} - The promise which resolves to an object.
1141 +
   *   The decoded operation object has result and metadata field to get information from.
1142 +
   *   Please see the
1143 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
1144 +
   *   for more details and examples.
1145 +
   * @example
1146 +
   * const decodedOperation = await checkCreateInstanceProgress(name);
1147 +
   * console.log(decodedOperation.result);
1148 +
   * console.log(decodedOperation.done);
1149 +
   * console.log(decodedOperation.metadata);
1150 +
   */
1151 +
  async checkCreateInstanceProgress(
1152 +
    name: string
1153 +
  ): Promise<
1154 +
    LROperation<
1155 +
      protos.google.spanner.admin.instance.v1.Instance,
1156 +
      protos.google.spanner.admin.instance.v1.CreateInstanceMetadata
1157 +
    >
1158 +
  > {
1159 +
    const request = new operationsProtos.google.longrunning.GetOperationRequest(
1160 +
      {name}
1161 +
    );
1162 +
    const [operation] = await this.operationsClient.getOperation(request);
1163 +
    const decodeOperation = new gax.Operation(
1164 +
      operation,
1165 +
      this.descriptors.longrunning.createInstance,
1166 +
      gax.createDefaultBackoffSettings()
1167 +
    );
1168 +
    return decodeOperation as LROperation<
1169 +
      protos.google.spanner.admin.instance.v1.Instance,
1170 +
      protos.google.spanner.admin.instance.v1.CreateInstanceMetadata
1171 +
    >;
1172 +
  }
1087 1173
  updateInstance(
1088 1174
    request: protos.google.spanner.admin.instance.v1.IUpdateInstanceRequest,
1089 -
    options?: gax.CallOptions
1175 +
    options?: CallOptions
1090 1176
  ): Promise<
1091 1177
    [
1092 1178
      LROperation<
@@ -1099,7 +1185,7 @@
Loading
1099 1185
  >;
1100 1186
  updateInstance(
1101 1187
    request: protos.google.spanner.admin.instance.v1.IUpdateInstanceRequest,
1102 -
    options: gax.CallOptions,
1188 +
    options: CallOptions,
1103 1189
    callback: Callback<
1104 1190
      LROperation<
1105 1191
        protos.google.spanner.admin.instance.v1.IInstance,
@@ -1175,13 +1261,20 @@
Loading
1175 1261
   * @param {object} [options]
1176 1262
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
1177 1263
   * @returns {Promise} - The promise which resolves to an array.
1178 -
   *   The first element of the array is an object representing [Operation]{@link google.longrunning.Operation}.
1179 -
   *   The promise has a method named "cancel" which cancels the ongoing API call.
1264 +
   *   The first element of the array is an object representing
1265 +
   *   a long running operation. Its `promise()` method returns a promise
1266 +
   *   you can `await` for.
1267 +
   *   Please see the
1268 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
1269 +
   *   for more details and examples.
1270 +
   * @example
1271 +
   * const [operation] = await client.updateInstance(request);
1272 +
   * const [response] = await operation.promise();
1180 1273
   */
1181 1274
  updateInstance(
1182 1275
    request: protos.google.spanner.admin.instance.v1.IUpdateInstanceRequest,
1183 1276
    optionsOrCallback?:
1184 -
      | gax.CallOptions
1277 +
      | CallOptions
1185 1278
      | Callback<
1186 1279
          LROperation<
1187 1280
            protos.google.spanner.admin.instance.v1.IInstance,
@@ -1209,12 +1302,12 @@
Loading
1209 1302
    ]
1210 1303
  > | void {
1211 1304
    request = request || {};
1212 -
    let options: gax.CallOptions;
1305 +
    let options: CallOptions;
1213 1306
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
1214 1307
      callback = optionsOrCallback;
1215 1308
      options = {};
1216 1309
    } else {
1217 -
      options = optionsOrCallback as gax.CallOptions;
1310 +
      options = optionsOrCallback as CallOptions;
1218 1311
    }
1219 1312
    options = options || {};
1220 1313
    options.otherArgs = options.otherArgs || {};
@@ -1227,9 +1320,46 @@
Loading
1227 1320
    this.initialize();
1228 1321
    return this.innerApiCalls.updateInstance(request, options, callback);
1229 1322
  }
1323 +
  /**
1324 +
   * Check the status of the long running operation returned by `updateInstance()`.
1325 +
   * @param {String} name
1326 +
   *   The operation name that will be passed.
1327 +
   * @returns {Promise} - The promise which resolves to an object.
1328 +
   *   The decoded operation object has result and metadata field to get information from.
1329 +
   *   Please see the
1330 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
1331 +
   *   for more details and examples.
1332 +
   * @example
1333 +
   * const decodedOperation = await checkUpdateInstanceProgress(name);
1334 +
   * console.log(decodedOperation.result);
1335 +
   * console.log(decodedOperation.done);
1336 +
   * console.log(decodedOperation.metadata);
1337 +
   */
1338 +
  async checkUpdateInstanceProgress(
1339 +
    name: string
1340 +
  ): Promise<
1341 +
    LROperation<
1342 +
      protos.google.spanner.admin.instance.v1.Instance,
1343 +
      protos.google.spanner.admin.instance.v1.UpdateInstanceMetadata
1344 +
    >
1345 +
  > {
1346 +
    const request = new operationsProtos.google.longrunning.GetOperationRequest(
1347 +
      {name}
1348 +
    );
1349 +
    const [operation] = await this.operationsClient.getOperation(request);
1350 +
    const decodeOperation = new gax.Operation(
1351 +
      operation,
1352 +
      this.descriptors.longrunning.updateInstance,
1353 +
      gax.createDefaultBackoffSettings()
1354 +
    );
1355 +
    return decodeOperation as LROperation<
1356 +
      protos.google.spanner.admin.instance.v1.Instance,
1357 +
      protos.google.spanner.admin.instance.v1.UpdateInstanceMetadata
1358 +
    >;
1359 +
  }
1230 1360
  listInstanceConfigs(
1231 1361
    request: protos.google.spanner.admin.instance.v1.IListInstanceConfigsRequest,
1232 -
    options?: gax.CallOptions
1362 +
    options?: CallOptions
1233 1363
  ): Promise<
1234 1364
    [
1235 1365
      protos.google.spanner.admin.instance.v1.IInstanceConfig[],
@@ -1239,7 +1369,7 @@
Loading
1239 1369
  >;
1240 1370
  listInstanceConfigs(
1241 1371
    request: protos.google.spanner.admin.instance.v1.IListInstanceConfigsRequest,
1242 -
    options: gax.CallOptions,
1372 +
    options: CallOptions,
1243 1373
    callback: PaginationCallback<
1244 1374
      protos.google.spanner.admin.instance.v1.IListInstanceConfigsRequest,
1245 1375
      | protos.google.spanner.admin.instance.v1.IListInstanceConfigsResponse
@@ -1278,24 +1408,19 @@
Loading
1278 1408
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
1279 1409
   * @returns {Promise} - The promise which resolves to an array.
1280 1410
   *   The first element of the array is Array of [InstanceConfig]{@link google.spanner.admin.instance.v1.InstanceConfig}.
1281 -
   *   The client library support auto-pagination by default: it will call the API as many
1411 +
   *   The client library will perform auto-pagination by default: it will call the API as many
1282 1412
   *   times as needed and will merge results from all the pages into this array.
1283 -
   *
1284 -
   *   When autoPaginate: false is specified through options, the array has three elements.
1285 -
   *   The first element is Array of [InstanceConfig]{@link google.spanner.admin.instance.v1.InstanceConfig} that corresponds to
1286 -
   *   the one page received from the API server.
1287 -
   *   If the second element is not null it contains the request object of type [ListInstanceConfigsRequest]{@link google.spanner.admin.instance.v1.ListInstanceConfigsRequest}
1288 -
   *   that can be used to obtain the next page of the results.
1289 -
   *   If it is null, the next page does not exist.
1290 -
   *   The third element contains the raw response received from the API server. Its type is
1291 -
   *   [ListInstanceConfigsResponse]{@link google.spanner.admin.instance.v1.ListInstanceConfigsResponse}.
1292 -
   *
1293 -
   *   The promise has a method named "cancel" which cancels the ongoing API call.
1413 +
   *   Note that it can affect your quota.
1414 +
   *   We recommend using `listInstanceConfigsAsync()`
1415 +
   *   method described below for async iteration which you can stop as needed.
1416 +
   *   Please see the
1417 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
1418 +
   *   for more details and examples.
1294 1419
   */
1295 1420
  listInstanceConfigs(
1296 1421
    request: protos.google.spanner.admin.instance.v1.IListInstanceConfigsRequest,
1297 1422
    optionsOrCallback?:
1298 -
      | gax.CallOptions
1423 +
      | CallOptions
1299 1424
      | PaginationCallback<
1300 1425
          protos.google.spanner.admin.instance.v1.IListInstanceConfigsRequest,
1301 1426
          | protos.google.spanner.admin.instance.v1.IListInstanceConfigsResponse
@@ -1318,12 +1443,12 @@
Loading
1318 1443
    ]
1319 1444
  > | void {
1320 1445
    request = request || {};
1321 -
    let options: gax.CallOptions;
1446 +
    let options: CallOptions;
1322 1447
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
1323 1448
      callback = optionsOrCallback;
1324 1449
      options = {};
1325 1450
    } else {
1326 -
      options = optionsOrCallback as gax.CallOptions;
1451 +
      options = optionsOrCallback as CallOptions;
1327 1452
    }
1328 1453
    options = options || {};
1329 1454
    options.otherArgs = options.otherArgs || {};
@@ -1338,18 +1463,7 @@
Loading
1338 1463
  }
1339 1464
1340 1465
  /**
1341 -
   * Equivalent to {@link listInstanceConfigs}, but returns a NodeJS Stream object.
1342 -
   *
1343 -
   * This fetches the paged responses for {@link listInstanceConfigs} continuously
1344 -
   * and invokes the callback registered for 'data' event for each element in the
1345 -
   * responses.
1346 -
   *
1347 -
   * The returned object has 'end' method when no more elements are required.
1348 -
   *
1349 -
   * autoPaginate option will be ignored.
1350 -
   *
1351 -
   * @see {@link https://nodejs.org/api/stream.html}
1352 -
   *
1466 +
   * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
1353 1467
   * @param {Object} request
1354 1468
   *   The request object that will be sent.
1355 1469
   * @param {string} request.parent
@@ -1367,10 +1481,17 @@
Loading
1367 1481
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
1368 1482
   * @returns {Stream}
1369 1483
   *   An object stream which emits an object representing [InstanceConfig]{@link google.spanner.admin.instance.v1.InstanceConfig} on 'data' event.
1484 +
   *   The client library will perform auto-pagination by default: it will call the API as many
1485 +
   *   times as needed. Note that it can affect your quota.
1486 +
   *   We recommend using `listInstanceConfigsAsync()`
1487 +
   *   method described below for async iteration which you can stop as needed.
1488 +
   *   Please see the
1489 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
1490 +
   *   for more details and examples.
1370 1491
   */
1371 1492
  listInstanceConfigsStream(
1372 1493
    request?: protos.google.spanner.admin.instance.v1.IListInstanceConfigsRequest,
1373 -
    options?: gax.CallOptions
1494 +
    options?: CallOptions
1374 1495
  ): Transform {
1375 1496
    request = request || {};
1376 1497
    options = options || {};
@@ -1391,10 +1512,9 @@
Loading
1391 1512
  }
1392 1513
1393 1514
  /**
1394 -
   * Equivalent to {@link listInstanceConfigs}, but returns an iterable object.
1395 -
   *
1396 -
   * for-await-of syntax is used with the iterable to recursively get response element on-demand.
1515 +
   * Equivalent to `listInstanceConfigs`, but returns an iterable object.
1397 1516
   *
1517 +
   * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
1398 1518
   * @param {Object} request
1399 1519
   *   The request object that will be sent.
1400 1520
   * @param {string} request.parent
@@ -1411,11 +1531,22 @@
Loading
1411 1531
   * @param {object} [options]
1412 1532
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
1413 1533
   * @returns {Object}
1414 -
   *   An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols.
1534 +
   *   An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
1535 +
   *   When you iterate the returned iterable, each element will be an object representing
1536 +
   *   [InstanceConfig]{@link google.spanner.admin.instance.v1.InstanceConfig}. The API will be called under the hood as needed, once per the page,
1537 +
   *   so you can stop the iteration when you don't need more results.
1538 +
   *   Please see the
1539 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
1540 +
   *   for more details and examples.
1541 +
   * @example
1542 +
   * const iterable = client.listInstanceConfigsAsync(request);
1543 +
   * for await (const response of iterable) {
1544 +
   *   // process response
1545 +
   * }
1415 1546
   */
1416 1547
  listInstanceConfigsAsync(
1417 1548
    request?: protos.google.spanner.admin.instance.v1.IListInstanceConfigsRequest,
1418 -
    options?: gax.CallOptions
1549 +
    options?: CallOptions
1419 1550
  ): AsyncIterable<protos.google.spanner.admin.instance.v1.IInstanceConfig> {
1420 1551
    request = request || {};
1421 1552
    options = options || {};
@@ -1437,7 +1568,7 @@
Loading
1437 1568
  }
1438 1569
  listInstances(
1439 1570
    request: protos.google.spanner.admin.instance.v1.IListInstancesRequest,
1440 -
    options?: gax.CallOptions
1571 +
    options?: CallOptions
1441 1572
  ): Promise<
1442 1573
    [
1443 1574
      protos.google.spanner.admin.instance.v1.IInstance[],
@@ -1447,7 +1578,7 @@
Loading
1447 1578
  >;
1448 1579
  listInstances(
1449 1580
    request: protos.google.spanner.admin.instance.v1.IListInstancesRequest,
1450 -
    options: gax.CallOptions,
1581 +
    options: CallOptions,
1451 1582
    callback: PaginationCallback<
1452 1583
      protos.google.spanner.admin.instance.v1.IListInstancesRequest,
1453 1584
      | protos.google.spanner.admin.instance.v1.IListInstancesResponse
@@ -1505,24 +1636,19 @@
Loading
1505 1636
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
1506 1637
   * @returns {Promise} - The promise which resolves to an array.
1507 1638
   *   The first element of the array is Array of [Instance]{@link google.spanner.admin.instance.v1.Instance}.
1508 -
   *   The client library support auto-pagination by default: it will call the API as many
1639 +
   *   The client library will perform auto-pagination by default: it will call the API as many
1509 1640
   *   times as needed and will merge results from all the pages into this array.
1510 -
   *
1511 -
   *   When autoPaginate: false is specified through options, the array has three elements.
1512 -
   *   The first element is Array of [Instance]{@link google.spanner.admin.instance.v1.Instance} that corresponds to
1513 -
   *   the one page received from the API server.
1514 -
   *   If the second element is not null it contains the request object of type [ListInstancesRequest]{@link google.spanner.admin.instance.v1.ListInstancesRequest}
1515 -
   *   that can be used to obtain the next page of the results.
1516 -
   *   If it is null, the next page does not exist.
1517 -
   *   The third element contains the raw response received from the API server. Its type is
1518 -
   *   [ListInstancesResponse]{@link google.spanner.admin.instance.v1.ListInstancesResponse}.
1519 -
   *
1520 -
   *   The promise has a method named "cancel" which cancels the ongoing API call.
1641 +
   *   Note that it can affect your quota.
1642 +
   *   We recommend using `listInstancesAsync()`
1643 +
   *   method described below for async iteration which you can stop as needed.
1644 +
   *   Please see the
1645 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
1646 +
   *   for more details and examples.
1521 1647
   */
1522 1648
  listInstances(
1523 1649
    request: protos.google.spanner.admin.instance.v1.IListInstancesRequest,
1524 1650
    optionsOrCallback?:
1525 -
      | gax.CallOptions
1651 +
      | CallOptions
1526 1652
      | PaginationCallback<
1527 1653
          protos.google.spanner.admin.instance.v1.IListInstancesRequest,
1528 1654
          | protos.google.spanner.admin.instance.v1.IListInstancesResponse
@@ -1545,12 +1671,12 @@
Loading
1545 1671
    ]
1546 1672
  > | void {
1547 1673
    request = request || {};
1548 -
    let options: gax.CallOptions;
1674 +
    let options: CallOptions;
1549 1675
    if (typeof optionsOrCallback === 'function' && callback === undefined) {
1550 1676
      callback = optionsOrCallback;
1551 1677
      options = {};
1552 1678
    } else {
1553 -
      options = optionsOrCallback as gax.CallOptions;
1679 +
      options = optionsOrCallback as CallOptions;
1554 1680
    }
1555 1681
    options = options || {};
1556 1682
    options.otherArgs = options.otherArgs || {};
@@ -1565,18 +1691,7 @@
Loading
1565 1691
  }
1566 1692
1567 1693
  /**
1568 -
   * Equivalent to {@link listInstances}, but returns a NodeJS Stream object.
1569 -
   *
1570 -
   * This fetches the paged responses for {@link listInstances} continuously
1571 -
   * and invokes the callback registered for 'data' event for each element in the
1572 -
   * responses.
1573 -
   *
1574 -
   * The returned object has 'end' method when no more elements are required.
1575 -
   *
1576 -
   * autoPaginate option will be ignored.
1577 -
   *
1578 -
   * @see {@link https://nodejs.org/api/stream.html}
1579 -
   *
1694 +
   * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
1580 1695
   * @param {Object} request
1581 1696
   *   The request object that will be sent.
1582 1697
   * @param {string} request.parent
@@ -1613,10 +1728,17 @@
Loading
1613 1728
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
1614 1729
   * @returns {Stream}
1615 1730
   *   An object stream which emits an object representing [Instance]{@link google.spanner.admin.instance.v1.Instance} on 'data' event.
1731 +
   *   The client library will perform auto-pagination by default: it will call the API as many
1732 +
   *   times as needed. Note that it can affect your quota.
1733 +
   *   We recommend using `listInstancesAsync()`
1734 +
   *   method described below for async iteration which you can stop as needed.
1735 +
   *   Please see the
1736 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
1737 +
   *   for more details and examples.
1616 1738
   */
1617 1739
  listInstancesStream(
1618 1740
    request?: protos.google.spanner.admin.instance.v1.IListInstancesRequest,
1619 -
    options?: gax.CallOptions
1741 +
    options?: CallOptions
1620 1742
  ): Transform {
1621 1743
    request = request || {};
1622 1744
    options = options || {};
@@ -1637,10 +1759,9 @@
Loading
1637 1759
  }
1638 1760
1639 1761
  /**
1640 -
   * Equivalent to {@link listInstances}, but returns an iterable object.
1641 -
   *
1642 -
   * for-await-of syntax is used with the iterable to recursively get response element on-demand.
1762 +
   * Equivalent to `listInstances`, but returns an iterable object.
1643 1763
   *
1764 +
   * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
1644 1765
   * @param {Object} request
1645 1766
   *   The request object that will be sent.
1646 1767
   * @param {string} request.parent
@@ -1676,11 +1797,22 @@
Loading
1676 1797
   * @param {object} [options]
1677 1798
   *   Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
1678 1799
   * @returns {Object}
1679 -
   *   An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols.
1800 +
   *   An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
1801 +
   *   When you iterate the returned iterable, each element will be an object representing
1802 +
   *   [Instance]{@link google.spanner.admin.instance.v1.Instance}. The API will be called under the hood as needed, once per the page,
1803 +
   *   so you can stop the iteration when you don't need more results.
1804 +
   *   Please see the
1805 +
   *   [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
1806 +
   *   for more details and examples.
1807 +
   * @example
1808 +
   * const iterable = client.listInstancesAsync(request);
1809 +
   * for await (const response of iterable) {
1810 +
   *   // process response
1811 +
   * }
1680 1812
   */
1681 1813
  listInstancesAsync(
1682 1814
    request?: protos.google.spanner.admin.instance.v1.IListInstancesRequest,
1683 -
    options?: gax.CallOptions
1815 +
    options?: CallOptions
1684 1816
  ): AsyncIterable<protos.google.spanner.admin.instance.v1.IInstance> {
1685 1817
    request = request || {};
1686 1818
    options = options || {};
@@ -1781,9 +1913,33 @@
Loading
1781 1913
  }
1782 1914
1783 1915
  /**
1784 -
   * Terminate the GRPC channel and close the client.
1916 +
   * Return a fully-qualified project resource name string.
1917 +
   *
1918 +
   * @param {string} project
1919 +
   * @returns {string} Resource name string.
1920 +
   */
1921 +
  projectPath(project: string) {
1922 +
    return this.pathTemplates.projectPathTemplate.render({
1923 +
      project: project,
1924 +
    });
1925 +
  }
1926 +
1927 +
  /**
1928 +
   * Parse the project from Project resource.
1929 +
   *
1930 +
   * @param {string} projectName
1931 +
   *   A fully-qualified path representing Project resource.
1932 +
   * @returns {string} A string representing the project.
1933 +
   */
1934 +
  matchProjectFromProjectName(projectName: string) {
1935 +
    return this.pathTemplates.projectPathTemplate.match(projectName).project;
1936 +
  }
1937 +
1938 +
  /**
1939 +
   * Terminate the gRPC channel and close the client.
1785 1940
   *
1786 1941
   * The client will no longer be usable and all future behavior is undefined.
1942 +
   * @returns {Promise} A promise that resolves when the client is closed.
1787 1943
   */
1788 1944
  close(): Promise<void> {
1789 1945
    this.initialize();

@@ -17,46 +17,51 @@
Loading
17 17
import {
18 18
  ApiError,
19 19
  ExistsCallback,
20 +
  GetConfig,
20 21
  Metadata,
21 22
  ServiceObjectConfig,
22 -
  GetConfig,
23 23
} from '@google-cloud/common';
24 -
import {GrpcServiceObject} from './common-grpc/service-object';
25 -
import {promisify, promisifyAll} from '@google-cloud/promisify';
26 -
import arrify = require('arrify');
24 +
// eslint-disable-next-line @typescript-eslint/no-var-requires
25 +
const common = require('./common-grpc/service-object');
26 +
import {promisify, promisifyAll, callbackifyAll} from '@google-cloud/promisify';
27 27
import * as extend from 'extend';
28 28
import * as r from 'teeny-request';
29 29
import * as streamEvents from 'stream-events';
30 30
import * as through from 'through2';
31 -
import {Operation as GaxOperation} from 'google-gax';
31 +
import {CallOptions, grpc, Operation as GaxOperation} from 'google-gax';
32 32
import {Backup} from './backup';
33 33
import {BatchTransaction, TransactionIdentifier} from './batch-transaction';
34 -
import {google as databaseAdmin} from '../protos/protos';
35 34
import {
36 -
  Instance,
37 -
  CreateDatabaseOptions,
35 +
  google as databaseAdmin,
36 +
  google,
37 +
  google as spannerClient,
38 +
} from '../protos/protos';
39 +
import {
38 40
  CreateDatabaseCallback,
41 +
  CreateDatabaseOptions,
39 42
  GetDatabaseOperationsOptions,
40 43
  GetDatabaseOperationsResponse,
44 +
  Instance,
45 +
  GetDatabaseOperationsCallback,
41 46
} from './instance';
42 47
import {PartialResultStream, Row} from './partial-result-stream';
43 48
import {Session} from './session';
44 49
import {
50 +
  isSessionNotFoundError,
45 51
  SessionPool,
46 -
  SessionPoolOptions,
47 52
  SessionPoolCloseCallback,
48 53
  SessionPoolInterface,
49 -
  isSessionNotFoundError,
54 +
  SessionPoolOptions,
50 55
} from './session-pool';
51 -
import {Table, CreateTableCallback, CreateTableResponse} from './table';
56 +
import {CreateTableCallback, CreateTableResponse, Table} from './table';
52 57
import {
58 +
  ExecuteSqlRequest,
59 +
  RunCallback,
60 +
  RunResponse,
61 +
  RunUpdateCallback,
53 62
  Snapshot,
54 63
  TimestampBounds,
55 64
  Transaction,
56 -
  ExecuteSqlRequest,
57 -
  RunUpdateCallback,
58 -
  RunResponse,
59 -
  RunCallback,
60 65
} from './transaction';
61 66
import {
62 67
  AsyncRunTransactionCallback,
@@ -65,23 +70,21 @@
Loading
65 70
  RunTransactionOptions,
66 71
  TransactionRunner,
67 72
} from './transaction-runner';
68 -
69 -
import {google} from '../protos/protos';
70 73
import {
71 74
  IOperation,
72 -
  Schema,
75 +
  LongRunningCallback,
76 +
  NormalCallback,
77 +
  PagedOptionsWithFilter,
78 +
  CLOUD_RESOURCE_HEADER,
79 +
  PagedResponse,
73 80
  RequestCallback,
74 -
  PagedRequest,
75 81
  ResourceCallback,
76 -
  PagedResponse,
77 -
  NormalCallback,
78 -
  LongRunningCallback,
82 +
  Schema,
79 83
} from './common';
80 -
import {ServiceError, CallOptions} from 'grpc';
81 -
import {Readable, Transform, Duplex} from 'stream';
84 +
import {Duplex, Readable, Transform} from 'stream';
82 85
import {PreciseDate} from '@google-cloud/precise-date';
83 -
import {google as spannerClient} from '../protos/protos';
84 86
import {EnumKey, RequestConfig, TranslateEnumKeys} from '.';
87 +
import arrify = require('arrify');
85 88
86 89
type CreateBatchTransactionCallback = ResourceCallback<
87 90
  BatchTransaction,
@@ -120,7 +123,7 @@
Loading
120 123
121 124
type ResultSetStats = spannerClient.spanner.v1.ResultSetStats;
122 125
123 -
type GetSessionsOptions = PagedRequest<google.spanner.v1.IListSessionsRequest>;
126 +
export type GetSessionsOptions = PagedOptionsWithFilter;
124 127
125 128
/**
126 129
 * IDatabase structure with database state enum translated to string form.
@@ -166,7 +169,9 @@
Loading
166 169
>;
167 170
168 171
export type GetDatabaseConfig = GetConfig &
169 -
  databaseAdmin.spanner.admin.database.v1.GetDatabaseRequest;
172 +
  databaseAdmin.spanner.admin.database.v1.GetDatabaseRequest & {
173 +
    gaxOptions?: CallOptions;
174 +
  };
170 175
type DatabaseCloseResponse = [google.protobuf.IEmpty];
171 176
172 177
export type CreateSessionResponse = [
@@ -175,8 +180,8 @@
Loading
175 180
];
176 181
177 182
export interface CreateSessionOptions {
178 -
  name?: string | null;
179 183
  labels?: {[k: string]: string} | null;
184 +
  gaxOptions?: CallOptions;
180 185
}
181 186
182 187
export type CreateSessionCallback = ResourceCallback<
@@ -198,7 +203,8 @@
Loading
198 203
  spannerClient.spanner.v1.IBatchCreateSessionsResponse
199 204
>;
200 205
201 -
export type DatabaseDeleteCallback = NormalCallback<r.Response>;
206 +
export type DatabaseDeleteResponse = [databaseAdmin.protobuf.IEmpty];
207 +
export type DatabaseDeleteCallback = NormalCallback<databaseAdmin.protobuf.IEmpty>;
202 208
203 209
export interface CancelableDuplex extends Duplex {
204 210
  cancel(): void;
@@ -212,6 +218,11 @@
Loading
212 218
  databaseAdmin.longrunning.IOperation
213 219
];
214 220
221 +
export type GetRestoreInfoCallback = NormalCallback<IRestoreInfoTranslatedEnum>;
222 +
export type GetStateCallback = NormalCallback<
223 +
  EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Database.State>
224 +
>;
225 +
215 226
interface DatabaseRequest {
216 227
  (
217 228
    config: RequestConfig,
@@ -237,11 +248,12 @@
Loading
237 248
 * const instance = spanner.instance('my-instance');
238 249
 * const database = instance.database('my-database');
239 250
 */
240 -
class Database extends GrpcServiceObject {
251 +
class Database extends common.GrpcServiceObject {
241 252
  private instance: Instance;
242 253
  formattedName_: string;
243 254
  pool_: SessionPoolInterface;
244 255
  queryOptions_?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions;
256 +
  resourceHeader_: {[k: string]: string};
245 257
  request: DatabaseRequest;
246 258
  constructor(
247 259
    instance: Instance,
@@ -304,7 +316,41 @@
Loading
304 316
        options: CreateDatabaseOptions,
305 317
        callback: CreateDatabaseCallback
306 318
      ) => {
307 -
        return instance.createDatabase(formattedName_, options, callback);
319 +
        const pool = this.pool_ as SessionPool;
320 +
        if (pool._pending > 0) {
321 +
          // If there are BatchCreateSessions requests pending, then we should
322 +
          // wait until these have finished before we try to create the database.
323 +
          // Otherwise the results of these requests might be propagated to
324 +
          // client requests that are submitted after the database has been
325 +
          // created. If the pending requests have not finished within 10 seconds,
326 +
          // they will be ignored and the database creation will proceed.
327 +
          let timeout;
328 +
          const promises = [
329 +
            new Promise<void>(
330 +
              resolve => (timeout = setTimeout(resolve, 10000))
331 +
            ),
332 +
            new Promise<void>(resolve => {
333 +
              pool
334 +
                .on('available', () => {
335 +
                  if (pool._pending === 0) {
336 +
                    clearTimeout(timeout);
337 +
                    resolve();
338 +
                  }
339 +
                })
340 +
                .on('createError', () => {
341 +
                  if (pool._pending === 0) {
342 +
                    clearTimeout(timeout);
343 +
                    resolve();
344 +
                  }
345 +
                });
346 +
            }),
347 +
          ];
348 +
          Promise.race(promises).then(() =>
349 +
            instance.createDatabase(formattedName_, options, callback)
350 +
          );
351 +
        } else {
352 +
          return instance.createDatabase(formattedName_, options, callback);
353 +
        }
308 354
      },
309 355
    } as {}) as ServiceObjectConfig);
310 356
@@ -314,6 +360,9 @@
Loading
314 360
        : new SessionPool(this, poolOptions);
315 361
    this.formattedName_ = formattedName_;
316 362
    this.instance = instance;
363 +
    this.resourceHeader_ = {
364 +
      [CLOUD_RESOURCE_HEADER]: this.formattedName_,
365 +
    };
317 366
    this.request = instance.request;
318 367
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
319 368
    this.requestStream = instance.requestStream as any;
@@ -417,6 +466,8 @@
Loading
417 466
        client: 'SpannerClient',
418 467
        method: 'batchCreateSessions',
419 468
        reqOpts,
469 +
        gaxOpts: options.gaxOptions,
470 +
        headers: this.resourceHeader_,
420 471
      },
421 472
      (err, resp) => {
422 473
        if (err) {
@@ -555,12 +606,13 @@
Loading
555 606
        ? (optionsOrCallback as TimestampBounds)
556 607
        : {};
557 608
558 -
    this.createSession((err, session, resp) => {
609 +
    this.pool_.getReadSession((err, session) => {
559 610
      if (err) {
560 -
        callback!(err, null, resp);
611 +
        callback!(err, null, undefined);
561 612
        return;
562 613
      }
563 614
      const transaction = this.batchTransaction({session: session!}, options);
615 +
      this._releaseOnEnd(session!, transaction);
564 616
      transaction.begin((err, resp) => {
565 617
        if (err) {
566 618
          callback!(err, null, resp!);
@@ -576,6 +628,20 @@
Loading
576 628
    options: CreateSessionOptions,
577 629
    callback: CreateSessionCallback
578 630
  ): void;
631 +
  /**
632 +
   * Create a new session.
633 +
   *
634 +
   * @typedef {object} CreateSessionOptions
635 +
   * @property {Object.<string, string>} [labels] The labels for the session.
636 +
   *
637 +
   *   * Label keys must be between 1 and 63 characters long and must conform to
638 +
   *     the following regular expression: `[a-z]([-a-z0-9]*[a-z0-9])?`.
639 +
   *   * Label values must be between 0 and 63 characters long and must conform
640 +
   *     to the regular expression `([a-z]([-a-z0-9]*[a-z0-9])?)?`.
641 +
   *   * No more than 64 labels can be associated with a given session.
642 +
   * @property {object} [gaxOptions] Request configuration options, outlined
643 +
   *     here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
644 +
   */
579 645
  /**
580 646
   * @typedef {array} CreateSessionResponse
581 647
   * @property {Session} 0 The newly created session.
@@ -637,10 +703,8 @@
Loading
637 703
    cb?: CreateSessionCallback
638 704
  ): void | Promise<CreateSessionResponse> {
639 705
    const callback =
640 -
      typeof optionsOrCallback === 'function'
641 -
        ? (optionsOrCallback as CreateSessionCallback)
642 -
        : cb!;
643 -
    const gaxOpts =
706 +
      typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;
707 +
    const options =
644 708
      typeof optionsOrCallback === 'object' && optionsOrCallback
645 709
        ? extend({}, optionsOrCallback)
646 710
        : ({} as CreateSessionOptions);
@@ -649,17 +713,17 @@
Loading
649 713
      database: this.formattedName_,
650 714
    };
651 715
652 -
    if (gaxOpts.labels) {
653 -
      reqOpts.session = {labels: gaxOpts.labels};
654 -
      delete gaxOpts.labels;
716 +
    if (options.labels) {
717 +
      reqOpts.session = {labels: options.labels};
655 718
    }
656 719
657 720
    this.request<google.spanner.v1.ISession>(
658 721
      {
659 722
        client: 'SpannerClient',
660 723
        method: 'createSession',
661 724
        reqOpts,
662 -
        gaxOpts,
725 +
        gaxOpts: options.gaxOptions,
726 +
        headers: this.resourceHeader_,
663 727
      },
664 728
      (err, resp) => {
665 729
        if (err) {
@@ -672,8 +736,16 @@
Loading
672 736
      }
673 737
    );
674 738
  }
675 -
  createTable(schema: Schema): Promise<CreateTableResponse>;
676 -
  createTable(schema: Schema, callback?: CreateTableCallback): void;
739 +
  createTable(
740 +
    schema: Schema,
741 +
    gaxOptions?: CallOptions
742 +
  ): Promise<CreateTableResponse>;
743 +
  createTable(schema: Schema, callback: CreateTableCallback): void;
744 +
  createTable(
745 +
    schema: Schema,
746 +
    gaxOptions: CallOptions,
747 +
    callback: CreateTableCallback
748 +
  ): void;
677 749
  /**
678 750
   * @typedef {array} CreateTableResponse
679 751
   * @property {Table} 0 The new {@link Table}.
@@ -697,6 +769,8 @@
Loading
697 769
   * @see {@link Database#updateSchema}
698 770
   *
699 771
   * @param {string} schema A DDL CREATE statement describing the table.
772 +
   * @param {object} [gaxOptions] Request configuration options, outlined here:
773 +
   *     https://googleapis.github.io/gax-nodejs/classes/CallSettings.html.
700 774
   * @param {CreateTableCallback} [callback] Callback function.
701 775
   * @returns {Promise<CreateTableResponse>}
702 776
   *
@@ -743,9 +817,15 @@
Loading
743 817
   */
744 818
  createTable(
745 819
    schema: Schema,
746 -
    callback?: CreateTableCallback
820 +
    gaxOptionsOrCallback?: CallOptions | CreateTableCallback,
821 +
    cb?: CreateTableCallback
747 822
  ): void | Promise<CreateTableResponse> {
748 -
    this.updateSchema(schema, (err, operation, resp) => {
823 +
    const gaxOptions =
824 +
      typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
825 +
    const callback =
826 +
      typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb!;
827 +
828 +
    this.updateSchema(schema, gaxOptions, (err, operation, resp) => {
749 829
      if (err) {
750 830
        callback!(err, null, null, resp!);
751 831
        return;
@@ -776,17 +856,21 @@
Loading
776 856
      }
777 857
    });
778 858
  }
779 -
  delete(): Promise<[r.Response]>;
859 +
  delete(gaxOptions?: CallOptions): Promise<DatabaseDeleteResponse>;
780 860
  delete(callback: DatabaseDeleteCallback): void;
861 +
  delete(gaxOptions: CallOptions, callback: DatabaseDeleteCallback): void;
781 862
  /**
782 863
   * Delete the database.
783 864
   *
784 865
   * Wrapper around {@link v1.DatabaseAdminClient#dropDatabase}.
785 866
   *
786 867
   * @see {@link v1.DatabaseAdminClient#dropDatabase}
787 868
   * @see [DropDatabase API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase)
788 -
   * @param {BasicCallback} [callback] Callback function.
789 -
   * @returns {Promise<BasicResponse>}
869 +
   *
870 +
   * @param {object} [gaxOptions] Request configuration options, outlined here:
871 +
   *     https://googleapis.github.io/gax-nodejs/classes/CallSettings.html.
872 +
   * @param {DatabaseDeleteCallback} [callback] Callback function.
873 +
   * @returns {Promise<DatabaseDeleteResponse>}
790 874
   *
791 875
   * @example
792 876
   * const {Spanner} = require('@google-cloud/spanner');
@@ -810,7 +894,15 @@
Loading
810 894
   *   const apiResponse = data[0];
811 895
   * });
812 896
   */
813 -
  delete(callback?: DatabaseDeleteCallback): void | Promise<[r.Response]> {
897 +
  delete(
898 +
    optionsOrCallback?: CallOptions | DatabaseDeleteCallback,
899 +
    cb?: DatabaseDeleteCallback
900 +
  ): void | Promise<DatabaseDeleteResponse> {
901 +
    const gaxOpts =
902 +
      typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
903 +
    const callback =
904 +
      typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;
905 +
814 906
    const reqOpts: databaseAdmin.spanner.admin.database.v1.IDropDatabaseRequest = {
815 907
      database: this.formattedName_,
816 908
    };
@@ -820,13 +912,16 @@
Loading
820 912
          client: 'DatabaseAdminClient',
821 913
          method: 'dropDatabase',
822 914
          reqOpts,
915 +
          gaxOpts,
916 +
          headers: this.resourceHeader_,
823 917
        },
824 918
        callback!
825 919
      );
826 920
    });
827 921
  }
828 -
  exists(): Promise<[boolean]>;
922 +
  exists(gaxOptions?: CallOptions): Promise<[boolean]>;
829 923
  exists(callback: ExistsCallback): void;
924 +
  exists(gaxOptions: CallOptions, callback: ExistsCallback): void;
830 925
  /**
831 926
   * @typedef {array} DatabaseExistsResponse
832 927
   * @property {boolean} 0 Whether the {@link Database} exists.
@@ -840,6 +935,8 @@
Loading
840 935
   * Check if a database exists.
841 936
   *
842 937
   * @method Database#exists
938 +
   * @param {object} [gaxOptions] Request configuration options, outlined here:
939 +
   *     https://googleapis.github.io/gax-nodejs/classes/CallSettings.html.
843 940
   * @param {DatabaseExistsCallback} [callback] Callback function.
844 941
   * @returns {Promise<DatabaseExistsResponse>}
845 942
   *
@@ -859,10 +956,18 @@
Loading
859 956
   *   const exists = data[0];
860 957
   * });
861 958
   */
862 -
  exists(callback?: ExistsCallback): void | Promise<[boolean]> {
959 +
  exists(
960 +
    gaxOptionsOrCallback?: CallOptions | ExistsCallback,
961 +
    cb?: ExistsCallback
962 +
  ): void | Promise<[boolean]> {
963 +
    const gaxOptions =
964 +
      typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
965 +
    const callback =
966 +
      typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb!;
967 +
863 968
    const NOT_FOUND = 5;
864 969
865 -
    this.getMetadata(err => {
970 +
    this.getMetadata(gaxOptions, err => {
866 971
      if (err && (err as ApiError).code !== NOT_FOUND) {
867 972
        callback!(err);
868 973
        return;
@@ -928,14 +1033,14 @@
Loading
928 1033
        : ({} as GetDatabaseConfig);
929 1034
    const callback =
930 1035
      typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
931 -
    this.getMetadata((err, metadata) => {
1036 +
    this.getMetadata(options.gaxOptions!, (err, metadata) => {
932 1037
      if (err) {
933 1038
        if (options.autoCreate && (err as ApiError).code === 5) {
934 1039
          this.create(
935 1040
            options,
936 1041
            (err, database: Database, operation: GaxOperation) => {
937 1042
              if (err) {
938 -
                callback!(err);
1043 +
                callback!(err as grpc.ServiceError);
939 1044
                return;
940 1045
              }
941 1046
              operation
@@ -954,8 +1059,9 @@
Loading
954 1059
      callback!(null, this, metadata as r.Response);
955 1060
    });
956 1061
  }
957 -
  getMetadata(): Promise<GetMetadataResponse>;
1062 +
  getMetadata(gaxOptions?: CallOptions): Promise<GetMetadataResponse>;
958 1063
  getMetadata(callback: GetMetadataCallback): void;
1064 +
  getMetadata(gaxOptions: CallOptions, callback: GetMetadataCallback): void;
959 1065
  /**
960 1066
   * @typedef {array} GetDatabaseMetadataResponse
961 1067
   * @property {object} 0 The {@link Database} metadata.
@@ -974,7 +1080,8 @@
Loading
974 1080
   *
975 1081
   * @see {@link v1.DatabaseAdminClient#getDatabase}
976 1082
   * @see [GetDatabase API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase)
977 -
   *
1083 +
   * @param {object} [gaxOptions] Request configuration options, outlined here:
1084 +
   *     https://googleapis.github.io/gax-nodejs/classes/CallSettings.html.
978 1085
   * @param {GetMetadataCallback} [callback] Callback function.
979 1086
   * @returns {Promise<GetMetadataResponse>}
980 1087
   *
@@ -1002,8 +1109,18 @@
Loading
1002 1109
   * });
1003 1110
   */
1004 1111
  getMetadata(
1005 -
    callback?: GetMetadataCallback
1112 +
    gaxOptionsOrCallback?: CallOptions | GetMetadataCallback,
1113 +
    cb?: GetMetadataCallback
1006 1114
  ): void | Promise<GetMetadataResponse> {
1115 +
    const callback =
1116 +
      typeof gaxOptionsOrCallback === 'function'
1117 +
        ? (gaxOptionsOrCallback as GetMetadataCallback)
1118 +
        : cb;
1119 +
    const gaxOpts =
1120 +
      typeof gaxOptionsOrCallback === 'object'
1121 +
        ? (gaxOptionsOrCallback as CallOptions)
1122 +
        : {};
1123 +
1007 1124
    const reqOpts: databaseAdmin.spanner.admin.database.v1.IGetDatabaseRequest = {
1008 1125
      name: this.formattedName_,
1009 1126
    };
@@ -1012,11 +1129,23 @@
Loading
1012 1129
        client: 'DatabaseAdminClient',
1013 1130
        method: 'getDatabase',
1014 1131
        reqOpts,
1132 +
        gaxOpts,
1133 +
        headers: this.resourceHeader_,
1015 1134
      },
1016 -
      callback!
1135 +
      (err, resp) => {
1136 +
        if (resp) {
1137 +
          this.metadata = resp;
1138 +
        }
1139 +
        callback!(err, resp);
1140 +
      }
1017 1141
    );
1018 1142
  }
1019 1143
1144 +
  getRestoreInfo(
1145 +
    options?: CallOptions
1146 +
  ): Promise<IRestoreInfoTranslatedEnum | undefined>;
1147 +
  getRestoreInfo(callback: GetRestoreInfoCallback): void;
1148 +
  getRestoreInfo(options: CallOptions, callback: GetRestoreInfoCallback): void;
1020 1149
  /**
1021 1150
   * {@link google.spanner.admin.database.v1#RestoreInfo} structure with restore
1022 1151
   * source type enum translated to string form.
@@ -1029,6 +1158,9 @@
Loading
1029 1158
   * @see {@link #getMetadata}
1030 1159
   *
1031 1160
   * @method Database#getRestoreInfo
1161 +
   * @param {object} [gaxOptions] Request configuration options, outlined here:
1162 +
   *     https://googleapis.github.io/gax-nodejs/classes/CallSettings.html.
1163 +
   * @param {GetRestoreInfoCallback} [callback] Callback function.
1032 1164
   * @returns {Promise<IRestoreInfoTranslatedEnum | undefined>} When resolved,
1033 1165
   *     contains the restore information for the database if it was restored
1034 1166
   *     from a backup.
@@ -1041,11 +1173,24 @@
Loading
1041 1173
   * const restoreInfo = await database.getRestoreInfo();
1042 1174
   * console.log(`Database restored from ${restoreInfo.backupInfo.backup}`);
1043 1175
   */
1044 -
  async getRestoreInfo(): Promise<IRestoreInfoTranslatedEnum | undefined> {
1045 -
    const [metadata] = await this.getMetadata();
1176 +
  async getRestoreInfo(
1177 +
    optionsOrCallback?: CallOptions | GetRestoreInfoCallback
1178 +
  ): Promise<IRestoreInfoTranslatedEnum | undefined> {
1179 +
    const gaxOptions =
1180 +
      typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
1181 +
1182 +
    const [metadata] = await this.getMetadata(gaxOptions);
1046 1183
    return metadata.restoreInfo ? metadata.restoreInfo : undefined;
1047 1184
  }
1048 1185
1186 +
  getState(
1187 +
    options?: CallOptions
1188 +
  ): Promise<
1189 +
    | EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Database.State>
1190 +
    | undefined
1191 +
  >;
1192 +
  getState(callback: GetStateCallback): void;
1193 +
  getState(options: CallOptions, callback: GetStateCallback): void;
1049 1194
  /**
1050 1195
   * Retrieves the state of the database.
1051 1196
   *
@@ -1055,6 +1200,9 @@
Loading
1055 1200
   * @see {@link #getMetadata}
1056 1201
   *
1057 1202
   * @method Database#getState
1203 +
   * @param {object} [gaxOptions] Request configuration options, outlined here:
1204 +
   *     https://googleapis.github.io/gax-nodejs/classes/CallSettings.html.
1205 +
   * @param {GetStateCallback} [callback] Callback function.
1058 1206
   * @returns {Promise<EnumKey<typeof, databaseAdmin.spanner.admin.database.v1.Database.State> | undefined>}
1059 1207
   *     When resolved, contains the current state of the database if the state
1060 1208
   *     is defined.
@@ -1067,16 +1215,22 @@
Loading
1067 1215
   * const state = await database.getState();
1068 1216
   * const isReady = (state === 'READY');
1069 1217
   */
1070 -
  async getState(): Promise<
1218 +
  async getState(
1219 +
    optionsOrCallback?: CallOptions | GetStateCallback
1220 +
  ): Promise<
1071 1221
    | EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Database.State>
1072 1222
    | undefined
1073 1223
  > {
1074 -
    const [metadata] = await this.getMetadata();
1224 +
    const gaxOptions =
1225 +
      typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
1226 +
1227 +
    const [metadata] = await this.getMetadata(gaxOptions);
1075 1228
    return metadata.state || undefined;
1076 1229
  }
1077 1230
1078 -
  getSchema(): Promise<GetSchemaResponse>;
1231 +
  getSchema(options?: CallOptions): Promise<GetSchemaResponse>;
1079 1232
  getSchema(callback: GetSchemaCallback): void;
1233 +
  getSchema(options: CallOptions, callback: GetSchemaCallback): void;
1080 1234
  /**
1081 1235
   * @typedef {array} GetSchemaResponse
1082 1236
   * @property {string[]} 0 An array of database DDL statements.
@@ -1097,6 +1251,8 @@
Loading
1097 1251
   * @see [Data Definition Language (DDL)](https://cloud.google.com/spanner/docs/data-definition-language)
1098 1252
   * @see [GetDatabaseDdl API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl)
1099 1253
   *
1254 +
   * @param {object} [gaxOptions] Request configuration options, outlined here:
1255 +
   *     https://googleapis.github.io/gax-nodejs/classes/CallSettings.html.
1100 1256
   * @param {GetSchemaCallback} [callback] Callback function.
1101 1257
   * @returns {Promise<GetSchemaResponse>}
1102 1258
   *
@@ -1117,17 +1273,25 @@
Loading
1117 1273
   *   const apiResponse = data[1];
1118 1274
   * });
1119 1275
   */
1120 -
  getSchema(callback?: GetSchemaCallback): void | Promise<GetSchemaResponse> {
1276 +
  getSchema(
1277 +
    optionsOrCallback?: CallOptions | GetSchemaCallback,
1278 +
    cb?: GetSchemaCallback
1279 +
  ): void | Promise<GetSchemaResponse> {
1280 +
    const gaxOpts =
1281 +
      typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
1282 +
    const callback =
1283 +
      typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;
1284 +
1121 1285
    const reqOpts: databaseAdmin.spanner.admin.database.v1.IGetDatabaseDdlRequest = {
1122 1286
      database: this.formattedName_,
1123 1287
    };
1124 -
    this.request<
1125 -
      databaseAdmin.spanner.admin.database.v1.IGetDatabaseDdlResponse
1126 -
    >(
1288 +
    this.request<databaseAdmin.spanner.admin.database.v1.IGetDatabaseDdlResponse>(
1127 1289
      {
1128 1290
        client: 'DatabaseAdminClient',
1129 1291
        method: 'getDatabaseDdl',
1130 1292
        reqOpts,
1293 +
        gaxOpts,
1294 +
        headers: this.resourceHeader_,
1131 1295
      },
1132 1296
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
1133 1297
      (err, statements, ...args: any[]) => {
@@ -1141,9 +1305,7 @@
Loading
1141 1305
  /**
1142 1306
   * Options object for listing sessions.
1143 1307
   *
1144 -
   * @typedef {object} GetSessionsRequest
1145 -
   * @property {boolean} [autoPaginate=true] Have pagination handled
1146 -
   *     automatically.
1308 +
   * @typedef {object} GetSessionsOptions
1147 1309
   * @property {string} [filter] An expression for filtering the results of the
1148 1310
   *     request. Filter rules are case insensitive. The fields eligible for
1149 1311
   *     filtering are:
@@ -1158,21 +1320,23 @@
Loading
1158 1320
   *     - **`labels.env:dev`** The instance's label env has the value dev.
1159 1321
   *     - **`name:howl labels.env:dev`** The instance's name is howl and it has
1160 1322
   *       the label env with value dev.
1161 -
   * @property {number} [maxApiCalls] Maximum number of API calls to make.
1162 -
   * @property {number} [maxResults] Maximum number of items to return.
1163 1323
   * @property {number} [pageSize] Maximum number of results per page.
1164 1324
   * @property {string} [pageToken] A previously-returned page token
1165 1325
   *     representing part of the larger set of results to view.
1326 +
   * @property {object} [gaxOptions] Request configuration options, outlined
1327 +
   *     here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
1166 1328
   */
1167 1329
  /**
1168 1330
   * @typedef {array} GetSessionsResponse
1169 1331
   * @property {Session[]} 0 Array of {@link Session} instances.
1170 -
   * @property {object} 1 The full API response.
1332 +
   * @property {object} 1 A query object to receive more results.
1333 +
   * @property {object} 2 The full API response.
1171 1334
   */
1172 1335
  /**
1173 1336
   * @callback GetSessionsCallback
1174 1337
   * @param {?Error} err Request error, if any.
1175 1338
   * @param {Session[]} instances Array of {@link Session} instances.
1339 +
   * @param {object} nextQuery A query object to receive more results.
1176 1340
   * @param {object} apiResponse The full API response.
1177 1341
   */
1178 1342
  /**
@@ -1210,7 +1374,7 @@
Loading
1210 1374
   * }
1211 1375
   *
1212 1376
   * database.getInstances({
1213 -
   *   autoPaginate: false
1377 +
   *   gaxOptions: {autoPaginate: false}
1214 1378
   * }, callback);
1215 1379
   *
1216 1380
   * //-
@@ -1227,19 +1391,32 @@
Loading
1227 1391
    // eslint-disable-next-line @typescript-eslint/no-this-alias
1228 1392
    const self = this;
1229 1393
    const callback =
1230 -
      typeof optionsOrCallback === 'function'
1231 -
        ? (optionsOrCallback as GetSessionsCallback)
1232 -
        : cb;
1394 +
      typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
1233 1395
    const options =
1234 1396
      typeof optionsOrCallback === 'object'
1235 -
        ? (optionsOrCallback as GetSessionsOptions)
1236 -
        : {gaxOptions: {}};
1237 -
    const gaxOpts: CallOptions = options.gaxOptions as CallOptions;
1238 -
    const reqOpts = extend({}, options, {
1397 +
        ? optionsOrCallback
1398 +
        : ({} as GetSessionsOptions);
1399 +
    const gaxOpts = extend(true, {}, options.gaxOptions);
1400 +
    let reqOpts = extend({}, options, {
1239 1401
      database: this.formattedName_,
1240 1402
    });
1241 -
1242 1403
    delete reqOpts.gaxOptions;
1404 +
1405 +
    // Copy over pageSize and pageToken values from gaxOptions.
1406 +
    // However values set on options take precedence.
1407 +
    if (gaxOpts) {
1408 +
      reqOpts = extend(
1409 +
        {},
1410 +
        {
1411 +
          pageSize: gaxOpts.pageSize,
1412 +
          pageToken: gaxOpts.pageToken,
1413 +
        },
1414 +
        reqOpts
1415 +
      );
1416 +
      delete gaxOpts.pageSize;
1417 +
      delete gaxOpts.pageToken;
1418 +
    }
1419 +
1243 1420
    this.request<
1244 1421
      google.spanner.v1.ISession,
1245 1422
      google.spanner.v1.IListSessionsResponse
@@ -1249,8 +1426,9 @@
Loading
1249 1426
        method: 'listSessions',
1250 1427
        reqOpts,
1251 1428
        gaxOpts,
1429 +
        headers: this.resourceHeader_,
1252 1430
      },
1253 -
      (err, sessions, ...args) => {
1431 +
      (err, sessions, nextPageRequest, ...args) => {
1254 1432
        let sessionInstances: Session[] | null = null;
1255 1433
        if (sessions) {
1256 1434
          sessionInstances = sessions.map(metadata => {
@@ -1259,10 +1437,84 @@
Loading
1259 1437
            return session;
1260 1438
          });
1261 1439
        }
1262 -
        callback!(err, sessionInstances!, ...args);
1440 +
        const nextQuery = nextPageRequest!
1441 +
          ? extend({}, options, nextPageRequest!)
1442 +
          : null;
1443 +
        callback!(err, sessionInstances!, nextQuery, ...args);
1263 1444
      }
1264 1445
    );
1265 1446
  }
1447 +
1448 +
  /**
1449 +
   * Get a list of sessions as a readable object stream.
1450 +
   *
1451 +
   * Wrapper around {@link v1.SpannerClient#listSessions}
1452 +
   *
1453 +
   * @see {@link v1.SpannerClient#listSessions}
1454 +
   * @see [ListSessions API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.ListSessions)
1455 +
   *
1456 +
   * @method Spanner#getSessionsStream
1457 +
   * @param {GetSessionsOptions} [options] Options object for listing sessions.
1458 +
   * @returns {ReadableStream} A readable stream that emits {@link Session}
1459 +
   *     instances.
1460 +
   *
1461 +
   * @example
1462 +
   * const {Spanner} = require('@google-cloud/spanner');
1463 +
   * const spanner = new Spanner();
1464 +
   *
1465 +
   * const instance = spanner.instance('my-instance');
1466 +
   * const database = instance.database('my-database');
1467 +
   *
1468 +
   * database.getSessionsStream()
1469 +
   *   .on('error', console.error)
1470 +
   *   .on('data', function(database) {
1471 +
   *     // `sessions` is a `Session` object.
1472 +
   *   })
1473 +
   *   .on('end', function() {
1474 +
   *     // All sessions retrieved.
1475 +
   *   });
1476 +
   *
1477 +
   * //-
1478 +
   * // If you anticipate many results, you can end a stream early to prevent
1479 +
   * // unnecessary processing and API requests.
1480 +
   * //-
1481 +
   * database.getSessionsStream()
1482 +
   *   .on('data', function(session) {
1483 +
   *     this.end();
1484 +
   *   });
1485 +
   */
1486 +
  getSessionsStream(options: GetSessionsOptions = {}): NodeJS.ReadableStream {
1487 +
    const gaxOpts = extend(true, {}, options.gaxOptions);
1488 +
1489 +
    let reqOpts = extend({}, options, {
1490 +
      database: this.formattedName_,
1491 +
    });
1492 +
    delete reqOpts.gaxOptions;
1493 +
1494 +
    // Copy over pageSize and pageToken values from gaxOptions.
1495 +
    // However values set on options take precedence.
1496 +
    if (gaxOpts) {
1497 +
      reqOpts = extend(
1498 +
        {},
1499 +
        {
1500 +
          pageSize: gaxOpts.pageSize,
1501 +
          pageToken: gaxOpts.pageToken,
1502 +
        },
1503 +
        reqOpts
1504 +
      );
1505 +
      delete gaxOpts.pageSize;
1506 +
      delete gaxOpts.pageToken;
1507 +
    }
1508 +
1509 +
    return this.requestStream({
1510 +
      client: 'SpannerClient',
1511 +
      method: 'listSessionsStream',
1512 +
      reqOpts,
1513 +
      gaxOpts,
1514 +
      headers: this.resourceHeader_,
1515 +
    });
1516 +
  }
1517 +
1266 1518
  getSnapshot(options?: TimestampBounds): Promise<[Snapshot]>;
1267 1519
  getSnapshot(callback: GetSnapshotCallback): void;
1268 1520
  getSnapshot(options: TimestampBounds, callback: GetSnapshotCallback): void;
@@ -1284,6 +1536,12 @@
Loading
1284 1536
   * called to release the underlying {@link Session}. **Failure to do could
1285 1537
   * result in a Session leak.**
1286 1538
   *
1539 +
   * **NOTE:** Since the returned {@link Snapshot} transaction is not a
1540 +
   * single-use transaction, it is invalid to set the `minReadTimestamp` and
1541 +
   * `maxStaleness` parameters in {@link TimestampBounds} as those parameters
1542 +
   * can only be set for single-use transactions.
1543 +
   * https://cloud.google.com/spanner/docs/reference/rest/v1/TransactionOptions#bounded-staleness
1544 +
   *
1287 1545
   * @see {@link v1.SpannerClient#beginTransaction}
1288 1546
   *
1289 1547
   * @param {TimestampBounds} [options] Timestamp bounds.
@@ -1404,10 +1662,18 @@
Loading
1404 1662
      if (!err) {
1405 1663
        this._releaseOnEnd(session!, transaction!);
1406 1664
      }
1407 -
      callback!(err, transaction);
1665 +
      callback!(err as grpc.ServiceError | null, transaction);
1408 1666
    });
1409 1667
  }
1410 1668
1669 +
  getOperations(
1670 +
    options?: GetDatabaseOperationsOptions
1671 +
  ): Promise<GetDatabaseOperationsResponse>;
1672 +
  getOperations(callback: GetDatabaseOperationsCallback): void;
1673 +
  getOperations(
1674 +
    options: GetDatabaseOperationsOptions,
1675 +
    callback: GetDatabaseOperationsCallback
1676 +
  ): void;
1411 1677
  /**
1412 1678
   * Query object for listing database operations.
1413 1679
   *
@@ -1418,6 +1684,9 @@
Loading
1418 1684
   * @property {number} [pageSize] Maximum number of results per page.
1419 1685
   * @property {string} [pageToken] A previously-returned page token
1420 1686
   *     representing part of the larger set of results to view.
1687 +
   * @property {object} [gaxOptions] Request configuration options, outlined
1688 +
   *     here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
1689 +
   * @param {GetDatabaseOperationsCallback} [callback] Callback function.
1421 1690
   */
1422 1691
  /**
1423 1692
   * @typedef {array} GetDatabaseOperationsResponse
@@ -1459,8 +1728,12 @@
Loading
1459 1728
   * } while (pageToken);
1460 1729
   */
1461 1730
  async getOperations(
1462 -
    options?: GetDatabaseOperationsOptions
1731 +
    optionsOrCallback?:
1732 +
      | GetDatabaseOperationsOptions
1733 +
      | GetDatabaseOperationsCallback
1463 1734
  ): Promise<GetDatabaseOperationsResponse> {
1735 +
    const options =
1736 +
      typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
1464 1737
    // Create a query that lists database operations only on this database from
1465 1738
    // the instance. Operation name will be prefixed with the database path for
1466 1739
    // all operations on this database
@@ -1529,7 +1802,7 @@
Loading
1529 1802
        requestStream.cancel();
1530 1803
      }
1531 1804
    };
1532 -
    function destroyStream(err: ServiceError) {
1805 +
    function destroyStream(err: grpc.ServiceError) {
1533 1806
      waitForSessionStream.destroy(err);
1534 1807
    }
1535 1808
    function releaseSession() {
@@ -1628,6 +1901,7 @@
Loading
1628 1901
        method: 'restoreDatabase',
1629 1902
        reqOpts,
1630 1903
        gaxOpts,
1904 +
        headers: this.resourceHeader_,
1631 1905
      },
1632 1906
      (err, operation, resp) => {
1633 1907
        if (err) {
@@ -1859,20 +2133,41 @@
Loading
1859 2133
        return;
1860 2134
      }
1861 2135
1862 -
      const transaction = session!.partitionedDml();
2136 +
      this._runPartitionedUpdate(session!, query, callback);
2137 +
    });
2138 +
  }
2139 +
2140 +
  _runPartitionedUpdate(
2141 +
    session: Session,
2142 +
    query: string | ExecuteSqlRequest,
2143 +
    callback?: RunUpdateCallback
2144 +
  ): void | Promise<number> {
2145 +
    const transaction = session.partitionedDml();
1863 2146
1864 -
      transaction.begin(err => {
2147 +
    transaction.begin(err => {
2148 +
      if (err) {
2149 +
        this.pool_.release(session!);
2150 +
        callback!(err, 0);
2151 +
        return;
2152 +
      }
2153 +
2154 +
      transaction.runUpdate(query, (err, updateCount) => {
1865 2155
        if (err) {
2156 +
          if (err.code !== grpc.status.ABORTED) {
2157 +
            this.pool_.release(session!);
2158 +
            callback!(err, 0);
2159 +
            return;
2160 +
          }
2161 +
          this._runPartitionedUpdate(session, query, callback);
2162 +
        } else {
1866 2163
          this.pool_.release(session!);
1867 -
          callback!(err, 0);
2164 +
          callback!(null, updateCount);
1868 2165
          return;
1869 2166
        }
1870 -
1871 -
        this._releaseOnEnd(session!, transaction);
1872 -
        transaction.runUpdate(query, callback!);
1873 2167
      });
1874 2168
    });
1875 2169
  }
2170 +
1876 2171
  /**
1877 2172
   * Create a readable object stream to receive resulting rows from a SQL
1878 2173
   * statement.
@@ -2018,12 +2313,15 @@
Loading
2018 2313
      dataStream
2019 2314
        .once('data', () => (dataReceived = true))
2020 2315
        .once('error', err => {
2021 -
          if (!dataReceived && isSessionNotFoundError(err)) {
2316 +
          if (
2317 +
            !dataReceived &&
2318 +
            isSessionNotFoundError(err as grpc.ServiceError)
2319 +
          ) {
2022 2320
            // If it is a 'Session not found' error and we have not yet received
2023 2321
            // any data, we can safely retry the query on a new session.
2024 2322
            // Register the error on the session so the pool can discard it.
2025 2323
            if (session) {
2026 -
              session.lastError = err;
2324 +
              session.lastError = err as grpc.ServiceError;
2027 2325
            }
2028 2326
            // Remove the current data stream from the end user stream.
2029 2327
            dataStream.unpipe(proxyStream);
@@ -2141,12 +2439,12 @@
Loading
2141 2439
        : {};
2142 2440
2143 2441
    this.pool_.getWriteSession((err, session?, transaction?) => {
2144 -
      if (err && isSessionNotFoundError(err)) {
2442 +
      if (err && isSessionNotFoundError(err as grpc.ServiceError)) {
2145 2443
        this.runTransaction(options, runFn!);
2146 2444
        return;
2147 2445
      }
2148 2446
      if (err) {
2149 -
        runFn!(err);
2447 +
        runFn!(err as grpc.ServiceError);
2150 2448
        return;
2151 2449
      }
2152 2450
@@ -2307,8 +2605,16 @@
Loading
2307 2605
    }
2308 2606
    return new Table(this, name);
2309 2607
  }
2310 -
  updateSchema(statements: Schema): Promise<UpdateSchemaResponse>;
2608 +
  updateSchema(
2609 +
    statements: Schema,
2610 +
    gaxOptions?: CallOptions
2611 +
  ): Promise<UpdateSchemaResponse>;
2311 2612
  updateSchema(statements: Schema, callback: UpdateSchemaCallback): void;
2613 +
  updateSchema(
2614 +
    statements: Schema,
2615 +
    gaxOptions: CallOptions,
2616 +
    callback: UpdateSchemaCallback
2617 +
  ): void;
2312 2618
  /**
2313 2619
   * Update the schema of the database by creating/altering/dropping tables,
2314 2620
   * columns, indexes, etc.
@@ -2327,6 +2633,8 @@
Loading
2327 2633
   * @param {string|string[]|object} statements An array of database DDL
2328 2634
   *     statements, or an
2329 2635
   *     [`UpdateDatabaseDdlRequest` object](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.UpdateDatabaseDdlRequest).
2636 +
   * @param {object} [gaxOptions] Request configuration options, outlined here:
2637 +
   *     https://googleapis.github.io/gax-nodejs/classes/CallSettings.html.
2330 2638
   * @param {LongRunningOperationCallback} [callback] Callback function.
2331 2639
   * @returns {Promise<LongRunningOperationResponse>}
2332 2640
   *
@@ -2384,8 +2692,14 @@
Loading
2384 2692
   */
2385 2693
  updateSchema(
2386 2694
    statements: Schema,
2387 -
    callback?: UpdateSchemaCallback
2695 +
    optionsOrCallback?: CallOptions | UpdateSchemaCallback,
2696 +
    cb?: UpdateSchemaCallback
2388 2697
  ): Promise<UpdateSchemaResponse> | void {
2698 +
    const gaxOpts =
2699 +
      typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
2700 +
    const callback =
2701 +
      typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;
2702 +
2389 2703
    if (typeof statements === 'string' || Array.isArray(statements)) {
2390 2704
      statements = {
2391 2705
        statements: arrify(statements) as string[],
@@ -2402,6 +2716,8 @@
Loading
2402 2716
        client: 'DatabaseAdminClient',
2403 2717
        method: 'updateDatabaseDdl',
2404 2718
        reqOpts,
2719 +
        gaxOpts,
2720 +
        headers: this.resourceHeader_,
2405 2721
      },
2406 2722
      callback!
2407 2723
    );
@@ -2439,17 +2755,49 @@
Loading
2439 2755
promisifyAll(Database, {
2440 2756
  exclude: [
2441 2757
    'batchTransaction',
2442 -
    'getMetadata',
2443 2758
    'getRestoreInfo',
2444 2759
    'getState',
2445 2760
    'getOperations',
2446 2761
    'runTransaction',
2762 +
    'runTransactionAsync',
2447 2763
    'table',
2448 -
    'updateSchema',
2449 2764
    'session',
2450 2765
  ],
2451 2766
});
2452 2767
2768 +
/*! Developer Documentation
2769 +
 *
2770 +
 * All async methods (except for streams) will return a Promise in the event
2771 +
 * that a callback is omitted.
2772 +
 */
2773 +
callbackifyAll(Database, {
2774 +
  exclude: [
2775 +
    'create',
2776 +
    'batchCreateSessions',
2777 +
    'batchTransaction',
2778 +
    'close',
2779 +
    'createBatchTransaction',
2780 +
    'createSession',
2781 +
    'createTable',
2782 +
    'delete',
2783 +
    'exists',
2784 +
    'get',
2785 +
    'getMetadata',
2786 +
    'getSchema',
2787 +
    'getSessions',
2788 +
    'getSnapshot',
2789 +
    'getTransaction',
2790 +
    'restore',
2791 +
    'run',
2792 +
    'runPartitionedUpdate',
2793 +
    'runTransaction',
2794 +
    'runTransactionAsync',
2795 +
    'session',
2796 +
    'table',
2797 +
    'updateSchema',
2798 +
  ],
2799 +
});
2800 +
2453 2801
/**
2454 2802
 * Reference to the {@link Database} class.
2455 2803
 * @name module:@google-cloud/spanner.Database

@@ -13,18 +13,24 @@
Loading
13 13
 * limitations under the License.
14 14
 */
15 15
16 -
import {promisifyAll} from '@google-cloud/promisify';
16 +
import {promisifyAll, callbackifyAll} from '@google-cloud/promisify';
17 17
import {Instance} from './instance';
18 18
import {
19 19
  IOperation,
20 20
  LongRunningCallback,
21 21
  RequestCallback,
22 22
  ResourceCallback,
23 +
  NormalCallback,
24 +
  CLOUD_RESOURCE_HEADER,
23 25
} from './common';
24 26
import {EnumKey, Spanner, RequestConfig, TranslateEnumKeys} from '.';
25 -
import {Metadata, Operation as GaxOperation} from 'google-gax';
27 +
import {
28 +
  grpc,
29 +
  CallOptions,
30 +
  Metadata,
31 +
  Operation as GaxOperation,
32 +
} from 'google-gax';
26 33
import {DateStruct, PreciseDate} from '@google-cloud/precise-date';
27 -
import {CallOptions, status} from 'grpc';
28 34
import {google as databaseAdmin} from '../protos/protos';
29 35
import {common as p} from 'protobufjs';
30 36
@@ -60,11 +66,9 @@
Loading
60 66
export type GetMetadataResponse = [IBackupTranslatedEnum];
61 67
type GetMetadataCallback = RequestCallback<IBackupTranslatedEnum>;
62 68
63 -
type UpdateExpireTimeCallback = RequestCallback<
64 -
  databaseAdmin.spanner.admin.database.v1.IBackup
65 -
>;
69 +
type UpdateExpireTimeCallback = RequestCallback<databaseAdmin.spanner.admin.database.v1.IBackup>;
66 70
67 -
type DeleteCallback = RequestCallback<void>;
71 +
type DeleteCallback = RequestCallback<databaseAdmin.protobuf.IEmpty>;
68 72
69 73
interface BackupRequest {
70 74
  (
@@ -73,6 +77,11 @@
Loading
73 77
  ): void;
74 78
  <T>(config: RequestConfig, callback: RequestCallback<T>): void;
75 79
}
80 +
export type GetStateCallback = NormalCallback<
81 +
  EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Backup.State>
82 +
>;
83 +
export type GetExpireTimeCallback = NormalCallback<PreciseDate>;
84 +
export type ExistsCallback = NormalCallback<boolean>;
76 85
/**
77 86
 * The {@link Backup} class represents a Cloud Spanner backup.
78 87
 *
@@ -90,12 +99,17 @@
Loading
90 99
  id: string;
91 100
  formattedName_: string;
92 101
  instanceFormattedName_: string;
102 +
  resourceHeader_: {[k: string]: string};
93 103
  request: BackupRequest;
104 +
  metadata?: databaseAdmin.spanner.admin.database.v1.IBackup;
94 105
  constructor(instance: Instance, name: string) {
95 106
    this.request = instance.request;
96 107
    this.instanceFormattedName_ = instance.formattedName_;
97 108
    this.formattedName_ = Backup.formatName_(instance.formattedName_, name);
98 109
    this.id = this.formattedName_.split('/').pop() || '';
110 +
    this.resourceHeader_ = {
111 +
      [CLOUD_RESOURCE_HEADER]: this.instanceFormattedName_,
112 +
    };
99 113
  }
100 114
101 115
  create(options: CreateBackupOptions): Promise<CreateBackupResponse>;
@@ -154,7 +168,7 @@
Loading
154 168
    options: CreateBackupOptions,
155 169
    callback?: CreateBackupCallback
156 170
  ): Promise<CreateBackupResponse> | void {
157 -
    const gaxOpts: CallOptions = options.gaxOptions as CallOptions;
171 +
    const gaxOpts = options.gaxOptions;
158 172
    const reqOpts: databaseAdmin.spanner.admin.database.v1.ICreateBackupRequest = {
159 173
      parent: this.instanceFormattedName_,
160 174
      backupId: this.id,
@@ -164,12 +178,13 @@
Loading
164 178
        name: this.formattedName_,
165 179
      },
166 180
    };
167 -
    return this.request(
181 +
    this.request(
168 182
      {
169 183
        client: 'DatabaseAdminClient',
170 184
        method: 'createBackup',
171 185
        reqOpts,
172 186
        gaxOpts,
187 +
        headers: this.resourceHeader_,
173 188
      },
174 189
      (err, operation, resp) => {
175 190
        if (err) {
@@ -181,7 +196,6 @@
Loading
181 196
    );
182 197
  }
183 198
184 -
  getMetadata(): Promise<GetMetadataResponse>;
185 199
  getMetadata(gaxOptions?: CallOptions): Promise<GetMetadataResponse>;
186 200
  getMetadata(callback: GetMetadataCallback): void;
187 201
  getMetadata(gaxOptions: CallOptions, callback: GetMetadataCallback): void;
@@ -231,19 +245,29 @@
Loading
231 245
    const reqOpts: databaseAdmin.spanner.admin.database.v1.IGetBackupRequest = {
232 246
      name: this.formattedName_,
233 247
    };
234 -
    return this.request<IBackupTranslatedEnum>(
248 +
    this.request<IBackupTranslatedEnum>(
235 249
      {
236 250
        client: 'DatabaseAdminClient',
237 251
        method: 'getBackup',
238 252
        reqOpts,
239 253
        gaxOpts,
254 +
        headers: this.resourceHeader_,
240 255
      },
241 256
      (err, response) => {
257 +
        if (response) {
258 +
          this.metadata = response;
259 +
        }
242 260
        callback!(err, response);
243 261
      }
244 262
    );
245 263
  }
246 264
265 +
  getState(): Promise<
266 +
    | EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Backup.State>
267 +
    | undefined
268 +
    | null
269 +
  >;
270 +
  getState(callback: GetStateCallback): void;
247 271
  /**
248 272
   * Retrieves the state of the backup.
249 273
   *
@@ -252,6 +276,7 @@
Loading
252 276
   * @see {@link #getMetadata}
253 277
   *
254 278
   * @method Backup#getState
279 +
   * @param {GetStateCallback} [callback] Callback function.
255 280
   * @returns {Promise<EnumKey<typeof, databaseAdmin.spanner.admin.database.v1.Backup.State> | undefined>}
256 281
   *     When resolved, contains the current state of the backup if it exists.
257 282
   *
@@ -266,11 +291,14 @@
Loading
266 291
  async getState(): Promise<
267 292
    | EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Backup.State>
268 293
    | undefined
294 +
    | null
269 295
  > {
270 296
    const [backupInfo] = await this.getMetadata();
271 -
    return backupInfo.state || undefined;
297 +
    return backupInfo.state;
272 298
  }
273 299
300 +
  getExpireTime(): Promise<PreciseDate | undefined>;
301 +
  getExpireTime(callback: GetExpireTimeCallback): void;
274 302
  /**
275 303
   * Retrieves the expiry time of the backup.
276 304
   *
@@ -294,6 +322,8 @@
Loading
294 322
    return new PreciseDate(backupInfo.expireTime as DateStruct);
295 323
  }
296 324
325 +
  exists(): Promise<boolean>;
326 +
  exists(callback: ExistsCallback): void;
297 327
  /**
298 328
   * Checks whether the backup exists.
299 329
   *
@@ -318,7 +348,7 @@
Loading
318 348
      // Found therefore it exists
319 349
      return true;
320 350
    } catch (err) {
321 -
      if (err.code === status.NOT_FOUND) {
351 +
      if (err.code === grpc.status.NOT_FOUND) {
322 352
        return false;
323 353
      }
324 354
      // Some other error occurred, rethrow
@@ -393,21 +423,21 @@
Loading
393 423
        paths: ['expire_time'],
394 424
      },
395 425
    };
396 -
    return this.request<databaseAdmin.spanner.admin.database.v1.IBackup>(
426 +
    this.request<databaseAdmin.spanner.admin.database.v1.IBackup>(
397 427
      {
398 428
        client: 'DatabaseAdminClient',
399 429
        method: 'updateBackup',
400 430
        reqOpts,
401 431
        gaxOpts,
432 +
        headers: this.resourceHeader_,
402 433
      },
403 434
      (err, response) => {
404 435
        callback!(err, response);
405 436
      }
406 437
    );
407 438
  }
408 439
409 -
  delete(): Promise<void>;
410 -
  delete(gaxOptions?: CallOptions): Promise<void>;
440 +
  delete(gaxOptions?: CallOptions): Promise<databaseAdmin.protobuf.IEmpty>;
411 441
  delete(callback: DeleteCallback): void;
412 442
  delete(gaxOptions: CallOptions, callback: DeleteCallback): void;
413 443
  /**
@@ -429,7 +459,7 @@
Loading
429 459
  delete(
430 460
    gaxOptionsOrCallback?: CallOptions | DeleteCallback,
431 461
    cb?: DeleteCallback
432 -
  ): void | Promise<void> {
462 +
  ): void | Promise<databaseAdmin.protobuf.IEmpty> {
433 463
    const callback =
434 464
      typeof gaxOptionsOrCallback === 'function'
435 465
        ? (gaxOptionsOrCallback as DeleteCallback)
@@ -441,12 +471,13 @@
Loading
441 471
    const reqOpts: databaseAdmin.spanner.admin.database.v1.IDeleteBackupRequest = {
442 472
      name: this.formattedName_,
443 473
    };
444 -
    return this.request<databaseAdmin.spanner.admin.database.v1.IBackup>(
474 +
    this.request<databaseAdmin.spanner.admin.database.v1.IBackup>(
445 475
      {
446 476
        client: 'DatabaseAdminClient',
447 477
        method: 'deleteBackup',
448 478
        reqOpts,
449 479
        gaxOpts,
480 +
        headers: this.resourceHeader_,
450 481
      },
451 482
      err => {
452 483
        callback!(err);
@@ -488,6 +519,15 @@
Loading
488 519
  exclude: ['getState', 'getExpireTime', 'exists'],
489 520
});
490 521
522 +
/*! Developer Documentation
523 +
 *
524 +
 * All async methods (except for streams) will return a Promise in the event
525 +
 * that a callback is omitted.
526 +
 */
527 +
callbackifyAll(Backup, {
528 +
  exclude: ['create', 'getMetadata', 'updateExpireTime', 'delete'],
529 +
});
530 +
491 531
/**
492 532
 * Reference to the {@link Backup} class.
493 533
 * @name module:@google-cloud/spanner.Backup