@google-cloud/spanner 7.1.0 → 7.2.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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,20 @@
4
4
 
5
5
  [1]: https://www.npmjs.com/package/nodejs-spanner?activeTab=versions
6
6
 
7
+ ## [7.2.0](https://github.com/googleapis/nodejs-spanner/compare/v7.1.0...v7.2.0) (2024-01-11)
8
+
9
+
10
+ ### Features
11
+
12
+ * Support for Directed Reads ([#1966](https://github.com/googleapis/nodejs-spanner/issues/1966)) ([c0a4363](https://github.com/googleapis/nodejs-spanner/commit/c0a43638c81dd769cc55e021cc4cf1d93db8a72a))
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **deps:** Update dependency @google-cloud/precise-date to v4 ([#1903](https://github.com/googleapis/nodejs-spanner/issues/1903)) ([7464c8b](https://github.com/googleapis/nodejs-spanner/commit/7464c8b2412a9b718cd8981363cb982aebbe3723))
18
+ * **deps:** Update dependency @types/stack-trace to v0.0.33 ([#1952](https://github.com/googleapis/nodejs-spanner/issues/1952)) ([45ab751](https://github.com/googleapis/nodejs-spanner/commit/45ab751da1f0f73bc06c8b8e0007b457fa75518f))
19
+ * **deps:** Update dependency retry-request to v7 ([#1934](https://github.com/googleapis/nodejs-spanner/issues/1934)) ([c575c80](https://github.com/googleapis/nodejs-spanner/commit/c575c80b17e5fdf2cbba24c806fa21f26c2010dc))
20
+
7
21
  ## [7.1.0](https://github.com/googleapis/nodejs-spanner/compare/v7.0.0...v7.1.0) (2023-11-16)
8
22
 
9
23
 
package/README.md CHANGED
@@ -112,6 +112,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-spanner/tre
112
112
  | Updates the default leader of an existing database | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/database-update-default-leader.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/database-update-default-leader.js,samples/README.md) |
113
113
  | Updates a Cloud Spanner Database. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/database-update.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/database-update.js,samples/README.md) |
114
114
  | Datatypes | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/datatypes.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/datatypes.js,samples/README.md) |
115
+ | Runs an execute sql request with directed read options | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/directed-reads.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/directed-reads.js,samples/README.md) |
115
116
  | Delete using DML returning. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/dml-returning-delete.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/dml-returning-delete.js,samples/README.md) |
116
117
  | Insert using DML returning. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/dml-returning-insert.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/dml-returning-insert.js,samples/README.md) |
117
118
  | Update using DML returning. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/dml-returning-update.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/dml-returning-update.js,samples/README.md) |
@@ -1,4 +1,4 @@
1
- // Copyright 2023 Google LLC
1
+ // Copyright 2024 Google LLC
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- // Copyright 2023 Google LLC
1
+ // Copyright 2024 Google LLC
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -117,8 +117,8 @@ const GRPC_ERROR_CODE_TO_HTTP = {
117
117
  */
118
118
  const GRPC_SERVICE_OPTIONS = {
119
119
  // RE: https://github.com/GoogleCloudPlatform/google-cloud-node/issues/1991
120
- 'grpc.max_send_message_length': -1,
121
- 'grpc.max_receive_message_length': -1,
120
+ 'grpc.max_send_message_length': -1, // unlimited
121
+ 'grpc.max_receive_message_length': -1, // unlimited
122
122
  // RE: https://github.com/grpc/grpc/issues/8839
123
123
  // RE: https://github.com/grpc/grpc/issues/8382
124
124
  // RE: https://github.com/GoogleCloudPlatform/google-cloud-node/issues/1991
@@ -50,6 +50,9 @@ export type GetInstanceConfigOperationsCallback = PagedCallback<IOperation, inst
50
50
  * Session pool configuration options.
51
51
  * @property {boolean} [routeToLeaderEnabled=True] If set to false leader aware routing will be disabled.
52
52
  * Disabling leader aware routing would route all requests in RW/PDML transactions to any region.
53
+ * @property {google.spanner.v1.IDirectedReadOptions} [directedReadOptions] Sets the DirectedReadOptions for all ReadRequests and ExecuteSqlRequests for the Client.
54
+ * Indicates which replicas or regions should be used for non-transactional reads or queries.
55
+ * DirectedReadOptions won't be set for readWrite transactions"
53
56
  */
54
57
  export interface SpannerOptions extends GrpcClientOptions {
55
58
  apiEndpoint?: string;
@@ -57,6 +60,7 @@ export interface SpannerOptions extends GrpcClientOptions {
57
60
  port?: number;
58
61
  sslCreds?: grpc.ChannelCredentials;
59
62
  routeToLeaderEnabled?: boolean;
63
+ directedReadOptions?: google.spanner.v1.IDirectedReadOptions | null;
60
64
  }
61
65
  export interface RequestConfig {
62
66
  client: string;
@@ -161,6 +165,7 @@ declare class Spanner extends GrpcService {
161
165
  [k: string]: string;
162
166
  };
163
167
  routeToLeaderEnabled: boolean;
168
+ directedReadOptions: google.spanner.v1.IDirectedReadOptions | null;
164
169
  /**
165
170
  * Placeholder used to auto populate a column with the commit timestamp.
166
171
  * This can only be used for timestamp columns that have set the option
@@ -150,6 +150,10 @@ class Spanner extends service_1.GrpcService {
150
150
  'grpc.gcpApiConfig': grpcGcp.createGcpApiConfig(gcpApiConfig),
151
151
  grpc: google_gax_1.grpc,
152
152
  }, options || {});
153
+ const directedReadOptions = options.directedReadOptions
154
+ ? options.directedReadOptions
155
+ : null;
156
+ delete options.directedReadOptions;
153
157
  const emulatorHost = Spanner.getSpannerEmulatorHost();
154
158
  if (emulatorHost &&
155
159
  emulatorHost.endpoint &&
@@ -187,6 +191,7 @@ class Spanner extends service_1.GrpcService {
187
191
  this.resourceHeader_ = {
188
192
  [common_1.CLOUD_RESOURCE_HEADER]: this.projectFormattedName_,
189
193
  };
194
+ this.directedReadOptions = directedReadOptions;
190
195
  }
191
196
  /** Closes this Spanner client and cleans up all resources used by it. */
192
197
  close() {
@@ -758,7 +758,9 @@ class SessionPool extends events_1.EventEmitter {
758
758
  * @private
759
759
  */
760
760
  _stopHouseKeeping() {
761
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
761
762
  clearInterval(this._pingHandle);
763
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
762
764
  clearInterval(this._evictHandle);
763
765
  }
764
766
  }
@@ -68,6 +68,7 @@ export interface ExecuteSqlRequest extends Statement, RequestOptions {
68
68
  queryOptions?: IQueryOptions;
69
69
  requestOptions?: Omit<IRequestOptions, 'transactionTag'>;
70
70
  dataBoostEnabled?: boolean | null;
71
+ directedReadOptions?: google.spanner.v1.IDirectedReadOptions;
71
72
  }
72
73
  export interface KeyRange {
73
74
  startClosed?: Value[];
@@ -87,6 +88,7 @@ export interface ReadRequest extends RequestOptions {
87
88
  partitionToken?: Uint8Array | null;
88
89
  requestOptions?: Omit<IRequestOptions, 'transactionTag'>;
89
90
  dataBoostEnabled?: boolean | null;
91
+ directedReadOptions?: google.spanner.v1.IDirectedReadOptions;
90
92
  }
91
93
  export interface BatchUpdateError extends grpc.ServiceError {
92
94
  rowCounts: number[];
@@ -340,6 +342,8 @@ export declare class Snapshot extends EventEmitter {
340
342
  * PartitionReadRequest message used to create this partition_token.
341
343
  * @property {google.spanner.v1.RequestOptions} [requestOptions]
342
344
  * Common options for this request.
345
+ * @property {google.spanner.v1.IDirectedReadOptions} [directedReadOptions]
346
+ * Indicates which replicas or regions should be used for non-transactional reads or queries.
343
347
  * @property {object} [gaxOptions]
344
348
  * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
345
349
  * for more details.
@@ -740,6 +744,8 @@ export declare class Snapshot extends EventEmitter {
740
744
  * that it is not ready for any more data. Increase this value if you
741
745
  * experience 'Stream is still not ready to receive data' errors as a
742
746
  * result of a slow writer in your receiving stream.
747
+ * @property {object} [directedReadOptions]
748
+ * Indicates which replicas or regions should be used for non-transactional reads or queries.
743
749
  */
744
750
  /**
745
751
  * Create a readable object stream to receive resulting rows from a SQL
@@ -841,6 +847,12 @@ export declare class Snapshot extends EventEmitter {
841
847
  [field: string]: spannerClient.spanner.v1.Type;
842
848
  };
843
849
  };
850
+ /**
851
+ * Get directed read options
852
+ * @private
853
+ * @param {google.spanner.v1.IDirectedReadOptions} directedReadOptions Request directedReadOptions object.
854
+ */
855
+ protected _getDirectedReadOptions(directedReadOptions: google.spanner.v1.IDirectedReadOptions | null | undefined): spannerClient.spanner.v1.IDirectedReadOptions | null | undefined;
844
856
  /**
845
857
  * Update transaction properties from the response.
846
858
  *
@@ -233,6 +233,8 @@ class Snapshot extends events_1.EventEmitter {
233
233
  * PartitionReadRequest message used to create this partition_token.
234
234
  * @property {google.spanner.v1.RequestOptions} [requestOptions]
235
235
  * Common options for this request.
236
+ * @property {google.spanner.v1.IDirectedReadOptions} [directedReadOptions]
237
+ * Indicates which replicas or regions should be used for non-transactional reads or queries.
236
238
  * @property {object} [gaxOptions]
237
239
  * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
238
240
  * for more details.
@@ -364,6 +366,7 @@ class Snapshot extends events_1.EventEmitter {
364
366
  else {
365
367
  transaction.singleUse = this._options;
366
368
  }
369
+ const directedReadOptions = this._getDirectedReadOptions(request.directedReadOptions);
367
370
  request = Object.assign({}, request);
368
371
  delete request.gaxOptions;
369
372
  delete request.json;
@@ -372,9 +375,11 @@ class Snapshot extends events_1.EventEmitter {
372
375
  delete request.keys;
373
376
  delete request.ranges;
374
377
  delete request.requestOptions;
378
+ delete request.directedReadOptions;
375
379
  const reqOpts = Object.assign(request, {
376
380
  session: this.session.formattedName_,
377
381
  requestOptions: this.configureTagOptions(typeof transaction.singleUse !== 'undefined', (_b = (_a = this.requestOptions) === null || _a === void 0 ? void 0 : _a.transactionTag) !== null && _b !== void 0 ? _b : undefined, requestOptions),
382
+ directedReadOptions: directedReadOptions,
378
383
  transaction,
379
384
  table,
380
385
  keySet,
@@ -536,6 +541,8 @@ class Snapshot extends events_1.EventEmitter {
536
541
  * that it is not ready for any more data. Increase this value if you
537
542
  * experience 'Stream is still not ready to receive data' errors as a
538
543
  * result of a slow writer in your receiving stream.
544
+ * @property {object} [directedReadOptions]
545
+ * Indicates which replicas or regions should be used for non-transactional reads or queries.
539
546
  */
540
547
  /**
541
548
  * Create a readable object stream to receive resulting rows from a SQL
@@ -604,6 +611,7 @@ class Snapshot extends events_1.EventEmitter {
604
611
  query.queryOptions = Object.assign(Object.assign({}, this.queryOptions), query.queryOptions);
605
612
  const { gaxOptions, json, jsonOptions, maxResumeRetries, requestOptions } = query;
606
613
  let reqOpts;
614
+ const directedReadOptions = this._getDirectedReadOptions(query.directedReadOptions);
607
615
  const sanitizeRequest = () => {
608
616
  var _a, _b;
609
617
  query = query;
@@ -624,10 +632,12 @@ class Snapshot extends events_1.EventEmitter {
624
632
  delete query.maxResumeRetries;
625
633
  delete query.requestOptions;
626
634
  delete query.types;
635
+ delete query.directedReadOptions;
627
636
  reqOpts = Object.assign(query, {
628
637
  session: this.session.formattedName_,
629
638
  seqno: this._seqno++,
630
639
  requestOptions: this.configureTagOptions(typeof transaction.singleUse !== 'undefined', (_b = (_a = this.requestOptions) === null || _a === void 0 ? void 0 : _a.transactionTag) !== null && _b !== void 0 ? _b : undefined, requestOptions),
640
+ directedReadOptions: directedReadOptions,
631
641
  transaction,
632
642
  params,
633
643
  paramTypes,
@@ -776,6 +786,19 @@ class Snapshot extends events_1.EventEmitter {
776
786
  }
777
787
  return { params, paramTypes };
778
788
  }
789
+ /**
790
+ * Get directed read options
791
+ * @private
792
+ * @param {google.spanner.v1.IDirectedReadOptions} directedReadOptions Request directedReadOptions object.
793
+ */
794
+ _getDirectedReadOptions(directedReadOptions) {
795
+ if (!directedReadOptions &&
796
+ this._getSpanner().directedReadOptions &&
797
+ this._options.readOnly) {
798
+ return this._getSpanner().directedReadOptions;
799
+ }
800
+ return directedReadOptions;
801
+ }
779
802
  /**
780
803
  * Update transaction properties from the response.
781
804
  *
@@ -978,7 +1001,7 @@ class Transaction extends Dml {
978
1001
  const rowCounts = [];
979
1002
  const error = new Error('batchUpdate requires at least 1 DML statement.');
980
1003
  const batchError = Object.assign(error, {
981
- code: 3,
1004
+ code: 3, // invalid argument
982
1005
  rowCounts,
983
1006
  });
984
1007
  callback(batchError, rowCounts);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@google-cloud/spanner",
3
3
  "description": "Cloud Spanner Client Library for Node.js",
4
- "version": "7.1.0",
4
+ "version": "7.2.0",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Google Inc.",
7
7
  "engines": {
@@ -52,12 +52,12 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@google-cloud/common": "^5.0.0",
55
- "@google-cloud/precise-date": "^3.0.0",
55
+ "@google-cloud/precise-date": "^4.0.0",
56
56
  "@google-cloud/projectify": "^4.0.0",
57
57
  "@google-cloud/promisify": "^4.0.0",
58
58
  "@grpc/proto-loader": "^0.7.0",
59
59
  "@types/big.js": "^6.0.0",
60
- "@types/stack-trace": "0.0.32",
60
+ "@types/stack-trace": "0.0.33",
61
61
  "arrify": "^2.0.0",
62
62
  "big.js": "^6.0.0",
63
63
  "checkpoint-stream": "^0.1.1",
@@ -72,7 +72,7 @@
72
72
  "merge-stream": "^2.0.0",
73
73
  "p-queue": "^6.0.2",
74
74
  "protobufjs": "^7.0.0",
75
- "retry-request": "^6.0.0",
75
+ "retry-request": "^7.0.0",
76
76
  "split-array-stream": "^2.0.0",
77
77
  "stack-trace": "0.0.10",
78
78
  "stream-events": "^1.0.4",
@@ -82,7 +82,7 @@
82
82
  "devDependencies": {
83
83
  "@types/concat-stream": "^2.0.0",
84
84
  "@types/extend": "^3.0.0",
85
- "@types/is": "0.0.24",
85
+ "@types/is": "0.0.25",
86
86
  "@types/lodash.snakecase": "^4.1.4",
87
87
  "@types/merge-stream": "^1.1.2",
88
88
  "@types/mocha": "^9.0.0",
@@ -97,12 +97,12 @@
97
97
  "c8": "^8.0.1",
98
98
  "codecov": "^3.0.2",
99
99
  "concat-stream": "^2.0.0",
100
- "dedent": "^0.7.0",
100
+ "dedent": "^1.0.0",
101
101
  "execa": "^5.0.0",
102
102
  "gapic-tools": "^0.2.0",
103
103
  "gts": "^5.0.0",
104
104
  "jsdoc": "^4.0.0",
105
- "jsdoc-fresh": "^2.0.0",
105
+ "jsdoc-fresh": "^3.0.0",
106
106
  "jsdoc-region-tag": "^3.0.0",
107
107
  "linkinator": "^4.0.0",
108
108
  "lodash.random": "^3.2.0",