@google-cloud/spanner 7.19.1 → 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.
@@ -17,7 +17,7 @@ import { GrpcService } from './common-grpc/service';
17
17
  import { PreciseDate } from '@google-cloud/precise-date';
18
18
  import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';
19
19
  import { common as p } from 'protobufjs';
20
- import { Float32, Float, Int, Numeric, PGNumeric, PGJsonb, SpannerDate, Struct, ProtoMessage, ProtoEnum, IProtoMessageParams, IProtoEnumParams } from './codec';
20
+ import { Float32, Float, Int, Numeric, PGNumeric, PGJsonb, SpannerDate, Interval, Struct, ProtoMessage, ProtoEnum, IProtoMessageParams, IProtoEnumParams } from './codec';
21
21
  import { Backup } from './backup';
22
22
  import { Database } from './database';
23
23
  import { Instance, CreateInstanceCallback, CreateInstanceResponse } from './instance';
@@ -62,7 +62,9 @@ export interface SpannerOptions extends GrpcClientOptions {
62
62
  sslCreds?: grpc.ChannelCredentials;
63
63
  routeToLeaderEnabled?: boolean;
64
64
  directedReadOptions?: google.spanner.v1.IDirectedReadOptions | null;
65
+ defaultTransactionOptions?: Pick<RunTransactionOptions, 'isolationLevel'>;
65
66
  observabilityOptions?: ObservabilityOptions;
67
+ interceptors?: any[];
66
68
  }
