@google-cloud/spanner 9.0.0 → 9.1.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 (40) hide show
  1. package/README.md +1 -16
  2. package/build/src/batch-transaction.js +15 -12
  3. package/build/src/codec.d.ts +6 -0
  4. package/build/src/codec.js +99 -34
  5. package/build/src/common.d.ts +14 -0
  6. package/build/src/common.js +27 -1
  7. package/build/src/database.d.ts +31 -41
  8. package/build/src/database.js +122 -313
  9. package/build/src/helper.d.ts +12 -0
  10. package/build/src/helper.js +44 -0
  11. package/build/src/index.d.ts +16 -8
  12. package/build/src/index.js +210 -90
  13. package/build/src/instance.d.ts +15 -2
  14. package/build/src/instance.js +11 -2
  15. package/build/src/instrument.d.ts +12 -1
  16. package/build/src/instrument.js +13 -0
  17. package/build/src/metrics/constants.d.ts +6 -0
  18. package/build/src/metrics/constants.js +6 -1
  19. package/build/src/metrics/interceptor.js +32 -28
  20. package/build/src/metrics/metrics-tracer-factory.d.ts +6 -11
  21. package/build/src/metrics/metrics-tracer-factory.js +62 -64
  22. package/build/src/metrics/metrics-tracer.d.ts +19 -6
  23. package/build/src/metrics/metrics-tracer.js +147 -55
  24. package/build/src/multiplexed-session.d.ts +13 -2
  25. package/build/src/multiplexed-session.js +20 -4
  26. package/build/src/partial-result-stream.d.ts +26 -33
  27. package/build/src/partial-result-stream.js +263 -283
  28. package/build/src/request-stream-coordinator.d.ts +88 -0
  29. package/build/src/request-stream-coordinator.js +229 -0
  30. package/build/src/request_id_header.d.ts +6 -4
  31. package/build/src/request_id_header.js +24 -24
  32. package/build/src/session-factory.d.ts +52 -63
  33. package/build/src/session-factory.js +41 -92
  34. package/build/src/session-pool.d.ts +97 -227
  35. package/build/src/session-pool.js +74 -547
  36. package/build/src/session.js +1 -1
  37. package/build/src/transaction-runner.js +1 -12
  38. package/build/src/transaction.d.ts +5 -5
  39. package/build/src/transaction.js +72 -112
  40. package/package.json +9 -10
@@ -15,9 +15,8 @@
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.MetricsTracer = void 0;
17
17
  const grpc_js_1 = require("@grpc/grpc-js");
18
- const metrics_tracer_factory_1 = require("./metrics-tracer-factory");
19
18
  const constants_1 = require("./constants");
