@google-cloud/spanner 8.4.0 → 8.6.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.
@@ -23,6 +23,7 @@ const big_js_1 = require("big.js");
23
23
  const protos_1 = require("../protos/protos");
24
24
  const google_gax_1 = require("google-gax");
25
25
  const uuid = require("uuid");
26
+ let uuidUntypedFlagWarned = false;
26
27
  /**
27
28
  * Date-like object used to represent Cloud Spanner Dates. DATE types represent
28
29
  * a logical calendar date, independent of time zone. DATE values do not
@@ -906,8 +907,14 @@ function getType(value) {
906
907
  if ((0, helper_1.isBoolean)(value)) {
907
908
  return { type: 'bool' };
908
909
  }
909
- if (uuid.validate(value)) {
910
- return { type: 'unspecified' };
910
+ if (process.env['SPANNER_ENABLE_UUID_AS_UNTYPED'] === 'true') {
911
+ if (!uuidUntypedFlagWarned) {
912
+ process.emitWarning('SPANNER_ENABLE_UUID_AS_UNTYPED environment variable is deprecated and will be removed in a future release.', 'DeprecationWarning');
913
+ uuidUntypedFlagWarned = true;
914
+ }
915
+ if (uuid.validate(value)) {
916
+ return { type: 'unspecified' };
917
+ }
911
918
  }
912
919
  if ((0, helper_1.isString)(value)) {
913
920
  return { type: 'string' };
@@ -191,7 +191,7 @@ declare class Database extends common.GrpcServiceObject {
191
191
  private _traceConfig;
192
192
  private _nthRequest;
193
193
  _clientId: number;
194
- constructor(instance: Instance, name: string, poolOptions?: SessionPoolConstructor | SessionPoolOptions, queryOptions?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions);
194
+ constructor(instance: Instance, name: string, poolOptions?: SessionPoolConstructor | SessionPoolOptions, queryOptions?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions, databaseRole?: string | null);
195
195
  _nextNthRequest(): number;
196
196
  /**
197
197
  * @typedef {array} SetDatabaseMetadataResponse
@@ -71,7 +71,7 @@ class Database extends common.GrpcServiceObject {
71
71
  _traceConfig;
72
72
  _nthRequest;
73
73
  _clientId;
74
- constructor(instance, name, poolOptions, queryOptions) {
74
+ constructor(instance, name, poolOptions, queryOptions, databaseRole) {
75
75
  const methods = {
76
76
  /**
77
77
  * Create a database.
@@ -159,12 +159,11 @@ class Database extends common.GrpcServiceObject {
159
159
  }
160
160
  },
161
161
  });
162
- if (typeof poolOptions === 'object') {
163
- this.databaseRole = poolOptions.databaseRole || null;
164
- this.labels = poolOptions.labels || null;
165
- }
166
162
  this.formattedName_ = formattedName_;
167
163
  this.instance = instance;
164
+ const poolOpts = typeof poolOptions === 'object' ? poolOptions : null;
165
+ this.databaseRole = databaseRole || poolOpts?.databaseRole || null;
166
+ this.labels = this._getSpanner().sessionLabels || poolOpts?.labels || null;
168
167
  this._observabilityOptions = instance._observabilityOptions;
169
168
  this._traceConfig = {
170
169
  opts: this._observabilityOptions,
@@ -230,7 +229,7 @@ class Database extends common.GrpcServiceObject {
230
229
  options = { count: options };
231
230
  }
232
231
  const count = options.count;
233
- const labels = options.labels || {};
232
+ const labels = options.labels || this.labels || null;
234
233
  const databaseRole = options.databaseRole || this.databaseRole || null;
235
234
  const reqOpts = {
236
235
  database: this.formattedName_,
@@ -67,6 +67,9 @@ export interface SpannerOptions extends GrpcClientOptions {
67
67
  observabilityOptions?: ObservabilityOptions;
68
68
  disableBuiltInMetrics?: boolean;
69
69
  interceptors?: any[];
70
+ sessionLabels?: {
71
+ [key: string]: string;
72
+ };
70
73
  /**
71
74
  * The Trusted Cloud Domain (TPC) DNS of the service used to make requests.
72
75
  * Defaults to `googleapis.com`.
@@ -186,6 +189,9 @@ declare class Spanner extends GrpcService {
186
189
  directedReadOptions: google.spanner.v1.IDirectedReadOptions | null;
187
190
  defaultTransactionOptions: RunTransactionOptions;
188
191
  _observabilityOptions: ObservabilityOptions | undefined;
192
+ sessionLabels: {
193
+ [key: string]: string;
194
+ } | null;
189
195
  private _universeDomain;
190
196
  private _isInSecureCredentials;
191
197
  private static _isAFEServerTimingEnabled;
@@ -160,6 +160,7 @@ class Spanner extends service_1.GrpcService {
160
160
  directedReadOptions;
161
161
  defaultTransactionOptions;
162
162
  _observabilityOptions;
163
+ sessionLabels;
163
164
  _universeDomain;
164
165
  _isInSecureCredentials;
165
166
  static _isAFEServerTimingEnabled;
@@ -301,6 +302,7 @@ class Spanner extends service_1.GrpcService {
301
302
  this.directedReadOptions = directedReadOptions;
302
303
  this.defaultTransactionOptions = defaultTransactionOptions;
303
304
  this._observabilityOptions = options.observabilityOptions;
305
+ this.sessionLabels = options.sessionLabels || null;
304
306
  this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.projectFormattedName_, this._observabilityOptions?.enableEndToEndTracing);
305
307
  (0, instrument_1.ensureInitialContextManagerSet)();
306
308
  this._nthClientId = (0, request_id_header_1.nextSpannerClientId)();
@@ -439,7 +439,7 @@ declare class Instance extends common.GrpcServiceObject {
439
439
  * const database = instance.database('my-database');
440
440
  * ```
441
441
  */