67
69
  export interface RequestConfig {
68
70
  client: string;
@@ -168,7 +170,9 @@ declare class Spanner extends GrpcService {
168
170
  };
169
171
  routeToLeaderEnabled: boolean;
170
172
  directedReadOptions: google.spanner.v1.IDirectedReadOptions | null;
173
+ defaultTransactionOptions: RunTransactionOptions;
171
174
  _observabilityOptions: ObservabilityOptions | undefined;
175
+ readonly _nthClientId: number;
172
176
  /**
173
177
  * Placeholder used to auto populate a column with the commit timestamp.
174
178
  * This can only be used for timestamp columns that have set the option
@@ -971,6 +975,21 @@ declare class Spanner extends GrpcService {
971
975
  * ```
972
976
  */
973
977
  static pgJsonb(value: any): PGJsonb;
978
+ /**
979
+ * Helper function to get a Cloud Spanner Interval object.
980
+ *
981
+ * @param {number} months The months part of Interval as number.
982
+ * @param {number} days The days part of Interval as number.
983
+ * @param {bigint} nanoseconds The nanoseconds part of Interval as bigint.
984
+ * @returns {Interval}
985
+ *
986
+ * @example
987
+ * ```
988
+ * const {Spanner} = require('@google-cloud/spanner');
989
+ * const interval = Spanner.Interval(10, 20, BigInt(30));
990
+ * ```
991
+ */
992
+ static interval(months: number, days: number, nanoseconds: bigint): Interval;
974
993
  /**
975
994
  * @typedef IProtoMessageParams
976
995
  * @property {object} value Proto Message value as serialized-buffer or message object.
@@ -1186,10 +1205,11 @@ export { MutationSet };
1186
1205
  */
1187
1206
  import * as protos from '../protos/protos';
1188
1207
  import IInstanceConfig = instanceAdmin.spanner.admin.instance.v1.IInstanceConfig;
1208
+ import { RunTransactionOptions } from './transaction-runner';
1189
1209
  export { v1, protos };
1190
1210
  declare const _default: {
1191
1211
  Spanner: typeof Spanner;
1192
1212
  };
1193
1213
  export default _default;
1194
- export { Float32, Float, Int, Struct, Numeric, PGNumeric, SpannerDate };
1214
+ export { Float32, Float, Int, Struct, Numeric, PGNumeric, SpannerDate, Interval };
1195
1215
  export { ObservabilityOptions };
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.SpannerDate = exports.PGNumeric = exports.Numeric = exports.Struct = exports.Int = exports.Float = exports.Float32 = exports.protos = exports.v1 = exports.MutationSet = exports.MutationGroup = exports.Transaction = exports.Snapshot = exports.PartitionedDml = exports.Table = exports.SessionPool = exports.Session = exports.Backup = exports.Database = exports.InstanceConfig = exports.Instance = exports.Spanner = void 0;
18
+ exports.Interval = exports.SpannerDate = exports.PGNumeric = exports.Numeric = exports.Struct = exports.Int = exports.Float = exports.Float32 = exports.protos = exports.v1 = exports.MutationSet = exports.MutationGroup = exports.Transaction = exports.Snapshot = exports.PartitionedDml = exports.Table = exports.SessionPool = exports.Session = exports.Backup = exports.Database = exports.InstanceConfig = exports.Instance = exports.Spanner = void 0;
19
19
  const service_1 = require("./common-grpc/service");
20
20
  const precise_date_1 = require("@google-cloud/precise-date");
21
21
  const projectify_1 = require("@google-cloud/projectify");
@@ -32,6 +32,7 @@ Object.defineProperty(exports, "Int", { enumerable: true, get: function () { ret
32
32
  Object.defineProperty(exports, "Numeric", { enumerable: true, get: function () { return codec_1.Numeric; } });
33
33
  Object.defineProperty(exports, "PGNumeric", { enumerable: true, get: function () { return codec_1.PGNumeric; } });
34
34
  Object.defineProperty(exports, "SpannerDate", { enumerable: true, get: function () { return codec_1.SpannerDate; } });
35
+ Object.defineProperty(exports, "Interval", { enumerable: true, get: function () { return codec_1.Interval; } });
35
36
  Object.defineProperty(exports, "Struct", { enumerable: true, get: function () { return codec_1.Struct; } });
36
37
  const api_1 = require("@opentelemetry/api");
37
38
  const backup_1 = require("./backup");
@@ -44,6 +45,7 @@ const instance_config_1 = require("./instance-config");
44
45
  Object.defineProperty(exports, "InstanceConfig", { enumerable: true, get: function () { return instance_config_1.InstanceConfig; } });
45
46
  const google_gax_1 = require("google-gax");
46
47
  const protos_1 = require("../protos/protos");
48
+ var IsolationLevel = protos_1.google.spanner.v1.TransactionOptions.IsolationLevel;
47
49
  const common_1 = require("./common");
48
50
  const session_1 = require("./session");
49
51
  Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return session_1.Session; } });
@@ -62,6 +64,7 @@ const grpcGcp = grpcGcpModule(google_gax_1.grpc);
62
64
  const v1 = require("./v1");
63
65
  exports.v1 = v1;
64
66
  const instrument_1 = require("./instrument");
67
+ const request_id_header_1 = require("./request_id_header");
65
68
  // eslint-disable-next-line @typescript-eslint/no-var-requires
66
69
  const gcpApiConfig = require('./spanner_grpc_config.json');
67
70
  /**
@@ -163,6 +166,12 @@ class Spanner extends service_1.GrpcService {
163
166
  ? options.directedReadOptions
164
167
  : null;
165
168
  delete options.directedReadOptions;
169
+ const defaultTransactionOptions = options.defaultTransactionOptions
170
+ ? options.defaultTransactionOptions
171
+ : {
172
+ isolationLevel: IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED,
173
+ };
174
+ delete options.defaultTransactionOptions;
166
175
  const emulatorHost = Spanner.getSpannerEmulatorHost();
167
176
  if (emulatorHost &&
168
177
  emulatorHost.endpoint &&
@@ -199,9 +208,11 @@ class Spanner extends service_1.GrpcService {
199
208
  this.projectIdReplaced_ = false;
200
209
  this.projectFormattedName_ = 'projects/' + this.projectId;
201
210
  this.directedReadOptions = directedReadOptions;
211
+ this.defaultTransactionOptions = defaultTransactionOptions;
202
212
  this._observabilityOptions = options.observabilityOptions;
203
213
  this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.projectFormattedName_, (_a = this._observabilityOptions) === null || _a === void 0 ? void 0 : _a.enableEndToEndTracing);
204
214
  (0, instrument_1.ensureInitialContextManagerSet)();
215
+ this._nthClientId = (0, request_id_header_1.nextSpannerClientId)();
205
216
  }
206
217
  /**
207
218
  * Gets the InstanceAdminClient object.
@@ -691,6 +702,8 @@ class Spanner extends service_1.GrpcService {
691
702
  carrier[key] = value; // Set the span context (trace and span ID)
692
703
  },
693
704
  });
705
+ // Attach the x-goog-spanner-request-id to the currently active span.
706
+ (0, request_id_header_1.attributeXGoogSpannerRequestIdToActiveSpan)(config);
694
707
  const requestFn = gaxClient[config.method].bind(gaxClient, reqOpts,
695
708
  // Add headers to `gaxOpts`
696
709
  extend(true, {}, config.gaxOpts, {
@@ -698,7 +711,48 @@ class Spanner extends service_1.GrpcService {
698
711
  headers: config.headers,
699
712
  },
700
713
  }));
701
- callback(null, requestFn);
714
+ // Wrap requestFn to inject the spanner request id into every returned error.
715
+ const wrappedRequestFn = (...args) => {
716
+ const hasCallback = args &&
717
+ args.length > 0 &&
718
+ typeof args[args.length - 1] === 'function';
719
+ switch (hasCallback) {
720
+ case true: {
721
+ const cb = args[args.length - 1];
722
+ const priorArgs = args.slice(0, args.length - 1);
723
+ requestFn(...priorArgs, (...results) => {
724
+ if (results && results.length > 0) {
725
+ const err = results[0];
726
+ (0, request_id_header_1.injectRequestIDIntoError)(config, err);
727
+ }
728
+ cb(...results);
729
+ });
730
+ return;
731
+ }
732
+ case false: {
733
+ const res = requestFn(...args);
734
+ const stream = res;
735
+ if (stream) {
736
+ stream.on('error', err => {
737
+ (0, request_id_header_1.injectRequestIDIntoError)(config, err);
738
+ });
739
+ }
740
+ const originallyPromise = res instanceof Promise;
741
+ if (!originallyPromise) {
742
+ return res;
743
+ }
744
+ return new Promise((resolve, reject) => {
745
+ requestFn(...args)
746
+ .then(resolve)
747
+ .catch(err => {
748
+ (0, request_id_header_1.injectRequestIDIntoError)(config, err);
749
+ reject(err);
750
+ });
751
+ });
752
+ }
753
+ }
754
+ };
755
+ callback(null, wrappedRequestFn);
702
756
  });
703
757
  }
704
758
  /**
@@ -936,6 +990,23 @@ class Spanner extends service_1.GrpcService {
936
990
  static pgJsonb(value) {
937
991
  return new codec_1.codec.PGJsonb(value);
938
992
  }
993
+ /**
994
+ * Helper function to get a Cloud Spanner Interval object.
995
+ *
996
+ * @param {number} months The months part of Interval as number.
997
+ * @param {number} days The days part of Interval as number.
998
+ * @param {bigint} nanoseconds The nanoseconds part of Interval as bigint.
999
+ * @returns {Interval}
1000
+ *
1001
+ * @example
1002
+ * ```
1003
+ * const {Spanner} = require('@google-cloud/spanner');
1004
+ * const interval = Spanner.Interval(10, 20, BigInt(30));
1005
+ * ```
1006
+ */
1007
+ static interval(months, days, nanoseconds) {
1008
+ return new codec_1.codec.Interval(months, days, nanoseconds);
1009
+ }
939
1010
  /**
940
1011
  * @typedef IProtoMessageParams
941
1012
  * @property {object} value Proto Message value as serialized-buffer or message object.
@@ -1040,6 +1111,7 @@ Spanner.GOOGLE_STANDARD_SQL = protos_1.google.spanner.admin.database.v1.Database
1040
1111
  'pgJsonb',
1041
1112
  'operation',
1042
1113
  'timestamp',
1114
+ 'interval',
1043
1115
  'getInstanceAdminClient',
1044
1116
  'getDatabaseAdminClient',
1045
1117
  ],
@@ -515,6 +515,10 @@ class Instance extends common.GrpcServiceObject {
515
515
  if (!this.databases_.has(key)) {
516
516
  const db = new database_1.Database(this, name, poolOptions, queryOptions);
517
517
  db._observabilityOptions = this._observabilityOptions;
518
+ const parent = this.parent;
519
+ if (parent && parent._nthClientId) {
520
+ db._clientId = parent._nthClientId;
521
+ }
518
522
  this.databases_.set(key, db);
519
523
  }
520
524
  return this.databases_.get(key);
@@ -38,4 +38,7 @@ declare function nextNthRequest(database: any): number;
38
38
  export interface RequestIDError extends grpc.ServiceError {
39
39
  requestID: string;
40
40
  }
41
- export { AtomicCounter, X_GOOG_SPANNER_REQUEST_ID_HEADER, craftRequestId, injectRequestIDIntoError, injectRequestIDIntoHeaders, nextNthRequest, nextSpannerClientId, newAtomicCounter, randIdForProcess, };
41
+ declare const X_GOOG_SPANNER_REQUEST_ID_SPAN_ATTR = "x_goog_spanner_request_id";
42
+ declare function attributeXGoogSpannerRequestIdToActiveSpan(config: any): void;
43
+ declare const X_GOOG_REQ_ID_REGEX: RegExp;
44
+ export { AtomicCounter, X_GOOG_REQ_ID_REGEX, X_GOOG_SPANNER_REQUEST_ID_HEADER, X_GOOG_SPANNER_REQUEST_ID_SPAN_ATTR, attributeXGoogSpannerRequestIdToActiveSpan, craftRequestId, injectRequestIDIntoError, injectRequestIDIntoHeaders, nextNthRequest, nextSpannerClientId, newAtomicCounter, randIdForProcess, };
@@ -15,8 +15,9 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.randIdForProcess = exports.X_GOOG_SPANNER_REQUEST_ID_HEADER = exports.AtomicCounter = void 0;
18
+ exports.randIdForProcess = exports.X_GOOG_SPANNER_REQUEST_ID_SPAN_ATTR = exports.X_GOOG_SPANNER_REQUEST_ID_HEADER = exports.X_GOOG_REQ_ID_REGEX = exports.AtomicCounter = void 0;
19
19
  exports.resetNthClientId = resetNthClientId;
20
+ exports.attributeXGoogSpannerRequestIdToActiveSpan = attributeXGoogSpannerRequestIdToActiveSpan;
20
21
  exports.craftRequestId = craftRequestId;
21
22
  exports.injectRequestIDIntoError = injectRequestIDIntoError;
22
23
  exports.injectRequestIDIntoHeaders = injectRequestIDIntoHeaders;
@@ -24,6 +25,7 @@ exports.nextNthRequest = nextNthRequest;
24
25
  exports.nextSpannerClientId = nextSpannerClientId;
25
26
  exports.newAtomicCounter = newAtomicCounter;
26
27
  const crypto_1 = require("crypto");
28
+ const instrument_1 = require("./instrument");
27
29
  const randIdForProcess = (0, crypto_1.randomBytes)(8)
28
30
  .readUint32LE(0)
29
31
  .toString(16)
@@ -135,4 +137,22 @@ function nextNthRequest(database) {
135
137
  }
136
138
  return database._nextNthRequest();
137
139
  }
140
+ const X_GOOG_SPANNER_REQUEST_ID_SPAN_ATTR = 'x_goog_spanner_request_id';
141
+ exports.X_GOOG_SPANNER_REQUEST_ID_SPAN_ATTR = X_GOOG_SPANNER_REQUEST_ID_SPAN_ATTR;
142
+ /*
143
+ * attributeXGoogSpannerRequestIdToActiveSpan extracts the x-goog-spanner-request-id
144
+ * from config, if possible and then adds it as an attribute to the current/active span.
145
+ * Since x-goog-spanner-request-id is associated with RPC invoking methods, it is invoked
146
+ * long after tracing has been performed.
147
+ */
148
+ function attributeXGoogSpannerRequestIdToActiveSpan(config) {
149
+ const reqId = extractRequestID(config);
150
+ if (!(reqId && reqId.length > 0)) {
151
+ return;
152
+ }
153
+ const span = (0, instrument_1.getActiveOrNoopSpan)();
154
+ span.setAttribute(X_GOOG_SPANNER_REQUEST_ID_SPAN_ATTR, reqId);
155
+ }
156
+ const X_GOOG_REQ_ID_REGEX = /^1\.[0-9A-Fa-f]{8}(\.\d+){3}\.\d+/;
157
+ exports.X_GOOG_REQ_ID_REGEX = X_GOOG_REQ_ID_REGEX;
138
158
  //# sourceMappingURL=request_id_header.js.map
@@ -40,6 +40,13 @@ export interface SessionFactoryInterface {
40
40
  * @param {GetSessionCallback} callback The callback function.
41
41
  */
42
42
  getSession(callback: GetSessionCallback): void;
43
+ /**
44
+ * When called returns a session for paritioned dml.
45
+ *
46
+ * @name SessionFactoryInterface#getSessionForPartitionedOps
47
+ * @param {GetSessionCallback} callback The callback function.
48
+ */
49
+ getSessionForPartitionedOps(callback: GetSessionCallback): void;
43
50
  /**
44
51
  * When called returns the pool object.
45
52
  *
@@ -75,6 +82,7 @@ export declare class SessionFactory extends common.GrpcServiceObject implements
75
82
  multiplexedSession_: MultiplexedSessionInterface;
76
83
  pool_: SessionPoolInterface;
77
84
  isMultiplexed: boolean;
85
+ isMultiplexedPartitionOps: boolean;
78
86
  constructor(database: Database, name: String, poolOptions?: SessionPoolConstructor | SessionPoolOptions);
79
87
  /**
80
88
  * Retrieves a session, either a regular session or a multiplexed session, based on the environment variable configuration.
@@ -85,6 +93,18 @@ export declare class SessionFactory extends common.GrpcServiceObject implements
85
93
  * @param {GetSessionCallback} callback The callback function.
86
94
  */
87
95
  getSession(callback: GetSessionCallback): void;
96
+ /**
97
+ * Retrieves a session for partitioned operations, selecting the appropriate session type
98
+ * based on whether multiplexed sessions are enabled.
99
+ *
100
+ * If multiplexed sessions are enabled for partitioned ops this methods delegates the request to `getSession()`, which returns
101
+ * either a multiplexed session or a regular session based on the configuration.
102
+ *
103
+ * If the multiplexed sessions are disabled, a session is retrieved from the regular session pool.
104
+ *
105
+ * @param {GetSessionCallback} callback The callback function.
106
+ */
107
+ getSessionForPartitionedOps(callback: GetSessionCallback): void;
88
108
  /**
89
109
  * Returns the regular session pool object.
90
110
  *
@@ -92,9 +112,11 @@ export declare class SessionFactory extends common.GrpcServiceObject implements
92
112
  */
93
113
  getPool(): SessionPoolInterface;
94
114
  /**
95
- * Releases a session back to the session pool.
115
+ * Releases a regular session back to the session pool.
116
+ *
117
+ * This methods does not release a multiplexed session.
96
118
  *
97
- * This method returns a session to the pool after it is no longer needed.
119
+ * It returns a session to the pool after it is no longer needed.
98
120
  * It is a no-op for multiplexed sessions.
99
121
  *
100
122
  * @param {Session} session - The session to be released. This should be an instance of `Session` that was
@@ -47,6 +47,11 @@ class SessionFactory extends common.GrpcServiceObject {
47
47
  process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'true'
48
48
  ? (this.isMultiplexed = true)
49
49
  : (this.isMultiplexed = false);
50
+ // set the isMultiplexedPartitionedOps property to true if multiplexed session is enabled for paritioned ops, otherwise set the property to false
51
+ this.isMultiplexedPartitionOps =
52
+ process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'true' &&
53
+ process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS ===
54
+ 'true';
50
55
  // Multiplexed sessions should only be created if its enabled.
51
56
  if (this.isMultiplexed) {
52
57
  this.multiplexedSession_.on('error', this.emit.bind(database, 'error'));
@@ -67,6 +72,22 @@ class SessionFactory extends common.GrpcServiceObject {
67
72
  : this.pool_;
68
73
  sessionHandler.getSession((err, session, transaction) => callback(err, session, transaction));
69
74
  }
75
+ /**
76
+ * Retrieves a session for partitioned operations, selecting the appropriate session type
77
+ * based on whether multiplexed sessions are enabled.
78
+ *
79
+ * If multiplexed sessions are enabled for partitioned ops this methods delegates the request to `getSession()`, which returns
80
+ * either a multiplexed session or a regular session based on the configuration.
81
+ *
82
+ * If the multiplexed sessions are disabled, a session is retrieved from the regular session pool.
83
+ *
84
+ * @param {GetSessionCallback} callback The callback function.
85
+ */
86
+ getSessionForPartitionedOps(callback) {
87
+ this.isMultiplexedPartitionOps
88
+ ? this.getSession(callback)
89
+ : this.pool_.getSession(callback);
90
+ }
70
91
  /**
71
92
  * Returns the regular session pool object.
72
93
  *
@@ -76,9 +97,11 @@ class SessionFactory extends common.GrpcServiceObject {
76
97
  return this.pool_;
77
98
  }
78
99
  /**
79
- * Releases a session back to the session pool.
100
+ * Releases a regular session back to the session pool.
101
+ *
102
+ * This methods does not release a multiplexed session.
80
103
  *
81
- * This method returns a session to the pool after it is no longer needed.
104
+ * It returns a session to the pool after it is no longer needed.
82
105
  * It is a no-op for multiplexed sessions.
83
106
  *
84
107
  * @param {Session} session - The session to be released. This should be an instance of `Session` that was
@@ -87,7 +110,8 @@ class SessionFactory extends common.GrpcServiceObject {
87
110
  * @throws {Error} If the session is invalid or cannot be released.
88
111
  */
89
112
  release(session) {
90
- if (!this.isMultiplexed) {
113
+ var _a;
114
+ if (!((_a = session.metadata) === null || _a === void 0 ? void 0 : _a.multiplexed)) {
91
115
  this.pool_.release(session);
92
116
  }
93
117
  }
@@ -254,5 +254,6 @@ export declare class Session extends common.GrpcServiceObject {
254
254
  * @returns {Spanner}
255
255
  */
256
256
  private _getSpanner;
257
+ private channelId;
257
258
  }
258
259
  export {};
@@ -25,6 +25,7 @@ const promisify_1 = require("@google-cloud/promisify");
25
25
  const extend = require("extend");
26
26
  const transaction_1 = require("./transaction");
27
27
  const common_1 = require("./common");
28
+ const request_id_header_1 = require("./request_id_header");
28
29
  /**
29
30
  * Create a Session object to interact with a Cloud Spanner session.
30
31
  *
@@ -212,12 +213,13 @@ class Session extends common.GrpcServiceObject {
212
213
  const reqOpts = {
213
214
  name: this.formattedName_,
214
215
  };
216
+ const database = this.parent;
215
217
  return this.request({
216
218
  client: 'SpannerClient',
217
219
  method: 'deleteSession',
218
220
  reqOpts,
219
221
  gaxOpts,
220
- headers: this.commonHeaders_,
222
+ headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(this.commonHeaders_, this, (0, request_id_header_1.nextNthRequest)(database), 1),
221
223
  }, callback);
222
224
  }
223
225
  getMetadata(optionsOrCallback, cb) {
@@ -230,12 +232,13 @@ class Session extends common.GrpcServiceObject {
230
232
  if (this._getSpanner().routeToLeaderEnabled) {
231
233
  (0, common_1.addLeaderAwareRoutingHeader)(headers);
232
234
  }
235
+ const database = this.parent;
233
236
  return this.request({
234
237
  client: 'SpannerClient',
235
238
  method: 'getSession',
236
239
  reqOpts,
237
240
  gaxOpts,
238
- headers: headers,
241
+ headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session, (0, request_id_header_1.nextNthRequest)(database), 1),
239
242
  }, (err, resp) => {
240
243
  if (resp) {
241
244
  resp.databaseRole = resp.creatorRole;
@@ -252,12 +255,13 @@ class Session extends common.GrpcServiceObject {
252
255
  session: this.formattedName_,
253
256
  sql: 'SELECT 1',
254
257
  };
258
+ const database = this.parent;
255
259
  return this.request({
256
260
  client: 'SpannerClient',
257
261
  method: 'executeSql',
258
262
  reqOpts,
259
263
  gaxOpts,
260
- headers: this.commonHeaders_,
264
+ headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(this.commonHeaders_, this, (0, request_id_header_1.nextNthRequest)(database), 1),
261
265
  }, callback);
262
266
  }
263
267
  /**
@@ -335,6 +339,10 @@ class Session extends common.GrpcServiceObject {
335
339
  _getSpanner() {
336
340
  return this.parent.parent.parent;
337
341
  }
342
+ channelId() {
343
+ // The Node.js client does not use a gRPC channel pool, so this always returns 1.
344
+ return 1;
345
+ }
338
346
  }
339
347
  exports.Session = Session;
340
348
  /*! Developer Documentation
@@ -21,6 +21,8 @@ import { google as databaseAdmin } from '../protos/protos';
21
21
  import { Schema, LongRunningCallback } from './common';
22
22
  import IRequestOptions = databaseAdmin.spanner.v1.IRequestOptions;
23
23
  import { ObservabilityOptions } from './instrument';
24
+ import { google } from '../protos/protos';
25
+ import IsolationLevel = google.spanner.v1.TransactionOptions.IsolationLevel;
24
26
  export type Key = string | string[];
25
27
  export type CreateTableResponse = [
26
28
  Table,
@@ -33,6 +35,7 @@ export type DropTableCallback = UpdateSchemaCallback;
33
35
  interface MutateRowsOptions extends CommitOptions {
34
36
  requestOptions?: Omit<IRequestOptions, 'requestTag'>;
35
37
  excludeTxnFromChangeStreams?: boolean;
38
+ isolationLevel?: IsolationLevel;
36
39
  }
37
40
  export type DeleteRowsCallback = CommitCallback;
38
41
  export type DeleteRowsResponse = CommitResponse;
@@ -19,6 +19,8 @@ exports.Table = void 0;
19
19
  const promisify_1 = require("@google-cloud/promisify");
20
20
  const through = require("through2");
21
21
  const instrument_1 = require("./instrument");
22
+ const protos_1 = require("../protos/protos");
23
+ var IsolationLevel = protos_1.google.spanner.v1.TransactionOptions.IsolationLevel;
22
24
  const GOOGLE_STANDARD_SQL = 'GOOGLE_STANDARD_SQL';
23
25
  const POSTGRESQL = 'POSTGRESQL';
24
26
  /**
@@ -243,9 +245,13 @@ class Table {
243
245
  const excludeTxnFromChangeStreams = 'excludeTxnFromChangeStreams' in options
244
246
  ? options.excludeTxnFromChangeStreams
245
247
  : false;
248
+ const isolationLevel = 'isolationLevel' in options
249
+ ? options.isolationLevel
250
+ : IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED;
246
251
  this.database.runTransaction({
247
252
  requestOptions: requestOptions,
248
253
  excludeTxnFromChangeStreams: excludeTxnFromChangeStreams,
254
+ isolationLevel: isolationLevel,
249
255
  }, (err, transaction) => {
250
256
  if (err) {
251
257
  (0, instrument_1.setSpanError)(span, err);
@@ -19,6 +19,7 @@ import { Transaction } from './transaction';
19
19
  import { NormalCallback } from './common';
20
20
  import { google } from '../protos/protos';
21
21
  import IRequestOptions = google.spanner.v1.IRequestOptions;
22
+ import IsolationLevel = google.spanner.v1.TransactionOptions.IsolationLevel;
22
23
  /**
23
24
  * @typedef {object} RunTransactionOptions
24
25
  * @property {number} [timeout] The maximum amount of time (in ms) that a
@@ -29,6 +30,7 @@ export interface RunTransactionOptions {
29
30
  requestOptions?: Pick<IRequestOptions, 'transactionTag'>;
30
31
  optimisticLock?: boolean;
31
32
  excludeTxnFromChangeStreams?: boolean;
33
+ isolationLevel?: IsolationLevel;
32
34
  }
33
35
  /**
34
36
  * A function to execute in the context of a transaction.
@@ -22,6 +22,8 @@ const google_gax_1 = require("google-gax");
22
22
  const protobufjs_1 = require("protobufjs");
23
23
  const through = require("through2");
24
24
  const session_pool_1 = require("./session-pool");
25
+ const protos_1 = require("../protos/protos");
26
+ var IsolationLevel = protos_1.google.spanner.v1.TransactionOptions.IsolationLevel;
25
27
  // eslint-disable-next-line @typescript-eslint/no-var-requires
26
28
  const jsonProtos = require('../protos/protos.json');
27
29
  const RETRY_INFO = 'google.rpc.retryinfo-bin';
@@ -65,7 +67,10 @@ class Runner {
65
67
  this.session = session;
66
68
  this.transaction = transaction;
67
69
  this.transaction.useInRunner();
68
- const defaults = { timeout: 3600000 };
70
+ const defaults = {
71
+ timeout: 3600000,
72
+ isolationLevel: IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED,
73
+ };
69
74
  this.options = Object.assign(defaults, options);
70
75
  }
71
76
  /**
@@ -119,12 +124,7 @@ class Runner {
119
124
  return transaction;
120
125
  }
121
126
  const transaction = this.session.transaction(this.session.parent.queryOptions_);
122
- if (this.options.optimisticLock) {
123
- transaction.useOptimisticLock();
124
- }
125
- if (this.options.excludeTxnFromChangeStreams) {
126
- transaction.excludeTxnFromChangeStreams();
127
- }
127
+ transaction.setReadWriteTransactionOptions(this.options);
128
128
  if (this.attempts > 0) {
129
129
  await transaction.begin();
130
130
  }
@@ -30,6 +30,7 @@ import IQueryOptions = google.spanner.v1.ExecuteSqlRequest.IQueryOptions;
30
30
  import IRequestOptions = google.spanner.v1.IRequestOptions;
31
31
  import { Spanner } from '.';
32
32
  import { ObservabilityOptions } from './instrument';
33
+ import { RunTransactionOptions } from './transaction-runner';
33
34
  export type Rows = Array<Row | Json>;
34
35
  export interface TimestampBounds {
35
36
  strong?: boolean;
@@ -1515,6 +1516,7 @@ export declare class Transaction extends Dml {
1515
1516
  * included in change streams.
1516
1517
  */
1517
1518
  excludeTxnFromChangeStreams(): void;
1519
+ setReadWriteTransactionOptions(options: RunTransactionOptions): void;
1518
1520
  }
1519
1521
  /**
1520
1522
  * MutationSet represent a set of changes to be applied atomically to a Cloud Spanner