20
- const __1 = require("..");
19
+ const common_1 = require("../common");
21
20
  /**
22
21
  * MetricAttemptTracer tracks the start time and status of a single gRPC attempt.
23
22
  *
@@ -93,6 +92,76 @@ class MetricOperationTracer {
93
92
  this._currentAttempt = new MetricAttemptTracer();
94
93
  }
95
94
  }
95
+ const GFE_METRIC_PREFIX = 'gfet4t7; dur=';
96
+ const AFE_METRIC_PREFIX = 'afe; dur=';
97
+ /**
98
+ * Checks whether a character code represents an entry delimiter or whitespace in a
99
+ * 'server-timing' header (start of string, space, comma, or tab).
100
+ *
101
+ * @param charCode The character code to check.
102
+ * @returns True if the character code is a valid entry separator or whitespace.
103
+ */
104
+ function isEntryDelimiter(charCode) {
105
+ return (charCode === 32 /* ' ' */ ||
106
+ charCode === 44 /* ',' */ ||
107
+ charCode === 9 /* '\t' */);
108
+ }
109
+ /**
110
+ * Parses consecutive ASCII digit characters into an integer starting from the given index.
111
+ * Returns null if the character at startIndex is not a digit (e.g. non-numeric, negative, or empty).
112
+ * Parsing stops at the first non-digit (e.g. ',', ';', or decimal point), matching the legacy
113
+ * regex `([0-9]+)` behavior without intermediate string slice allocations.
114
+ *
115
+ * @param header The 'server-timing' header string.
116
+ * @param startIndex The index where numeric digits are expected to begin.
117
+ * @returns The parsed non-negative integer, or null if no valid digits were found.
118
+ */
119
+ function parseConsecutiveDigits(header, startIndex) {
120
+ if (startIndex >= header.length) {
121
+ return null;
122
+ }
123
+ const firstCharCode = header.charCodeAt(startIndex);
124
+ if (firstCharCode < 48 || firstCharCode > 57) {
125
+ return null;
126
+ }
127
+ let value = firstCharCode - 48;
128
+ for (let index = startIndex + 1; index < header.length; index++) {
129
+ const code = header.charCodeAt(index);
130
+ if (code >= 48 && code <= 57) {
131
+ value = value * 10 + (code - 48);
132
+ }
133
+ else {
134
+ break;
135
+ }
136
+ }
137
+ return value;
138
+ }
139
+ /**
140
+ * Extracts a numeric latency value in milliseconds for a given metric prefix from a
141
+ * 'server-timing' header string without regex allocations or intermediate substring slices.
142
+ *
143
+ * @param header The 'server-timing' header string.
144
+ * @param prefix The metric prefix (e.g. 'gfet4t7; dur=').
145
+ * @returns The extracted latency in milliseconds, or null if not found.
146
+ */
147
+ function extractServerTimingLatency(header, prefix) {
148
+ if (!header || typeof header !== 'string') {
149
+ return null;
150
+ }
151
+ let prefixIndex = header.indexOf(prefix);
152
+ while (prefixIndex !== -1) {
153
+ // Ensure prefix is not part of a longer metric name (e.g., 'safe; dur=' matching 'afe; dur=')
154
+ if (prefixIndex === 0 ||
155
+ isEntryDelimiter(header.charCodeAt(prefixIndex - 1))) {
156
+ const latency = parseConsecutiveDigits(header, prefixIndex + prefix.length);
157
+ if (latency !== null) {
158
+ return latency;
159
+ }
160
+ }
161
+ prefixIndex = header.indexOf(prefix, prefixIndex + 1);
162
+ }
163
+ return null;
164
+ }
96
165
  /**
97
166
  * MetricsTracer is responsible for recording and managing metrics related to
98
167
  * gRPC Spanner operations and attempts counters, and latencies,
@@ -126,6 +195,11 @@ class MetricsTracer {
126
195
  * Stores client and resource attributes for labeling metrics.
127
196
  */
128
197
  _clientAttributes = {};
198
+ /**
199
+ * Cached OTel attribute objects keyed by status name, avoiding repeated
200
+ * object allocations on every metric recording call.
201
+ */
202
+ _attributesByStatus;
129
203
  /*
130
204
  * The current GFE latency associated with this tracer.
131
205
  */
