@google-cloud/spanner 6.4.0 → 6.6.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.
@@ -18,7 +18,7 @@
18
18
  import { EventEmitter } from 'events';
19
19
  import PQueue from 'p-queue';
20
20
  import { Database } from './database';
21
- import { Session, types } from './session';
21
+ import { Session } from './session';
22
22
  import { Transaction } from './transaction';
23
23
  import { NormalCallback } from './common';
24
24
  import { GoogleError, grpc } from 'google-gax';
@@ -30,19 +30,19 @@ import trace = require('stack-trace');
30
30
  export interface SessionPoolCloseCallback {
31
31
  (error?: SessionLeakError): void;
32
32
  }
33
+ /** @deprecated. Use GetSessionCallback instead. */
34
+ export type GetReadSessionCallback = NormalCallback<Session>;
35
+ /** @deprecated. Use GetSessionCallback instead. */
36
+ export interface GetWriteSessionCallback {
37
+ (err: Error | null, session?: Session | null, transaction?: Transaction | null): void;
38
+ }
33
39
  /**
34
- * @callback GetReadSessionCallback
35
- * @param {?Error} error Request error, if any.
36
- * @param {Session} session The read-only session.
37
- */
38
- export declare type GetReadSessionCallback = NormalCallback<Session>;
39
- /**
40
- * @callback GetWriteSessionCallback
40
+ * @callback GetSessionCallback
41
41
  * @param {?Error} error Request error, if any.
42
42
  * @param {Session} session The read-write session.
43
43
  * @param {Transaction} transaction The transaction object.
44
44
  */
