@google-cloud/spanner 5.15.2 → 5.16.3

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.
@@ -100,19 +100,27 @@ export declare type TranslateEnumKeys<T, U extends keyof T, E extends {
100
100
  * @see [Cloud Spanner Documentation](https://cloud.google.com/spanner/docs)
101
101
  * @see [Cloud Spanner Concepts](https://cloud.google.com/spanner/docs/concepts)
102
102
  *
103
- * @example <caption>Install the client library with <a
104
- * href="https://www.npmjs.com/">npm</a>:</caption> npm install --save
105
- * @google-cloud/spanner
103
+ * @example Install the client library with <a
104
+ * href="https://www.npmjs.com/">npm</a>:
105
+ * ```
106
+ * npm install --save @google-cloud/spanner
107
+ * ```
106
108
  *
107
- * @example <caption>Create a client that uses <a
109
+ * @example Create a client that uses <a
108
110
  * href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application
109
- * Default Credentials (ADC)</a>:</caption> const client = new Spanner();
111
+ * Default Credentials (ADC)</a>:
112
+ * ```
113
+ * const client = new Spanner();
114
+ * ```
110
115
  *
111
- * @example <caption>Create a client with <a
116
+ * @example Create a client with <a
112
117
  * href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit
113
- * credentials</a>:</caption> const client = new Spanner({ projectId:
118
+ * credentials</a>:
119
+ * ```
120
+ * const client = new Spanner({ projectId:
114
121
  * 'your-project-id', keyFilename: '/path/to/keyfile.json'
115
122
  * });
123
+ * ```
116
124
  *
117
125
  * @example <caption>include:samples/quickstart.js</caption>
118
126
  * region_tag:spanner_quickstart
@@ -148,8 +156,181 @@ declare class Spanner extends GrpcService {
148
156
  constructor(options?: SpannerOptions);
149
157
  /** Closes this Spanner client and cleans up all resources used by it. */
150
158
  close(): void;
159
+ /**
160
+ * Config for the new instance.
161
+ *
162
+ * @typedef {object} CreateInstanceRequest
163
+ * @property {string} config The name of the instance's configuration.
164
+ * @property {number} [nodes=1] The number of nodes allocated to this instance.
165
+ * Defaults to 1.
166
+ * @property {Object.<string, string>} [labels] Labels are a flexible and
167
+ * lightweight mechanism for organizing cloud resources into groups that
168
+ * reflect a customer's organizational needs and deployment strategies.
169
+ * Cloud Labels can be used to filter collections of resources. They can
170
+ * be used to control how resource metrics are aggregated. And they can
171
+ * be used as arguments to policy management rules (e.g. route,
172
+ * firewall, load balancing, etc.).
173
+ * @property {string} [displayName] The descriptive name for this instance
174
+ * as it appears in UIs. Must be unique per project and between 4 and 30
175
+ * characters in length.
176
+ * Defaults to the instance unique identifier '<instance>' of the full
177
+ * instance name of the form 'projects/<project>/instances/<instance>'.
178
+ */
179
+ /**
180
+ * @typedef {array} CreateInstanceResponse
181
+ * @property {Instance} 0 The new {@link Instance}.
182
+ * @property {google.longrunning.Operation} 1 An operation object that can be used to check
183
+ * the status of the request.
184
+ * @property {google.longrunning.IOperation} 2 The full API response.
185
+ */
186
+ /**
187
+ * @callback CreateInstanceCallback
188
+ * @param {?Error} err Request error, if any.
189
+ * @param {Instance} instance The new {@link Instance}.
190
+ * @param {google.longrunning.Operation} operation An operation object that can be used to
191
+ * check the status of the request.
192
+ * @param {google.longrunning.IOperation} apiResponse The full API response.
193
+ */
194
+ /**
195
+ * Create an instance.
196
+ *
197
+ * Wrapper around {@link v1.InstanceAdminClient#createInstance}.
198
+ *
199
+ * @see {@link v1.InstanceAdminClient#createInstance}
200
+ * @see [CreateInstace API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.CreateInstance)
201
+ *
202
+ * @throws {GoogleError} If a name is not provided.
203
+ * @throws {GoogleError} If a configuration object is not provided.
204
+ *
205
+ * @param {string} name The name of the instance to be created.
206
+ * @param {CreateInstanceRequest} config Configuration object.
207
+ * @param {CreateInstanceCallback} [callback] Callback function.
208
+ * @returns {Promise<CreateInstanceResponse>}
209
+ *
210
+ * @example
211
+ * ```
212
+ * const {Spanner} = require('@google-cloud/spanner');
213
+ * const spanner = new Spanner();
214
+ *
215
+ * const config = {
216
+ * config: 'regional-us-central1',
217
+ * nodes: 1
218
+ * };
219
+ *
220
+ * function callback(err, instance, operation, apiResponse) {
221
+ * if (err) {
222
+ * // Error handling omitted.
223
+ * }
224
+ *
225
+ * operation
226
+ * .on('error', function(err) {})
227
+ * .on('complete', function() {
228
+ * // Instance created successfully.
229
+ * });
230
+ * }
231
+ *
232
+ * spanner.createInstance('new-instance-name', config, callback);
233
+ *
234
+ * //-
235
+ * // If the callback is omitted, we'll return a Promise.
236
+ * //-
237
+ * spanner.createInstance('new-instance-name', config)
238
+ * .then(function(data) {
239
+ * const instance = data[0];
240
+ * const operation = data[1];
241
+ * return operation.promise();
242
+ * })
243
+ * .then(function() {
244
+ * // Instance created successfully.
245
+ * });
246
+ * ```
247
+ */
151
248
  createInstance(name: string, config: CreateInstanceRequest): Promise<CreateInstanceResponse>;
152
249
  createInstance(name: string, config: CreateInstanceRequest, callback: CreateInstanceCallback): void;
250
+ /**
251
+ * Query object for listing instances.
252
+ *
253
+ * @typedef {object} GetInstancesOptions
254
+ * @property {object} [gaxOptions] Request configuration options,
255
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
256
+ * for more details.
257
+ * @property {string} [filter] An expression for filtering the results of the
258
+ * request. Filter rules are case insensitive. The fields eligible for
259
+ * filtering are:
260
+ * - **`name`**
261
+ * - **`display_name`**
262
+ * - **`labels.key`** where key is the name of a label
263
+ *
264
+ * Some examples of using filters are:
265
+ * - **`name:*`** The instance has a name.
266
+ * - **`name:Howl`** The instance's name is howl.
267
+ * - **`labels.env:*`** The instance has the label env.
268
+ * - **`labels.env:dev`** The instance's label env has the value dev.
269
+ * - **`name:howl labels.env:dev`** The instance's name is howl and it has
270
+ * the label env with value dev.
271
+ * @property {number} [pageSize] Maximum number of results per page.
272
+ * @property {string} [pageToken] A previously-returned page token
273
+ * representing part of the larger set of results to view.
274
+ */
275
+ /**
276
+ * @typedef {array} GetInstancesResponse
277
+ * @property {Instance[]} 0 Array of {@link Instance} instances.
278
+ * @property {object} 1 A query object to receive more results.
279
+ * @property {object} 2 The full API response.
280
+ */
281
+ /**
282
+ * @callback GetInstancesCallback
283
+ * @param {?Error} err Request error, if any.
284
+ * @param {Instance[]} instances Array of {@link Instance} instances.
285
+ * @param {string} nextQuery A query object to receive more results.
286
+ * @param {object} apiResponse The full API response.
287
+ */
288
+ /**
289
+ * Get a list of instances.
290
+ *
291
+ * Wrapper around {@link v1.InstanceAdminClient#listInstances}.
292
+ *
293
+ * @see {@link v1.InstanceAdminClient#listInstances}
294
+ * @see [ListInstances API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.ListInstances)
295
+ *
296
+ * @param {GetInstancesOptions} [options] Query object for listing instances.
297
+ * @param {GetInstancesCallback} [callback] Callback function.
298
+ * @returns {Promise<GetInstancesResponse>}
299
+ *
300
+ * @example
301
+ * ```
302
+ * const {Spanner} = require('@google-cloud/spanner');
303
+ * const spanner = new Spanner();
304
+ *
305
+ * spanner.getInstances(function(err, instances) {
306
+ * // `instances` is an array of `Instance` objects.
307
+ * });
308
+ *
309
+ * //-
310
+ * // To control how many API requests are made and page through the results
311
+ * // manually, set `autoPaginate` to `false`.
312
+ * //-
313
+ * function callback(err, instances, nextQuery, apiResponse) {
314
+ * if (nextQuery) {
315
+ * // More results exist.
316
+ * spanner.getInstances(nextQuery, callback);
317
+ * }
318
+ * }
319
+ *
320
+ * spanner.getInstances({
321
+ * gaxOptions: {
322
+ * autoPaginate: false,
323
+ * }
324
+ * }, callback);
325
+ *
326
+ * //-
327
+ * // If the callback is omitted, we'll return a Promise.
328
+ * //-
329
+ * spanner.getInstances().then(function(data) {
330
+ * const instances = data[0];
331
+ * });
332
+ * ```
333
+ */
153
334
  getInstances(options?: GetInstancesOptions): Promise<GetInstancesResponse>;
154
335
  getInstances(callback: GetInstancesCallback): void;
155
336
  getInstances(query: GetInstancesOptions, callback: GetInstancesCallback): void;
@@ -167,6 +348,7 @@ declare class Spanner extends GrpcService {
167
348
  * instances.
168
349
  *
169
350
  * @example
351
+ * ```
170
352
  * const {Spanner} = require('@google-cloud/spanner');
171
353
  * const spanner = new Spanner();
172
354
  *
@@ -187,8 +369,93 @@ declare class Spanner extends GrpcService {
187
369
  * .on('data', function(instance) {
188
370
  * this.end();
189
371
  * });
372
+ * ```
190
373
  */
191
374
  getInstancesStream(options?: GetInstancesOptions): NodeJS.ReadableStream;
375
+ /**
376
+ * Lists the supported instance configurations for a given project.
377
+ *
378
+ * @typedef {object} GetInstanceConfigsOptions
379
+ * @property {number} [pageSize] Maximum number of results per page.
380
+ * @property {string} [pageToken] A previously-returned page token
381
+ * representing part of the larger set of results to view.
382
+ * @property {object} [gaxOptions] Request configuration options,
383
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
384
+ * for more details.
385
+ */
386
+ /**
387
+ * @typedef {array} GetInstanceConfigsResponse
388
+ * @property {object[]} 0 List of all available instance configs.
389
+ * @property {string} 0.name The unique identifier for the instance config.
390
+ * @property {string} 0.displayName The name of the instance config as it
391
+ * appears in UIs.
392
+ * @property {google.spanner.admin.instance.v1.IReplicaInfo[]} 0.replicas The replicas used by
393
+ * this instance config.
394
+ * @property {string[]} 0.leaderOptions The possible leader options for this instance config.
395
+ * @property {object} 1 A query object to receive more results.
396
+ * @property {object} 2 The full API response.
397
+ */
398
+ /**
399
+ * @callback GetInstanceConfigsCallback
400
+ * @param {?Error} err Request error, if any.
401
+ * @param {object[]} instanceConfigs List of all available instance configs.
402
+ * @param {string} instanceConfigs.name The unique identifier for the instance
403
+ * config.
404
+ * @param {string} instanceConfigs.displayName The name of the instance config
405
+ * as it appears in UIs.
406
+ * @param {google.spanner.admin.instance.v1.IReplicaInfo[]} instanceConfigs.replicas The replicas used by
407
+ * this instance config.
408
+ * @param {string[]} instanceConfigs.leaderOptions The possible leader options for this instance config.
409
+ * @param {object} nextQuery A query object to receive more results.
410
+ * @param {object} apiResponse The full API response.
411
+ */
412
+ /**
413
+ * Get a list of instance configs.
414
+ *
415
+ * Wrapper around {@link v1.InstanceAdminClient#listInstanceConfigs}.
416
+ *
417
+ * @see {@link v1.InstanceAdminClient#listInstanceConfigs}
418
+ * @see [ListInstanceConfigs API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.ListInstanceConfigs)
419
+ *
420
+ * @param {GetInstanceConfigsOptions} [options] Query object for listing instance
421
+ * configs.
422
+ * @param {GetInstanceConfigsCallback} [callback] Callback function.
423
+ * @returns {Promise<GetInstanceConfigsResponse>}
424
+ *
425
+ * @example
426
+ * ```
427
+ * const {Spanner} = require('@google-cloud/spanner');
428
+ * const spanner = new Spanner();
429
+ *
430
+ * spanner.getInstanceConfigs(function(err, instanceConfigs) {
431
+ * // `instanceConfigs` is an array of instance configuration descriptors.
432
+ * });
433
+ *
434
+ * //-
435
+ * // To control how many API requests are made and page through the results
436
+ * // manually, set `autoPaginate` to `false`.
437
+ * //-
438
+ * function callback(err, instanceConfigs, nextQuery, apiResponse) {
439
+ * if (nextQuery) {
440
+ * // More results exist.
441
+ * spanner.getInstanceConfigs(nextQuery, callback);
442
+ * }
443
+ * }
444
+ *
445
+ * spanner.getInstanceConfigs({
446
+ * gaxOptions: {
447
+ * autoPaginate: false,
448
+ * }
449
+ * }, callback);
450
+ *
451
+ * //-
452
+ * // If the callback is omitted, we'll return a Promise.
453
+ * //-
454
+ * spanner.getInstanceConfigs().then(function(data) {
455
+ * const instanceConfigs = data[0];
456
+ * });
457
+ * ```
458
+ */
192
459
  getInstanceConfigs(query?: GetInstanceConfigsOptions): Promise<GetInstanceConfigsResponse>;
193
460
  getInstanceConfigs(callback: GetInstanceConfigsCallback): void;
194
461
  getInstanceConfigs(query: GetInstanceConfigsOptions, callback: GetInstanceConfigsCallback): void;
@@ -206,6 +473,7 @@ declare class Spanner extends GrpcService {
206
473
  * @returns {ReadableStream} A readable stream that emits instance configs.
207
474
  *
208
475
  * @example
476
+ * ```
209
477
  * const {Spanner} = require('@google-cloud/spanner');
210
478
  * const spanner = new Spanner();
211
479
  *
@@ -224,8 +492,63 @@ declare class Spanner extends GrpcService {
224
492
  * .on('data', function(instanceConfig) {
225
493
  * this.end();
226
494
  * });
495
+ * ```
227
496
  */
228
497
  getInstanceConfigsStream(options?: GetInstanceConfigsOptions): NodeJS.ReadableStream;
498
+ /**
499
+ * Gets the instance configuration with the specified name.
500
+ */
501
+ /**
502
+ * @typedef {array} GetInstanceConfigResponse
503
+ * @property {object[]} 0 The metadata of the instance config.
504
+ * @property {string} 0.name The unique identifier for the instance config.
505
+ * @property {string} 0.displayName The name of the instance config as it
506
+ * appears in UIs.
507
+ * @property {google.spanner.admin.instance.v1.IReplicaInfo[]} 0.replicas The replicas used by
508
+ * this instance config.
509
+ * @property {string[]} 0.leaderOptions The possible leader options for this instance config.
510
+ */
511
+ /**
512
+ * @callback GetInstanceConfigCallback
513
+ * @param {?Error} err Request error, if any.
514
+ * @param {object} instanceConfig The metadata of the instance config.
515
+ * @param {string} instanceConfig.name The unique identifier for the instance
516
+ * config.
517
+ * @param {string} instanceConfig.displayName The name of the instance config
518
+ * as it appears in UIs.
519
+ * @param {google.spanner.admin.instance.v1.IReplicaInfo[]} instanceConfig.replicas The replicas used by
520
+ * this instance config.
521
+ * @param {string[]} 0.leaderOptions The possible leader options for this instance config.
522
+ */
523
+ /**
524
+ * Get a specific instance config.
525
+ *
526
+ * Wrapper around {@link v1.InstanceAdminClient#getInstanceConfig}.
527
+ *
528
+ * @see {@link v1.InstanceAdminClient#getInstanceConfig}
529
+ * @see [GetInstanceConfig API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.InstanceAdmin.GetInstanceConfig)
530
+ *
531
+ * @param {string} [name] The name of the instance config to get.
532
+ * @param {GetInstanceConfigCallback} [callback] Callback function.
533
+ * @returns {Promise<GetInstanceConfigResponse>}
534
+ *
535
+ * @example
536
+ * ```
537
+ * const {Spanner} = require('@google-cloud/spanner');
538
+ * const spanner = new Spanner();
539
+ *
540
+ * spanner.getInstanceConfig('nam6', function(err, instanceConfig) {
541
+ * // `instanceConfig` is an instance configuration descriptor.
542
+ * });
543
+ *
544
+ * //-
545
+ * // If the callback is omitted, we'll return a Promise.
546
+ * //-
547
+ * spanner.getInstanceConfig().then(function(data) {
548
+ * const instanceConfig = data[0];
549
+ * });
550
+ * ```
551
+ */
229
552
  getInstanceConfig(name: string): Promise<GetInstanceConfigResponse>;
230
553
  getInstanceConfig(name: string, options: GetInstanceConfigOptions): Promise<GetInstanceConfigResponse>;
231
554
  getInstanceConfig(name: string, callback: GetInstanceConfigCallback): void;
@@ -233,15 +556,17 @@ declare class Spanner extends GrpcService {
233
556
  /**
234
557
  * Get a reference to an Instance object.
235
558
  *
236
- * @throws {Error} If a name is not provided.
559
+ * @throws {GoogleError} If a name is not provided.
237
560
  *
238
561
  * @param {string} name The name of the instance.
239
562
  * @returns {Instance} An Instance object.
240
563
  *
241
564
  * @example
565
+ * ```
242
566
  * const {Spanner} = require('@google-cloud/spanner');
243
567
  * const spanner = new Spanner();
244
568
  * const instance = spanner.instance('my-instance');
569
+ * ```
245
570
  */
246
571
  instance(name: string): Instance;
247
572
  /**
@@ -304,14 +629,20 @@ declare class Spanner extends GrpcService {
304
629
  * @returns {external:PreciseDate}
305
630
  *
306
631
  * @example
632
+ * ```
307
633
  * const timestamp = Spanner.timestamp('2019-02-08T10:34:29.481145231Z');
308
634
  *
309
- * @example <caption>With a `google.protobuf.Timestamp` object</caption>
635
+ * ```
636
+ * @example With a `google.protobuf.Timestamp` object
637
+ * ```
310
638
  * const [seconds, nanos] = process.hrtime();
311
639
  * const timestamp = Spanner.timestamp({seconds, nanos});
640
+ * ```
312
641
  *
313
- * @example <caption>With a Date timestamp</caption>
642
+ * @example With a Date timestamp
643
+ * ```
314
644
  * const timestamp = Spanner.timestamp(Date.now());
645
+ * ```
315
646
  */
316
647
  static timestamp(value?: string | number | p.ITimestamp | PreciseDate): PreciseDate;
317
648
  /**
@@ -321,8 +652,10 @@ declare class Spanner extends GrpcService {
321
652
  * @returns {Float}
322
653
  *
323
654
  * @example
655
+ * ```
324
656
  * const {Spanner} = require('@google-cloud/spanner');
325
657
  * const float = Spanner.float(10);
658
+ * ```
326
659
  */
327
660
  static float(value: any): Float;
328
661
  /**
@@ -332,8 +665,10 @@ declare class Spanner extends GrpcService {
332
665
  * @returns {Int}
333
666
  *
334
667
  * @example
668
+ * ```
335
669
  * const {Spanner} = require('@google-cloud/spanner');
336
670
  * const int = Spanner.int(10);
671
+ * ```
337
672
  */
338
673
  static int(value: any): Int;
339
674
  /**
@@ -343,8 +678,10 @@ declare class Spanner extends GrpcService {
343
678
  * @returns {Numeric}
344
679
  *
345
680
  * @example
681
+ * ```
346
682
  * const {Spanner} = require('@google-cloud/spanner');
347
683
  * const numeric = Spanner.numeric("3.141592653");
684
+ * ```
348
685
  */
349
686
  static numeric(value: any): Numeric;
350
687
  /**
@@ -354,11 +691,13 @@ declare class Spanner extends GrpcService {
354
691
  * @returns {Struct}
355
692
  *
356
693
  * @example
694
+ * ```
357
695
  * const {Spanner} = require('@google-cloud/spanner');
358
696
  * const struct = Spanner.struct({
359
697
  * user: 'bob',
360
698
  * age: 32
361
699
  * });
700
+ * ```
362
701
  */
363
702
  static struct(value?: any): Struct;
364
703
  }
@@ -372,22 +711,32 @@ declare class Spanner extends GrpcService {
372
711
  * @module {constructor} @google-cloud/spanner
373
712
  * @alias nodejs-spanner
374
713
  *
375
- * @example <caption>Install the client library with <a
376
- * href="https://www.npmjs.com/">npm</a>:</caption> npm install --save
377
- * @google-cloud/spanner
714
+ * @example Install the client library with <a
715
+ * href="https://www.npmjs.com/">npm</a>:
716
+ * ```
717
+ * npm install --save @google-cloud/spanner
718
+ * ```
378
719
  *
379
- * @example <caption>Import the client library</caption>
720
+ * @example Import the client library
721
+ * ```
380
722
  * const {Spanner} = require('@google-cloud/spanner');
723
+ * ```
381
724
  *
382
- * @example <caption>Create a client that uses <a
725
+ * @example Create a client that uses <a
383
726
  * href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application
384
- * Default Credentials (ADC)</a>:</caption> const client = new Spanner();
727
+ * Default Credentials (ADC)</a>:
728
+ * ```
729
+ * const client = new Spanner();
730
+ * ```
385
731
  *
386
- * @example <caption>Create a client with <a
732
+ * @example Create a client with <a
387
733
  * href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit
388
- * credentials</a>:</caption> const client = new Spanner({ projectId:
734
+ * credentials</a>:
735
+ * ```
736
+ * const client = new Spanner({ projectId:
389
737
  * 'your-project-id', keyFilename: '/path/to/keyfile.json'
390
738
  * });
739
+ * ```
391
740
  *
392
741
  * @example <caption>include:samples/quickstart.js</caption>
393
742
  * region_tag:spanner_quickstart