@google-cloud/spanner 7.21.0 → 8.1.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/README.md +2 -0
- package/build/protos/google/spanner/admin/database/v1/backup.proto +1 -1
- package/build/protos/google/spanner/admin/database/v1/backup_schedule.proto +1 -1
- package/build/protos/google/spanner/admin/database/v1/common.proto +1 -1
- package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +36 -1
- package/build/protos/google/spanner/admin/instance/v1/common.proto +1 -1
- package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +1 -1
- package/build/protos/google/spanner/executor/v1/cloud_executor.proto +1 -1
- package/build/protos/google/spanner/v1/change_stream.proto +451 -0
- package/build/protos/google/spanner/v1/commit_response.proto +10 -5
- package/build/protos/google/spanner/v1/keys.proto +1 -1
- package/build/protos/google/spanner/v1/mutation.proto +1 -1
- package/build/protos/google/spanner/v1/query_plan.proto +1 -1
- package/build/protos/google/spanner/v1/result_set.proto +55 -49
- package/build/protos/google/spanner/v1/spanner.proto +1 -1
- package/build/protos/google/spanner/v1/transaction.proto +41 -357
- package/build/protos/google/spanner/v1/type.proto +1 -1
- package/build/protos/protos.d.ts +1577 -194
- package/build/protos/protos.js +3977 -288
- package/build/protos/protos.json +325 -3
- package/build/src/backup.js +7 -0
- package/build/src/batch-transaction.d.ts +48 -29
- package/build/src/batch-transaction.js +15 -100
- package/build/src/codec.js +63 -47
- package/build/src/common-grpc/service-object.js +1 -0
- package/build/src/common-grpc/service.js +35 -18
- package/build/src/common.d.ts +1 -0
- package/build/src/common.js +9 -1
- package/build/src/database.d.ts +1 -0
- package/build/src/database.js +54 -42
- package/build/src/helper.d.ts +99 -0
- package/build/src/helper.js +178 -0
- package/build/src/index.d.ts +33 -0
- package/build/src/index.js +202 -21
- package/build/src/instance-config.d.ts +1 -1
- package/build/src/instance-config.js +4 -0
- package/build/src/instance.js +12 -6
- package/build/src/instrument.js +5 -6
- package/build/src/metrics/constants.d.ts +36 -0
- package/build/src/metrics/constants.js +106 -0
- package/build/src/metrics/external-types.d.ts +20 -0
- package/build/src/metrics/external-types.js +32 -0
- package/build/src/metrics/interceptor.d.ts +13 -0
- package/build/src/metrics/interceptor.js +87 -0
- package/build/src/metrics/metrics-tracer-factory.d.ts +165 -0
- package/build/src/metrics/metrics-tracer-factory.js +389 -0
- package/build/src/metrics/metrics-tracer.d.ts +204 -0
- package/build/src/metrics/metrics-tracer.js +371 -0
- package/build/src/metrics/spanner-metrics-exporter.d.ts +35 -0
- package/build/src/metrics/spanner-metrics-exporter.js +119 -0
- package/build/src/metrics/transform.d.ts +144 -0
- package/build/src/metrics/transform.js +272 -0
- package/build/src/multiplexed-session.js +7 -1
- package/build/src/partial-result-stream.js +18 -10
- package/build/src/request_id_header.js +1 -0
- package/build/src/session-factory.d.ts +34 -0
- package/build/src/session-factory.js +35 -2
- package/build/src/session-pool.js +24 -8
- package/build/src/session.d.ts +0 -1
- package/build/src/session.js +7 -2
- package/build/src/table.js +6 -3
- package/build/src/transaction-runner.d.ts +1 -0
- package/build/src/transaction-runner.js +18 -2
- package/build/src/transaction.d.ts +42 -1
- package/build/src/transaction.js +258 -94
- package/build/src/v1/database_admin_client.d.ts +37 -2
- package/build/src/v1/database_admin_client.js +718 -168
- package/build/src/v1/database_admin_client_config.json +4 -0
- package/build/src/v1/instance_admin_client.d.ts +122 -1
- package/build/src/v1/instance_admin_client.js +765 -146
- package/build/src/v1/spanner_client.d.ts +2 -1
- package/build/src/v1/spanner_client.js +391 -85
- package/build/src/v1/spanner_executor_proxy_client.d.ts +2 -1
- package/build/src/v1/spanner_executor_proxy_client.js +41 -19
- package/build/src/v1/spanner_proto_list.json +1 -0
- package/package.json +64 -58
package/build/src/database.d.ts
CHANGED
|
@@ -177,6 +177,7 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
177
177
|
pool_: SessionPoolInterface;
|
|
178
178
|
sessionFactory_: SessionFactoryInterface;
|
|
179
179
|
queryOptions_?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions;
|
|
180
|
+
isMuxEnabledForRW_?: boolean;
|
|
180
181
|
commonHeaders_: {
|
|
181
182
|
[k: string]: string;
|
|
182
183
|
};
|
package/build/src/database.js
CHANGED
|
@@ -32,7 +32,7 @@ const table_1 = require("./table");
|
|
|
32
32
|
const transaction_runner_1 = require("./transaction-runner");
|
|
33
33
|
const common_1 = require("./common");
|
|
34
34
|
const stream_1 = require("stream");
|
|
35
|
-
const
|
|
35
|
+
const helper_1 = require("./helper");
|
|
36
36
|
const snakeCase = require("lodash.snakecase");
|
|
37
37
|
const instrument_1 = require("./instrument");
|
|
38
38
|
const request_id_header_1 = require("./request_id_header");
|
|
@@ -56,8 +56,22 @@ const request_id_header_1 = require("./request_id_header");
|
|
|
56
56
|
* ```
|
|
57
57
|
*/
|
|
58
58
|
class Database extends common.GrpcServiceObject {
|
|
59
|
+
instance;
|
|
60
|
+
formattedName_;
|
|
61
|
+
pool_;
|
|
62
|
+
sessionFactory_;
|
|
63
|
+
queryOptions_;
|
|
64
|
+
isMuxEnabledForRW_;
|
|
65
|
+
commonHeaders_;
|
|
66
|
+
request;
|
|
67
|
+
databaseRole;
|
|
68
|
+
labels;
|
|
69
|
+
databaseDialect;
|
|
70
|
+
_observabilityOptions; // TODO: exmaine if we can remove it
|
|
71
|
+
_traceConfig;
|
|
72
|
+
_nthRequest;
|
|
73
|
+
_clientId;
|
|
59
74
|
constructor(instance, name, poolOptions, queryOptions) {
|
|
60
|
-
var _a;
|
|
61
75
|
const methods = {
|
|
62
76
|
/**
|
|
63
77
|
* Create a database.
|
|
@@ -136,7 +150,9 @@ class Database extends common.GrpcServiceObject {
|
|
|
136
150
|
});
|
|
137
151
|
}),
|
|
138
152
|
];
|
|
139
|
-
Promise.race(promises)
|
|
153
|
+
Promise.race(promises)
|
|
154
|
+
.then(() => instance.createDatabase(formattedName_, options, callback))
|
|
155
|
+
.catch(() => { });
|
|
140
156
|
}
|
|
141
157
|
else {
|
|
142
158
|
return instance.createDatabase(formattedName_, options, callback);
|
|
@@ -163,11 +179,12 @@ class Database extends common.GrpcServiceObject {
|
|
|
163
179
|
this._clientId = instance._nthClientId;
|
|
164
180
|
}
|
|
165
181
|
this._observabilityOptions = instance._observabilityOptions;
|
|
166
|
-
this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.formattedName_,
|
|
182
|
+
this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.formattedName_, this._observabilityOptions?.enableEndToEndTracing);
|
|
167
183
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
184
|
this.requestStream = instance.requestStream;
|
|
169
185
|
this.sessionFactory_ = new session_factory_1.SessionFactory(this, name, poolOptions);
|
|
170
186
|
this.pool_ = this.sessionFactory_.getPool();
|
|
187
|
+
this.isMuxEnabledForRW_ = this.sessionFactory_.isMultiplexedEnabledForRW();
|
|
171
188
|
const sessionPoolInstance = this.pool_;
|
|
172
189
|
if (sessionPoolInstance) {
|
|
173
190
|
sessionPoolInstance._observabilityOptions =
|
|
@@ -324,14 +341,14 @@ class Database extends common.GrpcServiceObject {
|
|
|
324
341
|
(0, instrument_1.setSpanError)(span, err);
|
|
325
342
|
if ((0, session_pool_1.isSessionNotFoundError)(err)) {
|
|
326
343
|
span.addEvent('No session available', {
|
|
327
|
-
'session.id': session
|
|
344
|
+
'session.id': session?.id,
|
|
328
345
|
});
|
|
329
346
|
}
|
|
330
347
|
span.end();
|
|
331
348
|
callback(err, null, resp);
|
|
332
349
|
return;
|
|
333
350
|
}
|
|
334
|
-
span.addEvent('Using Session', { 'session.id': session
|
|
351
|
+
span.addEvent('Using Session', { 'session.id': session?.id });
|
|
335
352
|
span.end();
|
|
336
353
|
callback(null, transaction, resp);
|
|
337
354
|
});
|
|
@@ -718,7 +735,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
718
735
|
if ((0, session_pool_1.isSessionNotFoundError)(err) &&
|
|
719
736
|
!this.sessionFactory_.isMultiplexedEnabled()) {
|
|
720
737
|
span.addEvent('No session available', {
|
|
721
|
-
'session.id': session
|
|
738
|
+
'session.id': session?.id,
|
|
722
739
|
});
|
|
723
740
|
session.lastError = err;
|
|
724
741
|
this.sessionFactory_.release(session);
|
|
@@ -726,7 +743,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
726
743
|
this.getSnapshot(options, callback);
|
|
727
744
|
}
|
|
728
745
|
else {
|
|
729
|
-
span.addEvent('Using Session', { 'session.id': session
|
|
746
|
+
span.addEvent('Using Session', { 'session.id': session?.id });
|
|
730
747
|
this.sessionFactory_.release(session);
|
|
731
748
|
span.end();
|
|
732
749
|
callback(err);
|
|
@@ -741,7 +758,6 @@ class Database extends common.GrpcServiceObject {
|
|
|
741
758
|
});
|
|
742
759
|
}
|
|
743
760
|
getTransaction(optionsOrCallback, callback) {
|
|
744
|
-
var _a;
|
|
745
761
|
const cb = typeof optionsOrCallback === 'function'
|
|
746
762
|
? optionsOrCallback
|
|
747
763
|
: callback;
|
|
@@ -750,15 +766,15 @@ class Database extends common.GrpcServiceObject {
|
|
|
750
766
|
: {};
|
|
751
767
|
return (0, instrument_1.startTrace)('Database.getTransaction', {
|
|
752
768
|
...this._traceConfig,
|
|
753
|
-
transactionTag:
|
|
769
|
+
transactionTag: options.requestOptions?.transactionTag,
|
|
754
770
|
}, span => {
|
|
755
771
|
this.pool_.getSession((err, session, transaction) => {
|
|
756
772
|
if (!err) {
|
|
757
773
|
if (options.requestOptions) {
|
|
758
774
|
transaction.requestOptions = Object.assign(transaction.requestOptions || {}, options.requestOptions);
|
|
759
775
|
}
|
|
760
|
-
transaction
|
|
761
|
-
span.addEvent('Using Session', { 'session.id': session
|
|
776
|
+
transaction?.setReadWriteTransactionOptions(options);
|
|
777
|
+
span.addEvent('Using Session', { 'session.id': session?.id });
|
|
762
778
|
transaction._observabilityOptions = this._observabilityOptions;
|
|
763
779
|
this._releaseOnEnd(session, transaction, span);
|
|
764
780
|
}
|
|
@@ -822,7 +838,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
822
838
|
return;
|
|
823
839
|
}
|
|
824
840
|
const span = (0, instrument_1.getActiveOrNoopSpan)();
|
|
825
|
-
span.addEvent('Using Session', { 'session.id': session
|
|
841
|
+
span.addEvent('Using Session', { 'session.id': session?.id });
|
|
826
842
|
config.reqOpts.session = session.formattedName_;
|
|
827
843
|
this.request(config, (err, ...args) => {
|
|
828
844
|
pool.release(session);
|
|
@@ -869,7 +885,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
869
885
|
destroyStream(err);
|
|
870
886
|
return;
|
|
871
887
|
}
|
|
872
|
-
span.addEvent('Using Session', { 'session.id': session_
|
|
888
|
+
span.addEvent('Using Session', { 'session.id': session_?.id });
|
|
873
889
|
session = session_;
|
|
874
890
|
config.reqOpts.session = session.formattedName_;
|
|
875
891
|
requestStream = self.requestStream(config);
|
|
@@ -949,11 +965,11 @@ class Database extends common.GrpcServiceObject {
|
|
|
949
965
|
});
|
|
950
966
|
}
|
|
951
967
|
runPartitionedUpdate(query, callback) {
|
|
952
|
-
var _a;
|
|
953
968
|
return (0, instrument_1.startTrace)('Database.runPartitionedUpdate', {
|
|
954
969
|
...query,
|
|
955
970
|
...this._traceConfig,
|
|
956
|
-
requestTag:
|
|
971
|
+
requestTag: query?.requestOptions
|
|
972
|
+
?.requestTag,
|
|
957
973
|
}, span => {
|
|
958
974
|
this.sessionFactory_.getSessionForPartitionedOps((err, session) => {
|
|
959
975
|
if (err) {
|
|
@@ -962,7 +978,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
962
978
|
callback(err, 0);
|
|
963
979
|
return;
|
|
964
980
|
}
|
|
965
|
-
this._runPartitionedUpdate(session, query, (err, count) => {
|
|
981
|
+
void this._runPartitionedUpdate(session, query, (err, count) => {
|
|
966
982
|
if (err) {
|
|
967
983
|
(0, instrument_1.setSpanError)(span, err);
|
|
968
984
|
}
|
|
@@ -983,14 +999,14 @@ class Database extends common.GrpcServiceObject {
|
|
|
983
999
|
callback(err, 0);
|
|
984
1000
|
return;
|
|
985
1001
|
}
|
|
986
|
-
transaction.runUpdate(query, (err, updateCount) => {
|
|
1002
|
+
transaction.runUpdate(query, async (err, updateCount) => {
|
|
987
1003
|
if (err) {
|
|
988
1004
|
if (err.code !== google_gax_1.grpc.status.ABORTED) {
|
|
989
1005
|
this.sessionFactory_.release(session);
|
|
990
1006
|
callback(err, 0);
|
|
991
1007
|
return;
|
|
992
1008
|
}
|
|
993
|
-
this._runPartitionedUpdate(session, query, callback);
|
|
1009
|
+
void this._runPartitionedUpdate(session, query, callback);
|
|
994
1010
|
}
|
|
995
1011
|
else {
|
|
996
1012
|
this.sessionFactory_.release(session);
|
|
@@ -1126,12 +1142,11 @@ class Database extends common.GrpcServiceObject {
|
|
|
1126
1142
|
* ```
|
|
1127
1143
|
*/
|
|
1128
1144
|
runStream(query, options) {
|
|
1129
|
-
var _a;
|
|
1130
1145
|
const proxyStream = through.obj();
|
|
1131
1146
|
return (0, instrument_1.startTrace)('Database.runStream', {
|
|
1132
1147
|
...query,
|
|
1133
1148
|
...this._traceConfig,
|
|
1134
|
-
requestTag:
|
|
1149
|
+
requestTag: query?.requestOptions?.requestTag,
|
|
1135
1150
|
}, span => {
|
|
1136
1151
|
this.sessionFactory_.getSession((err, session) => {
|
|
1137
1152
|
if (err) {
|
|
@@ -1140,7 +1155,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1140
1155
|
span.end();
|
|
1141
1156
|
return;
|
|
1142
1157
|
}
|
|
1143
|
-
span.addEvent('Using Session', { 'session.id': session
|
|
1158
|
+
span.addEvent('Using Session', { 'session.id': session?.id });
|
|
1144
1159
|
const snapshot = session.snapshot(options, this.queryOptions_);
|
|
1145
1160
|
this._releaseOnEnd(session, snapshot, span);
|
|
1146
1161
|
let dataReceived = false;
|
|
@@ -1162,7 +1177,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1162
1177
|
session.lastError = err;
|
|
1163
1178
|
}
|
|
1164
1179
|
span.addEvent('No session available', {
|
|
1165
|
-
'session.id': session
|
|
1180
|
+
'session.id': session?.id,
|
|
1166
1181
|
});
|
|
1167
1182
|
// Remove the current data stream from the end user stream.
|
|
1168
1183
|
dataStream.unpipe(proxyStream);
|
|
@@ -1194,7 +1209,6 @@ class Database extends common.GrpcServiceObject {
|
|
|
1194
1209
|
});
|
|
1195
1210
|
}
|
|
1196
1211
|
runTransaction(optionsOrRunFn, fn) {
|
|
1197
|
-
var _a;
|
|
1198
1212
|
const runFn = typeof optionsOrRunFn === 'function'
|
|
1199
1213
|
? optionsOrRunFn
|
|
1200
1214
|
: fn;
|
|
@@ -1203,7 +1217,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1203
1217
|
: {};
|
|
1204
1218
|
(0, instrument_1.startTrace)('Database.runTransaction', {
|
|
1205
1219
|
...this._traceConfig,
|
|
1206
|
-
transactionTag:
|
|
1220
|
+
transactionTag: options.requestOptions?.transactionTag,
|
|
1207
1221
|
}, span => {
|
|
1208
1222
|
this.pool_.getSession((err, session, transaction) => {
|
|
1209
1223
|
if (err) {
|
|
@@ -1211,7 +1225,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1211
1225
|
}
|
|
1212
1226
|
if (err && (0, session_pool_1.isSessionNotFoundError)(err)) {
|
|
1213
1227
|
span.addEvent('No session available', {
|
|
1214
|
-
'session.id': session
|
|
1228
|
+
'session.id': session?.id,
|
|
1215
1229
|
});
|
|
1216
1230
|
span.end();
|
|
1217
1231
|
this.runTransaction(options, runFn);
|
|
@@ -1234,7 +1248,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1234
1248
|
(0, instrument_1.setSpanError)(span, err);
|
|
1235
1249
|
if ((0, session_pool_1.isSessionNotFoundError)(err)) {
|
|
1236
1250
|
span.addEvent('No session available', {
|
|
1237
|
-
'session.id': session
|
|
1251
|
+
'session.id': session?.id,
|
|
1238
1252
|
});
|
|
1239
1253
|
release();
|
|
1240
1254
|
this.runTransaction(options, runFn);
|
|
@@ -1307,7 +1321,6 @@ class Database extends common.GrpcServiceObject {
|
|
|
1307
1321
|
* ```
|
|
1308
1322
|
*/
|
|
1309
1323
|
async runTransactionAsync(optionsOrRunFn, fn) {
|
|
1310
|
-
var _a;
|
|
1311
1324
|
const runFn = typeof optionsOrRunFn === 'function'
|
|
1312
1325
|
? optionsOrRunFn
|
|
1313
1326
|
: fn;
|
|
@@ -1318,7 +1331,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1318
1331
|
const getSession = this.pool_.getSession.bind(this.pool_);
|
|
1319
1332
|
return (0, instrument_1.startTrace)('Database.runTransactionAsync', {
|
|
1320
1333
|
...this._traceConfig,
|
|
1321
|
-
transactionTag:
|
|
1334
|
+
transactionTag: options?.requestOptions?.transactionTag,
|
|
1322
1335
|
}, async (span) => {
|
|
1323
1336
|
// Loop to retry 'Session not found' errors.
|
|
1324
1337
|
// (and yes, we like while (true) more than for (;;) here)
|
|
@@ -1328,7 +1341,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1328
1341
|
const [session, transaction] = await (0, promisify_1.promisify)(getSession)();
|
|
1329
1342
|
transaction.requestOptions = Object.assign(transaction.requestOptions || {}, options.requestOptions);
|
|
1330
1343
|
transaction.setReadWriteTransactionOptions(options);
|
|
1331
|
-
sessionId = session
|
|
1344
|
+
sessionId = session?.id;
|
|
1332
1345
|
span.addEvent('Using Session', { 'session.id': sessionId });
|
|
1333
1346
|
const runner = new transaction_runner_1.AsyncTransactionRunner(session, transaction, runFn, options);
|
|
1334
1347
|
try {
|
|
@@ -1416,11 +1429,10 @@ class Database extends common.GrpcServiceObject {
|
|
|
1416
1429
|
* ```
|
|
1417
1430
|
*/
|
|
1418
1431
|
batchWriteAtLeastOnce(mutationGroups, options) {
|
|
1419
|
-
var _a;
|
|
1420
1432
|
const proxyStream = through.obj();
|
|
1421
1433
|
return (0, instrument_1.startTrace)('Database.batchWriteAtLeastOnce', {
|
|
1422
1434
|
...this._traceConfig,
|
|
1423
|
-
transactionTag:
|
|
1435
|
+
transactionTag: options?.requestOptions?.transactionTag,
|
|
1424
1436
|
}, span => {
|
|
1425
1437
|
this.pool_.getSession((err, session) => {
|
|
1426
1438
|
if (err) {
|
|
@@ -1429,13 +1441,13 @@ class Database extends common.GrpcServiceObject {
|
|
|
1429
1441
|
span.end();
|
|
1430
1442
|
return;
|
|
1431
1443
|
}
|
|
1432
|
-
span.addEvent('Using Session', { 'session.id': session
|
|
1433
|
-
const gaxOpts = extend(true, {}, options
|
|
1444
|
+
span.addEvent('Using Session', { 'session.id': session?.id });
|
|
1445
|
+
const gaxOpts = extend(true, {}, options?.gaxOptions);
|
|
1434
1446
|
const reqOpts = Object.assign({}, {
|
|
1435
1447
|
session: session.formattedName_,
|
|
1436
1448
|
mutationGroups: mutationGroups.map(mg => mg.proto()),
|
|
1437
|
-
requestOptions: options
|
|
1438
|
-
excludeTxnFromChangeStream: options
|
|
1449
|
+
requestOptions: options?.requestOptions,
|
|
1450
|
+
excludeTxnFromChangeStream: options?.excludeTxnFromChangeStreams,
|
|
1439
1451
|
});
|
|
1440
1452
|
let dataReceived = false;
|
|
1441
1453
|
let dataStream = this.requestStream({
|
|
@@ -1458,7 +1470,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1458
1470
|
session.lastError = err;
|
|
1459
1471
|
}
|
|
1460
1472
|
span.addEvent('No session available', {
|
|
1461
|
-
'session.id': session
|
|
1473
|
+
'session.id': session?.id,
|
|
1462
1474
|
});
|
|
1463
1475
|
// Remove the current data stream from the end user stream.
|
|
1464
1476
|
dataStream.unpipe(proxyStream);
|
|
@@ -1495,7 +1507,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1495
1507
|
(0, session_pool_1.isSessionNotFoundError)(err) &&
|
|
1496
1508
|
!this.sessionFactory_.isMultiplexedEnabled()) {
|
|
1497
1509
|
span.addEvent('No session available', {
|
|
1498
|
-
'session.id': session
|
|
1510
|
+
'session.id': session?.id,
|
|
1499
1511
|
});
|
|
1500
1512
|
span.end();
|
|
1501
1513
|
this.writeAtLeastOnce(mutations, options, cb);
|
|
@@ -1507,12 +1519,12 @@ class Database extends common.GrpcServiceObject {
|
|
|
1507
1519
|
cb(err);
|
|
1508
1520
|
return;
|
|
1509
1521
|
}
|
|
1510
|
-
span.addEvent('Using Session', { 'session.id': session
|
|
1522
|
+
span.addEvent('Using Session', { 'session.id': session?.id });
|
|
1511
1523
|
this._releaseOnEnd(session, transaction, span);
|
|
1512
1524
|
try {
|
|
1513
1525
|
transaction.setReadWriteTransactionOptions(options);
|
|
1514
|
-
transaction
|
|
1515
|
-
return transaction
|
|
1526
|
+
transaction?.setQueuedMutations(mutations.proto());
|
|
1527
|
+
return transaction?.commit(options, (err, resp) => {
|
|
1516
1528
|
if (err) {
|
|
1517
1529
|
(0, instrument_1.setSpanError)(span, err);
|
|
1518
1530
|
}
|
|
@@ -1578,7 +1590,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1578
1590
|
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
1579
1591
|
if (typeof statements === 'string' || Array.isArray(statements)) {
|
|
1580
1592
|
statements = {
|
|
1581
|
-
statements:
|
|
1593
|
+
statements: (0, helper_1.toArray)(statements),
|
|
1582
1594
|
};
|
|
1583
1595
|
}
|
|
1584
1596
|
const reqOpts = extend({
|
package/build/src/helper.d.ts
CHANGED
|
@@ -43,3 +43,102 @@ export declare function isProjectIdNotSetInEnvironmentError(error: grpc.ServiceE
|
|
|
43
43
|
* @return {boolean} True if the error is a 'Create session permission' error, and otherwise false.
|
|
44
44
|
*/
|
|
45
45
|
export declare function isCreateSessionPermissionError(error: grpc.ServiceError | undefined): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Converts any value into an array. Acts as a replacement for `arrify`.
|
|
48
|
+
* If the value is null or undefined, returns an empty array.
|
|
49
|
+
* If the value is already an array, returns is unchanges.
|
|
50
|
+
* Otherwise, wraps the value in a new array.
|
|
51
|
+
* @param value The value to convert into an array.
|
|
52
|
+
* @returns An array containing the value, or an empty array.
|
|
53
|
+
*/
|
|
54
|
+
export declare function toArray(value: any): any[];
|
|
55
|
+
/**
|
|
56
|
+
* Checks if a value is defined.
|
|
57
|
+
* @param {*} value The value to check.
|
|
58
|
+
* @returns {Boolean} `true` if the value is NOT `undefined`, otherwise `false`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function isDefined(value: any): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Checks if a value is null.
|
|
63
|
+
* @param {*} value The value to check.
|
|
64
|
+
* @returns {Boolean} `true` if the value is null, otherwise `false`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function isNull(value: any): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Checks if a value is undefined.
|
|
69
|
+
* @param {*} value The value to check.
|
|
70
|
+
* @returns {Boolean} `true` if the value is `undefined`, otherwise `false`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function isUndefined(value: any): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Checks if a value is empty.
|
|
75
|
+
* @param {*} value The value to check.
|
|
76
|
+
* @returns {Boolean} `true` if the value is empty, otherwise `false`.
|
|
77
|
+
*/
|
|
78
|
+
export declare function isEmpty(value: any): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Checks if a value is a plain javascript object.
|
|
81
|
+
* @param {*} value The value to check.
|
|
82
|
+
* @returns {Boolean} `true` if the value is an object, otherwise `false`.
|
|
83
|
+
*/
|
|
84
|
+
export declare function isObject(value: any): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Checks if a value is a string.
|
|
87
|
+
* @param {*} value The value to check.
|
|
88
|
+
* @returns {Boolean} `true` if the value is string, otherwise `false`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function isString(value: any): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Checks if a value is an array.
|
|
93
|
+
* @param {*} value The value to check.
|
|
94
|
+
* @returns {Boolean} `true` if the value is an array, otherwise `false`.
|
|
95
|
+
*/
|
|
96
|
+
export declare function isArray(value: any): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Checks if a value is a Date object.
|
|
99
|
+
* @param {*} value The value to check.
|
|
100
|
+
* @returns {Boolean} `true` if the value is a `Date` object, otherwise `false`.
|
|
101
|
+
*/
|
|
102
|
+
export declare function isDate(value: any): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Checks if a value is a boolean.
|
|
105
|
+
* @param {*} value The value to check.
|
|
106
|
+
* @returns {Boolean} `true` if the value is boolean, otherwise `false`.
|
|
107
|
+
*/
|
|
108
|
+
export declare function isBoolean(value: any): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Checks if a value is a number.
|
|
111
|
+
* @param {*} value The value to check.
|
|
112
|
+
* @returns {Boolean} `true` if the value is a number, otherwise `false`.
|
|
113
|
+
*/
|
|
114
|
+
export declare function isNumber(value: any): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Checks if a value is an integer.
|
|
117
|
+
* @param {*} value The value to check.
|
|
118
|
+
* @returns {Boolean} `true` if the value is an integer, otherwise `false`.
|
|
119
|
+
*/
|
|
120
|
+
export declare function isInteger(value: any): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Checks if a value is `NaN`.
|
|
123
|
+
* @param {*} value The value to check.
|
|
124
|
+
* @returns {Boolean} `true` if the value is `NaN`, otherwise `false`.
|
|
125
|
+
*/
|
|
126
|
+
export declare function isActualNaN(value: any): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Checks if a value is a non-integer (decimal) number.
|
|
129
|
+
* @param {*} value The value to check.
|
|
130
|
+
* @returns {Boolean} `true` if the value is a decimal number, otherwise `false`.
|
|
131
|
+
*/
|
|
132
|
+
export declare function isDecimal(value: any): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Checks if a value is `Infinity` or `-Infinity`.
|
|
135
|
+
* @param {*} value The value to check.
|
|
136
|
+
* @returns {Boolean} `true` if the value is infinite, otherwise `false`.
|
|
137
|
+
*/
|
|
138
|
+
export declare function isInfinite(value: any): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Checks if a value is an `Error` object.
|
|
141
|
+
* @param {*} value The value to check.
|
|
142
|
+
* @returns {Boolean} `true` if the value is an `Error` object, otherwise `false`.
|
|
143
|
+
*/
|
|
144
|
+
export declare function isError(value: any): boolean;
|
package/build/src/helper.js
CHANGED
|
@@ -19,6 +19,22 @@ exports.isInstanceNotFoundError = isInstanceNotFoundError;
|
|
|
19
19
|
exports.isDefaultCredentialsNotSetError = isDefaultCredentialsNotSetError;
|
|
20
20
|
exports.isProjectIdNotSetInEnvironmentError = isProjectIdNotSetInEnvironmentError;
|
|
21
21
|
exports.isCreateSessionPermissionError = isCreateSessionPermissionError;
|
|
22
|
+
exports.toArray = toArray;
|
|
23
|
+
exports.isDefined = isDefined;
|
|
24
|
+
exports.isNull = isNull;
|
|
25
|
+
exports.isUndefined = isUndefined;
|
|
26
|
+
exports.isEmpty = isEmpty;
|
|
27
|
+
exports.isObject = isObject;
|
|
28
|
+
exports.isString = isString;
|
|
29
|
+
exports.isArray = isArray;
|
|
30
|
+
exports.isDate = isDate;
|
|
31
|
+
exports.isBoolean = isBoolean;
|
|
32
|
+
exports.isNumber = isNumber;
|
|
33
|
+
exports.isInteger = isInteger;
|
|
34
|
+
exports.isActualNaN = isActualNaN;
|
|
35
|
+
exports.isDecimal = isDecimal;
|
|
36
|
+
exports.isInfinite = isInfinite;
|
|
37
|
+
exports.isError = isError;
|
|
22
38
|
const google_gax_1 = require("google-gax");
|
|
23
39
|
/**
|
|
24
40
|
* Checks whether the given error is a 'Database not found' error.
|
|
@@ -68,4 +84,166 @@ function isCreateSessionPermissionError(error) {
|
|
|
68
84
|
error.code === google_gax_1.grpc.status.PERMISSION_DENIED &&
|
|
69
85
|
error.message.includes('spanner.sessions.create'));
|
|
70
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Converts any value into an array. Acts as a replacement for `arrify`.
|
|
89
|
+
* If the value is null or undefined, returns an empty array.
|
|
90
|
+
* If the value is already an array, returns is unchanges.
|
|
91
|
+
* Otherwise, wraps the value in a new array.
|
|
92
|
+
* @param value The value to convert into an array.
|
|
93
|
+
* @returns An array containing the value, or an empty array.
|
|
94
|
+
*/
|
|
95
|
+
function toArray(value) {
|
|
96
|
+
if (value === null || value === undefined) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
if (Array.isArray(value)) {
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
if (typeof value === 'string') {
|
|
103
|
+
return [value];
|
|
104
|
+
}
|
|
105
|
+
if (typeof value[Symbol.iterator] === 'function') {
|
|
106
|
+
return [...value];
|
|
107
|
+
}
|
|
108
|
+
return [value];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Checks if a value is defined.
|
|
112
|
+
* @param {*} value The value to check.
|
|
113
|
+
* @returns {Boolean} `true` if the value is NOT `undefined`, otherwise `false`.
|
|
114
|
+
*/
|
|
115
|
+
function isDefined(value) {
|
|
116
|
+
return typeof value !== 'undefined';
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Checks if a value is null.
|
|
120
|
+
* @param {*} value The value to check.
|
|
121
|
+
* @returns {Boolean} `true` if the value is null, otherwise `false`.
|
|
122
|
+
*/
|
|
123
|
+
function isNull(value) {
|
|
124
|
+
return value === null;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Checks if a value is undefined.
|
|
128
|
+
* @param {*} value The value to check.
|
|
129
|
+
* @returns {Boolean} `true` if the value is `undefined`, otherwise `false`.
|
|
130
|
+
*/
|
|
131
|
+
function isUndefined(value) {
|
|
132
|
+
return typeof value === 'undefined';
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Checks if a value is empty.
|
|
136
|
+
* @param {*} value The value to check.
|
|
137
|
+
* @returns {Boolean} `true` if the value is empty, otherwise `false`.
|
|
138
|
+
*/
|
|
139
|
+
function isEmpty(value) {
|
|
140
|
+
const type = Object.prototype.toString.call(value);
|
|
141
|
+
if (type === '[object Array]' ||
|
|
142
|
+
type === '[object Arguments]' ||
|
|
143
|
+
type === '[object String]') {
|
|
144
|
+
return value.length === 0;
|
|
145
|
+
}
|
|
146
|
+
if (type === '[object Object]') {
|
|
147
|
+
for (const key in value) {
|
|
148
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
return !value;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Checks if a value is a plain javascript object.
|
|
158
|
+
* @param {*} value The value to check.
|
|
159
|
+
* @returns {Boolean} `true` if the value is an object, otherwise `false`.
|
|
160
|
+
*/
|
|
161
|
+
function isObject(value) {
|
|
162
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Checks if a value is a string.
|
|
166
|
+
* @param {*} value The value to check.
|
|
167
|
+
* @returns {Boolean} `true` if the value is string, otherwise `false`.
|
|
168
|
+
*/
|
|
169
|
+
function isString(value) {
|
|
170
|
+
return Object.prototype.toString.call(value) === '[object String]';
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Checks if a value is an array.
|
|
174
|
+
* @param {*} value The value to check.
|
|
175
|
+
* @returns {Boolean} `true` if the value is an array, otherwise `false`.
|
|
176
|
+
*/
|
|
177
|
+
function isArray(value) {
|
|
178
|
+
return Array.isArray(value);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Checks if a value is a Date object.
|
|
182
|
+
* @param {*} value The value to check.
|
|
183
|
+
* @returns {Boolean} `true` if the value is a `Date` object, otherwise `false`.
|
|
184
|
+
*/
|
|
185
|
+
function isDate(value) {
|
|
186
|
+
return Object.prototype.toString.call(value) === '[object Date]';
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Checks if a value is a boolean.
|
|
190
|
+
* @param {*} value The value to check.
|
|
191
|
+
* @returns {Boolean} `true` if the value is boolean, otherwise `false`.
|
|
192
|
+
*/
|
|
193
|
+
function isBoolean(value) {
|
|
194
|
+
return Object.prototype.toString.call(value) === '[object Boolean]';
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Checks if a value is a number.
|
|
198
|
+
* @param {*} value The value to check.
|
|
199
|
+
* @returns {Boolean} `true` if the value is a number, otherwise `false`.
|
|
200
|
+
*/
|
|
201
|
+
function isNumber(value) {
|
|
202
|
+
return Object.prototype.toString.call(value) === '[object Number]';
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Checks if a value is an integer.
|
|
206
|
+
* @param {*} value The value to check.
|
|
207
|
+
* @returns {Boolean} `true` if the value is an integer, otherwise `false`.
|
|
208
|
+
*/
|
|
209
|
+
function isInteger(value) {
|
|
210
|
+
return Number.isInteger(value);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Checks if a value is `NaN`.
|
|
214
|
+
* @param {*} value The value to check.
|
|
215
|
+
* @returns {Boolean} `true` if the value is `NaN`, otherwise `false`.
|
|
216
|
+
*/
|
|
217
|
+
function isActualNaN(value) {
|
|
218
|
+
return value !== value;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Checks if a value is a non-integer (decimal) number.
|
|
222
|
+
* @param {*} value The value to check.
|
|
223
|
+
* @returns {Boolean} `true` if the value is a decimal number, otherwise `false`.
|
|
224
|
+
*/
|
|
225
|
+
function isDecimal(value) {
|
|
226
|
+
// A number is a decimal if it's a number but not an integer.
|
|
227
|
+
return (isNumber(value) &&
|
|
228
|
+
!isInfinite(value) &&
|
|
229
|
+
!isActualNaN(value) &&
|
|
230
|
+
value % 1 !== 0);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Checks if a value is `Infinity` or `-Infinity`.
|
|
234
|
+
* @param {*} value The value to check.
|
|
235
|
+
* @returns {Boolean} `true` if the value is infinite, otherwise `false`.
|
|
236
|
+
*/
|
|
237
|
+
function isInfinite(value) {
|
|
238
|
+
return value === Infinity || value === -Infinity;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Checks if a value is an `Error` object.
|
|
242
|
+
* @param {*} value The value to check.
|
|
243
|
+
* @returns {Boolean} `true` if the value is an `Error` object, otherwise `false`.
|
|
244
|
+
*/
|
|
245
|
+
function isError(value) {
|
|
246
|
+
return (value instanceof Error ||
|
|
247
|
+
Object.prototype.toString.call(value) === '[object Error]');
|
|
248
|
+
}
|
|
71
249
|
//# sourceMappingURL=helper.js.map
|