@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
@@ -0,0 +1,88 @@
1
+ /*!
2
+ * Copyright 2026 Google LLC. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Transform } from 'stream';
17
+ import { CancellableStream } from 'google-gax';
18
+ import { MetricsTracer } from './metrics/metrics-tracer';
19
+ /**
20
+ * Coordinates lifecycle events, cancellation, and metric collection
21
+ * between the user-facing readable/transform stream and the underlying
22
+ * GAX/gRPC call stream.
23
+ */
24
+ export declare class RequestStreamCoordinator {
25
+ private readonly stream;
26
+ private readonly metricsTracer;
27
+ private callStream;
28
+ private statusReceived;
29
+ private streamFinished;
30
+ private operationCompleted;
31
+ private requestStarted;
32
+ private streamClosed;
33
+ constructor(stream: Transform, metricsTracer: MetricsTracer | null);
34
+ /**
35
+ * Sets up destruction hooks and lifecycle listeners on the user-facing stream.
36
+ */
37
+ setup(): void;
38
+ /**
39
+ * Cancels the active gRPC call stream if it has not already completed.
40
+ *
41
+ * Note: In `@grpc/grpc-js`, calling `.cancel()` after a stream has already
42
+ * finished or drained with `Status.OK` will overwrite the status to `CANCELLED`.
43
+ * We guard against this by checking `streamFinished` and `statusReceived`.
44
+ */
45
+ cancelCallStream(): void;
46
+ /**
47
+ * Invokes requestFn to initialize the callStream, or skips invocation
48
+ * if the user-facing stream was already destroyed before preparation finished.
49
+ *
50
+ * @param requestFn The function that instantiates the GAX call stream.
51
+ */
52
+ attachRequestFn(requestFn: () => CancellableStream): void;
53
+ /**
54
+ * Attaches the underlying gRPC call stream once it is prepared by GAPIC.
55
+ *
56
+ * @param callStream The cancellable stream returned by GAX.
57
+ */
58
+ attachCallStream(callStream: CancellableStream): void;
59
+ /**
60
+ * Handles errors encountered during GAPIC request preparation.
61
+ *
62
+ * @param error The error from prepareGapicRequest_.
63
+ */
64
+ handleRequestError(error: Error): void;
65
+ /**
66
+ * Handles stream finish when all data has been written to the transform stream.
67
+ */
68
+ handleStreamFinish(): void;
69
+ /**
70
+ * Marks that the GAPIC request preparation has been initiated (e.g. upon 'reading').
71
+ */
72
+ startRequest(): void;
73
+ /**
74
+ * Handles stream close on the user-facing stream. Defers metric completion
75
+ * if the gRPC call is still in flight, ensuring attempt status is recorded
76
+ * by the interceptor before operation completion is finalized.
77
+ */
78
+ handleStreamClose(): void;
79
+ /**
80
+ * Completes the OpenTelemetry operation metric. Idempotent.
81
+ */
82
+ completeOperation(): void;
83
+ /**
84
+ * Waits for the gRPC call to deliver its terminal status or close event before
85
+ * finalizing operation metrics.
86
+ */
87
+ private waitForStatusOrClose;
88
+ }
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright 2026 Google LLC. All Rights Reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.RequestStreamCoordinator = void 0;
19
+ /**
20
+ * Coordinates lifecycle events, cancellation, and metric collection
21
+ * between the user-facing readable/transform stream and the underlying
22
+ * GAX/gRPC call stream.
23
+ */
24
+ class RequestStreamCoordinator {
25
+ stream;
26
+ metricsTracer;
27
+ callStream = null;
28
+ statusReceived = false;
29
+ streamFinished = false;
30
+ operationCompleted = false;
31
+ requestStarted = false;
32
+ streamClosed = false;
33
+ constructor(stream, metricsTracer) {
34
+ this.stream = stream;
35
+ this.metricsTracer = metricsTracer;
36
+ }
37
+ /**
38
+ * Sets up destruction hooks and lifecycle listeners on the user-facing stream.
39
+ */
40
+ setup() {
41
+ // Intercept stream destruction to handle cancellation and metric completion.
42
+ // We override _destroy rather than solely relying on the 'close' event because
43
+ // internal callers (such as transaction retry logic in transaction.ts) or users
44
+ // may call stream.removeAllListeners() before calling stream.destroy().
45
+ const originalDestroy = this.stream._destroy;
46
+ this.stream._destroy = (error, callback) => {
47
+ // Immediately cancel the underlying gRPC call if still active.
48
+ this.cancelCallStream();
49
+ // Ensure stream closure and metric finalization are triggered upon destruction,
50
+ // even if removeAllListeners() previously removed the 'close' listener.
51
+ const handleClose = () => {
52
+ this.handleStreamClose();
53
+ };
54
+ if (typeof originalDestroy === 'function') {
55
+ originalDestroy.call(this.stream, error, (destroyError) => {
56
+ handleClose();
57
+ if (typeof callback === 'function') {
58
+ callback(destroyError);
59
+ }
60
+ });
61
+ }
62
+ else {
63
+ handleClose();
64
+ if (typeof callback === 'function') {
65
+ callback(error);
66
+ }
67
+ }
68
+ };
69
+ // When the stream finishes writing normally, mark it as finished so that subsequent
70
+ // teardown or destroy calls do not trigger cancelCallStream().
71
+ this.stream.on('finish', () => this.handleStreamFinish());
72
+ // Fallback for streams that close without an explicit destroy() invocation.
73
+ // handleStreamClose() is guarded by streamClosed to ensure idempotency.
74
+ this.stream.on('close', () => this.handleStreamClose());
75
+ }
76
+ /**
77
+ * Cancels the active gRPC call stream if it has not already completed.
78
+ *
79
+ * Note: In `@grpc/grpc-js`, calling `.cancel()` after a stream has already
80
+ * finished or drained with `Status.OK` will overwrite the status to `CANCELLED`.
81
+ * We guard against this by checking `streamFinished` and `statusReceived`.
82
+ */
83
+ cancelCallStream() {
84
+ // Guard against overwriting Status.OK:
85
+ // In @grpc/grpc-js, calling .cancel() on a stream that has already received
86
+ // its terminal status or completed normally will overwrite the status to CANCELLED.
87
+ // This guard preserves OK status for normally drained streams as well as queries
88
+ // using the PartialResultSet.last optimization (where the user stream completes early
89
+ // while remaining trailers drain in the background).
90
+ if (this.streamFinished || this.statusReceived) {
91
+ return;
92
+ }
93
+ if (this.callStream) {
94
+ // In google-gax, callStream is a StreamProxy wrapping the underlying gRPC call.
95
+ // Calling .destroy() on StreamProxy alone does not cancel the active gRPC call;
96
+ // .cancel() must be invoked explicitly to abort the RPC on the client.
97
+ if (typeof this.callStream.cancel === 'function') {
98
+ this.callStream.cancel();
99
+ }
100
+ // Clean up proxy and stream resources once cancellation has been requested.
101
+ const streamWithDestroy = this.callStream;
102
+ if (typeof streamWithDestroy.destroy === 'function' &&
103
+ !streamWithDestroy.destroyed) {
104
+ streamWithDestroy.destroy();
105
+ }
106
+ }
107
+ }
108
+ /**
109
+ * Invokes requestFn to initialize the callStream, or skips invocation
110
+ * if the user-facing stream was already destroyed before preparation finished.
111
+ *
112
+ * @param requestFn The function that instantiates the GAX call stream.
113
+ */
114
+ attachRequestFn(requestFn) {
115
+ if (this.stream.destroyed || this.streamClosed) {
116
+ this.completeOperation();
117
+ return;
118
+ }
119
+ try {
120
+ const callStream = requestFn();
121
+ if (callStream) {
122
+ this.attachCallStream(callStream);
123
+ }
124
+ else {
125
+ this.handleRequestError(new Error('Failed to initialize request stream.'));
126
+ }
127
+ }
128
+ catch (error) {
129
+ this.handleRequestError(error);
130
+ }
131
+ }
132
+ /**
133
+ * Attaches the underlying gRPC call stream once it is prepared by GAPIC.
134
+ *
135
+ * @param callStream The cancellable stream returned by GAX.
136
+ */
137
+ attachCallStream(callStream) {
138
+ this.callStream = callStream;
139
+ callStream.once('status', () => {
140
+ this.statusReceived = true;
141
+ });
142
+ callStream
143
+ .on('error', (error) => {
144
+ if (!this.stream.destroyed && !this.streamClosed) {
145
+ this.stream.destroy(error);
146
+ }
147
+ })
148
+ .pipe(this.stream);
149
+ }
150
+ /**
151
+ * Handles errors encountered during GAPIC request preparation.
152
+ *
153
+ * @param error The error from prepareGapicRequest_.
154
+ */
155
+ handleRequestError(error) {
156
+ this.stream.destroy(error);
157
+ this.completeOperation();
158
+ }
159
+ /**
160
+ * Handles stream finish when all data has been written to the transform stream.
161
+ */
162
+ handleStreamFinish() {
163
+ this.streamFinished = true;
164
+ this.stream.destroy();
165
+ }
166
+ /**
167
+ * Marks that the GAPIC request preparation has been initiated (e.g. upon 'reading').
168
+ */
169
+ startRequest() {
170
+ this.requestStarted = true;
171
+ }
172
+ /**
173
+ * Handles stream close on the user-facing stream. Defers metric completion
174
+ * if the gRPC call is still in flight, ensuring attempt status is recorded
175
+ * by the interceptor before operation completion is finalized.
176
+ */
177
+ handleStreamClose() {
178
+ if (this.streamClosed) {
179
+ return;
180
+ }
181
+ this.streamClosed = true;
182
+ if (this.callStream) {
183
+ if (!this.statusReceived) {
184
+ this.waitForStatusOrClose(this.callStream);
185
+ }
186
+ else {
187
+ this.completeOperation();
188
+ }
189
+ return;
190
+ }
191
+ if (!this.requestStarted) {
192
+ this.completeOperation();
193
+ }
194
+ }
195
+ /**
196
+ * Completes the OpenTelemetry operation metric. Idempotent.
197
+ */
198
+ completeOperation() {
199
+ if (this.operationCompleted) {
200
+ return;
201
+ }
202
+ this.operationCompleted = true;
203
+ this.metricsTracer?.recordOperationCompletion();
204
+ }
205
+ /**
206
+ * Waits for the gRPC call to deliver its terminal status or close event before
207
+ * finalizing operation metrics.
208
+ */
209
+ waitForStatusOrClose(callStream) {
210
+ callStream.once('status', () => {
211
+ this.statusReceived = true;
212
+ this.completeOperation();
213
+ });
214
+ callStream.once('close', () => {
215
+ // In @grpc/grpc-js, cancellation may emit 'close' before the status callback
216
+ // runs on next tick. Defer via setImmediate to allow onReceiveStatus to execute first.
217
+ setImmediate(() => {
218
+ this.completeOperation();
219
+ });
220
+ });
221
+ callStream.once('error', () => {
222
+ setImmediate(() => {
223
+ this.completeOperation();
224
+ });
225
+ });
226
+ }
227
+ }
228
+ exports.RequestStreamCoordinator = RequestStreamCoordinator;
229
+ //# sourceMappingURL=request-stream-coordinator.js.map
@@ -15,19 +15,21 @@
15
15
  */
