@google-cloud/spanner 8.0.0 → 8.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/README.md +2 -0
- package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +35 -0
- package/build/protos/google/spanner/v1/change_stream.proto +451 -0
- package/build/protos/google/spanner/v1/commit_response.proto +9 -4
- package/build/protos/google/spanner/v1/transaction.proto +40 -356
- package/build/protos/protos.d.ts +2087 -4
- package/build/protos/protos.js +6191 -349
- package/build/protos/protos.json +556 -25
- package/build/src/batch-transaction.js +2 -2
- package/build/src/codec.js +20 -21
- package/build/src/common-grpc/service.js +10 -10
- package/build/src/common.d.ts +1 -0
- package/build/src/common.js +9 -1
- package/build/src/database.d.ts +3 -2
- package/build/src/database.js +16 -14
- package/build/src/helper.d.ts +90 -0
- package/build/src/helper.js +154 -0
- package/build/src/index.d.ts +36 -1
- package/build/src/index.js +179 -8
- package/build/src/instrument.js +3 -2
- 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.d.ts +1 -1
- package/build/src/multiplexed-session.js +2 -4
- package/build/src/partial-result-stream.js +9 -5
- package/build/src/session-factory.d.ts +34 -0
- package/build/src/session-factory.js +30 -0
- package/build/src/session-pool.js +1 -2
- package/build/src/table.d.ts +2 -0
- package/build/src/table.js +5 -0
- package/build/src/transaction-runner.d.ts +6 -0
- package/build/src/transaction-runner.js +8 -0
- package/build/src/transaction.d.ts +44 -1
- package/build/src/transaction.js +202 -49
- package/build/src/v1/database_admin_client.d.ts +34 -0
- package/build/src/v1/database_admin_client.js +167 -1
- package/build/src/v1/database_admin_client_config.json +4 -0
- package/build/src/v1/instance_admin_client.d.ts +120 -0
- package/build/src/v1/instance_admin_client.js +312 -13
- package/build/src/v1/spanner_client.js +108 -0
- package/build/src/v1/spanner_proto_list.json +1 -0
- package/package.json +15 -8
|
@@ -19,11 +19,11 @@ exports.BatchTransaction = void 0;
|
|
|
19
19
|
const precise_date_1 = require("@google-cloud/precise-date");
|
|
20
20
|
const promisify_1 = require("@google-cloud/promisify");
|
|
21
21
|
const extend = require("extend");
|
|
22
|
-
const is = require("is");
|
|
23
22
|
const transaction_1 = require("./transaction");
|
|
24
23
|
const common_1 = require("../src/common");
|
|
25
24
|
const instrument_1 = require("./instrument");
|
|
26
25
|
const request_id_header_1 = require("./request_id_header");
|
|
26
|
+
const helper_1 = require("./helper");
|
|
27
27
|
/**
|
|
28
28
|
* Use a BatchTransaction object to create partitions and read/query against
|
|
29
29
|
* your Cloud Spanner database.
|
|
@@ -251,7 +251,7 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
251
251
|
*/
|
|
252
252
|
executeStream(partition) {
|
|
253
253
|
// TODO: Instrument the streams with Otel.
|
|
254
|
-
if (
|
|
254
|
+
if ((0, helper_1.isString)(partition.table)) {
|
|
255
255
|
return this.createReadStream(partition.table, partition);
|
|
256
256
|
}
|
|
257
257
|
return this.runStream(partition);
|
package/build/src/codec.js
CHANGED
|
@@ -20,7 +20,6 @@ const service_1 = require("./common-grpc/service");
|
|
|
20
20
|
const precise_date_1 = require("@google-cloud/precise-date");
|
|
21
21
|
const helper_1 = require("./helper");
|
|
22
22
|
const big_js_1 = require("big.js");
|
|
23
|
-
const is = require("is");
|
|
24
23
|
const protos_1 = require("../protos/protos");
|
|
25
24
|
const google_gax_1 = require("google-gax");
|
|
26
25
|
/**
|
|
@@ -357,13 +356,13 @@ class Interval {
|
|
|
357
356
|
* @param nanoseconds nanoseconds part of the `Interval`
|
|
358
357
|
*/
|
|
359
358
|
constructor(months, days, nanoseconds) {
|
|
360
|
-
if (!
|
|
359
|
+
if (!(0, helper_1.isInteger)(months)) {
|
|
361
360
|
throw new google_gax_1.GoogleError(`Invalid months: ${months}, months should be an integral value`);
|
|
362
361
|
}
|
|
363
|
-
if (!
|
|
362
|
+
if (!(0, helper_1.isInteger)(days)) {
|
|
364
363
|
throw new google_gax_1.GoogleError(`Invalid days: ${days}, days should be an integral value`);
|
|
365
364
|
}
|
|
366
|
-
if (
|
|
365
|
+
if ((0, helper_1.isNull)(nanoseconds) || (0, helper_1.isUndefined)(nanoseconds)) {
|
|
367
366
|
throw new google_gax_1.GoogleError(`Invalid nanoseconds: ${nanoseconds}, nanoseconds should be a valid bigint value`);
|
|
368
367
|
}
|
|
369
368
|
this.months = months;
|
|
@@ -404,7 +403,7 @@ class Interval {
|
|
|
404
403
|
* Constructs an `Interval` with specified seconds.
|
|
405
404
|
*/
|
|
406
405
|
static fromSeconds(seconds) {
|
|
407
|
-
if (!
|
|
406
|
+
if (!(0, helper_1.isInteger)(seconds)) {
|
|
408
407
|
throw new google_gax_1.GoogleError(`Invalid seconds: ${seconds}, seconds should be an integral value`);
|
|
409
408
|
}
|
|
410
409
|
return new Interval(0, 0, BigInt(Interval.NANOSECONDS_PER_SECOND) * BigInt(seconds));
|
|
@@ -413,7 +412,7 @@ class Interval {
|
|
|
413
412
|
* Constructs an `Interval` with specified milliseconds.
|
|
414
413
|
*/
|
|
415
414
|
static fromMilliseconds(milliseconds) {
|
|
416
|
-
if (!
|
|
415
|
+
if (!(0, helper_1.isInteger)(milliseconds)) {
|
|
417
416
|
throw new google_gax_1.GoogleError(`Invalid milliseconds: ${milliseconds}, milliseconds should be an integral value`);
|
|
418
417
|
}
|
|
419
418
|
return new Interval(0, 0, BigInt(Interval.NANOSECONDS_PER_MILLISECOND) * BigInt(milliseconds));
|
|
@@ -422,7 +421,7 @@ class Interval {
|
|
|
422
421
|
* Constructs an `Interval` with specified microseconds.
|
|
423
422
|
*/
|
|
424
423
|
static fromMicroseconds(microseconds) {
|
|
425
|
-
if (!
|
|
424
|
+
if (!(0, helper_1.isInteger)(microseconds)) {
|
|
426
425
|
throw new google_gax_1.GoogleError(`Invalid microseconds: ${microseconds}, microseconds should be an integral value`);
|
|
427
426
|
}
|
|
428
427
|
return new Interval(0, 0, BigInt(Interval.NANOSECONDS_PER_MICROSECOND) * BigInt(microseconds));
|
|
@@ -642,7 +641,7 @@ function convertValueToJson(value, options) {
|
|
|
642
641
|
* @returns {*}
|
|
643
642
|
*/
|
|
644
643
|
function decode(value, type, columnMetadata) {
|
|
645
|
-
if (
|
|
644
|
+
if ((0, helper_1.isNull)(value)) {
|
|
646
645
|
return null;
|
|
647
646
|
}
|
|
648
647
|
let decoded = value;
|
|
@@ -760,10 +759,10 @@ function encode(value) {
|
|
|
760
759
|
* @returns {*}
|
|
761
760
|
*/
|
|
762
761
|
function encodeValue(value) {
|
|
763
|
-
if (
|
|
762
|
+
if ((0, helper_1.isNumber)(value) && !(0, helper_1.isDecimal)(value)) {
|
|
764
763
|
return value.toString();
|
|
765
764
|
}
|
|
766
|
-
if (
|
|
765
|
+
if ((0, helper_1.isDate)(value)) {
|
|
767
766
|
return value.toJSON();
|
|
768
767
|
}
|
|
769
768
|
if (value instanceof WrappedNumber) {
|
|
@@ -787,7 +786,7 @@ function encodeValue(value) {
|
|
|
787
786
|
if (value instanceof Struct) {
|
|
788
787
|
return Array.from(value).map(field => encodeValue(field.value));
|
|
789
788
|
}
|
|
790
|
-
if (
|
|
789
|
+
if ((0, helper_1.isArray)(value)) {
|
|
791
790
|
return value.map(encodeValue);
|
|
792
791
|
}
|
|
793
792
|
if (value instanceof PGJsonb) {
|
|
@@ -796,7 +795,7 @@ function encodeValue(value) {
|
|
|
796
795
|
if (value instanceof Interval) {
|
|
797
796
|
return value.toISO8601();
|
|
798
797
|
}
|
|
799
|
-
if (
|
|
798
|
+
if ((0, helper_1.isObject)(value)) {
|
|
800
799
|
return JSON.stringify(value);
|
|
801
800
|
}
|
|
802
801
|
return value;
|
|
@@ -870,14 +869,14 @@ const TypeCode = {
|
|
|
870
869
|
* ```
|
|
871
870
|
*/
|
|
872
871
|
function getType(value) {
|
|
873
|
-
const isSpecialNumber =
|
|
872
|
+
const isSpecialNumber = (0, helper_1.isInfinite)(value) || ((0, helper_1.isNumber)(value) && isNaN(value));
|
|
874
873
|
if (value instanceof Float32) {
|
|
875
874
|
return { type: 'float32' };
|
|
876
875
|
}
|
|
877
|
-
if (
|
|
876
|
+
if ((0, helper_1.isDecimal)(value) || isSpecialNumber || value instanceof Float) {
|
|
878
877
|
return { type: 'float64' };
|
|
879
878
|
}
|
|
880
|
-
if (
|
|
879
|
+
if ((0, helper_1.isNumber)(value) || value instanceof Int) {
|
|
881
880
|
return { type: 'int64' };
|
|
882
881
|
}
|
|
883
882
|
if (value instanceof Numeric) {
|
|
@@ -901,10 +900,10 @@ function getType(value) {
|
|
|
901
900
|
if (value instanceof ProtoEnum) {
|
|
902
901
|
return { type: 'enum', fullName: value.fullName };
|
|
903
902
|
}
|
|
904
|
-
if (
|
|
903
|
+
if ((0, helper_1.isBoolean)(value)) {
|
|
905
904
|
return { type: 'bool' };
|
|
906
905
|
}
|
|
907
|
-
if (
|
|
906
|
+
if ((0, helper_1.isString)(value)) {
|
|
908
907
|
return { type: 'string' };
|
|
909
908
|
}
|
|
910
909
|
if (Buffer.isBuffer(value)) {
|
|
@@ -913,7 +912,7 @@ function getType(value) {
|
|
|
913
912
|
if (value instanceof SpannerDate) {
|
|
914
913
|
return { type: 'date' };
|
|
915
914
|
}
|
|
916
|
-
if (
|
|
915
|
+
if ((0, helper_1.isDate)(value)) {
|
|
917
916
|
return { type: 'timestamp' };
|
|
918
917
|
}
|
|
919
918
|
if (value instanceof Struct) {
|
|
@@ -924,11 +923,11 @@ function getType(value) {
|
|
|
924
923
|
}),
|
|
925
924
|
};
|
|
926
925
|
}
|
|
927
|
-
if (
|
|
926
|
+
if ((0, helper_1.isArray)(value)) {
|
|
928
927
|
let child;
|
|
929
928
|
for (let i = 0; i < value.length; i++) {
|
|
930
929
|
child = value[i];
|
|
931
|
-
if (!
|
|
930
|
+
if (!(0, helper_1.isNull)(child)) {
|
|
932
931
|
break;
|
|
933
932
|
}
|
|
934
933
|
}
|
|
@@ -937,7 +936,7 @@ function getType(value) {
|
|
|
937
936
|
child: getType(child),
|
|
938
937
|
};
|
|
939
938
|
}
|
|
940
|
-
if (
|
|
939
|
+
if ((0, helper_1.isObject)(value)) {
|
|
941
940
|
return { type: 'json' };
|
|
942
941
|
}
|
|
943
942
|
return { type: 'unspecified' };
|
|
@@ -26,9 +26,9 @@ const proto_loader_1 = require("@grpc/proto-loader");
|
|
|
26
26
|
const duplexify = require("duplexify");
|
|
27
27
|
const extend = require("extend");
|
|
28
28
|
const google_gax_1 = require("google-gax");
|
|
29
|
-
const is = require("is");
|
|
30
29
|
const retryRequest = require("retry-request");
|
|
31
30
|
const stream_1 = require("stream");
|
|
31
|
+
const helper_1 = require("../helper");
|
|
32
32
|
const gaxProtoPath = path.join(path.dirname(require.resolve('google-gax')), '..', 'protos');
|
|
33
33
|
// TODO: convert this object to an array
|
|
34
34
|
/**
|
|
@@ -173,7 +173,7 @@ class ObjectToStructConverter {
|
|
|
173
173
|
for (const prop in obj) {
|
|
174
174
|
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
175
175
|
const value = obj[prop];
|
|
176
|
-
if (
|
|
176
|
+
if ((0, helper_1.isUndefined)(value)) {
|
|
177
177
|
continue;
|
|
178
178
|
}
|
|
179
179
|
convertedObject.fields[prop] = this.encodeValue_(value);
|
|
@@ -198,22 +198,22 @@ class ObjectToStructConverter {
|
|
|
198
198
|
*/
|
|
199
199
|
encodeValue_(value) {
|
|
200
200
|
let convertedValue;
|
|
201
|
-
if (
|
|
201
|
+
if ((0, helper_1.isNull)(value)) {
|
|
202
202
|
convertedValue = {
|
|
203
203
|
nullValue: 0,
|
|
204
204
|
};
|
|
205
205
|
}
|
|
206
|
-
else if (
|
|
206
|
+
else if ((0, helper_1.isNumber)(value)) {
|
|
207
207
|
convertedValue = {
|
|
208
208
|
numberValue: value,
|
|
209
209
|
};
|
|
210
210
|
}
|
|
211
|
-
else if (
|
|
211
|
+
else if ((0, helper_1.isString)(value)) {
|
|
212
212
|
convertedValue = {
|
|
213
213
|
stringValue: value,
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
|
-
else if (
|
|
216
|
+
else if ((0, helper_1.isBoolean)(value)) {
|
|
217
217
|
convertedValue = {
|
|
218
218
|
boolValue: value,
|
|
219
219
|
};
|
|
@@ -223,7 +223,7 @@ class ObjectToStructConverter {
|
|
|
223
223
|
blobValue: value,
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
|
-
else if (
|
|
226
|
+
else if ((0, helper_1.isObject)(value)) {
|
|
227
227
|
if (this.seenObjects.has(value)) {
|
|
228
228
|
// Circular reference.
|
|
229
229
|
if (!this.removeCircular) {
|
|
@@ -242,7 +242,7 @@ class ObjectToStructConverter {
|
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
|
-
else if (
|
|
245
|
+
else if ((0, helper_1.isArray)(value)) {
|
|
246
246
|
convertedValue = {
|
|
247
247
|
listValue: {
|
|
248
248
|
values: value.map(this.encodeValue_.bind(this)),
|
|
@@ -531,7 +531,7 @@ class GrpcService extends common_1.Service {
|
|
|
531
531
|
const service = this.getService_(protoOpts);
|
|
532
532
|
const grpcMetadata = this.grpcMetadata;
|
|
533
533
|
const grpcOpts = {};
|
|
534
|
-
if (
|
|
534
|
+
if ((0, helper_1.isNumber)(protoOpts.timeout)) {
|
|
535
535
|
grpcOpts.deadline = GrpcService.createDeadline_(protoOpts.timeout);
|
|
536
536
|
}
|
|
537
537
|
try {
|
|
@@ -615,7 +615,7 @@ class GrpcService extends common_1.Service {
|
|
|
615
615
|
* @return {error|null}
|
|
616
616
|
*/
|
|
617
617
|
static decorateError_(err) {
|
|
618
|
-
const errorObj =
|
|
618
|
+
const errorObj = (0, helper_1.isError)(err) ? err : {};
|
|
619
619
|
return GrpcService.decorateGrpcResponse_(errorObj, err);
|
|
620
620
|
}
|
|
621
621
|
/**
|
package/build/src/common.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export declare const CLOUD_RESOURCE_HEADER = "google-cloud-resource-prefix";
|
|
|
50
50
|
*/
|
|
51
51
|
export declare const LEADER_AWARE_ROUTING_HEADER = "x-goog-spanner-route-to-leader";
|
|
52
52
|
export declare const END_TO_END_TRACING_HEADER = "x-goog-spanner-end-to-end-tracing";
|
|
53
|
+
export declare const AFE_SERVER_TIMING_HEADER = "x-goog-spanner-enable-afe-server-timing";
|
|
53
54
|
/**
|
|
54
55
|
* Add Leader aware routing header to existing header list.
|
|
55
56
|
* @param headers Existing header list.
|
package/build/src/common.js
CHANGED
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.END_TO_END_TRACING_HEADER = exports.LEADER_AWARE_ROUTING_HEADER = exports.CLOUD_RESOURCE_HEADER = void 0;
|
|
18
|
+
exports.AFE_SERVER_TIMING_HEADER = exports.END_TO_END_TRACING_HEADER = exports.LEADER_AWARE_ROUTING_HEADER = exports.CLOUD_RESOURCE_HEADER = void 0;
|
|
19
19
|
exports.addLeaderAwareRoutingHeader = addLeaderAwareRoutingHeader;
|
|
20
20
|
exports.getCommonHeaders = getCommonHeaders;
|
|
21
|
+
const _1 = require(".");
|
|
21
22
|
/*!
|
|
22
23
|
* HTTP header for the resource prefix to improve routing
|
|
23
24
|
* by the backend.
|
|
@@ -31,6 +32,10 @@ exports.LEADER_AWARE_ROUTING_HEADER = 'x-goog-spanner-route-to-leader';
|
|
|
31
32
|
* END TO END TRACING header.
|
|
32
33
|
*/
|
|
33
34
|
exports.END_TO_END_TRACING_HEADER = 'x-goog-spanner-end-to-end-tracing';
|
|
35
|
+
/*
|
|
36
|
+
* AFE SERVER TIMING header.
|
|
37
|
+
*/
|
|
38
|
+
exports.AFE_SERVER_TIMING_HEADER = 'x-goog-spanner-enable-afe-server-timing';
|
|
34
39
|
/**
|
|
35
40
|
* Add Leader aware routing header to existing header list.
|
|
36
41
|
* @param headers Existing header list.
|
|
@@ -48,6 +53,9 @@ function getCommonHeaders(resourceName, enableTracing) {
|
|
|
48
53
|
enableTracing) {
|
|
49
54
|
headers[exports.END_TO_END_TRACING_HEADER] = 'true';
|
|
50
55
|
}
|
|
56
|
+
if (_1.Spanner.isAFEServerTimingEnabled()) {
|
|
57
|
+
headers[exports.AFE_SERVER_TIMING_HEADER] = 'true';
|
|
58
|
+
}
|
|
51
59
|
headers[exports.CLOUD_RESOURCE_HEADER] = resourceName;
|
|
52
60
|
return headers;
|
|
53
61
|
}
|
package/build/src/database.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { BatchTransaction, TransactionIdentifier } from './batch-transaction';
|
|
|
21
21
|
import { SessionFactoryInterface } from './session-factory';
|
|
22
22
|
import { google as databaseAdmin, google, google as spannerClient } from '../protos/protos';
|
|
23
23
|
import IsolationLevel = google.spanner.v1.TransactionOptions.IsolationLevel;
|
|
24
|
+
import ReadLockMode = google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
|
|
24
25
|
import { GetDatabaseOperationsOptions, GetDatabaseOperationsResponse, Instance, GetDatabaseOperationsCallback } from './instance';
|
|
25
26
|
import { PartialResultStream } from './partial-result-stream';
|
|
26
27
|
import { Session } from './session';
|
|
@@ -114,8 +115,6 @@ export interface GetIamPolicyOptions {
|
|
|
114
115
|
}
|
|
115
116
|
/**
|
|
116
117
|
* @typedef {object} GetTransactionOptions
|
|
117
|
-
* * @property {boolean} [optimisticLock] The optimistic lock a
|
|
118
|
-
* {@link Transaction} should use while running.
|
|
119
118
|
*/
|
|
120
119
|
export type GetTransactionOptions = Omit<RunTransactionOptions, 'timeout'>;
|
|
121
120
|
export type CreateSessionCallback = ResourceCallback<Session, spannerClient.spanner.v1.ISession>;
|
|
@@ -150,6 +149,7 @@ export interface RestoreOptions {
|
|
|
150
149
|
gaxOptions?: CallOptions;
|
|
151
150
|
}
|
|
152
151
|
export interface WriteAtLeastOnceOptions extends CallOptions {
|
|
152
|
+
readLockMode?: ReadLockMode;
|
|
153
153
|
isolationLevel?: IsolationLevel;
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
@@ -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
|
@@ -61,6 +61,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
61
61
|
pool_;
|
|
62
62
|
sessionFactory_;
|
|
63
63
|
queryOptions_;
|
|
64
|
+
isMuxEnabledForRW_;
|
|
64
65
|
commonHeaders_;
|
|
65
66
|
request;
|
|
66
67
|
databaseRole;
|
|
@@ -183,6 +184,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
183
184
|
this.requestStream = instance.requestStream;
|
|
184
185
|
this.sessionFactory_ = new session_factory_1.SessionFactory(this, name, poolOptions);
|
|
185
186
|
this.pool_ = this.sessionFactory_.getPool();
|
|
187
|
+
this.isMuxEnabledForRW_ = this.sessionFactory_.isMultiplexedEnabledForRW();
|
|
186
188
|
const sessionPoolInstance = this.pool_;
|
|
187
189
|
if (sessionPoolInstance) {
|
|
188
190
|
sessionPoolInstance._observabilityOptions =
|
|
@@ -325,7 +327,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
325
327
|
? optionsOrCallback
|
|
326
328
|
: {};
|
|
327
329
|
return (0, instrument_1.startTrace)('Database.createBatchTransaction', this._traceConfig, span => {
|
|
328
|
-
this.
|
|
330
|
+
this.sessionFactory_.getSession((err, session) => {
|
|
329
331
|
if (err) {
|
|
330
332
|
(0, instrument_1.setSpanError)(span, err);
|
|
331
333
|
span.end();
|
|
@@ -766,7 +768,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
766
768
|
...this._traceConfig,
|
|
767
769
|
transactionTag: options.requestOptions?.transactionTag,
|
|
768
770
|
}, span => {
|
|
769
|
-
this.
|
|
771
|
+
this.sessionFactory_.getSessionForReadWrite((err, session, transaction) => {
|
|
770
772
|
if (!err) {
|
|
771
773
|
if (options.requestOptions) {
|
|
772
774
|
transaction.requestOptions = Object.assign(transaction.requestOptions || {}, options.requestOptions);
|
|
@@ -829,8 +831,8 @@ class Database extends common.GrpcServiceObject {
|
|
|
829
831
|
});
|
|
830
832
|
}
|
|
831
833
|
makePooledRequest_(config, callback) {
|
|
832
|
-
const
|
|
833
|
-
|
|
834
|
+
const sessionFactory_ = this.sessionFactory_;
|
|
835
|
+
sessionFactory_.getSessionForReadWrite((err, session) => {
|
|
834
836
|
if (err) {
|
|
835
837
|
callback(err, null);
|
|
836
838
|
return;
|
|
@@ -839,7 +841,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
839
841
|
span.addEvent('Using Session', { 'session.id': session?.id });
|
|
840
842
|
config.reqOpts.session = session.formattedName_;
|
|
841
843
|
this.request(config, (err, ...args) => {
|
|
842
|
-
|
|
844
|
+
sessionFactory_.release(session);
|
|
843
845
|
callback(err, ...args);
|
|
844
846
|
});
|
|
845
847
|
});
|
|
@@ -855,7 +857,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
855
857
|
makePooledStreamingRequest_(config) {
|
|
856
858
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
857
859
|
const self = this;
|
|
858
|
-
const
|
|
860
|
+
const sessionFactory_ = this.sessionFactory_;
|
|
859
861
|
let requestStream;
|
|
860
862
|
let session;
|
|
861
863
|
const waitForSessionStream = streamEvents(through.obj());
|
|
@@ -871,12 +873,12 @@ class Database extends common.GrpcServiceObject {
|
|
|
871
873
|
}
|
|
872
874
|
function releaseSession() {
|
|
873
875
|
if (session) {
|
|
874
|
-
|
|
876
|
+
sessionFactory_.release(session);
|
|
875
877
|
session = null;
|
|
876
878
|
}
|
|
877
879
|
}
|
|
878
880
|
waitForSessionStream.on('reading', () => {
|
|
879
|
-
|
|
881
|
+
sessionFactory_.getSession((err, session_) => {
|
|
880
882
|
const span = (0, instrument_1.getActiveOrNoopSpan)();
|
|
881
883
|
if (err) {
|
|
882
884
|
(0, instrument_1.setSpanError)(span, err);
|
|
@@ -1217,7 +1219,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1217
1219
|
...this._traceConfig,
|
|
1218
1220
|
transactionTag: options.requestOptions?.transactionTag,
|
|
1219
1221
|
}, span => {
|
|
1220
|
-
this.
|
|
1222
|
+
this.sessionFactory_.getSessionForReadWrite((err, session, transaction) => {
|
|
1221
1223
|
if (err) {
|
|
1222
1224
|
(0, instrument_1.setSpanError)(span, err);
|
|
1223
1225
|
}
|
|
@@ -1238,7 +1240,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1238
1240
|
transaction.requestOptions = Object.assign(transaction.requestOptions || {}, options.requestOptions);
|
|
1239
1241
|
transaction.setReadWriteTransactionOptions(options);
|
|
1240
1242
|
const release = () => {
|
|
1241
|
-
this.
|
|
1243
|
+
this.sessionFactory_.release(session);
|
|
1242
1244
|
span.end();
|
|
1243
1245
|
};
|
|
1244
1246
|
const runner = new transaction_runner_1.TransactionRunner(session, transaction, runFn, options);
|
|
@@ -1326,7 +1328,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1326
1328
|
? optionsOrRunFn
|
|
1327
1329
|
: {};
|
|
1328
1330
|
let sessionId = '';
|
|
1329
|
-
const getSession = this.
|
|
1331
|
+
const getSession = this.sessionFactory_.getSessionForReadWrite.bind(this.sessionFactory_);
|
|
1330
1332
|
return (0, instrument_1.startTrace)('Database.runTransactionAsync', {
|
|
1331
1333
|
...this._traceConfig,
|
|
1332
1334
|
transactionTag: options?.requestOptions?.transactionTag,
|
|
@@ -1351,7 +1353,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1351
1353
|
}
|
|
1352
1354
|
finally {
|
|
1353
1355
|
span.end();
|
|
1354
|
-
this.
|
|
1356
|
+
this.sessionFactory_.release(session);
|
|
1355
1357
|
}
|
|
1356
1358
|
}
|
|
1357
1359
|
catch (e) {
|
|
@@ -1432,7 +1434,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1432
1434
|
...this._traceConfig,
|
|
1433
1435
|
transactionTag: options?.requestOptions?.transactionTag,
|
|
1434
1436
|
}, span => {
|
|
1435
|
-
this.
|
|
1437
|
+
this.sessionFactory_.getSessionForReadWrite((err, session) => {
|
|
1436
1438
|
if (err) {
|
|
1437
1439
|
proxyStream.destroy(err);
|
|
1438
1440
|
(0, instrument_1.setSpanError)(span, err);
|
|
@@ -1485,7 +1487,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1485
1487
|
})
|
|
1486
1488
|
.once('end', () => {
|
|
1487
1489
|
span.end();
|
|
1488
|
-
this.
|
|
1490
|
+
this.sessionFactory_.release(session);
|
|
1489
1491
|
})
|
|
1490
1492
|
.pipe(proxyStream);
|
|
1491
1493
|
});
|
package/build/src/helper.d.ts
CHANGED
|
@@ -52,3 +52,93 @@ export declare function isCreateSessionPermissionError(error: grpc.ServiceError
|
|
|
52
52
|
* @returns An array containing the value, or an empty array.
|
|
53
53
|
*/
|
|
54
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;
|