@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,277 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright 2016 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.Table = void 0;
19
- const promisify_1 = require("@google-cloud/promisify");
20
- const through = require("through2");
21
- const instrument_1 = require("./instrument");
22
- const GOOGLE_STANDARD_SQL = 'GOOGLE_STANDARD_SQL';
23
- const POSTGRESQL = 'POSTGRESQL';
24
- /**
25
- * Create a Table object to interact with a table in a Cloud Spanner
26
- * database.
27
- *
28
- * @class
29
- *
30
- * @param {Database} database {@link Database} instance.
31
- * @param {string} name Name of the table.
32
- *
33
- * @example
34
- * ```
35
- * const {Spanner} = require('@google-cloud/spanner');
36
- * const spanner = new Spanner();
37
- *
38
- * const instance = spanner.instance('my-instance');
39
- * const database = instance.database('my-database');
40
- * const table = database.table('my-table');
41
- * ```
42
- */
43
- class Table {
44
- constructor(database, name) {
45
- /**
46
- * The {@link Database} instance of this {@link Table} instance.
47
- * @name Table#database
48
- * @type {Database}
49
- */
50
- this.database = database;
51
- /**
52
- * The name of this table.
53
- * @name Table#name
54
- * @type {string}
55
- */
56
- this.name = name;
57
- this._observabilityOptions = database._observabilityOptions;
58
- }
59
- create(schema, gaxOptionsOrCallback, cb) {
60
- const gaxOptions = typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
61
- const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
62
- this.database.createTable(schema, gaxOptions, callback);
63
- }
64
- getDBName() {
65
- return this.database.formattedName_;
66
- }
67
- /**
68
- * Create a readable object stream to receive rows from the database using key
69
- * lookups and scans.
70
- *
71
- * @see [StreamingRead API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.StreamingRead)
72
- * @see [ReadRequest API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ReadRequest)
73
- *
74
- * @param {ReadRequest} query Configuration object, describing what to read from the table..
75
- * @param {TimestampBounds} [options] [Transaction options](https://cloud.google.com/spanner/docs/timestamp-bounds).
76
- * @returns {PartialResultStream} A readable stream that emits rows.
77
- *
78
- * @example
79
- * ```
80
- * const {Spanner} = require('@google-cloud/spanner');
81
- * const spanner = new Spanner();
82
- *
83
- * const instance = spanner.instance('my-instance');
84
- * const database = instance.database('my-database');
85
- * const table = database.table('Singers');
86
- *
87
- * table.createReadStream({
88
- * keys: ['1'],
89
- * columns: ['SingerId', 'name']
90
- * })
91
- * .on('error', function(err) {})
92
- * .on('data', function(row) {
93
- * // row = {
94
- * // SingerId: '1',
95
- * // Name: 'Eddie Wilson'
96
- * // }
97
- * })
98
- * .on('end', function() {
99
- * // All results retrieved.
100
- * });
101
- *
102
- * //-
103
- * // Provide an array for `query.keys` to read with a composite key.
104
- * //-
105
- * const query = {
106
- * keys: [
107
- * [
108
- * 'Id1',
109
- * 'Name1'
110
- * ],
111
- * [
112
- * 'Id2',
113
- * 'Name2'
114
- * ]
115
- * ],
116
- * // ...
117
- * };
118
- *
119
- * //-
120
- * // If you anticipate many results, you can end a stream early to prevent
121
- * // unnecessary processing and API requests.
122
- * //-
123
- * table.createReadStream({
124
- * keys: ['1'],
125
- * columns: ['SingerId', 'name']
126
- * })
127
- * .on('data', function(row) {
128
- * this.end();
129
- * });
130
- * ```
131
- */
132
- createReadStream(request, options = {}) {
133
- const proxyStream = through.obj();
134
- this.database.getSnapshot(options, (err, snapshot) => {
135
- if (err) {
136
- proxyStream.destroy(err);
137
- return;
138
- }
139
- snapshot
140
- .createReadStream(this.name, request)
141
- .on('error', err => {
142
- proxyStream.destroy(err);
143
- snapshot.end();
144
- })
145
- .on('end', () => snapshot.end())
146
- .pipe(proxyStream);
147
- });
148
- return proxyStream;
149
- }
150
- delete(gaxOptionsOrCallback, cb) {
151
- const gaxOptions = typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
152
- const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
153
- const [schema, table] = this.name.includes('.')
154
- ? this.name.split('.')
155
- : [null, this.name];
156
- let dropStatement = 'DROP TABLE `' + table + '`';
157
- const performDelete = async () => {
158
- const result = await this.database.getDatabaseDialect(gaxOptions);
159
- if (result && result.includes(POSTGRESQL)) {
160
- dropStatement = schema
161
- ? `DROP TABLE "${schema}"."${table}"`
162
- : `DROP TABLE "${table}"`;
163
- }
164
- else if (result && result.includes(GOOGLE_STANDARD_SQL)) {
165
- dropStatement = schema
166
- ? 'DROP TABLE `' + schema + '`.`' + table + '`'
167
- : dropStatement;
168
- }
169
- const updateSchemaResult = callback
170
- ? this.database.updateSchema(dropStatement, gaxOptions, callback)
171
- : this.database.updateSchema(dropStatement, gaxOptions);
172
- return updateSchemaResult;
173
- };
174
- if (!callback) {
175
- return performDelete();
176
- }
177
- else {
178
- performDelete();
179
- }
180
- }
181
- deleteRows(keys, optionsOrCallback, cb) {
182
- const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
183
- const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
184
- return this._mutate('deleteRows', keys, options, callback);
185
- }
186
- drop(gaxOptionsOrCallback, cb) {
187
- const gaxOptions = typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
188
- const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
189
- return this.delete(gaxOptions, callback);
190
- }
191
- insert(rows, optionsOrCallback, cb) {
192
- const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
193
- const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
194
- this._mutate('insert', rows, options, callback);
195
- }
196
- read(request, optionsOrCallback, cb) {
197
- const rows = [];
198
- const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
199
- const options = typeof optionsOrCallback === 'object'
200
- ? optionsOrCallback
201
- : {};
202
- this.createReadStream(request, options)
203
- .on('error', callback)
204
- .on('data', (row) => rows.push(row))
205
- .on('end', () => callback(null, rows));
206
- }
207
- replace(rows, optionsOrCallback, cb) {
208
- const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
209
- const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
210
- this._mutate('replace', rows, options, callback);
211
- }
212
- update(rows, optionsOrCallback, cb) {
213
- const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
214
- const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
215
- this._mutate('update', rows, options, callback);
216
- }
217
- upsert(rows, optionsOrCallback, cb) {
218
- const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
219
- const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
220
- this._mutate('upsert', rows, options, callback);
221
- }
222
- /**
223
- * Creates a new transaction and applies the desired mutation via
224
- * {@link Transaction#commit}.
225
- *
226
- * @see [Commit API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.Commit)
227
- *
228
- * @private
229
- *
230
- * @param {string} method CRUD method (insert, update, etc.).
231
- * @param {object|object[]} rows A map of names to values of data to insert
232
- * into this table.
233
- * @param {function} callback The callback function.
234
- */
235
- _mutate(method, rows, options = {}, callback) {
236
- const traceConfig = {
237
- opts: this._observabilityOptions,
238
- tableName: this.name,
239
- dbName: this.getDBName(),
240
- };
241
- (0, instrument_1.startTrace)('Table.' + method, traceConfig, span => {
242
- const requestOptions = 'requestOptions' in options ? options.requestOptions : {};
243
- const excludeTxnFromChangeStreams = 'excludeTxnFromChangeStreams' in options
244
- ? options.excludeTxnFromChangeStreams
245
- : false;
246
- this.database.runTransaction({
247
- requestOptions: requestOptions,
248
- excludeTxnFromChangeStreams: excludeTxnFromChangeStreams,
249
- }, (err, transaction) => {
250
- if (err) {
251
- (0, instrument_1.setSpanError)(span, err);
252
- span.end();
253
- callback(err);
254
- return;
255
- }
256
- transaction[method](this.name, rows);
257
- transaction.commit(options, (err, resp) => {
258
- if (err) {
259
- (0, instrument_1.setSpanError)(span, err);
260
- }
261
- span.end();
262
- callback(err, resp);
263
- });
264
- });
265
- });
266
- }
267
- }
268
- exports.Table = Table;
269
- /*! Developer Documentation
270
- *
271
- * All async methods (except for streams) will return a Promise in the event
272
- * that a callback is omitted.
273
- */
274
- (0, promisify_1.promisifyAll)(Table, {
275
- exclude: ['delete', 'drop'],
276
- });
277
- //# sourceMappingURL=table.js.map
@@ -1,185 +0,0 @@
1
- /*!
2
- * Copyright 2019 Google Inc. 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 { grpc } from 'google-gax';
17
- import { Session } from './session';
18
- import { Transaction } from './transaction';
19
- import { NormalCallback } from './common';
20
- import { google } from '../protos/protos';
21
- import IRequestOptions = google.spanner.v1.IRequestOptions;
22
- /**
23
- * @typedef {object} RunTransactionOptions
24
- * @property {number} [timeout] The maximum amount of time (in ms) that a
25
- * {@link Transaction} should be ran for.
26
- */
27
- export interface RunTransactionOptions {
28
- timeout?: number;
29
- requestOptions?: Pick<IRequestOptions, 'transactionTag'>;
30
- optimisticLock?: boolean;
31
- excludeTxnFromChangeStreams?: boolean;
32
- }
33
- /**
34
- * A function to execute in the context of a transaction.
35
- * @callback RunTransactionCallback
36
- * @param {?Error} err An error returned while making this request.
37
- * @param {Transaction} transaction The transaction object. The transaction has
38
- * already been created, and is ready to be queried and committed against.
39
- */
40
- export type RunTransactionCallback = NormalCallback<Transaction>;
41
- /**
42
- * A function to execute in the context of a transaction.
43
- * @callback AsyncRunTransactionCallback
44
- * @param {Transaction} transaction The transaction object. The transaction has
45
- * already been created, and is ready to be queried and committed against.
46
- */
47
- export interface AsyncRunTransactionCallback<T> {
48
- (transaction: Transaction): Promise<T>;
49
- }
50
- /**
51
- * Error class used to signal a Transaction timeout.
52
- *
53
- * @private
54
- * @class
55
- *
56
- * @param {Error} [err] The last known retryable Error.
57
- */
58
- export declare class DeadlineError extends Error implements grpc.ServiceError {
59
- code: grpc.status;
60
- details: string;
61
- metadata: grpc.Metadata;
62
- errors: grpc.ServiceError[];
63
- constructor(error?: grpc.ServiceError);
64
- }
65
- /**
66
- * Base class for running/retrying Transactions.
67
- *
68
- * @private
69
- * @class
70
- * @abstract
71
- *
72
- * @param {Database} database The Database to pull Sessions/Transactions from.
73
- * @param {RunTransactionOptions} [options] The runner options.
74
- */
75
- export declare abstract class Runner<T> {
76
- abstract runFn: Function;
77
- attempts: number;
78
- session: Session;
79
- transaction?: Transaction;
80
- options: RunTransactionOptions;
81
- constructor(session: Session, transaction: Transaction, options?: RunTransactionOptions);
82
- /**
83
- * Runs the user function against the provided transaction. Resolving the
84
- * returned Promise upon completion/error.
85
- *
86
- * @private
87
- *
88
- * @param {Transaction} transaction The transaction to run against.
89
- * @returns {Promise}
90
- */
91
- protected abstract _run(transaction: Transaction): Promise<T>;
92
- /**
93
- * Attempts to retrieve the retry delay from the supplied error. If absent it
94
- * will create one based on the number of attempts made thus far.
95
- *
96
- * @private
97
- *
98
- * @param {Error} err The service error.
99
- * @returns {number} Delay in milliseconds.
100
- */
101
- getNextDelay(err: grpc.ServiceError): number;
102
- /** Returns whether the given error should cause a transaction retry. */
103
- shouldRetry(err: grpc.ServiceError): boolean;
104
- /**
105
- * Retrieves a transaction to run against.
106
- *
107
- * @private
108
- *
109
- * @returns Promise<Transaction>
110
- */
111
- getTransaction(): Promise<Transaction>;
112
- /**
113
- * This function is responsible for getting transactions, running them and
114
- * handling any errors, retrying if necessary.
115
- *
116
- * @private
117
- *
118
- * @returns {Promise}
119
- */
120
- run(): Promise<T>;
121
- }
122
- /**
123
- * This class handles transactions expecting to be ran in callback mode.
124
- *
125
- * @private
126
- * @class
127
- *
128
- * @param {Database} database The database to pull sessions/transactions from.
129
- * @param {RunTransactionCallback} runFn The user supplied run function.
130
- * @param {RunTransactionOptions} [options] Runner options.
131
- */
132
- export declare class TransactionRunner extends Runner<void> {
133
- runFn: RunTransactionCallback;
134
- constructor(session: Session, transaction: Transaction, runFn: RunTransactionCallback, options?: RunTransactionOptions);
135
- /**
136
- * Because the user has decided to use callback mode, we want to try and
137
- * intercept any ABORTED or UNKNOWN errors and stop the current function
138
- * execution.
139
- *
140
- * @private
141
- *
142
- * @param {Transaction} transaction The transaction to intercept errors for.
143
- * @param {Function} reject Function to call when a retryable error is found.
144
- */
145
- private _interceptErrors;
146
- /**
147
- * Creates a Promise that should resolve when the provided transaction has
148
- * been committed or rolled back. Rejects if a retryable error occurs.
149
- *
150
- * @private
151
- *
152
- * @param {Transaction}
153
- * @returns {Promise}
154
- */
155
- protected _run(transaction: Transaction): Promise<void>;
156
- }
157
- /**
158
- * This class handles transactions expecting to be ran in promise mode.
159
- *
160
- * @private
161
- * @class
162
- *
163
- * @param {Database} database The database to pull sessions/transactions from.
164
- * @param {AsyncRunTransactionCallback} runFn The user supplied run function.
165
- * @param {RunTransactionOptions} [options] Runner options.
166
- */
167
- export declare class AsyncTransactionRunner<T> extends Runner<T> {
168
- runFn: AsyncRunTransactionCallback<T>;
169
- constructor(session: Session, transaction: Transaction, runFn: AsyncRunTransactionCallback<T>, options?: RunTransactionOptions);
170
- /**
171
- * Since this is promise mode all we need to do is return the user function.
172
- *
173
- * @private
174
- *
175
- * @param {Transaction} transaction The transaction to be ran against.
176
- * @returns {Promise}
177
- */
178
- protected _run(transaction: Transaction): Promise<T>;
179
- }
180
- /**
181
- * Checks whether the given error is a retryable internal error.
182
- * @param error the error to check
183
- * @return true if the error is a retryable internal error, and otherwise false.
184
- */
185
- export declare function isRetryableInternalError(err: grpc.ServiceError): boolean;