@google-cloud/spanner 5.16.2 → 5.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +25 -12
  3. package/build/protos/google/spanner/admin/database/v1/backup.proto +177 -9
  4. package/build/protos/google/spanner/admin/database/v1/common.proto +14 -2
  5. package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +40 -5
  6. package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +8 -5
  7. package/build/protos/google/spanner/v1/commit_response.proto +2 -4
  8. package/build/protos/google/spanner/v1/keys.proto +0 -1
  9. package/build/protos/google/spanner/v1/mutation.proto +5 -5
  10. package/build/protos/google/spanner/v1/query_plan.proto +18 -19
  11. package/build/protos/google/spanner/v1/result_set.proto +1 -1
  12. package/build/protos/google/spanner/v1/spanner.proto +21 -19
  13. package/build/protos/google/spanner/v1/transaction.proto +19 -32
  14. package/build/protos/google/spanner/v1/type.proto +33 -7
  15. package/build/protos/protos.d.ts +463 -64
  16. package/build/protos/protos.js +1267 -182
  17. package/build/protos/protos.json +221 -21
  18. package/build/src/backup.d.ts +22 -4
  19. package/build/src/backup.js +60 -29
  20. package/build/src/codec.d.ts +11 -0
  21. package/build/src/codec.js +41 -3
  22. package/build/src/database.d.ts +1 -1
  23. package/build/src/database.js +2 -2
  24. package/build/src/index.d.ts +20 -5
  25. package/build/src/index.js +26 -7
  26. package/build/src/instance.d.ts +44 -5
  27. package/build/src/instance.js +61 -6
  28. package/build/src/partial-result-stream.js +3 -0
  29. package/build/src/session-pool.d.ts +4 -4
  30. package/build/src/session-pool.js +6 -6
  31. package/build/src/transaction.js +1 -1
  32. package/build/src/v1/database_admin_client.d.ts +175 -10
  33. package/build/src/v1/database_admin_client.js +113 -11
  34. package/build/src/v1/database_admin_client_config.json +5 -0
  35. package/build/src/v1/instance_admin_client.js +2 -3
  36. package/build/src/v1/spanner_client.d.ts +1 -31
  37. package/build/src/v1/spanner_client.js +11 -9
  38. package/package.json +4 -4
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.codec = exports.Numeric = exports.Struct = exports.Int = exports.Float = exports.SpannerDate = void 0;
3
+ exports.codec = exports.PGNumeric = exports.Numeric = exports.Struct = exports.Int = exports.Float = exports.SpannerDate = void 0;
4
4
  /*!
5
5
  * Copyright 2017 Google Inc. All Rights Reserved.
6
6
  *
@@ -22,6 +22,7 @@ const arrify = require("arrify");
22
22
  const big_js_1 = require("big.js");
23
23
  const is = require("is");
24
24
  const protos_1 = require("../protos/protos");
25
+ const google_gax_1 = require("google-gax");
25
26
  /**
26
27
  * Date-like object used to represent Cloud Spanner Dates. DATE types represent
27
28
  * a logical calendar date, independent of time zone. DATE values do not
@@ -117,7 +118,7 @@ class Int extends WrappedNumber {
117
118
  valueOf() {
118
119
  const num = Number(this.value);
119
120
  if (num > Number.MAX_SAFE_INTEGER) {
120
- throw new Error(`Integer ${this.value} is out of bounds.`);
121
+ throw new google_gax_1.GoogleError(`Integer ${this.value} is out of bounds.`);
121
122
  }
122
123
  return num;
123
124
  }
@@ -181,6 +182,25 @@ class Numeric {
181
182
  }
182
183
  }
183
184
  exports.Numeric = Numeric;
185
+ /**
186
+ * @typedef PGNumeric
187
+ * @see Spanner.pgNumeric
188
+ */
189
+ class PGNumeric {
190
+ constructor(pgValue) {
191
+ this.value = pgValue.toString();
192
+ }
193
+ valueOf() {
194
+ if (this.value.toLowerCase() === 'nan') {
195
+ throw new Error(`${this.value} cannot be converted to a numeric value`);
196
+ }
197
+ return new big_js_1.Big(this.value);
198
+ }
199
+ toJSON() {
200
+ return this.valueOf().toJSON();
201
+ }
202
+ }
203
+ exports.PGNumeric = PGNumeric;
184
204
  /**
185
205
  * @typedef JSONOptions
186
206
  * @property {boolean} [wrapNumbers=false] Indicates if the numbers should be
@@ -286,6 +306,12 @@ function decode(value, type) {
286
306
  break;
287
307
  case protos_1.google.spanner.v1.TypeCode.NUMERIC:
288
308
  case 'NUMERIC':
309
+ if (type.typeAnnotation ===
310
+ protos_1.google.spanner.v1.TypeAnnotationCode.PG_NUMERIC ||
311
+ type.typeAnnotation === 'PG_NUMERIC') {
312
+ decoded = new PGNumeric(decoded);
313
+ break;
314
+ }
289
315
  decoded = new Numeric(decoded);
290
316
  break;
291
317
  case protos_1.google.spanner.v1.TypeCode.TIMESTAMP:
@@ -353,6 +379,9 @@ function encodeValue(value) {
353
379
  if (value instanceof Numeric) {
354
380
  return value.value;
355
381
  }
382
+ if (value instanceof PGNumeric) {
383
+ return value.value;
384
+ }
356
385
  if (Buffer.isBuffer(value)) {
357
386
  return value.toString('base64');
358
387
  }
@@ -379,6 +408,7 @@ const TypeCode = {
379
408
  int64: 'INT64',
380
409
  float64: 'FLOAT64',
381
410
  numeric: 'NUMERIC',
411
+ pgNumeric: 'NUMERIC',
382
412
  timestamp: 'TIMESTAMP',
383
413
  date: 'DATE',
384
414
  string: 'STRING',
@@ -435,6 +465,9 @@ function getType(value) {
435
465
  if (value instanceof Numeric) {
436
466
  return { type: 'numeric' };
437
467
  }
468
+ if (value instanceof PGNumeric) {
469
+ return { type: 'pgNumeric' };
470
+ }
438
471
  if (is.boolean(value)) {
439
472
  return { type: 'bool' };
440
473
  }
@@ -527,7 +560,7 @@ function createTypeObject(friendlyType) {
527
560
  if (!friendlyType) {
528
561
  friendlyType = 'unspecified';
529
562
  }
530
- if (is.string(friendlyType)) {
563
+ if (typeof friendlyType === 'string') {
531
564
  friendlyType = { type: friendlyType };
532
565
  }
533
566
  const config = friendlyType;
@@ -545,6 +578,10 @@ function createTypeObject(friendlyType) {
545
578
  }),
546
579
  };
547
580
  }
581
+ if (friendlyType.type === 'pgNumeric') {
582
+ type.typeAnnotation =
583
+ protos_1.google.spanner.v1.TypeAnnotationCode.PG_NUMERIC;
584
+ }
548
585
  return type;
549
586
  }
550
587
  exports.codec = {
@@ -556,6 +593,7 @@ exports.codec = {
556
593
  Float,
557
594
  Int,
558
595
  Numeric,
596
+ PGNumeric,
559
597
  convertFieldsToJson,
560
598
  decode,
561
599
  encode,
@@ -1547,7 +1547,7 @@ declare class Database extends common.GrpcServiceObject {
1547
1547
  /**
1548
1548
  * Get a reference to a Table object.
1549
1549
  *
1550
- * @throws {Error} If a name is not provided.
1550
+ * @throws {GoogleError} If a name is not provided.
1551
1551
  *
1552
1552
  * @param {string} name The name of the table.
1553
1553
  * @return {Table} A Table object.
@@ -1048,7 +1048,7 @@ class Database extends common.GrpcServiceObject {
1048
1048
  /**
1049
1049
  * Get a reference to a Table object.
1050
1050
  *
1051
- * @throws {Error} If a name is not provided.
1051
+ * @throws {GoogleError} If a name is not provided.
1052
1052
  *
1053
1053
  * @param {string} name The name of the table.
1054
1054
  * @return {Table} A Table object.
@@ -1066,7 +1066,7 @@ class Database extends common.GrpcServiceObject {
1066
1066
  */
