@google-cloud/spanner 7.14.0 → 7.16.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/instance/v1/common.proto +7 -0
- package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +139 -16
- package/build/protos/google/spanner/v1/commit_response.proto +9 -0
- package/build/protos/google/spanner/v1/result_set.proto +21 -0
- package/build/protos/google/spanner/v1/spanner.proto +39 -2
- package/build/protos/google/spanner/v1/transaction.proto +34 -0
- package/build/protos/google/spanner/v1/type.proto +43 -30
- package/build/protos/protos.d.ts +1908 -1452
- package/build/protos/protos.js +5095 -3724
- package/build/protos/protos.json +310 -129
- package/build/src/batch-transaction.d.ts +1 -0
- package/build/src/batch-transaction.js +90 -50
- package/build/src/database.d.ts +6 -2
- package/build/src/database.js +433 -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 +212 -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/spanner_client.d.ts +14 -0
- package/package.json +12 -3
|
@@ -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>;
|
|
@@ -103,6 +104,7 @@ export interface CreateSessionOptions {
|
|
|
103
104
|
} | null;
|
|
104
105
|
databaseRole?: string | null;
|
|
105
106
|
gaxOptions?: CallOptions;
|
|
107
|
+
multiplexed?: boolean;
|
|
106
108
|
}
|
|
107
109
|
export interface GetIamPolicyOptions {
|
|
108
110
|
requestedPolicyVersion?: number | null;
|
|
@@ -175,6 +177,8 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
175
177
|
request: DatabaseRequest;
|
|
176
178
|
databaseRole?: string | null;
|
|
177
179
|
databaseDialect?: EnumKey<typeof databaseAdmin.spanner.admin.database.v1.DatabaseDialect> | null;
|
|
180
|
+
_observabilityOptions?: ObservabilityOptions;
|
|
181
|
+
private _traceConfig;
|
|
178
182
|
constructor(instance: Instance, name: string, poolOptions?: SessionPoolConstructor | SessionPoolOptions, queryOptions?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions);
|
|
179
183
|
/**
|
|
180
184
|
* @typedef {array} SetDatabaseMetadataResponse
|
|
@@ -1861,7 +1865,7 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
1861
1865
|
*
|
|
1862
1866
|
* @example
|
|
1863
1867
|
* ```
|
|
1864
|
-
* const {Spanner} = require('@google-cloud/spanner');
|
|
1868
|
+
* const {Spanner, MutationSet} = require('@google-cloud/spanner');
|
|
1865
1869
|
* const spanner = new Spanner();
|
|
1866
1870
|
*
|
|
1867
1871
|
* const instance = spanner.instance('my-instance');
|
|
@@ -1879,7 +1883,7 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
1879
1883
|
* });
|
|
1880
1884
|
*
|
|
1881
1885
|
* try {
|
|
1882
|
-
* const [response
|
|
1886
|
+
* const [response] = await database.writeAtLeastOnce(mutations, {});
|
|
1883
1887
|
* console.log(response.commitTimestamp);
|
|
1884
1888
|
* } catch(err) {
|
|
1885
1889
|
* console.log("Error: ", err);
|