@google-cloud/spanner 5.15.1 → 5.16.2

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.
@@ -51,7 +51,7 @@ class PartialResultStream extends stream_1.Transform {
51
51
  */
52
52
  destroy(err) {
53
53
  if (this._destroyed) {
54
- return;
54
+ return this;
55
55
  }
56
56
  this._destroyed = true;
57
57
  process.nextTick(() => {
@@ -60,6 +60,7 @@ class PartialResultStream extends stream_1.Transform {
60
60
  }
61
61
  this.emit('close');
62
62
  });
63
+ return this;
63
64
  }
64
65
  /**
65
66
  * Processes each chunk.
@@ -64,34 +64,34 @@ export interface SessionPoolInterface extends EventEmitter {
64
64
  * @name SessionPoolInterface#close
65
65
  * @param {SessionPoolCloseCallback} callback The callback function.
66
66
  */
67
- close(callback: SessionPoolCloseCallback): void;
68
67
  /**
69
68
  * Will be called by the Database object, should be used to start creating
70
69
  * sessions/etc.
71
70
  *
72
71
  * @name SessionPoolInterface#open
73
72
  */
74
- open(): void;
75
73
  /**
76
74
  * When called returns a read-only session.
77
75
  *
78
76
  * @name SessionPoolInterface#getReadSession
79
77
  * @param {GetReadSessionCallback} callback The callback function.
80
78
  */
81
- getReadSession(callback: GetReadSessionCallback): void;
82
79
  /**
83
80
  * When called returns a read-write session with prepared transaction.
84
81
  *
85
82
  * @name SessionPoolInterface#getWriteSession
86
83
  * @param {GetWriteSessionCallback} callback The callback function.
87
84
  */
88
- getWriteSession(callback: GetWriteSessionCallback): void;
89
85
  /**
90
86
  * To be called when releasing a session back into the pool.
91
87
  *
92
88
  * @name SessionPoolInterface#release
93
89
  * @param {Session} session The session to be released.
94
90
  */
91
+ close(callback: SessionPoolCloseCallback): void;
92
+ open(): void;
93
+ getReadSession(callback: GetReadSessionCallback): void;
94
+ getWriteSession(callback: GetWriteSessionCallback): void;
95
95
  release(session: Session): void;
96
96
  }
97
97
  /**
@@ -411,7 +411,7 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
411
411
  *
412
412
  * @private
413
413
  *
414
- * @fires SessoinPool#error
414
+ * @fires SessionPool#error
415
415
  * @param {Session} session The session to delete.
416
416
  * @returns {Promise}
417
417
  */