16
16
  import * as grpc from '@grpc/grpc-js';
17
17
  declare const randIdForProcess: string;
18
+ declare const PROCESS_PREFIX: string;
18
19
  declare const X_GOOG_SPANNER_REQUEST_ID_HEADER = "x-goog-spanner-request-id";
19
20
  declare class AtomicCounter {
20
- private readonly backingBuffer;
21
+ private _value;
21
22
  constructor(initialValue?: number);
22
- increment(n?: number): number;
23
+ increment(amount?: number): number;
23
24
  value(): number;
24
25
  toString(): string;
25
26
  reset(): void;
26
27
  }
28
+ declare function getRequestIdPrefix(clientId?: number, channelId?: number): string;
27
29
  declare function craftRequestId(nthClientId: number, channelId: number, nthRequest: number, attempt: number): string;
28
30
  export declare function resetNthClientId(): void;
29
31
  declare function nextSpannerClientId(): number;
30
- declare function newAtomicCounter(n?: number): AtomicCounter;
32
+ declare function newAtomicCounter(initialValue?: number): AtomicCounter;
31
33
  declare function injectRequestIDIntoError(config: any, err: Error): void;
32
34
  declare function injectRequestIDIntoHeaders(headers: {
33
35
  [k: string]: string;
@@ -41,4 +43,4 @@ export interface RequestIDError extends grpc.ServiceError {
41
43
  declare const X_GOOG_SPANNER_REQUEST_ID_SPAN_ATTR = "x_goog_spanner_request_id";
42
44
  declare function attributeXGoogSpannerRequestIdToActiveSpan(config: any): void;
43
45
  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, };
46
+ export { AtomicCounter, PROCESS_PREFIX, X_GOOG_REQ_ID_REGEX, X_GOOG_SPANNER_REQUEST_ID_HEADER, X_GOOG_SPANNER_REQUEST_ID_SPAN_ATTR, attributeXGoogSpannerRequestIdToActiveSpan, craftRequestId, getRequestIdPrefix, injectRequestIDIntoError, injectRequestIDIntoHeaders, nextNthRequest, nextSpannerClientId, newAtomicCounter, randIdForProcess, };
@@ -15,10 +15,11 @@
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_SPAN_ATTR = exports.X_GOOG_SPANNER_REQUEST_ID_HEADER = exports.X_GOOG_REQ_ID_REGEX = 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.PROCESS_PREFIX = exports.AtomicCounter = void 0;
19
19
  exports.resetNthClientId = resetNthClientId;
20
20
  exports.attributeXGoogSpannerRequestIdToActiveSpan = attributeXGoogSpannerRequestIdToActiveSpan;
21
21
  exports.craftRequestId = craftRequestId;
22
+ exports.getRequestIdPrefix = getRequestIdPrefix;
22
23
  exports.injectRequestIDIntoError = injectRequestIDIntoError;
23
24
  exports.injectRequestIDIntoHeaders = injectRequestIDIntoHeaders;
24
25
  exports.nextNthRequest = nextNthRequest;
@@ -33,36 +34,34 @@ const randIdForProcess = (0, crypto_1.randomBytes)(8)
33
34
  exports.randIdForProcess = randIdForProcess;
34
35
  const REQUEST_HEADER_VERSION = 1;
35
36
  const PROCESS_PREFIX = `${REQUEST_HEADER_VERSION}.${randIdForProcess}.`;
37
+ exports.PROCESS_PREFIX = PROCESS_PREFIX;
36
38
  const X_GOOG_SPANNER_REQUEST_ID_HEADER = 'x-goog-spanner-request-id';
37
39
  exports.X_GOOG_SPANNER_REQUEST_ID_HEADER = X_GOOG_SPANNER_REQUEST_ID_HEADER;
38
40
  class AtomicCounter {
39
- backingBuffer;
41
+ _value;
40
42
  constructor(initialValue) {
41
- this.backingBuffer = new Uint32Array(new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT));
42
- if (initialValue) {
43
- this.increment(initialValue);
44
- }
43
+ this._value = (initialValue ?? 0) >>> 0;
45
44
  }
46
- increment(n) {
47
- if (!n) {
48
- n = 1;
49
- }
50
- Atomics.add(this.backingBuffer, 0, n);
51
- return this.value();
45
+ increment(amount) {
46
+ const step = amount ?? 1;
47
+ return (this._value = (this._value + step) >>> 0);
52
48
  }
53
49
  value() {
54
- return Atomics.load(this.backingBuffer, 0);
50
+ return this._value;
55
51
  }
56
52
  toString() {
57
- return `${this.value()}`;
53
+ return `${this._value}`;
58
54
  }
59
55
  reset() {
60
- Atomics.store(this.backingBuffer, 0, 0);
56
+ this._value = 0;
61
57
  }
62
58
  }
63
59
  exports.AtomicCounter = AtomicCounter;
60
+ function getRequestIdPrefix(clientId = 1, channelId = 1) {
61
+ return `${PROCESS_PREFIX}${clientId ?? 1}.${channelId ?? 1}.`;
62
+ }
64
63
  function craftRequestId(nthClientId, channelId, nthRequest, attempt) {
65
- return `${PROCESS_PREFIX}${nthClientId}.${channelId}.${nthRequest}.${attempt}`;
64
+ return `${PROCESS_PREFIX}${nthClientId ?? 1}.${channelId ?? 1}.${nthRequest ?? 1}.${attempt ?? 1}`;
66
65
  }
67
66
  const nthClientId = new AtomicCounter();
68
67
  // Only exported for deterministic testing.
@@ -75,11 +74,10 @@ function resetNthClientId() {
75
74
  * with x-goog-spanner-request-id.
76
75
  */
77
76
  function nextSpannerClientId() {
78
- nthClientId.increment(1);
79
- return nthClientId.value();
77
+ return nthClientId.increment(1);
80
78
  }
81
- function newAtomicCounter(n) {
82
- return new AtomicCounter(n);
79
+ function newAtomicCounter(initialValue) {
80
+ return new AtomicCounter(initialValue);
83
81
  }
84
82
  function extractRequestID(config) {
85
83
  if (!config) {
@@ -107,16 +105,18 @@ function injectRequestIDIntoHeaders(headers, session, nthRequest, attempt) {
107
105
  return headers;
108
106
  }
109
107
  const database = session.parent;
110
- if (!nthRequest) {
108
+ if (nthRequest === undefined || nthRequest === null) {
111
109
  if (!database || typeof database._nextNthRequest !== 'function') {
112
110
  return headers;
113
111
  }
114
112
  nthRequest = database._nextNthRequest();
115
113
  }
116
- const clientId = database ? database._nthClientId || 1 : 1;
117
- const channelId = database ? database._channelId || 1 : 1;
114
+ const requestCount = nthRequest ?? 1;
115
+ const attemptCount = attempt ?? 1;
118
116
  const withReqId = { ...headers };
119
- withReqId[X_GOOG_SPANNER_REQUEST_ID_HEADER] = craftRequestId(clientId, channelId, nthRequest || 1, attempt || 1);
117
+ withReqId[X_GOOG_SPANNER_REQUEST_ID_HEADER] = database?._requestIdPrefix
118
+ ? `${database._requestIdPrefix}${requestCount}.${attemptCount}`
119
+ : craftRequestId(database?._clientId ?? database?._nthClientId ?? 1, database?._channelId ?? 1, requestCount, attemptCount);
120
120
  return withReqId;
121
121
  }
122
122
  function nextNthRequest(database) {
@@ -17,17 +17,16 @@ import { Database, Session, Transaction } from '.';
17
17
  import { MultiplexedSessionInterface } from './multiplexed-session';
18
18
  import { SessionPoolInterface, SessionPoolOptions } from './session-pool';
19
19
  import { SessionPoolConstructor } from './database';
20
+ import { ServiceError } from 'google-gax';
20
21
  declare const common: any;
21
22
  /**
22
23
  * @callback GetSessionCallback
23
24
  * @param {?Error} error Request error, if any.
24
25
  * @param {Session} [session] The session object.
25
26
  * @param {Transaction} [transaction] The transaction object, if applicable.
26
- * Omitted for read-only multiplexed session acquisitions to prevent throwaway
27
- * allocations. Provided by getSessionForReadWrite or when using regular session pools.
28
27
  */
29
28
  export interface GetSessionCallback {
30
- (err: Error | null, session?: Session | null, transaction?: Transaction | null): void;
29
+ (err: Error | ServiceError | null, session?: Session | null, transaction?: Transaction | null): void;
31
30
  }
32
31
  /**
33
32
  * Interface for implementing session-factory logic.
@@ -49,140 +48,130 @@ export interface SessionFactoryInterface {
49
48
  */
50
49
  getSessionSync(): Session | null;
51
50
  /**
52
- * When called returns a session for paritioned dml.
51
+ * When called returns a session for partitioned operations.
53
52
  *
53
+ * @deprecated Always delegates to {@link SessionFactoryInterface#getSession}.
54
54
  * @name SessionFactoryInterface#getSessionForPartitionedOps
55
55
  * @param {GetSessionCallback} callback The callback function.
56
56
  */
57
- getSessionForPartitionedOps(callback: GetSessionCallback): void;
57
+ getSessionForPartitionedOps?(callback: GetSessionCallback): void;
58
58
  /**
59
- * When called returns a session for read write.
59
+ * When called returns a session for read/write operations.
60
60
  *
61
+ * @deprecated Always delegates to {@link SessionFactoryInterface#getSession}.
61
62
  * @name SessionFactoryInterface#getSessionForReadWrite
62
63
  * @param {GetSessionCallback} callback The callback function.
63
64
  */
64
- getSessionForReadWrite(callback: GetSessionCallback): void;
65
+ getSessionForReadWrite?(callback: GetSessionCallback): void;
65
66
  /**
66
67
  * When called returns the pool object.
67
68
  *
69
+ * @deprecated Session pool is deprecated and will be removed in a future release.
68
70
  * @name SessionFactoryInterface#getPool
69
71
  */
70
- getPool(): SessionPoolInterface;
72
+ getPool?(): SessionPoolInterface;
71
73
  /**
72
- * To be called when releasing a session.
74
+ * Releases a session back into the pool. No-op for multiplexed sessions.
73
75
  *
76
+ * @deprecated Regular session pooling has been removed; this method is a no-op.
74
77
  * @name SessionFactoryInterface#release
75
- * @param {Session} session The session to be released.
78
+ * @param {Session} session The session object.
76
79
  */
77
- release(session: Session): void;
80
+ release?(session: Session): void;
78
81
  /**
79
- * When called returns if the multiplexed is enabled or not.
82
+ * Returns true if multiplexed sessions are enabled.
80
83
  *
84
+ * @deprecated Multiplexed sessions are always enabled.
81
85
  * @name SessionFactoryInterface#isMultiplexedEnabled
86
+ * @returns {boolean} Always true.
82
87
  */
83
- isMultiplexedEnabled(): boolean;
88
+ isMultiplexedEnabled?(): boolean;
84
89
  /**
85
- * When called returns if the multiplexed is enabled or not for read write transactions.
90
+ * Returns true if multiplexed sessions are enabled for read/write transactions.
86
91
  *
92
+ * @deprecated Multiplexed sessions are always enabled for read/write transactions.
87
93
  * @name SessionFactoryInterface#isMultiplexedEnabledForRW
94
+ * @returns {boolean} Always true.
88
95
  */
89
- isMultiplexedEnabledForRW(): boolean;
96
+ isMultiplexedEnabledForRW?(): boolean;
97
+ /**
98
+ * When called closes the session factory and stops background maintenance.
99
+ *
100
+ * @name SessionFactoryInterface#close
101
+ */
102
+ close?(): void;
90
103
  }
91
104
  /**
92
105
  * Creates a SessionFactory object to manage the creation of
93
- * session-pool and multiplexed session.
106
+ * multiplexed session.
94
107
  *
95
108
  * @class
96
109
  *
97
110
  * @param {Database} database Database object.
98
111
  * @param {String} name Name of the database.
99
- * @param {SessionPoolOptions|SessionPoolInterface} options Session pool
100
- * configuration options or custom pool inteface.
101
112
  */
102
113
  export declare class SessionFactory extends common.GrpcServiceObject implements SessionFactoryInterface {
103
- multiplexedSession_: MultiplexedSessionInterface;
104
114
  pool_: SessionPoolInterface;
105
- isMultiplexed: boolean;
106
- isMultiplexedPartitionOps: boolean;
107
- isMultiplexedRW: boolean;
115
+ multiplexedSession_: MultiplexedSessionInterface;
108
116
  constructor(database: Database, name: String, poolOptions?: SessionPoolConstructor | SessionPoolOptions);
109
117
  /**
110
- * Synchronously returns a cached multiplexed session if multiplexed sessions
111
- * are enabled and one is available, otherwise null.
118
+ * Synchronously returns a cached multiplexed session if available,
119
+ * otherwise null.
112
120
  *
113
121
  * @returns {Session|null} The cached multiplexed session or null.
114
122
  */
115
123
  getSessionSync(): Session | null;
116
124
  /**
117
- * Retrieves a session, either a regular session or a multiplexed session, based on the environment variable configuration.
118
- *
119
- * If the environment variable `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS` is set to `false`, the method will attempt to
120
- * retrieve a regular session. Otherwise, it will return a multiplexed session.
125
+ * Retrieves a multiplexed session.
121
126
  *
122
127
  * @param {GetSessionCallback} callback The callback function.
123
128
  */
124
129
  getSession(callback: GetSessionCallback): void;
125
130
  /**
126
- * Retrieves a session for partitioned operations, selecting the appropriate session type
127
- * based on whether multiplexed sessions are disabled or not.
128
- *
129
- * If multiplexed sessions are disabled for partitioned ops this methods delegates the request to `getSession()`, which returns
130
- * either a multiplexed session or a regular session based on the env configuration.
131
- *
132
- * If the multiplexed sessions are disabled, a session will get retrieved from the regular session pool.
133
- * Otherwise a multiplexed session will be used.
131
+ * Retrieves a session for partitioned operations.
134
132
  *
133
+ * @deprecated Use {@link SessionFactory#getSession} instead.
135
134
  * @param {GetSessionCallback} callback The callback function.
136
135
  */
137
136
  getSessionForPartitionedOps(callback: GetSessionCallback): void;
138
137
  /**
139
- * Retrieves a session for read write operations, selecting the appropriate session type
140
- * based on whether multiplexed sessions are enabled.
141
- *
142
- * If multiplexed sessions are disabled for read write this methods delegates the request to `getSession()`, which returns
143
- * either a multiplexed session or a regular session based on the env configuration.
144
- *
145
- * If the multiplexed sessions are disabled, a session will get retrieved from the regular session pool.
146
- * Otherise a multiplexed session will be used.
138
+ * Retrieves a session for read/write operations.
147
139
  *
140
+ * @deprecated Use {@link SessionFactory#getSession} instead.
148
141
  * @param {GetSessionCallback} callback The callback function.
149
142
  */
150
143
  getSessionForReadWrite(callback: GetSessionCallback): void;
151
144
  /**
152
145
  * Returns the regular session pool object.
153
146
  *
147
+ * @deprecated Session pool is deprecated and will be removed in a future release.
154
148
  * @returns {SessionPoolInterface} The session pool used by current instance.
155
149
  */
156
150
  getPool(): SessionPoolInterface;
157
151
  /**
158
- * Releases a regular session back to the session pool.
159
- *
160
- * This methods does not release a multiplexed session.
161
- *
162
- * It returns a session to the pool after it is no longer needed.
163
- * It is a no-op for multiplexed sessions.
152
+ * No-op release method retained for backwards compatibility.
164
153
  *
165
- * @param {Session} session - The session to be released. This should be an instance of `Session` that was
166
- * previously acquired from the session pool.
167
- *
168
- * @throws {Error} If the session is invalid or cannot be released.
154
+ * @deprecated Multiplexed sessions do not require releasing back to a pool.
155
+ * @param {Session} _session The session object.
169
156
  */
170
- release(session: Session): void;
157
+ release(_session: Session): void;
171
158
  /**
172
- * Returns if a multiplexed is enabled or not.
173
- *
174
- * This method returns true if multiplexed session is enabled, otherwise returns false
159
+ * Checks whether multiplexed session is enabled.
175
160
  *
176
- * @returns {boolean}
161
+ * @deprecated Multiplexed sessions are always enabled.
162
+ * @returns {boolean} Always returns `true`.
177
163
  */
178
164
  isMultiplexedEnabled(): boolean;
179
165
  /**
180
- * Returns if a multiplexed is enabled or not for read write transaction.
181
- *
182
- * This method returns true if multiplexed session is enabled for read write transactions, otherwise returns false
166
+ * Checks whether multiplexed session is enabled for read/write transactions.
183
167
  *
184
- * @returns {boolean}
168
+ * @deprecated Multiplexed sessions are always enabled for read/write transactions.
169
+ * @returns {boolean} Always returns `true`.
185
170
  */
186
171
  isMultiplexedEnabledForRW(): boolean;
172
+ /**
173
+ * Closes the session factory and stops background maintenance.
174
+ */
175
+ close(): void;
187
176
  }
188
177
  export {};