@google-cloud/spanner 7.21.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 (51) hide show
  1. package/build/protos/google/spanner/admin/database/v1/backup.proto +1 -1
  2. package/build/protos/google/spanner/admin/database/v1/backup_schedule.proto +1 -1
  3. package/build/protos/google/spanner/admin/database/v1/common.proto +1 -1
  4. package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +1 -1
  5. package/build/protos/google/spanner/admin/instance/v1/common.proto +1 -1
  6. package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +1 -1
  7. package/build/protos/google/spanner/executor/v1/cloud_executor.proto +1 -1
  8. package/build/protos/google/spanner/v1/commit_response.proto +1 -1
  9. package/build/protos/google/spanner/v1/keys.proto +1 -1
  10. package/build/protos/google/spanner/v1/mutation.proto +1 -1
  11. package/build/protos/google/spanner/v1/query_plan.proto +1 -1
  12. package/build/protos/google/spanner/v1/result_set.proto +55 -49
  13. package/build/protos/google/spanner/v1/spanner.proto +1 -1
  14. package/build/protos/google/spanner/v1/transaction.proto +1 -1
  15. package/build/protos/google/spanner/v1/type.proto +1 -1
  16. package/build/protos/protos.d.ts +56 -194
  17. package/build/protos/protos.js +71 -288
  18. package/build/protos/protos.json +8 -2
  19. package/build/src/backup.js +7 -0
  20. package/build/src/batch-transaction.d.ts +48 -29
  21. package/build/src/batch-transaction.js +13 -98
  22. package/build/src/codec.js +43 -26
  23. package/build/src/common-grpc/service-object.js +1 -0
  24. package/build/src/common-grpc/service.js +25 -8
  25. package/build/src/database.js +52 -42
  26. package/build/src/helper.d.ts +9 -0
  27. package/build/src/helper.js +24 -0
  28. package/build/src/index.js +24 -13
  29. package/build/src/instance-config.d.ts +1 -1
  30. package/build/src/instance-config.js +4 -0
  31. package/build/src/instance.js +12 -6
  32. package/build/src/instrument.js +2 -4
  33. package/build/src/multiplexed-session.js +7 -1
  34. package/build/src/partial-result-stream.js +9 -5
  35. package/build/src/request_id_header.js +1 -0
  36. package/build/src/session-factory.js +5 -2
  37. package/build/src/session-pool.js +23 -6
  38. package/build/src/session.d.ts +0 -1
  39. package/build/src/session.js +7 -2
  40. package/build/src/table.js +6 -3
  41. package/build/src/transaction-runner.js +12 -2
  42. package/build/src/transaction.js +66 -52
  43. package/build/src/v1/database_admin_client.d.ts +3 -2
  44. package/build/src/v1/database_admin_client.js +551 -167
  45. package/build/src/v1/instance_admin_client.d.ts +2 -1
  46. package/build/src/v1/instance_admin_client.js +453 -133
  47. package/build/src/v1/spanner_client.d.ts +2 -1
  48. package/build/src/v1/spanner_client.js +283 -85
  49. package/build/src/v1/spanner_executor_proxy_client.d.ts +2 -1
  50. package/build/src/v1/spanner_executor_proxy_client.js +41 -19
  51. package/package.json +57 -58
@@ -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);
@@ -741,7 +756,6 @@ class Database extends common.GrpcServiceObject {
741
756
  });
742
757
  }