@@ -550,9 +550,12 @@ class SessionPool extends events_1.EventEmitter {
550
550
  async _createSessions({ reads = 0, writes = 0, }) {
551
551
  const labels = this.options.labels;
552
552
  let needed = reads + writes;
553
+ if (needed <= 0) {
554
+ return;
555
+ }
553
556
  this._pending += needed;
554
557
  // while we can request as many sessions be created as we want, the backend
555
- // will return at most 100 at a time. hence the need for a while loop
558
+ // will return at most 100 at a time, hence the need for a while loop.
556
559
  while (needed > 0) {
557
560
  let sessions = null;
558
561
  try {
@@ -583,7 +586,7 @@ class SessionPool extends events_1.EventEmitter {
583
586
  *
584
587
  * @private
585
588
  *
586
- * @fires SessoinPool#error
589
+ * @fires SessionPool#error
587
590
  * @param {Session} session The session to delete.
588
591
  * @returns {Promise}
589
592
  */
@@ -624,7 +627,7 @@ class SessionPool extends events_1.EventEmitter {
624
627
  */
625
628
  async _fill() {
626
629
  const needed = this.options.min - this.size;
627
- if (!needed) {
630
+ if (needed <= 0) {
628
631
  return;
629
632
  }
630
633
  try {
@@ -736,11 +739,13 @@ class SessionPool extends events_1.EventEmitter {
736
739
  if (reads + this.size > this.options.max) {
737
740
  reads = this.options.max - this.size;
738
741
  }
739
- this._pending += reads;
740
- promises.push(new Promise((_, reject) => {
741
- this._pending -= reads;
742
- this._createSessions({ reads, writes: 0 }).catch(reject);
743
- }));
742
+ if (reads > 0) {
743
+ this._pending += reads;
744
+ promises.push(new Promise((_, reject) => {
745
+ this._pending -= reads;
746
+ this._createSessions({ reads, writes: 0 }).catch(reject);
747
+ }));
748
+ }
744
749
  }
745
750
  let removeErrorListener;
746
751
  promises.push(new Promise((_, reject) => {
@@ -51,6 +51,7 @@ export declare type DeleteSessionCallback = NormalCallback<google.protobuf.IEmpt
51
51
  * assumed you are going to create it.
52
52
  *
53
53
  * @example
54
+ * ```
54
55
  * const {Spanner} = require('@google-cloud/spanner');
55
56
  * const spanner = new Spanner();
56
57
  *
@@ -75,6 +76,7 @@ export declare type DeleteSessionCallback = NormalCallback<google.protobuf.IEmpt
75
76
  * // To access a previously-created session, provide a name.
76
77
  * //-
77
78
  * const session = database.session('session-name');
79
+ * ```
78
80
  */
79
81
  export declare class Session extends common.GrpcServiceObject {
80
82
  id: string;
@@ -87,12 +89,100 @@ export declare class Session extends common.GrpcServiceObject {
87
89
  [k: string]: string;
88
90
  };
89
91
  constructor(database: Database, name?: string);
92
+ /**
93
+ * Delete a session.
94
+ *
95
+ * Wrapper around {@link v1.SpannerClient#deleteSession}.
96
+ *
97
+ * @see {@link v1.SpannerClient#deleteSession}
98
+ * @see [DeleteSession API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.DeleteSession)
99
+ *
100
+ * @param {object} [gaxOptions] Request configuration options,
101
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
102
+ * for more details.
103
+ * @param {DeleteSessionCallback} [callback] Callback function.
104
+ * @returns {Promise<DeleteSessionResponse>}
105
+ *
106
+ * @example
107
+ * ```
108
+ * session.delete(function(err, apiResponse) {
109
+ * if (err) {
110
+ * // Error handling omitted.
111
+ * }
112
+ *
113
+ * // Session deleted successfully.
114
+ * });
115
+ *
116
+ * //-
117
+ * //Returns a Promise if the callback is omitted.
118
+ * //-
119
+ * session.delete().then(function(data) {
120
+ * const apiResponse = data[0];
121
+ * });
122
+ * ```
123
+ */
90
124
  delete(gaxOptions?: CallOptions): Promise<DeleteSessionResponse>;
91
125
  delete(callback: DeleteSessionCallback): void;
92
126
  delete(gaxOptions: CallOptions, callback: DeleteSessionCallback): void;
127
+ /**
128
+ * @typedef {array} GetSessionMetadataResponse
129
+ * @property {object} 0 The session's metadata.
130
+ * @property {object} 1 The full API response.
131
+ */
132
+ /**
133
+ * @callback GetSessionMetadataCallback
134
+ * @param {?Error} err Request error, if any.
135
+ * @param {object} metadata The session's metadata.
136
+ * @param {object} apiResponse The full API response.
137
+ */
138
+ /**
139
+ * Get the session's metadata.
140
+ *
141
+ * Wrapper around {@link v1.SpannerClient#getSession}.
142
+ *
143
+ * @see {@link v1.SpannerClient#getSession}
144
+ * @see [GetSession API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.GetSession)
145
+ *
146
+ * @param {object} [gaxOptions] Request configuration options,
147
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
148
+ * for more details.
149
+ * @param {GetSessionMetadataCallback} [callback] Callback function.
150
+ * @returns {Promise<GetSessionMetadataResponse>}
151
+ *
152
+ * @example
153
+ * ```
154
+ * session.getMetadata(function(err, metadata, apiResponse) {});
155
+ *
156
+ * //-
157
+ * //Returns a Promise if the callback is omitted.
158
+ * //-
159
+ * session.getMetadata().then(function(data) {
160
+ * const metadata = data[0];
161
+ * const apiResponse = data[1];
162
+ * });
163
+ * ```
164
+ */
93
165
  getMetadata(gaxOptions?: CallOptions): Promise<GetSessionMetadataResponse>;
94
166
  getMetadata(callback: GetSessionMetadataCallback): void;
95
167
  getMetadata(gaxOptions: CallOptions, callback: GetSessionMetadataCallback): void;
168
+ /**
169
+ * Ping the session with `SELECT 1` to prevent it from expiring.
170
+ *
171
+ * @param {object} [gaxOptions] Request configuration options,
172
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
173
+ * for more details.
174
+ * @param {BasicCallback} [callback] Callback function.
175
+ * @returns {Promise<BasicResponse>}
176
+ *
177
+ * @example
178
+ * ```
179
+ * session.keepAlive(function(err) {
180
+ * if (err) {
181
+ * // An error occurred while trying to keep this session alive.
182
+ * }
183
+ * });
184
+ * ```
185
+ */
96
186
  keepAlive(gaxOptions?: CallOptions): Promise<KeepAliveResponse>;
97
187
  keepAlive(callback: KeepAliveCallback): void;
98
188
  keepAlive(gaxOptions: CallOptions, callback: KeepAliveCallback): void;
@@ -102,7 +192,9 @@ export declare class Session extends common.GrpcServiceObject {
102
192
  * @returns {PartitionedDml}
103
193
  *
104
194
  * @example
195
+ * ```
105
196
  * const transaction = session.partitionedDml();
197
+ * ```
106
198
  */
107
199
  partitionedDml(): PartitionedDml;
108
200
  /**
@@ -113,7 +205,9 @@ export declare class Session extends common.GrpcServiceObject {
113
205
  * @returns {Snapshot}
114
206
  *
115
207
  * @example
208
+ * ```
116
209
  * const snapshot = session.snapshot({strong: false});
210
+ * ```
117
211
  */
118
212
  snapshot(options?: TimestampBounds, queryOptions?: google.spanner.v1.ExecuteSqlRequest.IQueryOptions): Snapshot;
119
213
  /**
@@ -123,7 +217,9 @@ export declare class Session extends common.GrpcServiceObject {
123
217
  * @return {Transaction}
124
218
  *
125
219
  * @example
220
+ * ```
126
221
  * const transaction = session.transaction();
222
+ * ```
127
223
  */
128
224
  transaction(queryOptions?: google.spanner.v1.ExecuteSqlRequest.IQueryOptions, requestOptions?: Pick<IRequestOptions, 'transactionTag'>): Transaction;
129
225
  /**
@@ -136,9 +232,11 @@ export declare class Session extends common.GrpcServiceObject {
136
232
  * @returns {string}
137
233
  *
138
234
  * @example
235
+ * ```
139
236
  * Session.formatName_('my-database', 'my-session');
140
237
  * // 'projects/grape-spaceship-123/instances/my-instance/' +
141
238
  * // 'databases/my-database/sessions/my-session'
239
+ * ```
142
240
  */
143
241
  static formatName_(databaseName: string, name: string): string;
144
242
  }
@@ -38,6 +38,7 @@ const common_1 = require("./common");
38
38
  * assumed you are going to create it.
39
39
  *
40
40
  * @example
41
+ * ```
41
42
  * const {Spanner} = require('@google-cloud/spanner');
42
43
  * const spanner = new Spanner();
43
44
  *
@@ -62,6 +63,7 @@ const common_1 = require("./common");
62
63
  * // To access a previously-created session, provide a name.
63
64
  * //-
64
65
  * const session = database.session('session-name');
66
+ * ```
65
67
  */
66
68
  class Session extends common.GrpcServiceObject {
67
69
  constructor(database, name) {
@@ -75,6 +77,7 @@ class Session extends common.GrpcServiceObject {
75
77
  * @returns {Promise<CreateSessionResponse>}
76
78
  *
77
79
  * @example
80
+ * ```
78
81
  * session.create(function(err, session, apiResponse) {
79
82
  * if (err) {
80
83
  * // Error handling omitted.
@@ -93,6 +96,7 @@ class Session extends common.GrpcServiceObject {
93
96
  *
94
97
  * // Session created successfully.
95
98
  * });
99
+ * ```
96
100
  */
97
101
  create: true,
98
102
  /**
@@ -112,6 +116,7 @@ class Session extends common.GrpcServiceObject {
112
116
  * @returns {Promise<SessionExistsResponse>}
113
117
  *
114
118
  * @example
119
+ * ```
115
120
  * session.exists(function(err, exists) {});
116
121
  *
117
122
  * //-
@@ -120,6 +125,7 @@ class Session extends common.GrpcServiceObject {
120
125
  * session.exists().then(function(data) {
121
126
  * const exists = data[0];
122
127
  * });
128
+ * ```
123
129
  */
124
130
  exists: true,
125
131
  /**
@@ -149,6 +155,7 @@ class Session extends common.GrpcServiceObject {
149
155
  * @returns {Promise<GetSessionResponse>}
150
156
  *
151
157
  * @example
158
+ * ```
152
159
  * session.get(function(err, session, apiResponse) {
153
160
  * // `session.metadata` has been populated.
154
161
  * });
@@ -160,6 +167,7 @@ class Session extends common.GrpcServiceObject {
160
167
  * const session = data[0];
161
168
  * const apiResponse = data[0];
162
169
  * });
170
+ * ```
163
171
  */
164
172
  get: true,
165
173
  };
@@ -196,36 +204,6 @@ class Session extends common.GrpcServiceObject {
196
204
  this.formattedName_ = Session.formatName_(database.formattedName_, name);
197
205
  }
198
206
  }
199
- /**
200
- * Delete a session.
201
- *
202
- * Wrapper around {@link v1.SpannerClient#deleteSession}.
203
- *
204
- * @see {@link v1.SpannerClient#deleteSession}
205
- * @see [DeleteSession API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.DeleteSession)
206
- *
207
- * @param {object} [gaxOptions] Request configuration options,
208
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
209
- * for more details.
210
- * @param {DeleteSessionCallback} [callback] Callback function.
211
- * @returns {Promise<DeleteSessionResponse>}
212
- *
213
- * @example
214
- * session.delete(function(err, apiResponse) {
215
- * if (err) {
216
- * // Error handling omitted.
217
- * }
218
- *
219
- * // Session deleted successfully.
220
- * });
221
- *
222
- * //-
223
- * //Returns a Promise if the callback is omitted.
224
- * //-
225
- * session.delete().then(function(data) {
226
- * const apiResponse = data[0];
227
- * });
228
- */
229
207
  delete(optionsOrCallback, cb) {
230
208
  const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
231
209
  const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
@@ -240,42 +218,6 @@ class Session extends common.GrpcServiceObject {
240
218
  headers: this.resourceHeader_,
241
219
  }, callback);
242
220
  }
243
- /**
244
- * @typedef {array} GetSessionMetadataResponse
245
- * @property {object} 0 The session's metadata.
246
- * @property {object} 1 The full API response.
247
- */
248
- /**
249
- * @callback GetSessionMetadataCallback
250
- * @param {?Error} err Request error, if any.
251
- * @param {object} metadata The session's metadata.
252
- * @param {object} apiResponse The full API response.
253
- */
254
- /**
255
- * Get the session's metadata.
256
- *
257
- * Wrapper around {@link v1.SpannerClient#getSession}.
258
- *
259
- * @see {@link v1.SpannerClient#getSession}
260
- * @see [GetSession API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.GetSession)
261
- *
262
- * @param {object} [gaxOptions] Request configuration options,
263
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
264
- * for more details.
265
- * @param {GetSessionMetadataCallback} [callback] Callback function.
266
- * @returns {Promise<GetSessionMetadataResponse>}
267
- *
268
- * @example
269
- * session.getMetadata(function(err, metadata, apiResponse) {});
270
- *
271
- * //-
272
- * //Returns a Promise if the callback is omitted.
273
- * //-
274
- * session.getMetadata().then(function(data) {
275
- * const metadata = data[0];
276
- * const apiResponse = data[1];
277
- * });
278
- */
279
221
  getMetadata(optionsOrCallback, cb) {
280
222
  const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
281
223
  const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
@@ -295,22 +237,6 @@ class Session extends common.GrpcServiceObject {
295
237
  callback(err, resp);
296
238
  });
297
239
  }
298
- /**
299
- * Ping the session with `SELECT 1` to prevent it from expiring.
300
- *
301
- * @param {object} [gaxOptions] Request configuration options,
302
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
303
- * for more details.
304
- * @param {BasicCallback} [callback] Callback function.
305
- * @returns {Promise<BasicResponse>}
306
- *
307
- * @example
308
- * session.keepAlive(function(err) {
309
- * if (err) {
310
- * // An error occurred while trying to keep this session alive.
311
- * }
312
- * });
313
- */
314
240
  keepAlive(optionsOrCallback, cb) {
315
241
  const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
316
242
  const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
@@ -332,7 +258,9 @@ class Session extends common.GrpcServiceObject {
332
258
  * @returns {PartitionedDml}
333
259
  *
334
260
  * @example
261
+ * ```
335
262
  * const transaction = session.partitionedDml();
263
+ * ```
336
264
  */
337
265
  partitionedDml() {
338
266
  return new transaction_1.PartitionedDml(this);
@@ -345,7 +273,9 @@ class Session extends common.GrpcServiceObject {
345
273
  * @returns {Snapshot}
346
274
  *
347
275
  * @example
276
+ * ```
348
277
  * const snapshot = session.snapshot({strong: false});
278
+ * ```
349
279
  */
350
280
  snapshot(options, queryOptions) {
351
281
  return new transaction_1.Snapshot(this, options, queryOptions);
@@ -357,7 +287,9 @@ class Session extends common.GrpcServiceObject {
357
287
  * @return {Transaction}
358
288
  *
359
289
  * @example
290
+ * ```
360
291
  * const transaction = session.transaction();
292
+ * ```
361
293
  */
362
294
  transaction(queryOptions, requestOptions) {
363
295
  return new transaction_1.Transaction(this, undefined, queryOptions, requestOptions);
@@ -372,9 +304,11 @@ class Session extends common.GrpcServiceObject {
372
304
  * @returns {string}
373
305
  *
374
306
  * @example
307
+ * ```
375
308
  * Session.formatName_('my-database', 'my-session');
376
309
  * // 'projects/grape-spaceship-123/instances/my-instance/' +
377
310
  * // 'databases/my-database/sessions/my-session'
311
+ * ```
378
312
  */
379
313
  static formatName_(databaseName, name) {
380
314
  if (name.indexOf('/') > -1) {