1067
1067
  table(name) {
1068
1068
  if (!name) {
1069
- throw new Error('A name is required to access a Table object.');
1069
+ throw new google_gax_1.GoogleError('A name is required to access a Table object.');
1070
1070
  }
1071
1071
  return new table_1.Table(this, name);
1072
1072
  }
@@ -18,12 +18,12 @@ import { GrpcService } from './common-grpc/service';
18
18
  import { PreciseDate } from '@google-cloud/precise-date';
19
19
  import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';
20
20
  import { common as p } from 'protobufjs';
21
- import { Float, Int, Numeric, Struct } from './codec';
21
+ import { Float, Int, Numeric, PGNumeric, Struct } from './codec';
22
22
  import { Backup } from './backup';
23
23
  import { Database } from './database';
24
24
  import { Instance, CreateInstanceCallback, CreateInstanceResponse } from './instance';
25
25
  import { grpc, GrpcClientOptions, CallOptions } from 'google-gax';
26
- import { google as instanceAdmin } from '../protos/protos';
26
+ import { google, google as instanceAdmin } from '../protos/protos';
27
27
  import { PagedOptions, PagedResponse, PagedCallback, PagedOptionsWithFilter, NormalCallback } from './common';
28
28
  import { Session } from './session';
29
29
  import { SessionPool } from './session-pool';
