@google-cloud/spanner 7.20.0 → 8.0.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 (54) hide show
  1. package/README.md +1 -0
  2. package/build/protos/google/spanner/admin/database/v1/backup.proto +1 -1
  3. package/build/protos/google/spanner/admin/database/v1/backup_schedule.proto +1 -1
  4. package/build/protos/google/spanner/admin/database/v1/common.proto +1 -1
  5. package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +1 -1
  6. package/build/protos/google/spanner/admin/instance/v1/common.proto +1 -1
  7. package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +1 -1
  8. package/build/protos/google/spanner/executor/v1/cloud_executor.proto +1 -1
  9. package/build/protos/google/spanner/v1/commit_response.proto +1 -1
  10. package/build/protos/google/spanner/v1/keys.proto +1 -1
  11. package/build/protos/google/spanner/v1/mutation.proto +1 -1
  12. package/build/protos/google/spanner/v1/query_plan.proto +1 -1
  13. package/build/protos/google/spanner/v1/result_set.proto +55 -49
  14. package/build/protos/google/spanner/v1/spanner.proto +1 -1
  15. package/build/protos/google/spanner/v1/transaction.proto +1 -1
  16. package/build/protos/google/spanner/v1/type.proto +1 -1
  17. package/build/protos/protos.d.ts +56 -50
  18. package/build/protos/protos.js +1016 -331
  19. package/build/protos/protos.json +47 -20
  20. package/build/src/backup.js +7 -0
  21. package/build/src/batch-transaction.d.ts +48 -29
  22. package/build/src/batch-transaction.js +13 -98
  23. package/build/src/codec.js +43 -26
  24. package/build/src/common-grpc/service-object.js +1 -0
  25. package/build/src/common-grpc/service.js +25 -8
  26. package/build/src/database.js +77 -49
  27. package/build/src/helper.d.ts +9 -0
  28. package/build/src/helper.js +24 -0
  29. package/build/src/index.js +24 -13
  30. package/build/src/instance-config.d.ts +1 -1
  31. package/build/src/instance-config.js +4 -0
  32. package/build/src/instance.js +12 -6
  33. package/build/src/instrument.d.ts +2 -0
  34. package/build/src/instrument.js +12 -9
  35. package/build/src/multiplexed-session.js +7 -1
  36. package/build/src/partial-result-stream.js +9 -5
  37. package/build/src/request_id_header.js +1 -0
  38. package/build/src/session-factory.js +5 -2
  39. package/build/src/session-pool.js +23 -6
  40. package/build/src/session.d.ts +2 -1
  41. package/build/src/session.js +8 -2
  42. package/build/src/table.js +6 -1
  43. package/build/src/transaction-runner.js +12 -2
  44. package/build/src/transaction.d.ts +2 -1
  45. package/build/src/transaction.js +95 -81
  46. package/build/src/v1/database_admin_client.d.ts +3 -2
  47. package/build/src/v1/database_admin_client.js +551 -167
  48. package/build/src/v1/instance_admin_client.d.ts +2 -1
  49. package/build/src/v1/instance_admin_client.js +453 -133
  50. package/build/src/v1/spanner_client.d.ts +2 -1
  51. package/build/src/v1/spanner_client.js +283 -85
  52. package/build/src/v1/spanner_executor_proxy_client.d.ts +2 -1
  53. package/build/src/v1/spanner_executor_proxy_client.js +41 -19
  54. package/package.json +57 -58
@@ -18,7 +18,7 @@ exports.codec = exports.Interval = exports.PGOid = exports.PGJsonb = exports.Pro
18
18
  */
19
19
  const service_1 = require("./common-grpc/service");
20
20
  const precise_date_1 = require("@google-cloud/precise-date");
21
- const arrify = require("arrify");
21
+ const helper_1 = require("./helper");
22
22
  const big_js_1 = require("big.js");
23
23
  const is = require("is");
24
24
  const protos_1 = require("../protos/protos");
@@ -85,12 +85,14 @@ exports.SpannerDate = SpannerDate;
85
85
  * @private
86
86
  */
87
87
  class WrappedNumber {
88
+ value;
88
89
  }
89
90
  /**
90
91
  * @typedef Float32
91
92
  * @see Spanner.float32
92
93
  */
