@google-cloud/spanner 8.12.0 → 9.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.
@@ -83,9 +83,9 @@ function transformResourceMetricToTimeSeriesArray(resourceMetrics, projectId) {
83
83
  function _createTimeSeries(metric, dataPoint, resource, projectId) {
84
84
  const type = path.posix.join(constants_1.CLIENT_METRICS_PREFIX, metric.descriptor.name);
85
85
  const resourceLabels = resource
86
- ? _extractLabels(resource, projectId)
86
+ ? _extractLabels(resource, projectId, true)
87
87
  : { metricLabels: {}, monitoredResourceLabels: {} };
88
- const dataLabels = _extractLabels(dataPoint, projectId);
88
+ const dataLabels = _extractLabels(dataPoint, projectId, false);
89
89
  const labels = {
90
90
  ...resourceLabels.metricLabels,
91
91
  ...dataLabels.metricLabels,
@@ -152,15 +152,21 @@ function _transformPoint(metric, dataPoint) {
152
152
  };
153
153
  }
154
154
  }
155
- /** Extracts metric and monitored resource labels from data point */
156
- function _extractLabels({ attributes = {} }, projectId) {
155
+ /** Extracts metric and monitored resource labels from data point or resource */
156
+ function _extractLabels({ attributes = {} }, projectId, isResource = false) {
157
157
  const factory = metrics_tracer_factory_1.MetricsTracerFactory.getInstance(projectId);
158
- // Add Client name and Client UID metric labels
159
- attributes[constants_1.METRIC_LABEL_KEY_CLIENT_UID] =
160
- factory?.clientUid ?? constants_1.UNKNOWN_ATTRIBUTE;
161
- attributes[constants_1.METRIC_LABEL_KEY_CLIENT_NAME] =
162
- factory?.clientName ?? constants_1.UNKNOWN_ATTRIBUTE;
163
- return Object.entries(attributes).reduce((result, [key, value]) => {
158
+ const combinedAttributes = {
159
+ ...attributes,
160
+ [constants_1.METRIC_LABEL_KEY_CLIENT_UID]: factory?.clientUid ?? constants_1.UNKNOWN_ATTRIBUTE,
161
+ [constants_1.METRIC_LABEL_KEY_CLIENT_NAME]: factory?.clientName ?? constants_1.UNKNOWN_ATTRIBUTE,
162
+ };
163
+ if (isResource &&
164
+ factory?.location &&
165
+ (!combinedAttributes[constants_1.MONITORED_RES_LABEL_KEY_LOCATION] ||
166
+ combinedAttributes[constants_1.MONITORED_RES_LABEL_KEY_LOCATION] === 'global')) {
167
+ combinedAttributes[constants_1.MONITORED_RES_LABEL_KEY_LOCATION] = factory.location;
168
+ }
169
+ return Object.entries(combinedAttributes).reduce((result, [key, value]) => {
164
170
  const normalizedKey = _normalizeLabelKey(key);
165
171
  const val = value?.toString();
166
172
  if (constants_1.METRIC_LABELS.has(key))
@@ -42,6 +42,12 @@ export interface MultiplexedSessionInterface extends EventEmitter {
42
42
  * @param {GetSessionCallback} callback The callback function.
43
43
  */
44
44
  getSession(callback: GetSessionCallback): void;
45
+ /**
46
+ * When called returns a cached multiplexed session synchronously if available.
47
+ *
48
+ * @name MultiplexedSessionInterface#getSessionSync
49
+ */
50
+ getSessionSync(): Session | null;
45
51
  }
46
52
  /**
47
53
  * Class used to manage connections to Spanner using multiplexed session.
@@ -98,6 +104,13 @@ export declare class MultiplexedSession extends EventEmitter implements Multiple
98
104
  *
99
105
  */
100
106
  _maintain(): void;
107
+ /**
108
+ * Synchronously returns the cached multiplexed session if available,
109
+ * or null if no session is currently cached.
110
+ *
111
+ * @returns {Session|null} The cached multiplexed session or null.
112
+ */
113
+ getSessionSync(): Session | null;
101
114
  /**
102
115
  * Retrieves a session asynchronously and invokes a callback with the session details.
103
116
  * Note: The callback receives `(null, session)`. To prevent unnecessary allocations on
@@ -144,6 +144,20 @@ class MultiplexedSession extends events_1.EventEmitter {
144
144
  // force the process to stay open.
145
145
  this._refreshHandle.unref();
146
146
  }
147
+ /**
148
+ * Synchronously returns the cached multiplexed session if available,
149
+ * or null if no session is currently cached.
150
+ *
151
+ * @returns {Session|null} The cached multiplexed session or null.
152
+ */
153
+ getSessionSync() {
154
+ if (this._multiplexedSession !== null) {
155
+ const span = (0, instrument_1.getActiveOrNoopSpan)();
156
+ span.addEvent('Cache hit: has usable multiplexed session');
157
+ return this._multiplexedSession;
158
+ }
159
+ return null;
160
+ }
147
161
  /**
148
162
  * Retrieves a session asynchronously and invokes a callback with the session details.
149
163
  * Note: The callback receives `(null, session)`. To prevent unnecessary allocations on
@@ -156,10 +170,8 @@ class MultiplexedSession extends events_1.EventEmitter {
156
170
  *
157
171
  */
158
172
  getSession(callback) {
159
- if (this._multiplexedSession !== null) {
160
- const session = this._multiplexedSession;
161
- const span = (0, instrument_1.getActiveOrNoopSpan)();
162
- span.addEvent('Cache hit: has usable multiplexed session');
173
+ const session = this.getSessionSync();
174
+ if (session !== null) {
163
175
  // Use process.nextTick to guarantee asynchronous callback execution ("never release Zalgo").
164
176
  // This avoids microtask and Promise allocation overhead while preventing race conditions
165
177
  // where callers (such as Database.prototype.runStream) need to return their stream and
@@ -196,12 +208,12 @@ class MultiplexedSession extends events_1.EventEmitter {
196
208
  *
197
209
  */
198
210
  async _getSession() {
199
- const span = (0, instrument_1.getActiveOrNoopSpan)();
200
211
  // Check if the multiplexed session is already available
201
- if (this._multiplexedSession !== null) {
202
- span.addEvent('Cache hit: has usable multiplexed session');
203
- return this._multiplexedSession;
212
+ const cachedSession = this.getSessionSync();
213
+ if (cachedSession !== null) {
214
+ return cachedSession;
204
215
  }
216
+ const span = (0, instrument_1.getActiveOrNoopSpan)();
205
217
  span.addEvent('Waiting for a multiplexed session to become available');
206
218
  // If initialization is ALREADY in progress, join the existing line!
207
219
  if (this._sharedMuxSessionWaitPromise) {
@@ -106,6 +106,39 @@ export interface Row extends Array<Field> {
106
106
  */
107
107
  toJSON(options?: JSONOptions): Json;
108
108
  }
109
+ /**
110
+ * Creates an array of decoder functions for the specified struct fields.
111
+ *
112
+ * @private
113
+ */
114
+ export declare function createFieldDecoders(fields: google.spanner.v1.StructType.Field[], options?: RowOptions): Function[];
115
+ /**
116
+ * Directly creates a plain JSON object from row cell values, bypassing
117
+ * Struct, Row, and WrappedNumber class wrappers when possible.
118
+ *
119
+ * @private
120
+ */
121
+ export declare function createJsonRow(fields: google.spanner.v1.StructType.Field[], decoders: Function[], values: Value[], includeNameless?: boolean): Json;
122
+ /**
123
+ * Converts an array of decoded cell values into a Row.
124
+ *
125
+ * @private
126
+ */
127
+ export declare function createRow(fields: google.spanner.v1.StructType.Field[], decoders: Function[], values: Value[]): Row;
128
+ /**
129
+ * Formats raw row values into either a plain JSON object or a Row instance
130
+ * according to the provided RowOptions.
131
+ *
132
+ * @private
133
+ */
134
+ export declare function formatRow(fields: google.spanner.v1.StructType.Field[], decoders: Function[], values: Value[], options?: RowOptions): Row;
135
+ /**
136
+ * Directly decodes rows from a PartialResultSet without going through the stream
137
+ * pipeline. Used by the fast-path for queries returning small results in a single chunk.
138
+ *
139
+ * @private
140
+ */
141
+ export declare function decodeRowsDirect(chunk: google.spanner.v1.PartialResultSet, options?: RowOptions, existingFields?: google.spanner.v1.StructType.Field[], existingDecoders?: Function[]): Row[];
109
142
  /**
110
143
  * @callback PartialResultStream~rowCallback
111
144
  * @param {Row|object} row The row data.
@@ -165,6 +198,7 @@ export declare class PartialResultStream extends Transform implements ResultEven
165
198
  private _pendingValueForResume?;
166
199
  private _values;
167
200
  private _numPushFailed;
201
+ private _isFirstChunk;
168
202
  constructor(options?: {});
169
203
  /**
170
204
  * Destroys the stream.
@@ -192,6 +226,15 @@ export declare class PartialResultStream extends Transform implements ResultEven
192
226
  * @param {object} chunk The partial result set.
193
227
  */
194
228
  private _addChunk;
229
+ /**
230
+ * Fast-path handler for single-chunk stream responses. Decodes rows directly
231
+ * and pushes them into the stream without incremental chunk buffering.
232
+ *
233
+ * @private
234
+ * @param {google.spanner.v1.PartialResultSet} chunk The partial result set.
235
+ * @returns {boolean} Whether the stream can accept more data.
236
+ */
237
+ private _addSingleChunk;
195
238
  /**
196
239
  * Manages complete values, pushing a completed row into the stream once all
197
240
  * values have been received.
@@ -16,6 +16,11 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.PartialResultStream = void 0;
19
+ exports.createFieldDecoders = createFieldDecoders;
20
+ exports.createJsonRow = createJsonRow;
21
+ exports.createRow = createRow;
22
+ exports.formatRow = formatRow;
23
+ exports.decodeRowsDirect = decodeRowsDirect;
19
24
  exports.partialResultStream = partialResultStream;
20
25
  const service_1 = require("./common-grpc/service");
21
26
  const stream_1 = require("stream");
@@ -43,6 +48,117 @@ Object.defineProperty(RowImpl.prototype, 'constructor', {
43
48
  configurable: true,
44
49
  enumerable: false,
45
50
  });
51
+ /**
52
+ * Creates an array of decoder functions for the specified struct fields.
53
+ *
54
+ * @private
55
+ */
56
+ function createFieldDecoders(fields, options) {
57
+ const jsonMode = Boolean(options?.json);
58
+ const jsonOptions = options?.jsonOptions;
59
+ const columnsMetadata = options?.columnsMetadata;
60
+ return fields.map(({ name, type }) => {
61
+ const columnMetadata = columnsMetadata &&
62
+ name !== null &&
63
+ name !== undefined &&
64
+ Object.prototype.hasOwnProperty.call(columnsMetadata, name)
65
+ ? columnsMetadata[name]
66
+ : undefined;
67
+ if (codec_1.codec.decode !== originalDecode) {
68
+ return (val) => codec_1.codec.decode(val, type, columnMetadata);
69
+ }
70
+ return codec_1.codec.getDecoder(type, columnMetadata, jsonMode ? jsonOptions || {} : undefined);
71
+ });
72
+ }
73
+ /**
74
+ * Directly creates a plain JSON object from row cell values, bypassing
75
+ * Struct, Row, and WrappedNumber class wrappers when possible.
76
+ *
77
+ * @private
78
+ */
79
+ function createJsonRow(fields, decoders, values, includeNameless) {
80
+ const json = {};
81
+ const len = fields.length;
82
+ for (let i = 0; i < len; i++) {
83
+ const { name } = fields[i];
84
+ if (!name && !includeNameless) {
85
+ continue;
86
+ }
87
+ const fieldName = name || `_${i}`;
88
+ try {
89
+ json[fieldName] = decoders[i](values[i]);
90
+ }
91
+ catch (e) {
92
+ e.message = [
93
+ `Serializing column "${fieldName}" encountered an error: ${e.message}`,
94
+ 'Call row.toJSON({ wrapNumbers: true }) to receive a custom type.',
95
+ ].join(' ');
96
+ throw e;
97
+ }
98
+ }
99
+ return json;
100
+ }
101
+ /**
102
+ * Converts an array of decoded cell values into a Row.
103
+ *
104
+ * @private
105
+ */
106
+ function createRow(fields, decoders, values) {
107
+ const len = fields.length;
108
+ const row = new RowImpl(len);
109
+ for (let i = 0; i < len; i++) {
110
+ row[i] = {
111
+ name: fields[i].name,
112
+ value: decoders[i](values[i]),
113
+ };
114
+ }
115
+ return row;
116
+ }
117
+ /**
118
+ * Formats raw row values into either a plain JSON object or a Row instance
119
+ * according to the provided RowOptions.
120
+ *
121
+ * @private
122
+ */
123
+ function formatRow(fields, decoders, values, options) {
124
+ const jsonMode = Boolean(options?.json);
125
+ const jsonOptions = options?.jsonOptions;
126
+ const isJsonStubbed = codec_1.codec.convertFieldsToJson !== originalConvertFieldsToJson;
127
+ if (jsonMode && !isJsonStubbed) {
128
+ return createJsonRow(fields, decoders, values, Boolean(jsonOptions?.includeNameless));
129
+ }
130
+ const row = createRow(fields, decoders, values);
131
+ return jsonMode ? row.toJSON(jsonOptions) : row;
132
+ }
133
+ /**
134
+ * Directly decodes rows from a PartialResultSet without going through the stream
135
+ * pipeline. Used by the fast-path for queries returning small results in a single chunk.
136
+ *
137
+ * @private
138
+ */
139
+ function decodeRowsDirect(chunk, options, existingFields, existingDecoders) {
140
+ const fields = existingFields ||
141
+ (chunk.metadata?.rowType?.fields ||
142
+ []);
143
+ const numFields = fields.length;
144
+ const chunkValues = chunk.values || [];
145
+ const numValues = chunkValues.length;
146
+ if (numFields === 0 || numValues === 0) {
147
+ return [];
148
+ }
149
+ const rowCount = Math.floor(numValues / numFields);
150
+ const rows = new Array(rowCount);
151
+ const decoders = existingDecoders || createFieldDecoders(fields, options);
152
+ const rowValues = new Array(numFields);
153
+ for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
154
+ const offset = rowIndex * numFields;
155
+ for (let columnIndex = 0; columnIndex < numFields; columnIndex++) {
156
+ rowValues[columnIndex] = service_1.GrpcService.decodeValue_(chunkValues[offset + columnIndex]);
157
+ }
158
+ rows[rowIndex] = formatRow(fields, decoders, rowValues, options);
159
+ }
160
+ return rows;
161
+ }
46
162
  /**
47
163
  * The PartialResultStream transforms partial result set objects into Row
48
164
  * objects.
@@ -61,11 +177,13 @@ class PartialResultStream extends stream_1.Transform {
61
177
  _pendingValueForResume;
62
178
  _values;
63
179
  _numPushFailed = 0;
180
+ _isFirstChunk = true;
64
181
  constructor(options = {}) {
65
182
  super({ objectMode: true });
66
183
  this._destroyed = false;
67
184
  this._options = Object.assign({ maxResumeRetries: 20 }, options);
68
185
  this._values = [];
186
+ this._isFirstChunk = true;
69
187
  }
70
188
  /**
71
189
  * Destroys the stream.
@@ -102,18 +220,7 @@ class PartialResultStream extends stream_1.Transform {
102
220
  if (!this._fields && chunk.metadata) {
103
221
  this._fields = chunk.metadata.rowType
104
222
  .fields;
105
- this._decoders = this._fields.map(({ name, type }) => {
106
- const columnMetadata = this._options.columnsMetadata &&
107
- name !== null &&
108
- name !== undefined &&
109
- Object.prototype.hasOwnProperty.call(this._options.columnsMetadata, name)
110
- ? this._options.columnsMetadata[name]
111
- : undefined;
112
- if (codec_1.codec.decode !== originalDecode) {
113
- return val => codec_1.codec.decode(val, type, columnMetadata);
114
- }
115
- return codec_1.codec.getDecoder(type, columnMetadata, this._options.json ? this._options.jsonOptions || {} : undefined);
116
- });
223
+ this._decoders = createFieldDecoders(this._fields, this._options);
117
224
  }
118
225
  let res = true;
119
226
  if (!(0, helper_1.isEmpty)(chunk.values)) {
@@ -187,6 +294,12 @@ class PartialResultStream extends stream_1.Transform {
187
294
  * @param {object} chunk The partial result set.
188
295
  */
189
296
  _addChunk(chunk) {
297
+ const isFirstChunk = this._isFirstChunk;
298
+ this._isFirstChunk = false;
299
+ // Fast path for single-chunk stream responses:
300
+ if (isFirstChunk && chunk.last && !chunk.chunkedValue) {
301
+ return this._addSingleChunk(chunk);
302
+ }
190
303
  const chunkValues = chunk.values;
191
304
  const numValues = chunkValues.length;
192
305
  const values = new Array(numValues);
@@ -222,6 +335,26 @@ class PartialResultStream extends stream_1.Transform {
222
335
  }
223
336
  return res;
224
337
  }
338
+ /**
339
+ * Fast-path handler for single-chunk stream responses. Decodes rows directly
340
+ * and pushes them into the stream without incremental chunk buffering.
341
+ *
342
+ * @private
343
+ * @param {google.spanner.v1.PartialResultSet} chunk The partial result set.
344
+ * @returns {boolean} Whether the stream can accept more data.
345
+ */
346
+ _addSingleChunk(chunk) {
347
+ const rows = decodeRowsDirect(chunk, this._options, this._fields, this._decoders);
348
+ let canAcceptMore = true;
349
+ for (let i = 0; i < rows.length; i++) {
350
+ const accepted = this.push(rows[i]);
351
+ if (!accepted && canAcceptMore) {
352
+ canAcceptMore = false;
353
+ this.emit('paused');
354
+ }
355
+ }
356
+ return canAcceptMore;
357
+ }
225
358
  /**
226
359
  * Manages complete values, pushing a completed row into the stream once all
227
360
  * values have been received.
@@ -237,15 +370,7 @@ class PartialResultStream extends stream_1.Transform {
237
370
  return true;
238
371
  }
239
372
  this._values = [];
240
- const isJsonStubbed = codec_1.codec.convertFieldsToJson !== originalConvertFieldsToJson;
241
- if (this._options.json && !isJsonStubbed) {
242
- return this.push(this._createJsonRow(values));
243
- }
244
- const row = this._createRow(values);
245
- if (this._options.json) {
246
- return this.push(row.toJSON(this._options.jsonOptions));
247
- }
248
- return this.push(row);
373
+ return this.push(formatRow(this._fields, this._decoders, values, this._options));
249
374
  }
250
375
  /**
251
376
  * Directly creates a plain JSON object from row cell values, bypassing
@@ -257,29 +382,7 @@ class PartialResultStream extends stream_1.Transform {
257
382
  * @returns {Json} The plain JavaScript object representing the row.
258
383
  */
259
384
  _createJsonRow(values) {
260
- const json = {};
261
- const fields = this._fields;
262
- const decoders = this._decoders;
263
- const len = fields.length;
264
- const includeNameless = !!this._options.jsonOptions?.includeNameless;
265
- for (let i = 0; i < len; i++) {
266
- const { name } = fields[i];
267
- if (!name && !includeNameless) {
268
- continue;
269
- }
270
- const fieldName = name ? name : `_${i}`;
271
- try {
272
- json[fieldName] = decoders[i](values[i]);
273
- }
274
- catch (e) {
275
- e.message = [
276
- `Serializing column "${fieldName}" encountered an error: ${e.message}`,
277
- 'Call row.toJSON({ wrapNumbers: true }) to receive a custom type.',
278
- ].join(' ');
279
- throw e;
280
- }
281
- }
282
- return json;
385
+ return createJsonRow(this._fields, this._decoders, values, Boolean(this._options.jsonOptions?.includeNameless));
283
386
  }
284
387
  /**
285
388
  * Converts an array of values into a row.
@@ -290,17 +393,7 @@ class PartialResultStream extends stream_1.Transform {
290
393
  * @returns {Row}
291
394
  */
292
395
  _createRow(values) {
293
- const len = values.length;
294
- const fields = new RowImpl(len);
295
- const decoders = this._decoders;
296
- const classFields = this._fields;
297
- for (let i = 0; i < len; i++) {
298
- fields[i] = {
299
- name: classFields[i].name,
300
- value: decoders[i](values[i]),
301
- };
302
- }
303
- return fields;
396
+ return createRow(this._fields, this._decoders, values);
304
397
  }
305
398
  /**
306
399
  * Attempts to merge chunked values together.
@@ -42,6 +42,12 @@ export interface SessionFactoryInterface {
42
42
  * @param {GetSessionCallback} callback The callback function.
43
43
  */
44
44
  getSession(callback: GetSessionCallback): void;
45
+ /**
46
+ * When called returns a cached multiplexed session synchronously if available.
47
+ *
48
+ * @name SessionFactoryInterface#getSessionSync
49
+ */
50
+ getSessionSync(): Session | null;
45
51
  /**
46
52
  * When called returns a session for paritioned dml.
47
53
  *
@@ -100,6 +106,13 @@ export declare class SessionFactory extends common.GrpcServiceObject implements
100
106
  isMultiplexedPartitionOps: boolean;
101
107
  isMultiplexedRW: boolean;
102
108
  constructor(database: Database, name: String, poolOptions?: SessionPoolConstructor | SessionPoolOptions);
109
+ /**
110
+ * Synchronously returns a cached multiplexed session if multiplexed sessions
111
+ * are enabled and one is available, otherwise null.
112
+ *
113
+ * @returns {Session|null} The cached multiplexed session or null.
114
+ */
115
+ getSessionSync(): Session | null;
103
116
  /**
104
117
  * Retrieves a session, either a regular session or a multiplexed session, based on the environment variable configuration.
105
118
  *
@@ -64,6 +64,17 @@ class SessionFactory extends common.GrpcServiceObject {
64
64
  this.pool_.open();
65
65
  }
66
66
  }
67
+ /**
68
+ * Synchronously returns a cached multiplexed session if multiplexed sessions
69
+ * are enabled and one is available, otherwise null.
70
+ *
71
+ * @returns {Session|null} The cached multiplexed session or null.
72
+ */
73
+ getSessionSync() {
74
+ return this.isMultiplexed
75
+ ? (this.multiplexedSession_?.getSessionSync?.() ?? null)
76
+ : null;
77
+ }
67
78
  /**
68
79
  * Retrieves a session, either a regular session or a multiplexed session, based on the environment variable configuration.
69
80
  *
@@ -76,7 +87,7 @@ class SessionFactory extends common.GrpcServiceObject {
76
87
  const sessionHandler = this.isMultiplexed
77
88
  ? this.multiplexedSession_
78
89
  : this.pool_;
79
- sessionHandler.getSession((err, session, transaction) => callback(err, session, transaction));
90
+ sessionHandler.getSession(callback);
80
91
  }
81
92
  /**
82
93
  * Retrieves a session for partitioned operations, selecting the appropriate session type
@@ -169,10 +169,6 @@ export interface BatchUpdateOptions {
169
169
  export interface BatchUpdateCallback {
170
170
  (err: null | BatchUpdateError, rowCounts: number[], response?: spannerClient.spanner.v1.ExecuteBatchDmlResponse): void;
171
171
  }
172
- export interface BatchUpdateOptions {
173
- requestOptions?: Omit<IRequestOptions, 'transactionTag'>;
174
- gaxOptions?: CallOptions;
175
- }
176
172
  export type ReadCallback = NormalCallback<Rows>;
177
173
  export interface RunCallback {
178
174
  (err: null | grpc.ServiceError, rows: Rows, stats: spannerClient.spanner.v1.ResultSetStats, metadata?: spannerClient.spanner.v1.ResultSetMetadata): void;
@@ -239,7 +235,7 @@ type PrecommitTokenProvider = spannerClient.spanner.v1.ITransaction | spannerCli
239
235
  export declare class Snapshot extends EventEmitter {
240
236
  protected _options: spannerClient.spanner.v1.ITransactionOptions;
241
237
  protected _seqno: number;
242
- protected _waitingRequests: Array<() => void>;
238
+ protected _waitingRequests: Array<(err?: Error) => void>;
243
239
  protected _inlineBeginStarted: any;
244
240
  protected _useInRunner: boolean;
245
241
  protected _latestPreCommitToken: spannerClient.spanner.v1.IMultiplexedSessionPrecommitToken | undefined | null;
@@ -308,6 +304,22 @@ export declare class Snapshot extends EventEmitter {
308
304
  * are specified for a query.
309
305
  */
310
306
  constructor(session: Session, options?: TimestampBounds, queryOptions?: IQueryOptions);
307
+ /**
308
+ * Binds the multiplexed session affinity key to the gax options of an
309
+ * outgoing request, so that all requests of this transaction are routed to
310
+ * the same gRPC channel.
311
+ *
312
+ * `config` is always a request descriptor that was freshly constructed by the
313
+ * caller for this one RPC (and {@link Spanner#prepareGapicRequest_} already
314
+ * modifies `config.headers` in place), so the affinity key is assigned
315
+ * directly instead of allocating a copy of the descriptor per request.
316
+ *
317
+ * @private
318
+ *
319
+ * @param {object} config The request configuration.
320
+ * @returns {object} The same request configuration.
321
+ */
322
+ private _applyAffinityGaxOpts;
311
323
  protected _updatePrecommitToken(resp: PrecommitTokenProvider): void;
312
324
  /**
313
325
  * Selects a single representative mutation from a list to be used as the
@@ -805,6 +817,26 @@ export declare class Snapshot extends EventEmitter {
805
817
  */
806
818
  run(query: string | ExecuteSqlRequest): Promise<RunResponse>;
807
819
  run(query: string | ExecuteSqlRequest, callback: RunCallback): void;
820
+ /**
821
+ * Always runs the query through the full streaming pipeline (Snapshot.prototype.runStream).
822
+ * Used when runStream has been overridden on Snapshot to preserve backward compatibility
823
+ * with custom stream implementations.
824
+ *
825
+ * @private
826
+ */
827
+ private _runLegacy;
828
+ /**
829
+ * Executes a query using an optimized streaming model:
830
+ * 1. If all results are returned in a single PartialResultSet, the internal streaming
831
+ * pipeline is simplified and rows are decoded directly, bypassing Stream overhead.
832
+ * 2. If there are more than one PartialResultSets, it seamlessly falls back to
833
+ * the standard streaming model.
834
+ *
835
+ * @private
836
+ */
837
+ _run(queryInput: string | ExecuteSqlRequest, callback: RunCallback, options?: {
838
+ startRunSpan?: boolean;
839
+ }): void;
808
840
  /**
809
841
  * ExecuteSql request options. This includes all standard ExecuteSqlRequest
810
842
  * options as well as several convenience properties.
@@ -967,7 +999,7 @@ export declare class Snapshot extends EventEmitter {
967
999
  * @private
968
1000
  */
969
1001
  private _wrapWithIdWaiter;
970
- _releaseWaitingRequests(): void;
1002
+ _releaseWaitingRequests(err?: Error): void;
971
1003
  /**
972
1004
  * Gets the Spanner object
973
1005
  *