@google-cloud/spanner 8.12.0 → 9.0.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/build/src/codec.d.ts +12 -30
- package/build/src/codec.js +98 -45
- package/build/src/common.js +2 -3
- package/build/src/database.d.ts +31 -0
- package/build/src/database.js +128 -6
- package/build/src/index.d.ts +8 -0
- package/build/src/index.js +99 -63
- package/build/src/instrument.js +4 -1
- package/build/src/metrics/constants.d.ts +7 -6
- package/build/src/metrics/constants.js +18 -13
- package/build/src/metrics/external-types.d.ts +14 -0
- package/build/src/metrics/interceptor.js +12 -18
- package/build/src/metrics/metrics-tracer-factory.d.ts +19 -3
- package/build/src/metrics/metrics-tracer-factory.js +57 -14
- package/build/src/metrics/spanner-metrics-exporter.js +7 -1
- package/build/src/metrics/transform.d.ts +3 -4
- package/build/src/metrics/transform.js +16 -10
- package/build/src/multiplexed-session.d.ts +13 -0
- package/build/src/multiplexed-session.js +20 -8
- package/build/src/partial-result-stream.d.ts +43 -0
- package/build/src/partial-result-stream.js +148 -55
- package/build/src/session-factory.d.ts +13 -0
- package/build/src/session-factory.js +12 -1
- package/build/src/transaction.d.ts +38 -6
- package/build/src/transaction.js +365 -41
- package/package.json +24 -32
package/build/src/transaction.js
CHANGED
|
@@ -31,6 +31,7 @@ var spannerClient = spanner_api_1.protos.google;
|
|
|
31
31
|
var google = spanner_api_1.protos.google;
|
|
32
32
|
var IsolationLevel = google.spanner.v1.TransactionOptions.IsolationLevel;
|
|
33
33
|
var ReadLockMode = google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
|
|
34
|
+
const transaction_runner_1 = require("./transaction-runner");
|
|
34
35
|
const request_id_header_1 = require("./request_id_header");
|
|
35
36
|
const RETRY_INFO_TYPE = 'type.googleapis.com/google.rpc.retryinfo';
|
|
36
37
|
const RETRY_INFO_BIN = 'google.rpc.retryinfo-bin';
|
|
@@ -48,6 +49,17 @@ function injectGaxOpt(existingOpts, key, value) {
|
|
|
48
49
|
}),
|
|
49
50
|
});
|
|
50
51
|
}
|
|
52
|
+
function normalizeError(err) {
|
|
53
|
+
const errorWithCode = err;
|
|
54
|
+
if (errorWithCode.code === undefined) {
|
|
55
|
+
Object.assign(errorWithCode, {
|
|
56
|
+
code: google_gax_1.grpc.status.UNKNOWN,
|
|
57
|
+
details: err.message,
|
|
58
|
+
metadata: new google_gax_1.grpc.Metadata(),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return errorWithCode;
|
|
62
|
+
}
|
|
51
63
|
/**
|
|
52
64
|
* @typedef {object} TimestampBounds
|
|
53
65
|
* @property {boolean} [strong=true] Read at a timestamp where all previously
|
|
@@ -200,28 +212,10 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
200
212
|
},
|
|
201
213
|
},
|
|
202
214
|
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
gaxOpts = injectGaxOpt(config.gaxOpts, 'affinityKey', this._affinityKey);
|
|
210
|
-
}
|
|
211
|
-
config = Object.assign({}, config, { gaxOpts });
|
|
212
|
-
return session.request(config, callback);
|
|
213
|
-
};
|
|
214
|
-
this.requestStream = (config) => {
|
|
215
|
-
let gaxOpts;
|
|
216
|
-
if (!config.gaxOpts || Object.keys(config.gaxOpts).length === 0) {
|
|
217
|
-
gaxOpts = this._bindGaxOpts;
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
gaxOpts = injectGaxOpt(config.gaxOpts, 'affinityKey', this._affinityKey);
|
|
221
|
-
}
|
|
222
|
-
config = Object.assign({}, config, { gaxOpts });
|
|
223
|
-
return session.requestStream(config);
|
|
224
|
-
};
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
216
|
+
this.request = (config, callback) => session.request(this._applyAffinityGaxOpts(config), callback);
|
|
217
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
218
|
+
this.requestStream = (config) => session.requestStream(this._applyAffinityGaxOpts(config));
|
|
225
219
|
}
|
|
226
220
|
else {
|
|
227
221
|
this.request = session.request.bind(session);
|
|
@@ -241,6 +235,34 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
241
235
|
this._latestPreCommitToken = null;
|
|
242
236
|
this._mutationKey = null;
|
|
243
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Binds the multiplexed session affinity key to the gax options of an
|
|
240
|
+
* outgoing request, so that all requests of this transaction are routed to
|
|
241
|
+
* the same gRPC channel.
|
|
242
|
+
*
|
|
243
|
+
* `config` is always a request descriptor that was freshly constructed by the
|
|
244
|
+
* caller for this one RPC (and {@link Spanner#prepareGapicRequest_} already
|
|
245
|
+
* modifies `config.headers` in place), so the affinity key is assigned
|
|
246
|
+
* directly instead of allocating a copy of the descriptor per request.
|
|
247
|
+
*
|
|
248
|
+
* @private
|
|
249
|
+
*
|
|
250
|
+
* @param {object} config The request configuration.
|
|
251
|
+
* @returns {object} The same request configuration.
|
|
252
|
+
*/
|
|
253
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
254
|
+
_applyAffinityGaxOpts(config) {
|
|
255
|
+
if (!config) {
|
|
256
|
+
return config;
|
|
257
|
+
}
|
|
258
|
+
if (!config.gaxOpts || Object.keys(config.gaxOpts).length === 0) {
|
|
259
|
+
config.gaxOpts = this._bindGaxOpts;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
config.gaxOpts = injectGaxOpt(config.gaxOpts, 'affinityKey', this._affinityKey);
|
|
263
|
+
}
|
|
264
|
+
return config;
|
|
265
|
+
}
|
|
244
266
|
_updatePrecommitToken(resp) {
|
|
245
267
|
if (this._latestPreCommitToken === null ||
|
|
246
268
|
this._latestPreCommitToken === undefined ||
|
|
@@ -746,6 +768,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
746
768
|
return;
|
|
747
769
|
}
|
|
748
770
|
this.ended = true;
|
|
771
|
+
this._releaseWaitingRequests(new Error('Transaction has ended.'));
|
|
749
772
|
process.nextTick(() => this.emit('end'));
|
|
750
773
|
if (this._affinityKey) {
|
|
751
774
|
const database = this.session?.parent;
|
|
@@ -754,7 +777,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
754
777
|
if (client?.spannerStub) {
|
|
755
778
|
Promise.resolve(client.spannerStub)
|
|
756
779
|
.then((stub) => {
|
|
757
|
-
stub?.getChannel?.()?.unbind?.(this._affinityKey);
|
|
780
|
+
return stub?.getChannel?.()?.unbind?.(this._affinityKey);
|
|
758
781
|
})
|
|
759
782
|
.catch(() => { });
|
|
760
783
|
}
|
|
@@ -791,6 +814,19 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
791
814
|
});
|
|
792
815
|
}
|
|
793
816
|
run(query, callback) {
|
|
817
|
+
if (this.runStream !== Snapshot.prototype.runStream) {
|
|
818
|
+
return this._runLegacy(query, callback);
|
|
819
|
+
}
|
|
820
|
+
return this._run(query, callback);
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Always runs the query through the full streaming pipeline (Snapshot.prototype.runStream).
|
|
824
|
+
* Used when runStream has been overridden on Snapshot to preserve backward compatibility
|
|
825
|
+
* with custom stream implementations.
|
|
826
|
+
*
|
|
827
|
+
* @private
|
|
828
|
+
*/
|
|
829
|
+
_runLegacy(query, callback) {
|
|
794
830
|
const rows = [];
|
|
795
831
|
let stats;
|
|
796
832
|
let metadata;
|
|
@@ -798,18 +834,11 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
798
834
|
...query,
|
|
799
835
|
...this._traceConfig,
|
|
800
836
|
}, span => {
|
|
801
|
-
|
|
837
|
+
this.runStream(query)
|
|
802
838
|
.on('error', err => {
|
|
803
839
|
(0, instrument_1.setSpanError)(span, err);
|
|
804
840
|
span.end();
|
|
805
|
-
|
|
806
|
-
Object.assign(err, {
|
|
807
|
-
code: google_gax_1.grpc.status.UNKNOWN,
|
|
808
|
-
details: err.message,
|
|
809
|
-
metadata: new google_gax_1.grpc.Metadata(),
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
callback(err, rows, stats, metadata);
|
|
841
|
+
callback(normalizeError(err), rows, stats, metadata);
|
|
813
842
|
})
|
|
814
843
|
.on('response', response => {
|
|
815
844
|
if (response.metadata) {
|
|
@@ -819,14 +848,298 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
819
848
|
}
|
|
820
849
|
}
|
|
821
850
|
})
|
|
822
|
-
.on('data', row =>
|
|
823
|
-
.
|
|
851
|
+
.on('data', row => {
|
|
852
|
+
rows.push(row);
|
|
853
|
+
})
|
|
854
|
+
.on('stats', _stats => {
|
|
855
|
+
stats = _stats;
|
|
856
|
+
})
|
|
824
857
|
.on('end', () => {
|
|
825
858
|
span.end();
|
|
826
859
|
callback(null, rows, stats, metadata);
|
|
827
860
|
});
|
|
828
861
|
});
|
|
829
862
|
}
|
|
863
|
+
/**
|
|
864
|
+
* Executes a query using an optimized streaming model:
|
|
865
|
+
* 1. If all results are returned in a single PartialResultSet, the internal streaming
|
|
866
|
+
* pipeline is simplified and rows are decoded directly, bypassing Stream overhead.
|
|
867
|
+
* 2. If there are more than one PartialResultSets, it seamlessly falls back to
|
|
868
|
+
* the standard streaming model.
|
|
869
|
+
*
|
|
870
|
+
* @private
|
|
871
|
+
*/
|
|
872
|
+
_run(queryInput, callback, options) {
|
|
873
|
+
let query = typeof queryInput === 'string' ? { sql: queryInput } : queryInput;
|
|
874
|
+
query = Object.assign({}, query);
|
|
875
|
+
query.queryOptions = Object.assign(Object.assign({}, this.queryOptions), query.queryOptions);
|
|
876
|
+
const { gaxOptions, json, jsonOptions, maxResumeRetries, requestOptions, columnsMetadata, types: _omittedTypes, directedReadOptions: rawDirectedReadOptions, ...rawQuery } = query;
|
|
877
|
+
void _omittedTypes;
|
|
878
|
+
let formattedRequest;
|
|
879
|
+
const seqno = this._seqno++;
|
|
880
|
+
const directedReadOptions = this._getDirectedReadOptions(rawDirectedReadOptions);
|
|
881
|
+
const sanitizeRequest = () => {
|
|
882
|
+
const { params, paramTypes } = Snapshot.encodeParams(query);
|
|
883
|
+
const transaction = {};
|
|
884
|
+
if (this.id) {
|
|
885
|
+
transaction.id = this.id;
|
|
886
|
+
}
|
|
887
|
+
else if (this._options.readWrite) {
|
|
888
|
+
transaction.begin = this._options;
|
|
889
|
+
}
|
|
890
|
+
else {
|
|
891
|
+
transaction.singleUse = this._options;
|
|
892
|
+
}
|
|
893
|
+
if (!this.id &&
|
|
894
|
+
this._options.readWrite &&
|
|
895
|
+
this.session.parent.isMuxEnabledForRW_) {
|
|
896
|
+
this._setPreviousTransactionId(transaction);
|
|
897
|
+
}
|
|
898
|
+
formattedRequest = Object.assign({}, rawQuery, {
|
|
899
|
+
session: this.session.formattedName_,
|
|
900
|
+
seqno,
|
|
901
|
+
requestOptions: this.configureTagOptions(typeof transaction.singleUse !== 'undefined', this.requestOptions?.transactionTag ?? undefined, requestOptions),
|
|
902
|
+
directedReadOptions,
|
|
903
|
+
transaction,
|
|
904
|
+
params,
|
|
905
|
+
paramTypes,
|
|
906
|
+
});
|
|
907
|
+
};
|
|
908
|
+
const headers = Object.assign({}, this.commonHeaders_);
|
|
909
|
+
if (this._getSpanner().routeToLeaderEnabled &&
|
|
910
|
+
(this._options.readWrite !== undefined ||
|
|
911
|
+
this._options.partitionedDml !== undefined)) {
|
|
912
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
913
|
+
}
|
|
914
|
+
const traceConfig = {
|
|
915
|
+
transactionTag: this.requestOptions?.transactionTag,
|
|
916
|
+
requestTag: requestOptions?.requestTag,
|
|
917
|
+
...query,
|
|
918
|
+
...this._traceConfig,
|
|
919
|
+
};
|
|
920
|
+
const executeWithSpans = (fn) => {
|
|
921
|
+
const startRunSpan = options?.startRunSpan !== false;
|
|
922
|
+
if (startRunSpan) {
|
|
923
|
+
return (0, instrument_1.startTrace)('Snapshot.run', traceConfig, runSpan => {
|
|
924
|
+
return (0, instrument_1.startTrace)('Snapshot.runStream', traceConfig, streamSpan => {
|
|
925
|
+
fn(runSpan, streamSpan);
|
|
926
|
+
});
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
else {
|
|
930
|
+
return (0, instrument_1.startTrace)('Snapshot.runStream', traceConfig, streamSpan => {
|
|
931
|
+
fn(null, streamSpan);
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
executeWithSpans((runSpan, streamSpan) => {
|
|
936
|
+
let attempt = 0;
|
|
937
|
+
const database = this.session.parent;
|
|
938
|
+
const nthRequest = (0, request_id_header_1.nextNthRequest)(database);
|
|
939
|
+
let completed = false;
|
|
940
|
+
const complete = (err, rows = [], stats, metadata) => {
|
|
941
|
+
if (completed) {
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
completed = true;
|
|
945
|
+
if (err) {
|
|
946
|
+
(0, instrument_1.setSpanError)(streamSpan, err);
|
|
947
|
+
}
|
|
948
|
+
streamSpan.end();
|
|
949
|
+
if (runSpan) {
|
|
950
|
+
if (err) {
|
|
951
|
+
(0, instrument_1.setSpanError)(runSpan, err);
|
|
952
|
+
}
|
|
953
|
+
runSpan.end();
|
|
954
|
+
}
|
|
955
|
+
callback(err ? normalizeError(err) : null, rows, stats, metadata);
|
|
956
|
+
};
|
|
957
|
+
const makeRequest = (resumeToken) => {
|
|
958
|
+
attempt++;
|
|
959
|
+
if (!resumeToken) {
|
|
960
|
+
if (attempt === 1) {
|
|
961
|
+
streamSpan.addEvent('Starting stream');
|
|
962
|
+
}
|
|
963
|
+
else {
|
|
964
|
+
streamSpan.addEvent('Re-attempting start stream', { attempt });
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
else {
|
|
968
|
+
streamSpan.addEvent('Resuming stream', {
|
|
969
|
+
resume_token: resumeToken.toString(),
|
|
970
|
+
attempt,
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
if (!formattedRequest ||
|
|
974
|
+
(this.id && !formattedRequest.transaction?.id)) {
|
|
975
|
+
try {
|
|
976
|
+
sanitizeRequest();
|
|
977
|
+
}
|
|
978
|
+
catch (e) {
|
|
979
|
+
const errorStream = new stream_1.PassThrough();
|
|
980
|
+
setImmediate(() => {
|
|
981
|
+
errorStream.destroy(e);
|
|
982
|
+
});
|
|
983
|
+
return errorStream;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
const injectedHeaders = (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session, nthRequest, attempt);
|
|
987
|
+
const requestId = injectedHeaders[request_id_header_1.X_GOOG_SPANNER_REQUEST_ID_HEADER];
|
|
988
|
+
if (runSpan && requestId) {
|
|
989
|
+
runSpan.setAttribute(request_id_header_1.X_GOOG_SPANNER_REQUEST_ID_SPAN_ATTR, requestId);
|
|
990
|
+
}
|
|
991
|
+
return this.requestStream({
|
|
992
|
+
client: 'SpannerClient',
|
|
993
|
+
method: 'executeStreamingSql',
|
|
994
|
+
reqOpts: Object.assign({}, formattedRequest, {
|
|
995
|
+
resumeToken,
|
|
996
|
+
}),
|
|
997
|
+
gaxOpts: gaxOptions,
|
|
998
|
+
headers: injectedHeaders,
|
|
999
|
+
});
|
|
1000
|
+
};
|
|
1001
|
+
const retryableCodes = [google_gax_1.grpc.status.UNAVAILABLE];
|
|
1002
|
+
const wrappedMakeRequest = this._wrapWithIdWaiter(makeRequest);
|
|
1003
|
+
const startTime = Date.now();
|
|
1004
|
+
const timeout = gaxOptions?.timeout ?? Infinity;
|
|
1005
|
+
const executeRequest = () => {
|
|
1006
|
+
const requestStream = this.id ? makeRequest() : wrappedMakeRequest();
|
|
1007
|
+
const onError = (err) => {
|
|
1008
|
+
const elapsed = Date.now() - startTime;
|
|
1009
|
+
let maxRetries = Infinity;
|
|
1010
|
+
if (maxResumeRetries !== undefined) {
|
|
1011
|
+
maxRetries = maxResumeRetries;
|
|
1012
|
+
}
|
|
1013
|
+
else if (timeout === Infinity) {
|
|
1014
|
+
maxRetries = 10;
|
|
1015
|
+
}
|
|
1016
|
+
if (elapsed < timeout &&
|
|
1017
|
+
attempt <= maxRetries &&
|
|
1018
|
+
err.code &&
|
|
1019
|
+
(retryableCodes.includes(err.code) || (0, transaction_runner_1.isRetryableInternalError)(err))) {
|
|
1020
|
+
requestStream.removeAllListeners();
|
|
1021
|
+
requestStream.on('error', () => { });
|
|
1022
|
+
requestStream.destroy();
|
|
1023
|
+
setImmediate(() => {
|
|
1024
|
+
executeRequest();
|
|
1025
|
+
});
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
const wasAborted = isErrorAborted(err);
|
|
1029
|
+
if (!this.id && this._useInRunner && !wasAborted) {
|
|
1030
|
+
streamSpan.addEvent('Stream broken. Safe to retry');
|
|
1031
|
+
void this.begin();
|
|
1032
|
+
}
|
|
1033
|
+
else if (wasAborted) {
|
|
1034
|
+
streamSpan.addEvent('Stream broken. Not safe to retry', {
|
|
1035
|
+
'transaction.id': this.id?.toString(),
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
const finalError = elapsed >= timeout ? new transaction_runner_1.DeadlineError(err) : err;
|
|
1039
|
+
complete(finalError);
|
|
1040
|
+
};
|
|
1041
|
+
const onEnd = () => {
|
|
1042
|
+
requestStream.removeListener('error', onError);
|
|
1043
|
+
complete(null, []);
|
|
1044
|
+
};
|
|
1045
|
+
const onData = (firstChunk) => {
|
|
1046
|
+
requestStream.removeListener('error', onError);
|
|
1047
|
+
requestStream.removeListener('end', onEnd);
|
|
1048
|
+
if (firstChunk.last && !firstChunk.chunkedValue) {
|
|
1049
|
+
// ⚡ FAST-PATH: Complete result in single chunk!
|
|
1050
|
+
if (firstChunk.metadata?.transaction && !this.id) {
|
|
1051
|
+
this._update(firstChunk.metadata.transaction, streamSpan);
|
|
1052
|
+
}
|
|
1053
|
+
this._updatePrecommitToken(firstChunk);
|
|
1054
|
+
let rows;
|
|
1055
|
+
try {
|
|
1056
|
+
rows = (0, partial_result_stream_1.decodeRowsDirect)(firstChunk, {
|
|
1057
|
+
json,
|
|
1058
|
+
jsonOptions,
|
|
1059
|
+
columnsMetadata,
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
catch (decodeErr) {
|
|
1063
|
+
requestStream.removeAllListeners();
|
|
1064
|
+
requestStream.on('error', () => { });
|
|
1065
|
+
requestStream.destroy();
|
|
1066
|
+
complete(decodeErr, [], undefined, firstChunk.metadata || undefined);
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
// Query completed successfully. Do not cancel the gRPC call; allow it
|
|
1070
|
+
// to drain remaining trailers/EOF in the background so it is not marked
|
|
1071
|
+
// CANCELLED by Spanner or Cloud Monitoring.
|
|
1072
|
+
requestStream.removeAllListeners('data');
|
|
1073
|
+
requestStream.removeAllListeners('error');
|
|
1074
|
+
requestStream.on('error', () => { });
|
|
1075
|
+
requestStream.resume();
|
|
1076
|
+
complete(null, rows, firstChunk.stats || undefined, firstChunk.metadata || undefined);
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
// 🌊 FALLBACK PATH: Multi-chunk query!
|
|
1080
|
+
if (firstChunk.metadata?.transaction && !this.id) {
|
|
1081
|
+
this._update(firstChunk.metadata.transaction, streamSpan);
|
|
1082
|
+
}
|
|
1083
|
+
this._updatePrecommitToken(firstChunk);
|
|
1084
|
+
requestStream.removeAllListeners('data');
|
|
1085
|
+
requestStream.removeAllListeners('error');
|
|
1086
|
+
const replayStream = new stream_1.PassThrough({ objectMode: true });
|
|
1087
|
+
replayStream.write(firstChunk);
|
|
1088
|
+
requestStream.pipe(replayStream);
|
|
1089
|
+
requestStream.on('error', err => {
|
|
1090
|
+
replayStream.destroy(err);
|
|
1091
|
+
});
|
|
1092
|
+
replayStream.on('close', () => {
|
|
1093
|
+
if (!requestStream.destroyed) {
|
|
1094
|
+
if (requestStream.readableEnded) {
|
|
1095
|
+
requestStream.resume();
|
|
1096
|
+
}
|
|
1097
|
+
else {
|
|
1098
|
+
requestStream.destroy();
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
let initialStream = replayStream;
|
|
1103
|
+
const fallbackMakeRequest = (resumeToken) => {
|
|
1104
|
+
if (!resumeToken && initialStream) {
|
|
1105
|
+
const stream = initialStream;
|
|
1106
|
+
initialStream = null;
|
|
1107
|
+
return stream;
|
|
1108
|
+
}
|
|
1109
|
+
return makeRequest(resumeToken);
|
|
1110
|
+
};
|
|
1111
|
+
const rows = [];
|
|
1112
|
+
let stats;
|
|
1113
|
+
let metadata;
|
|
1114
|
+
const fallbackStream = (0, partial_result_stream_1.partialResultStream)(fallbackMakeRequest, {
|
|
1115
|
+
json,
|
|
1116
|
+
jsonOptions,
|
|
1117
|
+
maxResumeRetries,
|
|
1118
|
+
columnsMetadata,
|
|
1119
|
+
gaxOptions,
|
|
1120
|
+
});
|
|
1121
|
+
fallbackStream
|
|
1122
|
+
.on('response', response => {
|
|
1123
|
+
this._updatePrecommitToken(response);
|
|
1124
|
+
if (response.metadata?.transaction && !this.id) {
|
|
1125
|
+
this._update(response.metadata.transaction, streamSpan);
|
|
1126
|
+
}
|
|
1127
|
+
if (response.metadata) {
|
|
1128
|
+
metadata = response.metadata;
|
|
1129
|
+
}
|
|
1130
|
+
})
|
|
1131
|
+
.on('data', row => rows.push(row))
|
|
1132
|
+
.on('stats', _stats => (stats = _stats))
|
|
1133
|
+
.on('error', err => complete(err, rows, stats, metadata))
|
|
1134
|
+
.on('end', () => complete(null, rows, stats, metadata));
|
|
1135
|
+
};
|
|
1136
|
+
requestStream.once('error', onError);
|
|
1137
|
+
requestStream.once('data', onData);
|
|
1138
|
+
requestStream.once('end', onEnd);
|
|
1139
|
+
};
|
|
1140
|
+
executeRequest();
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
830
1143
|
/**
|
|
831
1144
|
* ExecuteSql request options. This includes all standard ExecuteSqlRequest
|
|
832
1145
|
* options as well as several convenience properties.
|
|
@@ -1150,6 +1463,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
1150
1463
|
* @returns {object}
|
|
1151
1464
|
*/
|
|
1152
1465
|
static encodeParams(request) {
|
|
1466
|
+
const isUuidUntyped = codec_1.codec.isUuidUntypedEnv();
|
|
1153
1467
|
const typeMap = request.types || {};
|
|
1154
1468
|
const params = { fields: request.params?.fields || {} };
|
|
1155
1469
|
const paramTypes = request.paramTypes || {};
|
|
@@ -1158,7 +1472,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
1158
1472
|
Object.keys(request.params).forEach(param => {
|
|
1159
1473
|
const value = request.params[param];
|
|
1160
1474
|
if (!typeMap[param]) {
|
|
1161
|
-
typeMap[param] = codec_1.codec.getType(value);
|
|
1475
|
+
typeMap[param] = codec_1.codec.getType(value, isUuidUntyped);
|
|
1162
1476
|
}
|
|
1163
1477
|
fields[param] = codec_1.codec.encode(value);
|
|
1164
1478
|
});
|
|
@@ -1167,7 +1481,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
1167
1481
|
if (!(0, helper_1.isEmpty)(typeMap)) {
|
|
1168
1482
|
Object.keys(typeMap).forEach(param => {
|
|
1169
1483
|
const type = typeMap[param];
|
|
1170
|
-
if (
|
|
1484
|
+
if (isUuidUntyped) {
|
|
1171
1485
|
const typeObject = codec_1.codec.createTypeObject(type);
|
|
1172
1486
|
if ((type.child &&
|
|
1173
1487
|
typeObject.code === 'ARRAY' &&
|
|
@@ -1231,10 +1545,17 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
1231
1545
|
}
|
|
1232
1546
|
// Queue subsequent requests.
|
|
1233
1547
|
return (resumeToken) => {
|
|
1548
|
+
if (this.id) {
|
|
1549
|
+
return makeRequest(resumeToken);
|
|
1550
|
+
}
|
|
1234
1551
|
const streamProxy = new stream_1.Readable({
|
|
1235
1552
|
read() { },
|
|
1236
1553
|
});
|
|
1237
|
-
this._waitingRequests.push(() => {
|
|
1554
|
+
this._waitingRequests.push((err) => {
|
|
1555
|
+
if (err) {
|
|
1556
|
+
streamProxy.destroy(err);
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1238
1559
|
makeRequest(resumeToken)
|
|
1239
1560
|
.on('data', chunk => streamProxy.emit('data', chunk))
|
|
1240
1561
|
.on('error', err => streamProxy.emit('error', err))
|
|
@@ -1243,10 +1564,10 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
1243
1564
|
return streamProxy;
|
|
1244
1565
|
};
|
|
1245
1566
|
}
|
|
1246
|
-
_releaseWaitingRequests() {
|
|
1567
|
+
_releaseWaitingRequests(err) {
|
|
1247
1568
|
while (this._waitingRequests.length > 0) {
|
|
1248
1569
|
const request = this._waitingRequests.shift();
|
|
1249
|
-
request?.();
|
|
1570
|
+
request?.(err);
|
|
1250
1571
|
}
|
|
1251
1572
|
}
|
|
1252
1573
|
/**
|
|
@@ -1553,7 +1874,8 @@ class Transaction extends Dml {
|
|
|
1553
1874
|
if (this.session.parent.isMuxEnabledForRW_) {
|
|
1554
1875
|
this._setMutationKey(mutations);
|
|
1555
1876
|
}
|
|
1556
|
-
this.begin()
|
|
1877
|
+
this.begin()
|
|
1878
|
+
.then(() => {
|
|
1557
1879
|
this.commit(options, (err, resp) => {
|
|
1558
1880
|
if (err) {
|
|
1559
1881
|
(0, instrument_1.setSpanError)(span, err);
|
|
@@ -1561,7 +1883,9 @@ class Transaction extends Dml {
|
|
|
1561
1883
|
span.end();
|
|
1562
1884
|
callback(err, resp);
|
|
1563
1885
|
});
|
|
1564
|
-
|
|
1886
|
+
return null;
|
|
1887
|
+
})
|
|
1888
|
+
.catch(err => {
|
|
1565
1889
|
(0, instrument_1.setSpanError)(span, err);
|
|
1566
1890
|
span.end();
|
|
1567
1891
|
callback(err, null);
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@google-cloud/spanner",
|
|
3
3
|
"description": "Cloud Spanner Client Library for Node.js",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "9.0.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Google Inc.",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=22"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
],
|
|
33
33
|
"scripts": {
|
|
34
34
|
"docs": "jsdoc -c .jsdoc.js",
|
|
35
|
-
"predocs": "
|
|
35
|
+
"predocs": "pnpm run compile",
|
|
36
36
|
"lint": "gts check",
|
|
37
37
|
"system-test": "mocha build/system-test --timeout 1600000",
|
|
38
38
|
"observability-test": "mocha build/observability-test --timeout 1600000",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"clean": "gts clean",
|
|
44
44
|
"compile": "tsc -p . && cp -r protos build && cp -r test/data build/test",
|
|
45
45
|
"prepare": "cp -r protos build && npm run compile",
|
|
46
|
-
"pretest": "
|
|
47
|
-
"presystem-test": "
|
|
48
|
-
"preobservability-test": "
|
|
46
|
+
"pretest": "pnpm run compile",
|
|
47
|
+
"presystem-test": "pnpm run compile",
|
|
48
|
+
"preobservability-test": "pnpm run compile",
|
|
49
49
|
"benchwrapper": "node bin/benchwrapper.js",
|
|
50
50
|
"precompile": "gts clean",
|
|
51
51
|
"coverage": "c8 mocha build/test build/test/common && c8 report --check-coverage"
|
|
@@ -54,42 +54,42 @@
|
|
|
54
54
|
"@babel/core": "7.27.7",
|
|
55
55
|
"@babel/helpers": "7.27.6",
|
|
56
56
|
"@babel/traverse": "7.27.7",
|
|
57
|
-
"@google-cloud/common": "^
|
|
58
|
-
"@google-cloud/monitoring": "^
|
|
59
|
-
"@google-cloud/
|
|
60
|
-
"@google-cloud/
|
|
61
|
-
"@google-cloud/
|
|
62
|
-
"@google-cloud/spanner-api": "^0.2.0",
|
|
57
|
+
"@google-cloud/common": "^8.0.0",
|
|
58
|
+
"@google-cloud/monitoring": "^6.0.0",
|
|
59
|
+
"@google-cloud/precise-date": "^6.0.0",
|
|
60
|
+
"@google-cloud/promisify": "^6.0.0",
|
|
61
|
+
"@google-cloud/spanner-api": "^0.4.0",
|
|
63
62
|
"@grpc/grpc-js": "^1.13.2",
|
|
64
63
|
"@grpc/proto-loader": "^0.8.0",
|
|
65
64
|
"@opentelemetry/api": "^1.9.0",
|
|
66
65
|
"@opentelemetry/context-async-hooks": "^2.0.0",
|
|
67
66
|
"@opentelemetry/core": "^2.0.0",
|
|
68
|
-
"@opentelemetry/
|
|
69
|
-
"@opentelemetry/
|
|
67
|
+
"@opentelemetry/resource-detector-gcp": "^0.57.0",
|
|
68
|
+
"@opentelemetry/resources": "^2.11.0",
|
|
69
|
+
"@opentelemetry/sdk-metrics": "^2.11.0",
|
|
70
70
|
"@opentelemetry/semantic-conventions": "^1.30.0",
|
|
71
71
|
"@types/big.js": "^6.2.2",
|
|
72
72
|
"@types/stack-trace": "^0.0.33",
|
|
73
73
|
"big.js": "^7.0.0",
|
|
74
74
|
"duplexify": "^4.1.3",
|
|
75
75
|
"extend": "^3.0.2",
|
|
76
|
-
"google-auth-library": "^
|
|
77
|
-
"google-gax": "
|
|
76
|
+
"google-auth-library": "^11.0.0",
|
|
77
|
+
"google-gax": "^6.0.0",
|
|
78
78
|
"grpc-gcp": "^1.0.1",
|
|
79
79
|
"lodash.snakecase": "^4.1.1",
|
|
80
80
|
"p-queue": "^6.0.2",
|
|
81
81
|
"protobufjs": "^7.4.0",
|
|
82
|
-
"retry-request": "^
|
|
82
|
+
"retry-request": "^9.0.0",
|
|
83
83
|
"stack-trace": "0.0.10",
|
|
84
84
|
"stream-events": "^1.0.5",
|
|
85
|
-
"teeny-request": "^
|
|
85
|
+
"teeny-request": "^11.0.0",
|
|
86
86
|
"through2": "^4.0.2"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@grpc/reflection": "^1.0.4",
|
|
90
|
-
"@opentelemetry/sdk-trace-base": "^2.
|
|
90
|
+
"@opentelemetry/sdk-trace-base": "^2.11.0",
|
|
91
91
|
"@opentelemetry/sdk-trace-node": "^2.0.0",
|
|
92
|
-
"@opentelemetry/exporter-trace-otlp-grpc": "^0.
|
|
92
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.222.0",
|
|
93
93
|
"@types/concat-stream": "^2.0.3",
|
|
94
94
|
"@types/extend": "^3.0.4",
|
|
95
95
|
"@types/is": "^0.0.25",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"@types/mocha": "^10.0.10",
|
|
98
98
|
"@types/mv": "^2.1.4",
|
|
99
99
|
"@types/ncp": "^2.0.8",
|
|
100
|
-
"@types/node": "^
|
|
100
|
+
"@types/node": "^22.18.12",
|
|
101
101
|
"@types/proxyquire": "^1.3.31",
|
|
102
102
|
"@types/request": "^2.48.12",
|
|
103
103
|
"@types/sinon": "^21.0.0",
|
|
@@ -109,12 +109,12 @@
|
|
|
109
109
|
"concat-stream": "^2.0.0",
|
|
110
110
|
"dedent": "^1.5.3",
|
|
111
111
|
"execa": "^5.0.0",
|
|
112
|
-
"gapic-tools": "^
|
|
112
|
+
"gapic-tools": "^2.0.0",
|
|
113
113
|
"grpc-health-check": "^2.1.0",
|
|
114
114
|
"gts": "^6.0.2",
|
|
115
115
|
"jsdoc": "^4.0.4",
|
|
116
|
-
"jsdoc-fresh": "^
|
|
117
|
-
"jsdoc-region-tag": "^
|
|
116
|
+
"jsdoc-fresh": "^6.0.0",
|
|
117
|
+
"jsdoc-region-tag": "^5.0.0",
|
|
118
118
|
"lodash.random": "^3.2.0",
|
|
119
119
|
"long": "^5.3.2",
|
|
120
120
|
"mocha": "^11.1.0",
|
|
@@ -132,17 +132,9 @@
|
|
|
132
132
|
"yargs": "^17.7.2"
|
|
133
133
|
},
|
|
134
134
|
"overrides": {
|
|
135
|
-
"gcp-metadata": "^7.0.1",
|
|
136
135
|
"@sinonjs/fake-timers": "15.2.1",
|
|
137
136
|
"brace-expansion": "5.0.7",
|
|
138
137
|
"@eslint-community/eslint-utils": "<4.10.0"
|
|
139
138
|
},
|
|
140
|
-
"pnpm": {
|
|
141
|
-
"overrides": {
|
|
142
|
-
"gcp-metadata": "^7.0.1",
|
|
143
|
-
"@sinonjs/fake-timers": "15.2.1",
|
|
144
|
-
"@eslint-community/eslint-utils": "<4.10.0"
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
139
|
"homepage": "https://github.com/googleapis/google-cloud-node/tree/main/handwritten/spanner"
|
|
148
140
|
}
|