93
94
  class Float32 extends WrappedNumber {
95
+ value;
94
96
  constructor(value) {
95
97
  super();
96
98
  this.value = value;
@@ -105,6 +107,7 @@ exports.Float32 = Float32;
105
107
  * @see Spanner.float
106
108
  */
107
109
  class Float extends WrappedNumber {
110
+ value;
108
111
  constructor(value) {
109
112
  super();
110
113
  this.value = value;
@@ -119,6 +122,7 @@ exports.Float = Float;
119
122
  * @see Spanner.int
120
123
  */
121
124
  class Int extends WrappedNumber {
125
+ value;
122
126
  constructor(value) {
123
127
  super();
124
128
  this.value = value.toString();
@@ -179,6 +183,7 @@ exports.Struct = Struct;
179
183
  * @see Spanner.numeric
180
184
  */
181
185
  class Numeric {
186
+ value;
182
187
  constructor(value) {
183
188
  this.value = value;
184
189
  }
@@ -195,6 +200,7 @@ exports.Numeric = Numeric;
195
200
  * @see Spanner.pgNumeric
196
201
  */
197
202
  class PGNumeric {
203
+ value;
198
204
  constructor(pgValue) {
199
205
  this.value = pgValue.toString();
200
206
  }
@@ -214,6 +220,9 @@ exports.PGNumeric = PGNumeric;
214
220
  * @see Spanner.protoMessage
215
221
  */
216
222
  class ProtoMessage {
223
+ value;
224
+ fullName;
225
+ messageFunction;
217
226
  constructor(protoMessageParams) {
218
227
  this.fullName = protoMessageParams.fullName;
219
228
  this.messageFunction = protoMessageParams.messageFunction;
@@ -243,6 +252,9 @@ exports.ProtoMessage = ProtoMessage;
243
252
  * @see Spanner.protoEnum
244
253
  */
245
254
  class ProtoEnum {
255
+ value;
256
+ fullName;
257
+ enumObject;
246
258
  constructor(protoEnumParams) {
247
259
  this.fullName = protoEnumParams.fullName;
248
260
  this.enumObject = protoEnumParams.enumObject;
@@ -277,6 +289,7 @@ exports.ProtoEnum = ProtoEnum;
277
289
  * @see Spanner.pgJsonb
278
290
  */
279
291
  class PGJsonb {
292
+ value;
280
293
  constructor(pgValue) {
281
294
  if (typeof pgValue === 'string') {
282
295
  pgValue = JSON.parse(pgValue);
@@ -293,6 +306,7 @@ exports.PGJsonb = PGJsonb;
293
306
  * @see Spanner.pgOid
294
307
  */
295
308
  class PGOid extends WrappedNumber {
309
+ value;
296
310
  constructor(value) {
297
311
  super();
298
312
  this.value = value.toString();
@@ -311,6 +325,32 @@ exports.PGOid = PGOid;
311
325
  * @see Spanner.interval
312
326
  */
313
327
  class Interval {
328
+ months;
329
+ days;
330
+ nanoseconds;
331
+ // Regex to parse ISO8601 duration format: P[n]Y[n]M[n]DT[n]H[n]M[n][.fffffffff]S
332
+ // Only seconds can be fractional, and can have at most 9 digits after decimal point.
333
+ // Both '.' and ',' are considered valid decimal point.
334
+ static ISO8601_PATTERN = /^P(?!$)(-?\d+Y)?(-?\d+M)?(-?\d+D)?(T(?=-?[.,]?\d)(-?\d+H)?(-?\d+M)?(-?(((\d+)([.,]\d{1,9})?)|([.,]\d{1,9}))S)?)?$/;
335
+ static MONTHS_PER_YEAR = 12;
336
+ static DAYS_PER_MONTH = 30;
337
+ static HOURS_PER_DAY = 24;
338
+ static MINUTES_PER_HOUR = 60;
339
+ static SECONDS_PER_MINUTE = 60;
340
+ static SECONDS_PER_HOUR = Interval.MINUTES_PER_HOUR * Interval.SECONDS_PER_MINUTE;
341
+ static MILLISECONDS_PER_SECOND = 1000;
342
+ static MICROSECONDS_PER_MILLISECOND = 1000;
343
+ static NANOSECONDS_PER_MICROSECOND = 1000;
344
+ static NANOSECONDS_PER_MILLISECOND = Interval.MICROSECONDS_PER_MILLISECOND *
345
+ Interval.NANOSECONDS_PER_MICROSECOND;
346
+ static NANOSECONDS_PER_SECOND = Interval.MILLISECONDS_PER_SECOND *
347
+ Interval.MICROSECONDS_PER_MILLISECOND *
348
+ Interval.NANOSECONDS_PER_MICROSECOND;
349
+ static NANOSECONDS_PER_DAY = BigInt(Interval.HOURS_PER_DAY) *
350
+ BigInt(Interval.SECONDS_PER_HOUR) *
351
+ BigInt(Interval.NANOSECONDS_PER_SECOND);
352
+ static NANOSECONDS_PER_MONTH = BigInt(Interval.DAYS_PER_MONTH) * Interval.NANOSECONDS_PER_DAY;
353
+ static ZERO = new Interval(0, 0, BigInt(0));
314
354
  /**
315
355
  * @param months months part of the `Interval`
316
356
  * @param days days part of the `Interval`
@@ -513,29 +553,6 @@ class Interval {
513
553
  }
514
554
  }
515
555
  exports.Interval = Interval;
516
- // Regex to parse ISO8601 duration format: P[n]Y[n]M[n]DT[n]H[n]M[n][.fffffffff]S
517
- // Only seconds can be fractional, and can have at most 9 digits after decimal point.
518
- // Both '.' and ',' are considered valid decimal point.
519
- Interval.ISO8601_PATTERN = /^P(?!$)(-?\d+Y)?(-?\d+M)?(-?\d+D)?(T(?=-?[.,]?\d)(-?\d+H)?(-?\d+M)?(-?(((\d+)([.,]\d{1,9})?)|([.,]\d{1,9}))S)?)?$/;
520
- Interval.MONTHS_PER_YEAR = 12;
521
- Interval.DAYS_PER_MONTH = 30;
522
- Interval.HOURS_PER_DAY = 24;
523
- Interval.MINUTES_PER_HOUR = 60;
524
- Interval.SECONDS_PER_MINUTE = 60;
525
- Interval.SECONDS_PER_HOUR = Interval.MINUTES_PER_HOUR * Interval.SECONDS_PER_MINUTE;
526
- Interval.MILLISECONDS_PER_SECOND = 1000;
527
- Interval.MICROSECONDS_PER_MILLISECOND = 1000;
528
- Interval.NANOSECONDS_PER_MICROSECOND = 1000;
529
- Interval.NANOSECONDS_PER_MILLISECOND = Interval.MICROSECONDS_PER_MILLISECOND *
530
- Interval.NANOSECONDS_PER_MICROSECOND;
531
- Interval.NANOSECONDS_PER_SECOND = Interval.MILLISECONDS_PER_SECOND *
532
- Interval.MICROSECONDS_PER_MILLISECOND *
533
- Interval.NANOSECONDS_PER_MICROSECOND;
534
- Interval.NANOSECONDS_PER_DAY = BigInt(Interval.HOURS_PER_DAY) *
535
- BigInt(Interval.SECONDS_PER_HOUR) *
536
- BigInt(Interval.NANOSECONDS_PER_SECOND);
537
- Interval.NANOSECONDS_PER_MONTH = BigInt(Interval.DAYS_PER_MONTH) * Interval.NANOSECONDS_PER_DAY;
538
- Interval.ZERO = new Interval(0, 0, BigInt(0));
539
556
  /**
540
557
  * @typedef JSONOptions
541
558
  * @property {boolean} [wrapNumbers=false] Indicates if the numbers should be
@@ -934,7 +951,7 @@ function getType(value) {
934
951
  * @returns {object}
935
952
  */
936
953
  function convertToListValue(value) {
937
- const values = arrify(value).map(exports.codec.encode);
954
+ const values = (0, helper_1.toArray)(value).map(exports.codec.encode);
938
955
  return { values };
939
956
  }
940
957
  /**
@@ -992,7 +1009,7 @@ function createTypeObject(friendlyType) {
992
1009
  }
993
1010
  if (code === 'STRUCT') {
994
1011
  type.structType = {
995
- fields: arrify(config.fields).map(field => {
1012
+ fields: (0, helper_1.toArray)(config.fields).map(field => {
996
1013
  return { name: field.name, type: exports.codec.createTypeObject(field) };
997
1014
  }),
998
1015
  };
@@ -36,6 +36,7 @@ class GrpcServiceObject extends common_1.ServiceObject {
36
36
  */
37
37
  constructor(config) {
38
38
  super(config);
39
+ this.parent = config.parent;
39
40
  }
40
41
  delete(callback) {
41
42
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -125,6 +125,9 @@ const GRPC_SERVICE_OPTIONS = {
125
125
  'grpc.initial_reconnect_backoff_ms': 5000,
126
126
  };
127
127
  class ObjectToStructConverter {
128
+ seenObjects;
129
+ removeCircular;
130
+ stringify;
128
131
  /**
129
132
  * A class that can be used to convert an object to a struct. Optionally this
130
133
  * class can be used to erase/throw on circular references during conversion.
@@ -259,6 +262,19 @@ class ObjectToStructConverter {
259
262
  }
260
263
  exports.ObjectToStructConverter = ObjectToStructConverter;
261
264
  class GrpcService extends common_1.Service {
265
+ grpc;
266
+ grpcVersion;
267
+ grpcCredentials;
268
+ grpcMetadata;
269
+ maxRetries;
270
+ userAgent;
271
+ activeServiceMap_ = new Map();
272
+ protos = {};
273
+ /** A cache for proto objects. */
274
+ static protoObjectCache = {};
275
+ static GRPC_SERVICE_OPTIONS = GRPC_SERVICE_OPTIONS;
276
+ static GRPC_ERROR_CODE_TO_HTTP = GRPC_ERROR_CODE_TO_HTTP;
277
+ static ObjectToStructConverter = ObjectToStructConverter;
262
278
  /**
263
279
  * Service is a base class, meant to be inherited from by a "service," like
264
280
  * BigQuery or Storage.
@@ -274,8 +290,6 @@ class GrpcService extends common_1.Service {
274
290
  */
275
291
  constructor(config, options) {
276
292
  super(config, options);
277
- this.activeServiceMap_ = new Map();
278
- this.protos = {};
279
293
  if (global['GCLOUD_SANDBOX_ENV']) {
280
294
  // gRPC has a tendency to cause our doc unit tests to fail, so we prevent
281
295
  // any calls to that library from going through.
@@ -764,7 +778,15 @@ class GrpcService extends common_1.Service {
764
778
  */
765
779
  getGrpcCredentials_(callback) {
766
780
  this.authClient.getClient().then(client => {
767
- const credentials = this.grpc.credentials.combineChannelCredentials(this.grpc.credentials.createSsl(), this.grpc.credentials.createFromGoogleCredential(client));
781
+ const credentials = this.grpc.credentials.combineChannelCredentials(this.grpc.credentials.createSsl(), google_gax_1.grpc.credentials.createFromGoogleCredential({
782
+ // the `grpc` package does not support the `Headers` object yet
783
+ getRequestHeaders: async (url) => {
784
+ const headers = await client.getRequestHeaders(url);
785
+ const genericHeadersObject = {};
786
+ headers.forEach((value, key) => (genericHeadersObject[key] = value));
787
+ return genericHeadersObject;
788
+ },
789
+ }));
768
790
  if (!this.projectId || this.projectId === '{{projectId}}') {
769
791
  this.projectId = client.projectId;
770
792
  }
@@ -818,9 +840,4 @@ class GrpcService extends common_1.Service {
818
840
  }
819
841
  }
820
842
  exports.GrpcService = GrpcService;
821
- /** A cache for proto objects. */
822
- GrpcService.protoObjectCache = {};
823
- GrpcService.GRPC_SERVICE_OPTIONS = GRPC_SERVICE_OPTIONS;
824
- GrpcService.GRPC_ERROR_CODE_TO_HTTP = GRPC_ERROR_CODE_TO_HTTP;
825
- GrpcService.ObjectToStructConverter = ObjectToStructConverter;
826
843
  //# sourceMappingURL=service.js.map
@@ -32,7 +32,7 @@ const table_1 = require("./table");
32
32
  const transaction_runner_1 = require("./transaction-runner");
33
33
  const common_1 = require("./common");
34
34
  const stream_1 = require("stream");
35
- const arrify = require("arrify");
35
+ const helper_1 = require("./helper");
36
36
  const snakeCase = require("lodash.snakecase");
37
37
  const instrument_1 = require("./instrument");
38
38
  const request_id_header_1 = require("./request_id_header");
@@ -56,8 +56,21 @@ const request_id_header_1 = require("./request_id_header");
56
56
  * ```
57
57
  */
58
58
  class Database extends common.GrpcServiceObject {
59
+ instance;
60
+ formattedName_;
61
+ pool_;
62
+ sessionFactory_;
63
+ queryOptions_;
64
+ commonHeaders_;
65
+ request;
66
+ databaseRole;
67
+ labels;
68
+ databaseDialect;
69
+ _observabilityOptions; // TODO: exmaine if we can remove it
70
+ _traceConfig;
71
+ _nthRequest;
72
+ _clientId;
59
73
  constructor(instance, name, poolOptions, queryOptions) {
60
- var _a;
61
74
  const methods = {
62
75
  /**
63
76
  * Create a database.
@@ -136,7 +149,9 @@ class Database extends common.GrpcServiceObject {
136
149
  });
137
150
  }),
138
151
  ];
139
- Promise.race(promises).then(() => instance.createDatabase(formattedName_, options, callback));
152
+ Promise.race(promises)
153
+ .then(() => instance.createDatabase(formattedName_, options, callback))
154
+ .catch(() => { });
140
155
  }
141
156
  else {
142
157
  return instance.createDatabase(formattedName_, options, callback);
@@ -163,7 +178,7 @@ class Database extends common.GrpcServiceObject {
163
178
  this._clientId = instance._nthClientId;
164
179
  }
165
180
  this._observabilityOptions = instance._observabilityOptions;
166
- this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.formattedName_, (_a = this._observabilityOptions) === null || _a === void 0 ? void 0 : _a.enableEndToEndTracing);
181
+ this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.formattedName_, this._observabilityOptions?.enableEndToEndTracing);
167
182
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
183
  this.requestStream = instance.requestStream;
169
184
  this.sessionFactory_ = new session_factory_1.SessionFactory(this, name, poolOptions);
@@ -324,14 +339,14 @@ class Database extends common.GrpcServiceObject {
324
339
  (0, instrument_1.setSpanError)(span, err);
325
340
  if ((0, session_pool_1.isSessionNotFoundError)(err)) {
326
341
  span.addEvent('No session available', {
327
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
342
+ 'session.id': session?.id,
328
343
  });
329
344
  }
330
345
  span.end();
331
346
  callback(err, null, resp);
332
347
  return;
333
348
  }
334
- span.addEvent('Using Session', { 'session.id': session === null || session === void 0 ? void 0 : session.id });
349
+ span.addEvent('Using Session', { 'session.id': session?.id });
335
350
  span.end();
336
351
  callback(null, transaction, resp);
337
352
  });
@@ -718,7 +733,7 @@ class Database extends common.GrpcServiceObject {
718
733
  if ((0, session_pool_1.isSessionNotFoundError)(err) &&
719
734
  !this.sessionFactory_.isMultiplexedEnabled()) {
720
735
  span.addEvent('No session available', {
721
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
736
+ 'session.id': session?.id,
722
737
  });
723
738
  session.lastError = err;
724
739
  this.sessionFactory_.release(session);
@@ -726,7 +741,7 @@ class Database extends common.GrpcServiceObject {
726
741
  this.getSnapshot(options, callback);
727
742
  }
728
743
  else {
729
- span.addEvent('Using Session', { 'session.id': session === null || session === void 0 ? void 0 : session.id });
744
+ span.addEvent('Using Session', { 'session.id': session?.id });
730
745
  this.sessionFactory_.release(session);
731
746
  span.end();
732
747
  callback(err);
@@ -747,14 +762,17 @@ class Database extends common.GrpcServiceObject {
747
762
  const options = typeof optionsOrCallback === 'object' && optionsOrCallback
748
763
  ? optionsOrCallback
749
764
  : {};
750
- return (0, instrument_1.startTrace)('Database.getTransaction', this._traceConfig, span => {
765
+ return (0, instrument_1.startTrace)('Database.getTransaction', {
766
+ ...this._traceConfig,
767
+ transactionTag: options.requestOptions?.transactionTag,
768
+ }, span => {
751
769
  this.pool_.getSession((err, session, transaction) => {
752
- if (options.requestOptions) {
753
- transaction.requestOptions = Object.assign(transaction.requestOptions || {}, options.requestOptions);
754
- }
755
- transaction === null || transaction === void 0 ? void 0 : transaction.setReadWriteTransactionOptions(options);
756
770
  if (!err) {
757
- span.addEvent('Using Session', { 'session.id': session === null || session === void 0 ? void 0 : session.id });
771
+ if (options.requestOptions) {
772
+ transaction.requestOptions = Object.assign(transaction.requestOptions || {}, options.requestOptions);
773
+ }
774
+ transaction?.setReadWriteTransactionOptions(options);
775
+ span.addEvent('Using Session', { 'session.id': session?.id });
758
776
  transaction._observabilityOptions = this._observabilityOptions;
759
777
  this._releaseOnEnd(session, transaction, span);
760
778
  }
@@ -818,7 +836,7 @@ class Database extends common.GrpcServiceObject {
818
836
  return;
819
837
  }
820
838
  const span = (0, instrument_1.getActiveOrNoopSpan)();
821
- span.addEvent('Using Session', { 'session.id': session === null || session === void 0 ? void 0 : session.id });
839
+ span.addEvent('Using Session', { 'session.id': session?.id });
822
840
  config.reqOpts.session = session.formattedName_;
823
841
  this.request(config, (err, ...args) => {
824
842
  pool.release(session);
@@ -865,7 +883,7 @@ class Database extends common.GrpcServiceObject {
865
883
  destroyStream(err);
866
884
  return;
867
885
  }
868
- span.addEvent('Using Session', { 'session.id': session_ === null || session_ === void 0 ? void 0 : session_.id });
886
+ span.addEvent('Using Session', { 'session.id': session_?.id });
869
887
  session = session_;
870
888
  config.reqOpts.session = session.formattedName_;
871
889
  requestStream = self.requestStream(config);
@@ -919,11 +937,10 @@ class Database extends common.GrpcServiceObject {
919
937
  const options = typeof optionsOrCallback === 'object'
920
938
  ? optionsOrCallback
921
939
  : {};
922
- const traceConfig = {
923
- sql: query,
940
+ return (0, instrument_1.startTrace)('Database.run', {
941
+ ...query,
924
942
  ...this._traceConfig,
925
- };
926
- return (0, instrument_1.startTrace)('Database.run', traceConfig, span => {
943
+ }, span => {
927
944
  this.runStream(query, options)
928
945
  .on('error', err => {
929
946
  (0, instrument_1.setSpanError)(span, err);
@@ -946,11 +963,12 @@ class Database extends common.GrpcServiceObject {
946
963
  });
947
964
  }
948
965
  runPartitionedUpdate(query, callback) {
949
- const traceConfig = {
950
- sql: query,
966
+ return (0, instrument_1.startTrace)('Database.runPartitionedUpdate', {
967
+ ...query,
951
968
  ...this._traceConfig,
952
- };
953
- return (0, instrument_1.startTrace)('Database.runPartitionedUpdate', traceConfig, span => {
969
+ requestTag: query?.requestOptions
970
+ ?.requestTag,
971
+ }, span => {
954
972
  this.sessionFactory_.getSessionForPartitionedOps((err, session) => {
955
973
  if (err) {
956
974
  (0, instrument_1.setSpanError)(span, err);
@@ -958,7 +976,7 @@ class Database extends common.GrpcServiceObject {
958
976
  callback(err, 0);
959
977
  return;
960
978
  }
961
- this._runPartitionedUpdate(session, query, (err, count) => {
979
+ void this._runPartitionedUpdate(session, query, (err, count) => {
962
980
  if (err) {
963
981
  (0, instrument_1.setSpanError)(span, err);
964
982
  }
@@ -979,14 +997,14 @@ class Database extends common.GrpcServiceObject {
979
997
  callback(err, 0);
980
998
  return;
981
999
  }
982
- transaction.runUpdate(query, (err, updateCount) => {
1000
+ transaction.runUpdate(query, async (err, updateCount) => {
983
1001
  if (err) {
984
1002
  if (err.code !== google_gax_1.grpc.status.ABORTED) {
985
1003
  this.sessionFactory_.release(session);
986
1004
  callback(err, 0);
987
1005
  return;
988
1006
  }
989
- this._runPartitionedUpdate(session, query, callback);
1007
+ void this._runPartitionedUpdate(session, query, callback);
990
1008
  }
991
1009
  else {
992
1010
  this.sessionFactory_.release(session);
@@ -1123,11 +1141,11 @@ class Database extends common.GrpcServiceObject {
1123
1141
  */
1124
1142
  runStream(query, options) {
1125
1143
  const proxyStream = through.obj();
1126
- const traceConfig = {
1127
- sql: query,
1144
+ return (0, instrument_1.startTrace)('Database.runStream', {
1145
+ ...query,
1128
1146
  ...this._traceConfig,
1129
- };
1130
- return (0, instrument_1.startTrace)('Database.runStream', traceConfig, span => {
1147
+ requestTag: query?.requestOptions?.requestTag,
1148
+ }, span => {
1131
1149
  this.sessionFactory_.getSession((err, session) => {
1132
1150
  if (err) {
1133
1151
  (0, instrument_1.setSpanError)(span, err);
@@ -1135,7 +1153,7 @@ class Database extends common.GrpcServiceObject {
1135
1153
  span.end();
1136
1154
  return;
1137
1155
  }
1138
- span.addEvent('Using Session', { 'session.id': session === null || session === void 0 ? void 0 : session.id });
1156
+ span.addEvent('Using Session', { 'session.id': session?.id });
1139
1157
  const snapshot = session.snapshot(options, this.queryOptions_);
1140
1158
  this._releaseOnEnd(session, snapshot, span);
1141
1159
  let dataReceived = false;
@@ -1157,7 +1175,7 @@ class Database extends common.GrpcServiceObject {
1157
1175
  session.lastError = err;
1158
1176
  }
1159
1177
  span.addEvent('No session available', {
1160
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
1178
+ 'session.id': session?.id,
1161
1179
  });
1162
1180
  // Remove the current data stream from the end user stream.
1163
1181
  dataStream.unpipe(proxyStream);
@@ -1195,14 +1213,17 @@ class Database extends common.GrpcServiceObject {
1195
1213
  const options = typeof optionsOrRunFn === 'object' && optionsOrRunFn
1196
1214
  ? optionsOrRunFn
1197
1215
  : {};
1198
- (0, instrument_1.startTrace)('Database.runTransaction', this._traceConfig, span => {
1216
+ (0, instrument_1.startTrace)('Database.runTransaction', {
1217
+ ...this._traceConfig,
1218
+ transactionTag: options.requestOptions?.transactionTag,
1219
+ }, span => {
1199
1220
  this.pool_.getSession((err, session, transaction) => {
1200
1221
  if (err) {
1201
1222
  (0, instrument_1.setSpanError)(span, err);
1202
1223
  }
1203
1224
  if (err && (0, session_pool_1.isSessionNotFoundError)(err)) {
1204
1225
  span.addEvent('No session available', {
1205
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
1226
+ 'session.id': session?.id,
1206
1227
  });
1207
1228
  span.end();
1208
1229
  this.runTransaction(options, runFn);
@@ -1214,6 +1235,7 @@ class Database extends common.GrpcServiceObject {
1214
1235
  return;
1215
1236
  }
1216
1237
  transaction._observabilityOptions = this._observabilityOptions;
1238
+ transaction.requestOptions = Object.assign(transaction.requestOptions || {}, options.requestOptions);
1217
1239
  transaction.setReadWriteTransactionOptions(options);
1218
1240
  const release = () => {
1219
1241
  this.pool_.release(session);
@@ -1224,7 +1246,7 @@ class Database extends common.GrpcServiceObject {
1224
1246
  (0, instrument_1.setSpanError)(span, err);
1225
1247
  if ((0, session_pool_1.isSessionNotFoundError)(err)) {
1226
1248
  span.addEvent('No session available', {
1227
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
1249
+ 'session.id': session?.id,
1228
1250
  });
1229
1251
  release();
1230
1252
  this.runTransaction(options, runFn);
@@ -1305,7 +1327,10 @@ class Database extends common.GrpcServiceObject {
1305
1327
  : {};
1306
1328
  let sessionId = '';
1307
1329
  const getSession = this.pool_.getSession.bind(this.pool_);
1308
- return (0, instrument_1.startTrace)('Database.runTransactionAsync', this._traceConfig, async (span) => {
1330
+ return (0, instrument_1.startTrace)('Database.runTransactionAsync', {
1331
+ ...this._traceConfig,
1332
+ transactionTag: options?.requestOptions?.transactionTag,
1333
+ }, async (span) => {
1309
1334
  // Loop to retry 'Session not found' errors.
1310
1335
  // (and yes, we like while (true) more than for (;;) here)
1311
1336
  // eslint-disable-next-line no-constant-condition
@@ -1314,7 +1339,7 @@ class Database extends common.GrpcServiceObject {
1314
1339
  const [session, transaction] = await (0, promisify_1.promisify)(getSession)();
1315
1340
  transaction.requestOptions = Object.assign(transaction.requestOptions || {}, options.requestOptions);
1316
1341
  transaction.setReadWriteTransactionOptions(options);
1317
- sessionId = session === null || session === void 0 ? void 0 : session.id;
1342
+ sessionId = session?.id;
1318
1343
  span.addEvent('Using Session', { 'session.id': sessionId });
1319
1344
  const runner = new transaction_runner_1.AsyncTransactionRunner(session, transaction, runFn, options);
1320
1345
  try {
@@ -1403,7 +1428,10 @@ class Database extends common.GrpcServiceObject {
1403
1428
  */
1404
1429
  batchWriteAtLeastOnce(mutationGroups, options) {
1405
1430
  const proxyStream = through.obj();
1406
- return (0, instrument_1.startTrace)('Database.batchWriteAtLeastOnce', this._traceConfig, span => {
1431
+ return (0, instrument_1.startTrace)('Database.batchWriteAtLeastOnce', {
1432
+ ...this._traceConfig,
1433
+ transactionTag: options?.requestOptions?.transactionTag,
1434
+ }, span => {
1407
1435
  this.pool_.getSession((err, session) => {
1408
1436
  if (err) {
1409
1437
  proxyStream.destroy(err);
@@ -1411,13 +1439,13 @@ class Database extends common.GrpcServiceObject {
1411
1439
  span.end();
1412
1440
  return;
1413
1441
  }
1414
- span.addEvent('Using Session', { 'session.id': session === null || session === void 0 ? void 0 : session.id });
1415
- const gaxOpts = extend(true, {}, options === null || options === void 0 ? void 0 : options.gaxOptions);
1442
+ span.addEvent('Using Session', { 'session.id': session?.id });
1443
+ const gaxOpts = extend(true, {}, options?.gaxOptions);
1416
1444
  const reqOpts = Object.assign({}, {
1417
1445
  session: session.formattedName_,
1418
1446
  mutationGroups: mutationGroups.map(mg => mg.proto()),
1419
- requestOptions: options === null || options === void 0 ? void 0 : options.requestOptions,
1420
- excludeTxnFromChangeStream: options === null || options === void 0 ? void 0 : options.excludeTxnFromChangeStreams,
1447
+ requestOptions: options?.requestOptions,
1448
+ excludeTxnFromChangeStream: options?.excludeTxnFromChangeStreams,
1421
1449
  });
1422
1450
  let dataReceived = false;
1423
1451
  let dataStream = this.requestStream({
@@ -1440,7 +1468,7 @@ class Database extends common.GrpcServiceObject {
1440
1468
  session.lastError = err;
1441
1469
  }
1442
1470
  span.addEvent('No session available', {
1443
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
1471
+ 'session.id': session?.id,
1444
1472
  });
1445
1473
  // Remove the current data stream from the end user stream.
1446
1474
  dataStream.unpipe(proxyStream);
@@ -1477,7 +1505,7 @@ class Database extends common.GrpcServiceObject {
1477
1505
  (0, session_pool_1.isSessionNotFoundError)(err) &&
1478
1506
  !this.sessionFactory_.isMultiplexedEnabled()) {
1479
1507
  span.addEvent('No session available', {
1480
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
1508
+ 'session.id': session?.id,
1481
1509
  });
1482
1510
  span.end();
1483
1511
  this.writeAtLeastOnce(mutations, options, cb);
@@ -1489,12 +1517,12 @@ class Database extends common.GrpcServiceObject {
1489
1517
  cb(err);
1490
1518
  return;
1491
1519
  }
1492
- span.addEvent('Using Session', { 'session.id': session === null || session === void 0 ? void 0 : session.id });
1520
+ span.addEvent('Using Session', { 'session.id': session?.id });
1493
1521
  this._releaseOnEnd(session, transaction, span);
1494
1522
  try {
1495
1523
  transaction.setReadWriteTransactionOptions(options);
1496
- transaction === null || transaction === void 0 ? void 0 : transaction.setQueuedMutations(mutations.proto());
1497
- return transaction === null || transaction === void 0 ? void 0 : transaction.commit(options, (err, resp) => {
1524
+ transaction?.setQueuedMutations(mutations.proto());
1525
+ return transaction?.commit(options, (err, resp) => {
1498
1526
  if (err) {
1499
1527
  (0, instrument_1.setSpanError)(span, err);
1500
1528
  }
@@ -1560,7 +1588,7 @@ class Database extends common.GrpcServiceObject {
1560
1588
  const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
1561
1589
  if (typeof statements === 'string' || Array.isArray(statements)) {
1562
1590
  statements = {
1563
- statements: arrify(statements),
1591
+ statements: (0, helper_1.toArray)(statements),
1564
1592
  };
1565
1593
  }
1566
1594
  const reqOpts = extend({
@@ -43,3 +43,12 @@ export declare function isProjectIdNotSetInEnvironmentError(error: grpc.ServiceE
43
43
  * @return {boolean} True if the error is a 'Create session permission' error, and otherwise false.
44
44
  */
45
45
  export declare function isCreateSessionPermissionError(error: grpc.ServiceError | undefined): boolean;
46
+ /**
47
+ * Converts any value into an array. Acts as a replacement for `arrify`.
48
+ * If the value is null or undefined, returns an empty array.
49
+ * If the value is already an array, returns is unchanges.
50
+ * Otherwise, wraps the value in a new array.
51
+ * @param value The value to convert into an array.
52
+ * @returns An array containing the value, or an empty array.
53
+ */
54
+ export declare function toArray(value: any): any[];
@@ -19,6 +19,7 @@ exports.isInstanceNotFoundError = isInstanceNotFoundError;
19
19
  exports.isDefaultCredentialsNotSetError = isDefaultCredentialsNotSetError;
20
20
  exports.isProjectIdNotSetInEnvironmentError = isProjectIdNotSetInEnvironmentError;
21
21
  exports.isCreateSessionPermissionError = isCreateSessionPermissionError;
22
+ exports.toArray = toArray;
22
23
  const google_gax_1 = require("google-gax");
23
24
  /**
24
25
  * Checks whether the given error is a 'Database not found' error.
@@ -68,4 +69,27 @@ function isCreateSessionPermissionError(error) {
68
69
  error.code === google_gax_1.grpc.status.PERMISSION_DENIED &&
69
70
  error.message.includes('spanner.sessions.create'));
70
71
  }
72
+ /**
73
+ * Converts any value into an array. Acts as a replacement for `arrify`.
74
+ * If the value is null or undefined, returns an empty array.
75
+ * If the value is already an array, returns is unchanges.
76
+ * Otherwise, wraps the value in a new array.
77
+ * @param value The value to convert into an array.
78
+ * @returns An array containing the value, or an empty array.
79
+ */
80
+ function toArray(value) {
81
+ if (value === null || value === undefined) {
82
+ return [];
83
+ }
84
+ if (Array.isArray(value)) {
85
+ return value;
86
+ }
87
+ if (typeof value === 'string') {
88
+ return [value];
89
+ }
90
+ if (typeof value[Symbol.iterator] === 'function') {
91
+ return [...value];
92
+ }
93
+ return [value];
94
+ }
71
95
  //# sourceMappingURL=helper.js.map