@google-cloud/spanner 7.19.1 → 7.21.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 +1 -0
- package/build/protos/protos.js +993 -331
- package/build/protos/protos.json +39 -15
- package/build/src/batch-transaction.js +5 -3
- package/build/src/codec.d.ts +85 -0
- package/build/src/codec.js +244 -1
- package/build/src/database.d.ts +14 -2
- package/build/src/database.js +72 -44
- package/build/src/index.d.ts +22 -2
- package/build/src/index.js +74 -2
- package/build/src/instance.js +4 -0
- package/build/src/instrument.d.ts +2 -0
- package/build/src/instrument.js +10 -5
- package/build/src/request_id_header.d.ts +4 -1
- package/build/src/request_id_header.js +21 -1
- package/build/src/session-factory.d.ts +24 -2
- package/build/src/session-factory.js +27 -3
- package/build/src/session.d.ts +3 -0
- package/build/src/session.js +13 -4
- package/build/src/table.d.ts +3 -0
- package/build/src/table.js +8 -0
- package/build/src/transaction-runner.d.ts +2 -0
- package/build/src/transaction-runner.js +7 -7
- package/build/src/transaction.d.ts +4 -1
- package/build/src/transaction.js +81 -51
- package/package.json +1 -1
- package/CHANGELOG.md +0 -1611
package/build/protos/protos.json
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"FileDescriptorSet": {
|
|
29
|
+
"edition": "proto2",
|
|
29
30
|
"fields": {
|
|
30
31
|
"file": {
|
|
31
32
|
"rule": "repeated",
|
|
@@ -35,6 +36,7 @@
|
|
|
35
36
|
}
|
|
36
37
|
},
|
|
37
38
|
"Edition": {
|
|
39
|
+
"edition": "proto2",
|
|
38
40
|
"values": {
|
|
39
41
|
"EDITION_UNKNOWN": 0,
|
|
40
42
|
"EDITION_PROTO2": 998,
|
|
@@ -50,6 +52,7 @@
|
|
|
50
52
|
}
|
|
51
53
|
},
|
|
52
54
|
"FileDescriptorProto": {
|
|
55
|
+
"edition": "proto2",
|
|
53
56
|
"fields": {
|
|
54
57
|
"name": {
|
|
55
58
|
"type": "string",
|
|
@@ -67,18 +70,12 @@
|
|
|
67
70
|
"publicDependency": {
|
|
68
71
|
"rule": "repeated",
|
|
69
72
|
"type": "int32",
|
|
70
|
-
"id": 10
|
|
71
|
-
"options": {
|
|
72
|
-
"packed": false
|
|
73
|
-
}
|
|
73
|
+
"id": 10
|
|
74
74
|
},
|
|
75
75
|
"weakDependency": {
|
|
76
76
|
"rule": "repeated",
|
|
77
77
|
"type": "int32",
|
|
78
|
-
"id": 11
|
|
79
|
-
"options": {
|
|
80
|
-
"packed": false
|
|
81
|
-
}
|
|
78
|
+
"id": 11
|
|
82
79
|
},
|
|
83
80
|
"messageType": {
|
|
84
81
|
"rule": "repeated",
|
|
@@ -119,6 +116,7 @@
|
|
|
119
116
|
}
|
|
120
117
|
},
|
|
121
118
|
"DescriptorProto": {
|
|
119
|
+
"edition": "proto2",
|
|
122
120
|
"fields": {
|
|
123
121
|
"name": {
|
|
124
122
|
"type": "string",
|
|
@@ -201,6 +199,7 @@
|
|
|
201
199
|
}
|
|
202
200
|
},
|
|
203
201
|
"ExtensionRangeOptions": {
|
|
202
|
+
"edition": "proto2",
|
|
204
203
|
"fields": {
|
|
205
204
|
"uninterpretedOption": {
|
|
206
205
|
"rule": "repeated",
|
|
@@ -274,6 +273,7 @@
|
|
|
274
273
|
}
|
|
275
274
|
},
|
|
276
275
|
"FieldDescriptorProto": {
|
|
276
|
+
"edition": "proto2",
|
|
277
277
|
"fields": {
|
|
278
278
|
"name": {
|
|
279
279
|
"type": "string",
|
|
@@ -353,6 +353,7 @@
|
|
|
353
353
|
}
|
|
354
354
|
},
|
|
355
355
|
"OneofDescriptorProto": {
|
|
356
|
+
"edition": "proto2",
|
|
356
357
|
"fields": {
|
|
357
358
|
"name": {
|
|
358
359
|
"type": "string",
|
|
@@ -365,6 +366,7 @@
|
|
|
365
366
|
}
|
|
366
367
|
},
|
|
367
368
|
"EnumDescriptorProto": {
|
|
369
|
+
"edition": "proto2",
|
|
368
370
|
"fields": {
|
|
369
371
|
"name": {
|
|
370
372
|
"type": "string",
|
|
@@ -406,6 +408,7 @@
|
|
|
406
408
|
}
|
|
407
409
|
},
|
|
408
410
|
"EnumValueDescriptorProto": {
|
|
411
|
+
"edition": "proto2",
|
|
409
412
|
"fields": {
|
|
410
413
|
"name": {
|
|
411
414
|
"type": "string",
|
|
@@ -422,6 +425,7 @@
|
|
|
422
425
|
}
|
|
423
426
|
},
|
|
424
427
|
"ServiceDescriptorProto": {
|
|
428
|
+
"edition": "proto2",
|
|
425
429
|
"fields": {
|
|
426
430
|
"name": {
|
|
427
431
|
"type": "string",
|
|
@@ -439,6 +443,7 @@
|
|
|
439
443
|
}
|
|
440
444
|
},
|
|
441
445
|
"MethodDescriptorProto": {
|
|
446
|
+
"edition": "proto2",
|
|
442
447
|
"fields": {
|
|
443
448
|
"name": {
|
|
444
449
|
"type": "string",
|
|
@@ -473,6 +478,7 @@
|
|
|
473
478
|
}
|
|
474
479
|
},
|
|
475
480
|
"FileOptions": {
|
|
481
|
+
"edition": "proto2",
|
|
476
482
|
"fields": {
|
|
477
483
|
"javaPackage": {
|
|
478
484
|
"type": "string",
|
|
@@ -614,6 +620,7 @@
|
|
|
614
620
|
}
|
|
615
621
|
},
|
|
616
622
|
"MessageOptions": {
|
|
623
|
+
"edition": "proto2",
|
|
617
624
|
"fields": {
|
|
618
625
|
"messageSetWireFormat": {
|
|
619
626
|
"type": "bool",
|
|
@@ -687,6 +694,7 @@
|
|
|
687
694
|
]
|
|
688
695
|
},
|
|
689
696
|
"FieldOptions": {
|
|
697
|
+
"edition": "proto2",
|
|
690
698
|
"fields": {
|
|
691
699
|
"ctype": {
|
|
692
700
|
"type": "CType",
|
|
@@ -748,10 +756,7 @@
|
|
|
748
756
|
"targets": {
|
|
749
757
|
"rule": "repeated",
|
|
750
758
|
"type": "OptionTargetType",
|
|
751
|
-
"id": 19
|
|
752
|
-
"options": {
|
|
753
|
-
"packed": false
|
|
754
|
-
}
|
|
759
|
+
"id": 19
|
|
755
760
|
},
|
|
756
761
|
"editionDefaults": {
|
|
757
762
|
"rule": "repeated",
|
|
@@ -835,6 +840,7 @@
|
|
|
835
840
|
}
|
|
836
841
|
},
|
|
837
842
|
"OneofOptions": {
|
|
843
|
+
"edition": "proto2",
|
|
838
844
|
"fields": {
|
|
839
845
|
"features": {
|
|
840
846
|
"type": "FeatureSet",
|
|
@@ -854,6 +860,7 @@
|
|
|
854
860
|
]
|
|
855
861
|
},
|
|
856
862
|
"EnumOptions": {
|
|
863
|
+
"edition": "proto2",
|
|
857
864
|
"fields": {
|
|
858
865
|
"allowAlias": {
|
|
859
866
|
"type": "bool",
|
|
@@ -897,6 +904,7 @@
|
|
|
897
904
|
]
|
|
898
905
|
},
|
|
899
906
|
"EnumValueOptions": {
|
|
907
|
+
"edition": "proto2",
|
|
900
908
|
"fields": {
|
|
901
909
|
"deprecated": {
|
|
902
910
|
"type": "bool",
|
|
@@ -930,6 +938,7 @@
|
|
|
930
938
|
]
|
|
931
939
|
},
|
|
932
940
|
"ServiceOptions": {
|
|
941
|
+
"edition": "proto2",
|
|
933
942
|
"fields": {
|
|
934
943
|
"features": {
|
|
935
944
|
"type": "FeatureSet",
|
|
@@ -956,6 +965,7 @@
|
|
|
956
965
|
]
|
|
957
966
|
},
|
|
958
967
|
"MethodOptions": {
|
|
968
|
+
"edition": "proto2",
|
|
959
969
|
"fields": {
|
|
960
970
|
"deprecated": {
|
|
961
971
|
"type": "bool",
|
|
@@ -998,6 +1008,7 @@
|
|
|
998
1008
|
}
|
|
999
1009
|
},
|
|
1000
1010
|
"UninterpretedOption": {
|
|
1011
|
+
"edition": "proto2",
|
|
1001
1012
|
"fields": {
|
|
1002
1013
|
"name": {
|
|
1003
1014
|
"rule": "repeated",
|
|
@@ -1047,6 +1058,7 @@
|
|
|
1047
1058
|
}
|
|
1048
1059
|
},
|
|
1049
1060
|
"FeatureSet": {
|
|
1061
|
+
"edition": "proto2",
|
|
1050
1062
|
"fields": {
|
|
1051
1063
|
"fieldPresence": {
|
|
1052
1064
|
"type": "FieldPresence",
|
|
@@ -1188,6 +1200,7 @@
|
|
|
1188
1200
|
}
|
|
1189
1201
|
},
|
|
1190
1202
|
"FeatureSetDefaults": {
|
|
1203
|
+
"edition": "proto2",
|
|
1191
1204
|
"fields": {
|
|
1192
1205
|
"defaults": {
|
|
1193
1206
|
"rule": "repeated",
|
|
@@ -1219,6 +1232,7 @@
|
|
|
1219
1232
|
}
|
|
1220
1233
|
},
|
|
1221
1234
|
"SourceCodeInfo": {
|
|
1235
|
+
"edition": "proto2",
|
|
1222
1236
|
"fields": {
|
|
1223
1237
|
"location": {
|
|
1224
1238
|
"rule": "repeated",
|
|
@@ -1232,12 +1246,18 @@
|
|
|
1232
1246
|
"path": {
|
|
1233
1247
|
"rule": "repeated",
|
|
1234
1248
|
"type": "int32",
|
|
1235
|
-
"id": 1
|
|
1249
|
+
"id": 1,
|
|
1250
|
+
"options": {
|
|
1251
|
+
"packed": true
|
|
1252
|
+
}
|
|
1236
1253
|
},
|
|
1237
1254
|
"span": {
|
|
1238
1255
|
"rule": "repeated",
|
|
1239
1256
|
"type": "int32",
|
|
1240
|
-
"id": 2
|
|
1257
|
+
"id": 2,
|
|
1258
|
+
"options": {
|
|
1259
|
+
"packed": true
|
|
1260
|
+
}
|
|
1241
1261
|
},
|
|
1242
1262
|
"leadingComments": {
|
|
1243
1263
|
"type": "string",
|
|
@@ -1257,6 +1277,7 @@
|
|
|
1257
1277
|
}
|
|
1258
1278
|
},
|
|
1259
1279
|
"GeneratedCodeInfo": {
|
|
1280
|
+
"edition": "proto2",
|
|
1260
1281
|
"fields": {
|
|
1261
1282
|
"annotation": {
|
|
1262
1283
|
"rule": "repeated",
|
|
@@ -1270,7 +1291,10 @@
|
|
|
1270
1291
|
"path": {
|
|
1271
1292
|
"rule": "repeated",
|
|
1272
1293
|
"type": "int32",
|
|
1273
|
-
"id": 1
|
|
1294
|
+
"id": 1,
|
|
1295
|
+
"options": {
|
|
1296
|
+
"packed": true
|
|
1297
|
+
}
|
|
1274
1298
|
},
|
|
1275
1299
|
"sourceFile": {
|
|
1276
1300
|
"type": "string",
|
|
@@ -23,6 +23,7 @@ const is = require("is");
|
|
|
23
23
|
const transaction_1 = require("./transaction");
|
|
24
24
|
const common_1 = require("../src/common");
|
|
25
25
|
const instrument_1 = require("./instrument");
|
|
26
|
+
const request_id_header_1 = require("./request_id_header");
|
|
26
27
|
/**
|
|
27
28
|
* Use a BatchTransaction object to create partitions and read/query against
|
|
28
29
|
* your Cloud Spanner database.
|
|
@@ -139,7 +140,7 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
139
140
|
method: 'partitionQuery',
|
|
140
141
|
reqOpts,
|
|
141
142
|
gaxOpts: query.gaxOptions,
|
|
142
|
-
headers: headers,
|
|
143
|
+
headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session),
|
|
143
144
|
}, (err, partitions, resp) => {
|
|
144
145
|
if (err) {
|
|
145
146
|
(0, instrument_1.setSpanError)(span, err);
|
|
@@ -173,10 +174,11 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
173
174
|
transaction: { id: this.id },
|
|
174
175
|
});
|
|
175
176
|
config.reqOpts = extend({}, query);
|
|
176
|
-
|
|
177
|
+
const headers = {
|
|
177
178
|
[common_1.CLOUD_RESOURCE_HEADER]: this.session.parent
|
|
178
179
|
.formattedName_,
|
|
179
180
|
};
|
|
181
|
+
config.headers = (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session);
|
|
180
182
|
delete query.partitionOptions;
|
|
181
183
|
this.session.request(config, (err, resp) => {
|
|
182
184
|
if (err) {
|
|
@@ -251,7 +253,7 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
251
253
|
method: 'partitionRead',
|
|
252
254
|
reqOpts,
|
|
253
255
|
gaxOpts: options.gaxOptions,
|
|
254
|
-
headers: headers,
|
|
256
|
+
headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session),
|
|
255
257
|
}, (err, partitions, resp) => {
|
|
256
258
|
if (err) {
|
|
257
259
|
(0, instrument_1.setSpanError)(span, err);
|
package/build/src/codec.d.ts
CHANGED
|
@@ -205,6 +205,89 @@ export declare class PGOid extends WrappedNumber {
|
|
|
205
205
|
constructor(value: string);
|
|
206
206
|
valueOf(): number;
|
|
207
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* @typedef Interval
|
|
210
|
+
* @see Spanner.interval
|
|
211
|
+
*/
|
|
212
|
+
export declare class Interval {
|
|
213
|
+
private months;
|
|
214
|
+
private days;
|
|
215
|
+
private nanoseconds;
|
|
216
|
+
private static readonly ISO8601_PATTERN;
|
|
217
|
+
static readonly MONTHS_PER_YEAR: number;
|
|
218
|
+
static readonly DAYS_PER_MONTH: number;
|
|
219
|
+
static readonly HOURS_PER_DAY: number;
|
|
220
|
+
static readonly MINUTES_PER_HOUR: number;
|
|
221
|
+
static readonly SECONDS_PER_MINUTE: number;
|
|
222
|
+
static readonly SECONDS_PER_HOUR: number;
|
|
223
|
+
static readonly MILLISECONDS_PER_SECOND: number;
|
|
224
|
+
static readonly MICROSECONDS_PER_MILLISECOND: number;
|
|
225
|
+
static readonly NANOSECONDS_PER_MICROSECOND: number;
|
|
226
|
+
static readonly NANOSECONDS_PER_MILLISECOND: number;
|
|
227
|
+
static readonly NANOSECONDS_PER_SECOND: number;
|
|
228
|
+
static readonly NANOSECONDS_PER_DAY: bigint;
|
|
229
|
+
static readonly NANOSECONDS_PER_MONTH: bigint;
|
|
230
|
+
static readonly ZERO: Interval;
|
|
231
|
+
/**
|
|
232
|
+
* @param months months part of the `Interval`
|
|
233
|
+
* @param days days part of the `Interval`
|
|
234
|
+
* @param nanoseconds nanoseconds part of the `Interval`
|
|
235
|
+
*/
|
|
236
|
+
constructor(months: number, days: number, nanoseconds: bigint);
|
|
237
|
+
/**
|
|
238
|
+
* @returns months part of the `Interval`.
|
|
239
|
+
*/
|
|
240
|
+
getMonths(): number;
|
|
241
|
+
/**
|
|
242
|
+
* @returns days part of the `Interval`.
|
|
243
|
+
*/
|
|
244
|
+
getDays(): number;
|
|
245
|
+
/**
|
|
246
|
+
* @returns nanoseconds part of the `Interval`.
|
|
247
|
+
*/
|
|
248
|
+
getNanoseconds(): bigint;
|
|
249
|
+
/**
|
|
250
|
+
* Constructs an `Interval` with specified months.
|
|
251
|
+
*/
|
|
252
|
+
static fromMonths(months: number): Interval;
|
|
253
|
+
/**
|
|
254
|
+
* Constructs an `Interval` with specified days.
|
|
255
|
+
*/
|
|
256
|
+
static fromDays(days: number): Interval;
|
|
257
|
+
/**
|
|
258
|
+
* Constructs an `Interval` with specified seconds.
|
|
259
|
+
*/
|
|
260
|
+
static fromSeconds(seconds: number): Interval;
|
|
261
|
+
/**
|
|
262
|
+
* Constructs an `Interval` with specified milliseconds.
|
|
263
|
+
*/
|
|
264
|
+
static fromMilliseconds(milliseconds: number): Interval;
|
|
265
|
+
/**
|
|
266
|
+
* Constructs an `Interval` with specified microseconds.
|
|
267
|
+
*/
|
|
268
|
+
static fromMicroseconds(microseconds: number): Interval;
|
|
269
|
+
/**
|
|
270
|
+
* Constructs an `Interval` with specified nanoseconds.
|
|
271
|
+
*/
|
|
272
|
+
static fromNanoseconds(nanoseconds: bigint): Interval;
|
|
273
|
+
/**
|
|
274
|
+
* Constructs an Interval from ISO8601 duration format: `P[n]Y[n]M[n]DT[n]H[n]M[n][.fffffffff]S`.
|
|
275
|
+
* Only seconds can be fractional, and can have at most 9 digits after decimal point.
|
|
276
|
+
* Both '.' and ',' are considered valid decimal point.
|
|
277
|
+
*/
|
|
278
|
+
static fromISO8601(isoString: string): Interval;
|
|
279
|
+
/**
|
|
280
|
+
* @returns string representation of Interval in ISO8601 duration format: `P[n]Y[n]M[n]DT[n]H[n]M[n][.fffffffff]S`
|
|
281
|
+
*/
|
|
282
|
+
toISO8601(): string;
|
|
283
|
+
equals(other: Interval): boolean;
|
|
284
|
+
valueOf(): Interval;
|
|
285
|
+
/**
|
|
286
|
+
* @returns JSON representation for Interval.
|
|
287
|
+
* Interval is represented in ISO8601 duration format string in JSON.
|
|
288
|
+
*/
|
|
289
|
+
toJSON(): string;
|
|
290
|
+
}
|
|
208
291
|
/**
|
|
209
292
|
* @typedef JSONOptions
|
|
210
293
|
* @property {boolean} [wrapNumbers=false] Indicates if the numbers should be
|
|
@@ -276,6 +359,7 @@ interface FieldType extends Type {
|
|
|
276
359
|
* - string
|
|
277
360
|
* - bytes
|
|
278
361
|
* - json
|
|
362
|
+
* - interval
|
|
279
363
|
* - proto
|
|
280
364
|
* - enum
|
|
281
365
|
* - timestamp
|
|
@@ -353,6 +437,7 @@ export declare const codec: {
|
|
|
353
437
|
ProtoMessage: typeof ProtoMessage;
|
|
354
438
|
ProtoEnum: typeof ProtoEnum;
|
|
355
439
|
PGOid: typeof PGOid;
|
|
440
|
+
Interval: typeof Interval;
|
|
356
441
|
convertFieldsToJson: typeof convertFieldsToJson;
|
|
357
442
|
decode: typeof decode;
|
|
358
443
|
encode: typeof encode;
|
package/build/src/codec.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.codec = exports.PGOid = exports.PGJsonb = exports.ProtoEnum = exports.ProtoMessage = exports.PGNumeric = exports.Numeric = exports.Struct = exports.Int = exports.Float = exports.Float32 = exports.SpannerDate = void 0;
|
|
3
|
+
exports.codec = exports.Interval = exports.PGOid = exports.PGJsonb = exports.ProtoEnum = exports.ProtoMessage = exports.PGNumeric = exports.Numeric = exports.Struct = exports.Int = exports.Float = exports.Float32 = exports.SpannerDate = void 0;
|
|
4
4
|
/*!
|
|
5
5
|
* Copyright 2017 Google Inc. All Rights Reserved.
|
|
6
6
|
*
|
|
@@ -306,6 +306,236 @@ class PGOid extends WrappedNumber {
|
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
exports.PGOid = PGOid;
|
|
309
|
+
/**
|
|
310
|
+
* @typedef Interval
|
|
311
|
+
* @see Spanner.interval
|
|
312
|
+
*/
|
|
313
|
+
class Interval {
|
|
314
|
+
/**
|
|
315
|
+
* @param months months part of the `Interval`
|
|
316
|
+
* @param days days part of the `Interval`
|
|
317
|
+
* @param nanoseconds nanoseconds part of the `Interval`
|
|
318
|
+
*/
|
|
319
|
+
constructor(months, days, nanoseconds) {
|
|
320
|
+
if (!is.integer(months)) {
|
|
321
|
+
throw new google_gax_1.GoogleError(`Invalid months: ${months}, months should be an integral value`);
|
|
322
|
+
}
|
|
323
|
+
if (!is.integer(days)) {
|
|
324
|
+
throw new google_gax_1.GoogleError(`Invalid days: ${days}, days should be an integral value`);
|
|
325
|
+
}
|
|
326
|
+
if (is.null(nanoseconds) || is.undefined(nanoseconds)) {
|
|
327
|
+
throw new google_gax_1.GoogleError(`Invalid nanoseconds: ${nanoseconds}, nanoseconds should be a valid bigint value`);
|
|
328
|
+
}
|
|
329
|
+
this.months = months;
|
|
330
|
+
this.days = days;
|
|
331
|
+
this.nanoseconds = nanoseconds;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* @returns months part of the `Interval`.
|
|
335
|
+
*/
|
|
336
|
+
getMonths() {
|
|
337
|
+
return this.months;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* @returns days part of the `Interval`.
|
|
341
|
+
*/
|
|
342
|
+
getDays() {
|
|
343
|
+
return this.days;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* @returns nanoseconds part of the `Interval`.
|
|
347
|
+
*/
|
|
348
|
+
getNanoseconds() {
|
|
349
|
+
return this.nanoseconds;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Constructs an `Interval` with specified months.
|
|
353
|
+
*/
|
|
354
|
+
static fromMonths(months) {
|
|
355
|
+
return new Interval(months, 0, BigInt(0));
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Constructs an `Interval` with specified days.
|
|
359
|
+
*/
|
|
360
|
+
static fromDays(days) {
|
|
361
|
+
return new Interval(0, days, BigInt(0));
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Constructs an `Interval` with specified seconds.
|
|
365
|
+
*/
|
|
366
|
+
static fromSeconds(seconds) {
|
|
367
|
+
if (!is.integer(seconds)) {
|
|
368
|
+
throw new google_gax_1.GoogleError(`Invalid seconds: ${seconds}, seconds should be an integral value`);
|
|
369
|
+
}
|
|
370
|
+
return new Interval(0, 0, BigInt(Interval.NANOSECONDS_PER_SECOND) * BigInt(seconds));
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Constructs an `Interval` with specified milliseconds.
|
|
374
|
+
*/
|
|
375
|
+
static fromMilliseconds(milliseconds) {
|
|
376
|
+
if (!is.integer(milliseconds)) {
|
|
377
|
+
throw new google_gax_1.GoogleError(`Invalid milliseconds: ${milliseconds}, milliseconds should be an integral value`);
|
|
378
|
+
}
|
|
379
|
+
return new Interval(0, 0, BigInt(Interval.NANOSECONDS_PER_MILLISECOND) * BigInt(milliseconds));
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Constructs an `Interval` with specified microseconds.
|
|
383
|
+
*/
|
|
384
|
+
static fromMicroseconds(microseconds) {
|
|
385
|
+
if (!is.integer(microseconds)) {
|
|
386
|
+
throw new google_gax_1.GoogleError(`Invalid microseconds: ${microseconds}, microseconds should be an integral value`);
|
|
387
|
+
}
|
|
388
|
+
return new Interval(0, 0, BigInt(Interval.NANOSECONDS_PER_MICROSECOND) * BigInt(microseconds));
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Constructs an `Interval` with specified nanoseconds.
|
|
392
|
+
*/
|
|
393
|
+
static fromNanoseconds(nanoseconds) {
|
|
394
|
+
return new Interval(0, 0, nanoseconds);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Constructs an Interval from ISO8601 duration format: `P[n]Y[n]M[n]DT[n]H[n]M[n][.fffffffff]S`.
|
|
398
|
+
* Only seconds can be fractional, and can have at most 9 digits after decimal point.
|
|
399
|
+
* Both '.' and ',' are considered valid decimal point.
|
|
400
|
+
*/
|
|
401
|
+
static fromISO8601(isoString) {
|
|
402
|
+
const matcher = Interval.ISO8601_PATTERN.exec(isoString);
|
|
403
|
+
if (!matcher) {
|
|
404
|
+
throw new google_gax_1.GoogleError(`Invalid ISO8601 duration string: ${isoString}`);
|
|
405
|
+
}
|
|
406
|
+
const getNullOrDefault = (groupIdx) => matcher[groupIdx] === undefined ? '0' : matcher[groupIdx];
|
|
407
|
+
const years = parseInt(getNullOrDefault(1).replace('Y', ''));
|
|
408
|
+
const months = parseInt(getNullOrDefault(2).replace('M', ''));
|
|
409
|
+
const days = parseInt(getNullOrDefault(3).replace('D', ''));
|
|
410
|
+
const hours = parseInt(getNullOrDefault(5).replace('H', ''));
|
|
411
|
+
const minutes = parseInt(getNullOrDefault(6).replace('M', ''));
|
|
412
|
+
const seconds = (0, big_js_1.Big)(getNullOrDefault(7).replace('S', '').replace(',', '.'));
|
|
413
|
+
const totalMonths = (0, big_js_1.Big)(years)
|
|
414
|
+
.mul((0, big_js_1.Big)(Interval.MONTHS_PER_YEAR))
|
|
415
|
+
.add((0, big_js_1.Big)(months))
|
|
416
|
+
.toNumber();
|
|
417
|
+
if (!Number.isSafeInteger(totalMonths)) {
|
|
418
|
+
throw new google_gax_1.GoogleError('Total months is outside of the range of safe integer');
|
|
419
|
+
}
|
|
420
|
+
const totalNanoseconds = BigInt(seconds
|
|
421
|
+
.add((0, big_js_1.Big)((BigInt(hours) * BigInt(Interval.SECONDS_PER_HOUR)).toString()))
|
|
422
|
+
.add((0, big_js_1.Big)((BigInt(minutes) * BigInt(Interval.SECONDS_PER_MINUTE)).toString()))
|
|
423
|
+
.mul((0, big_js_1.Big)(this.NANOSECONDS_PER_SECOND))
|
|
424
|
+
.toString());
|
|
425
|
+
return new Interval(totalMonths, days, totalNanoseconds);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* @returns string representation of Interval in ISO8601 duration format: `P[n]Y[n]M[n]DT[n]H[n]M[n][.fffffffff]S`
|
|
429
|
+
*/
|
|
430
|
+
toISO8601() {
|
|
431
|
+
if (this.equals(Interval.ZERO)) {
|
|
432
|
+
return 'P0Y';
|
|
433
|
+
}
|
|
434
|
+
// months part is normalized to years and months.
|
|
435
|
+
let result = 'P';
|
|
436
|
+
if (this.months !== 0) {
|
|
437
|
+
const years_part = Math.trunc(this.months / Interval.MONTHS_PER_YEAR);
|
|
438
|
+
const months_part = this.months - years_part * Interval.MONTHS_PER_YEAR;
|
|
439
|
+
if (years_part !== 0) {
|
|
440
|
+
result += `${years_part}Y`;
|
|
441
|
+
}
|
|
442
|
+
if (months_part !== 0) {
|
|
443
|
+
result += `${months_part}M`;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (this.days !== 0) {
|
|
447
|
+
result += `${this.days}D`;
|
|
448
|
+
}
|
|
449
|
+
// Nanoseconds part is normalized to hours, minutes and nanoseconds.
|
|
450
|
+
if (this.nanoseconds !== BigInt(0)) {
|
|
451
|
+
result += 'T';
|
|
452
|
+
let nanoseconds = this.nanoseconds;
|
|
453
|
+
const hours_part = nanoseconds /
|
|
454
|
+
BigInt(Interval.NANOSECONDS_PER_SECOND * Interval.SECONDS_PER_HOUR);
|
|
455
|
+
nanoseconds =
|
|
456
|
+
nanoseconds -
|
|
457
|
+
hours_part *
|
|
458
|
+
BigInt(Interval.NANOSECONDS_PER_SECOND * Interval.SECONDS_PER_HOUR);
|
|
459
|
+
const minutes_part = nanoseconds /
|
|
460
|
+
BigInt(Interval.NANOSECONDS_PER_SECOND * Interval.SECONDS_PER_MINUTE);
|
|
461
|
+
nanoseconds =
|
|
462
|
+
nanoseconds -
|
|
463
|
+
minutes_part *
|
|
464
|
+
BigInt(Interval.NANOSECONDS_PER_SECOND * Interval.SECONDS_PER_MINUTE);
|
|
465
|
+
const zero_bigint = BigInt(0);
|
|
466
|
+
if (hours_part !== zero_bigint) {
|
|
467
|
+
result += `${hours_part}H`;
|
|
468
|
+
}
|
|
469
|
+
if (minutes_part !== zero_bigint) {
|
|
470
|
+
result += `${minutes_part}M`;
|
|
471
|
+
}
|
|
472
|
+
let sign = '';
|
|
473
|
+
if (nanoseconds < zero_bigint) {
|
|
474
|
+
sign = '-';
|
|
475
|
+
nanoseconds = -nanoseconds;
|
|
476
|
+
}
|
|
477
|
+
// Nanoseconds are converted to seconds and fractional part.
|
|
478
|
+
const seconds_part = nanoseconds / BigInt(Interval.NANOSECONDS_PER_SECOND);
|
|
479
|
+
nanoseconds =
|
|
480
|
+
nanoseconds - seconds_part * BigInt(Interval.NANOSECONDS_PER_SECOND);
|
|
481
|
+
if (seconds_part !== zero_bigint || nanoseconds !== zero_bigint) {
|
|
482
|
+
result += `${sign}${seconds_part}`;
|
|
483
|
+
if (nanoseconds !== zero_bigint) {
|
|
484
|
+
// Fractional part is kept in a group of 3
|
|
485
|
+
// For e.g.: PT0.5S will be normalized to PT0.500S
|
|
486
|
+
result += `.${nanoseconds
|
|
487
|
+
.toString()
|
|
488
|
+
.padStart(9, '0')
|
|
489
|
+
.replace(/(0{3})+$/, '')}`;
|
|
490
|
+
}
|
|
491
|
+
result += 'S';
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return result;
|
|
495
|
+
}
|
|
496
|
+
equals(other) {
|
|
497
|
+
if (!other) {
|
|
498
|
+
return false;
|
|
499
|
+
}
|
|
500
|
+
return (this.months === other.months &&
|
|
501
|
+
this.days === other.days &&
|
|
502
|
+
this.nanoseconds === other.nanoseconds);
|
|
503
|
+
}
|
|
504
|
+
valueOf() {
|
|
505
|
+
return this;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* @returns JSON representation for Interval.
|
|
509
|
+
* Interval is represented in ISO8601 duration format string in JSON.
|
|
510
|
+
*/
|
|
511
|
+
toJSON() {
|
|
512
|
+
return this.toISO8601().toString();
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
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));
|
|
309
539
|
/**
|
|
310
540
|
* @typedef JSONOptions
|
|
311
541
|
* @property {boolean} [wrapNumbers=false] Indicates if the numbers should be
|
|
@@ -468,6 +698,10 @@ function decode(value, type, columnMetadata) {
|
|
|
468
698
|
}
|
|
469
699
|
decoded = JSON.parse(decoded);
|
|
470
700
|
break;
|
|
701
|
+
case protos_1.google.spanner.v1.TypeCode.INTERVAL:
|
|
702
|
+
case 'INTERVAL':
|
|
703
|
+
decoded = Interval.fromISO8601(decoded);
|
|
704
|
+
break;
|
|
471
705
|
case protos_1.google.spanner.v1.TypeCode.ARRAY:
|
|
472
706
|
case 'ARRAY':
|
|
473
707
|
decoded = decoded.map(value => {
|
|
@@ -542,6 +776,9 @@ function encodeValue(value) {
|
|
|
542
776
|
if (value instanceof PGJsonb) {
|
|
543
777
|
return value.toString();
|
|
544
778
|
}
|
|
779
|
+
if (value instanceof Interval) {
|
|
780
|
+
return value.toISO8601();
|
|
781
|
+
}
|
|
545
782
|
if (is.object(value)) {
|
|
546
783
|
return JSON.stringify(value);
|
|
547
784
|
}
|
|
@@ -568,6 +805,7 @@ const TypeCode = {
|
|
|
568
805
|
bytes: 'BYTES',
|
|
569
806
|
json: 'JSON',
|
|
570
807
|
jsonb: 'JSON',
|
|
808
|
+
interval: 'INTERVAL',
|
|
571
809
|
proto: 'PROTO',
|
|
572
810
|
enum: 'ENUM',
|
|
573
811
|
array: 'ARRAY',
|
|
@@ -588,6 +826,7 @@ const TypeCode = {
|
|
|
588
826
|
* - string
|
|
589
827
|
* - bytes
|
|
590
828
|
* - json
|
|
829
|
+
* - interval
|
|
591
830
|
* - proto
|
|
592
831
|
* - enum
|
|
593
832
|
* - timestamp
|
|
@@ -636,6 +875,9 @@ function getType(value) {
|
|
|
636
875
|
if (value instanceof PGOid) {
|
|
637
876
|
return { type: 'pgOid' };
|
|
638
877
|
}
|
|
878
|
+
if (value instanceof Interval) {
|
|
879
|
+
return { type: 'interval' };
|
|
880
|
+
}
|
|
639
881
|
if (value instanceof ProtoMessage) {
|
|
640
882
|
return { type: 'proto', fullName: value.fullName };
|
|
641
883
|
}
|
|
@@ -782,6 +1024,7 @@ exports.codec = {
|
|
|
782
1024
|
ProtoMessage,
|
|
783
1025
|
ProtoEnum,
|
|
784
1026
|
PGOid,
|
|
1027
|
+
Interval,
|
|
785
1028
|
convertFieldsToJson,
|
|
786
1029
|
decode,
|
|
787
1030
|
encode,
|