45
- export interface GetWriteSessionCallback {
45
+ export interface GetSessionCallback {
46
46
  (err: Error | null, session?: Session | null, transaction?: Transaction | null): void;
47
47
  }
48
48
  /**
@@ -72,14 +72,22 @@ export interface SessionPoolInterface extends EventEmitter {
72
72
  * @name SessionPoolInterface#open
73
73
  */
74
74
  /**
75
- * When called returns a read-only session.
75
+ * When called returns a session.
76
76
  *
77
+ * @name SessionPoolInterface#getSession
78
+ * @param {GetSessionCallback} callback The callback function.
79
+ */
80
+ /**
81
+ * When called returns a session.
82
+ *
83
+ * @deprecated Use getSession instead.
77
84
  * @name SessionPoolInterface#getReadSession
78
85
  * @param {GetReadSessionCallback} callback The callback function.
79
86
  */
80
87
  /**
81
- * When called returns a read-write session with prepared transaction.
88
+ * When called returns a session.
82
89
  *
90
+ * @deprecated Use getSession instead.
83
91
  * @name SessionPoolInterface#getWriteSession
84
92
  * @param {GetWriteSessionCallback} callback The callback function.
85
93
  */
@@ -91,6 +99,7 @@ export interface SessionPoolInterface extends EventEmitter {
91
99
  */
92
100
  close(callback: SessionPoolCloseCallback): void;
93
101
  open(): void;
102
+ getSession(callback: GetSessionCallback): void;
94
103
  getReadSession(callback: GetReadSessionCallback): void;
95
104
  getWriteSession(callback: GetWriteSessionCallback): void;
96
105
  release(session: Session): void;
@@ -118,8 +127,7 @@ export interface SessionPoolInterface extends EventEmitter {
118
127
  * the pool at any given time.
119
128
  * @property {number} [min=0] Minimum number of resources to keep in the pool at
120
129
  * any given time.
121
- * @property {number} [writes=0.0] Percentage of sessions to be pre-allocated as
122
- * write sessions represented as a float.
130
+ * @property {number} [writes=0.0]. Deprecated.
123
131
  * @property {number} [incStep=25] The number of new sessions to create when at
124
132
  * least one more session is needed.
125
133
  */
@@ -135,8 +143,13 @@ export interface SessionPoolOptions {
135
143
  max?: number;
136
144
  maxIdle?: number;
137
145
  min?: number;
146
+ /**
147
+ * @deprecated. Starting from v6.5.0 the same session can be reused for
148
+ * different types of transactions.
149
+ */
138
150
  writes?: number;
139
151
  incStep?: number;
152
+ databaseRole?: string | null;
140
153
  }
141
154
  /**
142
155
  * Error to be thrown when attempting to release unknown resources.
@@ -200,14 +213,10 @@ export declare function isDefaultCredentialsNotSetError(error: grpc.ServiceError
200
213
  */
201
214
  export declare function isProjectIdNotSetInEnvironmentError(error: grpc.ServiceError | undefined): boolean;
202
215
  interface SessionInventory {
203
- [types.ReadOnly]: Session[];
204
- [types.ReadWrite]: Session[];
216
+ sessions: Session[];
205
217
  borrowed: Set<Session>;
206
218
  }
207
- interface Waiters {
208
- [types.ReadOnly]: number;
209
- [types.ReadWrite]: number;
210
- }
219
+ /** @deprecated. */
211
220
  export interface CreateSessionsOptions {
212
221
  writes?: number;
213
222
  reads?: number;
@@ -230,9 +239,7 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
230
239
  _inventory: SessionInventory;
231
240
  _onClose: Promise<void>;
232
241
  _pending: number;
233
- _pendingPrepare: number;
234
- _waiters: Waiters;
235
- _numInProcessPrepare: number;
242
+ _waiters: number;
236
243
  _pingHandle: NodeJS.Timer;
237
244
  _requests: PQueue;
238
245
  _traces: Map<string, trace.StackFrame[]>;
@@ -248,9 +255,8 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
248
255
  * @type {number}
249
256
  */
250
257
  get available(): number;
251
- /**
252
- * Current fraction of write-prepared sessions in the pool.
253
- * @type {number}
258
+ /** @deprecated Starting from v6.5.0 the same session can be reused for
259
+ * different types of transactions.
254
260
  */
255
261
  get currentWriteFraction(): number;
256
262
  /**
@@ -263,43 +269,25 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
263
269
  * @type {boolean}
264
270
  */
265
271
  get isFull(): boolean;
266
- /**
267
- * Total number of read sessions.
268
- * @type {number}
269
- */
272
+ /** @deprecated Use `size()` instead. */
270
273
  get reads(): number;
271
274
  /**
272
275
  * Total size of pool.
273
276
  * @type {number}
274
277
  */
275
278
  get size(): number;
276
- /**
277
- * Total number of write sessions.
278
- * @type {number}
279
- */
279
+ /** @deprecated Use `size()` instead. */
280
280
  get writes(): number;
281
- /**
282
- * Number of sessions currently being prepared for a read/write transaction
283
- * before being released into the pool. This number does not include the
284
- * number of sessions being prepared for a read/write transaction that have
285
- * already been checked out of the pool.
286
- * @type {number}
287
- */
281
+ /** @deprecated Starting v6.5.0 the pending prepare state is obsolete. */
288
282
  get pendingPrepare(): number;
289
283
  /**
290
284
  * Number of sessions being created or prepared for a read/write transaction.
291
285
  * @type {number}
292
286
  */
293
287
  get totalPending(): number;
294
- /**
295
- * Current number of waiters for a read-only session.
296
- * @type {number}
297
- */
288
+ /** @deprecated Use totalWaiters instead. */
298
289
  get numReadWaiters(): number;
299
- /**
300
- * Current number of waiters for a read/write session.
301
- * @type {number}
302
- */
290
+ /** @deprecated Use totalWaiters instead. */
303
291
  get numWriteWaiters(): number;
304
292
  /**
305
293
  * Sum of read and write waiters.
@@ -322,15 +310,23 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
322
310
  /**
323
311
  * Retrieve a read session.
324
312
  *
313
+ * @deprecated Use getSession instead.
325
314
  * @param {GetReadSessionCallback} callback The callback function.
326
315
  */
327
316
  getReadSession(callback: GetReadSessionCallback): void;
328
317
  /**
329
318
  * Retrieve a read/write session.
330
319
  *
320
+ * @deprecated use getSession instead.
331
321
  * @param {GetWriteSessionCallback} callback The callback function.
332
322
  */
333
323
  getWriteSession(callback: GetWriteSessionCallback): void;
324
+ /**
325
+ * Retrieve a session.
326
+ *
327
+ * @param {GetSessionCallback} callback The callback function.
328
+ */
329
+ getSession(callback: GetSessionCallback): void;
334
330
  /**
335
331
  * Opens the pool, filling it to the configured number of read and write
336
332
  * sessions.
@@ -340,14 +336,14 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
340
336
  */
341
337
  open(): void;
342
338
  /**
343
- * Releases session back into the pool. If the session is a write session it
344
- * will also prepare a new transaction before releasing it.
339
+ * Releases session back into the pool.
345
340
  *
346
341
  * @throws {Error} For unknown sessions.
347
342
  * @emits SessionPool#available
348
343
  * @emits SessionPool#error
349
- * @emits SessionPool#readonly-available
350
- * @emits SessionPool#readwrite-available
344
+ * @fires SessionPool#session-available
345
+ * @fires @deprecated SessionPool#readonly-available
346
+ * @fires @deprecated SessionPool#readwrite-available
351
347
  * @param {Session} session The session to release.
352
348
  */
353
349
  release(session: Session): void;
@@ -356,10 +352,9 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
356
352
  *
357
353
  * @private
358
354
  *
359
- * @param {string} type The desired type to borrow.
360
355
  * @returns {Promise<Session>}
361
356
  */
362
- _acquire(type: types): Promise<Session>;
357
+ _acquire(): Promise<Session>;
363
358
  /**
364
359
  * Moves a session into the borrowed group.
365
360
  *
@@ -369,43 +364,39 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
369
364
  */
370
365
  _borrow(session: Session): void;
371
366
  /**
372
- * Borrows the first session from specific group. This method may only be called if the inventory
373
- * actually contains a session of the desired type.
367
+ * Borrows the first session from the inventory.
374
368
  *
375
369
  * @private
376
370
  *
377
- * @param {string} type The desired session type.
378
371
  * @return {Session}
379
372
  */
380
- _borrowFrom(type: types): Session;
373
+ _borrowFrom(): Session;
381
374
  /**
382
375
  * Grabs the next available session.
383
376
  *
384
377
  * @private
385
378
  *
386
- * @param {string} type The desired session type.
387
379
  * @returns {Promise<Session>}
388
380
  */
389
- _borrowNextAvailableSession(type: types): Session;
381
+ _borrowNextAvailableSession(): Session;
390
382
  /**
391
- * Attempts to create a single session of a certain type.
383
+ * Attempts to create a single session.
392
384
  *
393
385
  * @private
394
386
  *
395
- * @param {string} type The desired type to create.
396
387
  * @returns {Promise}
397
388
  */
398
- _createSession(type: types): Promise<void>;
389
+ _createSession(): Promise<void>;
399
390
  /**
400
- * Batch creates sessions and prepares any necessary transactions.
391
+ * Batch creates sessions.
401
392
  *
402
393
  * @private
403
394
  *
404
- * @param {object} [options] Config specifying how many sessions to create.
395
+ * @param {number} [amount] Config specifying how many sessions to create.
405
396
  * @returns {Promise}
406
397
  * @emits SessionPool#createError
407
398
  */
408
- _createSessions({ reads, writes, }: CreateSessionsOptions): Promise<void>;
399
+ _createSessions(amount: number): Promise<void>;
409
400
  /**
410
401
  * Attempts to delete a session, optionally creating a new one of the same
411
402
  * type if the pool is still open and we're under the configured min value.
@@ -444,26 +435,19 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
444
435
  */
445
436
  _getLeaks(): string[];
446
437
  /**
447
- * Returns true if the pool has a session that is usable for the specified
448
- * type, i.e. if a read-only session is requested, it returns true if the
449
- * pool has a read-only or a read/write session. If a read/write session is
450
- * requested, the method only returns true if the pool has a read/write
451
- * session available.
452
- * @param type The type of session.
438
+ * Returns true if the pool has a usable session.
453
439
  * @private
454
440
  */
455
- _hasSessionUsableFor(type: types): boolean;
441
+ _hasSessionUsableFor(): boolean;
456
442
  /**
457
- * Attempts to get a session of a specific type. If the type is unavailable it
458
- * may try to use a different type.
443
+ * Attempts to get a session.
459
444
  *
460
445
  * @private
461
446
  *
462
- * @param {string} type The desired session type.
463
447
  * @param {number} startTime Timestamp to use when determining timeouts.
464
448
  * @returns {Promise<Session>}
465
449
  */
466
- _getSession(type: types, startTime: number): Promise<Session>;
450
+ _getSession(startTime: number): Promise<Session>;
467
451
  /**
468
452
  * Checks to see whether or not session is expired.
469
453
  *
@@ -495,17 +479,17 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
495
479
  *
496
480
  * @param {Session} session The session object.
497
481
  * @param {object} options The transaction options.
498
- * @returns {Promise}
499
482
  */
500
- _prepareTransaction(session: Session): Promise<void>;
483
+ _prepareTransaction(session: Session): void;
501
484
  /**
502
485
  * Releases a session back into the pool.
503
486
  *
504
487
  * @private
505
488
  *
506
489
  * @fires SessionPool#available
507
- * @fires SessionPool#readonly-available
508
- * @fires SessionPool#readwrite-available
490
+ * @fires SessionPool#session-available
491
+ * @fires @deprecated SessionPool#readonly-available
492
+ * @fires @deprecated SessionPool#readwrite-available
509
493
  * @param {Session} session The session object.
510
494
  */
511
495
  _release(session: Session): void;