@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.
Files changed (84) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +1 -0
  3. package/build/protos/google/spanner/admin/database/v1/backup.proto +773 -0
  4. package/build/protos/google/spanner/admin/database/v1/backup_schedule.proto +230 -0
  5. package/build/protos/google/spanner/admin/database/v1/common.proto +132 -0
  6. package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +1279 -0
  7. package/build/protos/google/spanner/admin/instance/v1/common.proto +64 -0
  8. package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +2110 -0
  9. package/build/protos/google/spanner/executor/v1/cloud_executor.proto +1520 -0
  10. package/build/protos/google/spanner/v1/commit_response.proto +59 -0
  11. package/build/protos/google/spanner/v1/keys.proto +163 -0
  12. package/build/protos/google/spanner/v1/mutation.proto +107 -0
  13. package/build/protos/google/spanner/v1/query_plan.proto +128 -0
  14. package/build/protos/google/spanner/v1/result_set.proto +237 -0
  15. package/build/protos/google/spanner/v1/spanner.proto +1389 -0
  16. package/build/protos/google/spanner/v1/transaction.proto +622 -0
  17. package/build/protos/google/spanner/v1/type.proto +214 -0
  18. package/build/protos/protos.d.ts +39869 -0
  19. package/build/protos/protos.js +101659 -0
  20. package/build/protos/protos.json +10391 -0
  21. package/build/src/backup.d.ts +349 -0
  22. package/build/src/backup.js +246 -0
  23. package/build/src/batch-transaction.d.ts +247 -0
  24. package/build/src/batch-transaction.js +384 -0
  25. package/build/src/codec.d.ts +362 -0
  26. package/build/src/codec.js +791 -0
  27. package/build/src/common-grpc/service-object.d.ts +80 -0
  28. package/build/src/common-grpc/service-object.js +101 -0
  29. package/build/src/common-grpc/service.d.ts +445 -0
  30. package/build/src/common-grpc/service.js +826 -0
  31. package/build/src/common.d.ts +66 -0
  32. package/build/src/common.js +54 -0
  33. package/build/src/database.d.ts +2103 -0
  34. package/build/src/database.js +1660 -0
  35. package/build/src/extra_proto_list.json +1 -0
  36. package/build/src/helper.d.ts +45 -0
  37. package/build/src/helper.js +71 -0
  38. package/build/src/index.d.ts +1195 -0
  39. package/build/src/index.js +1059 -0
  40. package/build/src/instance-config.d.ts +294 -0
  41. package/build/src/instance-config.js +216 -0
  42. package/build/src/instance.d.ts +832 -0
  43. package/build/src/instance.js +781 -0
  44. package/build/src/instrument.d.ts +85 -0
  45. package/build/src/instrument.js +215 -0
  46. package/build/src/multiplexed-session.d.ts +135 -0
  47. package/build/src/multiplexed-session.js +194 -0
  48. package/build/src/partial-result-stream.d.ts +253 -0
  49. package/build/src/partial-result-stream.js +400 -0
  50. package/build/src/request_id_header.d.ts +41 -0
  51. package/build/src/request_id_header.js +138 -0
  52. package/build/src/session-factory.d.ts +115 -0
  53. package/build/src/session-factory.js +106 -0
  54. package/build/src/session-pool.d.ts +471 -0
  55. package/build/src/session-pool.js +765 -0
  56. package/build/src/session.d.ts +258 -0
  57. package/build/src/session.js +348 -0
  58. package/build/src/spanner_grpc_config.json +92 -0
  59. package/build/src/table.d.ts +831 -0
  60. package/build/src/table.js +277 -0
  61. package/build/src/transaction-runner.d.ts +185 -0
  62. package/build/src/transaction-runner.js +282 -0
  63. package/build/src/transaction.d.ts +1691 -0
  64. package/build/src/transaction.js +2003 -0
  65. package/build/src/v1/database_admin_client.d.ts +2332 -0
  66. package/build/src/v1/database_admin_client.js +2364 -0
  67. package/build/src/v1/database_admin_client_config.json +165 -0
  68. package/build/src/v1/database_admin_proto_list.json +6 -0
  69. package/build/src/v1/gapic_metadata.json +27 -0
  70. package/build/src/v1/index.d.ts +4 -0
  71. package/build/src/v1/index.js +29 -0
  72. package/build/src/v1/instance_admin_client.d.ts +1985 -0
  73. package/build/src/v1/instance_admin_client.js +1768 -0
  74. package/build/src/v1/instance_admin_client_config.json +129 -0
  75. package/build/src/v1/instance_admin_proto_list.json +4 -0
  76. package/build/src/v1/spanner_client.d.ts +1250 -0
  77. package/build/src/v1/spanner_client.js +1086 -0
  78. package/build/src/v1/spanner_client_config.json +119 -0
  79. package/build/src/v1/spanner_executor_proxy_client.d.ts +418 -0
  80. package/build/src/v1/spanner_executor_proxy_client.js +706 -0
  81. package/build/src/v1/spanner_executor_proxy_client_config.json +30 -0
  82. package/build/src/v1/spanner_executor_proxy_proto_list.json +14 -0
  83. package/build/src/v1/spanner_proto_list.json +10 -0
  84. package/package.json +1 -1