442
- database(name: string, poolOptions?: SessionPoolOptions | SessionPoolConstructor, queryOptions?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions): Database;
442
+ database(name: string, poolOptions?: SessionPoolOptions | SessionPoolConstructor, queryOptions?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions, databaseRole?: string | null): Database;
443
443
  /**
444
444
  * @typedef {array} DeleteInstanceResponse
445
445
  * @property {object} 0 The full API response.
@@ -504,7 +504,7 @@ class Instance extends common.GrpcServiceObject {
504
504
  * const database = instance.database('my-database');
505
505
  * ```
506
506
  */
507
- database(name, poolOptions, queryOptions) {
507
+ database(name, poolOptions, queryOptions, databaseRole) {
508
508
  if (!name) {
509
509
  throw new google_gax_1.GoogleError('A name is required to access a Database object.');
510
510
  }
@@ -519,7 +519,7 @@ class Instance extends common.GrpcServiceObject {
519
519
  }
520
520
  const key = name.split('/').pop() + optionsKey;
521
521
  if (!this.databases_.has(key)) {
522
- const db = new database_1.Database(this, name, poolOptions, queryOptions);
522
+ const db = new database_1.Database(this, name, poolOptions, queryOptions, databaseRole);
523
523
  db._observabilityOptions = this._observabilityOptions;
524
524
  const parent = this.parent;
525
525
  if (parent && parent._nthClientId) {
@@ -87,6 +87,7 @@ function startTrace(spanNameSuffix, config, cb) {
87
87
  span.setAttribute('db.sql.table', config.tableName);
88
88
  }
89
89
  if (config.dbName) {
90
+ span.setAttribute('gcp.resource.name', `//spanner.googleapis.com/${config.dbName}`);
90
91
  span.setAttribute('db.name', config.dbName);
91
92
  }
92
93
  if (config.requestTag) {
@@ -93,7 +93,7 @@ class PartialResultStream extends stream_1.Transform {
93
93
  res = this._addChunk(chunk);
94
94
  }
95
95
  if (chunk.last) {
96
- this.emit('end');
96
+ this.push(null);
97
97
  return;
98
98
  }
99
99
  if (res) {
@@ -128,6 +128,9 @@ export interface SessionPoolOptions {
128
128
  fail?: boolean;
129
129
  idlesAfter?: number;
130
130
  keepAlive?: number;
131
+ /**
132
+ * @deprecated Use SpannerOptions.sessionLabels instead.
133
+ */
131
134
  labels?: {
132
135
  [label: string]: string;
133
136
  };
@@ -140,6 +143,9 @@ export interface SessionPoolOptions {
140
143
  */
141
144
  writes?: number;
142
145
  incStep?: number;
146
+ /**
147
+ * @deprecated Use Database constructor to pass databaseRole.
148
+ */
143
149
  databaseRole?: string | null;
144
150
  }
145
151
  /**
@@ -29,12 +29,10 @@ const DEFAULTS = {
29
29
  fail: false,
30
30
  idlesAfter: 10,
31
31
  keepAlive: 30,
32
- labels: {},
33
32
  max: 100,
34
33
  maxIdle: 1,
35
34
  min: 25,
36
35
  incStep: 25,
37
- databaseRole: null,
38
36
  };
39
37
  /**
40
38
  * Error to be thrown when attempting to release unknown resources.
@@ -1088,12 +1088,17 @@ class Snapshot extends events_1.EventEmitter {
1088
1088
  if (!(0, helper_1.isEmpty)(typeMap)) {
1089
1089
  Object.keys(typeMap).forEach(param => {
1090
1090
  const type = typeMap[param];
1091
- const typeObject = codec_1.codec.createTypeObject(type);
1092
- if ((type.child &&
1093
- typeObject.code === 'ARRAY' &&
1094
- typeObject.arrayElementType?.code !== 'TYPE_CODE_UNSPECIFIED') ||
1095
- (!type.child && typeObject.code !== 'TYPE_CODE_UNSPECIFIED')) {
1096
- paramTypes[param] = typeObject;
1091
+ if (process.env['SPANNER_ENABLE_UUID_AS_UNTYPED'] === 'true') {
1092
+ const typeObject = codec_1.codec.createTypeObject(type);
1093
+ if ((type.child &&
1094
+ typeObject.code === 'ARRAY' &&
1095
+ typeObject.arrayElementType?.code !== 'TYPE_CODE_UNSPECIFIED') ||
1096
+ (!type.child && typeObject.code !== 'TYPE_CODE_UNSPECIFIED')) {
1097
+ paramTypes[param] = typeObject;
1098
+ }
1099
+ }
1100
+ else {
1101
+ paramTypes[param] = codec_1.codec.createTypeObject(type);
1097
1102
  }
1098
1103
  });
1099
1104
  }
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2025 Google LLC
2
+ // Copyright 2026 Google LLC
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
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": "8.4.0",
4
+ "version": "8.6.0",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Google Inc.",
7
7
  "engines": {