743
758
  getTransaction(optionsOrCallback, callback) {
744
- var _a;
745
759
  const cb = typeof optionsOrCallback === 'function'
746
760
  ? optionsOrCallback
747
761
  : callback;
@@ -750,15 +764,15 @@ class Database extends common.GrpcServiceObject {
750
764
  : {};
751
765
  return (0, instrument_1.startTrace)('Database.getTransaction', {
752
766
  ...this._traceConfig,
753
- transactionTag: (_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.transactionTag,
767
+ transactionTag: options.requestOptions?.transactionTag,
754
768
  }, span => {
755
769
  this.pool_.getSession((err, session, transaction) => {
756
770
  if (!err) {
757
771
  if (options.requestOptions) {
758
772
  transaction.requestOptions = Object.assign(transaction.requestOptions || {}, options.requestOptions);
759
773
  }
760
- transaction === null || transaction === void 0 ? void 0 : transaction.setReadWriteTransactionOptions(options);
761
- span.addEvent('Using Session', { 'session.id': session === null || session === void 0 ? void 0 : session.id });
774
+ transaction?.setReadWriteTransactionOptions(options);
775
+ span.addEvent('Using Session', { 'session.id': session?.id });
762
776
  transaction._observabilityOptions = this._observabilityOptions;
763
777
  this._releaseOnEnd(session, transaction, span);
764
778
  }
@@ -822,7 +836,7 @@ class Database extends common.GrpcServiceObject {
822
836
  return;
823
837
  }
824
838
  const span = (0, instrument_1.getActiveOrNoopSpan)();
825
- span.addEvent('Using Session', { 'session.id': session === null || session === void 0 ? void 0 : session.id });
839
+ span.addEvent('Using Session', { 'session.id': session?.id });
826
840
  config.reqOpts.session = session.formattedName_;
827
841
  this.request(config, (err, ...args) => {
828
842
  pool.release(session);
@@ -869,7 +883,7 @@ class Database extends common.GrpcServiceObject {
869
883
  destroyStream(err);
870
884
  return;
871
885
  }
872
- span.addEvent('Using Session', { 'session.id': session_ === null || session_ === void 0 ? void 0 : session_.id });
886
+ span.addEvent('Using Session', { 'session.id': session_?.id });
873
887
  session = session_;
874
888
  config.reqOpts.session = session.formattedName_;
875
889
  requestStream = self.requestStream(config);
@@ -949,11 +963,11 @@ class Database extends common.GrpcServiceObject {
949
963
  });
950
964
  }
951
965
  runPartitionedUpdate(query, callback) {
952
- var _a;
953
966
  return (0, instrument_1.startTrace)('Database.runPartitionedUpdate', {
954
967
  ...query,
955
968
  ...this._traceConfig,
956
- requestTag: (_a = query === null || query === void 0 ? void 0 : query.requestOptions) === null || _a === void 0 ? void 0 : _a.requestTag,
969
+ requestTag: query?.requestOptions
970
+ ?.requestTag,
957
971
  }, span => {
958
972
  this.sessionFactory_.getSessionForPartitionedOps((err, session) => {
959
973
  if (err) {
@@ -962,7 +976,7 @@ class Database extends common.GrpcServiceObject {
962
976
  callback(err, 0);
963
977
  return;
964
978
  }
965
- this._runPartitionedUpdate(session, query, (err, count) => {
979
+ void this._runPartitionedUpdate(session, query, (err, count) => {
966
980
  if (err) {
967
981
  (0, instrument_1.setSpanError)(span, err);
968
982
  }
@@ -983,14 +997,14 @@ class Database extends common.GrpcServiceObject {
983
997
  callback(err, 0);
984
998
  return;
985
999
  }
986
- transaction.runUpdate(query, (err, updateCount) => {
1000
+ transaction.runUpdate(query, async (err, updateCount) => {
987
1001
  if (err) {
988
1002
  if (err.code !== google_gax_1.grpc.status.ABORTED) {
989
1003
  this.sessionFactory_.release(session);
990
1004
  callback(err, 0);
991
1005
  return;
992
1006
  }
993
- this._runPartitionedUpdate(session, query, callback);
1007
+ void this._runPartitionedUpdate(session, query, callback);
994
1008
  }
995
1009
  else {
996
1010
  this.sessionFactory_.release(session);
@@ -1126,12 +1140,11 @@ class Database extends common.GrpcServiceObject {
1126
1140
  * ```
1127
1141
  */
1128
1142
  runStream(query, options) {
1129
- var _a;
1130
1143
  const proxyStream = through.obj();
1131
1144
  return (0, instrument_1.startTrace)('Database.runStream', {
1132
1145
  ...query,
1133
1146
  ...this._traceConfig,
1134
- requestTag: (_a = query === null || query === void 0 ? void 0 : query.requestOptions) === null || _a === void 0 ? void 0 : _a.requestTag,
1147
+ requestTag: query?.requestOptions?.requestTag,
1135
1148
  }, span => {
1136
1149
  this.sessionFactory_.getSession((err, session) => {
1137
1150
  if (err) {
@@ -1140,7 +1153,7 @@ class Database extends common.GrpcServiceObject {
1140
1153
  span.end();
1141
1154
  return;
1142
1155
  }
1143
- span.addEvent('Using Session', { 'session.id': session === null || session === void 0 ? void 0 : session.id });
1156
+ span.addEvent('Using Session', { 'session.id': session?.id });
1144
1157
  const snapshot = session.snapshot(options, this.queryOptions_);
1145
1158
  this._releaseOnEnd(session, snapshot, span);
1146
1159
  let dataReceived = false;
@@ -1162,7 +1175,7 @@ class Database extends common.GrpcServiceObject {
1162
1175
  session.lastError = err;
1163
1176
  }
1164
1177
  span.addEvent('No session available', {
1165
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
1178
+ 'session.id': session?.id,
1166
1179
  });
1167
1180
  // Remove the current data stream from the end user stream.
1168
1181
  dataStream.unpipe(proxyStream);
@@ -1194,7 +1207,6 @@ class Database extends common.GrpcServiceObject {
1194
1207
  });
1195
1208
  }
1196
1209
  runTransaction(optionsOrRunFn, fn) {
1197
- var _a;
1198
1210
  const runFn = typeof optionsOrRunFn === 'function'
1199
1211
  ? optionsOrRunFn
1200
1212
  : fn;
@@ -1203,7 +1215,7 @@ class Database extends common.GrpcServiceObject {
1203
1215
  : {};
1204
1216
  (0, instrument_1.startTrace)('Database.runTransaction', {
1205
1217
  ...this._traceConfig,
1206
- transactionTag: (_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.transactionTag,
1218
+ transactionTag: options.requestOptions?.transactionTag,
1207
1219
  }, span => {
1208
1220
  this.pool_.getSession((err, session, transaction) => {
1209
1221
  if (err) {
@@ -1211,7 +1223,7 @@ class Database extends common.GrpcServiceObject {
1211
1223
  }
1212
1224
  if (err && (0, session_pool_1.isSessionNotFoundError)(err)) {
1213
1225
  span.addEvent('No session available', {
1214
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
1226
+ 'session.id': session?.id,
1215
1227
  });
1216
1228
  span.end();
1217
1229
  this.runTransaction(options, runFn);
@@ -1234,7 +1246,7 @@ class Database extends common.GrpcServiceObject {
1234
1246
  (0, instrument_1.setSpanError)(span, err);
1235
1247
  if ((0, session_pool_1.isSessionNotFoundError)(err)) {
1236
1248
  span.addEvent('No session available', {
1237
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
1249
+ 'session.id': session?.id,
1238
1250
  });
1239
1251
  release();
1240
1252
  this.runTransaction(options, runFn);
@@ -1307,7 +1319,6 @@ class Database extends common.GrpcServiceObject {
1307
1319
  * ```
1308
1320
  */
1309
1321
  async runTransactionAsync(optionsOrRunFn, fn) {
1310
- var _a;
1311
1322
  const runFn = typeof optionsOrRunFn === 'function'
1312
1323
  ? optionsOrRunFn
1313
1324
  : fn;
@@ -1318,7 +1329,7 @@ class Database extends common.GrpcServiceObject {
1318
1329
  const getSession = this.pool_.getSession.bind(this.pool_);
1319
1330
  return (0, instrument_1.startTrace)('Database.runTransactionAsync', {
1320
1331
  ...this._traceConfig,
1321
- transactionTag: (_a = options === null || options === void 0 ? void 0 : options.requestOptions) === null || _a === void 0 ? void 0 : _a.transactionTag,
1332
+ transactionTag: options?.requestOptions?.transactionTag,
1322
1333
  }, async (span) => {
1323
1334
  // Loop to retry 'Session not found' errors.
1324
1335
  // (and yes, we like while (true) more than for (;;) here)
@@ -1328,7 +1339,7 @@ class Database extends common.GrpcServiceObject {
1328
1339
  const [session, transaction] = await (0, promisify_1.promisify)(getSession)();
1329
1340
  transaction.requestOptions = Object.assign(transaction.requestOptions || {}, options.requestOptions);
1330
1341
  transaction.setReadWriteTransactionOptions(options);
1331
- sessionId = session === null || session === void 0 ? void 0 : session.id;
1342
+ sessionId = session?.id;
1332
1343
  span.addEvent('Using Session', { 'session.id': sessionId });
1333
1344
  const runner = new transaction_runner_1.AsyncTransactionRunner(session, transaction, runFn, options);
1334
1345
  try {
@@ -1416,11 +1427,10 @@ class Database extends common.GrpcServiceObject {
1416
1427
  * ```
1417
1428
  */
1418
1429
  batchWriteAtLeastOnce(mutationGroups, options) {
1419
- var _a;
1420
1430
  const proxyStream = through.obj();
1421
1431
  return (0, instrument_1.startTrace)('Database.batchWriteAtLeastOnce', {
1422
1432
  ...this._traceConfig,
1423
- transactionTag: (_a = options === null || options === void 0 ? void 0 : options.requestOptions) === null || _a === void 0 ? void 0 : _a.transactionTag,
1433
+ transactionTag: options?.requestOptions?.transactionTag,
1424
1434
  }, span => {
1425
1435
  this.pool_.getSession((err, session) => {
1426
1436
  if (err) {
@@ -1429,13 +1439,13 @@ class Database extends common.GrpcServiceObject {
1429
1439
  span.end();
1430
1440
  return;
1431
1441
  }
1432
- span.addEvent('Using Session', { 'session.id': session === null || session === void 0 ? void 0 : session.id });
1433
- 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);
1434
1444
  const reqOpts = Object.assign({}, {
1435
1445
  session: session.formattedName_,
1436
1446
  mutationGroups: mutationGroups.map(mg => mg.proto()),
1437
- requestOptions: options === null || options === void 0 ? void 0 : options.requestOptions,
1438
- excludeTxnFromChangeStream: options === null || options === void 0 ? void 0 : options.excludeTxnFromChangeStreams,
1447
+ requestOptions: options?.requestOptions,
1448
+ excludeTxnFromChangeStream: options?.excludeTxnFromChangeStreams,
1439
1449
  });
1440
1450
  let dataReceived = false;
1441
1451
  let dataStream = this.requestStream({
@@ -1458,7 +1468,7 @@ class Database extends common.GrpcServiceObject {
1458
1468
  session.lastError = err;
1459
1469
  }
1460
1470
  span.addEvent('No session available', {
1461
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
1471
+ 'session.id': session?.id,
1462
1472
  });
1463
1473
  // Remove the current data stream from the end user stream.
1464
1474
  dataStream.unpipe(proxyStream);
@@ -1495,7 +1505,7 @@ class Database extends common.GrpcServiceObject {
1495
1505
  (0, session_pool_1.isSessionNotFoundError)(err) &&
1496
1506
  !this.sessionFactory_.isMultiplexedEnabled()) {
1497
1507
  span.addEvent('No session available', {
1498
- 'session.id': session === null || session === void 0 ? void 0 : session.id,
1508
+ 'session.id': session?.id,
1499
1509
  });
1500
1510
  span.end();
1501
1511
  this.writeAtLeastOnce(mutations, options, cb);
@@ -1507,12 +1517,12 @@ class Database extends common.GrpcServiceObject {
1507
1517
  cb(err);
1508
1518
  return;
1509
1519
  }
1510
- span.addEvent('Using Session', { 'session.id': session === null || session === void 0 ? void 0 : session.id });
1520
+ span.addEvent('Using Session', { 'session.id': session?.id });
1511
1521
  this._releaseOnEnd(session, transaction, span);
1512
1522
  try {
1513
1523
  transaction.setReadWriteTransactionOptions(options);
1514
- transaction === null || transaction === void 0 ? void 0 : transaction.setQueuedMutations(mutations.proto());
1515
- 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) => {
1516
1526
  if (err) {
1517
1527
  (0, instrument_1.setSpanError)(span, err);
1518
1528
  }
@@ -1578,7 +1588,7 @@ class Database extends common.GrpcServiceObject {
1578
1588
  const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
1579
1589
  if (typeof statements === 'string' || Array.isArray(statements)) {
1580
1590
  statements = {
1581
- statements: arrify(statements),
1591
+ statements: (0, helper_1.toArray)(statements),
1582
1592
  };
1583
1593
  }
1584
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
@@ -108,6 +108,29 @@ const gcpApiConfig = require('./spanner_grpc_config.json');
108
108
  * @param {ClientConfig} [options] Configuration options.
109
109
  */
110
110
  class Spanner extends service_1.GrpcService {
111
+ options;
112
+ auth;
113
+ clients_;
114
+ instances_;
115
+ instanceConfigs_;
116
+ projectIdReplaced_;
117
+ projectFormattedName_;
118
+ commonHeaders_;
119
+ routeToLeaderEnabled = true;
120
+ directedReadOptions;
121
+ defaultTransactionOptions;
122
+ _observabilityOptions;
123
+ _nthClientId;
124
+ /**
125
+ * Placeholder used to auto populate a column with the commit timestamp.
126
+ * This can only be used for timestamp columns that have set the option
127
+ * "(allow_commit_timestamp=true)" in the schema.
128
+ *
129
+ * @type {string}
130
+ */
131
+ static COMMIT_TIMESTAMP = 'spanner.commit_timestamp()';
132
+ static POSTGRESQL = protos_1.google.spanner.admin.database.v1.DatabaseDialect.POSTGRESQL;
133
+ static GOOGLE_STANDARD_SQL = protos_1.google.spanner.admin.database.v1.DatabaseDialect.GOOGLE_STANDARD_SQL;
111
134
  /**
112
135
  * Gets the configured Spanner emulator host from an environment variable.
113
136
  */
@@ -135,7 +158,6 @@ class Spanner extends service_1.GrpcService {
135
158
  return undefined;
136
159
  }
137
160
  constructor(options) {
138
- var _a;
139
161
  const scopes = [];
140
162
  const clientClasses = [
141
163
  v1.DatabaseAdminClient,
@@ -196,7 +218,6 @@ class Spanner extends service_1.GrpcService {
196
218
  packageJson: require('../../package.json'),
197
219
  };
198
220
  super(config, options);
199
- this.routeToLeaderEnabled = true;
200
221
  if (options.routeToLeaderEnabled === false) {
201
222
  this.routeToLeaderEnabled = false;
202
223
  }
@@ -210,7 +231,7 @@ class Spanner extends service_1.GrpcService {
210
231
  this.directedReadOptions = directedReadOptions;
211
232
  this.defaultTransactionOptions = defaultTransactionOptions;
212
233
  this._observabilityOptions = options.observabilityOptions;
213
- this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.projectFormattedName_, (_a = this._observabilityOptions) === null || _a === void 0 ? void 0 : _a.enableEndToEndTracing);
234
+ this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.projectFormattedName_, this._observabilityOptions?.enableEndToEndTracing);
214
235
  (0, instrument_1.ensureInitialContextManagerSet)();
215
236
  this._nthClientId = (0, request_id_header_1.nextSpannerClientId)();
216
237
  }
@@ -1083,16 +1104,6 @@ class Spanner extends service_1.GrpcService {
1083
1104
  }
1084
1105
  }
1085
1106
  exports.Spanner = Spanner;
1086
- /**
1087
- * Placeholder used to auto populate a column with the commit timestamp.
1088
- * This can only be used for timestamp columns that have set the option
1089
- * "(allow_commit_timestamp=true)" in the schema.
1090
- *
1091
- * @type {string}
1092
- */
1093
- Spanner.COMMIT_TIMESTAMP = 'spanner.commit_timestamp()';
1094
- Spanner.POSTGRESQL = protos_1.google.spanner.admin.database.v1.DatabaseDialect.POSTGRESQL;
1095
- Spanner.GOOGLE_STANDARD_SQL = protos_1.google.spanner.admin.database.v1.DatabaseDialect.GOOGLE_STANDARD_SQL;
1096
1107
  /*! Developer Documentation
1097
1108
  *
1098
1109
  * All async methods (except for streams) will return a Promise in the event
@@ -14,7 +14,7 @@
14
14
  */
15
15
  declare const common: any;
16
16
  import { google as instanceAdmin } from '../protos/protos';
17
- import { Operation as GaxOperation } from 'google-gax/build/src/longRunningCalls/longrunning';
17
+ import { Operation as GaxOperation } from 'google-gax';
18
18
  import { LongRunningCallback, RequestCallback, ResourceCallback, NormalCallback } from './common';
19
19
  import { GetInstanceConfigCallback, GetInstanceConfigOptions, GetInstanceConfigResponse, RequestConfig, Spanner } from './index';
20
20
  import { CallOptions } from 'google-gax';
@@ -41,6 +41,10 @@ const extend = require("extend");
41
41
  * ```
42
42
  */
43
43
  class InstanceConfig extends common.GrpcServiceObject {
44
+ formattedName_;
45
+ request;
46
+ metadata;
47
+ resourceHeader_;
44
48
  constructor(spanner, name) {
45
49
  const formattedName_ = InstanceConfig.formatName_(spanner.projectId, name);
46
50
  const methods = {
@@ -16,7 +16,7 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.Instance = void 0;
19
- const arrify = require("arrify");
19
+ const helper_1 = require("./helper");
20
20
  // eslint-disable-next-line @typescript-eslint/no-var-requires
21
21
  const common = require('./common-grpc/service-object');
22
22
  const promisify_1 = require("@google-cloud/promisify");
@@ -46,8 +46,14 @@ const protos_1 = require("../protos/protos");
46
46
  * ```
47
47
  */
48
48
  class Instance extends common.GrpcServiceObject {
49
+ formattedName_;
50
+ request;
51
+ requestStream;
52
+ databases_;
53
+ metadata;
54
+ commonHeaders_;
55
+ _observabilityOptions;
49
56
  constructor(spanner, name) {
50
- var _a;
51
57
  const formattedName_ = Instance.formatName_(spanner.projectId, name);
52
58
  const methods = {
53
59
  /**
@@ -116,7 +122,7 @@ class Instance extends common.GrpcServiceObject {
116
122
  this.requestStream = spanner.requestStream.bind(spanner);
117
123
  this.databases_ = new Map();
118
124
  this._observabilityOptions = spanner._observabilityOptions;
119
- this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.formattedName_, (_a = this._observabilityOptions) === null || _a === void 0 ? void 0 : _a.enableEndToEndTracing);
125
+ this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.formattedName_, this._observabilityOptions?.enableEndToEndTracing);
120
126
  }
121
127
  /**
122
128
  * Get a reference to a Backup object.
@@ -456,7 +462,7 @@ class Instance extends common.GrpcServiceObject {
456
462
  delete reqOpts.poolCtor;
457
463
  delete reqOpts.gaxOptions;
458
464
  if (reqOpts.schema) {
459
- reqOpts.extraStatements = arrify(reqOpts.schema);
465
+ reqOpts.extraStatements = (0, helper_1.toArray)(reqOpts.schema);
460
466
  delete reqOpts.schema;
461
467
  }
462
468
  this.request({
@@ -529,7 +535,7 @@ class Instance extends common.GrpcServiceObject {
529
535
  const reqOpts = {
530
536
  name: this.formattedName_,
531
537
  };
532
- Promise.all(Array.from(this.databases_.values()).map(database => {
538
+ void Promise.all(Array.from(this.databases_.values()).map(database => {
533
539
  return database.close();
534
540
  }))
535
541
  .catch(() => { })
@@ -715,7 +721,7 @@ class Instance extends common.GrpcServiceObject {
715
721
  };
716
722
  if (options.fieldNames) {
717
723
  reqOpts['fieldMask'] = {
718
- paths: arrify(options['fieldNames']).map(snakeCase),
724
+ paths: (0, helper_1.toArray)(options['fieldNames']).map(snakeCase),
719
725
  };
720
726
  }
721
727
  return this.request({
@@ -73,12 +73,10 @@ function ensureInitialContextManagerSet() {
73
73
  * @returns {Span} The created span.
74
74
  */
75
75
  function startTrace(spanNameSuffix, config, cb) {
76
- var _a;
77
76
  if (!config) {
78
77
  config = {};
79
78
  }
80
- return getTracer((_a = config.opts) === null || _a === void 0 ? void 0 : _a.tracerProvider).startActiveSpan(SPAN_NAMESPACE_PREFIX + '.' + spanNameSuffix, { kind: api_1.SpanKind.CLIENT }, span => {
81
- var _a;
79
+ return getTracer(config.opts?.tracerProvider).startActiveSpan(SPAN_NAMESPACE_PREFIX + '.' + spanNameSuffix, { kind: api_1.SpanKind.CLIENT }, span => {
82
80
  span.setAttribute(semantic_conventions_1.ATTR_OTEL_SCOPE_NAME, TRACER_NAME);
83
81
  span.setAttribute(semantic_conventions_1.ATTR_OTEL_SCOPE_VERSION, TRACER_VERSION);
84
82
  span.setAttribute('gcp.client.service', 'spanner');
@@ -96,7 +94,7 @@ function startTrace(spanNameSuffix, config, cb) {
96
94
  if (config.transactionTag) {
97
95
  span.setAttribute('transaction.tag', config.transactionTag);
98
96
  }
99
- const allowExtendedTracing = optedInPII || ((_a = config.opts) === null || _a === void 0 ? void 0 : _a.enableExtendedTracing);
97
+ const allowExtendedTracing = optedInPII || config.opts?.enableExtendedTracing;
100
98
  if (config.sql && allowExtendedTracing) {
101
99
  const sql = config.sql;
102
100
  if (typeof sql === 'string') {
@@ -30,6 +30,12 @@ exports.MUX_SESSION_CREATE_ERROR = 'mux-session-create-error';
30
30
  * @extends {EventEmitter}
31
31
  */
32
32
  class MultiplexedSession extends events_1.EventEmitter {
33
+ database;
34
+ // frequency to create new mux session
35
+ refreshRate;
36
+ _multiplexedSession;
37
+ _refreshHandle;
38
+ _observabilityOptions;
33
39
  constructor(database) {
34
40
  super();
35
41
  this.database = database;
@@ -125,7 +131,7 @@ class MultiplexedSession extends events_1.EventEmitter {
125
131
  *
126
132
  */
127
133
  getSession(callback) {
128
- this._acquire().then(session => callback(null, session, session === null || session === void 0 ? void 0 : session.txn), callback);
134
+ this._acquire().then(session => callback(null, session, session?.txn), callback);
129
135
  }
130
136
  /**
131
137
  * Acquires a session asynchronously, and prepares the transaction for the session.
@@ -39,9 +39,15 @@ const stream = require("stream");
39
39
  * @param {RowOptions} [options] The row options.
40
40
  */
41
41
  class PartialResultStream extends stream_1.Transform {
42
+ _destroyed;
43
+ _fields;
44
+ _options;
45
+ _pendingValue;
46
+ _pendingValueForResume;
47
+ _values;
48
+ _numPushFailed = 0;
42
49
  constructor(options = {}) {
43
50
  super({ objectMode: true });
44
- this._numPushFailed = 0;
45
51
  this._destroyed = false;
46
52
  this._options = Object.assign({ maxResumeRetries: 20 }, options);
47
53
  this._values = [];
@@ -199,9 +205,8 @@ class PartialResultStream extends stream_1.Transform {
199
205
  */
200
206
  _createRow(values) {
201
207
  const fields = values.map((value, index) => {
202
- var _a;
203
208
  const { name, type } = this._fields[index];
204
- const columnMetadata = (_a = this._options.columnsMetadata) === null || _a === void 0 ? void 0 : _a[name];
209
+ const columnMetadata = this._options.columnsMetadata?.[name];
205
210
  return {
206
211
  name,
207
212
  value: codec_1.codec.decode(value, type, columnMetadata),
@@ -284,13 +289,12 @@ exports.PartialResultStream = PartialResultStream;
284
289
  * @returns {PartialResultStream}
285
290
  */
286
291
  function partialResultStream(requestFn, options) {
287
- var _a, _b;
288
292
  const retryableCodes = [google_gax_1.grpc.status.UNAVAILABLE];
289
293
  const maxQueued = 10;
290
294
  let lastResumeToken;
291
295
  let lastRequestStream;
292
296
  const startTime = Date.now();
293
- const timeout = (_b = (_a = options === null || options === void 0 ? void 0 : options.gaxOptions) === null || _a === void 0 ? void 0 : _a.timeout) !== null && _b !== void 0 ? _b : Infinity;
297
+ const timeout = options?.gaxOptions?.timeout ?? Infinity;
294
298
  // mergeStream allows multiple streams to be connected into one. This is good;
295
299
  // if we need to retry a request and pipe more data to the user's stream.
296
300
  // We also add an additional stream that can be used to flush any remaining
@@ -34,6 +34,7 @@ exports.randIdForProcess = randIdForProcess;
34
34
  const X_GOOG_SPANNER_REQUEST_ID_HEADER = 'x-goog-spanner-request-id';
35
35
  exports.X_GOOG_SPANNER_REQUEST_ID_HEADER = X_GOOG_SPANNER_REQUEST_ID_HEADER;
36
36
  class AtomicCounter {
37
+ backingBuffer;
37
38
  constructor(initialValue) {
38
39
  this.backingBuffer = new Uint32Array(new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT));
39
40
  if (initialValue) {
@@ -31,6 +31,10 @@ const common = require('./common-grpc/service-object');
31
31
  * configuration options or custom pool inteface.
32
32
  */
33
33
  class SessionFactory extends common.GrpcServiceObject {
34
+ multiplexedSession_;
35
+ pool_;
36
+ isMultiplexed;
37
+ isMultiplexedPartitionOps;
34
38
  constructor(database, name, poolOptions) {
35
39
  super({
36
40
  parent: database,
@@ -110,8 +114,7 @@ class SessionFactory extends common.GrpcServiceObject {
110
114
  * @throws {Error} If the session is invalid or cannot be released.
111
115
  */
112
116
  release(session) {
113
- var _a;
114
- if (!((_a = session.metadata) === null || _a === void 0 ? void 0 : _a.multiplexed)) {
117
+ if (!session.metadata?.multiplexed) {
115
118
  this.pool_.release(session);
116
119
  }
117
120
  }