@google-cloud/spanner 7.17.0 → 7.18.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 (81) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +1 -1
  3. package/build/protos/google/spanner/admin/database/v1/backup.proto +0 -757
  4. package/build/protos/google/spanner/admin/database/v1/backup_schedule.proto +0 -230
  5. package/build/protos/google/spanner/admin/database/v1/common.proto +0 -132
  6. package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +0 -1209
  7. package/build/protos/google/spanner/admin/instance/v1/common.proto +0 -63
  8. package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +0 -1983
  9. package/build/protos/google/spanner/executor/v1/cloud_executor.proto +0 -1520
  10. package/build/protos/google/spanner/v1/commit_response.proto +0 -59
  11. package/build/protos/google/spanner/v1/keys.proto +0 -163
  12. package/build/protos/google/spanner/v1/mutation.proto +0 -107
  13. package/build/protos/google/spanner/v1/query_plan.proto +0 -128
  14. package/build/protos/google/spanner/v1/result_set.proto +0 -237
  15. package/build/protos/google/spanner/v1/spanner.proto +0 -1389
  16. package/build/protos/google/spanner/v1/transaction.proto +0 -575
  17. package/build/protos/google/spanner/v1/type.proto +0 -210
  18. package/build/protos/protos.d.ts +0 -38999
  19. package/build/protos/protos.js +0 -99538
  20. package/build/protos/protos.json +0 -10182
  21. package/build/src/backup.d.ts +0 -349
  22. package/build/src/backup.js +0 -246
  23. package/build/src/batch-transaction.d.ts +0 -247
  24. package/build/src/batch-transaction.js +0 -384
  25. package/build/src/codec.d.ts +0 -362
  26. package/build/src/codec.js +0 -791
  27. package/build/src/common-grpc/service-object.d.ts +0 -80
  28. package/build/src/common-grpc/service-object.js +0 -101
  29. package/build/src/common-grpc/service.d.ts +0 -445
  30. package/build/src/common-grpc/service.js +0 -826
  31. package/build/src/common.d.ts +0 -66
  32. package/build/src/common.js +0 -54
  33. package/build/src/database.d.ts +0 -2104
  34. package/build/src/database.js +0 -1655
  35. package/build/src/extra_proto_list.json +0 -1
  36. package/build/src/helper.d.ts +0 -45
  37. package/build/src/helper.js +0 -71
  38. package/build/src/index.d.ts +0 -1195
  39. package/build/src/index.js +0 -1060
  40. package/build/src/instance-config.d.ts +0 -295
  41. package/build/src/instance-config.js +0 -216
  42. package/build/src/instance.d.ts +0 -833
  43. package/build/src/instance.js +0 -781
  44. package/build/src/instrument.d.ts +0 -87
  45. package/build/src/instrument.js +0 -217
  46. package/build/src/multiplexed-session.d.ts +0 -136
  47. package/build/src/multiplexed-session.js +0 -197
  48. package/build/src/partial-result-stream.d.ts +0 -253
  49. package/build/src/partial-result-stream.js +0 -400
  50. package/build/src/session-factory.d.ts +0 -101
  51. package/build/src/session-factory.js +0 -93
  52. package/build/src/session-pool.d.ts +0 -471
  53. package/build/src/session-pool.js +0 -754
  54. package/build/src/session.d.ts +0 -259
  55. package/build/src/session.js +0 -348
  56. package/build/src/spanner_grpc_config.json +0 -92
  57. package/build/src/table.d.ts +0 -831
  58. package/build/src/table.js +0 -277
  59. package/build/src/transaction-runner.d.ts +0 -185
  60. package/build/src/transaction-runner.js +0 -282
  61. package/build/src/transaction.d.ts +0 -1691
  62. package/build/src/transaction.js +0 -2004
  63. package/build/src/v1/database_admin_client.d.ts +0 -2301
  64. package/build/src/v1/database_admin_client.js +0 -2286
  65. package/build/src/v1/database_admin_client_config.json +0 -160
  66. package/build/src/v1/database_admin_proto_list.json +0 -6
  67. package/build/src/v1/gapic_metadata.json +0 -27
  68. package/build/src/v1/index.d.ts +0 -4
  69. package/build/src/v1/index.js +0 -29
  70. package/build/src/v1/instance_admin_client.d.ts +0 -1982
  71. package/build/src/v1/instance_admin_client.js +0 -1766
  72. package/build/src/v1/instance_admin_client_config.json +0 -129
  73. package/build/src/v1/instance_admin_proto_list.json +0 -4
  74. package/build/src/v1/spanner_client.d.ts +0 -1250
  75. package/build/src/v1/spanner_client.js +0 -1086
  76. package/build/src/v1/spanner_client_config.json +0 -119
  77. package/build/src/v1/spanner_executor_proxy_client.d.ts +0 -418
  78. package/build/src/v1/spanner_executor_proxy_client.js +0 -706
  79. package/build/src/v1/spanner_executor_proxy_client_config.json +0 -30
  80. package/build/src/v1/spanner_executor_proxy_proto_list.json +0 -14
  81. package/build/src/v1/spanner_proto_list.json +0 -10