@@ -147,7 +221,7 @@ class MetricsTracer {
147
221
  * @param _instrumentAfeLatency Histogram for AFE latency metrics.
148
222
  * @param enabled Whether metrics recording is enabled.
149
223
  */
150
- constructor(_instrumentAttemptCounter, _instrumentAttemptLatency, _instrumentOperationCounter, _instrumentOperationLatency, _instrumentGfeConnectivityErrorCount, _instrumentGfeLatency, _instrumentAfeConnectivityErrorCount, _instrumentAfeLatency, enabled, _database, _instance, _projectId, _methodName, _request) {
224
+ constructor(_instrumentAttemptCounter, _instrumentAttemptLatency, _instrumentOperationCounter, _instrumentOperationLatency, _instrumentGfeConnectivityErrorCount, _instrumentGfeLatency, _instrumentAfeConnectivityErrorCount, _instrumentAfeLatency, enabled, _database, _instance, _projectId, _methodName, _request, attributesCache) {
151
225
  this._instrumentAttemptCounter = _instrumentAttemptCounter;
152
226
  this._instrumentAttemptLatency = _instrumentAttemptLatency;
153
227
  this._instrumentOperationCounter = _instrumentOperationCounter;
@@ -165,6 +239,8 @@ class MetricsTracer {
165
239
  this._clientAttributes[constants_1.METRIC_LABEL_KEY_DATABASE] = _database;
166
240
  this._clientAttributes[constants_1.METRIC_LABEL_KEY_METHOD] = _methodName;
167
241
  this._clientAttributes[constants_1.MONITORED_RES_LABEL_KEY_INSTANCE] = _instance;
242
+ this._attributesByStatus =
243
+ attributesCache ?? new Map();
168
244
  }
169
245
  /**
170
246
  * Returns the difference in milliseconds between two times.
@@ -210,7 +286,7 @@ class MetricsTracer {
210
286
  * Increments the attempt count and creates a new MetricAttemptTracer.
211
287
  */
212
288
  recordAttemptStart() {
213
- if (!this.enabled)
289
+ if (!this.enabled || !this.currentOperation)
214
290
  return;
215
291
  this.currentOperation.createNewAttempt();
216
292
  }
@@ -220,12 +296,13 @@ class MetricsTracer {
220
296
  * @param status The status code of the attempt (default: Status.OK).
221
297
  */
222
298
  recordAttemptCompletion(statusCode = grpc_js_1.status.OK) {
223
- if (!this.enabled)
299
+ if (!this.enabled || !this.currentOperation?.currentAttempt)
224
300
  return;
225
- this.currentOperation.currentAttempt.status = grpc_js_1.status[statusCode];
301
+ const currentAttempt = this.currentOperation.currentAttempt;
302
+ currentAttempt.status = grpc_js_1.status[statusCode] ?? grpc_js_1.status[grpc_js_1.status.UNKNOWN];
226
303
  const attemptAttributes = this._createAttemptOtelAttributes();
227
304
  const endTime = performance.now();
228
- const attemptLatencyMilliseconds = this._getMillisecondTimeDifference(this.currentOperation.currentAttempt.startTime, endTime);
305
+ const attemptLatencyMilliseconds = this._getMillisecondTimeDifference(currentAttempt.startTime, endTime);
229
306
  this.instrumentAttemptLatency?.record(attemptLatencyMilliseconds, attemptAttributes);
230
307
  this.instrumentAttemptCounter?.add(1, attemptAttributes);
231
308
  }
@@ -252,7 +329,7 @@ class MetricsTracer {
252
329
  const operationLatencyMilliseconds = this._getMillisecondTimeDifference(this.currentOperation.startTime, endTime);
253
330
  this.instrumentOperationCounter?.add(1, operationAttributes);
254
331
  this.instrumentOperationLatency?.record(operationLatencyMilliseconds, operationAttributes);
255
- metrics_tracer_factory_1.MetricsTracerFactory.getInstance(this._projectId).clearCurrentTracer(this._request);
332
+ this.currentOperation = null;
256
333
  }
257
334
  /**
258
335
  * Extracts the GFE latency value (in milliseconds) from a 'server-timing' header string.
@@ -262,13 +339,7 @@ class MetricsTracer {
262
339
  * @returns The extracted GFE latency in milliseconds, or null if not found.
263
340
  */
264
341
  extractGfeLatency(header) {
265
- const regex = /gfet4t7; dur=([0-9]+).*/;
266
- if (header === undefined)
267
- return null;
268
- const match = header.match(regex);
269
- if (!match)
270
- return null;
271
- return Number(match[1]);
342
+ return extractServerTimingLatency(header, GFE_METRIC_PREFIX);
272
343
  }
273
344
  /**
274
345
  * Extracts the AFE latency value (in milliseconds) from a 'server-timing' header string.
@@ -278,66 +349,91 @@ class MetricsTracer {
278
349
  * @returns The extracted AFE latency in milliseconds, or null if not found.
279
350
  */
280
351
  extractAfeLatency(header) {
281
- if (!__1.Spanner.isAFEServerTimingEnabled())
352
+ if (!(0, common_1.isAFEServerTimingEnabled)())
282
353
  return null;
283
- const regex = /afe; dur=([0-9]+).*/;
284
- if (header === undefined)
285
- return null;
286
- const match = header.match(regex);
287
- if (!match)
288
- return null;
289
- return Number(match[1]);
354
+ return extractServerTimingLatency(header, AFE_METRIC_PREFIX);
290
355
  }
291
356
  /**
292
- * Records the provided GFE latency.
293
- * @param latency The GFE latency in milliseconds.
357
+ * Returns a cached set of OTEL attributes for the given status, avoiding
358
+ * repeated object cloning on every metric record/add call.
359
+ *
360
+ * @param status Optional status code (as numeric Status enum or status name string).
361
+ * @returns The cached attributes object.
362
+ */
363
+ _getAttributesForStatus(status) {
364
+ const statusString = typeof status === 'number'
365
+ ? (grpc_js_1.status[status] ?? grpc_js_1.status[grpc_js_1.status.UNKNOWN])
366
+ : typeof status === 'string'
367
+ ? status
368
+ : undefined;
369
+ const cacheKey = statusString ?? '';
370
+ let attributes = this._attributesByStatus.get(cacheKey);
371
+ if (!attributes) {
372
+ const newAttributes = { ...this._clientAttributes };
373
+ if (statusString !== undefined) {
374
+ newAttributes[constants_1.METRIC_LABEL_KEY_STATUS] = statusString;
375
+ }
376
+ attributes = Object.freeze(newAttributes);
377
+ this._attributesByStatus.set(cacheKey, attributes);
378
+ }
379
+ return attributes;
380
+ }
381
+ /**
382
+ * Records the GFE latency for this attempt.
383
+ * @param statusCode The gRPC status code of the attempt.
294
384
  */
295
385
  recordGfeLatency(statusCode) {
296
- if (!this.enabled)
386
+ if (!this.enabled || !this._instrumentGfeLatency)
297
387
  return;
298
- if (!this.gfeLatency) {
388
+ if (typeof this.gfeLatency !== 'number' ||
389
+ !Number.isFinite(this.gfeLatency) ||
390
+ this.gfeLatency < 0) {
299
391
  console.error('ERROR: Attempted to record GFE metric with no latency value.');
300
392
  return;
301
393
  }
302
- const attributes = { ...this._clientAttributes };
303
- attributes[constants_1.METRIC_LABEL_KEY_STATUS] = grpc_js_1.status[statusCode];
304
- this._instrumentGfeLatency?.record(this.gfeLatency, attributes);
394
+ const attributes = this._getAttributesForStatus(statusCode);
395
+ this._instrumentGfeLatency.record(this.gfeLatency, attributes);
305
396
  this.gfeLatency = null; // Reset latency value
306
397
  }
307
398
  /**
308
399
  * Increments the GFE connectivity error count metric.
309
400
  */
310
401
  recordGfeConnectivityErrorCount(statusCode) {
311
- if (!this.enabled)
402
+ if (!this.enabled || !this._instrumentGfeConnectivityErrorCount)
312
403
  return;
313
- const attributes = { ...this._clientAttributes };
314
- attributes[constants_1.METRIC_LABEL_KEY_STATUS] = grpc_js_1.status[statusCode];
315
- this._instrumentGfeConnectivityErrorCount?.add(1, attributes);
404
+ const attributes = this._getAttributesForStatus(statusCode);
405
+ this._instrumentGfeConnectivityErrorCount.add(1, attributes);
316
406
  }
317
407
  /**
318
408
  * Increments the AFE connectivity error count metric.
319
409
  */
320
410
  recordAfeConnectivityErrorCount(statusCode) {
321
- if (!this.enabled || !__1.Spanner.isAFEServerTimingEnabled())
411
+ if (!this.enabled ||
412
+ !this._instrumentAfeConnectivityErrorCount ||
413
+ !(0, common_1.isAFEServerTimingEnabled)()) {
322
414
  return;
323
- const attributes = { ...this._clientAttributes };
324
- attributes[constants_1.METRIC_LABEL_KEY_STATUS] = grpc_js_1.status[statusCode];
325
- this._instrumentAfeConnectivityErrorCount?.add(1, attributes);
415
+ }
416
+ const attributes = this._getAttributesForStatus(statusCode);
417
+ this._instrumentAfeConnectivityErrorCount.add(1, attributes);
326
418
  }
327
419
  /**
328
- * Records the provided AFE latency.
329
- * @param latency The AFE latency in milliseconds.
420
+ * Records the AFE latency for this attempt.
421
+ * @param statusCode The gRPC status code of the attempt.
330
422
  */
331
423
  recordAfeLatency(statusCode) {
332
- if (!this.enabled || !__1.Spanner.isAFEServerTimingEnabled())
424
+ if (!this.enabled ||
425
+ !this._instrumentAfeLatency ||
426
+ !(0, common_1.isAFEServerTimingEnabled)()) {
333
427
  return;
334
- if (!this.afeLatency) {
428
+ }
429
+ if (typeof this.afeLatency !== 'number' ||
430
+ !Number.isFinite(this.afeLatency) ||
431
+ this.afeLatency < 0) {
335
432
  console.error('ERROR: Attempted to record AFE metric with no latency value.');
336
433
  return;
337
434
  }
338
- const attributes = { ...this._clientAttributes };
339
- attributes[constants_1.METRIC_LABEL_KEY_STATUS] = grpc_js_1.status[statusCode];
340
- this._instrumentAfeLatency?.record(this.afeLatency, attributes);
435
+ const attributes = this._getAttributesForStatus(statusCode);
436
+ this._instrumentAfeLatency.record(this.afeLatency, attributes);
341
437
  this.afeLatency = null; // Reset latency value
342
438
  }
343
439
  /**
@@ -347,10 +443,8 @@ class MetricsTracer {
347
443
  _createOperationOtelAttributes() {
348
444
  if (!this.enabled)
349
445
  return {};
350
- const attributes = { ...this._clientAttributes };
351
- attributes[constants_1.METRIC_LABEL_KEY_STATUS] =
352
- this.currentOperation.currentAttempt?.status ?? grpc_js_1.status[grpc_js_1.status.UNKNOWN];
353
- return attributes;
446
+ const status = this.currentOperation?.currentAttempt?.status ?? grpc_js_1.status[grpc_js_1.status.UNKNOWN];
447
+ return this._getAttributesForStatus(status);
354
448
  }
355
449
  /**
356
450
  * Creates and returns a set of OTEL attributes for attempt-level metrics.
@@ -361,12 +455,10 @@ class MetricsTracer {
361
455
  _createAttemptOtelAttributes() {
362
456
  if (!this.enabled)
363
457
  return {};
364
- const attributes = { ...this._clientAttributes };
365
- if (this.currentOperation?.currentAttempt === null)
366
- return attributes;
367
- attributes[constants_1.METRIC_LABEL_KEY_STATUS] =
368
- this.currentOperation.currentAttempt.status;
369
- return attributes;
458
+ if (!this.currentOperation?.currentAttempt) {
459
+ return this._getAttributesForStatus();
460
+ }
461
+ return this._getAttributesForStatus(this.currentOperation.currentAttempt.status);
370
462
  }
371
463
  }
372
464
  exports.MetricsTracer = MetricsTracer;
@@ -48,6 +48,12 @@ export interface MultiplexedSessionInterface extends EventEmitter {
48
48
  * @name MultiplexedSessionInterface#getSessionSync
49
49
  */
50
50
  getSessionSync(): Session | null;
51
+ /**
52
+ * When called closes the multiplexed session and stops background maintenance.
53
+ *
54
+ * @name MultiplexedSessionInterface#close
55
+ */
56
+ close?(): void;
51
57
  }
52
58
  /**
53
59
  * Class used to manage connections to Spanner using multiplexed session.
@@ -65,6 +71,7 @@ export declare class MultiplexedSession extends EventEmitter implements Multiple
65
71
  _refreshHandle: NodeJS.Timeout;
66
72
  _observabilityOptions?: ObservabilityOptions;
67
73
  _sharedMuxSessionWaitPromise: Promise<void> | null;
74
+ private _isClosed;
68
75
  constructor(database: Database);
69
76
  /**
70
77
  * Creates a new multiplexed session and manages its maintenance.
@@ -104,6 +111,10 @@ export declare class MultiplexedSession extends EventEmitter implements Multiple
104
111
  *
105
112
  */
106
113
  _maintain(): void;
114
+ /**
115
+ * Closes the multiplexed session by stopping the periodic refresh interval.
116
+ */
117
+ close(): void;
107
118
  /**
108
119
  * Synchronously returns the cached multiplexed session if available,
109
120
  * or null if no session is currently cached.
@@ -114,8 +125,8 @@ export declare class MultiplexedSession extends EventEmitter implements Multiple
114
125
  /**
115
126
  * Retrieves a session asynchronously and invokes a callback with the session details.
116
127
  * Note: The callback receives `(null, session)`. To prevent unnecessary allocations on
117
- * read query paths, a `Transaction` is not created here. Callers requiring a read-write
118
- * transaction should use `SessionFactory.prototype.getSessionForReadWrite`.
128
+ * read query paths, a `Transaction` is not created here; callers requiring a read-write
129
+ * transaction instantiate it via `session.transaction()`.
119
130
  *
120
131
  * @param {GetSessionCallback} callback - The callback to be invoked once the session is acquired or an error occurs.
121
132
  *
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.MultiplexedSession = void 0;
19
19
  const events_1 = require("events");
20
20
  const api_1 = require("@opentelemetry/api");
21
+ const google_gax_1 = require("google-gax");
21
22
  const instrument_1 = require("./instrument");
22
23
  /**
23
24
  * Class used to manage connections to Spanner using multiplexed session.
@@ -37,6 +38,7 @@ class MultiplexedSession extends events_1.EventEmitter {
37
38
  _observabilityOptions;
38
39
  // shared promise lock to handle concurrent session creation requests
39
40
  _sharedMuxSessionWaitPromise;
41
+ _isClosed = false;
40
42
  constructor(database) {
41
43
  super();
42
44
  this.database = database;
@@ -56,7 +58,9 @@ class MultiplexedSession extends events_1.EventEmitter {
56
58
  createSession() {
57
59
  this._createSession()
58
60
  .then(() => {
59
- this._maintain();
61
+ if (!this._isClosed) {
62
+ this._maintain();
63
+ }
60
64
  return null;
61
65
  })
62
66
  // Ignore errors here. If this fails, the next user request will
@@ -144,6 +148,15 @@ class MultiplexedSession extends events_1.EventEmitter {
144
148
  // force the process to stay open.
145
149
  this._refreshHandle.unref();
146
150
  }
151
+ /**
152
+ * Closes the multiplexed session by stopping the periodic refresh interval.
153
+ */
154
+ close() {
155
+ this._isClosed = true;
156
+ if (this._refreshHandle) {
157
+ clearInterval(this._refreshHandle);
158
+ }
159
+ }
147
160
  /**
148
161
  * Synchronously returns the cached multiplexed session if available,
149
162
  * or null if no session is currently cached.
@@ -151,7 +164,7 @@ class MultiplexedSession extends events_1.EventEmitter {
151
164
  * @returns {Session|null} The cached multiplexed session or null.
152
165
  */
153
166
  getSessionSync() {
154
- if (this._multiplexedSession !== null) {
167
+ if (!this._isClosed && this._multiplexedSession !== null) {
155
168
  const span = (0, instrument_1.getActiveOrNoopSpan)();
156
169
  span.addEvent('Cache hit: has usable multiplexed session');
157
170
  return this._multiplexedSession;
@@ -161,8 +174,8 @@ class MultiplexedSession extends events_1.EventEmitter {
161
174
  /**
162
175
  * Retrieves a session asynchronously and invokes a callback with the session details.
163
176
  * Note: The callback receives `(null, session)`. To prevent unnecessary allocations on
164
- * read query paths, a `Transaction` is not created here. Callers requiring a read-write
165
- * transaction should use `SessionFactory.prototype.getSessionForReadWrite`.
177
+ * read query paths, a `Transaction` is not created here; callers requiring a read-write
178
+ * transaction instantiate it via `session.transaction()`.
166
179
  *
167
180
  * @param {GetSessionCallback} callback - The callback to be invoked once the session is acquired or an error occurs.
168
181
  *
@@ -208,6 +221,9 @@ class MultiplexedSession extends events_1.EventEmitter {
208
221
  *
209
222
  */
210
223
  async _getSession() {
224
+ if (this._isClosed) {
225
+ throw new google_gax_1.GoogleError('Database is closed.');
226
+ }
211
227
  // Check if the multiplexed session is already available
212
228
  const cachedSession = this.getSessionSync();
213
229
  if (cachedSession !== null) {
@@ -32,11 +32,9 @@ interface RequestFunction {
32
32
  * @property {boolean} [json=false] Indicates if the Row objects should be
33
33
  * formatted into JSON.
34
34
  * @property {JSONOptions} [jsonOptions] JSON options.
35
- * @property {number} [maxResumeRetries=20] The maximum number of times that the
36
- * stream will retry to push data downstream, when the downstream indicates
37
- * that it is not ready for any more data. Increase this value if you
38
- * experience 'Stream is still not ready to receive data' errors as a
39
- * result of a slow writer in your receiving stream.
35
+ * @property {number} [maxResumeRetries=20] Deprecated. This option is no longer
36
+ * used. Backpressure is now handled natively via Node.js stream flow
37
+ * control without polling or retry limits.
40
38
  * @property {object} [columnsMetadata] An object map that can be used to pass
41
39
  * additional properties for each column type which can help in deserializing
42
40
  * the data coming from backend. (Eg: We need to pass Proto Function and Enum
@@ -45,6 +43,10 @@ interface RequestFunction {
45
43
  export interface RowOptions {
46
44
  json?: boolean;
47
45
  jsonOptions?: JSONOptions;
46
+ /**
47
+ * @deprecated Backpressure is now handled natively via Node.js stream flow
48
+ * control without polling or retry limits.
49
+ */
48
50
  maxResumeRetries?: number;
49
51
  /**
50
52
  * An object where column names as keys and custom objects as corresponding
@@ -190,14 +192,13 @@ interface ResultEvents {
190
192
  * @param {RowOptions} [options] The row options.
191
193
  */
192
194
  export declare class PartialResultStream extends Transform implements ResultEvents {
193
- private _destroyed;
194
195
  private _fields;
195
196
  private _decoders;
196
197
  private _options;
197
198
  private _pendingValue?;
198
- private _pendingValueForResume?;
199
- private _values;
200
- private _numPushFailed;
199
+ private _rowValues?;
200
+ private _valueIndex;
201
+ private _resumeCallback?;
201
202
  private _isFirstChunk;
202
203
  constructor(options?: {});
203
204
  /**
@@ -216,14 +217,25 @@ export declare class PartialResultStream extends Transform implements ResultEven
216
217
  * @param {function} next Function to be called upon completion.
217
218
  */
218
219
  _transform(chunk: google.spanner.v1.PartialResultSet, enc: string, next: Function): void;
219
- private _tryResume;
220
- _resetPendingValues(): void;
220
+ _flush(callback: Function): void;
221
+ _read(size: number): void;
221
222
  /**
222
- * Manages any chunked values.
223
+ * Manages stream chunks, chunked value merging across chunk boundaries,
224
+ * row assembly, and resume token checkpoints.
223
225
  *
224
- * @private
226
+ * Processing follows 4 distinct stages:
227
+ * 1. Single-chunk fast path: If the entire stream response is in this first chunk,
228
+ * decode rows directly and bypass incremental chunk buffering.
229
+ * 2. Pending value merge: If the previous chunk ended with an incomplete chunked
230
+ * value, merge it with the incoming continuation value at chunkValues[0].
231
+ * 3. Chunked value hold: If this chunk ends with a chunked value, hold the tail
232
+ * value (chunkValues[numValues - 1]) in `this._pendingValue` for the next chunk.
233
+ * 4. Complete value decoding: Iterate from `startIndex` to `endIndex`, decoding
234
+ * and adding values into row buffers via `_addValue`.
225
235
  *
226
- * @param {object} chunk The partial result set.
236
+ * @private
237
+ * @param {google.spanner.v1.PartialResultSet} chunk The partial result set.
238
+ * @returns {boolean} Whether downstream can accept more data.
227
239
  */
228
240
  private _addChunk;
229
241
  /**
@@ -244,25 +256,6 @@ export declare class PartialResultStream extends Transform implements ResultEven
244
256
  * @param {*} value The complete value.
245
257
  */
246
258
  private _addValue;
247
- /**
248
- * Directly creates a plain JSON object from row cell values, bypassing
249
- * Struct, Row, and WrappedNumber class wrappers when possible.
250
- *
251
- * @private
252
- *
253
- * @param {Value[]} values The raw cell values for the current row.
254
- * @returns {Json} The plain JavaScript object representing the row.
255
- */
256
- private _createJsonRow;
257
- /**
258
- * Converts an array of values into a row.
259
- *
260
- * @private
261
- *
262
- * @param {Array.<*>} values The row values.
263
- * @returns {Row}
264
- */
265
- private _createRow;
266
259
  /**
267
260
  * Attempts to merge chunked values together.
268
261
  *