@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.
- package/CHANGELOG.md +30 -0
- package/README.md +1 -0
- package/build/protos/google/spanner/admin/database/v1/backup.proto +773 -0
- package/build/protos/google/spanner/admin/database/v1/backup_schedule.proto +230 -0
- package/build/protos/google/spanner/admin/database/v1/common.proto +132 -0
- package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +1279 -0
- package/build/protos/google/spanner/admin/instance/v1/common.proto +64 -0
- package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +2110 -0
- package/build/protos/google/spanner/executor/v1/cloud_executor.proto +1520 -0
- package/build/protos/google/spanner/v1/commit_response.proto +59 -0
- package/build/protos/google/spanner/v1/keys.proto +163 -0
- package/build/protos/google/spanner/v1/mutation.proto +107 -0
- package/build/protos/google/spanner/v1/query_plan.proto +128 -0
- package/build/protos/google/spanner/v1/result_set.proto +237 -0
- package/build/protos/google/spanner/v1/spanner.proto +1389 -0
- package/build/protos/google/spanner/v1/transaction.proto +622 -0
- package/build/protos/google/spanner/v1/type.proto +214 -0
- package/build/protos/protos.d.ts +39869 -0
- package/build/protos/protos.js +101659 -0
- package/build/protos/protos.json +10391 -0
- package/build/src/backup.d.ts +349 -0
- package/build/src/backup.js +246 -0
- package/build/src/batch-transaction.d.ts +247 -0
- package/build/src/batch-transaction.js +384 -0
- package/build/src/codec.d.ts +362 -0
- package/build/src/codec.js +791 -0
- package/build/src/common-grpc/service-object.d.ts +80 -0
- package/build/src/common-grpc/service-object.js +101 -0
- package/build/src/common-grpc/service.d.ts +445 -0
- package/build/src/common-grpc/service.js +826 -0
- package/build/src/common.d.ts +66 -0
- package/build/src/common.js +54 -0
- package/build/src/database.d.ts +2103 -0
- package/build/src/database.js +1660 -0
- package/build/src/extra_proto_list.json +1 -0
- package/build/src/helper.d.ts +45 -0
- package/build/src/helper.js +71 -0
- package/build/src/index.d.ts +1195 -0
- package/build/src/index.js +1059 -0
- package/build/src/instance-config.d.ts +294 -0
- package/build/src/instance-config.js +216 -0
- package/build/src/instance.d.ts +832 -0
- package/build/src/instance.js +781 -0
- package/build/src/instrument.d.ts +85 -0
- package/build/src/instrument.js +215 -0
- package/build/src/multiplexed-session.d.ts +135 -0
- package/build/src/multiplexed-session.js +194 -0
- package/build/src/partial-result-stream.d.ts +253 -0
- package/build/src/partial-result-stream.js +400 -0
- package/build/src/request_id_header.d.ts +41 -0
- package/build/src/request_id_header.js +138 -0
- package/build/src/session-factory.d.ts +115 -0
- package/build/src/session-factory.js +106 -0
- package/build/src/session-pool.d.ts +471 -0
- package/build/src/session-pool.js +765 -0
- package/build/src/session.d.ts +258 -0
- package/build/src/session.js +348 -0
- package/build/src/spanner_grpc_config.json +92 -0
- package/build/src/table.d.ts +831 -0
- package/build/src/table.js +277 -0
- package/build/src/transaction-runner.d.ts +185 -0
- package/build/src/transaction-runner.js +282 -0
- package/build/src/transaction.d.ts +1691 -0
- package/build/src/transaction.js +2003 -0
- package/build/src/v1/database_admin_client.d.ts +2332 -0
- package/build/src/v1/database_admin_client.js +2364 -0
- package/build/src/v1/database_admin_client_config.json +165 -0
- package/build/src/v1/database_admin_proto_list.json +6 -0
- package/build/src/v1/gapic_metadata.json +27 -0
- package/build/src/v1/index.d.ts +4 -0
- package/build/src/v1/index.js +29 -0
- package/build/src/v1/instance_admin_client.d.ts +1985 -0
- package/build/src/v1/instance_admin_client.js +1768 -0
- package/build/src/v1/instance_admin_client_config.json +129 -0
- package/build/src/v1/instance_admin_proto_list.json +4 -0
- package/build/src/v1/spanner_client.d.ts +1250 -0
- package/build/src/v1/spanner_client.js +1086 -0
- package/build/src/v1/spanner_client_config.json +119 -0
- package/build/src/v1/spanner_executor_proxy_client.d.ts +418 -0
- package/build/src/v1/spanner_executor_proxy_client.js +706 -0
- package/build/src/v1/spanner_executor_proxy_client_config.json +30 -0
- package/build/src/v1/spanner_executor_proxy_proto_list.json +14 -0
- package/build/src/v1/spanner_proto_list.json +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,277 @@
|
|
|
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
|
|
@@ -0,0 +1,185 @@
|
|
|
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;
|