@@ -1,282 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright 2019 Google Inc. 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.AsyncTransactionRunner = exports.TransactionRunner = exports.Runner = exports.DeadlineError = void 0;
19
- exports.isRetryableInternalError = isRetryableInternalError;
20
- const promisify_1 = require("@google-cloud/promisify");
21
- const google_gax_1 = require("google-gax");
22
- const protobufjs_1 = require("protobufjs");
23
- const through = require("through2");
24
- const session_pool_1 = require("./session-pool");
25
- // eslint-disable-next-line @typescript-eslint/no-var-requires
26
- const jsonProtos = require('../protos/protos.json');
27
- const RETRY_INFO = 'google.rpc.retryinfo-bin';
28
- const RETRYABLE = [google_gax_1.grpc.status.ABORTED];
29
- // tslint:disable-next-line variable-name
30
- const RetryInfo = protobufjs_1.Root.fromJSON(jsonProtos).lookup('google.rpc.RetryInfo');
31
- /**
32
- * Error class used to signal a Transaction timeout.
33
- *
34
- * @private
35
- * @class
36
- *
37
- * @param {Error} [err] The last known retryable Error.
38
- */
39
- class DeadlineError extends Error {
40
- constructor(error) {
41
- super('Deadline for Transaction exceeded.');
42
- this.code = google_gax_1.grpc.status.DEADLINE_EXCEEDED;
43
- this.details = (error === null || error === void 0 ? void 0 : error.details) || '';
44
- this.metadata = (error === null || error === void 0 ? void 0 : error.metadata) || new google_gax_1.grpc.Metadata();
45
- this.errors = [];
46
- if (error) {
47
- this.errors.push(error);
48
- }
49
- }
50
- }
51
- exports.DeadlineError = DeadlineError;
52
- /**
53
- * Base class for running/retrying Transactions.
54
- *
55
- * @private
56
- * @class
57
- * @abstract
58
- *
59
- * @param {Database} database The Database to pull Sessions/Transactions from.
60
- * @param {RunTransactionOptions} [options] The runner options.
61
- */
62
- class Runner {
63
- constructor(session, transaction, options) {
64
- this.attempts = 0;
65
- this.session = session;
66
- this.transaction = transaction;
67
- this.transaction.useInRunner();
68
- const defaults = { timeout: 3600000 };
69
- this.options = Object.assign(defaults, options);
70
- }
71
- /**
72
- * Attempts to retrieve the retry delay from the supplied error. If absent it
73
- * will create one based on the number of attempts made thus far.
74
- *
75
- * @private
76
- *
77
- * @param {Error} err The service error.
78
- * @returns {number} Delay in milliseconds.
79
- */
80
- getNextDelay(err) {
81
- const retryInfo = err.metadata && err.metadata.get(RETRY_INFO);
82
- if (retryInfo && retryInfo.length) {
83
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
- const { retryDelay } = RetryInfo.decode(retryInfo[0]);
85
- let { seconds } = retryDelay;
86
- if (typeof seconds !== 'number') {
87
- seconds = seconds.toNumber();
88
- }
89
- const secondsInMs = Math.floor(seconds) * 1000;
90
- const nanosInMs = Math.floor(retryDelay.nanos) / 1e6;
91
- return secondsInMs + nanosInMs;
92
- }
93
- // A 'Session not found' error without any specific retry info should not
94
- // cause any delay between retries.
95
- if ((0, session_pool_1.isSessionNotFoundError)(err)) {
96
- return 0;
97
- }
98
- // Max backoff should be 32 seconds.
99
- return (Math.pow(2, Math.min(this.attempts, 5)) * 1000 +
100
- Math.floor(Math.random() * 1000));
101
- }
102
- /** Returns whether the given error should cause a transaction retry. */
103
- shouldRetry(err) {
104
- return (RETRYABLE.includes(err.code) ||
105
- (0, session_pool_1.isSessionNotFoundError)(err) ||
106
- isRetryableInternalError(err));
107
- }
108
- /**
109
- * Retrieves a transaction to run against.
110
- *
111
- * @private
112
- *
113
- * @returns Promise<Transaction>
114
- */
115
- async getTransaction() {
116
- if (this.transaction) {
117
- const transaction = this.transaction;
118
- delete this.transaction;
119
- return transaction;
120
- }
121
- const transaction = this.session.transaction(this.session.parent.queryOptions_);
122
- if (this.options.optimisticLock) {
123
- transaction.useOptimisticLock();
124
- }
125
- if (this.options.excludeTxnFromChangeStreams) {
126
- transaction.excludeTxnFromChangeStreams();
127
- }
128
- if (this.attempts > 0) {
129
- await transaction.begin();
130
- }
131
- return transaction;
132
- }
133
- /**
134
- * This function is responsible for getting transactions, running them and
135
- * handling any errors, retrying if necessary.
136
- *
137
- * @private
138
- *
139
- * @returns {Promise}
140
- */
141
- async run() {
142
- const start = Date.now();
143
- const timeout = this.options.timeout;
144
- let lastError;
145
- // The transaction runner should always execute at least one attempt before
146
- // timing out.
147
- while (this.attempts === 0 || Date.now() - start < timeout) {
148
- const transaction = await this.getTransaction();
149
- try {
150
- return await this._run(transaction);
151
- }
152
- catch (e) {
153
- this.session.lastError = e;
154
- lastError = e;
155
- }
156
- // Note that if the error is a 'Session not found' error, it will be
157
- // thrown here. We do this to bubble this error up to the caller who is
158
- // responsible for retrying the transaction on a different session.
159
- if (!RETRYABLE.includes(lastError.code) &&
160
- !isRetryableInternalError(lastError)) {
161
- throw lastError;
162
- }
163
- this.attempts += 1;
164
- const delay = this.getNextDelay(lastError);
165
- await new Promise(resolve => setTimeout(resolve, delay));
166
- }
167
- throw new DeadlineError(lastError);
168
- }
169
- }
170
- exports.Runner = Runner;
171
- /**
172
- * This class handles transactions expecting to be ran in callback mode.
173
- *
174
- * @private
175
- * @class
176
- *
177
- * @param {Database} database The database to pull sessions/transactions from.
178
- * @param {RunTransactionCallback} runFn The user supplied run function.
179
- * @param {RunTransactionOptions} [options] Runner options.
180
- */
181
- class TransactionRunner extends Runner {
182
- constructor(session, transaction, runFn, options) {
183
- super(session, transaction, options);
184
- this.runFn = runFn;
185
- }
186
- /**
187
- * Because the user has decided to use callback mode, we want to try and
188
- * intercept any ABORTED or UNKNOWN errors and stop the current function
189
- * execution.
190
- *
191
- * @private
192
- *
193
- * @param {Transaction} transaction The transaction to intercept errors for.
194
- * @param {Function} reject Function to call when a retryable error is found.
195
- */
196
- _interceptErrors(transaction, reject) {
197
- const request = transaction.request;
198
- transaction.request = (0, promisify_1.promisify)((config, callback) => {
199
- request(config, (err, resp) => {
200
- if (!err || !this.shouldRetry(err)) {
201
- callback(err, resp);
202
- return;
203
- }
204
- reject(err);
205
- });
206
- });
207
- const requestStream = transaction.requestStream;
208
- transaction.requestStream = (config) => {
209
- const proxyStream = through.obj();
210
- const stream = requestStream(config);
211
- stream
212
- .on('error', (err) => {
213
- if (!this.shouldRetry(err)) {
214
- proxyStream.destroy(err);
215
- return;
216
- }
217
- stream.unpipe(proxyStream);
218
- reject(err);
219
- })
220
- .pipe(proxyStream);
221
- return proxyStream;
222
- };
223
- }
224
- /**
225
- * Creates a Promise that should resolve when the provided transaction has
226
- * been committed or rolled back. Rejects if a retryable error occurs.
227
- *
228
- * @private
229
- *
230
- * @param {Transaction}
231
- * @returns {Promise}
232
- */
233
- _run(transaction) {
234
- return new Promise((resolve, reject) => {
235
- transaction.once('end', resolve);
236
- this._interceptErrors(transaction, reject);
237
- this.runFn(null, transaction);
238
- });
239
- }
240
- }
241
- exports.TransactionRunner = TransactionRunner;
242
- /**
243
- * This class handles transactions expecting to be ran in promise mode.
244
- *
245
- * @private
246
- * @class
247
- *
248
- * @param {Database} database The database to pull sessions/transactions from.
249
- * @param {AsyncRunTransactionCallback} runFn The user supplied run function.
250
- * @param {RunTransactionOptions} [options] Runner options.
251
- */
252
- class AsyncTransactionRunner extends Runner {
253
- constructor(session, transaction, runFn, options) {
254
- super(session, transaction, options);
255
- this.runFn = runFn;
256
- }
257
- /**
258
- * Since this is promise mode all we need to do is return the user function.
259
- *
260
- * @private
261
- *
262
- * @param {Transaction} transaction The transaction to be ran against.
263
- * @returns {Promise}
264
- */
265
- _run(transaction) {
266
- return this.runFn(transaction);
267
- }
268
- }
269
- exports.AsyncTransactionRunner = AsyncTransactionRunner;
270
- /**
271
- * Checks whether the given error is a retryable internal error.
272
- * @param error the error to check
273
- * @return true if the error is a retryable internal error, and otherwise false.
274
- */
275
- function isRetryableInternalError(err) {
276
- return (err.code === google_gax_1.grpc.status.INTERNAL &&
277
- (err.message.includes('Received unexpected EOS on DATA frame from server') ||
278
- err.message.includes('RST_STREAM') ||
279
- err.message.includes('HTTP/2 error code: INTERNAL_ERROR') ||
280
- err.message.includes('Connection closed with unknown cause')));
281
- }
282
- //# sourceMappingURL=transaction-runner.js.map