@google-cloud/spanner 5.17.0 → 6.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.
- package/CHANGELOG.md +53 -0
- package/README.md +16 -0
- package/build/protos/google/spanner/admin/database/v1/backup.proto +174 -9
- package/build/protos/google/spanner/admin/database/v1/common.proto +1 -2
- package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +27 -2
- package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +22 -10
- package/build/protos/google/spanner/v1/commit_response.proto +1 -3
- package/build/protos/google/spanner/v1/keys.proto +1 -2
- package/build/protos/google/spanner/v1/mutation.proto +1 -2
- package/build/protos/google/spanner/v1/query_plan.proto +1 -2
- package/build/protos/google/spanner/v1/result_set.proto +1 -3
- package/build/protos/google/spanner/v1/spanner.proto +4 -1
- package/build/protos/google/spanner/v1/transaction.proto +73 -22
- package/build/protos/google/spanner/v1/type.proto +1 -2
- package/build/protos/protos.d.ts +883 -282
- package/build/protos/protos.js +2447 -880
- package/build/protos/protos.json +297 -87
- package/build/src/backup.d.ts +27 -5
- package/build/src/backup.js +62 -31
- package/build/src/batch-transaction.js +1 -1
- package/build/src/codec.d.ts +12 -1
- package/build/src/codec.js +44 -13
- package/build/src/common-grpc/service-object.js +1 -1
- package/build/src/common-grpc/service.js +2 -2
- package/build/src/database.d.ts +26 -6
- package/build/src/database.js +8 -8
- package/build/src/index.d.ts +18 -3
- package/build/src/index.js +26 -7
- package/build/src/instance.d.ts +41 -1
- package/build/src/instance.js +56 -2
- package/build/src/session-pool.d.ts +1 -0
- package/build/src/session-pool.js +46 -46
- package/build/src/session.js +1 -1
- package/build/src/table.d.ts +5 -1
- package/build/src/table.js +1 -1
- package/build/src/transaction-runner.js +3 -3
- package/build/src/transaction.d.ts +10 -2
- package/build/src/transaction.js +12 -12
- package/build/src/v1/database_admin_client.d.ts +267 -30
- package/build/src/v1/database_admin_client.js +148 -13
- package/build/src/v1/database_admin_client_config.json +5 -0
- package/build/src/v1/index.js +1 -0
- package/build/src/v1/instance_admin_client.d.ts +63 -18
- package/build/src/v1/instance_admin_client.js +42 -9
- package/build/src/v1/spanner_client.d.ts +70 -19
- package/build/src/v1/spanner_client.js +7 -8
- package/package.json +12 -12
|
@@ -65,7 +65,7 @@ exports.SessionLeakError = SessionLeakError;
|
|
|
65
65
|
*/
|
|
66
66
|
class SessionPoolExhaustedError extends google_gax_1.GoogleError {
|
|
67
67
|
constructor(leaks) {
|
|
68
|
-
super("No resources available." /* Exhausted */);
|
|
68
|
+
super("No resources available." /* errors.Exhausted */);
|
|
69
69
|
// Restore error name that was overwritten by the super constructor call.
|
|
70
70
|
this.name = SessionPoolExhaustedError.name;
|
|
71
71
|
this.messages = leaks;
|
|
@@ -168,13 +168,13 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
168
168
|
throw new TypeError('Write percentage should be represented as a float between 0.0 and 1.0.');
|
|
169
169
|
}
|
|
170
170
|
this._inventory = {
|
|
171
|
-
["readonly" /* ReadOnly */]: [],
|
|
172
|
-
["readwrite" /* ReadWrite */]: [],
|
|
171
|
+
["readonly" /* types.ReadOnly */]: [],
|
|
172
|
+
["readwrite" /* types.ReadWrite */]: [],
|
|
173
173
|
borrowed: new Set(),
|
|
174
174
|
};
|
|
175
175
|
this._waiters = {
|
|
176
|
-
["readonly" /* ReadOnly */]: 0,
|
|
177
|
-
["readwrite" /* ReadWrite */]: 0,
|
|
176
|
+
["readonly" /* types.ReadOnly */]: 0,
|
|
177
|
+
["readwrite" /* types.ReadWrite */]: 0,
|
|
178
178
|
};
|
|
179
179
|
this._requests = new p_queue_1.default({
|
|
180
180
|
concurrency: this.options.concurrency,
|
|
@@ -205,8 +205,8 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
205
205
|
* @type {number}
|
|
206
206
|
*/
|
|
207
207
|
get available() {
|
|
208
|
-
const reads = this._inventory["readonly" /* ReadOnly */];
|
|
209
|
-
const writes = this._inventory["readwrite" /* ReadWrite */];
|
|
208
|
+
const reads = this._inventory["readonly" /* types.ReadOnly */];
|
|
209
|
+
const writes = this._inventory["readwrite" /* types.ReadWrite */];
|
|
210
210
|
return reads.length + writes.length;
|
|
211
211
|
}
|
|
212
212
|
/**
|
|
@@ -221,7 +221,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
221
221
|
// otherwise be a read-only session.
|
|
222
222
|
return 0.5;
|
|
223
223
|
}
|
|
224
|
-
const writes = this._inventory["readwrite" /* ReadWrite */].length + this.pendingPrepare;
|
|
224
|
+
const writes = this._inventory["readwrite" /* types.ReadWrite */].length + this.pendingPrepare;
|
|
225
225
|
return writes / (this.available + this.pendingPrepare);
|
|
226
226
|
}
|
|
227
227
|
/**
|
|
@@ -243,8 +243,8 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
243
243
|
* @type {number}
|
|
244
244
|
*/
|
|
245
245
|
get reads() {
|
|
246
|
-
const available = this._inventory["readonly" /* ReadOnly */].length;
|
|
247
|
-
const borrowed = [...this._inventory.borrowed].filter(session => session.type === "readonly" /* ReadOnly */).length;
|
|
246
|
+
const available = this._inventory["readonly" /* types.ReadOnly */].length;
|
|
247
|
+
const borrowed = [...this._inventory.borrowed].filter(session => session.type === "readonly" /* types.ReadOnly */).length;
|
|
248
248
|
return available + borrowed;
|
|
249
249
|
}
|
|
250
250
|
/**
|
|
@@ -259,8 +259,8 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
259
259
|
* @type {number}
|
|
260
260
|
*/
|
|
261
261
|
get writes() {
|
|
262
|
-
const available = this._inventory["readwrite" /* ReadWrite */].length;
|
|
263
|
-
const borrowed = [...this._inventory.borrowed].filter(session => session.type === "readwrite" /* ReadWrite */).length;
|
|
262
|
+
const available = this._inventory["readwrite" /* types.ReadWrite */].length;
|
|
263
|
+
const borrowed = [...this._inventory.borrowed].filter(session => session.type === "readwrite" /* types.ReadWrite */).length;
|
|
264
264
|
return available + borrowed;
|
|
265
265
|
}
|
|
266
266
|
/**
|
|
@@ -285,14 +285,14 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
285
285
|
* @type {number}
|
|
286
286
|
*/
|
|
287
287
|
get numReadWaiters() {
|
|
288
|
-
return this._waiters["readonly" /* ReadOnly */];
|
|
288
|
+
return this._waiters["readonly" /* types.ReadOnly */];
|
|
289
289
|
}
|
|
290
290
|
/**
|
|
291
291
|
* Current number of waiters for a read/write session.
|
|
292
292
|
* @type {number}
|
|
293
293
|
*/
|
|
294
294
|
get numWriteWaiters() {
|
|
295
|
-
return this._waiters["readwrite" /* ReadWrite */];
|
|
295
|
+
return this._waiters["readwrite" /* types.ReadWrite */];
|
|
296
296
|
}
|
|
297
297
|
/**
|
|
298
298
|
* Sum of read and write waiters.
|
|
@@ -309,8 +309,8 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
309
309
|
*/
|
|
310
310
|
close(callback) {
|
|
311
311
|
const sessions = [
|
|
312
|
-
...this._inventory["readonly" /* ReadOnly */],
|
|
313
|
-
...this._inventory["readwrite" /* ReadWrite */],
|
|
312
|
+
...this._inventory["readonly" /* types.ReadOnly */],
|
|
313
|
+
...this._inventory["readwrite" /* types.ReadWrite */],
|
|
314
314
|
...this._inventory.borrowed,
|
|
315
315
|
];
|
|
316
316
|
this.isOpen = false;
|
|
@@ -320,8 +320,8 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
320
320
|
this._requests.onIdle().then(() => {
|
|
321
321
|
const leaks = this._getLeaks();
|
|
322
322
|
let error;
|
|
323
|
-
this._inventory["readonly" /* ReadOnly */] = [];
|
|
324
|
-
this._inventory["readwrite" /* ReadWrite */] = [];
|
|
323
|
+
this._inventory["readonly" /* types.ReadOnly */] = [];
|
|
324
|
+
this._inventory["readwrite" /* types.ReadWrite */] = [];
|
|
325
325
|
this._inventory.borrowed.clear();
|
|
326
326
|
if (leaks.length) {
|
|
327
327
|
error = new SessionLeakError(leaks);
|
|
@@ -335,7 +335,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
335
335
|
* @param {GetReadSessionCallback} callback The callback function.
|
|
336
336
|
*/
|
|
337
337
|
getReadSession(callback) {
|
|
338
|
-
this._acquire("readonly" /* ReadOnly */).then(session => callback(null, session), callback);
|
|
338
|
+
this._acquire("readonly" /* types.ReadOnly */).then(session => callback(null, session), callback);
|
|
339
339
|
}
|
|
340
340
|
/**
|
|
341
341
|
* Retrieve a read/write session.
|
|
@@ -343,7 +343,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
343
343
|
* @param {GetWriteSessionCallback} callback The callback function.
|
|
344
344
|
*/
|
|
345
345
|
getWriteSession(callback) {
|
|
346
|
-
this._acquire("readwrite" /* ReadWrite */).then(session => callback(null, session, session.txn), callback);
|
|
346
|
+
this._acquire("readwrite" /* types.ReadWrite */).then(session => callback(null, session, session.txn), callback);
|
|
347
347
|
}
|
|
348
348
|
/**
|
|
349
349
|
* Opens the pool, filling it to the configured number of read and write
|
|
@@ -404,11 +404,11 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
404
404
|
// needs read/write sessions, and the pool should try to keep that number
|
|
405
405
|
// of read/write sessions dynamically.
|
|
406
406
|
// 3. The user has set a write fraction and that fraction has been reached.
|
|
407
|
-
const shouldBeWrite = (session.type === "readwrite" /* ReadWrite */ && this.options.writes === 0) ||
|
|
407
|
+
const shouldBeWrite = (session.type === "readwrite" /* types.ReadWrite */ && this.options.writes === 0) ||
|
|
408
408
|
(this.options.writes > 0 &&
|
|
409
409
|
this.currentWriteFraction < this.options.writes);
|
|
410
410
|
if (this.totalWaiters > this.available || !shouldBeWrite) {
|
|
411
|
-
session.type = "readonly" /* ReadOnly */;
|
|
411
|
+
session.type = "readonly" /* types.ReadOnly */;
|
|
412
412
|
this._release(session);
|
|
413
413
|
return;
|
|
414
414
|
}
|
|
@@ -417,9 +417,9 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
417
417
|
// the pool is closed while the session is being prepared.
|
|
418
418
|
this._traces.delete(session.id);
|
|
419
419
|
this._pendingPrepare++;
|
|
420
|
-
session.type = "readwrite" /* ReadWrite */;
|
|
420
|
+
session.type = "readwrite" /* types.ReadWrite */;
|
|
421
421
|
this._prepareTransaction(session)
|
|
422
|
-
.catch(() => (session.type = "readonly" /* ReadOnly */))
|
|
422
|
+
.catch(() => (session.type = "readonly" /* types.ReadOnly */))
|
|
423
423
|
.then(() => {
|
|
424
424
|
this._pendingPrepare--;
|
|
425
425
|
this._release(session);
|
|
@@ -435,7 +435,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
435
435
|
*/
|
|
436
436
|
async _acquire(type) {
|
|
437
437
|
if (!this.isOpen) {
|
|
438
|
-
throw new google_gax_1.GoogleError("Database is closed." /* Closed */);
|
|
438
|
+
throw new google_gax_1.GoogleError("Database is closed." /* errors.Closed */);
|
|
439
439
|
}
|
|
440
440
|
// Get the stacktrace of the caller before we call any async methods, as calling an async method will break the stacktrace.
|
|
441
441
|
const frames = trace.get();
|
|
@@ -446,7 +446,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
446
446
|
const getSession = async () => {
|
|
447
447
|
const elapsed = Date.now() - startTime;
|
|
448
448
|
if (elapsed >= timeout) {
|
|
449
|
-
throw new google_gax_1.GoogleError("Timeout occurred while acquiring session." /* Timeout */);
|
|
449
|
+
throw new google_gax_1.GoogleError("Timeout occurred while acquiring session." /* errors.Timeout */);
|
|
450
450
|
}
|
|
451
451
|
const session = await this._getSession(type, startTime);
|
|
452
452
|
if (this._isValidSession(session)) {
|
|
@@ -456,7 +456,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
456
456
|
return getSession();
|
|
457
457
|
};
|
|
458
458
|
const session = await this._acquires.add(getSession);
|
|
459
|
-
if (type === "readwrite" /* ReadWrite */ && session.type === "readonly" /* ReadOnly */) {
|
|
459
|
+
if (type === "readwrite" /* types.ReadWrite */ && session.type === "readonly" /* types.ReadOnly */) {
|
|
460
460
|
this._numInProcessPrepare++;
|
|
461
461
|
try {
|
|
462
462
|
await this._prepareTransaction(session);
|
|
@@ -515,15 +515,15 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
515
515
|
* @returns {Promise<Session>}
|
|
516
516
|
*/
|
|
517
517
|
_borrowNextAvailableSession(type) {
|
|
518
|
-
const hasReads = !!this._inventory["readonly" /* ReadOnly */].length;
|
|
519
|
-
if (type === "readonly" /* ReadOnly */ && hasReads) {
|
|
520
|
-
return this._borrowFrom("readonly" /* ReadOnly */);
|
|
518
|
+
const hasReads = !!this._inventory["readonly" /* types.ReadOnly */].length;
|
|
519
|
+
if (type === "readonly" /* types.ReadOnly */ && hasReads) {
|
|
520
|
+
return this._borrowFrom("readonly" /* types.ReadOnly */);
|
|
521
521
|
}
|
|
522
|
-
const hasWrites = !!this._inventory["readwrite" /* ReadWrite */].length;
|
|
522
|
+
const hasWrites = !!this._inventory["readwrite" /* types.ReadWrite */].length;
|
|
523
523
|
if (hasWrites) {
|
|
524
|
-
return this._borrowFrom("readwrite" /* ReadWrite */);
|
|
524
|
+
return this._borrowFrom("readwrite" /* types.ReadWrite */);
|
|
525
525
|
}
|
|
526
|
-
return this._borrowFrom("readonly" /* ReadOnly */);
|
|
526
|
+
return this._borrowFrom("readonly" /* types.ReadOnly */);
|
|
527
527
|
}
|
|
528
528
|
/**
|
|
529
529
|
* Attempts to create a single session of a certain type.
|
|
@@ -534,7 +534,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
534
534
|
* @returns {Promise}
|
|
535
535
|
*/
|
|
536
536
|
_createSession(type) {
|
|
537
|
-
const kind = type === "readonly" /* ReadOnly */ ? 'reads' : 'writes';
|
|
537
|
+
const kind = type === "readonly" /* types.ReadOnly */ ? 'reads' : 'writes';
|
|
538
538
|
const options = { [kind]: 1 };
|
|
539
539
|
return this._createSessions(options);
|
|
540
540
|
}
|
|
@@ -571,7 +571,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
571
571
|
throw e;
|
|
572
572
|
}
|
|
573
573
|
sessions.forEach((session) => {
|
|
574
|
-
session.type = writes-- > 0 ? "readwrite" /* ReadWrite */ : "readonly" /* ReadOnly */;
|
|
574
|
+
session.type = writes-- > 0 ? "readwrite" /* types.ReadWrite */ : "readonly" /* types.ReadOnly */;
|
|
575
575
|
setImmediate(() => {
|
|
576
576
|
this._inventory.borrowed.add(session);
|
|
577
577
|
this._pending -= 1;
|
|
@@ -647,8 +647,8 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
647
647
|
_getIdleSessions() {
|
|
648
648
|
const idlesAfter = this.options.idlesAfter * 60000;
|
|
649
649
|
const sessions = [
|
|
650
|
-
...this._inventory["readonly" /* ReadOnly */],
|
|
651
|
-
...this._inventory["readwrite" /* ReadWrite */],
|
|
650
|
+
...this._inventory["readonly" /* types.ReadOnly */],
|
|
651
|
+
...this._inventory["readwrite" /* types.ReadWrite */],
|
|
652
652
|
];
|
|
653
653
|
return sessions.filter(session => {
|
|
654
654
|
return Date.now() - session.lastUsed >= idlesAfter;
|
|
@@ -673,7 +673,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
673
673
|
*/
|
|
674
674
|
_hasSessionUsableFor(type) {
|
|
675
675
|
return (this._inventory[type].length > 0 ||
|
|
676
|
-
this._inventory["readwrite" /* ReadWrite */].length > 0);
|
|
676
|
+
this._inventory["readwrite" /* types.ReadWrite */].length > 0);
|
|
677
677
|
}
|
|
678
678
|
/**
|
|
679
679
|
* Attempts to get a session of a specific type. If the type is unavailable it
|
|
@@ -693,8 +693,8 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
693
693
|
// available, we should return that session unless there is a session
|
|
694
694
|
// currently being prepared for read/write that is not already claimed by
|
|
695
695
|
// another requester.
|
|
696
|
-
if (type === "readwrite" /* ReadWrite */ &&
|
|
697
|
-
this._hasSessionUsableFor("readonly" /* ReadOnly */) &&
|
|
696
|
+
if (type === "readwrite" /* types.ReadWrite */ &&
|
|
697
|
+
this._hasSessionUsableFor("readonly" /* types.ReadOnly */) &&
|
|
698
698
|
this.numWriteWaiters >= this.pendingPrepare) {
|
|
699
699
|
return this._borrowNextAvailableSession(type);
|
|
700
700
|
}
|
|
@@ -706,7 +706,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
706
706
|
const availableEvent = type + '-available';
|
|
707
707
|
const promises = [
|
|
708
708
|
this._onClose.then(() => {
|
|
709
|
-
throw new google_gax_1.GoogleError("Database is closed." /* Closed */);
|
|
709
|
+
throw new google_gax_1.GoogleError("Database is closed." /* errors.Closed */);
|
|
710
710
|
}),
|
|
711
711
|
new Promise(resolve => {
|
|
712
712
|
this.once(availableEvent, resolve);
|
|
@@ -719,7 +719,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
719
719
|
const elapsed = Date.now() - startTime;
|
|
720
720
|
const remaining = timeout - elapsed;
|
|
721
721
|
promises.push(new Promise((_, reject) => {
|
|
722
|
-
const error = new Error("Timeout occurred while acquiring session." /* Timeout */);
|
|
722
|
+
const error = new Error("Timeout occurred while acquiring session." /* errors.Timeout */);
|
|
723
723
|
const timeoutFunction = setTimeout(reject.bind(null, error), remaining);
|
|
724
724
|
removeTimeoutListener = () => clearTimeout(timeoutFunction);
|
|
725
725
|
}));
|
|
@@ -843,15 +843,15 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
843
843
|
this.emit('available');
|
|
844
844
|
// Determine the type of waiter to unblock.
|
|
845
845
|
let emitType;
|
|
846
|
-
if (type === "readonly" /* ReadOnly */ &&
|
|
846
|
+
if (type === "readonly" /* types.ReadOnly */ &&
|
|
847
847
|
!this.numReadWaiters &&
|
|
848
848
|
this.numWriteWaiters) {
|
|
849
|
-
emitType = "readwrite" /* ReadWrite */;
|
|
849
|
+
emitType = "readwrite" /* types.ReadWrite */;
|
|
850
850
|
}
|
|
851
|
-
else if (type === "readwrite" /* ReadWrite */ &&
|
|
851
|
+
else if (type === "readwrite" /* types.ReadWrite */ &&
|
|
852
852
|
!this.numWriteWaiters &&
|
|
853
853
|
this.numReadWaiters) {
|
|
854
|
-
emitType = "readonly" /* ReadOnly */;
|
|
854
|
+
emitType = "readonly" /* types.ReadOnly */;
|
|
855
855
|
}
|
|
856
856
|
else {
|
|
857
857
|
emitType = type;
|
package/build/src/session.js
CHANGED
|
@@ -324,7 +324,7 @@ exports.Session = Session;
|
|
|
324
324
|
* All async methods (except for streams) will return a Promise in the event
|
|
325
325
|
* that a callback is omitted.
|
|
326
326
|
*/
|
|
327
|
-
promisify_1.promisifyAll(Session, {
|
|
327
|
+
(0, promisify_1.promisifyAll)(Session, {
|
|
328
328
|
exclude: [
|
|
329
329
|
'delete',
|
|
330
330
|
'getMetadata',
|
package/build/src/table.d.ts
CHANGED
|
@@ -21,7 +21,11 @@ import { google as databaseAdmin } from '../protos/protos';
|
|
|
21
21
|
import { Schema, LongRunningCallback } from './common';
|
|
22
22
|
import IRequestOptions = databaseAdmin.spanner.v1.IRequestOptions;
|
|
23
23
|
export declare type Key = string | string[];
|
|
24
|
-
export declare type CreateTableResponse = [
|
|
24
|
+
export declare type CreateTableResponse = [
|
|
25
|
+
Table,
|
|
26
|
+
GaxOperation,
|
|
27
|
+
databaseAdmin.longrunning.IOperation
|
|
28
|
+
];
|
|
25
29
|
export declare type CreateTableCallback = LongRunningCallback<Table>;
|
|
26
30
|
export declare type DropTableResponse = UpdateSchemaResponse;
|
|
27
31
|
export declare type DropTableCallback = UpdateSchemaCallback;
|
package/build/src/table.js
CHANGED
|
@@ -217,7 +217,7 @@ exports.Table = Table;
|
|
|
217
217
|
* All async methods (except for streams) will return a Promise in the event
|
|
218
218
|
* that a callback is omitted.
|
|
219
219
|
*/
|
|
220
|
-
promisify_1.promisifyAll(Table, {
|
|
220
|
+
(0, promisify_1.promisifyAll)(Table, {
|
|
221
221
|
exclude: ['delete', 'drop'],
|
|
222
222
|
});
|
|
223
223
|
//# sourceMappingURL=table.js.map
|
|
@@ -90,7 +90,7 @@ class Runner {
|
|
|
90
90
|
}
|
|
91
91
|
// A 'Session not found' error without any specific retry info should not
|
|
92
92
|
// cause any delay between retries.
|
|
93
|
-
if (session_pool_1.isSessionNotFoundError(err)) {
|
|
93
|
+
if ((0, session_pool_1.isSessionNotFoundError)(err)) {
|
|
94
94
|
return 0;
|
|
95
95
|
}
|
|
96
96
|
// Max backoff should be 32 seconds.
|
|
@@ -99,7 +99,7 @@ class Runner {
|
|
|
99
99
|
}
|
|
100
100
|
/** Returns whether the given error should cause a transaction retry. */
|
|
101
101
|
shouldRetry(err) {
|
|
102
|
-
return RETRYABLE.includes(err.code) || session_pool_1.isSessionNotFoundError(err);
|
|
102
|
+
return RETRYABLE.includes(err.code) || (0, session_pool_1.isSessionNotFoundError)(err);
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* Retrieves a transaction to run against.
|
|
@@ -182,7 +182,7 @@ class TransactionRunner extends Runner {
|
|
|
182
182
|
*/
|
|
183
183
|
_interceptErrors(transaction, reject) {
|
|
184
184
|
const request = transaction.request;
|
|
185
|
-
transaction.request = promisify_1.promisify((config, callback) => {
|
|
185
|
+
transaction.request = (0, promisify_1.promisify)((config, callback) => {
|
|
186
186
|
request(config, (err, resp) => {
|
|
187
187
|
if (!err || !this.shouldRetry(err)) {
|
|
188
188
|
callback(err, resp);
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
/// <reference types="long" />
|
|
17
17
|
/// <reference types="node" />
|
|
18
|
+
/// <reference types="node" />
|
|
18
19
|
import { PreciseDate } from '@google-cloud/precise-date';
|
|
19
20
|
import { EventEmitter } from 'events';
|
|
20
21
|
import { grpc, CallOptions } from 'google-gax';
|
|
@@ -88,12 +89,19 @@ export interface BatchUpdateError extends grpc.ServiceError {
|
|
|
88
89
|
rowCounts: number[];
|
|
89
90
|
}
|
|
90
91
|
export declare type CommitRequest = spannerClient.spanner.v1.ICommitRequest;
|
|
91
|
-
export declare type BatchUpdateResponse = [
|
|
92
|
+
export declare type BatchUpdateResponse = [
|
|
93
|
+
number[],
|
|
94
|
+
spannerClient.spanner.v1.ExecuteBatchDmlResponse
|
|
95
|
+
];
|
|
92
96
|
export declare type BeginResponse = [spannerClient.spanner.v1.ITransaction];
|
|
93
97
|
export declare type BeginTransactionCallback = NormalCallback<spannerClient.spanner.v1.ITransaction>;
|
|
94
98
|
export declare type CommitResponse = [spannerClient.spanner.v1.ICommitResponse];
|
|
95
99
|
export declare type ReadResponse = [Rows];
|
|
96
|
-
export declare type RunResponse = [
|
|
100
|
+
export declare type RunResponse = [
|
|
101
|
+
Rows,
|
|
102
|
+
spannerClient.spanner.v1.ResultSetStats,
|
|
103
|
+
spannerClient.spanner.v1.ResultSetMetadata
|
|
104
|
+
];
|
|
97
105
|
export declare type RunUpdateResponse = [number];
|
|
98
106
|
export interface BatchUpdateOptions {
|
|
99
107
|
requestOptions?: Omit<IRequestOptions, 'transactionTag'>;
|
package/build/src/transaction.js
CHANGED
|
@@ -346,7 +346,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
346
346
|
* ```
|
|
347
347
|
*/
|
|
348
348
|
createReadStream(table, request = {}) {
|
|
349
|
-
var _a;
|
|
349
|
+
var _a, _b;
|
|
350
350
|
const { gaxOptions, json, jsonOptions, maxResumeRetries, requestOptions } = request;
|
|
351
351
|
const keySet = Snapshot.encodeKeySet(request);
|
|
352
352
|
const transaction = {};
|
|
@@ -366,7 +366,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
366
366
|
delete request.requestOptions;
|
|
367
367
|
const reqOpts = Object.assign(request, {
|
|
368
368
|
session: this.session.formattedName_,
|
|
369
|
-
requestOptions: this.configureTagOptions(typeof transaction.singleUse !== 'undefined', (_a = this.requestOptions) === null || _a === void 0 ? void 0 : _a.transactionTag, requestOptions),
|
|
369
|
+
requestOptions: this.configureTagOptions(typeof transaction.singleUse !== 'undefined', (_b = (_a = this.requestOptions) === null || _a === void 0 ? void 0 : _a.transactionTag) !== null && _b !== void 0 ? _b : undefined, requestOptions),
|
|
370
370
|
transaction,
|
|
371
371
|
table,
|
|
372
372
|
keySet,
|
|
@@ -380,7 +380,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
380
380
|
headers: this.resourceHeader_,
|
|
381
381
|
});
|
|
382
382
|
};
|
|
383
|
-
return partial_result_stream_1.partialResultStream(makeRequest, {
|
|
383
|
+
return (0, partial_result_stream_1.partialResultStream)(makeRequest, {
|
|
384
384
|
json,
|
|
385
385
|
jsonOptions,
|
|
386
386
|
maxResumeRetries,
|
|
@@ -576,7 +576,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
576
576
|
const { gaxOptions, json, jsonOptions, maxResumeRetries, requestOptions } = query;
|
|
577
577
|
let reqOpts;
|
|
578
578
|
const sanitizeRequest = () => {
|
|
579
|
-
var _a;
|
|
579
|
+
var _a, _b;
|
|
580
580
|
query = query;
|
|
581
581
|
const { params, paramTypes } = Snapshot.encodeParams(query);
|
|
582
582
|
const transaction = {};
|
|
@@ -595,7 +595,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
595
595
|
reqOpts = Object.assign(query, {
|
|
596
596
|
session: this.session.formattedName_,
|
|
597
597
|
seqno: this._seqno++,
|
|
598
|
-
requestOptions: this.configureTagOptions(typeof transaction.singleUse !== 'undefined', (_a = this.requestOptions) === null || _a === void 0 ? void 0 : _a.transactionTag, requestOptions),
|
|
598
|
+
requestOptions: this.configureTagOptions(typeof transaction.singleUse !== 'undefined', (_b = (_a = this.requestOptions) === null || _a === void 0 ? void 0 : _a.transactionTag) !== null && _b !== void 0 ? _b : undefined, requestOptions),
|
|
599
599
|
transaction,
|
|
600
600
|
params,
|
|
601
601
|
paramTypes,
|
|
@@ -620,7 +620,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
620
620
|
headers: this.resourceHeader_,
|
|
621
621
|
});
|
|
622
622
|
};
|
|
623
|
-
return partial_result_stream_1.partialResultStream(makeRequest, {
|
|
623
|
+
return (0, partial_result_stream_1.partialResultStream)(makeRequest, {
|
|
624
624
|
json,
|
|
625
625
|
jsonOptions,
|
|
626
626
|
maxResumeRetries,
|
|
@@ -735,7 +735,7 @@ exports.Snapshot = Snapshot;
|
|
|
735
735
|
* All async methods (except for streams) return a Promise in the event
|
|
736
736
|
* that a callback is omitted.
|
|
737
737
|
*/
|
|
738
|
-
promisify_1.promisifyAll(Snapshot, {
|
|
738
|
+
(0, promisify_1.promisifyAll)(Snapshot, {
|
|
739
739
|
exclude: ['configureTagOptions', 'end'],
|
|
740
740
|
});
|
|
741
741
|
/**
|
|
@@ -765,7 +765,7 @@ exports.Dml = Dml;
|
|
|
765
765
|
* All async methods (except for streams) return a Promise in the event
|
|
766
766
|
* that a callback is omitted.
|
|
767
767
|
*/
|
|
768
|
-
promisify_1.promisifyAll(Dml);
|
|
768
|
+
(0, promisify_1.promisifyAll)(Dml);
|
|
769
769
|
/**
|
|
770
770
|
* This type of transaction is the only way to write data into Cloud Spanner.
|
|
771
771
|
* These transactions rely on pessimistic locking and, if necessary, two-phase
|
|
@@ -859,7 +859,7 @@ class Transaction extends Dml {
|
|
|
859
859
|
this.requestOptions = requestOptions;
|
|
860
860
|
}
|
|
861
861
|
batchUpdate(queries, optionsOrCallback, cb) {
|
|
862
|
-
var _a;
|
|
862
|
+
var _a, _b;
|
|
863
863
|
const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
864
864
|
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
865
865
|
const gaxOpts = 'gaxOptions' in options
|
|
@@ -885,7 +885,7 @@ class Transaction extends Dml {
|
|
|
885
885
|
});
|
|
886
886
|
const reqOpts = {
|
|
887
887
|
session: this.session.formattedName_,
|
|
888
|
-
requestOptions: this.configureTagOptions(false, (_a = this.requestOptions) === null || _a === void 0 ? void 0 : _a.transactionTag, options.requestOptions),
|
|
888
|
+
requestOptions: this.configureTagOptions(false, (_b = (_a = this.requestOptions) === null || _a === void 0 ? void 0 : _a.transactionTag) !== null && _b !== void 0 ? _b : undefined, options.requestOptions),
|
|
889
889
|
transaction: { id: this.id },
|
|
890
890
|
seqno: this._seqno++,
|
|
891
891
|
statements,
|
|
@@ -1346,7 +1346,7 @@ exports.Transaction = Transaction;
|
|
|
1346
1346
|
* All async methods (except for streams) return a Promise in the event
|
|
1347
1347
|
* that a callback is omitted.
|
|
1348
1348
|
*/
|
|
1349
|
-
promisify_1.promisifyAll(Transaction, {
|
|
1349
|
+
(0, promisify_1.promisifyAll)(Transaction, {
|
|
1350
1350
|
exclude: ['deleteRows', 'insert', 'replace', 'update', 'upsert'],
|
|
1351
1351
|
});
|
|
1352
1352
|
/**
|
|
@@ -1381,5 +1381,5 @@ exports.PartitionedDml = PartitionedDml;
|
|
|
1381
1381
|
* All async methods (except for streams) return a Promise in the event
|
|
1382
1382
|
* that a callback is omitted.
|
|
1383
1383
|
*/
|
|
1384
|
-
promisify_1.promisifyAll(PartitionedDml);
|
|
1384
|
+
(0, promisify_1.promisifyAll)(PartitionedDml);
|
|
1385
1385
|
//# sourceMappingURL=transaction.js.map
|