@google-cloud/spanner 7.18.0 → 7.19.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 (84) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +1 -0
  3. package/build/protos/google/spanner/admin/database/v1/backup.proto +773 -0
  4. package/build/protos/google/spanner/admin/database/v1/backup_schedule.proto +230 -0
  5. package/build/protos/google/spanner/admin/database/v1/common.proto +132 -0
  6. package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +1279 -0
  7. package/build/protos/google/spanner/admin/instance/v1/common.proto +64 -0
  8. package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +2110 -0
  9. package/build/protos/google/spanner/executor/v1/cloud_executor.proto +1520 -0
  10. package/build/protos/google/spanner/v1/commit_response.proto +59 -0
  11. package/build/protos/google/spanner/v1/keys.proto +163 -0
  12. package/build/protos/google/spanner/v1/mutation.proto +107 -0
  13. package/build/protos/google/spanner/v1/query_plan.proto +128 -0
  14. package/build/protos/google/spanner/v1/result_set.proto +237 -0
  15. package/build/protos/google/spanner/v1/spanner.proto +1389 -0
  16. package/build/protos/google/spanner/v1/transaction.proto +622 -0
  17. package/build/protos/google/spanner/v1/type.proto +214 -0
  18. package/build/protos/protos.d.ts +39869 -0
  19. package/build/protos/protos.js +101659 -0
  20. package/build/protos/protos.json +10391 -0
  21. package/build/src/backup.d.ts +349 -0
  22. package/build/src/backup.js +246 -0
  23. package/build/src/batch-transaction.d.ts +247 -0
  24. package/build/src/batch-transaction.js +384 -0
  25. package/build/src/codec.d.ts +362 -0
  26. package/build/src/codec.js +791 -0
  27. package/build/src/common-grpc/service-object.d.ts +80 -0
  28. package/build/src/common-grpc/service-object.js +101 -0
  29. package/build/src/common-grpc/service.d.ts +445 -0
  30. package/build/src/common-grpc/service.js +826 -0
  31. package/build/src/common.d.ts +66 -0
  32. package/build/src/common.js +54 -0
  33. package/build/src/database.d.ts +2103 -0
  34. package/build/src/database.js +1660 -0
  35. package/build/src/extra_proto_list.json +1 -0
  36. package/build/src/helper.d.ts +45 -0
  37. package/build/src/helper.js +71 -0
  38. package/build/src/index.d.ts +1195 -0
  39. package/build/src/index.js +1059 -0
  40. package/build/src/instance-config.d.ts +294 -0
  41. package/build/src/instance-config.js +216 -0
  42. package/build/src/instance.d.ts +832 -0
  43. package/build/src/instance.js +781 -0
  44. package/build/src/instrument.d.ts +85 -0
  45. package/build/src/instrument.js +215 -0
  46. package/build/src/multiplexed-session.d.ts +135 -0
  47. package/build/src/multiplexed-session.js +194 -0
  48. package/build/src/partial-result-stream.d.ts +253 -0
  49. package/build/src/partial-result-stream.js +400 -0
  50. package/build/src/request_id_header.d.ts +41 -0
  51. package/build/src/request_id_header.js +138 -0
  52. package/build/src/session-factory.d.ts +115 -0
  53. package/build/src/session-factory.js +106 -0
  54. package/build/src/session-pool.d.ts +471 -0
  55. package/build/src/session-pool.js +765 -0
  56. package/build/src/session.d.ts +258 -0
  57. package/build/src/session.js +348 -0
  58. package/build/src/spanner_grpc_config.json +92 -0
  59. package/build/src/table.d.ts +831 -0
  60. package/build/src/table.js +277 -0
  61. package/build/src/transaction-runner.d.ts +185 -0
  62. package/build/src/transaction-runner.js +282 -0
  63. package/build/src/transaction.d.ts +1691 -0
  64. package/build/src/transaction.js +2003 -0
  65. package/build/src/v1/database_admin_client.d.ts +2332 -0
  66. package/build/src/v1/database_admin_client.js +2364 -0
  67. package/build/src/v1/database_admin_client_config.json +165 -0
  68. package/build/src/v1/database_admin_proto_list.json +6 -0
  69. package/build/src/v1/gapic_metadata.json +27 -0
  70. package/build/src/v1/index.d.ts +4 -0
  71. package/build/src/v1/index.js +29 -0
  72. package/build/src/v1/instance_admin_client.d.ts +1985 -0
  73. package/build/src/v1/instance_admin_client.js +1768 -0
  74. package/build/src/v1/instance_admin_client_config.json +129 -0
  75. package/build/src/v1/instance_admin_proto_list.json +4 -0
  76. package/build/src/v1/spanner_client.d.ts +1250 -0
  77. package/build/src/v1/spanner_client.js +1086 -0
  78. package/build/src/v1/spanner_client_config.json +119 -0
  79. package/build/src/v1/spanner_executor_proxy_client.d.ts +418 -0
  80. package/build/src/v1/spanner_executor_proxy_client.js +706 -0
  81. package/build/src/v1/spanner_executor_proxy_client_config.json +30 -0
  82. package/build/src/v1/spanner_executor_proxy_proto_list.json +14 -0
  83. package/build/src/v1/spanner_proto_list.json +10 -0
  84. package/package.json +1 -1
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2025 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.randIdForProcess = exports.X_GOOG_SPANNER_REQUEST_ID_HEADER = exports.AtomicCounter = void 0;
19
+ exports.resetNthClientId = resetNthClientId;
20
+ exports.craftRequestId = craftRequestId;
21
+ exports.injectRequestIDIntoError = injectRequestIDIntoError;
22
+ exports.injectRequestIDIntoHeaders = injectRequestIDIntoHeaders;
23
+ exports.nextNthRequest = nextNthRequest;
24
+ exports.nextSpannerClientId = nextSpannerClientId;
25
+ exports.newAtomicCounter = newAtomicCounter;
26
+ const crypto_1 = require("crypto");
27
+ const randIdForProcess = (0, crypto_1.randomBytes)(8)
28
+ .readUint32LE(0)
29
+ .toString(16)
30
+ .padStart(8, '0');
31
+ exports.randIdForProcess = randIdForProcess;
32
+ const X_GOOG_SPANNER_REQUEST_ID_HEADER = 'x-goog-spanner-request-id';
33
+ exports.X_GOOG_SPANNER_REQUEST_ID_HEADER = X_GOOG_SPANNER_REQUEST_ID_HEADER;
34
+ class AtomicCounter {
35
+ constructor(initialValue) {
36
+ this.backingBuffer = new Uint32Array(new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT));
37
+ if (initialValue) {
38
+ this.increment(initialValue);
39
+ }
40
+ }
41
+ increment(n) {
42
+ if (!n) {
43
+ n = 1;
44
+ }
45
+ Atomics.add(this.backingBuffer, 0, n);
46
+ return this.value();
47
+ }
48
+ value() {
49
+ return Atomics.load(this.backingBuffer, 0);
50
+ }
51
+ toString() {
52
+ return `${this.value()}`;
53
+ }
54
+ reset() {
55
+ Atomics.store(this.backingBuffer, 0, 0);
56
+ }
57
+ }
58
+ exports.AtomicCounter = AtomicCounter;
59
+ const REQUEST_HEADER_VERSION = 1;
60
+ function craftRequestId(nthClientId, channelId, nthRequest, attempt) {
61
+ return `${REQUEST_HEADER_VERSION}.${randIdForProcess}.${nthClientId}.${channelId}.${nthRequest}.${attempt}`;
62
+ }
63
+ const nthClientId = new AtomicCounter();
64
+ // Only exported for deterministic testing.
65
+ function resetNthClientId() {
66
+ nthClientId.reset();
67
+ }
68
+ /*
69
+ * nextSpannerClientId increments the internal
70
+ * counter for created SpannerClients, for use
71
+ * with x-goog-spanner-request-id.
72
+ */
73
+ function nextSpannerClientId() {
74
+ nthClientId.increment(1);
75
+ return nthClientId.value();
76
+ }
77
+ function newAtomicCounter(n) {
78
+ return new AtomicCounter(n);
79
+ }
80
+ function extractRequestID(config) {
81
+ if (!config) {
82
+ return '';
83
+ }
84
+ const hdrs = config;
85
+ if (hdrs && hdrs.headers) {
86
+ return hdrs.headers[X_GOOG_SPANNER_REQUEST_ID_HEADER];
87
+ }
88
+ return '';
89
+ }
90
+ function injectRequestIDIntoError(config, err) {
91
+ if (!err) {
92
+ return;
93
+ }
94
+ // Inject that RequestID into the actual
95
+ // error object regardless of the type.
96
+ const requestID = extractRequestID(config);
97
+ if (requestID) {
98
+ Object.assign(err, { requestID: requestID });
99
+ }
100
+ }
101
+ function injectRequestIDIntoHeaders(headers, session, nthRequest, attempt) {
102
+ if (!session) {
103
+ return headers;
104
+ }
105
+ if (!nthRequest) {
106
+ const database = session.parent;
107
+ if (!(database && typeof database._nextNthRequest === 'function')) {
108
+ return headers;
109
+ }
110
+ nthRequest = database._nextNthRequest();
111
+ }
112
+ attempt = attempt || 1;
113
+ return _metadataWithRequestId(session, nthRequest, attempt, headers);
114
+ }
115
+ function _metadataWithRequestId(session, nthRequest, attempt, priorMetadata) {
116
+ if (!priorMetadata) {
117
+ priorMetadata = {};
118
+ }
119
+ const withReqId = {
120
+ ...priorMetadata,
121
+ };
122
+ const database = session.parent;
123
+ let clientId = 1;
124
+ let channelId = 1;
125
+ if (database) {
126
+ clientId = database._nthClientId || 1;
127
+ channelId = database._channelId || 1;
128
+ }
129
+ withReqId[X_GOOG_SPANNER_REQUEST_ID_HEADER] = craftRequestId(clientId, channelId, nthRequest, attempt);
130
+ return withReqId;
131
+ }
132
+ function nextNthRequest(database) {
133
+ if (!(database && typeof database._nextNthRequest === 'function')) {
134
+ return 1;
135
+ }
136
+ return database._nextNthRequest();
137
+ }
138
+ //# sourceMappingURL=request_id_header.js.map
@@ -0,0 +1,115 @@
1
+ /*!
2
+ * Copyright 2024 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 { Database, Session, Transaction } from '.';
17
+ import { MultiplexedSessionInterface } from './multiplexed-session';
18
+ import { SessionPoolInterface, SessionPoolOptions } from './session-pool';
19
+ import { SessionPoolConstructor } from './database';
20
+ declare const common: any;
21
+ /**
22
+ * @callback GetSessionCallback
23
+ * @param {?Error} error Request error, if any.
24
+ * @param {Session} session The read-write session.
25
+ * @param {Transaction} transaction The transaction object.
26
+ */
27
+ export interface GetSessionCallback {
28
+ (err: Error | null, session?: Session | null, transaction?: Transaction | null): void;
29
+ }
30
+ /**
31
+ * Interface for implementing session-factory logic.
32
+ *
33
+ * @interface SessionFactoryInterface
34
+ */
35
+ export interface SessionFactoryInterface {
36
+ /**
37
+ * When called returns a session.
38
+ *
39
+ * @name SessionFactoryInterface#getSession
40
+ * @param {GetSessionCallback} callback The callback function.
41
+ */
42
+ getSession(callback: GetSessionCallback): void;
43
+ /**
44
+ * When called returns the pool object.
45
+ *
46
+ * @name SessionFactoryInterface#getPool
47
+ */
48
+ getPool(): SessionPoolInterface;
49
+ /**
50
+ * To be called when releasing a session.
51
+ *
52
+ * @name SessionFactoryInterface#release
53
+ * @param {Session} session The session to be released.
54
+ */
55
+ release(session: Session): void;
56
+ /**
57
+ * When called returns if the multiplexed is enabled or not.
58
+ *
59
+ * @name SessionFactoryInterface#isMultiplexedEnabled
60
+ */
61
+ isMultiplexedEnabled(): boolean;
62
+ }
63
+ /**
64
+ * Creates a SessionFactory object to manage the creation of
65
+ * session-pool and multiplexed session.
66
+ *
67
+ * @class
68
+ *
69
+ * @param {Database} database Database object.
70
+ * @param {String} name Name of the database.
71
+ * @param {SessionPoolOptions|SessionPoolInterface} options Session pool
72
+ * configuration options or custom pool inteface.
73
+ */
74
+ export declare class SessionFactory extends common.GrpcServiceObject implements SessionFactoryInterface {
75
+ multiplexedSession_: MultiplexedSessionInterface;
76
+ pool_: SessionPoolInterface;
77
+ isMultiplexed: boolean;
78
+ constructor(database: Database, name: String, poolOptions?: SessionPoolConstructor | SessionPoolOptions);
79
+ /**
80
+ * Retrieves a session, either a regular session or a multiplexed session, based on the environment variable configuration.
81
+ *
82
+ * If the environment variable `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS` is set to `true`, the method will attempt to
83
+ * retrieve a multiplexed session. Otherwise, it will retrieve a session from the regular pool.
84
+ *
85
+ * @param {GetSessionCallback} callback The callback function.
86
+ */
87
+ getSession(callback: GetSessionCallback): void;
88
+ /**
89
+ * Returns the regular session pool object.
90
+ *
91
+ * @returns {SessionPoolInterface} The session pool used by current instance.
92
+ */
93
+ getPool(): SessionPoolInterface;
94
+ /**
95
+ * Releases a session back to the session pool.
96
+ *
97
+ * This method returns a session to the pool after it is no longer needed.
98
+ * It is a no-op for multiplexed sessions.
99
+ *
100
+ * @param {Session} session - The session to be released. This should be an instance of `Session` that was
101
+ * previously acquired from the session pool.
102
+ *
103
+ * @throws {Error} If the session is invalid or cannot be released.
104
+ */
105
+ release(session: Session): void;
106
+ /**
107
+ * Returns if a multiplexed is enabled or not.
108
+ *
109
+ * This method returns true if multiplexed session is enabled, otherwise returns false
110
+ *
111
+ * @returns {boolean}
112
+ */
113
+ isMultiplexedEnabled(): boolean;
114
+ }
115
+ export {};
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright 2024 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.SessionFactory = void 0;
19
+ const multiplexed_session_1 = require("./multiplexed-session");
20
+ const session_pool_1 = require("./session-pool");
21
+ const common = require('./common-grpc/service-object');
22
+ /**
23
+ * Creates a SessionFactory object to manage the creation of
24
+ * session-pool and multiplexed session.
25
+ *
26
+ * @class
27
+ *
28
+ * @param {Database} database Database object.
29
+ * @param {String} name Name of the database.
30
+ * @param {SessionPoolOptions|SessionPoolInterface} options Session pool
31
+ * configuration options or custom pool inteface.
32
+ */
33
+ class SessionFactory extends common.GrpcServiceObject {
34
+ constructor(database, name, poolOptions) {
35
+ super({
36
+ parent: database,
37
+ id: name,
38
+ });
39
+ this.pool_ =
40
+ typeof poolOptions === 'function'
41
+ ? new poolOptions(database, null)
42
+ : new session_pool_1.SessionPool(database, poolOptions);
43
+ this.pool_.on('error', this.emit.bind(database, 'error'));
44
+ this.pool_.open();
45
+ this.multiplexedSession_ = new multiplexed_session_1.MultiplexedSession(database);
46
+ // set the isMultiplexed property to true if multiplexed session is enabled, otherwise set the property to false
47
+ process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'true'
48
+ ? (this.isMultiplexed = true)
49
+ : (this.isMultiplexed = false);
50
+ // Multiplexed sessions should only be created if its enabled.
51
+ if (this.isMultiplexed) {
52
+ this.multiplexedSession_.on('error', this.emit.bind(database, 'error'));
53
+ this.multiplexedSession_.createSession();
54
+ }
55
+ }
56
+ /**
57
+ * Retrieves a session, either a regular session or a multiplexed session, based on the environment variable configuration.
58
+ *
59
+ * If the environment variable `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS` is set to `true`, the method will attempt to
60
+ * retrieve a multiplexed session. Otherwise, it will retrieve a session from the regular pool.
61
+ *
62
+ * @param {GetSessionCallback} callback The callback function.
63
+ */
64
+ getSession(callback) {
65
+ const sessionHandler = this.isMultiplexed
66
+ ? this.multiplexedSession_
67
+ : this.pool_;
68
+ sessionHandler.getSession((err, session, transaction) => callback(err, session, transaction));
69
+ }
70
+ /**
71
+ * Returns the regular session pool object.
72
+ *
73
+ * @returns {SessionPoolInterface} The session pool used by current instance.
74
+ */
75
+ getPool() {
76
+ return this.pool_;
77
+ }
78
+ /**
79
+ * Releases a session back to the session pool.
80
+ *
81
+ * This method returns a session to the pool after it is no longer needed.
82
+ * It is a no-op for multiplexed sessions.
83
+ *
84
+ * @param {Session} session - The session to be released. This should be an instance of `Session` that was
85
+ * previously acquired from the session pool.
86
+ *
87
+ * @throws {Error} If the session is invalid or cannot be released.
88
+ */
89
+ release(session) {
90
+ if (!this.isMultiplexed) {
91
+ this.pool_.release(session);
92
+ }
93
+ }
94
+ /**
95
+ * Returns if a multiplexed is enabled or not.
96
+ *
97
+ * This method returns true if multiplexed session is enabled, otherwise returns false
98
+ *
99
+ * @returns {boolean}
100
+ */
101
+ isMultiplexedEnabled() {
102
+ return this.isMultiplexed;
103
+ }
104
+ }
105
+ exports.SessionFactory = SessionFactory;
106
+ //# sourceMappingURL=session-factory.js.map