@google-cloud/spanner 6.4.0 → 6.5.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,6 +143,10 @@ 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;
140
152
  }
@@ -200,14 +212,10 @@ export declare function isDefaultCredentialsNotSetError(error: grpc.ServiceError
200
212
  */
201
213
  export declare function isProjectIdNotSetInEnvironmentError(error: grpc.ServiceError | undefined): boolean;
202
214
  interface SessionInventory {
203
- [types.ReadOnly]: Session[];
204
- [types.ReadWrite]: Session[];
215
+ sessions: Session[];
205
216
  borrowed: Set<Session>;
206
217
  }
207
- interface Waiters {
208
- [types.ReadOnly]: number;
209
- [types.ReadWrite]: number;
210
- }
218
+ /** @deprecated. */
211
219
  export interface CreateSessionsOptions {
212
220
  writes?: number;
213
221
  reads?: number;
@@ -230,9 +238,7 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
230
238
  _inventory: SessionInventory;
231
239
  _onClose: Promise<void>;
232
240
  _pending: number;
233
- _pendingPrepare: number;
234
- _waiters: Waiters;
235
- _numInProcessPrepare: number;
241
+ _waiters: number;
236
242
  _pingHandle: NodeJS.Timer;
237
243
  _requests: PQueue;
238
244
  _traces: Map<string, trace.StackFrame[]>;
@@ -248,9 +254,8 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
248
254
  * @type {number}
249
255
  */
250
256
  get available(): number;
251
- /**
252
- * Current fraction of write-prepared sessions in the pool.
253
- * @type {number}
257
+ /** @deprecated Starting from v6.5.0 the same session can be reused for
258
+ * different types of transactions.
254
259
  */
255
260
  get currentWriteFraction(): number;
256
261
  /**
@@ -263,43 +268,25 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
263
268
  * @type {boolean}
264
269
  */
265
270
  get isFull(): boolean;
266
- /**
267
- * Total number of read sessions.
268
- * @type {number}
269
- */
271
+ /** @deprecated Use `size()` instead. */
270
272
  get reads(): number;
271
273
  /**
272
274
  * Total size of pool.
273
275
  * @type {number}
274
276
  */
275
277
  get size(): number;
276
- /**
277
- * Total number of write sessions.
278
- * @type {number}
279
- */
278
+ /** @deprecated Use `size()` instead. */
280
279
  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
- */
280
+ /** @deprecated Starting v6.5.0 the pending prepare state is obsolete. */
288
281
  get pendingPrepare(): number;
289
282
  /**
290
283
  * Number of sessions being created or prepared for a read/write transaction.
291
284
  * @type {number}
292
285
  */
293
286
  get totalPending(): number;
294
- /**
295
- * Current number of waiters for a read-only session.
296
- * @type {number}
297
- */
287
+ /** @deprecated Use totalWaiters instead. */
298
288
  get numReadWaiters(): number;
299
- /**
300
- * Current number of waiters for a read/write session.
301
- * @type {number}
302
- */
289
+ /** @deprecated Use totalWaiters instead. */
303
290
  get numWriteWaiters(): number;
304
291
  /**
305
292
  * Sum of read and write waiters.
@@ -322,15 +309,23 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
322
309
  /**
323
310
  * Retrieve a read session.
324
311
  *
312
+ * @deprecated Use getSession instead.
325
313
  * @param {GetReadSessionCallback} callback The callback function.
326
314
  */
327
315
  getReadSession(callback: GetReadSessionCallback): void;
328
316
  /**
329
317
  * Retrieve a read/write session.
330
318
  *
319
+ * @deprecated use getSession instead.
331
320
  * @param {GetWriteSessionCallback} callback The callback function.
332
321
  */
333
322
  getWriteSession(callback: GetWriteSessionCallback): void;
323
+ /**
324
+ * Retrieve a session.
325
+ *
326
+ * @param {GetSessionCallback} callback The callback function.
327
+ */
328
+ getSession(callback: GetSessionCallback): void;
334
329
  /**
335
330
  * Opens the pool, filling it to the configured number of read and write
336
331
  * sessions.
@@ -340,14 +335,14 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
340
335
  */
341
336
  open(): void;
342
337
  /**
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.
338
+ * Releases session back into the pool.
345
339
  *
346
340
  * @throws {Error} For unknown sessions.
347
341
  * @emits SessionPool#available
348
342
  * @emits SessionPool#error
349
- * @emits SessionPool#readonly-available
350
- * @emits SessionPool#readwrite-available
343
+ * @fires SessionPool#session-available
344
+ * @fires @deprecated SessionPool#readonly-available
345
+ * @fires @deprecated SessionPool#readwrite-available
351
346
  * @param {Session} session The session to release.
352
347
  */
353
348
  release(session: Session): void;
@@ -356,10 +351,9 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
356
351
  *
357
352
  * @private
358
353
  *
359
- * @param {string} type The desired type to borrow.
360
354
  * @returns {Promise<Session>}
361
355
  */
362
- _acquire(type: types): Promise<Session>;
356
+ _acquire(): Promise<Session>;
363
357
  /**
364
358
  * Moves a session into the borrowed group.
365
359
  *
@@ -369,43 +363,39 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
369
363
  */
370
364
  _borrow(session: Session): void;
371
365
  /**
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.
366
+ * Borrows the first session from the inventory.
374
367
  *
375
368
  * @private
376
369
  *
377
- * @param {string} type The desired session type.
378
370
  * @return {Session}
379
371
  */
380
- _borrowFrom(type: types): Session;
372
+ _borrowFrom(): Session;
381
373
  /**
382
374
  * Grabs the next available session.
383
375
  *
384
376
  * @private
385
377
  *
386
- * @param {string} type The desired session type.
387
378
  * @returns {Promise<Session>}
388
379
  */
389
- _borrowNextAvailableSession(type: types): Session;
380
+ _borrowNextAvailableSession(): Session;
390
381
  /**
391
- * Attempts to create a single session of a certain type.
382
+ * Attempts to create a single session.
392
383
  *
393
384
  * @private
394
385
  *
395
- * @param {string} type The desired type to create.
396
386
  * @returns {Promise}
397
387
  */
398
- _createSession(type: types): Promise<void>;
388
+ _createSession(): Promise<void>;
399
389
  /**
400
- * Batch creates sessions and prepares any necessary transactions.
390
+ * Batch creates sessions.
401
391
  *
402
392
  * @private
403
393
  *
404
- * @param {object} [options] Config specifying how many sessions to create.
394
+ * @param {number} [amount] Config specifying how many sessions to create.
405
395
  * @returns {Promise}
406
396
  * @emits SessionPool#createError
407
397
  */
408
- _createSessions({ reads, writes, }: CreateSessionsOptions): Promise<void>;
398
+ _createSessions(amount: number): Promise<void>;
409
399
  /**
410
400
  * Attempts to delete a session, optionally creating a new one of the same
411
401
  * type if the pool is still open and we're under the configured min value.
@@ -444,26 +434,19 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
444
434
  */
445
435
  _getLeaks(): string[];
446
436
  /**
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.
437
+ * Returns true if the pool has a usable session.
453
438
  * @private
454
439
  */
455
- _hasSessionUsableFor(type: types): boolean;
440
+ _hasSessionUsableFor(): boolean;
456
441
  /**
457
- * Attempts to get a session of a specific type. If the type is unavailable it
458
- * may try to use a different type.
442
+ * Attempts to get a session.
459
443
  *
460
444
  * @private
461
445
  *
462
- * @param {string} type The desired session type.
463
446
  * @param {number} startTime Timestamp to use when determining timeouts.
464
447
  * @returns {Promise<Session>}
465
448
  */
466
- _getSession(type: types, startTime: number): Promise<Session>;
449
+ _getSession(startTime: number): Promise<Session>;
467
450
  /**
468
451
  * Checks to see whether or not session is expired.
469
452
  *
@@ -495,17 +478,17 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
495
478
  *
496
479
  * @param {Session} session The session object.
497
480
  * @param {object} options The transaction options.
498
- * @returns {Promise}
499
481
  */
500
- _prepareTransaction(session: Session): Promise<void>;
482
+ _prepareTransaction(session: Session): void;
501
483
  /**
502
484
  * Releases a session back into the pool.
503
485
  *
504
486
  * @private
505
487
  *
506
488
  * @fires SessionPool#available
507
- * @fires SessionPool#readonly-available
508
- * @fires SessionPool#readwrite-available
489
+ * @fires SessionPool#session-available
490
+ * @fires @deprecated SessionPool#readonly-available
491
+ * @fires @deprecated SessionPool#readwrite-available
509
492
  * @param {Session} session The session object.
510
493
  */
511
494
  _release(session: Session): void;