@google-cloud/spanner 7.19.0 → 7.20.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.
@@ -29,8 +29,10 @@ const instrument_1 = require("./instrument");
29
29
  const protos_1 = require("../protos/protos");
30
30
  const common_1 = require("./common");
31
31
  const protos_2 = require("../protos/protos");
32
+ var IsolationLevel = protos_2.google.spanner.v1.TransactionOptions.IsolationLevel;
32
33
  var ReadLockMode = protos_2.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
33
34
  const instrument_2 = require("./instrument");
35
+ const request_id_header_1 = require("./request_id_header");
34
36
  const RETRY_INFO_TYPE = 'type.googleapis.com/google.rpc.retryinfo';
35
37
  const RETRY_INFO_BIN = 'google.rpc.retryinfo-bin';
36
38
  /**
@@ -182,7 +184,7 @@ class Snapshot extends events_1.EventEmitter {
182
184
  method: 'beginTransaction',
183
185
  reqOpts,
184
186
  gaxOpts,
185
- headers: headers,
187
+ headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session),
186
188
  }, (err, resp) => {
187
189
  if (err) {
188
190
  (0, instrument_2.setSpanError)(span, err);
@@ -412,6 +414,8 @@ class Snapshot extends events_1.EventEmitter {
412
414
  return (0, instrument_2.startTrace)('Snapshot.createReadStream', traceConfig, span => {
413
415
  var _a;
414
416
  let attempt = 0;
417
+ const database = this.session.parent;
418
+ const nthRequest = (0, request_id_header_1.nextNthRequest)(database);
415
419
  const makeRequest = (resumeToken) => {
416
420
  if (this.id && transaction.begin) {
417
421
  delete transaction.begin;
@@ -437,7 +441,7 @@ class Snapshot extends events_1.EventEmitter {
437
441
  method: 'streamingRead',
438
442
  reqOpts: Object.assign({}, reqOpts, { resumeToken }),
439
443
  gaxOpts: gaxOptions,
440
- headers: headers,
444
+ headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session, nthRequest, attempt),
441
445
  });
442
446
  };
443
447
  const resultStream = (_a = (0, partial_result_stream_1.partialResultStream)(this._wrapWithIdWaiter(makeRequest), {
@@ -752,6 +756,8 @@ class Snapshot extends events_1.EventEmitter {
752
756
  };
753
757
  return (0, instrument_2.startTrace)('Snapshot.runStream', traceConfig, span => {
754
758
  let attempt = 0;
759
+ const database = this.session.parent;
760
+ const nthRequest = (0, request_id_header_1.nextNthRequest)(database);
755
761
  const makeRequest = (resumeToken) => {
756
762
  attempt++;
757
763
  if (!resumeToken) {
@@ -785,7 +791,7 @@ class Snapshot extends events_1.EventEmitter {
785
791
  method: 'executeStreamingSql',
786
792
  reqOpts: Object.assign({}, reqOpts, { resumeToken }),
787
793
  gaxOpts: gaxOptions,
788
- headers: headers,
794
+ headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session, nthRequest, attempt),
789
795
  });
790
796
  };
791
797
  const resultStream = (0, partial_result_stream_1.partialResultStream)(this._wrapWithIdWaiter(makeRequest), {
@@ -915,10 +921,11 @@ class Snapshot extends events_1.EventEmitter {
915
921
  * @returns {object}
916
922
  */
