@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
|
@@ -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.
|
|
@@ -80,53 +80,13 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
80
80
|
callback();
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
* @property {string} partitionToken The partition token.
|
|
87
|
-
*/
|
|
88
|
-
/**
|
|
89
|
-
* @typedef {array} CreateQueryPartitionsResponse
|
|
90
|
-
* @property {QueryPartition[]} 0 List of query partitions.
|
|
91
|
-
* @property {object} 1 The full API response.
|
|
92
|
-
*/
|
|
93
|
-
/**
|
|
94
|
-
* @callback CreateQueryPartitionsCallback
|
|
95
|
-
* @param {?Error} err Request error, if any.
|
|
96
|
-
* @param {QueryPartition[]} partitions List of query partitions.
|
|
97
|
-
* @param {object} apiResponse The full API response.
|
|
98
|
-
*/
|
|
99
|
-
/**
|
|
100
|
-
* Creates a set of query partitions that can be used to execute a query
|
|
101
|
-
* operation in parallel. Partitions become invalid when the transaction used
|
|
102
|
-
* to create them is closed.
|
|
103
|
-
*
|
|
104
|
-
* @param {string|object} query A SQL query or
|
|
105
|
-
* [`ExecuteSqlRequest`](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ExecuteSqlRequest)
|
|
106
|
-
* object.
|
|
107
|
-
* @param {object} [query.gaxOptions] Request configuration options,
|
|
108
|
-
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
109
|
-
* for more details.
|
|
110
|
-
* @param {object} [query.params] A map of parameter name to values.
|
|
111
|
-
* @param {object} [query.partitionOptions] A map of partition options.
|
|
112
|
-
* @param {object} [query.types] A map of parameter types.
|
|
113
|
-
* @param {CreateQueryPartitionsCallback} [callback] Callback callback function.
|
|
114
|
-
* @returns {Promise<CreateQueryPartitionsResponse>}
|
|
115
|
-
*
|
|
116
|
-
* @example <caption>include:samples/batch.js</caption>
|
|
117
|
-
* region_tag:spanner_batch_client
|
|
118
|
-
*/
|
|
119
|
-
createQueryPartitions(query, callback) {
|
|
120
|
-
if (is.string(query)) {
|
|
121
|
-
query = {
|
|
122
|
-
sql: query,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
const reqOpts = Object.assign({}, query, transaction_1.Snapshot.encodeParams(query));
|
|
83
|
+
createQueryPartitions(query, cb) {
|
|
84
|
+
const request = typeof query === 'string' ? { sql: query } : query;
|
|
85
|
+
const reqOpts = Object.assign({}, request, transaction_1.Snapshot.encodeParams(request));
|
|
126
86
|
delete reqOpts.gaxOptions;
|
|
127
87
|
delete reqOpts.types;
|
|
128
88
|
const traceConfig = {
|
|
129
|
-
sql:
|
|
89
|
+
sql: request.sql,
|
|
130
90
|
opts: this._observabilityOptions,
|
|
131
91
|
dbName: this.getDBName(),
|
|
132
92
|
};
|
|
@@ -139,14 +99,14 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
139
99
|
client: 'SpannerClient',
|
|
140
100
|
method: 'partitionQuery',
|
|
141
101
|
reqOpts,
|
|
142
|
-
gaxOpts:
|
|
102
|
+
gaxOpts: request.gaxOptions,
|
|
143
103
|
headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session),
|
|
144
104
|
}, (err, partitions, resp) => {
|
|
145
105
|
if (err) {
|
|
146
106
|
(0, instrument_1.setSpanError)(span, err);
|
|
147
107
|
}
|
|
148
108
|
span.end();
|
|
149
|
-
|
|
109
|
+
cb(err, partitions, resp);
|
|
150
110
|
});
|
|
151
111
|
});
|
|
152
112
|
}
|
|
@@ -203,36 +163,7 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
203
163
|
});
|
|
204
164
|
});
|
|
205
165
|
}
|
|
206
|
-
|
|
207
|
-
* @typedef {object} ReadPartition
|
|
208
|
-
* @mixes ReadRequestOptions
|
|
209
|
-
* @property {string} partitionToken The partition token.
|
|
210
|
-
* @property {object} [gaxOptions] Request configuration options,
|
|
211
|
-
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
212
|
-
* for more details.
|
|
213
|
-
*/
|
|
214
|
-
/**
|
|
215
|
-
* @typedef {array} CreateReadPartitionsResponse
|
|
216
|
-
* @property {ReadPartition[]} 0 List of read partitions.
|
|
217
|
-
* @property {object} 1 The full API response.
|
|
218
|
-
*/
|
|
219
|
-
/**
|
|
220
|
-
* @callback CreateReadPartitionsCallback
|
|
221
|
-
* @param {?Error} err Request error, if any.
|
|
222
|
-
* @param {ReadPartition[]} partitions List of read partitions.
|
|
223
|
-
* @param {object} apiResponse The full API response.
|
|
224
|
-
*/
|
|
225
|
-
/**
|
|
226
|
-
* Creates a set of read partitions that can be used to execute a read
|
|
227
|
-
* operation in parallel. Partitions become invalid when the transaction used
|
|
228
|
-
* to create them is closed.
|
|
229
|
-
*
|
|
230
|
-
* @param {ReadRequestOptions} options Configuration object, describing what to
|
|
231
|
-
* read from.
|
|
232
|
-
* @param {CreateReadPartitionsCallback} [callback] Callback function.
|
|
233
|
-
* @returns {Promise<CreateReadPartitionsResponse>}
|
|
234
|
-
*/
|
|
235
|
-
createReadPartitions(options, callback) {
|
|
166
|
+
createReadPartitions(options, cb) {
|
|
236
167
|
const traceConfig = {
|
|
237
168
|
opts: this._observabilityOptions,
|
|
238
169
|
dbName: this.getDBName(),
|
|
@@ -259,33 +190,17 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
259
190
|
(0, instrument_1.setSpanError)(span, err);
|
|
260
191
|
}
|
|
261
192
|
span.end();
|
|
262
|
-
|
|
193
|
+
cb(err, partitions, resp);
|
|
263
194
|
});
|
|
264
195
|
});
|
|
265
196
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
* @see {@link Transaction#run} when using {@link QueryParition}.
|
|
271
|
-
*
|
|
272
|
-
* @param {ReadPartition|QueryParition} partition The partition object.
|
|
273
|
-
* @param {object} [partition.gaxOptions] Request configuration options,
|
|
274
|
-
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
275
|
-
* for more details.
|
|
276
|
-
* @param {TransactionRequestReadCallback|RunCallback} [callback] Callback
|
|
277
|
-
* function.
|
|
278
|
-
* @returns {Promise<RunResponse>|Promise<TransactionRequestReadResponse>}
|
|
279
|
-
*
|
|
280
|
-
* @example <caption>include:samples/batch.js</caption>
|
|
281
|
-
* region_tag:spanner_batch_execute_partitions
|
|
282
|
-
*/
|
|
283
|
-
execute(partition, callback) {
|
|
284
|
-
if (is.string(partition.table)) {
|
|
285
|
-
this.read(partition.table, partition, callback);
|
|
197
|
+
execute(partition, cb) {
|
|
198
|
+
const isRead = typeof partition.table === 'string';
|
|
199
|
+
if (isRead) {
|
|
200
|
+
this.read(partition.table, partition, cb);
|
|
286
201
|
return;
|
|
287
202
|
}
|
|
288
|
-
this.run(partition,
|
|
203
|
+
this.run(partition, cb);
|
|
289
204
|
}
|
|
290
205
|
/**
|
|
291
206
|
* Executes partition in streaming mode.
|
|
@@ -336,7 +251,7 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
336
251
|
*/
|
|
337
252
|
executeStream(partition) {
|
|
338
253
|
// TODO: Instrument the streams with Otel.
|
|
339
|
-
if (
|
|
254
|
+
if ((0, helper_1.isString)(partition.table)) {
|
|
340
255
|
return this.createReadStream(partition.table, partition);
|
|
341
256
|
}
|
|
342
257
|
return this.runStream(partition);
|
package/build/src/codec.js
CHANGED
|
@@ -18,9 +18,8 @@ exports.codec = exports.Interval = exports.PGOid = exports.PGJsonb = exports.Pro
|
|
|
18
18
|
*/
|
|
19
19
|
const service_1 = require("./common-grpc/service");
|
|
20
20
|
const precise_date_1 = require("@google-cloud/precise-date");
|
|
21
|
-
const
|
|
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
|
/**
|
|
@@ -85,12 +84,14 @@ exports.SpannerDate = SpannerDate;
|
|
|
85
84
|
* @private
|
|
86
85
|
*/
|
|
87
86
|
class WrappedNumber {
|
|
87
|
+
value;
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* @typedef Float32
|
|
91
91
|
* @see Spanner.float32
|
|
92
92
|
*/
|
|
93
93
|
class Float32 extends WrappedNumber {
|
|
94
|
+
value;
|
|
94
95
|
constructor(value) {
|
|
95
96
|
super();
|
|
96
97
|
this.value = value;
|
|
@@ -105,6 +106,7 @@ exports.Float32 = Float32;
|
|
|
105
106
|
* @see Spanner.float
|
|
106
107
|
*/
|
|
107
108
|
class Float extends WrappedNumber {
|
|
109
|
+
value;
|
|
108
110
|
constructor(value) {
|
|
109
111
|
super();
|
|
110
112
|
this.value = value;
|
|
@@ -119,6 +121,7 @@ exports.Float = Float;
|
|
|
119
121
|
* @see Spanner.int
|
|
120
122
|
*/
|
|
121
123
|
class Int extends WrappedNumber {
|
|
124
|
+
value;
|
|
122
125
|
constructor(value) {
|
|
123
126
|
super();
|
|
124
127
|
this.value = value.toString();
|
|
@@ -179,6 +182,7 @@ exports.Struct = Struct;
|
|
|
179
182
|
* @see Spanner.numeric
|
|
180
183
|
*/
|
|
181
184
|
class Numeric {
|
|
185
|
+
value;
|
|
182
186
|
constructor(value) {
|
|
183
187
|
this.value = value;
|
|
184
188
|
}
|
|
@@ -195,6 +199,7 @@ exports.Numeric = Numeric;
|
|
|
195
199
|
* @see Spanner.pgNumeric
|
|
196
200
|
*/
|
|
197
201
|
class PGNumeric {
|
|
202
|
+
value;
|
|
198
203
|
constructor(pgValue) {
|
|
199
204
|
this.value = pgValue.toString();
|
|
200
205
|
}
|
|
@@ -214,6 +219,9 @@ exports.PGNumeric = PGNumeric;
|
|
|
214
219
|
* @see Spanner.protoMessage
|
|
215
220
|
*/
|
|
216
221
|
class ProtoMessage {
|
|
222
|
+
value;
|
|
223
|
+
fullName;
|
|
224
|
+
messageFunction;
|
|
217
225
|
constructor(protoMessageParams) {
|
|
218
226
|
this.fullName = protoMessageParams.fullName;
|
|
219
227
|
this.messageFunction = protoMessageParams.messageFunction;
|
|
@@ -243,6 +251,9 @@ exports.ProtoMessage = ProtoMessage;
|
|
|
243
251
|
* @see Spanner.protoEnum
|
|
244
252
|
*/
|
|
245
253
|
class ProtoEnum {
|
|
254
|
+
value;
|
|
255
|
+
fullName;
|
|
256
|
+
enumObject;
|
|
246
257
|
constructor(protoEnumParams) {
|
|
247
258
|
this.fullName = protoEnumParams.fullName;
|
|
248
259
|
this.enumObject = protoEnumParams.enumObject;
|
|
@@ -277,6 +288,7 @@ exports.ProtoEnum = ProtoEnum;
|
|
|
277
288
|
* @see Spanner.pgJsonb
|
|
278
289
|
*/
|
|
279
290
|
class PGJsonb {
|
|
291
|
+
value;
|
|
280
292
|
constructor(pgValue) {
|
|
281
293
|
if (typeof pgValue === 'string') {
|
|
282
294
|
pgValue = JSON.parse(pgValue);
|
|
@@ -293,6 +305,7 @@ exports.PGJsonb = PGJsonb;
|
|
|
293
305
|
* @see Spanner.pgOid
|
|
294
306
|
*/
|
|
295
307
|
class PGOid extends WrappedNumber {
|
|
308
|
+
value;
|
|
296
309
|
constructor(value) {
|
|
297
310
|
super();
|
|
298
311
|
this.value = value.toString();
|
|
@@ -311,19 +324,45 @@ exports.PGOid = PGOid;
|
|
|
311
324
|
* @see Spanner.interval
|
|
312
325
|
*/
|
|
313
326
|
class Interval {
|
|
327
|
+
months;
|
|
328
|
+
days;
|
|
329
|
+
nanoseconds;
|
|
330
|
+
// Regex to parse ISO8601 duration format: P[n]Y[n]M[n]DT[n]H[n]M[n][.fffffffff]S
|
|
331
|
+
// Only seconds can be fractional, and can have at most 9 digits after decimal point.
|
|
332
|
+
// Both '.' and ',' are considered valid decimal point.
|
|
333
|
+
static ISO8601_PATTERN = /^P(?!$)(-?\d+Y)?(-?\d+M)?(-?\d+D)?(T(?=-?[.,]?\d)(-?\d+H)?(-?\d+M)?(-?(((\d+)([.,]\d{1,9})?)|([.,]\d{1,9}))S)?)?$/;
|
|
334
|
+
static MONTHS_PER_YEAR = 12;
|
|
335
|
+
static DAYS_PER_MONTH = 30;
|
|
336
|
+
static HOURS_PER_DAY = 24;
|
|
337
|
+
static MINUTES_PER_HOUR = 60;
|
|
338
|
+
static SECONDS_PER_MINUTE = 60;
|
|
339
|
+
static SECONDS_PER_HOUR = Interval.MINUTES_PER_HOUR * Interval.SECONDS_PER_MINUTE;
|
|
340
|
+
static MILLISECONDS_PER_SECOND = 1000;
|
|
341
|
+
static MICROSECONDS_PER_MILLISECOND = 1000;
|
|
342
|
+
static NANOSECONDS_PER_MICROSECOND = 1000;
|
|
343
|
+
static NANOSECONDS_PER_MILLISECOND = Interval.MICROSECONDS_PER_MILLISECOND *
|
|
344
|
+
Interval.NANOSECONDS_PER_MICROSECOND;
|
|
345
|
+
static NANOSECONDS_PER_SECOND = Interval.MILLISECONDS_PER_SECOND *
|
|
346
|
+
Interval.MICROSECONDS_PER_MILLISECOND *
|
|
347
|
+
Interval.NANOSECONDS_PER_MICROSECOND;
|
|
348
|
+
static NANOSECONDS_PER_DAY = BigInt(Interval.HOURS_PER_DAY) *
|
|
349
|
+
BigInt(Interval.SECONDS_PER_HOUR) *
|
|
350
|
+
BigInt(Interval.NANOSECONDS_PER_SECOND);
|
|
351
|
+
static NANOSECONDS_PER_MONTH = BigInt(Interval.DAYS_PER_MONTH) * Interval.NANOSECONDS_PER_DAY;
|
|
352
|
+
static ZERO = new Interval(0, 0, BigInt(0));
|
|
314
353
|
/**
|
|
315
354
|
* @param months months part of the `Interval`
|
|
316
355
|
* @param days days part of the `Interval`
|
|
317
356
|
* @param nanoseconds nanoseconds part of the `Interval`
|
|
318
357
|
*/
|
|
319
358
|
constructor(months, days, nanoseconds) {
|
|
320
|
-
if (!
|
|
359
|
+
if (!(0, helper_1.isInteger)(months)) {
|
|
321
360
|
throw new google_gax_1.GoogleError(`Invalid months: ${months}, months should be an integral value`);
|
|
322
361
|
}
|
|
323
|
-
if (!
|
|
362
|
+
if (!(0, helper_1.isInteger)(days)) {
|
|
324
363
|
throw new google_gax_1.GoogleError(`Invalid days: ${days}, days should be an integral value`);
|
|
325
364
|
}
|
|
326
|
-
if (
|
|
365
|
+
if ((0, helper_1.isNull)(nanoseconds) || (0, helper_1.isUndefined)(nanoseconds)) {
|
|
327
366
|
throw new google_gax_1.GoogleError(`Invalid nanoseconds: ${nanoseconds}, nanoseconds should be a valid bigint value`);
|
|
328
367
|
}
|
|
329
368
|
this.months = months;
|
|
@@ -364,7 +403,7 @@ class Interval {
|
|
|
364
403
|
* Constructs an `Interval` with specified seconds.
|
|
365
404
|
*/
|
|
366
405
|
static fromSeconds(seconds) {
|
|
367
|
-
if (!
|
|
406
|
+
if (!(0, helper_1.isInteger)(seconds)) {
|
|
368
407
|
throw new google_gax_1.GoogleError(`Invalid seconds: ${seconds}, seconds should be an integral value`);
|
|
369
408
|
}
|
|
370
409
|
return new Interval(0, 0, BigInt(Interval.NANOSECONDS_PER_SECOND) * BigInt(seconds));
|
|
@@ -373,7 +412,7 @@ class Interval {
|
|
|
373
412
|
* Constructs an `Interval` with specified milliseconds.
|
|
374
413
|
*/
|
|
375
414
|
static fromMilliseconds(milliseconds) {
|
|
376
|
-
if (!
|
|
415
|
+
if (!(0, helper_1.isInteger)(milliseconds)) {
|
|
377
416
|
throw new google_gax_1.GoogleError(`Invalid milliseconds: ${milliseconds}, milliseconds should be an integral value`);
|
|
378
417
|
}
|
|
379
418
|
return new Interval(0, 0, BigInt(Interval.NANOSECONDS_PER_MILLISECOND) * BigInt(milliseconds));
|
|
@@ -382,7 +421,7 @@ class Interval {
|
|
|
382
421
|
* Constructs an `Interval` with specified microseconds.
|
|
383
422
|
*/
|
|
384
423
|
static fromMicroseconds(microseconds) {
|
|
385
|
-
if (!
|
|
424
|
+
if (!(0, helper_1.isInteger)(microseconds)) {
|
|
386
425
|
throw new google_gax_1.GoogleError(`Invalid microseconds: ${microseconds}, microseconds should be an integral value`);
|
|
387
426
|
}
|
|
388
427
|
return new Interval(0, 0, BigInt(Interval.NANOSECONDS_PER_MICROSECOND) * BigInt(microseconds));
|
|
@@ -513,29 +552,6 @@ class Interval {
|
|
|
513
552
|
}
|
|
514
553
|
}
|
|
515
554
|
exports.Interval = Interval;
|
|
516
|
-
// Regex to parse ISO8601 duration format: P[n]Y[n]M[n]DT[n]H[n]M[n][.fffffffff]S
|
|
517
|
-
// Only seconds can be fractional, and can have at most 9 digits after decimal point.
|
|
518
|
-
// Both '.' and ',' are considered valid decimal point.
|
|
519
|
-
Interval.ISO8601_PATTERN = /^P(?!$)(-?\d+Y)?(-?\d+M)?(-?\d+D)?(T(?=-?[.,]?\d)(-?\d+H)?(-?\d+M)?(-?(((\d+)([.,]\d{1,9})?)|([.,]\d{1,9}))S)?)?$/;
|
|
520
|
-
Interval.MONTHS_PER_YEAR = 12;
|
|
521
|
-
Interval.DAYS_PER_MONTH = 30;
|
|
522
|
-
Interval.HOURS_PER_DAY = 24;
|
|
523
|
-
Interval.MINUTES_PER_HOUR = 60;
|
|
524
|
-
Interval.SECONDS_PER_MINUTE = 60;
|
|
525
|
-
Interval.SECONDS_PER_HOUR = Interval.MINUTES_PER_HOUR * Interval.SECONDS_PER_MINUTE;
|
|
526
|
-
Interval.MILLISECONDS_PER_SECOND = 1000;
|
|
527
|
-
Interval.MICROSECONDS_PER_MILLISECOND = 1000;
|
|
528
|
-
Interval.NANOSECONDS_PER_MICROSECOND = 1000;
|
|
529
|
-
Interval.NANOSECONDS_PER_MILLISECOND = Interval.MICROSECONDS_PER_MILLISECOND *
|
|
530
|
-
Interval.NANOSECONDS_PER_MICROSECOND;
|
|
531
|
-
Interval.NANOSECONDS_PER_SECOND = Interval.MILLISECONDS_PER_SECOND *
|
|
532
|
-
Interval.MICROSECONDS_PER_MILLISECOND *
|
|
533
|
-
Interval.NANOSECONDS_PER_MICROSECOND;
|
|
534
|
-
Interval.NANOSECONDS_PER_DAY = BigInt(Interval.HOURS_PER_DAY) *
|
|
535
|
-
BigInt(Interval.SECONDS_PER_HOUR) *
|
|
536
|
-
BigInt(Interval.NANOSECONDS_PER_SECOND);
|
|
537
|
-
Interval.NANOSECONDS_PER_MONTH = BigInt(Interval.DAYS_PER_MONTH) * Interval.NANOSECONDS_PER_DAY;
|
|
538
|
-
Interval.ZERO = new Interval(0, 0, BigInt(0));
|
|
539
555
|
/**
|
|
540
556
|
* @typedef JSONOptions
|
|
541
557
|
* @property {boolean} [wrapNumbers=false] Indicates if the numbers should be
|
|
@@ -625,7 +641,7 @@ function convertValueToJson(value, options) {
|
|
|
625
641
|
* @returns {*}
|
|
626
642
|
*/
|
|
627
643
|
function decode(value, type, columnMetadata) {
|
|
628
|
-
if (
|
|
644
|
+
if ((0, helper_1.isNull)(value)) {
|
|
629
645
|
return null;
|
|
630
646
|
}
|
|
631
647
|
let decoded = value;
|
|
@@ -743,10 +759,10 @@ function encode(value) {
|
|
|
743
759
|
* @returns {*}
|
|
744
760
|
*/
|
|
745
761
|
function encodeValue(value) {
|
|
746
|
-
if (
|
|
762
|
+
if ((0, helper_1.isNumber)(value) && !(0, helper_1.isDecimal)(value)) {
|
|
747
763
|
return value.toString();
|
|
748
764
|
}
|
|
749
|
-
if (
|
|
765
|
+
if ((0, helper_1.isDate)(value)) {
|
|
750
766
|
return value.toJSON();
|
|
751
767
|
}
|
|
752
768
|
if (value instanceof WrappedNumber) {
|
|
@@ -770,7 +786,7 @@ function encodeValue(value) {
|
|
|
770
786
|
if (value instanceof Struct) {
|
|
771
787
|
return Array.from(value).map(field => encodeValue(field.value));
|
|
772
788
|
}
|
|
773
|
-
if (
|
|
789
|
+
if ((0, helper_1.isArray)(value)) {
|
|
774
790
|
return value.map(encodeValue);
|
|
775
791
|
}
|
|
776
792
|
if (value instanceof PGJsonb) {
|
|
@@ -779,7 +795,7 @@ function encodeValue(value) {
|
|
|
779
795
|
if (value instanceof Interval) {
|
|
780
796
|
return value.toISO8601();
|
|
781
797
|
}
|
|
782
|
-
if (
|
|
798
|
+
if ((0, helper_1.isObject)(value)) {
|
|
783
799
|
return JSON.stringify(value);
|
|
784
800
|
}
|
|
785
801
|
return value;
|
|
@@ -853,14 +869,14 @@ const TypeCode = {
|
|
|
853
869
|
* ```
|
|
854
870
|
*/
|
|
855
871
|
function getType(value) {
|
|
856
|
-
const isSpecialNumber =
|
|
872
|
+
const isSpecialNumber = (0, helper_1.isInfinite)(value) || ((0, helper_1.isNumber)(value) && isNaN(value));
|
|
857
873
|
if (value instanceof Float32) {
|
|
858
874
|
return { type: 'float32' };
|
|
859
875
|
}
|
|
860
|
-
if (
|
|
876
|
+
if ((0, helper_1.isDecimal)(value) || isSpecialNumber || value instanceof Float) {
|
|
861
877
|
return { type: 'float64' };
|
|
862
878
|
}
|
|
863
|
-
if (
|
|
879
|
+
if ((0, helper_1.isNumber)(value) || value instanceof Int) {
|
|
864
880
|
return { type: 'int64' };
|
|
865
881
|
}
|
|
866
882
|
if (value instanceof Numeric) {
|
|
@@ -884,10 +900,10 @@ function getType(value) {
|
|
|
884
900
|
if (value instanceof ProtoEnum) {
|
|
885
901
|
return { type: 'enum', fullName: value.fullName };
|
|
886
902
|
}
|
|
887
|
-
if (
|
|
903
|
+
if ((0, helper_1.isBoolean)(value)) {
|
|
888
904
|
return { type: 'bool' };
|
|
889
905
|
}
|
|
890
|
-
if (
|
|
906
|
+
if ((0, helper_1.isString)(value)) {
|
|
891
907
|
return { type: 'string' };
|
|
892
908
|
}
|
|
893
909
|
if (Buffer.isBuffer(value)) {
|
|
@@ -896,7 +912,7 @@ function getType(value) {
|
|
|
896
912
|
if (value instanceof SpannerDate) {
|
|
897
913
|
return { type: 'date' };
|
|
898
914
|
}
|
|
899
|
-
if (
|
|
915
|
+
if ((0, helper_1.isDate)(value)) {
|
|
900
916
|
return { type: 'timestamp' };
|
|
901
917
|
}
|
|
902
918
|
if (value instanceof Struct) {
|
|
@@ -907,11 +923,11 @@ function getType(value) {
|
|
|
907
923
|
}),
|
|
908
924
|
};
|
|
909
925
|
}
|
|
910
|
-
if (
|
|
926
|
+
if ((0, helper_1.isArray)(value)) {
|
|
911
927
|
let child;
|
|
912
928
|
for (let i = 0; i < value.length; i++) {
|
|
913
929
|
child = value[i];
|
|
914
|
-
if (!
|
|
930
|
+
if (!(0, helper_1.isNull)(child)) {
|
|
915
931
|
break;
|
|
916
932
|
}
|
|
917
933
|
}
|
|
@@ -920,7 +936,7 @@ function getType(value) {
|
|
|
920
936
|
child: getType(child),
|
|
921
937
|
};
|
|
922
938
|
}
|
|
923
|
-
if (
|
|
939
|
+
if ((0, helper_1.isObject)(value)) {
|
|
924
940
|
return { type: 'json' };
|
|
925
941
|
}
|
|
926
942
|
return { type: 'unspecified' };
|
|
@@ -934,7 +950,7 @@ function getType(value) {
|
|
|
934
950
|
* @returns {object}
|
|
935
951
|
*/
|
|
936
952
|
function convertToListValue(value) {
|
|
937
|
-
const values =
|
|
953
|
+
const values = (0, helper_1.toArray)(value).map(exports.codec.encode);
|
|
938
954
|
return { values };
|
|
939
955
|
}
|
|
940
956
|
/**
|
|
@@ -992,7 +1008,7 @@ function createTypeObject(friendlyType) {
|
|
|
992
1008
|
}
|
|
993
1009
|
if (code === 'STRUCT') {
|
|
994
1010
|
type.structType = {
|
|
995
|
-
fields:
|
|
1011
|
+
fields: (0, helper_1.toArray)(config.fields).map(field => {
|
|
996
1012
|
return { name: field.name, type: exports.codec.createTypeObject(field) };
|
|
997
1013
|
}),
|
|
998
1014
|
};
|
|
@@ -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
|
/**
|
|
@@ -125,6 +125,9 @@ const GRPC_SERVICE_OPTIONS = {
|
|
|
125
125
|
'grpc.initial_reconnect_backoff_ms': 5000,
|
|
126
126
|
};
|
|
127
127
|
class ObjectToStructConverter {
|
|
128
|
+
seenObjects;
|
|
129
|
+
removeCircular;
|
|
130
|
+
stringify;
|
|
128
131
|
/**
|
|
129
132
|
* A class that can be used to convert an object to a struct. Optionally this
|
|
130
133
|
* class can be used to erase/throw on circular references during conversion.
|
|
@@ -170,7 +173,7 @@ class ObjectToStructConverter {
|
|
|
170
173
|
for (const prop in obj) {
|
|
171
174
|
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
172
175
|
const value = obj[prop];
|
|
173
|
-
if (
|
|
176
|
+
if ((0, helper_1.isUndefined)(value)) {
|
|
174
177
|
continue;
|
|
175
178
|
}
|
|
176
179
|
convertedObject.fields[prop] = this.encodeValue_(value);
|
|
@@ -195,22 +198,22 @@ class ObjectToStructConverter {
|
|
|
195
198
|
*/
|
|
196
199
|
encodeValue_(value) {
|
|
197
200
|
let convertedValue;
|
|
198
|
-
if (
|
|
201
|
+
if ((0, helper_1.isNull)(value)) {
|
|
199
202
|
convertedValue = {
|
|
200
203
|
nullValue: 0,
|
|
201
204
|
};
|
|
202
205
|
}
|
|
203
|
-
else if (
|
|
206
|
+
else if ((0, helper_1.isNumber)(value)) {
|
|
204
207
|
convertedValue = {
|
|
205
208
|
numberValue: value,
|
|
206
209
|
};
|
|
207
210
|
}
|
|
208
|
-
else if (
|
|
211
|
+
else if ((0, helper_1.isString)(value)) {
|
|
209
212
|
convertedValue = {
|
|
210
213
|
stringValue: value,
|
|
211
214
|
};
|
|
212
215
|
}
|
|
213
|
-
else if (
|
|
216
|
+
else if ((0, helper_1.isBoolean)(value)) {
|
|
214
217
|
convertedValue = {
|
|
215
218
|
boolValue: value,
|
|
216
219
|
};
|
|
@@ -220,7 +223,7 @@ class ObjectToStructConverter {
|
|
|
220
223
|
blobValue: value,
|
|
221
224
|
};
|
|
222
225
|
}
|
|
223
|
-
else if (
|
|
226
|
+
else if ((0, helper_1.isObject)(value)) {
|
|
224
227
|
if (this.seenObjects.has(value)) {
|
|
225
228
|
// Circular reference.
|
|
226
229
|
if (!this.removeCircular) {
|
|
@@ -239,7 +242,7 @@ class ObjectToStructConverter {
|
|
|
239
242
|
};
|
|
240
243
|
}
|
|
241
244
|
}
|
|
242
|
-
else if (
|
|
245
|
+
else if ((0, helper_1.isArray)(value)) {
|
|
243
246
|
convertedValue = {
|
|
244
247
|
listValue: {
|
|
245
248
|
values: value.map(this.encodeValue_.bind(this)),
|
|
@@ -259,6 +262,19 @@ class ObjectToStructConverter {
|
|
|
259
262
|
}
|
|
260
263
|
exports.ObjectToStructConverter = ObjectToStructConverter;
|
|
261
264
|
class GrpcService extends common_1.Service {
|
|
265
|
+
grpc;
|
|
266
|
+
grpcVersion;
|
|
267
|
+
grpcCredentials;
|
|
268
|
+
grpcMetadata;
|
|
269
|
+
maxRetries;
|
|
270
|
+
userAgent;
|
|
271
|
+
activeServiceMap_ = new Map();
|
|
272
|
+
protos = {};
|
|
273
|
+
/** A cache for proto objects. */
|
|
274
|
+
static protoObjectCache = {};
|
|
275
|
+
static GRPC_SERVICE_OPTIONS = GRPC_SERVICE_OPTIONS;
|
|
276
|
+
static GRPC_ERROR_CODE_TO_HTTP = GRPC_ERROR_CODE_TO_HTTP;
|
|
277
|
+
static ObjectToStructConverter = ObjectToStructConverter;
|
|
262
278
|
/**
|
|
263
279
|
* Service is a base class, meant to be inherited from by a "service," like
|
|
264
280
|
* BigQuery or Storage.
|
|
@@ -274,8 +290,6 @@ class GrpcService extends common_1.Service {
|
|
|
274
290
|
*/
|
|
275
291
|
constructor(config, options) {
|
|
276
292
|
super(config, options);
|
|
277
|
-
this.activeServiceMap_ = new Map();
|
|
278
|
-
this.protos = {};
|
|
279
293
|
if (global['GCLOUD_SANDBOX_ENV']) {
|
|
280
294
|
// gRPC has a tendency to cause our doc unit tests to fail, so we prevent
|
|
281
295
|
// any calls to that library from going through.
|
|
@@ -517,7 +531,7 @@ class GrpcService extends common_1.Service {
|
|
|
517
531
|
const service = this.getService_(protoOpts);
|
|
518
532
|
const grpcMetadata = this.grpcMetadata;
|
|
519
533
|
const grpcOpts = {};
|
|
520
|
-
if (
|
|
534
|
+
if ((0, helper_1.isNumber)(protoOpts.timeout)) {
|
|
521
535
|
grpcOpts.deadline = GrpcService.createDeadline_(protoOpts.timeout);
|
|
522
536
|
}
|
|
523
537
|
try {
|
|
@@ -601,7 +615,7 @@ class GrpcService extends common_1.Service {
|
|
|
601
615
|
* @return {error|null}
|
|
602
616
|
*/
|
|
603
617
|
static decorateError_(err) {
|
|
604
|
-
const errorObj =
|
|
618
|
+
const errorObj = (0, helper_1.isError)(err) ? err : {};
|
|
605
619
|
return GrpcService.decorateGrpcResponse_(errorObj, err);
|
|
606
620
|
}
|
|
607
621
|
/**
|
|
@@ -764,7 +778,15 @@ class GrpcService extends common_1.Service {
|
|
|
764
778
|
*/
|
|
765
779
|
getGrpcCredentials_(callback) {
|
|
766
780
|
this.authClient.getClient().then(client => {
|
|
767
|
-
const credentials = this.grpc.credentials.combineChannelCredentials(this.grpc.credentials.createSsl(),
|
|
781
|
+
const credentials = this.grpc.credentials.combineChannelCredentials(this.grpc.credentials.createSsl(), google_gax_1.grpc.credentials.createFromGoogleCredential({
|
|
782
|
+
// the `grpc` package does not support the `Headers` object yet
|
|
783
|
+
getRequestHeaders: async (url) => {
|
|
784
|
+
const headers = await client.getRequestHeaders(url);
|
|
785
|
+
const genericHeadersObject = {};
|
|
786
|
+
headers.forEach((value, key) => (genericHeadersObject[key] = value));
|
|
787
|
+
return genericHeadersObject;
|
|
788
|
+
},
|
|
789
|
+
}));
|
|
768
790
|
if (!this.projectId || this.projectId === '{{projectId}}') {
|
|
769
791
|
this.projectId = client.projectId;
|
|
770
792
|
}
|
|
@@ -818,9 +840,4 @@ class GrpcService extends common_1.Service {
|
|
|
818
840
|
}
|
|
819
841
|
}
|
|
820
842
|
exports.GrpcService = GrpcService;
|
|
821
|
-
/** A cache for proto objects. */
|
|
822
|
-
GrpcService.protoObjectCache = {};
|
|
823
|
-
GrpcService.GRPC_SERVICE_OPTIONS = GRPC_SERVICE_OPTIONS;
|
|
824
|
-
GrpcService.GRPC_ERROR_CODE_TO_HTTP = GRPC_ERROR_CODE_TO_HTTP;
|
|
825
|
-
GrpcService.ObjectToStructConverter = ObjectToStructConverter;
|
|
826
843
|
//# sourceMappingURL=service.js.map
|
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
|
}
|