@@ -146,6 +146,8 @@ declare class Spanner extends GrpcService {
146
146
  * @type {string}
147
147
  */
148
148
  static COMMIT_TIMESTAMP: string;
149
+ static POSTGRESQL: google.spanner.admin.database.v1.DatabaseDialect;
150
+ static GOOGLE_STANDARD_SQL: google.spanner.admin.database.v1.DatabaseDialect;
149
151
  /**
150
152
  * Gets the configured Spanner emulator host from an environment variable.
151
153
  */
@@ -199,8 +201,8 @@ declare class Spanner extends GrpcService {
199
201
  * @see {@link v1.InstanceAdminClient#createInstance}
200
202
  * @see [CreateInstace API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance)
201
203
  *
202
- * @throws {Error} If a name is not provided.
203
- * @throws {Error} If a configuration object is not provided.
204
+ * @throws {GoogleError} If a name is not provided.
205
+ * @throws {GoogleError} If a configuration object is not provided.
204
206
  *
205
207
  * @param {string} name The name of the instance to be created.
206
208
  * @param {CreateInstanceRequest} config Configuration object.
@@ -556,7 +558,7 @@ declare class Spanner extends GrpcService {
556
558
  /**
557
559
  * Get a reference to an Instance object.
558
560
  *
559
- * @throws {Error} If a name is not provided.
561
+ * @throws {GoogleError} If a name is not provided.
560
562
  *
561
563
  * @param {string} name The name of the instance.
562
564
  * @returns {Instance} An Instance object.
@@ -684,6 +686,19 @@ declare class Spanner extends GrpcService {
684
686
  * ```
685
687
  */
686
688
  static numeric(value: any): Numeric;
689
+ /**
690
+ * Helper function to get a Cloud Spanner pgNumeric object.
691
+ *
692
+ * @param {string} value The pgNumeric value as a string.
693
+ * @returns {PGNumeric}
694
+ *
695
+ * @example
696
+ * ```
697
+ * const {Spanner} = require('@google-cloud/spanner');
698
+ * const pgNumeric = Spanner.pgNumeric("3.141592653");
699
+ * ```
700
+ */
701
+ static pgNumeric(value: any): PGNumeric;
687
702
  /**
688
703
  * Helper function to get a Cloud Spanner Struct object.
689
704
  *
@@ -33,6 +33,7 @@ Object.defineProperty(exports, "Database", { enumerable: true, get: function ()
33
33
  const instance_1 = require("./instance");
34
34
  Object.defineProperty(exports, "Instance", { enumerable: true, get: function () { return instance_1.Instance; } });
35
35
  const google_gax_1 = require("google-gax");
36
+ const protos_1 = require("../protos/protos");
36
37
  const common_1 = require("./common");
37
38
  const session_1 = require("./session");
38
39
  Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return session_1.Session; } });
@@ -156,14 +157,14 @@ class Spanner extends service_1.GrpcService {
156
157
  if (endpointWithPort) {
157
158
  if (endpointWithPort.startsWith('http:') ||
158
159
  endpointWithPort.startsWith('https:')) {
159
- throw new Error('SPANNER_EMULATOR_HOST must not start with a protocol specification (http/https)');
160
+ throw new google_gax_1.GoogleError('SPANNER_EMULATOR_HOST must not start with a protocol specification (http/https)');
160
161
  }
161
162
  const index = endpointWithPort.indexOf(':');
162
163
  if (index > -1) {
163
164
  const portName = endpointWithPort.substring(index + 1);
164
165
  const port = +portName;
165
166
  if (!port || port < 1 || port > 65535) {
166
- throw new Error(`Invalid port number: ${portName}`);
167
+ throw new google_gax_1.GoogleError(`Invalid port number: ${portName}`);
167
168
  }
168
169
  return {
169
170
  endpoint: endpointWithPort.substring(0, index),
@@ -187,10 +188,10 @@ class Spanner extends service_1.GrpcService {
187
188
  }
188
189
  createInstance(name, config, callback) {
189
190
  if (!name) {
190
- throw new Error('A name is required to create an instance.');
191
+ throw new google_gax_1.GoogleError('A name is required to create an instance.');
191
192
  }
192
193
  if (!config) {
193
- throw new Error(['A configuration object is required to create an instance.'].join(''));
194
+ throw new google_gax_1.GoogleError(['A configuration object is required to create an instance.'].join(''));
194
195
  }
195
196
  const formattedName = instance_1.Instance.formatName_(this.projectId, name);
196
197
  const displayName = config.displayName || formattedName.split('/').pop();
@@ -205,7 +206,7 @@ class Spanner extends service_1.GrpcService {
205
206
  }, config),
206
207
  };
207
208
  if (reqOpts.instance.nodeCount && reqOpts.instance.processingUnits) {
208
- throw new Error(['Only one of nodeCount or processingUnits can be specified.'].join(''));
209
+ throw new google_gax_1.GoogleError(['Only one of nodeCount or processingUnits can be specified.'].join(''));
209
210
  }
210
211
  if (!reqOpts.instance.nodeCount && !reqOpts.instance.processingUnits) {
211
212
  // If neither nodes nor processingUnits are specified, default to a
@@ -450,7 +451,7 @@ class Spanner extends service_1.GrpcService {
450
451
  /**
451
452
  * Get a reference to an Instance object.
452
453
  *
453
- * @throws {Error} If a name is not provided.
454
+ * @throws {GoogleError} If a name is not provided.
454
455
  *
455
456
  * @param {string} name The name of the instance.
456
457
  * @returns {Instance} An Instance object.
@@ -464,7 +465,7 @@ class Spanner extends service_1.GrpcService {
464
465
  */
465
466
  instance(name) {
466
467
  if (!name) {
467
- throw new Error('A name is required to access an Instance object.');
468
+ throw new google_gax_1.GoogleError('A name is required to access an Instance object.');
468
469
  }
469
470
  const key = name.split('/').pop();
470
471
  if (!this.instances_.has(key)) {
@@ -705,6 +706,21 @@ class Spanner extends service_1.GrpcService {
705
706
  static numeric(value) {
706
707
  return new codec_1.codec.Numeric(value);
707
708
  }
709
+ /**
710
+ * Helper function to get a Cloud Spanner pgNumeric object.
711
+ *
712
+ * @param {string} value The pgNumeric value as a string.
713
+ * @returns {PGNumeric}
714
+ *
715
+ * @example
716
+ * ```
717
+ * const {Spanner} = require('@google-cloud/spanner');
718
+ * const pgNumeric = Spanner.pgNumeric("3.141592653");
719
+ * ```
720
+ */
721
+ static pgNumeric(value) {
722
+ return new codec_1.codec.PGNumeric(value);
723
+ }
708
724
  /**
709
725
  * Helper function to get a Cloud Spanner Struct object.
710
726
  *
@@ -736,6 +752,8 @@ exports.Spanner = Spanner;
736
752
  * @type {string}
737
753
  */
738
754
  Spanner.COMMIT_TIMESTAMP = 'spanner.commit_timestamp()';
755
+ Spanner.POSTGRESQL = protos_1.google.spanner.admin.database.v1.DatabaseDialect.POSTGRESQL;
756
+ Spanner.GOOGLE_STANDARD_SQL = protos_1.google.spanner.admin.database.v1.DatabaseDialect.GOOGLE_STANDARD_SQL;
739
757
  /*! Developer Documentation
740
758
  *
741
759
  * All async methods (except for streams) will return a Promise in the event
@@ -748,6 +766,7 @@ promisify_1.promisifyAll(Spanner, {
748
766
  'instance',
749
767
  'int',
750
768
  'numeric',
769
+ 'pgNumeric',
751
770
  'operation',
752
771
  'timestamp',
753
772
  ],
@@ -22,7 +22,7 @@ import { RequestCallback, PagedOptions, PagedResponse, LongRunningCallback, Norm
22
22
  import { Duplex } from 'stream';
23
23
  import { SessionPoolOptions, SessionPool } from './session-pool';
24
24
  import { Operation as GaxOperation, CallOptions } from 'google-gax';
25
- import { Backup } from './backup';
25
+ import { Backup, CopyBackupCallback, CopyBackupResponse, CopyBackupOptions } from './backup';
26
26
  import { google as instanceAdmin } from '../protos/protos';
27
27
  import { google as databaseAdmin } from '../protos/protos';
28
28
  import { google as spannerClient } from '../protos/protos';
@@ -49,7 +49,7 @@ export declare type GetDatabaseOperationsResponse = PagedResponse<IOperation, da
49
49
  export interface CreateDatabaseOptions extends databaseAdmin.spanner.admin.database.v1.ICreateDatabaseRequest {
50
50
  poolOptions?: SessionPoolOptions;
51
51
  poolCtor?: SessionPool;
52
- schema?: string;
52
+ schema?: string | string[];
53
53
  gaxOptions?: CallOptions;
54
54
  }
55
55
  export declare type GetDatabasesOptions = PagedOptions;
@@ -105,7 +105,7 @@ declare class Instance extends common.GrpcServiceObject {
105
105
  /**
106
106
  * Get a reference to a Backup object.
107
107
  *
108
- * @throws {Error} If any parameter is not provided.
108
+ * @throws {GoogleError} If any parameter is not provided.
109
109
  *
110
110
  * @param {string} backupId The name of the backup.
111
111
  * @return {Backup} A Backup object.
@@ -119,6 +119,45 @@ declare class Instance extends common.GrpcServiceObject {
119
119
  * ```
120
120
  */
121
121
  backup(backupId: string): Backup;
122
+ /**
123
+ * Get a reference to a Backup object.
124
+ *
125
+ * @throws {GoogleError} If any parameter is not provided.
126
+ *
127
+ * @typedef {object} CopyBackupOptions
128
+ * * @property {string|null}
129
+ * * sourceBackup The full path of the backup to be copied
130
+ * * @property {string|number|google.protobuf.Timestamp|external:PreciseDate}
131
+ * * expireTime The expire time of the backup.
132
+ * * @property {google.spanner.admin.database.v1.ICopyBackupEncryptionConfig}
133
+ * * encryptionConfig An encryption configuration describing the
134
+ * * encryption type and key resources in Cloud KMS to be used to encrypt
135
+ * * the copy backup.
136
+ * * @property {object} [gaxOptions] The request configuration options,
137
+ * * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
138
+ * * for more details.
139
+ * */
140
+ /**
141
+ * @callback CopyBackupCallback
142
+ * @param {string} sourceBackupId Full path of the source backup to be copied.
143
+ * @param {string} backupId The name of the backup.
144
+ * @param {CopyBackupOptions}
145
+ * @return {Backup} A Backup object.
146
+ *
147
+ * @example
148
+ * ```
149
+ * const {Spanner} = require('@google-cloud/spanner');
150
+ * const spanner = new Spanner();
151
+ * const instance = spanner.instance('my-instance');
152
+ * const backup = instance.backup('my-source-backup','my-backup',{
153
+ * expireTime: expireTime,
154
+ * encryptionConfig: {
155
+ * encryptionType: 'CUSTOMER_MANAGED_ENCRYPTION',
156
+ * kmsKeyName: 'projects/my-project-id/my-region/keyRings/my-key-ring/cryptoKeys/my-key',
157
+ * },);
158
+ * ```
159
+ */
160
+ copyBackup(sourceBackupId: string, backupId: string, options: CopyBackupOptions, callback?: CopyBackupCallback): Promise<CopyBackupResponse> | void;
122
161
  /**
123
162
  * Query object for listing backups.
124
163
  *
@@ -317,7 +356,7 @@ declare class Instance extends common.GrpcServiceObject {
317
356
  * @see {@link v1.DatabaseAdminClient#createDatabase}
318
357
  * @see [CreateDatabase API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.DatabaseAdmin.CreateDatabase)
319
358
  *
320
- * @throws {Error} If a name is not provided.
359
+ * @throws {GoogleError} If a name is not provided.
321
360
  *
322
361
  * @param {name} name The name of the database to create.
323
362
  * @param {CreateDatabaseRequest} [options] Configuration object.
@@ -379,7 +418,7 @@ declare class Instance extends common.GrpcServiceObject {
379
418
  /**
380
419
  * Get a reference to a Database object.
381
420
  *
382
- * @throws {Error} If a name is not provided.
421
+ * @throws {GoogleError} If a name is not provided.
383
422
  *
384
423
  * @param {string} name The name of the instance.
385
424
  * @param {SessionPoolOptions|SessionPoolCtor} [poolOptions] Session pool
@@ -24,7 +24,9 @@ const extend = require("extend");
24
24
  const snakeCase = require("lodash.snakecase");
25
25
  const database_1 = require("./database");
26
26
  const common_1 = require("./common");
27
+ const google_gax_1 = require("google-gax");
27
28
  const backup_1 = require("./backup");
29
+ const protos_1 = require("../protos/protos");
28
30
  /**
29
31
  * The {@link Instance} class represents a [Cloud Spanner
30
32
  * instance](https://cloud.google.com/spanner/docs/instances).
@@ -119,7 +121,7 @@ class Instance extends common.GrpcServiceObject {
119
121
  /**
120
122
  * Get a reference to a Backup object.
121
123
  *
122
- * @throws {Error} If any parameter is not provided.
124
+ * @throws {GoogleError} If any parameter is not provided.
123
125
  *
124
126
  * @param {string} backupId The name of the backup.
125
127
  * @return {Backup} A Backup object.
@@ -134,10 +136,58 @@ class Instance extends common.GrpcServiceObject {
134
136
  */
135
137
  backup(backupId) {
136
138
  if (!backupId) {
137
- throw new Error('A backup ID is required to create a Backup.');
139
+ throw new google_gax_1.GoogleError('A backup ID is required to create a Backup.');
138
140
  }
139
141
  return new backup_1.Backup(this, backupId);
140
142
  }
143
+ /**
144
+ * Get a reference to a Backup object.
145
+ *
146
+ * @throws {GoogleError} If any parameter is not provided.
147
+ *
148
+ * @typedef {object} CopyBackupOptions
149
+ * * @property {string|null}
150
+ * * sourceBackup The full path of the backup to be copied
151
+ * * @property {string|number|google.protobuf.Timestamp|external:PreciseDate}
152
+ * * expireTime The expire time of the backup.
153
+ * * @property {google.spanner.admin.database.v1.ICopyBackupEncryptionConfig}
154
+ * * encryptionConfig An encryption configuration describing the
155
+ * * encryption type and key resources in Cloud KMS to be used to encrypt
156
+ * * the copy backup.
157
+ * * @property {object} [gaxOptions] The request configuration options,
158
+ * * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
159
+ * * for more details.
160
+ * */
161
+ /**
162
+ * @callback CopyBackupCallback
163
+ * @param {string} sourceBackupId Full path of the source backup to be copied.
164
+ * @param {string} backupId The name of the backup.
165
+ * @param {CopyBackupOptions}
166
+ * @return {Backup} A Backup object.
167
+ *
168
+ * @example
169
+ * ```
170
+ * const {Spanner} = require('@google-cloud/spanner');
171
+ * const spanner = new Spanner();
172
+ * const instance = spanner.instance('my-instance');
173
+ * const backup = instance.backup('my-source-backup','my-backup',{
174
+ * expireTime: expireTime,
175
+ * encryptionConfig: {
176
+ * encryptionType: 'CUSTOMER_MANAGED_ENCRYPTION',
177
+ * kmsKeyName: 'projects/my-project-id/my-region/keyRings/my-key-ring/cryptoKeys/my-key',
178
+ * },);
179
+ * ```
180
+ */
181
+ copyBackup(sourceBackupId, backupId, options, callback) {
182
+ if (!backupId || !sourceBackupId) {
183
+ throw new google_gax_1.GoogleError('A backup ID and source backup ID is required to create a copy of the source backup.');
184
+ }
185
+ const copyOfBackup = new backup_1.Backup(this, backupId, sourceBackupId);
186
+ if (callback) {
187
+ return copyOfBackup.create(options, callback);
188
+ }
189
+ return copyOfBackup.create(options);
190
+ }
141
191
  getBackups(optionsOrCallback, cb) {
142
192
  const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
143
193
  const options = typeof optionsOrCallback === 'object'
@@ -385,7 +435,7 @@ class Instance extends common.GrpcServiceObject {
385
435
  }
386
436
  createDatabase(name, optionsOrCallback, cb) {
387
437
  if (!name) {
388
- throw new Error('A name is required to create a database.');
438
+ throw new google_gax_1.GoogleError('A name is required to create a database.');
389
439
  }
390
440
  const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
391
441
  const options = typeof optionsOrCallback === 'object'
@@ -393,9 +443,14 @@ class Instance extends common.GrpcServiceObject {
393
443
  : {};
394
444
  const poolOptions = options.poolOptions;
395
445
  const poolCtor = options.poolCtor;
446
+ let createStatement = 'CREATE DATABASE `' + name.split('/').pop() + '`';
447
+ if (protos_1.google.spanner.admin.database.v1.DatabaseDialect.POSTGRESQL ===
448
+ options.databaseDialect) {
449
+ createStatement = 'CREATE DATABASE "' + name.split('/').pop() + '"';
450
+ }
396
451
  const reqOpts = extend({
397
452
  parent: this.formattedName_,
398
- createStatement: 'CREATE DATABASE `' + name.split('/').pop() + '`',
453
+ createStatement: createStatement,
399
454
  }, options);
400
455
  delete reqOpts.poolOptions;
401
456
  delete reqOpts.poolCtor;
@@ -422,7 +477,7 @@ class Instance extends common.GrpcServiceObject {
422
477
  /**
423
478
  * Get a reference to a Database object.
424
479
  *
425
- * @throws {Error} If a name is not provided.
480
+ * @throws {GoogleError} If a name is not provided.
426
481
  *
427
482
  * @param {string} name The name of the instance.
428
483
  * @param {SessionPoolOptions|SessionPoolCtor} [poolOptions] Session pool
@@ -444,7 +499,7 @@ class Instance extends common.GrpcServiceObject {
444
499
  */
445
500
  database(name, poolOptions, queryOptions) {
446
501
  if (!name) {
447
- throw new Error('A name is required to access a Database object.');
502
+ throw new google_gax_1.GoogleError('A name is required to access a Database object.');
448
503
  }
449
504
  // Only add an additional key for SessionPoolOptions and QueryOptions if an
450
505
  // options object with at least one value was passed in.
@@ -225,6 +225,9 @@ class PartialResultStream extends stream_1.Transform {
225
225
  type.code === 'ARRAY' ||
226
226
  type.code === protos_1.google.spanner.v1.TypeCode.STRUCT ||
227
227
  type.code === 'STRUCT') {
228
+ if (head === null || tail === null) {
229
+ return [head, tail];
230
+ }
228
231
  return [PartialResultStream.mergeLists(type, head, tail)];
229
232
  }
230
233
  if (is.string(head) && is.string(tail)) {
@@ -20,7 +20,7 @@ import { Database } from './database';
20
20
  import { Session, types } from './session';
21
21
  import { Transaction } from './transaction';
22
22
  import { NormalCallback } from './common';
23
- import { grpc } from 'google-gax';
23
+ import { GoogleError, grpc } from 'google-gax';
24
24
  import trace = require('stack-trace');
25
25
  /**
26
26
  * @callback SessionPoolCloseCallback
@@ -142,7 +142,7 @@ export interface SessionPoolOptions {
142
142
  *
143
143
  * @private
144
144
  */
145
- export declare class ReleaseError extends Error {
145
+ export declare class ReleaseError extends GoogleError {
146
146
  resource: unknown;
147
147
  constructor(resource: unknown);
148
148
  }
@@ -151,14 +151,14 @@ export declare class ReleaseError extends Error {
151
151
  *
152
152
  * @private
153
153
  */
154
- export declare class SessionLeakError extends Error {
154
+ export declare class SessionLeakError extends GoogleError {
155
155
  messages: string[];
156
156
  constructor(leaks: string[]);
157
157
  }
158
158
  /**
159
159
  * Error to be thrown when the session pool is exhausted.
160
160
  */
161
- export declare class SessionPoolExhaustedError extends Error {
161
+ export declare class SessionPoolExhaustedError extends GoogleError {
162
162
  messages: string[];
163
163
  constructor(leaks: string[]);
164
164
  }
@@ -39,7 +39,7 @@ const DEFAULTS = {
39
39
  *
40
40
  * @private
41
41
  */
42
- class ReleaseError extends Error {
42
+ class ReleaseError extends google_gax_1.GoogleError {
43
43
  constructor(resource) {
44
44
  super('Unable to release unknown resource.');
45
45
  this.resource = resource;
@@ -51,7 +51,7 @@ exports.ReleaseError = ReleaseError;
51
51
  *
52
52
  * @private
53
53
  */
54
- class SessionLeakError extends Error {
54
+ class SessionLeakError extends google_gax_1.GoogleError {
55
55
  constructor(leaks) {
56
56
  super(`${leaks.length} session leak(s) detected.`);
57
57
  // Restore error name that was overwritten by the super constructor call.
@@ -63,7 +63,7 @@ exports.SessionLeakError = SessionLeakError;
63
63
  /**
64
64
  * Error to be thrown when the session pool is exhausted.
65
65
  */
66
- class SessionPoolExhaustedError extends Error {
66
+ class SessionPoolExhaustedError extends google_gax_1.GoogleError {
67
67
  constructor(leaks) {
68
68
  super("No resources available." /* Exhausted */);
69
69
  // Restore error name that was overwritten by the super constructor call.
@@ -435,7 +435,7 @@ class SessionPool extends events_1.EventEmitter {
435
435
  */
436
436
  async _acquire(type) {
437
437
  if (!this.isOpen) {
438
- throw new Error("Database is closed." /* Closed */);
438
+ throw new google_gax_1.GoogleError("Database is closed." /* Closed */);
439
439
  }
440
440
  // Get the stacktrace of the caller before we call any async methods, as calling an async method will break the stacktrace.
441
441
  const frames = trace.get();
@@ -446,7 +446,7 @@ class SessionPool extends events_1.EventEmitter {
446
446
  const getSession = async () => {
447
447
  const elapsed = Date.now() - startTime;
448
448
  if (elapsed >= timeout) {
449
- throw new Error("Timeout occurred while acquiring session." /* Timeout */);
449
+ throw new google_gax_1.GoogleError("Timeout occurred while acquiring session." /* Timeout */);
450
450
  }
451
451
  const session = await this._getSession(type, startTime);
452
452
  if (this._isValidSession(session)) {
@@ -706,7 +706,7 @@ class SessionPool extends events_1.EventEmitter {
706
706
  const availableEvent = type + '-available';
707
707
  const promises = [
708
708
  this._onClose.then(() => {
709
- throw new Error("Database is closed." /* Closed */);
709
+ throw new google_gax_1.GoogleError("Database is closed." /* Closed */);
710
710
  }),
711
711
  new Promise(resolve => {
712
712
  this.once(availableEvent, resolve);
@@ -1312,7 +1312,7 @@ class Transaction extends Dml {
1312
1312
  const keys = Object.keys(row);
1313
1313
  const missingColumns = columns.filter(column => !keys.includes(column));
1314
1314
  if (missingColumns.length > 0) {
1315
- throw new Error([
1315
+ throw new google_gax_1.GoogleError([
1316
1316
  `Row at index ${index} does not contain the correct number of columns.`,
1317
1317
  `Missing columns: ${JSON.stringify(missingColumns)}`,
1318
1318
  ].join('\n\n'));