917
923
  static encodeParams(request) {
924
+ var _a;
918
925
  const typeMap = request.types || {};
919
- const params = {};
920
- const paramTypes = {};
921
- if (request.params) {
926
+ const params = { fields: ((_a = request.params) === null || _a === void 0 ? void 0 : _a.fields) || {} };
927
+ const paramTypes = request.paramTypes || {};
928
+ if (request.params && !request.params.fields) {
922
929
  const fields = {};
923
930
  Object.keys(request.params).forEach(param => {
924
931
  const value = request.params[param];
@@ -1153,6 +1160,7 @@ class Transaction extends Dml {
1153
1160
  super(session, undefined, queryOptions);
1154
1161
  this._queuedMutations = [];
1155
1162
  this._options = { readWrite: options };
1163
+ this._options.isolationLevel = IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED;
1156
1164
  this.requestOptions = requestOptions;
1157
1165
  }
1158
1166
  batchUpdate(queries, optionsOrCallback, cb) {
@@ -1194,7 +1202,8 @@ class Transaction extends Dml {
1194
1202
  seqno: this._seqno++,
1195
1203
  statements,
1196
1204
  };
1197
- const headers = this.commonHeaders_;
1205
+ const database = this.session.parent;
1206
+ const headers = (0, request_id_header_1.injectRequestIDIntoHeaders)(this.commonHeaders_, this.session, (0, request_id_header_1.nextNthRequest)(database), 1);
1198
1207
  if (this._getSpanner().routeToLeaderEnabled) {
1199
1208
  (0, common_1.addLeaderAwareRoutingHeader)(headers);
1200
1209
  }
@@ -1316,12 +1325,13 @@ class Transaction extends Dml {
1316
1325
  (0, common_1.addLeaderAwareRoutingHeader)(headers);
1317
1326
  }
1318
1327
  span.addEvent('Starting Commit');
1328
+ const database = this.session.parent;
1319
1329
  this.request({
1320
1330
  client: 'SpannerClient',
1321
1331
  method: 'commit',
1322
1332
  reqOpts,
1323
1333
  gaxOpts: gaxOpts,
1324
- headers: headers,
1334
+ headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session, (0, request_id_header_1.nextNthRequest)(database), 1),
1325
1335
  }, (err, resp) => {
1326
1336
  this.end();
1327
1337
  if (err) {
@@ -1735,6 +1745,27 @@ class Transaction extends Dml {
1735
1745
  excludeTxnFromChangeStreams() {
1736
1746
  this._options.excludeTxnFromChangeStreams = true;
1737
1747
  }
1748
+ setReadWriteTransactionOptions(options) {
1749
+ /**
1750
+ * Set optimistic concurrency control for the transaction.
1751
+ */
1752
+ if (options === null || options === void 0 ? void 0 : options.optimisticLock) {
1753
+ this._options.readWrite.readLockMode = ReadLockMode.OPTIMISTIC;
1754
+ }
1755
+ /**
1756
+ * Set option excludeTxnFromChangeStreams=true to exclude read/write transactions
1757
+ * from being tracked in change streams.
1758
+ */
1759
+ if (options === null || options === void 0 ? void 0 : options.excludeTxnFromChangeStreams) {
1760
+ this._options.excludeTxnFromChangeStreams = true;
1761
+ }
1762
+ /**
1763
+ * Set isolation level .
1764
+ */
1765
+ this._options.isolationLevel = (options === null || options === void 0 ? void 0 : options.isolationLevel)
1766
+ ? options === null || options === void 0 ? void 0 : options.isolationLevel
1767
+ : this._getSpanner().defaultTransactionOptions.isolationLevel;
1768
+ }
1738
1769
  }
1739
1770
  exports.Transaction = Transaction;
1740
1771
  /*! Developer Documentation
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@google-cloud/spanner",
3
3
  "description": "Cloud Spanner Client Library for Node.js",
4
- "version": "7.19.0",
4
+ "version": "7.20.0",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Google Inc.",
7
7
  "engines": {
@@ -57,7 +57,7 @@
57
57
  "@google-cloud/common": "^5.0.0",
58
58
  "@google-cloud/precise-date": "^4.0.0",
59
59
  "@google-cloud/projectify": "^4.0.0",
60
- "@google-cloud/promisify": "^4.0.0",
60
+ "@google-cloud/promisify": "4.0.0",
61
61
  "@grpc/proto-loader": "^0.7.0",
62
62
  "@opentelemetry/api": "^1.9.0",
63
63
  "@opentelemetry/core": "^1.27.0",