@@ -0,0 +1,471 @@
1
+ /*!
2
+ * Copyright 2016 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 { EventEmitter } from 'events';
17
+ import PQueue from 'p-queue';
18
+ import { Database } from './database';
19
+ import { Session } from './session';
20
+ import { Transaction } from './transaction';
21
+ import { NormalCallback } from './common';
22
+ import { GoogleError, grpc } from 'google-gax';
23
+ import trace = require('stack-trace');
24
+ import { ObservabilityOptions } from './instrument';
25
+ import { GetSessionCallback } from './session-factory';
26
+ /**
27
+ * @callback SessionPoolCloseCallback
28
+ * @param {?Error} error Closing error, if any.
29
+ */
30
+ export interface SessionPoolCloseCallback {
31
+ (error?: SessionLeakError): void;
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
+ }
39
+ /**
40
+ * Interface for implementing custom session pooling logic, it should extend the
41
+ * {@link https://nodejs.org/api/events.html|EventEmitter} class and emit any
42
+ * asynchronous errors via an error event.
43
+ *
44
+ * @interface SessionPoolInterface
45
+ * @extends external:{@link https://nodejs.org/api/events.html|EventEmitter}
46
+ */
47
+ /**
48
+ * @constructs SessionPoolInterface
49
+ * @param {Database} database The database to create a pool for.
50
+ */
51
+ export interface SessionPoolInterface extends EventEmitter {
52
+ /**
53
+ * Will be called via {@link Database#close}. Indicates that the pool should
54
+ * perform any necessary teardown actions to its resources.
55
+ *
56
+ * @name SessionPoolInterface#close
57
+ * @param {SessionPoolCloseCallback} callback The callback function.
58
+ */
59
+ /**
60
+ * Will be called by the Database object, should be used to start creating
61
+ * sessions/etc.
62
+ *
63
+ * @name SessionPoolInterface#open
64
+ */
65
+ /**
66
+ * When called returns a session.
67
+ *
68
+ * @name SessionPoolInterface#getSession
69
+ * @param {GetSessionCallback} callback The callback function.
70
+ */
71
+ /**
72
+ * When called returns a session.
73
+ *
74
+ * @deprecated Use getSession instead.
75
+ * @name SessionPoolInterface#getReadSession
76
+ * @param {GetReadSessionCallback} callback The callback function.
77
+ */
78
+ /**
79
+ * When called returns a session.
80
+ *
81
+ * @deprecated Use getSession instead.
82
+ * @name SessionPoolInterface#getWriteSession
83
+ * @param {GetWriteSessionCallback} callback The callback function.
84
+ */
85
+ /**
86
+ * To be called when releasing a session back into the pool.
87
+ *
88
+ * @name SessionPoolInterface#release
89
+ * @param {Session} session The session to be released.
90
+ */
91
+ close(callback: SessionPoolCloseCallback): void;
92
+ open(): void;
93
+ getSession(callback: GetSessionCallback): void;
94
+ getReadSession(callback: GetReadSessionCallback): void;
95
+ getWriteSession(callback: GetWriteSessionCallback): void;
96
+ release(session: Session): void;
97
+ }
98
+ /**
99
+ * Session pool configuration options.
100
+ *
101
+ * @typedef {object} SessionPoolOptions
102
+ * @property {number} [acquireTimeout=Infinity] Time in milliseconds before
103
+ * giving up trying to acquire a session. If the specified value is
104
+ * `Infinity`, a timeout will not occur.
105
+ * @property {number} [concurrency=Infinity] How many concurrent requests the pool is
106
+ * allowed to make.
107
+ * @property {boolean} [fail=false] If set to true, an error will be thrown when
108
+ * there are no available sessions for a request.
109
+ * @property {number} [idlesAfter=10] How long until a resource becomes idle, in
110
+ * minutes.
111
+ * @property {number} [keepAlive=30] How often to ping idle sessions, in
112
+ * minutes. Must be less than 1 hour.
113
+ * @property {Object<string, string>} [labels] Labels to apply to any session
114
+ * created by the pool.
115
+ * @property {number} [max=100] Maximum number of resources to create at any
116
+ * given time.
117
+ * @property {number} [maxIdle=1] Maximum number of idle resources to keep in
118
+ * the pool at any given time.
119
+ * @property {number} [min=25] Minimum number of resources to keep in the pool at
120
+ * any given time.
121
+ * @property {number} [writes=0.0]. Deprecated.
122
+ * @property {number} [incStep=25] The number of new sessions to create when at
123
+ * least one more session is needed.
124
+ */
125
+ export interface SessionPoolOptions {
126
+ acquireTimeout?: number;
127
+ concurrency?: number;
128
+ fail?: boolean;
129
+ idlesAfter?: number;
130
+ keepAlive?: number;
131
+ labels?: {
132
+ [label: string]: string;
133
+ };
134
+ max?: number;
135
+ maxIdle?: number;
136
+ min?: number;
137
+ /**
138
+ * @deprecated. Starting from v6.5.0 the same session can be reused for
139
+ * different types of transactions.
140
+ */
141
+ writes?: number;
142
+ incStep?: number;
143
+ databaseRole?: string | null;
144
+ }
145
+ /**
146
+ * Error to be thrown when attempting to release unknown resources.
147
+ *
148
+ * @private
149
+ */
150
+ export declare class ReleaseError extends GoogleError {
151
+ resource: unknown;
152
+ constructor(resource: unknown);
153
+ }
154
+ /**
155
+ * Error to be thrown when session leaks are detected.
156
+ *
157
+ * @private
158
+ */
159
+ export declare class SessionLeakError extends GoogleError {
160
+ messages: string[];
161
+ constructor(leaks: string[]);
162
+ }
163
+ /**
164
+ * Error to be thrown when the session pool is exhausted.
165
+ */
166
+ export declare class SessionPoolExhaustedError extends GoogleError {
167
+ messages: string[];
168
+ constructor(leaks: string[]);
169
+ }
170
+ /**
171
+ * Checks whether the given error is a 'Session not found' error.
172
+ * @param error the error to check
173
+ * @return true if the error is a 'Session not found' error, and otherwise false.
174
+ */
175
+ export declare function isSessionNotFoundError(error: grpc.ServiceError | undefined): boolean;
176
+ interface SessionInventory {
177
+ sessions: Session[];
178
+ borrowed: Set<Session>;
179
+ }
180
+ /** @deprecated. */
181
+ export interface CreateSessionsOptions {
182
+ writes?: number;
183
+ reads?: number;
184
+ }
185
+ /**
186
+ * Class used to manage connections to Spanner.
187
+ *
188
+ * **You don't need to use this class directly, connections will be handled for
189
+ * you.**
190
+ *
191
+ * @class
192
+ * @extends {EventEmitter}
193
+ */
194
+ export declare class SessionPool extends EventEmitter implements SessionPoolInterface {
195
+ database: Database;
196
+ isOpen: boolean;
197
+ options: SessionPoolOptions;
198
+ _acquires: PQueue;
199
+ _evictHandle: NodeJS.Timer;
200
+ _inventory: SessionInventory;
201
+ _onClose: Promise<void>;
202
+ _pending: number;
203
+ _waiters: number;
204
+ _pingHandle: NodeJS.Timer;
205
+ _requests: PQueue;
206
+ _traces: Map<string, trace.StackFrame[]>;
207
+ _observabilityOptions?: ObservabilityOptions;
208
+ /**
209
+ * Formats stack trace objects into Node-like stack trace.
210
+ *
211
+ * @param {object[]} trace The trace object.
212
+ * @return {string}
213
+ */
214
+ static formatTrace(frames: trace.StackFrame[]): string;
215
+ /**
216
+ * Total number of available sessions.
217
+ * @type {number}
218
+ */
219
+ get available(): number;
220
+ /** @deprecated Starting from v6.5.0 the same session can be reused for
221
+ * different types of transactions.
222
+ */
223
+ get currentWriteFraction(): number;
224
+ /**
225
+ * Total number of borrowed sessions.
226
+ * @type {number}
227
+ */
228
+ get borrowed(): number;
229
+ /**
230
+ * Flag to determine if Pool is full.
231
+ * @type {boolean}
232
+ */
233
+ get isFull(): boolean;
234
+ /** @deprecated Use `size()` instead. */
235
+ get reads(): number;
236
+ /**
237
+ * Total size of pool.
238
+ * @type {number}
239
+ */
240
+ get size(): number;
241
+ /** @deprecated Use `size()` instead. */
242
+ get writes(): number;
243
+ /** @deprecated Starting v6.5.0 the pending prepare state is obsolete. */
244
+ get pendingPrepare(): number;
245
+ /**
246
+ * Number of sessions being created or prepared for a read/write transaction.
247
+ * @type {number}
248
+ */
249
+ get totalPending(): number;
250
+ /** @deprecated Use totalWaiters instead. */
251
+ get numReadWaiters(): number;
252
+ /** @deprecated Use totalWaiters instead. */
253
+ get numWriteWaiters(): number;
254
+ /**
255
+ * Sum of read and write waiters.
256
+ * @type {number}
257
+ */
258
+ get totalWaiters(): number;
259
+ /**
260
+ * @constructor
261
+ * @param {Database} database The DB instance.
262
+ * @param {SessionPoolOptions} [options] Configuration options.
263
+ */
264
+ constructor(database: Database, options?: SessionPoolOptions);
265
+ /**
266
+ * Closes and the pool.
267
+ *
268
+ * @emits SessionPool#close
269
+ * @param {SessionPoolCloseCallback} callback The callback function.
270
+ */
271
+ close(callback: SessionPoolCloseCallback): void;
272
+ /**
273
+ * Retrieve a read session.
274
+ *
275
+ * @deprecated Use getSession instead.
276
+ * @param {GetReadSessionCallback} callback The callback function.
277
+ */
278
+ getReadSession(callback: GetReadSessionCallback): void;
279
+ /**
280
+ * Retrieve a read/write session.
281
+ *
282
+ * @deprecated use getSession instead.
283
+ * @param {GetWriteSessionCallback} callback The callback function.
284
+ */
285
+ getWriteSession(callback: GetWriteSessionCallback): void;
286
+ /**
287
+ * Retrieve a session.
288
+ *
289
+ * @param {GetSessionCallback} callback The callback function.
290
+ */
291
+ getSession(callback: GetSessionCallback): void;
292
+ /**
293
+ * Opens the pool, filling it to the configured number of read and write
294
+ * sessions.
295
+ *
296
+ * @emits SessionPool#open
297
+ * @return {Promise}
298
+ */
299
+ open(): void;
300
+ /**
301
+ * Releases session back into the pool.
302
+ *
303
+ * @throws {Error} For unknown sessions.
304
+ * @emits SessionPool#available
305
+ * @emits SessionPool#error
306
+ * @fires SessionPool#session-available
307
+ * @fires @deprecated SessionPool#readonly-available
308
+ * @fires @deprecated SessionPool#readwrite-available
309
+ * @param {Session} session The session to release.
310
+ */
311
+ release(session: Session): void;
312
+ /**
313
+ * Attempts to borrow a session from the pool.
314
+ *
315
+ * @private
316
+ *
317
+ * @returns {Promise<Session>}
318
+ */
319
+ _acquire(): Promise<Session>;
320
+ /**
321
+ * Moves a session into the borrowed group.
322
+ *
323
+ * @private
324
+ *
325
+ * @param {Session} session The session object.
326
+ */
327
+ _borrow(session: Session): void;
328
+ /**
329
+ * Borrows the first session from the inventory.
330
+ *
331
+ * @private
332
+ *
333
+ * @return {Session}
334
+ */
335
+ _borrowFrom(): Session;
336
+ /**
337
+ * Grabs the next available session.
338
+ *
339
+ * @private
340
+ *
341
+ * @returns {Promise<Session>}
342
+ */
343
+ _borrowNextAvailableSession(): Session;
344
+ /**
345
+ * Attempts to create a single session.
346
+ *
347
+ * @private
348
+ *
349
+ * @returns {Promise}
350
+ */
351
+ _createSession(): Promise<void>;
352
+ /**
353
+ * Batch creates sessions.
354
+ *
355
+ * @private
356
+ *
357
+ * @param {number} [amount] Config specifying how many sessions to create.
358
+ * @returns {Promise}
359
+ * @emits SessionPool#createError
360
+ */
361
+ _createSessions(amount: number): Promise<void>;
362
+ /**
363
+ * Attempts to delete a session, optionally creating a new one of the same
364
+ * type if the pool is still open and we're under the configured min value.
365
+ *
366
+ * @private
367
+ *
368
+ * @fires SessionPool#error
369
+ * @param {Session} session The session to delete.
370
+ * @returns {Promise}
371
+ */
372
+ _destroy(session: Session): Promise<void>;
373
+ /**
374
+ * Deletes idle sessions that exceed the maxIdle configuration.
375
+ *
376
+ * @private
377
+ */
378
+ _evictIdleSessions(): void;
379
+ /**
380
+ * Fills the pool with the minimum number of sessions.
381
+ *
382
+ * @return {Promise}
383
+ */
384
+ _fill(): Promise<void>;
385
+ /**
386
+ * Retrieves a list of all the idle sessions.
387
+ *
388
+ * @private
389
+ *
390
+ * @returns {Session[]}
391
+ */
392
+ _getIdleSessions(): Session[];
393
+ /**
394
+ * Returns stack traces for sessions that have not been released.
395
+ *
396
+ * @return {string[]}
397
+ */
398
+ _getLeaks(): string[];
399
+ /**
400
+ * Returns true if the pool has a usable session.
401
+ * @private
402
+ */
403
+ _hasSessionUsableFor(): boolean;
404
+ /**
405
+ * Attempts to get a session.
406
+ *
407
+ * @private
408
+ *
409
+ * @param {number} startTime Timestamp to use when determining timeouts.
410
+ * @returns {Promise<Session>}
411
+ */
412
+ _getSession(startTime: number): Promise<Session>;
413
+ /**
414
+ * Checks to see whether or not session is expired.
415
+ *
416
+ * @param {Session} session The session to check.
417
+ * @returns {boolean}
418
+ */
419
+ _isValidSession(session: Session): boolean;
420
+ /**
421
+ * Pings an individual session.
422
+ *
423
+ * @private
424
+ *
425
+ * @param {Session} session The session to ping.
426
+ * @returns {Promise}
427
+ */
428
+ _ping(session: Session): Promise<void>;
429
+ /**
430
+ * Makes a keep alive request to all the idle sessions.
431
+ *
432
+ * @private
433
+ *
434
+ * @returns {Promise}
435
+ */
436
+ _pingIdleSessions(): Promise<void>;
437
+ /**
438
+ * Creates a transaction for a session.
439
+ *
440
+ * @private
441
+ *
442
+ * @param {Session} session The session object.
443
+ * @param {object} options The transaction options.
444
+ */
445
+ _prepareTransaction(session: Session): void;
446
+ /**
447
+ * Releases a session back into the pool.
448
+ *
449
+ * @private
450
+ *
451
+ * @fires SessionPool#available
452
+ * @fires SessionPool#session-available
453
+ * @fires @deprecated SessionPool#readonly-available
454
+ * @fires @deprecated SessionPool#readwrite-available
455
+ * @param {Session} session The session object.
456
+ */
457
+ _release(session: Session): void;
458
+ /**
459
+ * Starts housekeeping (pinging/evicting) of idle sessions.
460
+ *
461
+ * @private
462
+ */
463
+ _startHouseKeeping(): void;
464
+ /**
465
+ * Stops housekeeping.
466
+ *
467
+ * @private
468
+ */
469
+ _stopHouseKeeping(): void;
470
+ }
471
+ export {};