@google-cloud/spanner 7.13.0 → 7.15.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 +36 -0
- package/README.md +14 -2
- package/build/protos/google/spanner/admin/database/v1/backup.proto +9 -2
- package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +203 -62
- package/build/protos/protos.d.ts +338 -144
- package/build/protos/protos.js +864 -339
- package/build/protos/protos.json +83 -1
- package/build/src/batch-transaction.d.ts +1 -0
- package/build/src/batch-transaction.js +90 -50
- package/build/src/database.d.ts +5 -2
- package/build/src/database.js +430 -235
- package/build/src/index.d.ts +5 -0
- package/build/src/index.js +4 -0
- package/build/src/instance.d.ts +2 -0
- package/build/src/instance.js +6 -1
- package/build/src/instrument.d.ts +84 -0
- package/build/src/instrument.js +213 -0
- package/build/src/session-pool.d.ts +2 -0
- package/build/src/session-pool.js +61 -23
- package/build/src/session.js +1 -7
- package/build/src/table.d.ts +3 -0
- package/build/src/table.js +34 -14
- package/build/src/transaction.d.ts +3 -0
- package/build/src/transaction.js +411 -194
- package/build/src/v1/database_admin_client.d.ts +9 -0
- package/build/src/v1/database_admin_client.js +6 -0
- package/build/src/v1/instance_admin_client.d.ts +141 -43
- package/build/src/v1/instance_admin_client.js +44 -4
- package/build/src/v1/instance_admin_client_config.json +4 -0
- package/package.json +13 -4
package/build/protos/protos.json
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
+
"options": {
|
|
3
|
+
"syntax": "proto3"
|
|
4
|
+
},
|
|
2
5
|
"nested": {
|
|
3
6
|
"google": {
|
|
4
7
|
"nested": {
|
|
@@ -1740,7 +1743,8 @@
|
|
|
1740
1743
|
"type": "string",
|
|
1741
1744
|
"id": 14,
|
|
1742
1745
|
"options": {
|
|
1743
|
-
"(google.api.field_behavior)": "OUTPUT_ONLY"
|
|
1746
|
+
"(google.api.field_behavior)": "OUTPUT_ONLY",
|
|
1747
|
+
"(google.api.resource_reference).type": "spanner.googleapis.com/BackupSchedule"
|
|
1744
1748
|
}
|
|
1745
1749
|
},
|
|
1746
1750
|
"incrementalBackupChainId": {
|
|
@@ -4046,6 +4050,30 @@
|
|
|
4046
4050
|
"(google.api.method_signature)": "parent"
|
|
4047
4051
|
}
|
|
4048
4052
|
]
|
|
4053
|
+
},
|
|
4054
|
+
"MoveInstance": {
|
|
4055
|
+
"requestType": "MoveInstanceRequest",
|
|
4056
|
+
"responseType": "google.longrunning.Operation",
|
|
4057
|
+
"options": {
|
|
4058
|
+
"(google.api.http).post": "/v1/{name=projects/*/instances/*}:move",
|
|
4059
|
+
"(google.api.http).body": "*",
|
|
4060
|
+
"(google.longrunning.operation_info).response_type": "google.spanner.admin.instance.v1.MoveInstanceResponse",
|
|
4061
|
+
"(google.longrunning.operation_info).metadata_type": "google.spanner.admin.instance.v1.MoveInstanceMetadata"
|
|
4062
|
+
},
|
|
4063
|
+
"parsedOptions": [
|
|
4064
|
+
{
|
|
4065
|
+
"(google.api.http)": {
|
|
4066
|
+
"post": "/v1/{name=projects/*/instances/*}:move",
|
|
4067
|
+
"body": "*"
|
|
4068
|
+
}
|
|
4069
|
+
},
|
|
4070
|
+
{
|
|
4071
|
+
"(google.longrunning.operation_info)": {
|
|
4072
|
+
"response_type": "google.spanner.admin.instance.v1.MoveInstanceResponse",
|
|
4073
|
+
"metadata_type": "google.spanner.admin.instance.v1.MoveInstanceMetadata"
|
|
4074
|
+
}
|
|
4075
|
+
}
|
|
4076
|
+
]
|
|
4049
4077
|
}
|
|
4050
4078
|
}
|
|
4051
4079
|
},
|
|
@@ -4307,6 +4335,13 @@
|
|
|
4307
4335
|
"options": {
|
|
4308
4336
|
"(google.api.field_behavior)": "OUTPUT_ONLY"
|
|
4309
4337
|
}
|
|
4338
|
+
},
|
|
4339
|
+
"edition": {
|
|
4340
|
+
"type": "Edition",
|
|
4341
|
+
"id": 20,
|
|
4342
|
+
"options": {
|
|
4343
|
+
"(google.api.field_behavior)": "OPTIONAL"
|
|
4344
|
+
}
|
|
4310
4345
|
}
|
|
4311
4346
|
},
|
|
4312
4347
|
"nested": {
|
|
@@ -4316,6 +4351,14 @@
|
|
|
4316
4351
|
"CREATING": 1,
|
|
4317
4352
|
"READY": 2
|
|
4318
4353
|
}
|
|
4354
|
+
},
|
|
4355
|
+
"Edition": {
|
|
4356
|
+
"values": {
|
|
4357
|
+
"EDITION_UNSPECIFIED": 0,
|
|
4358
|
+
"STANDARD": 1,
|
|
4359
|
+
"ENTERPRISE": 2,
|
|
4360
|
+
"ENTERPRISE_PLUS": 3
|
|
4361
|
+
}
|
|
4319
4362
|
}
|
|
4320
4363
|
}
|
|
4321
4364
|
},
|
|
@@ -4981,6 +5024,45 @@
|
|
|
4981
5024
|
"id": 3
|
|
4982
5025
|
}
|
|
4983
5026
|
}
|
|
5027
|
+
},
|
|
5028
|
+
"MoveInstanceRequest": {
|
|
5029
|
+
"fields": {
|
|
5030
|
+
"name": {
|
|
5031
|
+
"type": "string",
|
|
5032
|
+
"id": 1,
|
|
5033
|
+
"options": {
|
|
5034
|
+
"(google.api.field_behavior)": "REQUIRED",
|
|
5035
|
+
"(google.api.resource_reference).type": "spanner.googleapis.com/Instance"
|
|
5036
|
+
}
|
|
5037
|
+
},
|
|
5038
|
+
"targetConfig": {
|
|
5039
|
+
"type": "string",
|
|
5040
|
+
"id": 2,
|
|
5041
|
+
"options": {
|
|
5042
|
+
"(google.api.field_behavior)": "REQUIRED",
|
|
5043
|
+
"(google.api.resource_reference).type": "spanner.googleapis.com/InstanceConfig"
|
|
5044
|
+
}
|
|
5045
|
+
}
|
|
5046
|
+
}
|
|
5047
|
+
},
|
|
5048
|
+
"MoveInstanceResponse": {
|
|
5049
|
+
"fields": {}
|
|
5050
|
+
},
|
|
5051
|
+
"MoveInstanceMetadata": {
|
|
5052
|
+
"fields": {
|
|
5053
|
+
"targetConfig": {
|
|
5054
|
+
"type": "string",
|
|
5055
|
+
"id": 1
|
|
5056
|
+
},
|
|
5057
|
+
"progress": {
|
|
5058
|
+
"type": "OperationProgress",
|
|
5059
|
+
"id": 2
|
|
5060
|
+
},
|
|
5061
|
+
"cancelTime": {
|
|
5062
|
+
"type": "google.protobuf.Timestamp",
|
|
5063
|
+
"id": 3
|
|
5064
|
+
}
|
|
5065
|
+
}
|
|
4984
5066
|
}
|
|
4985
5067
|
}
|
|
4986
5068
|
}
|
|
@@ -109,6 +109,7 @@ declare class BatchTransaction extends Snapshot {
|
|
|
109
109
|
* region_tag:spanner_batch_client
|
|
110
110
|
*/
|
|
111
111
|
createQueryPartitions(query: any, callback: any): void;
|
|
112
|
+
protected getDBName(): string;
|
|
112
113
|
/**
|
|
113
114
|
* Generic create partition method. Handles common parameters used in both
|
|
114
115
|
* {@link BatchTransaction#createQueryPartitions} and {@link
|
|
@@ -22,6 +22,7 @@ const extend = require("extend");
|
|
|
22
22
|
const is = require("is");
|
|
23
23
|
const transaction_1 = require("./transaction");
|
|
24
24
|
const common_1 = require("../src/common");
|
|
25
|
+
const instrument_1 = require("./instrument");
|
|
25
26
|
/**
|
|
26
27
|
* Use a BatchTransaction object to create partitions and read/query against
|
|
27
28
|
* your Cloud Spanner database.
|
|
@@ -123,17 +124,33 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
123
124
|
const reqOpts = Object.assign({}, query, transaction_1.Snapshot.encodeParams(query));
|
|
124
125
|
delete reqOpts.gaxOptions;
|
|
125
126
|
delete reqOpts.types;
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
127
|
+
const traceConfig = {
|
|
128
|
+
sql: query,
|
|
129
|
+
opts: this._observabilityOptions,
|
|
130
|
+
dbName: this.getDBName(),
|
|
131
|
+
};
|
|
132
|
+
return (0, instrument_1.startTrace)('BatchTransaction.createQueryPartitions', traceConfig, span => {
|
|
133
|
+
const headers = {};
|
|
134
|
+
if (this._getSpanner().routeToLeaderEnabled) {
|
|
135
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
136
|
+
}
|
|
137
|
+
this.createPartitions_({
|
|
138
|
+
client: 'SpannerClient',
|
|
139
|
+
method: 'partitionQuery',
|
|
140
|
+
reqOpts,
|
|
141
|
+
gaxOpts: query.gaxOptions,
|
|
142
|
+
headers: headers,
|
|
143
|
+
}, (err, partitions, resp) => {
|
|
144
|
+
if (err) {
|
|
145
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
146
|
+
}
|
|
147
|
+
span.end();
|
|
148
|
+
callback(err, partitions, resp);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
getDBName() {
|
|
153
|
+
return this.session.parent.formattedName_;
|
|
137
154
|
}
|
|
138
155
|
/**
|
|
139
156
|
* Generic create partition method. Handles common parameters used in both
|
|
@@ -146,32 +163,42 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
146
163
|
* @param {function} callback Callback function.
|
|
147
164
|
*/
|
|
148
165
|
createPartitions_(config, callback) {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
});
|
|
153
|
-
config.reqOpts = extend({}, query);
|
|
154
|
-
config.headers = {
|
|
155
|
-
[common_1.CLOUD_RESOURCE_HEADER]: this.session.parent.formattedName_,
|
|
166
|
+
const traceConfig = {
|
|
167
|
+
opts: this._observabilityOptions,
|
|
168
|
+
dbName: this.getDBName(),
|
|
156
169
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const partitions = resp.partitions.map(partition => {
|
|
164
|
-
return extend({}, query, partition);
|
|
170
|
+
return (0, instrument_1.startTrace)('BatchTransaction.createPartitions_', traceConfig, span => {
|
|
171
|
+
const query = extend({}, config.reqOpts, {
|
|
172
|
+
session: this.session.formattedName_,
|
|
173
|
+
transaction: { id: this.id },
|
|
165
174
|
});
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
this.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
175
|
+
config.reqOpts = extend({}, query);
|
|
176
|
+
config.headers = {
|
|
177
|
+
[common_1.CLOUD_RESOURCE_HEADER]: this.session.parent
|
|
178
|
+
.formattedName_,
|
|
179
|
+
};
|
|
180
|
+
delete query.partitionOptions;
|
|
181
|
+
this.session.request(config, (err, resp) => {
|
|
182
|
+
if (err) {
|
|
183
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
184
|
+
span.end();
|
|
185
|
+
callback(err, null, resp);
|
|
186
|
+
return;
|
|
172
187
|
}
|
|
173
|
-
|
|
174
|
-
|
|
188
|
+
const partitions = resp.partitions.map(partition => {
|
|
189
|
+
return extend({}, query, partition);
|
|
190
|
+
});
|
|
191
|
+
if (resp.transaction) {
|
|
192
|
+
const { id, readTimestamp } = resp.transaction;
|
|
193
|
+
this.id = id;
|
|
194
|
+
if (readTimestamp) {
|
|
195
|
+
this.readTimestampProto = readTimestamp;
|
|
196
|
+
this.readTimestamp = new precise_date_1.PreciseDate(readTimestamp);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
span.end();
|
|
200
|
+
callback(null, partitions, resp);
|
|
201
|
+
});
|
|
175
202
|
});
|
|
176
203
|
}
|
|
177
204
|
/**
|
|
@@ -204,23 +231,35 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
204
231
|
* @returns {Promise<CreateReadPartitionsResponse>}
|
|
205
232
|
*/
|
|
206
233
|
createReadPartitions(options, callback) {
|
|
207
|
-
const
|
|
208
|
-
|
|
234
|
+
const traceConfig = {
|
|
235
|
+
opts: this._observabilityOptions,
|
|
236
|
+
dbName: this.getDBName(),
|
|
237
|
+
};
|
|
238
|
+
return (0, instrument_1.startTrace)('BatchTransaction.createReadPartitions', traceConfig, span => {
|
|
239
|
+
const reqOpts = Object.assign({}, options, {
|
|
240
|
+
keySet: transaction_1.Snapshot.encodeKeySet(options),
|
|
241
|
+
});
|
|
242
|
+
delete reqOpts.gaxOptions;
|
|
243
|
+
delete reqOpts.keys;
|
|
244
|
+
delete reqOpts.ranges;
|
|
245
|
+
const headers = {};
|
|
246
|
+
if (this._getSpanner().routeToLeaderEnabled) {
|
|
247
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
248
|
+
}
|
|
249
|
+
this.createPartitions_({
|
|
250
|
+
client: 'SpannerClient',
|
|
251
|
+
method: 'partitionRead',
|
|
252
|
+
reqOpts,
|
|
253
|
+
gaxOpts: options.gaxOptions,
|
|
254
|
+
headers: headers,
|
|
255
|
+
}, (err, partitions, resp) => {
|
|
256
|
+
if (err) {
|
|
257
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
258
|
+
}
|
|
259
|
+
span.end();
|
|
260
|
+
callback(err, partitions, resp);
|
|
261
|
+
});
|
|
209
262
|
});
|
|
210
|
-
delete reqOpts.gaxOptions;
|
|
211
|
-
delete reqOpts.keys;
|
|
212
|
-
delete reqOpts.ranges;
|
|
213
|
-
const headers = {};
|
|
214
|
-
if (this._getSpanner().routeToLeaderEnabled) {
|
|
215
|
-
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
216
|
-
}
|
|
217
|
-
this.createPartitions_({
|
|
218
|
-
client: 'SpannerClient',
|
|
219
|
-
method: 'partitionRead',
|
|
220
|
-
reqOpts,
|
|
221
|
-
gaxOpts: options.gaxOptions,
|
|
222
|
-
headers: headers,
|
|
223
|
-
}, callback);
|
|
224
263
|
}
|
|
225
264
|
/**
|
|
226
265
|
* Executes partition.
|
|
@@ -294,6 +333,7 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
294
333
|
* ```
|
|
295
334
|
*/
|
|
296
335
|
executeStream(partition) {
|
|
336
|
+
// TODO: Instrument the streams with Otel.
|
|
297
337
|
if (is.string(partition.table)) {
|
|
298
338
|
return this.createReadStream(partition.table, partition);
|
|
299
339
|
}
|
package/build/src/database.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ import IPolicy = google.iam.v1.IPolicy;
|
|
|
33
33
|
import Policy = google.iam.v1.Policy;
|
|
34
34
|
import FieldMask = google.protobuf.FieldMask;
|
|
35
35
|
import IDatabase = google.spanner.admin.database.v1.IDatabase;
|
|
36
|
+
import { ObservabilityOptions } from './instrument';
|
|
36
37
|
export type GetDatabaseRolesCallback = RequestCallback<IDatabaseRole, databaseAdmin.spanner.admin.database.v1.IListDatabaseRolesResponse>;
|
|
37
38
|
export type GetDatabaseRolesResponse = PagedResponse<IDatabaseRole, databaseAdmin.spanner.admin.database.v1.IListDatabaseRolesResponse>;
|
|
38
39
|
type SetDatabaseMetadataCallback = ResourceCallback<GaxOperation, IOperation>;
|
|
@@ -175,6 +176,8 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
175
176
|
request: DatabaseRequest;
|
|
176
177
|
databaseRole?: string | null;
|
|
177
178
|
databaseDialect?: EnumKey<typeof databaseAdmin.spanner.admin.database.v1.DatabaseDialect> | null;
|
|
179
|
+
_observabilityOptions?: ObservabilityOptions;
|
|
180
|
+
private _traceConfig;
|
|
178
181
|
constructor(instance: Instance, name: string, poolOptions?: SessionPoolConstructor | SessionPoolOptions, queryOptions?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions);
|
|
179
182
|
/**
|
|
180
183
|
* @typedef {array} SetDatabaseMetadataResponse
|
|
@@ -1861,7 +1864,7 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
1861
1864
|
*
|
|
1862
1865
|
* @example
|
|
1863
1866
|
* ```
|
|
1864
|
-
* const {Spanner} = require('@google-cloud/spanner');
|
|
1867
|
+
* const {Spanner, MutationSet} = require('@google-cloud/spanner');
|
|
1865
1868
|
* const spanner = new Spanner();
|
|
1866
1869
|
*
|
|
1867
1870
|
* const instance = spanner.instance('my-instance');
|
|
@@ -1879,7 +1882,7 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
1879
1882
|
* });
|
|
1880
1883
|
*
|
|
1881
1884
|
* try {
|
|
1882
|
-
* const [response
|
|
1885
|
+
* const [response] = await database.writeAtLeastOnce(mutations, {});
|
|
1883
1886
|
* console.log(response.commitTimestamp);
|
|
1884
1887
|
* } catch(err) {
|
|
1885
1888
|
* console.log("Error: ", err);
|